-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.php
144 lines (130 loc) · 6.81 KB
/
worker.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
include('functions.php');
$target = argv[1];
$cip = argv[2];
// Send the scan job to webscan at Pentest Tools
$payload = "{\"op\":\"start_scan\",\"tool_id\":170,\"tool_params\":{\"target\":\"$target\",\"scan_type\":\"quick\",\"follow_redirects\":\"true\"}}";
$json_data = ptt($payload);
$json = json_decode($json_data);
$scan_id = $json->scan_id;
$scan_status = $json->scan_status;
logger("CIP:$cip TARGET:$target STATUS:$scan_status");
dblogger($cip,$target,$scan_status);
// If the scan is waiting, loop and keep checking it every 5 seconds
if ($scan_status = "waiting") {
while ($scan_status == "waiting") {
sleep(5);
$payload = "{\"op\":\"get_scan_status\",\"scan_id\":$scan_id}";
$json_data = ptt($payload);
$json = json_decode($json_data);
$scan_status = $json->scan_status;
logger("CIP:$cip TARGET:$target STATUS:$scan_status");
dblogger($cip,$target,$scan_status);
}
}
// If the scan is running, loop and keep checking it every 5 seconds
if ($scan_status = "running") {
while ($scan_status == "running") {
sleep(5);
$payload = "{\"op\":\"get_scan_status\",\"scan_id\":$scan_id}";
$json_data = ptt($payload);
$json = json_decode($json_data);
$scan_status = $json->scan_status;
logger("CIP:$cip TARGET:$target STATUS:$scan_status");
dblogger($cip,$target,$scan_status);
}
}
if ($scan_status == "finished") {
// Get the scan output
logger("CIP:$cip TARGET:$target STATUS:$scan_status");
dblogger($cip,$target,$scan_status);
$payload = "{\"op\":\"get_output\",\"scan_id\":$scan_id,\"output_format\":\"json\"}";
$json = ptt($payload);
$json_report_data = json_decode($json);
// Delete the scan from Pentest Tools
$payload = "{\"op\":\"delete_scan\",\"scan_id\":$scan_id}";
ptt($payload);
logger("CIP:$cip TARGET:$target STATUS:deleted");
dblogger($cip,$target,"deleted");
$high_count = $json_report_data->scan_info->output_summary->high;
$medium_count = $json_report_data->scan_info->output_summary->medium;
$low_count = $json_report_data->scan_info->output_summary->low;
$info_count = $json_report_data->scan_info->output_summary->info;
$start = $json_report_data->scan_info->start_time;
$stop = $json_report_data->scan_info->end_time;
$duration = $json_report_data->scan_info->duration;
$num_tests = $json_report_data->scan_info->num_tests;
$num_finished_tests = $json_report_data->scan_info->num_finished_tests;
$arrayLength = count($json_report_data->scan_output->scan_tests);
$i = 0;
while ($i < $arrayLength) {
$name = $json_report_data->scan_output->scan_tests[$i]->vuln_description;
$description = $json_report_data->scan_output->scan_tests[$i]->risk_description;
$vuln_evidence = $json_report_data->scan_output->scan_tests[$i]->vuln_evidence->data;
$risklevel = $json_report_data->scan_output->scan_tests[$i]->risk_level;
$evidence = '<tr>';
if (is_array($vuln_evidence)) {
$evidence_Length = count($vuln_evidence);
$ecount = 0;
while ($ecount < $evidence_Length) {
if (ISSET($vuln_evidence[$ecount][0])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][0]);
$vdata = str_replace(" ", " ", $vdata);
$vdata = preg_replace("/<img[^>]+>/i", "", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][1])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][1]);
$vdata = str_replace(" ", " ", $vdata);
$vdata = preg_replace("/<img[^>]+>/i", "", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][2])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][2]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][3])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][3]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][4])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][4]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][5])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][5]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][6])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][6]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][7])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][7]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
if (ISSET($vuln_evidence[$ecount][8])) {
$vdata = str_replace(" ", " ", $vuln_evidence[$ecount][8]);
$vdata = str_replace(" ", " ", $vdata);
$evidence .= "<td>$vdata</td>";
}
$evidence .= "</tr>";
$ecount++;
}
} else {
if (EMPTY($evidence)) {
$evidence = "No evidence was collected for this vulnerability";
}
}
$recommendation = $json_report_data->scan_output->scan_tests[$i]->recommendation;
$sql = "INSERT INTO vulnerabilities (cip,target,vulnName,vulnRiskLevel,vulnEvidence,vulnDescription,vulnRecommendation) VALUES ('$cip','$target','$name','$risklevel','$evidence','$description','$recommendation')";
$i++;
}
$sql = "INSERT INTO W (cip,target,start,stop,duration,num_tests,num_finished_tests) VALUES ('$cip','$target','$start','$stop','$duration','$num_tests','$num_finished_tests')";
}