forked from RASSec/pentestER-Fully-automatic-scanner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
import1.php
100 lines (97 loc) · 2.65 KB
/
import1.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* This script is only runnable form command line
*/
if (substr(php_sapi_name(), 0, 3) != 'cli'):
die('This script can only be run from command line!');
endif;
/**
* Convert seconds to minutes, hours..
* NOTICE : Approximate, assumes months have 30 days.
*/
function seconds2human($ss)
{
$s = $ss%60;
$mins = floor(($ss%3600)/60);
$hours = floor(($ss%86400)/3600);
$days = floor(($ss%2592000)/86400);
$months = floor($ss/2592000);
$text = '';
if ($months > 0) {
$text .= $months." months,";
}
if ($days > 0) {
$text .= $days." days,";
}
if ($hours > 0) {
$text .= $hours." hours,";
}
if ($mins > 0) {
$text .= $mins." minutes,";
}
if ($s > 0) {
$text .= $s." seconds";
}
return $text;
}
/**
* Magic starts here
*/
$start_ts = time();
if (!isset($argv[1])):
die('Please provide a file name to import!'."\n");
endif;
$tmp = pathinfo($argv[1]);
if ($tmp['dirname'] == "."):
$filepath = dirname(__FILE__).'/'.$argv[1];
else:
$filepath = $argv[1];
endif;
if (!is_file($filepath)):
echo "File:".$filepath;
echo PHP_EOL;
echo 'File does not exist!';
echo PHP_EOL;
exit;
endif;
echo "Reading file";
echo PHP_EOL;
$content = utf8_encode(file_get_contents($filepath));
echo "Parsing file";
echo PHP_EOL;
$xml = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
if ($xml === false):
die('There is a problem with this xml file?!'.PHP_EOL);
endif;
$total = 0;
$inserted = 0;
echo "Processing data (This may take some time depending on file size)";
echo PHP_EOL;
foreach ($xml->host as $host):
$AA=array();
foreach ($host->ports as $p):
$ip = $host->address['addr'];
@file_put_contents("report/result_sentives.html", '<h2><font color=red>'.$ip.'</font></h2>', FILE_APPEND);
print $ip.'<br>';
foreach ($p->port as $pp){
$p_protocol=$pp['protocol'];
$p_port=(int)$pp['portid'];
$p_service_http_title=$pp->script["http-title"]['output'];
$p_banner=$pp->script['output'];
$p_service=$pp->service["name"];
$total++;
$fwritt='<b>'.$p_protocol.'</b> '.'<a href="http://'.$ip.':'.$p_port.'"" target=_blank><b>'.$p_port.'</b></a>'.' <b>'.$p_service.'</b> <pre>'.$p_service_http_title.'</pre> <pre>'.$p_banner.'</pre> '.' '.'<br>';
print $fwritt;
@file_put_contents("report/result_sentives.html", $fwritt, FILE_APPEND);
}
endforeach;
endforeach;
$end_ts = time();
echo PHP_EOL;
echo "Summary:";
echo PHP_EOL;
echo "Total records:".$total."\n";
echo "Inserted records:".$inserted."\n";
$secs = $end_ts - $start_ts;
echo "Took about:".seconds2human($secs);
echo PHP_EOL;