line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package HTTP::CheckProxy; |
3
|
1
|
|
|
1
|
|
23733
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
106233
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
218831
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
14
|
use Exporter (); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
14
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
126
|
|
9
|
1
|
|
|
1
|
|
3
|
$VERSION = 0.4; |
10
|
1
|
|
|
|
|
23
|
@ISA = qw (Exporter); |
11
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
12
|
1
|
|
|
|
|
2
|
@EXPORT = qw (); |
13
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw (); |
14
|
1
|
|
|
|
|
928
|
%EXPORT_TAGS = (); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
########################################### main pod documentation begin ## |
19
|
|
|
|
|
|
|
# Below is the stub of documentation for your module. You better edit it! |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
HTTP::CheckProxy - Perl module for testing for open proxies |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use HTTP::CheckProxy |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This module uses LWP to test the supplied IP address to see if it will |
35
|
|
|
|
|
|
|
promiscuosly proxy on port 80. Caution: this can have false alarms if |
36
|
|
|
|
|
|
|
you are on a network where you are supposed to go through a proxy, |
37
|
|
|
|
|
|
|
such as AOL -- but are you supposed to be running a webserver on such |
38
|
|
|
|
|
|
|
a network ? |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
If you feed this an invalid ip address, LWP will complain. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Note: while there is HTTP::ProxyCheck it is much slower, though it |
43
|
|
|
|
|
|
|
does a lot of input validation. |
44
|
|
|
|
|
|
|
HTTP::CheckProxy is intended to be useful in processing lots of |
45
|
|
|
|
|
|
|
candidate proxies and in recording useful information. To do this, |
46
|
|
|
|
|
|
|
make one object and repeatedly invoke the test() method with |
47
|
|
|
|
|
|
|
different IP addresses. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 USAGE |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $open_proxy_test = HTTP::CheckProxy->new($ip); |
52
|
|
|
|
|
|
|
print "proxy test for $ip returns ".$open_proxy_test->code."\n"; |
53
|
|
|
|
|
|
|
print ($open_proxy_test->guilty? "guilty" : "innocent"); |
54
|
|
|
|
|
|
|
$open_proxy_test->test($ip2); |
55
|
|
|
|
|
|
|
print "proxy test for $ip2 returns ".$open_proxy_test->code."\n"; |
56
|
|
|
|
|
|
|
print ($open_proxy_test->guilty? "guilty" : "innocent"); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 BUGS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SUPPORT |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Email bugs to the author. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Dana Hudes |
69
|
|
|
|
|
|
|
CPAN ID: DHUDES |
70
|
|
|
|
|
|
|
dhudes@hudes.org |
71
|
|
|
|
|
|
|
http://www.hudes.org |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This program is free software licensed under the... |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The General Public License (GPL) |
78
|
|
|
|
|
|
|
Version 2, June 1991 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The full text of the license can be found in the |
81
|
|
|
|
|
|
|
LICENSE file included with this module. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SEE ALSO |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
perl(1). |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
############################################# main pod documentation end ## |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 new |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Usage : HTTP::CheckProxy->new($ip); |
97
|
|
|
|
|
|
|
Purpose : constructor |
98
|
|
|
|
|
|
|
Returns : object instance |
99
|
|
|
|
|
|
|
Argument : Optional first paramenter: |
100
|
|
|
|
|
|
|
name or ip address of candidate proxy. Do not include http:// . |
101
|
|
|
|
|
|
|
Optional second parameter: url (including the http://) to try to fetch. If this is invalid or unreachable the results of the test are meaningless, but this is NOT checked. |
102
|
|
|
|
|
|
|
Throws : We should probably throw an exception if the ip address under test is unreachable |
103
|
|
|
|
|
|
|
Comments : |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
See Also : HTTPD::ADS::AbuseNotify for sending complaints about validated proxies and other abuse. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $target_url="http://www.hudes.org"; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub new |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
1
|
15
|
my ($class, $ip, $target) = @_; |
114
|
1
|
|
33
|
|
|
11
|
my $self = bless ({}, ref ($class) || $class); |
115
|
1
|
50
|
|
|
|
5
|
$target_url= $target if defined $target; |
116
|
1
|
50
|
|
|
|
7
|
$self->test($ip) if defined $ip; |
117
|
1
|
|
|
|
|
1512
|
return ($self); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
{ |
122
|
|
|
|
|
|
|
my $response; |
123
|
|
|
|
|
|
|
sub get_response { |
124
|
2
|
|
|
2
|
0
|
15
|
return $response; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
sub _set_response { |
127
|
1
|
|
|
1
|
|
3
|
my ($self,$param) = @_; |
128
|
1
|
|
50
|
|
|
754
|
$response = $param || die "OpenProxyDetector - no response to store"; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 get_proxy_port |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Usage : $open_proxy_test->get_proxy_port; |
135
|
|
|
|
|
|
|
Purpose : tell which port successfully proxied |
136
|
|
|
|
|
|
|
Returns : 16-bit integer port number |
137
|
|
|
|
|
|
|
Argument : none |
138
|
|
|
|
|
|
|
Throws : nothing |
139
|
|
|
|
|
|
|
Comments : only valid when $open_proxy_test->guilty is TRUE , may be undef otherwise (or have incorrect info if you reused the object)! |
140
|
|
|
|
|
|
|
See Also : HTTPD::ADS::AbuseNotify for sending complaints about validated proxies and other abuse. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
my $port;#the port the proxy answered on |
146
|
|
|
|
|
|
|
sub get_proxy_port { |
147
|
0
|
|
|
0
|
1
|
0
|
return $port; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
sub _set_proxy_port { |
150
|
0
|
|
|
0
|
|
0
|
my ($self, $param) = @_; |
151
|
0
|
|
0
|
|
|
0
|
$port = $param || die "OpenProxyDetector - no port to store"; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
################################################ subroutine header begin ## |
156
|
|
|
|
|
|
|
=head2 test |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Usage : $open_proxy_test->test($ip) |
159
|
|
|
|
|
|
|
Purpose : tries to fetch a known web page via the supplied ip as proxy. |
160
|
|
|
|
|
|
|
Returns : true (proxy fetch successful) or false (it failed to fetch) |
161
|
|
|
|
|
|
|
Argument : IPv4 |
162
|
|
|
|
|
|
|
Throws : We should probably throw an exception if the ip address under test is unreachable |
163
|
|
|
|
|
|
|
Comments : Not all open proxies or compromised hosts listen on port 80 and their are other means than straightforward HTTP to communicate with zombies but this is a start. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See Also : HTTPD::ADS::AbuseNotify for sending complaints about validated proxies and other abuse. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
################################################## subroutine header end ## |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub test { |
171
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
172
|
1
|
|
50
|
|
|
7
|
my $ip = shift || die "no ip address supplied to test"; |
173
|
1
|
|
|
|
|
7
|
my @ports = qw/80 8080 8001 scx-proxy dproxy sdproxy funkproxy dpi-proxy proxy-gateway ace-proxy plgproxy csvr-proxy flamenco-proxy awg-proxy trnsprntproxy castorproxy ttlpriceprocy privoxy ezproxy ezproxy-2/;#1080 is SOCKS |
174
|
1
|
|
|
|
|
2
|
my $port; |
175
|
|
|
|
|
|
|
my $response; |
176
|
1
|
|
|
|
|
11
|
my $browser = LWP::UserAgent->new( |
177
|
|
|
|
|
|
|
timeout =>10, max_size =>2048, |
178
|
|
|
|
|
|
|
requests_redirectable => [] |
179
|
|
|
|
|
|
|
);#fixme -- come back later and stuff in a fake agent name |
180
|
1
|
|
|
|
|
4984
|
foreach $port (@ports) |
181
|
|
|
|
|
|
|
{ |
182
|
20
|
|
|
|
|
812
|
$browser->proxy("http","http://$ip:".$port); |
183
|
20
|
|
|
|
|
3368
|
$response = $browser->head($target_url); |
184
|
20
|
50
|
|
|
|
382424357
|
last unless defined $response; |
185
|
20
|
50
|
|
|
|
88
|
if(! $response->is_error) {#keep going while we don't get a successful proxying |
186
|
0
|
|
|
|
|
0
|
$self->_set_proxy_port($port); |
187
|
0
|
|
|
|
|
0
|
last; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
1
|
|
|
|
|
55
|
$self->_set_response($response); |
191
|
1
|
|
|
|
|
19
|
return $response->code(); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 guilty |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Usage : $open_proxy_test->guilty |
198
|
|
|
|
|
|
|
Purpose : Is in fact the tested host guilty of being an open proxy? |
199
|
|
|
|
|
|
|
Returns : true (its an open proxy) or false (it isn't) |
200
|
|
|
|
|
|
|
Argument : none |
201
|
|
|
|
|
|
|
Throws : nothing |
202
|
|
|
|
|
|
|
Comments : This method checks the return status code of the test. If an error code is returned, esp. code 500, the host is not guilty. If the status code is success, the host is guilty. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
See Also : HTTPD::ADS::AbuseNotify for sending complaints about validated proxies and other abuse. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub guilty { |
209
|
1
|
|
|
1
|
1
|
434
|
my $self = shift; |
210
|
|
|
|
|
|
|
#we should get an error if its not an open proxy; informational etc. is not the right thing.... |
211
|
1
|
|
|
|
|
5
|
return ! ( ($self->get_response)->is_error); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 code |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Usage : $open_proxy_test->code |
217
|
|
|
|
|
|
|
Purpose : Return the status code of the proxy test |
218
|
|
|
|
|
|
|
Returns : HTTP status code |
219
|
|
|
|
|
|
|
Argument : none |
220
|
|
|
|
|
|
|
Throws : nothing |
221
|
|
|
|
|
|
|
Comments : |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
See Also : HTTPD::ADS::AbuseNotify for sending complaints about validated proxies and other abuse. |
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub code { |
227
|
1
|
|
|
1
|
1
|
4710
|
my $self = shift; |
228
|
1
|
|
|
|
|
8
|
return ($self->get_response)->code(); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
1; #this line is important and will help the module return a true value |
232
|
|
|
|
|
|
|
__END__ |