请选择 进入手机版 | 继续访问电脑版

女黑客安全网-网络安全培训学院-渗透测试零基础入门学习

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1659|回复: 0

关于nmap 导出结果为xml的处理办法

[复制链接]

88

主题

99

帖子

789

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
789
发表于 2017-4-27 10:51:04 | 显示全部楼层 |阅读模式
      在一家公司做项目,同事把nmap结果导出为xml,因为要对同一端口,如21进行弱口令探测,需要整理成excel表格,ip:port形式
      xml格式如下,感觉很乱
  1. <host starttime="1492997851" endtime="1492998179"><status state="up" reason="echo-reply" reason_ttl="61"/>
  2. <address addr="192.168.0.133" addrtype="ipv4"/>
  3. <hostnames>
  4. </hostnames>
  5. <ports><extraports state="filtered" count="65522">
  6. <extrareasons reason="no-responses" count="65522"/>
  7. </extraports>
  8. <port protocol="tcp" portid="22"><state state="closed" reason="reset" reason_ttl="61"/><service name="ssh" method="table" conf="3"/></port>
  9. <port protocol="tcp" portid="80"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="http" product="VMware ESXi Server httpd" hostname="E1-VM001.ufh.com" method="probed" conf="10"><cpe>cpe:/o:vmware:esxi</cpe></service></port>
  10. <port protocol="tcp" portid="427"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="svrloc" method="table" conf="3"/></port>
  11. <port protocol="tcp" portid="443"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="http" product="VMware ESXi Server httpd" tunnel="ssl" method="probed" conf="10"><cpe>cpe:/o:vmware:esxi</cpe></service></port>
  12. <port protocol="tcp" portid="902"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="vmware-auth" product="VMware Authentication Daemon" version="1.10" extrainfo="Uses VNC, SOAP" tunnel="ssl" method="probed" conf="10"/></port>
  13. <port protocol="tcp" portid="2233"><state state="closed" reason="reset" reason_ttl="61"/><service name="infocrypt" method="table" conf="3"/></port>
  14. <port protocol="tcp" portid="5988"><state state="closed" reason="reset" reason_ttl="61"/><service name="wbem-http" method="table" conf="3"/></port>
  15. <port protocol="tcp" portid="5989"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="wbem" product="SBLIM Small Footprint CIM Broker" tunnel="ssl" method="probed" conf="10"><cpe>cpe:/a:standards_based_linux_instrumentation_project:sfcb</cpe></service></port>
  16. <port protocol="tcp" portid="8000"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="http-alt" method="table" conf="3"/></port>
  17. <port protocol="tcp" portid="8080"><state state="closed" reason="reset" reason_ttl="61"/><service name="http-proxy" method="table" conf="3"/></port>
  18. <port protocol="tcp" portid="8100"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="tcpwrapped" method="probed" conf="8"/></port>
  19. <port protocol="tcp" portid="8182"><state state="open" reason="syn-ack" reason_ttl="61"/><service name="vmware-fdm" tunnel="ssl" method="table" conf="3"/></port>
  20. <port protocol="tcp" portid="8300"><state state="closed" reason="reset" reason_ttl="61"/><service name="tmi" method="table" conf="3"/></port>
  21. </ports>
  22. <times srtt="1866" rttvar="800" to="100000"/>
复制代码
使用php语言,按行读取文件
  1. <?php
  2. $file_path = "scan/ip2-result.xml";
  3. $file = fopen($file_path, "r");

  4. //输出文本中所有的行,直到文件结束为止。
  5. global $ip;
  6. while(! feof($file))
  7. {
  8.     $line= fgets($file);//fgets()函数从文件指针中读取一行'
  9.     //echo $line;
  10.     preg_match("/address addr=\"(.+)\" addrtype=\"ipv4\"/", $line,$ips);//匹配IP
  11.     preg_match("/<port protocol=\"tcp\" portid=\"(.+)\"><state state=\"open\".+<service name=\"(\S+)\" /", $line,$port);//匹配端口

  12.     if ($ips) {
  13.         $ip = $ips;
  14.     }
  15.     if ($port) {
  16.         echo $ip[1].":".$port[1].":".$port[2];
  17.         echo '<br>';
  18.     }
  19. }
  20. fclose($file);
  21. ?>
复制代码
输出结果如图:
QQ图片20170427105048.png





必火网络安全培训,北京实地培训,月月有开班,零基础入门,四个月打造渗透高手。
详情请加微信:18622800700,手机微信同号。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|女黑客安全网-网络安全培训学院-渗透测试零基础入门学习 ( 津ICP备17008032号-3

GMT+8, 2018-9-21 21:25 , Processed in 0.143287 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表