@@ -14,10 +14,6 @@ class Db
14
14
require 'tempfile'
15
15
16
16
include Msf ::Ui ::Console ::CommandDispatcher
17
-
18
- # TODO: Not thrilled about including this entire module for just store_local.
19
- include Msf ::Auxiliary ::Report
20
-
21
17
include Metasploit ::Credential ::Creation
22
18
23
19
#
@@ -1752,15 +1748,14 @@ def cmd_db_nmap(*args)
1752
1748
return unless active?
1753
1749
::ActiveRecord ::Base . connection_pool . with_connection {
1754
1750
if ( args . length == 0 )
1755
- print_status ( "Usage: db_nmap [nmap options]" )
1751
+ print_status ( "Usage: db_nmap [--save | [--help | -h]] [ nmap options]" )
1756
1752
return
1757
1753
end
1758
- save = false
1759
1754
arguments = [ ]
1760
1755
while ( arg = args . shift )
1761
1756
case arg
1762
- when 'save'
1763
- save = active?
1757
+ when '-- save'
1758
+ save = true
1764
1759
when '--help' , '-h'
1765
1760
cmd_db_nmap_help
1766
1761
return
@@ -1778,55 +1773,47 @@ def cmd_db_nmap(*args)
1778
1773
return
1779
1774
end
1780
1775
1781
- fd = Tempfile . new ( 'dbnmap' )
1782
- fd . binmode
1783
-
1784
- fo = Tempfile . new ( 'dbnmap' )
1785
- fo . binmode
1786
-
1787
- # When executing native Nmap in Cygwin, expand the Cygwin path to a Win32 path
1788
- if ( Rex ::Compat . is_cygwin and nmap =~ /cygdrive/ )
1789
- # Custom function needed because cygpath breaks on 8.3 dirs
1790
- tout = Rex ::Compat . cygwin_to_win32 ( fd . path )
1791
- fout = Rex ::Compat . cygwin_to_win32 ( fo . path )
1792
- arguments . push ( '-oX' , tout )
1793
- arguments . push ( '-oN' , fout )
1794
- else
1795
- arguments . push ( '-oX' , fd . path )
1796
- arguments . push ( '-oN' , fo . path )
1797
- end
1776
+ fd = Rex ::Quickfile . new ( [ 'msf-db-nmap-' , '.xml' ] , Msf ::Config . local_directory )
1798
1777
1799
1778
begin
1800
- nmap_pipe = :: Open3 :: popen3 ( [ nmap , 'nmap' ] , * arguments )
1801
- temp_nmap_threads = [ ]
1802
- temp_nmap_threads << framework . threads . spawn ( "db_nmap-Stdout" , false , nmap_pipe [ 1 ] ) do | np_1 |
1803
- np_1 . each_line do | nmap_out |
1804
- next if nmap_out . strip . empty?
1805
- print_status ( "Nmap: #{ nmap_out . strip } " )
1806
- end
1779
+ # When executing native Nmap in Cygwin, expand the Cygwin path to a Win32 path
1780
+ if ( Rex :: Compat . is_cygwin and nmap =~ /cygdrive/ )
1781
+ # Custom function needed because cygpath breaks on 8.3 dirs
1782
+ tout = Rex :: Compat . cygwin_to_win32 ( fd . path )
1783
+ arguments . push ( '-oX' , tout )
1784
+ else
1785
+ arguments . push ( '-oX' , fd . path )
1807
1786
end
1808
1787
1809
- temp_nmap_threads << framework . threads . spawn ( "db_nmap-Stderr" , false , nmap_pipe [ 2 ] ) do |np_2 |
1810
- np_2 . each_line do |nmap_err |
1811
- next if nmap_err . strip . empty?
1812
- print_status ( "Nmap: '#{ nmap_err . strip } '" )
1788
+ begin
1789
+ nmap_pipe = ::Open3 ::popen3 ( [ nmap , 'nmap' ] , *arguments )
1790
+ temp_nmap_threads = [ ]
1791
+ temp_nmap_threads << framework . threads . spawn ( "db_nmap-Stdout" , false , nmap_pipe [ 1 ] ) do |np_1 |
1792
+ np_1 . each_line do |nmap_out |
1793
+ next if nmap_out . strip . empty?
1794
+ print_status ( "Nmap: #{ nmap_out . strip } " )
1795
+ end
1796
+ end
1797
+
1798
+ temp_nmap_threads << framework . threads . spawn ( "db_nmap-Stderr" , false , nmap_pipe [ 2 ] ) do |np_2 |
1799
+ np_2 . each_line do |nmap_err |
1800
+ next if nmap_err . strip . empty?
1801
+ print_status ( "Nmap: '#{ nmap_err . strip } '" )
1802
+ end
1813
1803
end
1814
- end
1815
1804
1816
- temp_nmap_threads . map { |t | t . join rescue nil }
1817
- nmap_pipe . each { |p | p . close rescue nil }
1818
- rescue ::IOError
1819
- end
1805
+ temp_nmap_threads . map { |t | t . join rescue nil }
1806
+ nmap_pipe . each { |p | p . close rescue nil }
1807
+ rescue ::IOError
1808
+ end
1820
1809
1821
- fo . close ( true )
1822
- framework . db . import_nmap_xml_file ( :filename => fd . path )
1810
+ framework . db . import_nmap_xml_file ( :filename => fd . path )
1823
1811
1824
- if save
1825
- fd . rewind
1826
- saved_path = report_store_local ( "nmap.scan.xml" , "text/xml" , fd . read , "nmap_ #{ Time . now . utc . to_i } " )
1827
- print_status ( "Saved NMAP XML results to #{ saved_path } " )
1812
+ print_status ( "Saved NMAP XML results to #{ fd . path } " ) if save
1813
+ ensure
1814
+ fd . close
1815
+ fd . unlink unless save
1828
1816
end
1829
- fd . close ( true )
1830
1817
}
1831
1818
end
1832
1819
@@ -1869,13 +1856,6 @@ def cmd_db_nmap_tabs(str, words)
1869
1856
tabs
1870
1857
end
1871
1858
1872
- #
1873
- # Store some locally-generated data as a file, similiar to store_loot.
1874
- #
1875
- def report_store_local ( ltype = nil , ctype = nil , data = nil , filename = nil )
1876
- store_local ( ltype , ctype , data , filename )
1877
- end
1878
-
1879
1859
#
1880
1860
# Database management
1881
1861
#
0 commit comments