@@ -205,6 +205,7 @@ def cmd_hosts(*args)
205
205
mode = :search
206
206
delete_count = 0
207
207
208
+ rhosts = [ ]
208
209
host_ranges = [ ]
209
210
search_term = nil
210
211
@@ -241,7 +242,6 @@ def cmd_hosts(*args)
241
242
output = args . shift
242
243
when '-R' , '--rhosts'
243
244
set_rhosts = true
244
- rhosts = [ ]
245
245
when '-S' , '--search'
246
246
search_term = /#{ args . shift } /nmi
247
247
@@ -280,12 +280,6 @@ def cmd_hosts(*args)
280
280
range . each do |address |
281
281
host = framework . db . find_or_create_host ( :host => address )
282
282
print_status ( "Time: #{ host . created_at } Host: host=#{ host . address } " )
283
- if set_rhosts
284
- # only unique addresses
285
- addr = ( host . scope ? host . address + '%' + host . scope : host . address )
286
- rhosts << addr
287
- end
288
- rhosts . uniq!
289
283
end
290
284
end
291
285
return
@@ -326,7 +320,6 @@ def cmd_hosts(*args)
326
320
addr = ( host . scope ? host . address + '%' + host . scope : host . address )
327
321
rhosts << addr
328
322
end
329
- rhosts . uniq!
330
323
if mode == :delete
331
324
host . destroy
332
325
delete_count += 1
@@ -346,7 +339,7 @@ def cmd_hosts(*args)
346
339
347
340
# Finally, handle the case where the user wants the resulting list
348
341
# of hosts to go into RHOSTS.
349
- set_rhosts_from_addrs ( rhosts ) if set_rhosts
342
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
350
343
print_status ( "Deleted #{ delete_count } hosts" ) if delete_count > 0
351
344
}
352
345
##
@@ -370,10 +363,11 @@ def cmd_services(*args)
370
363
default_columns = ::Mdm ::Service . column_names . sort
371
364
default_columns . delete_if { |v | ( v [ -2 , 2 ] == "id" ) }
372
365
373
- host_ranges = [ ]
374
- port_ranges = [ ]
366
+ host_ranges = [ ]
367
+ port_ranges = [ ]
368
+ rhosts = [ ]
375
369
delete_count = 0
376
- search_term = nil
370
+ search_term = nil
377
371
378
372
# option parsing
379
373
while ( arg = args . shift )
@@ -424,7 +418,6 @@ def cmd_services(*args)
424
418
output_file = ::File . expand_path ( output_file )
425
419
when '-R' , '--rhosts'
426
420
set_rhosts = true
427
- rhosts = [ ]
428
421
when '-S' , '--search'
429
422
search_term = /#{ args . shift } /nmi
430
423
@@ -514,7 +507,6 @@ def cmd_services(*args)
514
507
addr = ( host . scope ? host . address + '%' + host . scope : host . address )
515
508
rhosts << addr
516
509
end
517
- rhosts . uniq!
518
510
519
511
if ( mode == :delete )
520
512
service . destroy
@@ -534,7 +526,7 @@ def cmd_services(*args)
534
526
535
527
# Finally, handle the case where the user wants the resulting list
536
528
# of hosts to go into RHOSTS.
537
- set_rhosts_from_addrs ( rhosts ) if set_rhosts
529
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
538
530
print_status ( "Deleted #{ delete_count } services" ) if delete_count > 0
539
531
540
532
}
@@ -685,6 +677,7 @@ def cmd_creds(*args)
685
677
686
678
host_ranges = [ ]
687
679
port_ranges = [ ]
680
+ rhosts = [ ]
688
681
svcs = [ ]
689
682
search_term = nil
690
683
@@ -738,7 +731,6 @@ def cmd_creds(*args)
738
731
end
739
732
when "-R"
740
733
set_rhosts = true
741
- rhosts = [ ]
742
734
when '-S' , '--search'
743
735
search_term = /#{ args . shift } /nmi
744
736
when "-u" , "--user"
@@ -835,7 +827,6 @@ def cmd_creds(*args)
835
827
addr = ( cred . service . host . scope ? cred . service . host . address + '%' + cred . service . host . scope : cred . service . host . address )
836
828
rhosts << addr
837
829
end
838
- rhosts . uniq!
839
830
creds_returned += 1
840
831
end
841
832
@@ -848,7 +839,7 @@ def cmd_creds(*args)
848
839
print_status ( "Wrote services to #{ output_file } " )
849
840
end
850
841
851
- set_rhosts_from_addrs ( rhosts ) if set_rhosts
842
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
852
843
print_status "Found #{ creds_returned } credential#{ creds_returned == 1 ? "" : "s" } ."
853
844
}
854
845
end
@@ -879,6 +870,7 @@ def cmd_notes(*args)
879
870
set_rhosts = false
880
871
881
872
host_ranges = [ ]
873
+ rhosts = [ ]
882
874
search_term = nil
883
875
884
876
while ( arg = args . shift )
@@ -902,7 +894,6 @@ def cmd_notes(*args)
902
894
types = typelist . strip ( ) . split ( "," )
903
895
when '-R' , '--rhosts'
904
896
set_rhosts = true
905
- rhosts = [ ]
906
897
when '-S' , '--search'
907
898
search_term = /#{ args . shift } /nmi
908
899
when '-h' , '--help'
@@ -962,7 +953,6 @@ def cmd_notes(*args)
962
953
addr = ( host . scope ? host . address + '%' + host . scope : host . address )
963
954
rhosts << addr
964
955
end
965
- rhosts . uniq!
966
956
end
967
957
if ( note . service )
968
958
name = ( note . service . name ? note . service . name : "#{ note . service . port } /#{ note . service . proto } " )
@@ -978,7 +968,7 @@ def cmd_notes(*args)
978
968
979
969
# Finally, handle the case where the user wants the resulting list
980
970
# of hosts to go into RHOSTS.
981
- set_rhosts_from_addrs ( rhosts ) if set_rhosts
971
+ set_rhosts_from_addrs ( rhosts . uniq ) if set_rhosts
982
972
983
973
print_status ( "Deleted #{ delete_count } note#{ delete_count == 1 ? "" : "s" } " ) if delete_count > 0
984
974
}
@@ -1483,7 +1473,7 @@ def cmd_db_rebuild_cache
1483
1473
print_error ( "The database is not connected" )
1484
1474
return
1485
1475
end
1486
-
1476
+
1487
1477
print_status ( "Purging and rebuilding the module cache in the background..." )
1488
1478
framework . threads . spawn ( "ModuleCacheRebuild" , true ) do
1489
1479
framework . db . purge_all_module_details
@@ -1714,4 +1704,3 @@ def each_host_range_chunk(host_ranges, &block)
1714
1704
end
1715
1705
end
1716
1706
end
1717
-
0 commit comments