PageRenderTime 36ms CodeModel.GetById 13ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/lib/rex/parser/nmap_xml_spec.rb

https://github.com/debbiemezyene/metasploit-framework
Ruby | 52 lines | 47 code | 4 blank | 1 comment | 3 complexity | 80e8a9efea018ba112212a2d46367286 MD5 | raw file
 1# -*- coding:binary -*-
 2
 3require 'rex/parser/nmap_xml'
 4
 5xml = '
 6<?xml version="1.0" ?>
 7<?xml-stylesheet href="/usr/share/nmap/nmap.xsl" type="text/xsl"?>
 8<!-- 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 -->
 9<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">
10<scaninfo type="connect"  protocol="tcp" numservices="2" services="22,80" />
11<verbose level="0" />
12<debugging level="0" />
13<host starttime="1258080887" endtime="1258080893"><status state="up" reason="syn-ack"/>
14<address addr="192.168.0.1" addrtype="ipv4" />
15<hostnames><hostname name="localhost" type="PTR" /></hostnames>
16<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,&quot;SSH-2\.0-OpenSSH_5\.1p1\x20Debian-5ubuntu1\r\n&quot;);" method="probed" conf="10" /></port>
17<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>
18</ports>
19<times srtt="119" rttvar="2882" to="50000" />
20</host>
21<runstats><finished time="1258080893" timestr="Thu Nov 12 19:54:53 2009"/><hosts up="1" down="0" total="1" />
22<!-- Nmap done at Thu Nov 12 19:54:53 2009; 1 IP address (1 host up) scanned in 6.43 seconds -->
23</runstats></nmaprun>
24'
25
26describe Rex::Parser::NmapXMLStreamParser do
27  parser = Rex::Parser::NmapXMLStreamParser.new
28  total_hosts = 0
29  parser.on_found_host = Proc.new { |host|
30    total_hosts += 1
31    it "should yield a host" do
32      host.should_not be_nil
33    end
34    it "should populate the host with proper keys" do
35      host.should have_key("status")
36      host.should have_key("ports")
37      host.should have_key("addrs")
38      host["ports"].should be_a(Array)
39      host["addrs"].should be_a(Hash)
40    end
41    it "should find the address" do
42      host["addrs"].keys.length.should == 1
43      host["addrs"].should have_key("ipv4")
44      host["addrs"]["ipv4"].should == "192.168.0.1"
45    end
46  }
47  REXML::Document.parse_stream(StringIO.new(xml), parser)
48  it "should have found exactly one host" do
49    total_hosts.should == 1
50  end
51end
52