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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
use std::time::Duration;

use Error;
use parser;
use Waitable;
use VulnScanner;

#[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: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct CreateScanRequest {
    pub uuid: String,
    pub settings: ScanSettings,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct CreateScanResponse {
    pub scan: CreateScanResponseData,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct CreateScanResponseData {
    pub creation_date: u64,
    pub custom_targets: String,
    pub default_permisssions: u64,
    pub description: String,
    pub emails: String,
    pub id: u64,
    pub last_modification_date: u64,
    pub name: String,
    pub notification_filter_type: String,
    pub notification_filters: String,
    pub owner: String,
    pub owner_id: u64,
    pub policy_id: u64,
    pub enabled: bool,
    pub rrules: String,
    pub scanner_id: u64,
    pub shared: u64,
    pub starttime: String,
    pub tag_id: u64,
    pub timezone: String,
    #[serde(rename="type")]
    pub scan_type: String,
    pub user_permissions: u64,
    pub uuid: String,
}

#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
pub struct ScanSettings {
    /// The name of the scan
    pub name: String,
    /// The description of the scan
    pub description: Option<String>,
    /// The unique id of the policy to use
    pub policy_id: Option<u64>,
    /// The unique id of the destination folder for the scan
    pub folder_id: Option<u64>,
    /// The unique id of the scanner to use
    pub scanner_id: Option<u64>,
    /// If true, the schedule for the scan is enabled
    pub enabled: bool,
    /// When to launch the scan. (i.e. ON_DEMAND, DAILY, WEEKLY, MONTHLY, YEARLY)
    pub launch: Option<String>,
    /// The starting time and date for the scan (i.e. YYYYMMDDTHHMMSS)
    pub starttime: Option<String>,
    /// Expects a semi-colon delimited string comprised of three values. The frequency (FREQ=ONCE or DAILY or WEEKLY or MONTHLY or YEARLY), the interval (INTERVAL=1 or 2 or 3 ... x), and the days of the week (BYDAY=SU,MO,TU,WE,TH,FR,SA). To create a scan that runs every three weeks on Monday Wednesday and Friday the string would be 'FREQ=WEEKLY;INTERVAL=3;BYDAY=MO,WE,FR'
    pub rrules: Option<String>,
    /// The timezone for the scan schedule
    pub timezone: Option<String>,
    /// The list of targets to scan
    pub text_targets: String,
    /// The name of a file containing the list of targets to scan
    pub file_targets: Option<String>,
    /// A comma separated list of accounts who will recieve the email summary report
    pub emails: Option<String>,
    // /// An array containing permissions to apply to the scan
    // pub acls: Option<Vec<String>>>, // type isn't documented
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct UpdateScanRequest {
    pub uuid: Option<String>,
    pub settings: ScanSettingsUpdate,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct UpdateScanResponse {
    pub uuid: String,
    // TODO: settings
}

#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
pub struct ScanSettingsUpdate {
    /// The name of the scan
    pub name: Option<String>,
    /// The description of the scan
    pub description: Option<String>,
    /// The unique id of the policy to use
    pub policy_id: Option<u64>,
    /// The unique id of the destination folder for the scan
    pub folder_id: Option<u64>,
    /// The unique id of the scanner to use
    pub scanner_id: Option<u64>,
    /// If true, the schedule for the scan is enabled
    pub enabled: bool,
    /// When to launch the scan. (i.e. ON_DEMAND, DAILY, WEEKLY, MONTHLY, YEARLY)
    pub launch: Option<String>,
    /// The starting time and date for the scan (i.e. YYYYMMDDTHHMMSS)
    pub starttime: Option<String>,
    /// Expects a semi-colon delimited string comprised of three values. The frequency (FREQ=ONCE or DAILY or WEEKLY or MONTHLY or YEARLY), the interval (INTERVAL=1 or 2 or 3 ... x), and the days of the week (BYDAY=SU,MO,TU,WE,TH,FR,SA). To create a scan that runs every three weeks on Monday Wednesday and Friday the string would be 'FREQ=WEEKLY;INTERVAL=3;BYDAY=MO,WE,FR'
    pub rrules: Option<String>,
    /// The timezone for the scan schedule
    pub timezone: Option<String>,
    // /// An array of target group IDs to scan
    // pub target_groups: Option<Vec<u64>>,
    // /// An array An array of agent group IDs to scan. Required if the scan is an agent scan
    // pub agent_groups: Option<Vec<u64>>,
    /// The list of targets to scan
    pub text_targets: String,
    /// The name of a file containing the list of targets to scan
    pub file_targets: Option<String>,
    /// A comma separated list of accounts who will recieve the email summary report
    pub emails: Option<String>,
    // /// An array containing permissions to apply to the scan
    // pub acls: Option<Vec<String>>>, // type isn't documented
}

#[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<V: VulnScanner>(&self, client: &V, interval: Duration, max_attempts: Option<u64>) -> Result<(), Error> {
        <ScanLaunchResponse as Waitable<V>>::wait(self, client, interval, max_attempts)
    }
}

impl<V: VulnScanner> Waitable<V> for ScanLaunchResponse {
    fn is_pending(&self, client: &V) -> 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<u64>,
    pub custom: u64,
    pub default_tag: u64,
    #[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: Option<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<V: VulnScanner>(&self, client: &V, interval: Duration, max_attempts: Option<u64>) -> Result<(), Error> {
        <ExportToken as Waitable<V>>::wait(self, client, interval, max_attempts)
    }

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

impl<V: VulnScanner> Waitable<V> for ExportToken {
    fn is_pending(&self, client: &V) -> 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"
    }
}