traceroute

This commit is contained in:
Adrien MALINGREY 2025-02-04 22:57:44 +01:00
parent c2268c4f00
commit 55f6be594a
4 changed files with 73 additions and 79 deletions

View File

@ -5,7 +5,7 @@ $SCANSDIR = "scans";
$STYLESHEETSDIR = "stylesheets"; $STYLESHEETSDIR = "stylesheets";
$NMAP = "sudo nmap"; # nmap command, E.g. 'nmap', 'sudo nmap' for root privileges or '/usr/bin/nmap' if not in PATH $NMAP = "sudo nmap"; # nmap command, E.g. 'nmap', 'sudo nmap' for root privileges or '/usr/bin/nmap' if not in PATH
$LANSCANOPTIONS = "-PSmicrosoft-ds -F -T5 --datadir . --script http-info,smb-shares-size --script-args-file script-args.ini -oX - --stylesheet $BASEDIR/$STYLESHEETSDIR/lanScan.xsl";
$HOSTSCANOPTIONS = "-A -T5 --datadir . --script http-info,smb-shares-size --script-args-file script-args.ini -oX - --stylesheet $BASEDIR/$STYLESHEETSDIR/hostScan.xsl";
$DATADIR = "."; $DATADIR = ".";
$SCRIPTARGSFILE = "script-args.ini"; $SCRIPTARGSFILE = "script-args.ini";
$LANSCANOPTIONS = "-PSmicrosoft-ds -F -T5 --datadir '$DATADIR' --script http-info,smb-shares-size --script-args-file '$SCRIPTARGSFILE' -oX - --stylesheet $BASEDIR/$STYLESHEETSDIR/lanScan.xsl";
$HOSTSCANOPTIONS = "-A -T5 --datadir '$DATADIR' --script http-info,smb-shares-size --script-args-file '$SCRIPTARGSFILE' -oX - --stylesheet $BASEDIR/$STYLESHEETSDIR/hostScan.xsl";

View File

