-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuniscan.pl
231 lines (166 loc) · 8.65 KB
/
uniscan.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
#!/usr/bin/perl
use threads;
use threads::shared;
use Thread::Queue;
use Thread::Semaphore;
use POSIX qw(setsid);
use strict;
use warnings;
use File::Pid;
use IPC::Open3;
use lib "./Uniscan";
use Uniscan::Functions;
use Uniscan::Queue;
use Uniscan::Configure;
my $CHILD_PID;
my $UNISCAN_DIR = "/opt/ONS";
my $nome = "uniscan";
my $pidlocation = "/var/run/$nome.pid";
my $MAX_INSTANCES;
my $semaphore = Thread::Semaphore->new();
our @lock : shared = ();
$SIG{"INT"} = "IGNORE";
$SIG{"HUP"} = "IGNORE";
$SIG{"TERM"} = "IGNORE";
$SIG{"CHLD"} = "IGNORE";
#auto flush
$| = 1;
&setMaxInstances();
open STDIN, '<', '/dev/null' or die $!;
open STDOUT, '>>', '/var/log/ons.txt' or die $!;
open STDERR, '>>', '/var/log/ons.txt' or die $!;
setsid;
chdir "$UNISCAN_DIR/";
umask 0;
our $pid = fork;
exit(0) if ($pid != 0);
die "Fork problem: $!\n" unless defined($pid);
&writePid();
my $queue = Uniscan::Queue->new();
my %report;
my @instaces_pid;
my $active_instances;
# inicia $MAX_INSTANCES do scanner
my $ins = 0;
my @thr = ();
$MAX_INSTANCES = 2;
while($ins < $MAX_INSTANCES){
push(@thr, threads->new(\&scan, $ins));
sleep(1);
$ins++;
print "Thread: $ins\n";
}
while(1){
sleep(30);
}
sub setMaxInstances(){
my($wtr, $rdr, $err, @ret_command);
open3($wtr, $rdr, $err, "/bin/grep processor /proc/cpuinfo | /usr/bin/tail -1");
while (<$rdr>) {
chomp;
push(@ret_command, $_);
}
$ret_command[@ret_command - 1] =~ s/.*: ?//;
$MAX_INSTANCES = ($ret_command[@ret_command - 1] + 1) - 2;
$MAX_INSTANCES = 1 if ($MAX_INSTANCES < 1);
}
sub scan(){
my $ins = shift;
my $func = Uniscan::Functions->new();
my $c = Uniscan::Configure->new(conffile => "uniscan.conf");
my %conf = ( );
while(1){
$lock[$ins] = 0;
my $waitTime = 15;
$semaphore->down();
my %report = $queue->getNext();
my ($thread, $ip, $banner);
$semaphore->up();
if(defined($report{site})){
my $site = $func->pega_site($report{report_id});
%conf = $c->loadconf();
# para o thread do ack, thread vai rodar enquanto $lock=1
$lock[$ins] = 1;
# cria o thread do ack
$thread = threads->new(\&ack, $waitTime, $ins, $report{report_id}) if(!$thread);
$func->insert("UPDATE report SET data_inicio=now() WHERE report_id = ".$report{report_id});
$ip = $func->GetServerIp($report{site});
$banner = "";
$banner = $func->GetServerInfo($report{site});
$banner =~s/'/\\'/g if(defined($banner));
$func->insert("UPDATE report SET ip='$ip', server_banner='$banner' WHERE report_id = ". $report{report_id});
#next if($banner =~/iis/gi);
#$func->logAdd($conf{'queue_log'}, "Iniciando Bing.pl em ". $report{site});
#system("perl $UNISCAN_DIR/BingIP.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando FingerPrint.pl em ". $report{site});
#system("perl $UNISCAN_DIR/FingerPrint.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando FingerPrint_server.pl em ". $report{site});
#system("perl $UNISCAN_DIR/FingerPrint_Server.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkHeartbleed.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkHeartbleed.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando Files.pl em ". $report{site});
#system("perl $UNISCAN_DIR/Files.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando Directory.pl em ". $report{site});
#system("perl $UNISCAN_DIR/Directory.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkWordpress.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkWordpress.pl $report{report_id}") if($func->checa_online($report{report_id}));
$func->logAdd($conf{'queue_log'}, "Iniciando Crawler.pl em ". $report{site});
system("perl $UNISCAN_DIR/Crawler.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkBlindSQLI.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkBlindSQLI.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkLFI.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkLFI.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkPHPCGI.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkPHPCGI.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkRCE.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkRCE.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkRFI.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkRFI.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkSQLI.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkSQLI.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkSQLiFriendlyURL.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkSQLiFriendlyURL.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkXSS.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkXSS.pl $report{report_id}") if($func->checa_online($report{report_id}));
#if(int($report{nivel}) == 4){
# $func->logAdd($conf{'queue_log'}, "Iniciando stress.pl em ". $report{site});
# system("perl $UNISCAN_DIR/stress.pl $report{report_id}") if($func->checa_online($report{report_id}));
#}
#$func->logAdd($conf{'queue_log'}, "Iniciando FCKeditor.pl em ". $report{site});
#system("perl $UNISCAN_DIR/FCKeditor.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando Timthumb.pl em ". $report{site});
#system("perl $UNISCAN_DIR/Timthumb.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando webShell.pl em ". $report{site});
#system("perl $UNISCAN_DIR/webShell.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkRCEarq.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkRCEarq.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkRFIarq.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkRFIarq.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkLFIarq.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkLFIarq.pl $report{report_id}") if($func->checa_online($report{report_id}));
#$func->logAdd($conf{'queue_log'}, "Iniciando checkBackup.pl em ". $report{site});
#system("perl $UNISCAN_DIR/checkBackup.pl $report{report_id}") if($func->checa_online($report{report_id}));
$func->logAdd($conf{'queue_log'}, "o scan de ". $report{site} . " terminou");
$func->insert("UPDATE report SET data_fim=now() WHERE report_id = $report{report_id}");
Uniscan::Queue->endScan(%report);
$lock[$ins] = 0;
# $thread->join();
# $thread = undef;
}
else{ sleep(30); }
#$thread->join;
#$thread = undef;
}
}
sub ack($$$){
my ($waitTime, $ins, $report_id) = @_;
while($lock[$ins]){
sleep(30);
Uniscan::Queue->sendAck($report_id) if($lock[$ins] == 1);
}
}
sub writePid(){
system("rm -f $pidlocation") if(-e "$pidlocation");
my $pidfile = File::Pid->new( { file => $pidlocation, } );
$pidfile->write or die "Erro ao criar o arquivo de PID, /dev/null: $!";
}