/[svn]/hopm/branches/1.0.x/src/libopm/src/proxy.c
ViewVC logotype

Contents of /hopm/branches/1.0.x/src/libopm/src/proxy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5309 - (show annotations)
Mon Jan 5 18:15:48 2015 UTC (7 years, 5 months ago) by michael
File MIME type: text/x-chdr
File size: 7070 byte(s)
- proxy.c: removed unused header include

1 /* Copyright (C) 2002 Erik Fears
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to
15 *
16 * The Free Software Foundation, Inc.
17 * 59 Temple Place - Suite 330
18 * Boston, MA 02111-1307, USA.
19 *
20 *
21 */
22
23 #include "setup.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "inet.h"
30 #include "config.h"
31 #include "proxy.h"
32 #include "opm_common.h"
33 #include "opm_types.h"
34 #include "opm_error.h"
35 #include "libopm.h"
36
37
38 static char SENDBUF[SENDBUFLEN + 1];
39
40 int libopm_proxy_http_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
41 {
42 snprintf(SENDBUF, SENDBUFLEN, "CONNECT %s:%d HTTP/1.0\r\n\r\n",
43 (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP),
44 *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT));
45
46 if(send(conn->fd, SENDBUF, strlen(SENDBUF), 0) == -1)
47 return 0; /* Return error code ? */
48
49 return OPM_SUCCESS;
50 }
51
52
53 /*
54 * CONNECT request byte order for socks4
55 *
56 * +----+----+----+----+----+----+----+----+----+----+....+----+
57 * | VN | CD | DSTPORT | DSTIP | USERID |NULL|
58 * +----+----+----+----+----+----+----+----+----+----+....+----+
59 * # of bytes: 1 1 2 4 variable 1
60 *
61 * VN = Version, CD = Command Code (1 is connect request)
62 */
63
64 int libopm_proxy_socks4_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
65 {
66 struct in_addr addr;
67 unsigned long laddr;
68 int len, scan_port;
69 char *scan_ip;
70
71 scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
72 scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
73
74 if (inet_pton(AF_INET, scan_ip, &addr) <= 0)
75 ; /* handle error */
76
77 laddr = htonl(addr.s_addr);
78
79 len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c", 4, 1,
80 (((unsigned short) scan_port) >> 8) & 0xFF,
81 (((unsigned short) scan_port) & 0xFF),
82 (char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF,
83 (char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF, 0);
84
85 send(conn->fd, SENDBUF, (unsigned int)len, 0);
86
87 return OPM_SUCCESS;
88 }
89
90
91 /*
92 * Send version authentication selection message to socks5
93 *
94 * +----+----------+----------+
95 * |VER | NMETHODS | METHODS |
96 * +----+----------+----------+
97 * | 1 | 1 | 1 to 255 |
98 * +----+----------+----------+
99 *
100 * VER always contains 5, for socks version 5
101 * Method 0 is 'No authentication required'
102 *
103 *
104 *
105 * The SOCKS request is formed as follows:
106 *
107 * +----+-----+-------+------+----------+----------+
108 * |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
109 * +----+-----+-------+------+----------+----------+
110 * | 1 | 1 | X'00' | 1 | Variable | 2 |
111 * +----+-----+-------+------+----------+----------+
112 *
113 *
114 * o VER protocol version: X'05'
115 * o CMD
116 * o CONNECT X'01'
117 * o BIND X'02'
118 * o UDP ASSOCIATE X'03'
119 * o RSV RESERVED
120 * o ATYP address type of following address
121 * o IP V4 address: X'01'
122 * o DOMAINNAME: X'03'
123 * o IP V6 address: X'04'
124 * o DST.ADDR desired destination address
125 * o DST.PORT desired destination port in network octet
126 * order
127 *
128 *
129 */
130
131 int libopm_proxy_socks5_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
132 {
133 struct in_addr addr;
134 unsigned long laddr;
135 int len, scan_port;
136 char *scan_ip;
137
138 scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
139 scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
140
141 if (inet_pton(AF_INET, scan_ip, &addr) <= 0)
142 ; /* handle error */
143
144 laddr = htonl(addr.s_addr);
145
146 /* Form authentication string */
147 /* Version 5, 1 number of methods, 0 method (no auth). */
148 len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c", 5, 1, 0);
149 send(conn->fd, SENDBUF, (unsigned int)len, 0);
150
151 /* Form request string */
152
153 /* Will need to write ipv6 support here in future
154 * as socks5 is ipv6 compatible
155 */
156 len = snprintf(SENDBUF, SENDBUFLEN, "%c%c%c%c%c%c%c%c%c%c", 5, 1, 0, 1,
157 (char) (laddr >> 24) & 0xFF, (char) (laddr >> 16) & 0xFF,
158 (char) (laddr >> 8) & 0xFF, (char) laddr & 0xFF,
159 (((unsigned short) scan_port) >> 8) & 0xFF,
160 (((unsigned short) scan_port) & 0xFF));
161
162 send(conn->fd, SENDBUF, (unsigned int)len, 0);
163
164 return OPM_SUCCESS;
165 }
166
167 /*
168 * Open wingates require no authentication, they will send a prompt when
169 * connect.
170 */
171
172 int libopm_proxy_wingate_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
173 {
174 int scan_port, len;
175 char *scan_ip;
176
177 scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
178 scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
179
180 len = snprintf(SENDBUF, SENDBUFLEN, "%s:%d\r\n", scan_ip, scan_port);
181 send(conn->fd, SENDBUF, (unsigned int)len, 0);
182
183 return OPM_SUCCESS;
184 }
185
186
187 /*
188 * Cisco scanning
189 *
190 * Some cisco routers have 'cisco' set as password which allow open telnet
191 * relay. Attempt to connect using cisco as a password, then give command for
192 * telnet to the scanip/scanport
193 */
194
195 int libopm_proxy_router_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
196 {
197 int len, scan_port;
198 char *scan_ip;
199
200 scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
201 scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
202
203 len = snprintf(SENDBUF, SENDBUFLEN, "cisco\r\n");
204 send(conn->fd, SENDBUF, (unsigned int)len, 0);
205
206 len = snprintf(SENDBUF, SENDBUFLEN, "telnet %s %d\r\n", scan_ip, scan_port);
207 send(conn->fd, SENDBUF, (unsigned int)len, 0);
208
209 return OPM_SUCCESS;
210 }
211
212
213 /*
214 * HTTP POST Scanning
215 *
216 */
217
218 int libopm_proxy_httppost_write(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
219 {
220 int len, scan_port;
221 char *scan_ip;
222
223 scan_ip = (char *) libopm_config(scanner->config, OPM_CONFIG_SCAN_IP);
224 scan_port = *(int *) libopm_config(scanner->config, OPM_CONFIG_SCAN_PORT);
225
226 len = snprintf(SENDBUF, SENDBUFLEN, "POST http://%s:%d/ HTTP/1.0\r\n"
227 "Content-type: text/plain\r\n"
228 "Content-length: 5\r\n\r\n"
229 "quit\r\n\r\n",
230 scan_ip, scan_port);
231
232 send(conn->fd, SENDBUF, (unsigned int)len, 0);
233
234 return OPM_SUCCESS;
235 }

Properties

Name Value
svn:eol-style native
svn:keywords Id

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28