Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/parser/nmap_xml_spec.rb
Views: 11655
# -*- coding:binary -*-123xml = '4<?xml version="1.0" ?>5<?xml-stylesheet href="/usr/share/nmap/nmap.xsl" type="text/xsl"?>6<!-- 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 -->7<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">8<scaninfo type="connect" protocol="tcp" numservices="2" services="22,80" />9<verbose level="0" />10<debugging level="0" />11<host starttime="1258080887" endtime="1258080893"><status state="up" reason="syn-ack"/>12<address addr="192.168.0.1" addrtype="ipv4" />13<hostnames><hostname name="localhost" type="PTR" /></hostnames>14<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,
SF:27,"SSH-2\.0-OpenSSH_5\.1p1\x20Debian-5ubuntu1\r\n");" method="probed" conf="10" /></port>15<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>16</ports>17<times srtt="119" rttvar="2882" to="50000" />18</host>19<runstats><finished time="1258080893" timestr="Thu Nov 12 19:54:53 2009"/><hosts up="1" down="0" total="1" />20<!-- Nmap done at Thu Nov 12 19:54:53 2009; 1 IP address (1 host up) scanned in 6.43 seconds -->21</runstats></nmaprun>22'2324RSpec.describe Rex::Parser::NmapXMLStreamParser do25parser = Rex::Parser::NmapXMLStreamParser.new26total_hosts = 027parser.on_found_host = Proc.new { |host|28total_hosts += 129it "should yield a host" do30expect(host).not_to be_nil31end32it "should populate the host with proper keys" do33expect(host).to have_key("status")34expect(host).to have_key("ports")35expect(host).to have_key("addrs")36expect(host["ports"]).to be_a(Array)37expect(host["addrs"]).to be_a(Hash)38end39it "should find the address" do40expect(host["addrs"].keys.length).to eq 141expect(host["addrs"]).to have_key("ipv4")42expect(host["addrs"]["ipv4"]).to eq "192.168.0.1"43end44}45REXML::Document.parse_stream(StringIO.new(xml), parser)46it "should have found exactly one host" do47expect(total_hosts).to eq 148end49end50515253