1
After scanning with NMAP, I am trying to create a table with the following columns:
ITEM | PORTA | PROTOCOLO | ESTADO | SERVIÇO
where for each column an NMAP result is: item: the vector index port: port number (before bar) protocol: protocol type (after bar) state: service status if open or closed service: which application is running
Doing local scan my exit looks like this:
array(7) {
[0]=>
string(22) "PORT STATE SERVICE"
[1]=>
string(18) "21/tcp open ftp"
[2]=>
string(19) "80/tcp open http"
[3]=>
string(26) "139/tcp open netbios-ssn"
[4]=>
string(27) "445/tcp open microsoft-ds"
[5]=>
string(20) "3306/tcp open mysql"
[6]=>
string(25) "5432/tcp open postgresql"
}
What would the algorithm look like to turn this vector into a table within HTML?
Follow code for analysis
<?php
$host = $_POST["host"];
$saida = shell_exec('nmap -P0 ' . $host);
$vetorLinhas = explode("\n", $saida);
$start = array_keys(preg_grep('/^PORT/', $vetorLinhas))[0];
$data = array_slice($vetorLinhas, $start, -3)
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Projeto Integrador de Tecnologia</title>
</head>
<body>
<table>
<tr>
<td colspan="5">Scanner de Porta TCP/UDP</td>
</tr>
<tr>
<td height="60" colspan="5" align="center">
<form id="form1" name="form1" method="post" action="index.php">
<br/><br/><br/>
Endereço de Host
<label for="textfield"></label>
<input type="text" name="host" id="textfield" placeholder="Digite o host aqui" />
<input type="submit" name="button" id="button" value="Ir" />
</form>
</td>
</tr>
<tr>
<td height="60" colspan="5">
<?php if ($_POST["host"]) { ?>
<pre>
<?php
$ctt = count($data);
for ($i = 0; $i < $ctt; $i++) {//for
}
foreach ($data as $key => $value) {//foreach
}
echo "<pre><br/>";
var_dump($data);
?>
</pre>
<?php } ?>
</td>
</tr>
</table>
</body>
</html>
This question was duplicated because the moderation ordered that no question be asked on the same previously created topic and ordered that a new question be asked precisely because the answer was partially satisfactory