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
use std::time::{Duration, Instant};
use std::collections::HashMap;
mod uri;
pub type NewUriScannerResult = Result<UriScanner, String>;
pub struct UriScanner {
base_uri: String,
word_list: Vec<String>,
timeout: Duration,
scan_result: UriScanResult,
}
#[derive(Clone)]
pub struct UriScanResult {
pub responses: HashMap<String, String>,
pub scan_time: Duration,
}
impl UriScanner{
pub fn new() -> NewUriScannerResult {
let ini_scan_result = UriScanResult{
responses: HashMap::new(),
scan_time: Duration::from_millis(1),
};
let uri_scanner = UriScanner{
base_uri: String::new(),
word_list: vec![],
timeout: Duration::from_millis(30000),
scan_result: ini_scan_result,
};
Ok(uri_scanner)
}
pub fn set_base_uri(&mut self, base_uri: String) {
self.base_uri = base_uri;
}
pub fn add_word(&mut self, word: String) {
self.word_list.push(word);
}
pub fn set_timeout(&mut self, timeout: Duration){
self.timeout = timeout;
}
pub async fn run_scan(&mut self){
let start_time = Instant::now();
self.scan_result.responses = uri::scan_uri(&self.base_uri, &self.word_list).await;
self.scan_result.scan_time = Instant::now().duration_since(start_time);
}
pub fn get_result(&mut self) -> UriScanResult{
return self.scan_result.clone();
}
}