2013-04-17 19:26:16 +00:00
# -*- coding:binary -*-
2009-11-18 06:15:45 +00:00
require 'rex/parser/nmap_xml'
xml = '
< ? xml version = " 1.0 " ?>
< ? xml - stylesheet href = " /usr/share/nmap/nmap.xsl " type = " text/xsl " ?>
< ! - - Nmap 4 . 76 scan initiated Thu Nov 12 19 : 54 : 47 2009 as : nmap - p22 , 80 - A - oX nmap . xml - T5 192 . 168 . 0 . 1 - - >
< nmaprun scanner = " nmap " args = " nmap -p22,80 -A -oX nmap.xml -T5 192.168.0.1 " start = " 1258080887 " startstr = " Thu Nov 12 19:54:47 2009 " version = " 4.76 " xmloutputversion = " 1.02 " >
< scaninfo type = " connect " protocol = " tcp " numservices = " 2 " services = " 22,80 " / >
< verbose level = " 0 " / >
< debugging level = " 0 " / >
< host starttime = " 1258080887 " endtime = " 1258080893 " > < status state = " up " reason = " syn-ack " / >
< address addr = " 192.168.0.1 " addrtype = " ipv4 " / >
< hostnames > < hostname name = " localhost " type = " PTR " / >< / hostnames >
< ports > < port protocol = " tcp " portid = " 22 " > < state state = " open " reason = " syn-ack " reason_ttl = " 0 " / > < service name = " ssh " extrainfo = " protocol 2.0 " servicefp = " SF-Port22-TCP:V=4.76%I=7%D=11/12%Time=4AFCCA7D%P=i686-pc-linux-gnu%r(NULL,& # xa;SF:27,"SSH-2 \ .0-OpenSSH_5 \ .1p1 \x20 Debian-5ubuntu1 \r \n "); " method = " probed " conf = " 10 " / >< / port >
< port protocol = " tcp " portid = " 80 " > < state state = " open " reason = " syn-ack " reason_ttl = " 0 " / > < service name = " http " product = " Apache httpd " version = " 2.2.11 " extrainfo = " (Ubuntu) PHP/5.2.6-3ubuntu4.2 with Suhosin-Patch " method = " probed " conf = " 10 " / >< / port >
< / ports>
< times srtt = " 119 " rttvar = " 2882 " to = " 50000 " / >
< / host>
< runstats > < finished time = " 1258080893 " timestr = " Thu Nov 12 19:54:53 2009 " / > < hosts up = " 1 " down = " 0 " total = " 1 " / >
< ! - - Nmap done at Thu Nov 12 19 : 54 : 53 2009 ; 1 IP address ( 1 host up ) scanned in 6 . 43 seconds - - >
< / runstats>< /nm aprun >
'
2015-10-16 20:57:04 +00:00
RSpec . describe Rex :: Parser :: NmapXMLStreamParser do
2013-09-30 18:47:53 +00:00
parser = Rex :: Parser :: NmapXMLStreamParser . new
total_hosts = 0
parser . on_found_host = Proc . new { | host |
total_hosts += 1
it " should yield a host " do
2015-10-21 13:14:48 +00:00
expect ( host ) . not_to be_nil
2013-09-30 18:47:53 +00:00
end
it " should populate the host with proper keys " do
2015-10-20 19:37:18 +00:00
expect ( host ) . to have_key ( " status " )
expect ( host ) . to have_key ( " ports " )
expect ( host ) . to have_key ( " addrs " )
expect ( host [ " ports " ] ) . to be_a ( Array )
expect ( host [ " addrs " ] ) . to be_a ( Hash )
2013-09-30 18:47:53 +00:00
end
it " should find the address " do
2015-10-20 16:30:38 +00:00
expect ( host [ " addrs " ] . keys . length ) . to eq 1
2015-10-20 19:37:18 +00:00
expect ( host [ " addrs " ] ) . to have_key ( " ipv4 " )
2015-10-20 16:30:38 +00:00
expect ( host [ " addrs " ] [ " ipv4 " ] ) . to eq " 192.168.0.1 "
2013-09-30 18:47:53 +00:00
end
}
REXML :: Document . parse_stream ( StringIO . new ( xml ) , parser )
it " should have found exactly one host " do
2015-10-20 16:30:38 +00:00
expect ( total_hosts ) . to eq 1
2013-09-30 18:47:53 +00:00
end
2009-11-18 06:15:45 +00:00
end