forked from foreni-packages/cisco-torch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cisco-torch.pl
executable file
·296 lines (248 loc) · 5.95 KB
/
cisco-torch.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
#!/usr/bin/perl
eval ("use IO::Socket;");die "[error] IO::Socket perl module is not installed \n" if $@;
eval ("use sigtrap;");die "[error] sigtrap perl is not suported \n" if $@;
eval ("use Net::hostent;");die "[error] Net::hostent perl module is not installed \n" if $@;
eval ("use Getopt::Std;");die "[error] Getopt::Std perl module is not installed \n" if $@;
eval ("use Net::Telnet;");die "[error] Net::Telnet perl module is not installed \n" if $@;
eval ("use Net::SSH::Perl;");die "[error] Net::SSH::Perl perl module is not installed \n" if $@;
eval ("use Net::SSLeay qw(get_https post_https sslcat make_headers make_form);");die "[error] Net::SSLeay perl module is not installed \n" if $@;
eval ("use MIME::Base64 qw(encode_base64);");die "[error] MIME::Base64 perl module is not installed \n" if $@;
eval ("use Net::SNMP;");die "[error] Net::SNMP perl module is not installed \n" if $@;
eval ("use POSIX;");die "[error] POSIX perl is not suported \n" if $@;
eval{require "torch.conf"};
if($@) {
print "Failed to load config file:torch.conf\n";
}
print "Using config file torch.conf...\n";
# Plugins
print "Loading include and plugin ...\n";
opendir(DIR, "include");
while($in=readdir(DIR)) {
next if ($in=~/^[.]{1,2}/);
next if !($in=~/\.pm$/);
require "include/$in";
}
closedir(DIR);
my $version = "0.4b";
#SNMP staff
$ENV{'MIBS'}="ALL"; #Load all available MIBs
&getopts('AtsdunbcjzwVl:XF:O:g');
use vars qw(
$opt_A
$opt_t
$opt_s
$opt_d
$opt_c
$opt_u
$opt_n
$opt_V
$opt_l
$opt_w
$opt_z
$opt_a
$opt_X
$opt_F
$opt_O
$opt_b
$opt_j
$opt_g
);
if ( !$opt_F ) { $host = $ARGV[0]; }
else { chomp $opt_F; $targetfile = $opt_F }
if ($opt_V)
{
print(" Version $version\n");
exit(0);
}
if (
( !$host && !$opt_F )
|| ( $host && $opt_F )
|| ( !$opt_A
&& !$opt_t
&& !$opt_s
&& !$opt_w
&& !$opt_z
&& !$opt_X
&& !$opt_F
&& !$opt_u
&& !$opt_n
&& !$opt_b
&& !$opt_c
&& !$opt_j
&& !$opt_g
&& !$ARGV[1] )
)
{
&usage;
exit(0);
}
if ( $opt_g && !($opt_u || $opt_j ) )
{
print (" -g should only be used with either -u or -j with -b option\n");
exit(0);
}
if ( $opt_g && ($opt_u ) )
{
print (" You must be root or administrator to start the TFTP server!! \n Required for config download by SNMP\n");
}
if ( $opt_b && !($opt_t || $opt_s || $opt_u || $opt_c || $opt_w || $opt_j ) )
{
print (" -b should only be used with either -t , -s, -c , -j , -w or -u option\n");
exit(0);
}
$logfile = $opt_O if $opt_O;
print("\n");
&banner;
if ($opt_l)
{
if ( ( $opt_l !~ /^[cdv]+$/ ) )
{
print "Unknown loglevel defenition: " . $opt_l . "\n";
exit(0);
}
$llevel = $opt_l;
}
if ($opt_F)
{
$date = `date`;
open( TARGETLIST, "$targetfile" )
|| die "$0: Could not read from $targetfile! ($!)";
while (<TARGETLIST>) { chomp; push( @targetlist, $_ ); }
} else
{
if ( $host =~ /[A-z]/ )
{
@targetlist=($host);
} else
{
&GetRange;
}
}
$tgt_cnt = defined $IPstart ? $IPend-$IPstart : $#targetlist + 1;
log_print( "List of targets contains $tgt_cnt host(s)\n", "c" );
# Determine how many scanner processes is required ------------------------------------------------------
$proc_cnt = $tgt_cnt / $hosts_per_process > $max_processes ? $max_processes : floor($tgt_cnt / $hosts_per_process);
$proc_tgt_cnt = ceil( $tgt_cnt / ($proc_cnt + 1) );
log_print( "Will fork $proc_cnt additional scaner processes\n", "c" ) if $proc_cnt;
# Fork scanner processes --------------------------------------------------------------------------------
@children = ();
for ($bi = 0, $pid = -1 ; $bi < $tgt_cnt - $proc_tgt_cnt; $bi += $proc_tgt_cnt)
{
last if !($pid = fork());
push(@children, $pid);
}
# Determine scan range for each process -----------------------------------------------------------------
$ei = $bi + $proc_tgt_cnt <= $tgt_cnt ? $bi + $proc_tgt_cnt - 1 : $tgt_cnt - 1;
if (defined $IPstart)
{
$start = GetIP($IPstart + $bi);
$end = GetIP($IPstart + $ei);
}
else
{
$start = $targetlist[$bi];
$end = $targetlist[$ei];
@targetlist = @targetlist[$bi..$ei];
}
# Perform the scan --------------------------------------------------------------------------------------
log_print( "Range Scan from $start to $end\n", "c" ) unless ( "$start" eq "$end" );
for ($c = $bi; $c <= $ei; $c++)
{
$host = defined $IPstart ? GetIP($IPstart + $c) : $targetlist[$c - $bi];
log_print( "$$:\tChecking $host ...\n", "c" );
log_start();
&scanit;
log_write("Host: $host *****************************************************\n");
}
if ($pid) # Master process
{
{} until wait() == -1; # Wait for clildren to terminate
&endbanner;
push (@children, $$);
foreach $cpid (@children)
{
`cat $tmplogprefix.$cpid >>$logfile && rm -f $tmplogprefix.$cpid` if (stat("$tmplogprefix.$cpid"))
}
}
# end core
#############################
###############
# Subroutines #
###############
sub scanit
{
if ( !&check_ip($host) )
{
log_print( " trying to resolve hostname $host\n\n", "c" );
my $handler = gethost($host);
if ( !$handler )
{
log_print( "$host does not resolve, I died\n\n", "c" );
exit(0);
}
$target = inet_ntoa( @{ $handler->addr_list }[0] );
log_print( "resolved host to: $target\n\n", "i" );
$host_resolves = 1;
} else
{
$target = $host;
$host_resolves = 0;
}
if ($opt_A)
{
$opt_u = "1";
$opt_n = "1";
$opt_t = "1";
$opt_w = "1";
$opt_s = "1";
$opt_c = "1";
$opt_j = "1";
}
if ($opt_t)
{
if (telnetfprint())
{
telnet_leak_user() ? pwdbforce() : bruteforce(0) if $opt_b;
}
}
if ($opt_s)
{
if (sshfprint())
{
bruteforce(1) if $opt_b;
}
}
if ($opt_u)
{
if ( snmp_ping())
{
snmp_bruteforce(1) if $opt_b;
}
}
if ($opt_n)
{
&ntp
}
if ($opt_j)
{
&tftp
}
if ($opt_z)
{
&cisco_auth_http
}
if ($opt_w)
{
if (checkweb())
{
brute_www(1) if $opt_b;
}
}
if ($opt_c)
{
if (ssl_finger())
{
brute_ssl(1) if $opt_b;
}
}
}