【小白学习记】XSLT 模板美化nmap输出报告

Nmap 扫描与报告美化

简介

Nmap(Network Mapper)是一款开源的网络探测和安全审核工具,它主要用于扫描IP地址和端口,检测网络上的设备、开放的端口以及运行的服务。Nmap是网络管理员评估网络系统安全性的重要工具。

扫描并输出 XML 文档

首先使用 Nmap 进行网络扫描,并将详细结果输出到 XML 格式的文档中。

nmap --script=vuln -oX C:\phpStudy\WWW\141.xml 192.168.52.141

使用 XSLT 模板进行报告美化

mode.xsl 是一个 XSLT 模板文件,用于将 Nmap 生成的 XML 报告转换为更易于阅读的 HTML 格式。模板内容如下:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/>
  <xsl:template match="/">
    <html lang="en">
      <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css"/>
        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
        <style>
          .target:before {
            content: "";
            display: block;
            height: 50px;
            margin: -20px 0 0;
          }
          @media only screen and (min-width:1900px) {
            .container {
              width: 1800px;
              }
          }
          .footer {
            margin-top:60px;
            padding-top:60px;
            width: 100%;
            height: 180px;
            background-color: #f5f5f5;
          }
        .navbar-right {
		 float: right!important;
		 margin-right: -15px;
	   }
        </style>
        <title>Nmap Scanner 扫描报告</title>
      </head>
      <body>
	  <!--导航栏-->
        <nav class="navbar navbar-default navbar-fixed-top">
          <div class="container-fluid">
            <div class="navbar-header">
              <a class="navbar-brand" href="#"><span class="glyphicon glyphicon-home"></span></a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
              <ul class="nav navbar-nav">
                <li><a href="#summary">概要信息</a></li>
                <li><a href="#scannedhosts">主机信息</a></li>
                <li><a href="#onlinehosts">在线主机</a></li>
                <li><a href="#openservices">服务信息</a></li>
              </ul>
            </div>
          </div>
        </nav>
 
	 <!--内容区-->
        <div class="container">		
		 <h2 id="summary" class="target">扫描概要</h2>
          <div class="target">
			<p >Nmap 版本:<xsl:value-of select="/nmaprun/@version"/></p>
            <p >Nmap命令:<xsl:value-of select="/nmaprun/@args"/></p>
			<p >开始时间:<xsl:value-of select="/nmaprun/@startstr"/> </p>
			<p >结束时间:<xsl:value-of select="/nmaprun/runstats/finished/@timestr"/></p>
          </div>
		  
          <h2 id="scannedhosts" class="target">主机信息<xsl:if test="/nmaprun/runstats/hosts/@down > 1024"><small> (offline hosts are hidden)</small></xsl:if></h2>
          <div class="table-responsive">
            <table id="table-overview" class="table table-striped dataTable" role="grid">
              <thead>
                <tr>
                  <th>状态</th>
                  <th>IP</th>
                  <th>主机名</th>
                  <th>开放TCP端口数</th>
                  <th>开放UDP端口数</th>
                </tr>
              </thead>
              <tbody>
                <xsl:choose>
                  <xsl:when test="/nmaprun/runstats/hosts/@down > 1024">
                    <xsl:for-each select="/nmaprun/host[status/@state='up']">
                      <tr>
                        <td><span class="label label-danger"><xsl:if test="status/@state='up'"><xsl:attribute name="class">label label-success</xsl:attribute></xsl:if><xsl:value-of select="status/@state"/></span></td>
                        <td><xsl:value-of select="address/@addr"/></td>
                        <td><xsl:value-of select="hostnames/hostname/@name"/></td>
                        <td><xsl:value-of select="count(ports/port[state/@state='open' and @protocol='tcp'])"/></td>
                        <td><xsl:value-of select="count(ports/port[state/@state='open' and @protocol='udp'])"/></td>
                      </tr>
                    </xsl:for-each>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:for-each select="/nmaprun/host">
                      <tr>
                        <td><span class="label label-danger"><xsl:if test="status/@state='up'"><xsl:attribute name="class">label label-success</xsl:attribute></xsl:if><xsl:value-of select="status/@state"/></span></td>
                        <td><xsl:value-of select="address/@addr"/></td>
                        <td><xsl:value-of select="hostnames/hostname/@name"/></td>
                        <td><xsl:value-of select="count(ports/port[state/@state='open' and @protocol='tcp'])"/></td>
                        <td><xsl:value-of select="count(ports/port[state/@state='open' and @protocol='udp'])"/></td>
                      </tr>
                    </xsl:for-each>
                  </xsl:otherwise>
                </xsl:choose>
              </tbody>
            </table>
          </div>
          <script>
            $(document).ready(function() {			  
			 $('#table-overview').DataTable({
				 language: {
					 "sProcessing": "处理中...",
					 "sLengthMenu": "显示 _MENU_ 项结果",
					 "sZeroRecords": "没有匹配结果",
					 "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
					 "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
					 "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
					 "sInfoPostFix": "",
					 "sSearch": "搜索:",
					 "sUrl": "",
					 "sEmptyTable": "表中数据为空",
					 "sLoadingRecords": "载入中...",
					 "sInfoThousands": ",",
					 "oPaginate": {
						 "sFirst": "首页",
						 "sPrevious": "上页",
						 "sNext": "下页",
						 "sLast": "末页"
					 },
					 "oAria": {
						 "sSortAscending": ": 以升序排列此列",
						 "sSortDescending": ": 以降序排列此列"
					 }
				 }
			 });			  
            });
			
          </script>
		  
          <h2 id="onlinehosts" class="target">在线主机</h2>
          <xsl:for-each select="/nmaprun/host[status/@state='up']">
            <div class="panel panel-default">
              <div class="panel-heading">
                <h3 class="panel-title"><xsl:value-of select="address/@addr"/><xsl:if test="count(hostnames/hostname) > 0"> - <xsl:value-of select="hostnames/hostname/@name"/></xsl:if></h3>
              </div>
              <div class="panel-body">
                <xsl:if test="count(hostnames/hostname) > 0">
                  <h4>Hostnames</h4>
                  <ul>
                    <xsl:for-each select="hostnames/hostname">
                      <li><xsl:value-of select="@name"/> (<xsl:value-of select="@type"/>)</li>
                    </xsl:for-each>
                  </ul>
                </xsl:if>
                <h4>端口信息</h4>
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>端口</th>
                        <th>协议</th>
                        <th>状态</th>
                        <th>探测手段</th>
                        <th>服务</th>
                        <th>组件</th>
                        <th>版本</th>
                        <th>附件信息</th>
                        <th>CPE 信息</th>
                      </tr>
                    </thead>
                    <tbody>
                      <xsl:for-each select="ports/port">
                        <xsl:choose>
                          <xsl:when test="state/@state = 'open'">
                            <tr class="success">
                              <td title="Port"><xsl:value-of select="@portid"/></td>
                              <td title="Protocol"><xsl:value-of select="@protocol"/></td>
                              <td title="State"><xsl:value-of select="state/@state"/></td>
							  <td title="Reason"><xsl:value-of select="state/@reason"/></td>
                              <td title="Service"><xsl:value-of select="service/@name"/></td>
                              <td title="Product"><xsl:value-of select="service/@product"/></td>
                              <td title="Version"><xsl:value-of select="service/@version"/></td>
                              <td title="Extra Info"><xsl:value-of select="service/@extrainfo"/></td>
                              <td title="CPE Info"><xsl:value-of select="service/cpe"/></td>
                            </tr>
							
							  <xsl:for-each select="script">
								<tr class="script">
								  <td></td>
								  <td><xsl:value-of select="@id"/> <xsl:text>&#xA0;</xsl:text></td>
								  <td colspan="7">
									<pre><xsl:value-of select="@output"/> <xsl:text>&#xA0;</xsl:text></pre>
								  </td>
								</tr>
 
							  </xsl:for-each>
							  
                          </xsl:when>
                          <xsl:when test="state/@state = 'filtered'">
                            <tr class="warning">
                              <td><xsl:value-of select="@portid"/></td>
                              <td><xsl:value-of select="@protocol"/></td>
                              <td><xsl:value-of select="state/@state"/><br/><xsl:value-of select="state/@reason"/></td>
                              <td><xsl:value-of select="service/@name"/></td>
                              <td><xsl:value-of select="service/@product"/></td>
                              <td><xsl:value-of select="service/@version"/></td>
                              <td><xsl:value-of select="service/@extrainfo"/></td>
							  <td><xsl:value-of select="service/cpe"/></td>
                            </tr>
                          </xsl:when>
                          <xsl:when test="state/@state = 'closed'">
                            <tr class="active">
                              <td><xsl:value-of select="@portid"/></td>
                              <td><xsl:value-of select="@protocol"/></td>
                              <td><xsl:value-of select="state/@state"/><br/><xsl:value-of select="state/@reason"/></td>
                              <td><xsl:value-of select="service/@name"/></td>
                              <td><xsl:value-of select="service/@product"/></td>
                              <td><xsl:value-of select="service/@version"/></td>
                              <td><xsl:value-of select="service/@extrainfo"/></td>
							  <td><xsl:value-of select="service/cpe"/></td>
                            </tr>
                          </xsl:when>
                          <xsl:otherwise>
                            <tr class="info">
                              <td><xsl:value-of select="@portid"/></td>
                              <td><xsl:value-of select="@protocol"/></td>
                              <td><xsl:value-of select="state/@state"/><br/><xsl:value-of select="state/@reason"/></td>
                              <td><xsl:value-of select="service/@name"/></td>
                              <td><xsl:value-of select="service/@product"/></td>
                              <td><xsl:value-of select="service/@version"/></td>
                              <td><xsl:value-of select="service/@extrainfo"/></td>
							  <td><xsl:value-of select="service/cpe"/></td>
                            </tr>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </tbody>
                  </table>
                </div>
				
                <xsl:if test="count(hostscript/script) > 0">
                  <h4>主机 脚本</h4>
                </xsl:if>
                <xsl:for-each select="hostscript/script">
                  <h5><xsl:value-of select="@id"/></h5>
                  <pre style="white-space:pre-wrap; word-wrap:break-word;"><xsl:value-of select="@output"/></pre>
                </xsl:for-each>
				
              </div>
            </div>
          </xsl:for-each>
		  
		  
		  
          <h2 id="openservices" class="target">服务信息</h2>
          <div class="table-responsive">
            <table id="table-services" class="table table-striped dataTable" role="grid">
              <thead>
                <tr>
                  <th>IP</th>
                  <th>端口</th>
                  <th>协议</th>
                  <th>服务</th>
                  <th>组件</th>
                  <th>版本</th>
                  <th>CPE</th>
                  <th>附加信息</th>
                </tr>
              </thead>
              <tbody>
                <xsl:for-each select="/nmaprun/host">
                  <xsl:for-each select="ports/port[state/@state='open']">
                    <tr>
                      <td><xsl:value-of select="../../address/@addr"/><xsl:if test="count(../../hostnames/hostname) > 0"> - <xsl:value-of select="../../hostnames/hostname/@name"/></xsl:if></td>
                      <td><xsl:value-of select="@portid"/></td>
                      <td><xsl:value-of select="@protocol"/></td>
                      <td><xsl:value-of select="service/@name"/></td>
                      <td><xsl:value-of select="service/@product"/></td>
                      <td><xsl:value-of select="service/@version"/></td>
                      <td><xsl:value-of select="service/cpe"/></td>
                      <td><xsl:value-of select="service/@extrainfo"/></td>
                    </tr>
                  </xsl:for-each>
                </xsl:for-each>
              </tbody>
            </table>
          </div>
          <script>		
            $(document).ready(function() {			  
			 $('#table-services').DataTable({
				 language: {
					 "sProcessing": "处理中...",
					 "sLengthMenu": "显示 _MENU_ 项结果",
					 "sZeroRecords": "没有匹配结果",
					 "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
					 "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
					 "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
					 "sInfoPostFix": "",
					 "sSearch": "搜索:",
					 "sUrl": "",
					 "sEmptyTable": "表中数据为空",
					 "sLoadingRecords": "载入中...",
					 "sInfoThousands": ",",
					 "oPaginate": {
						 "sFirst": "首页",
						 "sPrevious": "上页",
						 "sNext": "下页",
						 "sLast": "末页"
					 },
					 "oAria": {
						 "sSortAscending": ": 以升序排列此列",
						 "sSortDescending": ": 以降序排列此列"
					 }
				 }
			 });			  
            });			
          </script>
        </div>
	 <!-- 页脚 -->
		<footer class="footer" style="height: 50px; margin-top: 20px; padding-top: 20px;">
          <div class="container">
            <p class="text-muted">
              This Report Was Generated By <a href='https://www.cnblogs.com/lyshark'>LyShark</a>.<br/>
            </p>
          </div>
        </footer>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

