-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckRFIarq.pl
156 lines (127 loc) · 3.22 KB
/
checkRFIarq.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
#!/usr/bin/perl -w
use lib "./Uniscan";
use Uniscan::Configure;
use Uniscan::Functions;
use Uniscan::Http;
use threads;
use threads::shared;
use Thread::Queue;
use Thread::Semaphore;
my $c = Uniscan::Configure->new(conffile => "uniscan.conf");
my $func = Uniscan::Functions->new();
my $http = Uniscan::Http->new();
my $q = new Thread::Queue;
our %conf = ( );
%conf = $c->loadconf();
$|++;
#metricas
our $requests : shared = 0;
our %testado : shared = ();
our $arqs : shared = 0;
our $vuls : shared = "";
our %arqvul : shared = ();
our $arqv : shared = 0;
our $report_id :shared = $ARGV[0];
my $url = $func->pega_site($report_id);
my $semaphore = Thread::Semaphore->new();
my $t = threads->new(\&online);
&ScanStaticRFI($url);
$vuls =~s/'/\\'/gi;
$func->insert("INSERT INTO vulnerabilidade(report_id, dados, arq_testados, arq_vuls, var_testadas, var_vuls, reqs, tipo_id) VALUES($report_id, '$vuls', $arqs, $arqv, 0, 0, $requests, 30)");
$func->insert("UPDATE historico SET rfiest = $arqv WHERE report_id= $report_id");
while($q->pending > 0){
$q->dequeue;
}
$t->join();
sub ScanStaticRFI(){
my $url = shift;
open(my $a, "<DB/RFI") or die "$!\n";
my @tests = <$a>;
close($a);
my @urls = ();
foreach my $test (@tests){
chomp $test;
# $test = urlencode($test) if($conf{'url_encode'} == 1);
push(@urls, $url.$test);
}
&threadnize("TestRFI", @urls);
}
sub TestRFI(){
my ($resp, $test) = 0;
while($q->pending > 0){
$semaphore->down();
$test = $q->dequeue;
$semaphore->up();
next if(not defined $test);
$resp = $http->GET($test);
&metrica_testados($test);
$requests++;
if($resp =~/$conf{'rfi_return'}/){
$vuls .= $test . "\n";
&metricas_vul($test);
}
$resp = 0;
}
$q->enqueue(undef);
}
sub threadnize(){
my ($fun, @tests) = @_;
foreach my $test (@tests){
$q->enqueue($test) if($test);
}
my $x=0;
my @threads = ();
while($q->pending() && $x <= $conf{'max_threads'}-1){
no strict 'refs';
push @threads, threads->new(\&{$fun});
$x++;
}
sleep(2);
foreach my $running (@threads) {
$running->join();
}
@threads = ();
}
sub metricas_vul(){
my $url = shift;
if(!$arqvul{$func->get_file($url)}){
$arqvul{$func->get_file($url)} = 1;
$arqv++;
}
}
sub metrica_testados(){
my $url = shift;
if(!$testado{$func->get_file($url)}){
$testado{$func->get_file($url)}=1;
$arqs++;
}
}
sub checa_online(){
my $h = Uniscan::Http->new();
my $x=0;
my $site = $func->pega_site($report_id);
while ($x<=10) {
my $res = $h->GET1($site);
if ($res->is_success) {
return 1;
}
else{
sleep(30);
}
$x++;
}
&grava_waf();
return 0;
}
sub grava_waf(){
$func->insert("UPDATE report SET waf=1 WHERE report_id=". $report_id);
}
sub online(){
while(checa_online() && $q->pending > 0){
sleep(10);
}
#exit();
while($q->pending > 0){
$q->dequeue;
}
}