1 |
/* |
2 |
* Copyright (C) 2002 Erik Fears |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License |
6 |
* as published by the Free Software Foundation; either version 2 |
7 |
* of the License, or (at your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
* GNU General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to |
16 |
* |
17 |
* The Free Software Foundation, Inc. |
18 |
* 59 Temple Place - Suite 330 |
19 |
* Boston, MA 02111-1307, USA. |
20 |
* |
21 |
* |
22 |
*/ |
23 |
|
24 |
#include "setup.h" |
25 |
|
26 |
#include <stdio.h> |
27 |
#include "opm.h" |
28 |
#include "opm_error.h" |
29 |
#include "opm_types.h" |
30 |
#include "compat.h" |
31 |
#ifdef HAVE_UNISTD_H |
32 |
# include <unistd.h> |
33 |
#endif |
34 |
|
35 |
|
36 |
#define ARRAY_SIZEOF(x) (sizeof(x) / sizeof((x)[0])) |
37 |
|
38 |
void open_proxy(OPM_T *, OPM_REMOTE_T *, int, void *); |
39 |
void negotiation_failed(OPM_T *, OPM_REMOTE_T *, int, void *); |
40 |
void timeout(OPM_T *, OPM_REMOTE_T *, int, void *); |
41 |
void end(OPM_T *, OPM_REMOTE_T *, int, void *); |
42 |
void handle_error(OPM_T *, OPM_REMOTE_T *, int, void *); |
43 |
|
44 |
int complete = 0; |
45 |
|
46 |
int main(int argc, char **argv) |
47 |
{ |
48 |
OPM_ERR_T err; |
49 |
int fdlimit = 1024; |
50 |
int scan_port = 6667; |
51 |
int max_read = 4096; |
52 |
int scantimeout = 10; |
53 |
unsigned int i, s; |
54 |
|
55 |
unsigned short http_ports[] = { |
56 |
8000, 8080, 3128, 80 |
57 |
}; |
58 |
|
59 |
unsigned short wingate_ports[] = { |
60 |
23 |
61 |
}; |
62 |
|
63 |
unsigned short router_ports[] = { |
64 |
23 |
65 |
}; |
66 |
|
67 |
unsigned short socks4_ports[] = { |
68 |
1080 |
69 |
}; |
70 |
|
71 |
unsigned short socks5_ports[] = { |
72 |
1080 |
73 |
}; |
74 |
|
75 |
unsigned short httppost_ports[] = { |
76 |
80, 8090, 3128 |
77 |
}; |
78 |
|
79 |
OPM_T *scanner; |
80 |
OPM_REMOTE_T *remote; |
81 |
|
82 |
scanner = opm_create(); |
83 |
|
84 |
if(argc >= 2) |
85 |
remote = opm_remote_create(argv[1]); |
86 |
else |
87 |
remote = opm_remote_create("127.0.0.1"); |
88 |
|
89 |
/* Setup callbacks */ |
90 |
opm_callback(scanner, OPM_CALLBACK_OPENPROXY, &open_proxy, NULL); |
91 |
opm_callback(scanner, OPM_CALLBACK_NEGFAIL, &negotiation_failed, NULL); |
92 |
opm_callback(scanner, OPM_CALLBACK_TIMEOUT, &timeout, NULL); |
93 |
opm_callback(scanner, OPM_CALLBACK_END, &end, NULL); |
94 |
opm_callback(scanner, OPM_CALLBACK_ERROR, &handle_error, NULL); |
95 |
|
96 |
|
97 |
/* Setup the scanner configuration */ |
98 |
opm_config(scanner, OPM_CONFIG_FD_LIMIT, &fdlimit); |
99 |
opm_config(scanner, OPM_CONFIG_SCAN_IP, "216.175.104.202"); |
100 |
opm_config(scanner, OPM_CONFIG_SCAN_PORT, &scan_port); |
101 |
opm_config(scanner, OPM_CONFIG_TARGET_STRING, "*** Looking up your hostname..."); |
102 |
opm_config(scanner, OPM_CONFIG_TARGET_STRING, "ERROR :Trying to reconnect too fast."); |
103 |
opm_config(scanner, OPM_CONFIG_TIMEOUT, &scantimeout); |
104 |
opm_config(scanner, OPM_CONFIG_MAX_READ, &max_read); |
105 |
|
106 |
/* Setup the protocol configuration */ |
107 |
for (s = ARRAY_SIZEOF(http_ports), i = 0; i < s; i++) { |
108 |
opm_addtype(scanner, OPM_TYPE_HTTP, http_ports[i]); |
109 |
} |
110 |
|
111 |
for (s = ARRAY_SIZEOF(wingate_ports), i = 0; i < s; i++) { |
112 |
opm_addtype(scanner, OPM_TYPE_WINGATE, wingate_ports[i]); |
113 |
} |
114 |
|
115 |
for (s = ARRAY_SIZEOF(router_ports), i = 0; i < s; i++) { |
116 |
opm_addtype(scanner, OPM_TYPE_ROUTER, router_ports[i]); |
117 |
} |
118 |
|
119 |
for (s = ARRAY_SIZEOF(socks4_ports), i = 0; i < s; i++) { |
120 |
opm_addtype(scanner, OPM_TYPE_SOCKS4, socks4_ports[i]); |
121 |
} |
122 |
|
123 |
for (s = ARRAY_SIZEOF(socks5_ports), i = 0; i < s; i++) { |
124 |
opm_addtype(scanner, OPM_TYPE_SOCKS5, socks5_ports[i]); |
125 |
} |
126 |
|
127 |
for (s = ARRAY_SIZEOF(httppost_ports), i = 0; i < s; i++) { |
128 |
opm_addtype(scanner, OPM_TYPE_HTTPPOST, httppost_ports[i]); |
129 |
} |
130 |
|
131 |
/* Remote structs can also have their own extended protocol configurations. For instance |
132 |
if the target hostname contains strings such as 'proxy' or 'www', extended ports could |
133 |
be scanned. */ |
134 |
opm_remote_addtype(remote, OPM_TYPE_HTTP, 8001); |
135 |
opm_remote_addtype(remote, OPM_TYPE_HTTP, 8002); |
136 |
|
137 |
switch(err = opm_scan(scanner, remote)) |
138 |
{ |
139 |
case OPM_SUCCESS: |
140 |
break; |
141 |
case OPM_ERR_BADADDR: |
142 |
printf("Bad address\n"); |
143 |
opm_free(scanner); |
144 |
opm_remote_free(remote); |
145 |
return 0; |
146 |
default: |
147 |
printf("Unknown Error %d\n", err); |
148 |
return 0; |
149 |
} |
150 |
|
151 |
|
152 |
while(!complete) |
153 |
opm_cycle(scanner); |
154 |
|
155 |
opm_free(scanner); |
156 |
|
157 |
return 0; |
158 |
} |
159 |
|
160 |
void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, |
161 |
void *data) |
162 |
{ |
163 |
printf("Open proxy on %s:%d [%d bytes read]\n", remote->ip, |
164 |
remote->port, remote->bytes_read); |
165 |
opm_end(scanner, remote); |
166 |
} |
167 |
|
168 |
void negotiation_failed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, |
169 |
void *data) |
170 |
{ |
171 |
printf("Negotiation on %s:%d failed [%d bytes read]\n", remote->ip, |
172 |
remote->port, remote->bytes_read); |
173 |
} |
174 |
|
175 |
void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data) |
176 |
{ |
177 |
printf("Negotiation timed out on %s:%d\n", remote->ip, remote->port); |
178 |
} |
179 |
|
180 |
void end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data) |
181 |
{ |
182 |
printf("Scan on %s has ended\n", remote->ip); |
183 |
opm_remote_free(remote); |
184 |
complete = 1; |
185 |
} |
186 |
|
187 |
void handle_error(OPM_T *scanner, OPM_REMOTE_T *remote, int err, void *data) |
188 |
{ |
189 |
switch(err) |
190 |
{ |
191 |
case OPM_ERR_MAX_READ: |
192 |
printf("Reached MAX READ on %s:%d\n", remote->ip, remote->port); |
193 |
break; |
194 |
case OPM_ERR_BIND: |
195 |
printf("Unable to bind for %s:%d\n", remote->ip, remote->port); |
196 |
break; |
197 |
case OPM_ERR_NOFD: |
198 |
printf("Unable to allocate file descriptor for %s:%d\n", |
199 |
remote->ip, remote->port); |
200 |
break; |
201 |
default: |
202 |
printf("Unknown error on %s:%d, err = %d\n", remote->ip, |
203 |
remote->port, err); |
204 |
} |
205 |
} |