@ -70,7 +70,7 @@ if (file_exists($SCANSDIR)) {
</div> </div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui/dist/semantic.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js"></script>
<script> <script>
$('#lanSelect').dropdown({allowAdditions: true, clearable: true}) $('#lanSelect').dropdown({allowAdditions: true, clearable: true})

View File

@ -7,33 +7,13 @@ $targetsListRegex = '/^[\da-zA-Z-. \/]+$/';
$lan = filter_input(INPUT_GET, 'lan', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]); $lan = filter_input(INPUT_GET, 'lan', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]);
if ($lan) { if ($lan) {
$cmd = "$NMAP $LANSCANOPTIONS $lan"; $cmd = "$NMAP $LANSCANOPTIONS $lan";
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$filename = str_replace("/", "!", $lan); $filename = str_replace("/", "!", $lan);
$path = "$SCANSDIR/$filename.xml";
if (!file_exists($path)) $cmd .= " | tee '$path'";
header('Content-type: text/xml');
system("$cmd", $retcode);
exit();
} }
$host = filter_input(INPUT_GET, 'host', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]); $host = filter_input(INPUT_GET, 'host', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]);
if ($host) { if ($host) {
$cmd = "$NMAP $HOSTSCANOPTIONS $host"; $cmd = "$NMAP $HOSTSCANOPTIONS $host";
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$filename = str_replace("/", "!", $host); $filename = str_replace("/", "!", $host);
$path = "$SCANSDIR/$filename.xml";
if (!file_exists($path)) $cmd .= " | tee '$path'";
header('Content-type: text/xml');
system("$cmd", $retcode);
exit();
} }
$targets = filter_input(INPUT_GET, 'targets', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]); $targets = filter_input(INPUT_GET, 'targets', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $targetsListRegex], "flags" => FILTER_NULL_ON_FAILURE]);
@ -173,10 +153,11 @@ if ($targets) {
} }
$cmd = "$NMAP$options $targets"; $cmd = "$NMAP$options $targets";
echo "<!--$cmd-->\n";
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$filename = str_replace("/", "!", $targets); $filename = str_replace("/", "!", $targets);
}
if ($cmd) {
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$path = "$SCANSDIR/$filename.xml"; $path = "$SCANSDIR/$filename.xml";
if (!file_exists($path)) $cmd .= " | tee '$path'"; if (!file_exists($path)) $cmd .= " | tee '$path'";

View File

@ -11,19 +11,15 @@
<xsl:output indent="yes" /> <xsl:output indent="yes" />
<xsl:strip-space elements='*' /> <xsl:strip-space elements='*' />
<xsl:variable name="stylesheetURL" <xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '&quot;')" />
select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '&quot;')" />
<xsl:variable name="base" select="concat($stylesheetURL, '/../../')" /> <xsl:variable name="base" select="concat($stylesheetURL, '/../../')" />
<xsl:template match="nmaprun"> <xsl:template match="nmaprun">
<xsl:variable name="targets" select="substring-after(@args, '.xsl ')" /> <xsl:variable name="targets" select="substring-after(@args, '.xsl ')" />
<xsl:variable <xsl:variable name="current" select="." />
name="current" select="." /> <xsl:variable name="init" select="document(concat($base, 'scans/', translate($targets,'/', '!'), '.xml'))/nmaprun" />
<xsl:variable name="init"
select="document(concat($base, 'scans/', translate($targets,'/', '!'), '.xml'))/nmaprun" />
<html <html lang="fr">
lang="fr">
<xsl:apply-templates select="." mode="head"> <xsl:apply-templates select="." mode="head">
<xsl:with-param name="base" select="$base" /> <xsl:with-param name="base" select="$base" />
<xsl:with-param name="targets" select="$targets" /> <xsl:with-param name="targets" select="$targets" />
@ -34,8 +30,7 @@
</xsl:apply-templates> </xsl:apply-templates>
<main class="ui main container inverted segment"> <main class="ui main container inverted segment">
<xsl:apply-templates <xsl:apply-templates select="$current/host | $init/host[not(address/@addr=$current/host/address/@addr)][not(status/@state='down')]">
select="$current/host | $init/host[not(address/@addr=$current/host/address/@addr)][not(status/@state='down')]">
<xsl:with-param name="init" select="$init" /> <xsl:with-param name="init" select="$init" />
<xsl:with-param name="current" select="$current" /> <xsl:with-param name="current" select="$current" />
</xsl:apply-templates> </xsl:apply-templates>
@ -57,12 +52,9 @@ $('.ui.dropdown').dropdown()
<xsl:template match="host"> <xsl:template match="host">
<xsl:param name="init" /> <xsl:param name="init" />
<xsl:param name="current" /> <xsl:param name="current" />
<xsl:variable name="addr" <xsl:variable name="addr" select="address/@addr" />
select="address/@addr" /> <xsl:variable name="initHost" select="$init/host[address/@addr=$addr]" />
<xsl:variable name="initHost" <xsl:variable name="currentHost" select="$current/host[address/@addr=$addr]" />
select="$init/host[address/@addr=$addr]" />
<xsl:variable name="currentHost"
select="$current/host[address/@addr=$addr]" />
<xsl:variable name="hostAddress"> <xsl:variable name="hostAddress">
<xsl:choose> <xsl:choose>
<xsl:when test="hostnames/hostname/@name"> <xsl:when test="hostnames/hostname/@name">
@ -92,8 +84,7 @@ $('.ui.dropdown').dropdown()
</xsl:choose> </xsl:choose>
</h1> </h1>
<table <table class="ui inverted table" style="width: max-content">
class="ui inverted table" style="width: max-content">
<thead> <thead>
<tr> <tr>
<xsl:if test="address[@addrtype='ipv4']/@addr"> <xsl:if test="address[@addrtype='ipv4']/@addr">
@ -141,7 +132,7 @@ $('.ui.dropdown').dropdown()
<xsl:if test="distance/@value"> <xsl:if test="distance/@value">
<td> <td>
<xsl:value-of select="distance/@value" /> <xsl:value-of select="distance/@value" />
<xsl:text> rebond(s)</xsl:text> <xsl:text> étape(s)</xsl:text>
</td> </td>
</xsl:if> </xsl:if>
<xsl:if test="uptime/@lastboot"> <xsl:if test="uptime/@lastboot">
@ -153,8 +144,7 @@ $('.ui.dropdown').dropdown()
</tbody> </tbody>
</table> </table>
<xsl:if <xsl:if test="hostscript/script">
test="hostscript/script">
<div class="ui inverted tree accordion"> <div class="ui inverted tree accordion">
<div class="title"> <div class="title">
<i class="dropdown icon"></i> Informations supplémentaires </div> <i class="dropdown icon"></i> Informations supplémentaires </div>
@ -164,30 +154,26 @@ $('.ui.dropdown').dropdown()
</div> </div>
</xsl:if> </xsl:if>
<h2 <h2 class="ui header">Services</h2>
class="ui header">Services</h2>
<div class="ui cards"> <div class="ui cards">
<xsl:apply-templates <xsl:apply-templates select="$currentHost/ports/port | $initHost/ports/port[not(@portid=$currentHost/ports/port/@portid)][not(state/@state='closed')]">
select="$currentHost/ports/port | $initHost/ports/port[not(@portid=$currentHost/ports/port/@portid)][not(state/@state='closed')]">
<xsl:with-param name="initHost" select="$initHost" /> <xsl:with-param name="initHost" select="$initHost" />
<xsl:with-param name="currentHost" select="$currentHost" /> <xsl:with-param name="currentHost" select="$currentHost" />
<xsl:with-param name="hostAddress" select="$hostAddress" /> <xsl:with-param name="hostAddress" select="$hostAddress" />
</xsl:apply-templates> </xsl:apply-templates>
</div> </div>
<xsl:apply-templates select="trace" />
</xsl:template> </xsl:template>
<xsl:template match="port"> <xsl:template match="port">
<xsl:param name="hostAddress" /> <xsl:param name="hostAddress" />
<xsl:param name="initHost" /> <xsl:param name="initHost" />
<xsl:param name="currentHost" /> <xsl:param name="currentHost" />
<xsl:variable <xsl:variable name="portid" select="@portid" />
name="portid" select="@portid" /> <xsl:variable name="initPort" select="$initHost/ports/port[@portid=$portid]" />
<xsl:variable name="initPort" <xsl:variable name="currentPort" select="$currentHost/ports/port[@portid=$portid]" />
select="$initHost/ports/port[@portid=$portid]" />
<xsl:variable name="currentPort"
select="$currentHost/ports/port[@portid=$portid]" />
<xsl:variable name="color"> <xsl:variable name="color">
<xsl:choose> <xsl:choose>
<xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=500">red</xsl:when> <xsl:when test="$currentPort/script[@id='http-info']/elem[@key='status']>=500">red</xsl:when>
@ -199,8 +185,7 @@ $('.ui.dropdown').dropdown()
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<div <div class="ui inverted card {$color}">
class="ui inverted card {$color}">
<div class="content"> <div class="content">
<div class="header"> <div class="header">
<div class="ui {$color} ribbon label"> <div class="ui {$color} ribbon label">
@ -249,8 +234,7 @@ $('.ui.dropdown').dropdown()
</div> </div>
</div> </div>
</div> </div>
<xsl:if <xsl:if test="service/@name='ftp' or service/@name='ssh' or service/@name='http' or service/@name='https' or service/@name='ms-wbt-server'">
test="service/@name='ftp' or service/@name='ssh' or service/@name='http' or service/@name='https' or service/@name='ms-wbt-server'">
<a class="ui {$color} button" target="_blank"> <a class="ui {$color} button" target="_blank">
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:choose> <xsl:choose>
@ -258,8 +242,7 @@ $('.ui.dropdown').dropdown()
<xsl:text>rdp.php?v=</xsl:text> <xsl:text>rdp.php?v=</xsl:text>
<xsl:value-of select="$hostAddress" /> <xsl:value-of select="$hostAddress" />
<xsl:text>&amp;p=</xsl:text> <xsl:text>&amp;p=</xsl:text>
<xsl:value-of <xsl:value-of select="@portid" />
select="@portid" />
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:choose> <xsl:choose>
@ -271,8 +254,7 @@ $('.ui.dropdown').dropdown()
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:text>://</xsl:text> <xsl:text>://</xsl:text>
<xsl:value-of <xsl:value-of select="$hostAddress" />
select="$hostAddress" />
<xsl:text>:</xsl:text> <xsl:text>:</xsl:text>
<xsl:value-of select="@portid" /> <xsl:value-of select="@portid" />
</xsl:otherwise> </xsl:otherwise>
@ -286,14 +268,12 @@ $('.ui.dropdown').dropdown()
<div class="ui {$color} center aligned dropdown share-size button"> <div class="ui {$color} center aligned dropdown share-size button">
<xsl:attribute name="style"> <xsl:attribute name="style">
<xsl:for-each select="$currentPort/script[@id='smb-shares-size']/table"> <xsl:for-each select="$currentPort/script[@id='smb-shares-size']/table">
<xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" <xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" order="ascending" />
order="ascending" />
<xsl:if test="position()=1"> <xsl:if test="position()=1">
<xsl:text>--free: </xsl:text> <xsl:text>--free: </xsl:text>
<xsl:value-of select="elem[@key='FreeSize']" /> <xsl:value-of select="elem[@key='FreeSize']" />
<xsl:text>; --total: </xsl:text> <xsl:text>; --total: </xsl:text>
<xsl:value-of <xsl:value-of select="elem[@key='TotalSize']" />
select="elem[@key='TotalSize']" />
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
</xsl:attribute> </xsl:attribute>
@ -327,8 +307,7 @@ $('.ui.dropdown').dropdown()
</tbody> </tbody>
</table> </table>
</xsl:if> </xsl:if>
<xsl:apply-templates <xsl:apply-templates select="table" />
select="table" />
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:value-of select="@output" /> <xsl:value-of select="@output" />
@ -381,11 +360,45 @@ $('.ui.dropdown').dropdown()
<xsl:template match="table"> <xsl:template match="table">
<xsl:param name="hostAddress" /> <xsl:param name="hostAddress" />
<a class="item share-size" <a class="item share-size" href="file://///{$hostAddress}/{@key}" target="_blank" rel="noopener noreferrer" style="--free: {elem[@key='FreeSize']}; --total: {elem[@key='TotalSize']}">
href="file://///{$hostAddress}/{@key}" target="_blank" rel="noopener noreferrer"
style="--free: {elem[@key='FreeSize']}; --total: {elem[@key='TotalSize']}">
<xsl:value-of select="@key" /> <xsl:value-of select="@key" />
</a> </a>
</xsl:template> </xsl:template>
<xsl:template match="trace">
<h2 class="ui header">Traceroute</h2>
<table class="ui inverted table">
<thead>
<tr>
<th>Étape</th>
<th>Adresse</th>
<th>Temps</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="hop" />
</tbody>
</table>
</xsl:template>
<xsl:template match="hop">
<tr>
<td>
<xsl:value-of select="@ttl" />
</td>
<td>
<xsl:value-of select="@host" />
<xsl:text> (</xsl:text>
<xsl:value-of select="@ipaddr" />
<xsl:text>)</xsl:text>
</td>
<td>
<xsl:value-of select="@rtt" />
<xsl:text> ms</xsl:text>
</td>
</tr>
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>