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
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate reqwest;

use std::collections::HashMap;

/// A set of scanning an URL
pub mod url;
/// A set of reporting domain
pub mod domain;
/// A set of repoting ip
pub mod ip;
/// A set of scanning a file
pub mod file;
/// A set of putting a comment
pub mod comment;

#[derive(Debug,Deserialize)]
pub struct CommentPutResponse {
    pub response_code: i32,
    pub verbose_msg: String
}

#[derive(Debug,Deserialize)]
pub struct Comment {
    pub date: String,
    pub comment: String
}

#[derive(Debug,Deserialize)]
pub struct CommentGetResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resource: String,
    pub comments: Vec<Comment>
}

#[derive(Debug,Deserialize)]
pub struct UrlScanResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub scan_id: Option<String>,
    pub scan_date: Option<String>,
    pub url: Option<String>,
    pub permalink: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct UrlReportResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resource: Option<String>,
    pub scan_id: Option<String>,
    pub scan_date: Option<String>,
    pub url: Option<String>,
    pub permalink: Option<String>,
    pub filescan_id: Option<String>,
    pub positives: Option<u32>,
    pub total: Option<u32>,
    pub scans: Option<HashMap<String, Scan>>
}

#[derive(Debug,Deserialize)]
pub struct Scan {
    pub detected: Option<bool>,
    pub version: Option<String>,
    pub result: Option<String>,
    pub update: Option<String>,
    pub detail: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct FileScanResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resource: Option<String>,
    pub scan_id: Option<String>,
    pub sha256: Option<String>,
    pub permalink: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct FileRescanResponse {
    pub response_code: i32,
    //pub verbose_msg: Option<String>,
    pub resource: Option<String>,
    pub scan_id: Option<String>,
    pub permalink: Option<String>,
    pub sha256: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct FileReportResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resource: Option<String>,
    pub scan_id: Option<String>,
    pub scan_date: Option<String>,
    pub md5: Option<String>,
    pub sha1: Option<String>,
    pub sha256: Option<String>,
    pub url: Option<String>,
    pub permalink: Option<String>,
    pub filescan_id: Option<String>,
    pub positives: Option<u32>,
    pub total: Option<u32>,
    pub scans: Option<HashMap<String, Scan>>
}

#[derive(Debug,Deserialize)]
pub struct ReportResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resource: Option<String>,
    pub scan_id: Option<String>,
    pub scan_date: Option<String>,
    pub url: Option<String>,
    pub permalink: Option<String>,
    pub filescan_id: Option<String>,
    pub positives: Option<u32>,
    pub total: Option<u32>,
    pub scans: Option<HashMap<String, Scan>>
}

#[derive(Debug,Deserialize)]
pub struct DomainResolutions {
    pub last_resolved: String,
    pub ip_address: String
}

#[derive(Debug,Deserialize)]
pub struct IpAddressResolutions {
    pub last_resolved: String,
    pub hostname: String
}

#[derive(Debug,Deserialize)]
pub struct DetectedUrls {
    pub url: String,
    pub positives: u32,
    pub total: u32,
    pub scan_date: String,
}

#[derive(Debug,Deserialize)]
pub struct ReferrerSample {
    pub date: Option<String>,
    pub positives: Option<i32>,
    pub total: Option<i32>,
    pub sha256: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct DomainReportResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub resolutions: Vec<DomainResolutions>,
    pub detected_urls: Vec<DetectedUrls>,
    pub subdomains: Vec<String>,
    pub categories: Vec<String>,
    //pub domain_siblings: Vec<String>,
    pub undetected_referrer_samples: Option<Vec<ReferrerSample>>,
    pub undetected_downloaded_samples: Option<Vec<ReferrerSample>>,
    pub detected_referrer_samples: Option<Vec<ReferrerSample>>,
    pub detected_downloaded_samples: Option<Vec<ReferrerSample>>,
    pub whois_timestamp: i32,
    pub whois: Option<String>
}

#[derive(Debug,Deserialize)]
pub struct IpAddressReportResponse {
    pub response_code: i32,
    pub verbose_msg: String,
    pub country: Option<String>,
    pub asn: Option<u64>,
    pub detected_downloaded_samples: Option<Vec<ReferrerSample>>,
    pub undetected_downloaded_samples: Option<Vec<ReferrerSample>>,
    pub resolutions: Vec<IpAddressResolutions>,
    pub detected_urls: Vec<DetectedUrls>,
}

#[derive(Copy, Clone)]
pub struct VtClient<'a> {
    api_key: &'a str,
    endpoint: &'a str
}
impl <'a>VtClient<'a> {
    pub fn new(api_key: &'a str) -> Self {
        VtClient{api_key: api_key, endpoint: "https://www.virustotal.com/vtapi/v2"}
    }
}