执行 XSLT 转换生成 HTML 报告

使用 xsltproc 工具和 mode.xsl 模板,将 Nmap 输出的 XML 报告转换成 HTML 格式,以便于查看。

xsltproc -o 141.html mode.xsl 141.xml

美化后的报告效果

转换后的 HTML 报告更加直观,方便分析和展示扫描结果。

在这里插入图片描述

  • 16
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java XSLT模板XML是指使用Java编程语言的XSLT技术来将XML数据与XSLT模板文件进行结合,生成新的XML文档。在Java中,你可以使用Java内置的javax.xml.transform包中的Transformer类来完成这个过程。首先,你需要创建一个Transformer对象,并指定XSLT模板文件的位置。然后,你可以使用Transformer对象的transform()方法来将XML数据与XSLT模板进行处理,生成新的XML文档。在这个过程中,XSLT模板文件中定义了XML数据的转换规则,包括选择和过滤节点、应用样式和格式等。通过使用XSLT模板XML,你可以方便地对XML数据进行转换和处理,以满足不同的需求。,从Java Web开发的角度来看,使用XSLT模板XML可以实现动态生成HTML或其他前端页面。XML数据可以作为数据源,XSLT模板文件可以定义页面的样式和布局。通过XSLT模板XML,你可以将XML数据转换为具有特定样式和布局的HTML或其他前端页面,从而实现动态的数据展示和交互。这种方式在Java Web开发中被广泛应用,以提供灵活和可定制的界面效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [XML实验报告XML,DTD,SCHEMA,XPATH,XSLT,利用JAVA对XML进行读写操作)](https://blog.csdn.net/qq_51513626/article/details/122017954)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part2](https://download.csdn.net/download/ljtt123/4479797)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值