forked from pentestmonkey/yaptest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaptest-issues.pl
executable file
·342 lines (307 loc) · 13.5 KB
/
yaptest-issues.pl
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/env perl
use strict;
use warnings;
use POSIX;
use Getopt::Long;
use yaptest;
use Data::Dumper;
use File::Basename;
my $script_name = basename($0);
my $usage = "
Usage: $script_name query [ --ip ip ] [ -p port ] [ --trans tcp|udp ] [ --issue name ] [ --test test_area ]
$script_name export out.xml [ --ip ip ] [ -p port ] [ --trans tcp|udp ] [ --issue name ] [ --test test_area ]
$script_name parse file [ file ... ]
$script_name add --issue name -i ip [ -p port --trans tcp|udp ]
$script_name delete --issue name -i ip [ -p port --trans tcp|udp ]
$script_name insecgen
query mode:
Display issues related to hosts or ports from the backend database.
export mode:
Save the query output to an XML file.
parse mode
Attempts to automatically parse a file and extract security issues.
Currently parses nessus nbe files for a few exploitable issues and
the output of nxscan and tnscmd.pl.
If a nessus html file is passed, this won't be parsed for issues,
but will be stored in the database.
add mode:
Associate an issue with a host or port.
delete mode:
Un-Associate an issue with a host or port. It is recommended that you
ALWAYS specify an issue name. It's not manditatory though, and it IS
possible to delete all the issues for a host, or even simply delete
ALL the issues.
insecgen:
Generate issues about insecure protocols (current test area only).
";
my $test_area;
my $issue;
my $ip;
my $port;
my $trans;
my %good_issue = (
"10657" => "MS01-023",
"11412" => "MS03-007",
"11835" => "MS03-039",
"11890" => "MS03-043",
"11921" => "MS03-049",
"12054" => "MS04-007",
"12209" => "MS04-011",
"15456" => "MS04-031",
"18489" => "MS05-030",
"19408" => "MS05-039",
"20382" => "MS06-001",
"21193" => "MS05-047",
"21210" => "MS06-013",
"21689" => "MS06-025",
"22034" => "MS06-035",
"22194" => "MS06-040",
"22536" => "MS06-063",
"23643" => "MS06-066",
"24323" => "telnet_fuser",
"29308" => "MS07-064",
"21564" => "vnc_auth_bypass",
"10114" => "icmp_timestamp",
"12295" => "dell_openmanage",
"10674" => "mssql_version_udp",
"10539" => "dns_recursive",
"11819" => "tftp_insecure",
"10884" => "ntp_os_info",
"18405" => "rdp_mitm",
"26928" => "ssl_weak_ciphers",
"15901" => "expired_ssl_cert",
"10150" => "nbt_info",
"10785" => "smb_os_info",
"10397" => "windows_browse_list",
"26920" => "smb_null_session",
"11424" => "webdav_enabled",
"10722" => "ldap_null_base_dn",
"10245" => "rsh_insecure",
"20007" => "sslv2_supported",
"32397" => "epo_version",
"25702" => "epo_code_exec",
"10281" => "insec_proto_telnet",
"32314" => "weak_ssh_host_key",
"19948" => "x11_open",
"10860" => "win_rid_cycle",
);
GetOptions (
"test_area=s" => \$test_area,
"trans=s" => \$trans,
"ip=s" => \$ip,
"issue=s" => \$issue,
"port=s" => \$port,
);
my $command = shift or die $usage;
my $y = yaptest->new();
if ($command eq "parse") {
my $file = shift or die $usage;
unshift @ARGV, $file;
while (my $filename = shift) {
my $ip;
print "Processing $filename ...\n";
unless (open(FILE, "<$filename")) {
print "WARNING: Can't open $filename for reading. Skipping...\n";
next;
}
# slurp nessus html into database
if ($filename =~ /nessus-report-(\d+\.\d+\.\d+\.\d+).html/) {
my $ip = $1;
if (open HTML, "<$filename") {
local undef $/;
my $html = <HTML>;
$html =~ s/10pt/11pt/g;
$html =~ s/8pt/10pt/g;
$y->insert_host_info(ip_address => $ip, key => "nessus_html_report", value => $html);
} else {
print "ERROR: Couldn't open nessus html file $filename for reading: $!. Skipping.\n";
}
next;
}
while (<FILE>) {
print;
chomp;
my $line = $_;
# nxscan
# 1.2.3.4 03 OS[Windows 5.0] MS04-007 VULNERABLE, MS04-011 VULNERABLE, MS06-040 INCONCLUSIVE [00000000]
if ($filename =~ /nxscan/ and $line =~ /^(\d+\.\d+\.\d+\.\d+) [0-9a-fA-F]{2} OS\[[^]]*\] (MS[0-9]{2}-[0-9]{3}.*MS[0-9]{2}-[0-9]{3}.*MS[0-9]{2}-[0-9]{3}.*)/) {
my $ip = $1;
my $result = $2;
my @results = split ", ", $result;
foreach my $r (@results) {
if ($r =~ /(MS[0-9]{2}-[0-9]{3}) VULNERABLE/) {
my $issue = $1;
print "PARSED: IP=$ip, ISSUE=$issue\n";
$y->insert_issue(name => $issue, ip_address => $ip);
}
}
}
# ms08-067_check
# 1.2.3.4: VULNERABLE
if ($filename =~ /ms08-067/ and $line =~ /^(\d+\.\d+\.\d+\.\d+): VULNERABLE/) {
my $ip = $1;
my $issue = "MS08-067";
print "PARSED: IP=$ip, ISSUE=$issue\n";
$y->insert_issue(name => $issue, ip_address => $ip);
}
# nessus
# results|1.2.3|1.2.3.4|telnet (23/tcp)|24323|Security Hole|\nSynopsis
if ($filename =~ /(?:nessus|\.nbe)/ and $line =~ /^results\|[\d\.]+\|(\d+\.\d+\.\d+\.\d+)\|.*?\((\d+)\/(tcp|udp)\)\|(\d+)\|Security[^|]+\|(.*)/) {
my $ip = $1;
my $port = $2;
my $trans = uc $3;
my $ness_id = $4;
my $issue_text = $5;
# Only parse the SSL cipher issue if ciphers are weak
if ($ness_id eq '26928') {
next unless ($issue_text =~ /\(40\)|\(56\)|/);
}
# Only parse the NTP issue if it actually leaks OS info
if ($ness_id eq '10884') {
next unless $issue_text =~ /system=/;
}
if (defined($good_issue{$ness_id})) {
print "PARSED: $ip:$port/$trans issue $ness_id (" . $good_issue{$ness_id} . ")\n";
$y->insert_issue(name => $good_issue{$ness_id}, ip_address => $ip, port => $port, transport_protocol => $trans);
}
}
# results|1.2.3|1.2.3.4|general/icmp|10114|Security Note|
if ($filename =~ /(?:nessus|\.nbe)/ and $line =~ /^results\|[\d\.]+\|(\d+\.\d+\.\d+\.\d+)\|general\/icmp\|(\d+)\|Security Note\|.*/) {
my $ip = $1;
my $ness_id = $2;
if (defined($good_issue{$ness_id})) {
print "PARSED: $ip issue $ness_id (" . $good_issue{$ness_id} . ")\n";
$y->insert_issue(name => $good_issue{$ness_id}, ip_address => $ip);
}
}
# FScan
if ($filename =~ /fscan/ and $line =~ /^"(\d+\.\d+\.\d+\.\d+)",[^,]+,[^,]+,[^,]+,"(MS\d\d-\d\d\d)","Vulnerable"/) {
my $ip = $1;
my $issue = $2;
print "PARSED: $ip: issue=$issue\n";
$y->insert_issue(name => $issue, ip_address => $ip);
}
# insec tns listener
if ($line =~ /^\s+LOGFILE=/) {
if ($filename =~ /tns.*?(\d+\.\d+\.\d+\.\d+)/) {
my $ip = $1;
print "PARSED: $ip: issue=tns-listener\n";
$y->insert_issue(name => "tns-listener", ip_address => $ip);
}
}
}
}
} elsif ($command eq "query" or $command eq "export") {
my $aref = $y->get_issues(test_area_name => $test_area, ip_address => $ip, port => $port, issue => $issue);
if ($command eq "query") {
$y->print_table_hashes($aref, undef, qw(test_area_name ip_address port transport_protocol_name issue_shortname));
}
if ($command eq "export") {
my $filename = shift or die "ERROR: Filename argument is mandatory for 'export'\n";
$y->export_to_xml($aref, "issues", $filename);
print "XML output of query saved to $filename\n";
}
} elsif ($command eq "add") {
unless (defined($issue) and defined($ip)) {
die "ERROR: --issue and --ip options are mandatory for 'add' mode\n";
}
$y->insert_issue(name => $issue, ip_address => $ip, port => $port, transport_protocol => $trans);
print "Associated issue $issue with IP $ip\n";
} elsif ($command eq "delete") {
my $error = shift;
if (defined($error)) {
print "ERROR: Too many arguments passed. Aborting.\n";
exit 1;
}
print "Deleting issues... \n\n";
$y->delete_issues(test_area => $test_area, ip_address => $ip, issue => $issue);
print "Issues deleted successfully\n";
} elsif ($command eq "insecgen") {
my $arefs;
# FTP
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 21, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_ftp', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_ftp", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# telnet
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 23, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_telnet', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_telnet", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# smc
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 898, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_smc', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_smc", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# XDMCP
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 177, transport_protocol => 'UDP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_xdmcp', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_xdmcp", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# tftp
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 69, transport_protocol => 'UDP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_tftp', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_tftp", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# rexec
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 512, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_rexec', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_rexec", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# rlogin
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 513, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_rlogin', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_rlogin", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# rsh
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 514, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_rsh', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "insec_proto_rsh", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# rdp
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 3389, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'rdp_mitm', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "rdp_mitm", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# cisco smart install
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 4786, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'cisco_smart_install', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(name => "cisco_smart_install", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# snmpv1
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 161, transport_protocol => 'UDP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'insec_proto_snmp1', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(test_area => $href->{test_area_name}, name => "insec_proto_snmp1", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# finger
$arefs = $y->get_ports(test_area => $y->get_test_area, port => 79, transport_protocol => 'TCP');
foreach my $href (@$arefs) {
print "DEBUG: name => 'finger_user_enum', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(test_area => $href->{test_area_name}, name => "finger_user_enum", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
# small services
foreach my $port (7, 9, 13, 19, 37) {
foreach my $trans ("UDP", "TCP") {
$arefs = $y->get_ports(test_area => $y->get_test_area, port => $port, transport_protocol => $trans);
foreach my $href (@$arefs) {
print "DEBUG: name => 'small_services', ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol}\n";
$y->insert_issue(test_area => $href->{test_area_name}, name => "small_services", ip_address => $href->{ip_address}, port => $href->{port}, transport_protocol => $href->{transport_protocol});
}
}
}
} else {
print "ERROR: Command $command not implemented\n";
}
$y->commit;
$y->destroy;