@@ -11,14 +11,7 @@ use tokio::time::timeout;
11
11
use hickory_resolver:: config:: { ResolverConfig , ResolverOpts } ;
12
12
use hickory_resolver:: AsyncResolver ;
13
13
14
- use super :: setting:: DEFAULT_USER_AGENT_FIREFOX ;
15
- #[ cfg( feature = "passive" ) ]
16
- use crate :: config:: URL_CRT ;
17
- #[ cfg( feature = "passive" ) ]
18
- use crate :: model:: CertEntry ;
19
14
use crate :: scan:: result:: ScanStatus ;
20
- #[ cfg( feature = "passive" ) ]
21
- use reqwest:: Url ;
22
15
23
16
/// Structure for domain scan
24
17
///
@@ -41,10 +34,6 @@ pub struct DomainScanner {
41
34
tx : Arc < Mutex < Sender < String > > > ,
42
35
/// Receiver for progress messaging
43
36
rx : Arc < Mutex < Receiver < String > > > ,
44
- /// Run passive scan
45
- pub passive : bool ,
46
- /// User-Agent for passive scan
47
- user_agent : String ,
48
37
}
49
38
50
39
impl DomainScanner {
@@ -60,8 +49,6 @@ impl DomainScanner {
60
49
scan_result : DomainScanResult :: new ( ) ,
61
50
tx : Arc :: new ( Mutex :: new ( tx) ) ,
62
51
rx : Arc :: new ( Mutex :: new ( rx) ) ,
63
- passive : false ,
64
- user_agent : DEFAULT_USER_AGENT_FIREFOX . to_string ( ) ,
65
52
} ;
66
53
Ok ( domain_scanner)
67
54
}
@@ -84,69 +71,31 @@ impl DomainScanner {
84
71
pub fn set_timeout ( & mut self , timeout : Duration ) {
85
72
self . timeout = timeout;
86
73
}
87
- /// Set active/passive scan (default is active)
88
- pub fn set_passive ( & mut self , passive : bool ) {
89
- self . passive = passive;
90
- }
91
- /// Set user-agent for passive scan
92
- pub fn set_user_agent ( & mut self , user_agent : String ) {
93
- self . user_agent = user_agent;
94
- }
95
74
async fn scan_domain ( & self ) -> Result < Vec < Domain > , ( ) > {
96
- if self . passive {
97
- #[ cfg( feature = "passive" ) ]
98
- match timeout (
99
- self . timeout ,
100
- scan_subdomain_passive (
101
- self . base_domain . clone ( ) ,
102
- & self . tx ,
103
- self . resolve_timeout ,
104
- self . concurrent_limit ,
105
- self . user_agent . clone ( ) ,
106
- ) ,
107
- )
108
- . await
109
- {
110
- Ok ( domains) => {
111
- return Ok ( domains) ;
112
- }
113
- Err ( _) => {
114
- return Err ( ( ) ) ;
115
- }
75
+ match timeout (
76
+ self . timeout ,
77
+ scan_subdomain (
78
+ self . base_domain . clone ( ) ,
79
+ self . word_list . clone ( ) ,
80
+ & self . tx ,
81
+ self . resolve_timeout ,
82
+ self . concurrent_limit ,
83
+ ) ,
84
+ )
85
+ . await
86
+ {
87
+ Ok ( domains) => {
88
+ return Ok ( domains) ;
116
89
}
117
- #[ cfg( not( feature = "passive" ) ) ]
118
- return Err ( ( ) ) ;
119
- } else {
120
- match timeout (
121
- self . timeout ,
122
- scan_subdomain (
123
- self . base_domain . clone ( ) ,
124
- self . word_list . clone ( ) ,
125
- & self . tx ,
126
- self . resolve_timeout ,
127
- self . concurrent_limit ,
128
- ) ,
129
- )
130
- . await
131
- {
132
- Ok ( domains) => {
133
- return Ok ( domains) ;
134
- }
135
- Err ( _) => {
136
- return Err ( ( ) ) ;
137
- }
90
+ Err ( _) => {
91
+ return Err ( ( ) ) ;
138
92
}
139
93
}
140
94
}
141
95
/// Run scan with current settings.
142
96
///
143
97
/// Results are stored in DomainScanner::scan_result
144
98
pub async fn run_scan ( & mut self ) {
145
- if self . passive && cfg ! ( not( feature = "passive" ) ) {
146
- self . scan_result . scan_status =
147
- ScanStatus :: Error ( String :: from ( "Passive scan not supported" ) ) ;
148
- return ;
149
- }
150
99
let start_time = Instant :: now ( ) ;
151
100
let res = self . scan_domain ( ) . await ;
152
101
match res {
@@ -190,7 +139,6 @@ async fn resolve_domain(host_name: String) -> Vec<IpAddr> {
190
139
ips
191
140
}
192
141
193
- #[ cfg( feature = "async" ) ]
194
142
#[ cfg( not( any( unix, target_os = "windows" ) ) ) ]
195
143
async fn resolve_domain ( host_name : String ) -> Vec < IpAddr > {
196
144
let mut ips: Vec < IpAddr > = vec ! [ ] ;
@@ -207,25 +155,6 @@ async fn resolve_domain(host_name: String) -> Vec<IpAddr> {
207
155
ips
208
156
}
209
157
210
- #[ cfg( feature = "passive" ) ]
211
- fn extract_domain ( target : String ) -> String {
212
- let mut domain_name: String = target;
213
- match domain_name. strip_prefix ( "*." ) {
214
- Some ( d) => {
215
- domain_name = d. to_string ( ) ;
216
- }
217
- None => { }
218
- }
219
- domain_name
220
- }
221
-
222
- #[ cfg( feature = "passive" ) ]
223
- fn is_subdomain ( domain : String , apex_domain : String ) -> bool {
224
- domain. contains ( & apex_domain)
225
- && domain. ends_with ( & apex_domain)
226
- && domain. len ( ) > apex_domain. len ( )
227
- }
228
-
229
158
async fn scan_subdomain (
230
159
base_domain : String ,
231
160
word_list : Vec < String > ,
@@ -279,124 +208,3 @@ async fn scan_subdomain(
279
208
}
280
209
result
281
210
}
282
-
283
- #[ cfg( feature = "passive" ) ]
284
- async fn scan_subdomain_passive (
285
- base_domain : String ,
286
- ptx : & Arc < Mutex < Sender < String > > > ,
287
- resolve_timeout : Duration ,
288
- concurrent_limit : usize ,
289
- user_agent : String ,
290
- ) -> Vec < Domain > {
291
- let mut result: Vec < Domain > = vec ! [ ] ;
292
- let scan_results: Arc < Mutex < Vec < Domain > > > = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
293
- let mut certs: Vec < CertEntry > = vec ! [ ] ;
294
- //"https://crt.sh/?dNSName=example.com&output=json"
295
- let url = match Url :: parse_with_params (
296
- URL_CRT ,
297
- & [
298
- ( "dNSName" , base_domain. clone ( ) . as_str ( ) ) ,
299
- ( "output" , "json" ) ,
300
- ] ,
301
- ) {
302
- Ok ( url) => url,
303
- Err ( e) => {
304
- println ! ( "{}" , e) ;
305
- return result;
306
- }
307
- } ;
308
- let client = reqwest:: Client :: builder ( )
309
- . timeout ( Duration :: from_secs ( 60 ) )
310
- . build ( )
311
- . expect ( "failed to build HTTP reqest client" ) ;
312
- let res = client
313
- . get ( url)
314
- . header ( reqwest:: header:: USER_AGENT , user_agent)
315
- . send ( )
316
- . await ;
317
- match res {
318
- Ok ( r) => {
319
- if r. status ( ) . is_success ( ) {
320
- match r. text ( ) . await {
321
- Ok ( res_text) => {
322
- let certs_json: serde_json:: Value = serde_json:: from_str ( res_text. as_str ( ) )
323
- . unwrap_or ( serde_json:: json!( { } ) ) ;
324
- if certs_json. is_array ( ) {
325
- let cert_array = certs_json. as_array ( ) . unwrap ( ) ;
326
- for cert in cert_array {
327
- match serde_json:: to_string ( cert) {
328
- Ok ( cert) => {
329
- let cert: CertEntry =
330
- match serde_json:: from_str ( cert. as_str ( ) ) {
331
- Ok ( cert) => cert,
332
- Err ( _) => continue ,
333
- } ;
334
- certs. push ( cert) ;
335
- }
336
- Err ( _) => { }
337
- }
338
- }
339
- }
340
- }
341
- Err ( _) => { }
342
- } ;
343
- }
344
- }
345
- Err ( _) => { }
346
- }
347
- let mut target_domains: Vec < String > = vec ! [ ] ;
348
- for cert in certs {
349
- let domain_name: String = extract_domain ( cert. common_name ) ;
350
- if is_subdomain ( domain_name. clone ( ) , base_domain. clone ( ) )
351
- && !target_domains. contains ( & domain_name)
352
- {
353
- target_domains. push ( domain_name) ;
354
- }
355
- let name_values: Vec < & str > = cert. name_value . trim ( ) . split ( "\n " ) . collect ( ) ;
356
- for value in name_values {
357
- let name: String = extract_domain ( value. to_string ( ) ) ;
358
- if is_subdomain ( name. clone ( ) , base_domain. clone ( ) ) && !target_domains. contains ( & name) {
359
- target_domains. push ( name) ;
360
- }
361
- }
362
- }
363
- let results = stream:: iter ( target_domains)
364
- . map ( |domain| async move {
365
- let mut d: Domain = Domain {
366
- domain_name : domain. clone ( ) ,
367
- ips : vec ! [ ] ,
368
- } ;
369
- match timeout ( resolve_timeout, resolve_domain ( domain. clone ( ) ) ) . await {
370
- Ok ( ips) => {
371
- d. ips = ips;
372
- match ptx. lock ( ) {
373
- Ok ( lr) => match lr. send ( domain) {
374
- Ok ( _) => { }
375
- Err ( _) => { }
376
- } ,
377
- Err ( _) => { }
378
- }
379
- }
380
- Err ( _) => match ptx. lock ( ) {
381
- Ok ( lr) => match lr. send ( domain) {
382
- Ok ( _) => { }
383
- Err ( _) => { }
384
- } ,
385
- Err ( _) => { }
386
- } ,
387
- }
388
- d
389
- } )
390
- . buffer_unordered ( concurrent_limit) ;
391
- results
392
- . for_each ( |domain| async {
393
- if domain. ips . len ( ) > 0 {
394
- scan_results. lock ( ) . unwrap ( ) . push ( domain) ;
395
- }
396
- } )
397
- . await ;
398
- for domain in scan_results. lock ( ) . unwrap ( ) . iter ( ) {
399
- result. push ( domain. to_owned ( ) ) ;
400
- }
401
- result
402
- }
0 commit comments