ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/libopm/src/proxy.c
Revision: 5135
Committed: Thu Dec 25 18:51:51 2014 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 7162 byte(s)
Log Message:
- propset svn:eol-style native

File Contents

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

Properties

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