/[svn]/hopm/trunk/src/libopm/src/proxy.c
ViewVC logotype

Contents of /hopm/trunk/src/libopm/src/proxy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5137 - (show annotations)
Thu Dec 25 19:36:37 2014 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 7108 byte(s)
- Removed vim settings from the source files

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

Properties

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

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