-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmap2md.xsl
84 lines (76 loc) · 3.41 KB
/
nmap2md.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Output method for plain text (Markdown) -->
<xsl:output method="text" />
<!-- Main Template -->
<xsl:template match="/nmaprun">
<!-- Loop through each host -->
<xsl:for-each select="host">
<xsl:text>#### TCP - Target: `</xsl:text>
<xsl:value-of select="hostnames/hostname/@name" />
<xsl:if test="hostnames/hostname"><xsl:text> </xsl:text></xsl:if>
<xsl:value-of select="address/@addr" />
<xsl:text>` </xsl:text>
<xsl:text>- Command: `</xsl:text>
<xsl:value-of select="/nmaprun/@args" />
<xsl:text> </xsl:text>
<!-- Loop through each port -->
<xsl:for-each select="ports/port">
<xsl:text>##### </xsl:text>
<xsl:value-of select="@portid" />
<xsl:text>/</xsl:text>
<xsl:value-of select="@protocol" />
<xsl:text>-</xsl:text>
<xsl:value-of select="service/@name" />
<!-- Display product and version, if available -->
<xsl:if test="service/@product">
<xsl:text> `</xsl:text>
<xsl:value-of select="service/@product" />
<xsl:text>`</xsl:text>
</xsl:if>
<xsl:if test="service/@version">
<xsl:text> `</xsl:text>
<xsl:value-of select="service/@version" />
<xsl:text>`</xsl:text>
</xsl:if>
<xsl:if test="service/@extrainfo">
<xsl:text> `(</xsl:text>
<xsl:value-of select="service/@extrainfo" />
<xsl:text>)`</xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
<!-- Script output (if any) -->
<xsl:if test="script">
<xsl:text>```</xsl:text>
</xsl:if>
<xsl:for-each select="script">
<xsl:text> __</xsl:text>
<xsl:value-of select="@id" /><xsl:text>: </xsl:text>
<!-- Call recursive template to remove leading newlines -->
<xsl:call-template name="strip-leading-newlines">
<xsl:with-param name="text" select="@output" />
</xsl:call-template>
</xsl:for-each>
<xsl:if test="script">
<xsl:text> ``` </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<!-- Recursive template to strip leading newlines -->
<xsl:template name="strip-leading-newlines">
<xsl:param name="text" />
<xsl:choose>
<!-- If the first character is a newline, strip it recursively -->
<xsl:when test="starts-with($text, ' ')">
<xsl:call-template name="strip-leading-newlines">
<xsl:with-param name="text" select="substring($text, 2)" />
</xsl:call-template>
</xsl:when>
<!-- Otherwise, output the string as-is -->
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>