1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use std::time::Duration;

use Client;
use Error;
use parser;
use Waitable;

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct PolicyReponse {
    pub templates: Vec<Policy>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Policy {
    pub desc: String,
    pub title: String,
    pub name: String,
    pub subscription_only: bool,
    pub uuid: String,
    pub cloud_only: bool,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanLaunchResponse {
    pub scan_uuid: String,

    pub scan_id: Option<u64>, // added by nessus-rs
}

impl ScanLaunchResponse {
    pub fn wait(&self, client: &Client, interval: Duration, max_attempts: Option<u64>) -> Result<(), Error> {
        <ScanLaunchResponse as Waitable>::wait(self, client, interval, max_attempts)
    }
}

impl Waitable for ScanLaunchResponse {
    fn is_pending(&self, client: &Client) -> Result<bool, Error> {
        let details = client.scan_details(self.scan_id.unwrap())?;
        Ok(details.is_running())
    }
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanListResponse {
    pub folders: Vec<Folder>,
    pub scans: Vec<Scan>,
    pub timestamp: u64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Folder {
    pub unread_count: Option<u32>,
    pub custom: u32,
    pub default_tag: u32,
    #[serde(rename="type")]
    pub folder_type: String,
    pub name: String,
    pub id: u64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Scan {
    pub folder_id: u64,
    pub read: bool,
    pub last_modification_date: u64,
    pub creation_date: u64,
    pub status: String,
    pub uuid: Option<String>,
    pub shared: bool,
    pub user_permissions: u64,
    pub owner: String,
    pub timezone: Option<String>,
    pub rrules: Option<String>,
    pub starttime: Option<String>,
    pub control: bool,
    pub name: String,
    pub id: u64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanDetails {
    pub info: ScanDetailsInfo,
    #[serde(default)]
    pub hosts: Vec<ScanDetailsHost>,
    #[serde(default)]
    pub comphosts: Vec<ScanDetailsHost>,
    #[serde(default)]
    pub vulnerabilities: Vec<ScanDetailsVulnerability>,
    #[serde(default)]
    pub compliance: Vec<ScanDetailsVulnerability>,
}

impl ScanDetails {
    pub fn is_complete(&self) -> bool {
        self.info.status == "complete"
    }

    pub fn is_running(&self) -> bool {
        self.info.status == "running"
    }
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanDetailsInfo {
    // pub acls
    pub edit_allowed: Option<bool>,
    pub status: String,
    pub policy: Option<String>,
    #[serde(rename="pci-can-upload")]
    pub pci_can_upload: Option<bool>,
    pub hasaudittrail: Option<bool>,
    pub scan_start: Option<u64>,
    pub folder_id: u64,
    pub targets: Option<String>,
    pub timestamp: Option<u64>,
    pub object_id: u64,
    pub scanner_name: String,
    pub haskb: Option<bool>,
    pub uuid: Option<String>,
    pub hostcount: Option<u64>,
    pub name: String,
    pub user_permissions: u64,
    pub control: bool,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanDetailsHost {
    pub host_id: u64,
    pub host_index: u64,
    pub hostname: String,
    pub progress: String,
    pub critical: u64,
    pub high: u64,
    pub medium: u64,
    pub low: u64,
    pub info: u64,
    pub totalchecksconsidered: u64,
    pub numchecksconsidered: u64,
    pub scanprogresstotal: u64,
    pub scanprogresscurrent: u64,
    pub score: u64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ScanDetailsVulnerability {
    pub plugin_id: u64,
    pub plugin_name: String,
    pub plugin_family: String,
    pub count: u64,
    pub vuln_index: u64,
    pub severity_index: u64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ExportToken {
    pub file: u64,
    pub token: String,

    pub scan_id: Option<u64>, // added by nessus-rs
}

impl ExportToken {
    pub fn wait(&self, client: &Client, interval: Duration, max_attempts: Option<u64>) -> Result<(), Error> {
        <ExportToken as Waitable>::wait(self, client, interval, max_attempts)
    }

    pub fn download(&self, client: &Client) -> Result<parser::NessusClientDatav2, Error> {
        client.download_export(self.scan_id.unwrap(), self.file)
    }
}

impl Waitable for ExportToken {
    fn is_pending(&self, client: &Client) -> Result<bool, Error> {
        let status = client.export_status(self.scan_id.unwrap(), self.file)?;
        Ok(!status.is_ready())
    }
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct ExportStatus {
    pub status: String,
}

impl ExportStatus {
    pub fn is_ready(&self) -> bool {
        self.status == "ready"
    }
}