2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 * MS Proxy (ISA server) support is (c) 2006 Pavel Fedin <sonic_amiga@rambler.ru>
19 * based on Dante source code
20 * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
21 * Inferno Nettverk A/S, Norway. All rights reserved.
26 #define MSPROXY_EXECUTABLE "xchat.exe" /* This probably can be used for access control on the server side */
28 #define MSPROXY_MINLENGTH 172 /* minimum length of packet. */
29 #define NT_MAXNAMELEN 17 /* maximum name length (domain etc), comes from NetBIOS */
30 #define MSPROXY_VERSION 0x00010200 /* MS Proxy v2 ? */
32 /* Commands / responses */
33 #define MSPROXY_HELLO 0x0500 /* packet 1 from client. */
34 #define MSPROXY_HELLO_ACK 0x1000 /* packet 1 from server. */
36 #define MSPROXY_USERINFO_ACK 0x0400 /* packet 2 from server. */
38 #define MSPROXY_AUTHENTICATE 0x4700 /* authentication request */
39 #define MSPROXY_AUTHENTICATE_ACK 0x4714 /* authentication challenge */
41 #define MSPROXY_AUTHENTICATE_2 0x4701 /* authentication response */
42 #define MSPROXY_AUTHENTICATE_2_ACK 0x4715 /* authentication passed */
43 #define MSPROXY_AUTHENTICATE_2_NAK 0x4716 /* authentication failure */
45 #define MSPROXY_CONNECT 0x071e /* connect request. */
46 #define MSPROXY_CONNECT_ACK 0x0703 /* connect request accepted. */
56 struct msproxy_request_t
{
57 guint32 clientid
; /* 1-4 */
58 guint32 magic25
; /* 5-8 */
59 guint32 serverid
; /* 9-12 */
60 unsigned char serverack
; /* 13: ack of last server packet */
61 char pad10
[3]; /* 14-16 */
62 unsigned char sequence
; /* 17: sequence # of this packet. */
63 char pad11
[7]; /* 18-24 */
64 char RWSP
[4]; /* 25-28: 0x52,0x57,0x53,0x50 */
65 char pad15
[8]; /* 29-36 */
66 guint16 command
; /* 37-38 */
68 /* packet specifics start at 39. */
71 char pad1
[18]; /* 39-56 */
72 guint16 magic3
; /* 57-58 */
73 char pad3
[114]; /* 59-172 */
74 guint16 magic5
; /* 173-174: 0x4b, 0x00 */
75 char pad5
[2]; /* 175-176 */
76 guint16 magic10
; /* 177-178: 0x14, 0x00 */
77 char pad6
[2]; /* 179-180 */
78 guint16 magic15
; /* 181-182: 0x04, 0x00 */
79 char pad10
[2]; /* 183-184 */
80 guint16 magic16
; /* 185-186 */
81 char pad11
[2]; /* 187-188 */
82 guint16 magic20
; /* 189-190: 0x57, 0x04 */
83 guint16 magic25
; /* 191-192: 0x00, 0x04 */
84 guint16 magic30
; /* 193-194: 0x01, 0x00 */
85 char pad20
[2]; /* 195-196: 0x4a, 0x02 */
86 guint16 magic35
; /* 197-198: 0x4a, 0x02 */
87 char pad30
[10]; /* 199-208 */
88 guint16 magic40
; /* 209-210: 0x30, 0x00 */
89 char pad40
[2]; /* 211-212 */
90 guint16 magic45
; /* 213-214: 0x44, 0x00 */
91 char pad45
[2]; /* 215-216 */
92 guint16 magic50
; /* 217-218: 0x39, 0x00 */
93 char pad50
[2]; /* 219-220 */
94 char data
[256]; /* 221-EOP: a sequence of NULL-terminated strings:
96 - empty string (just a NULL);
102 char pad1
[4]; /* 39-42 */
103 guint16 magic2
; /* 43-44 */
104 char pad10
[12]; /* 45-56 */
105 guint32 bindaddr
; /* 57-60: address to bind. */
106 guint16 bindport
; /* 61-62: port to bind. */
107 char pad15
[2]; /* 63-64 */
108 guint16 magic3
; /* 65-66 */
109 guint16 boundport
; /* 67-68 */
110 char pad20
[104]; /* 69-172 */
111 char NTLMSSP
[sizeof("NTLMSSP")]; /* 173-180: "NTLMSSP" */
112 guint32 msgtype
; /* 181-184: NTLM message type = 1 */
113 guint32 flags
; /* 185-188: NTLM message flags */
114 guint16 magic20
; /* 189-190: 0x28, 0x00 */
115 char pad30
[2]; /* 191-192 */
116 guint16 magic25
; /* 193-194: 0x96, 0x82 */
117 guint16 magic30
; /* 195-196: 0x01, 0x00 */
118 char pad40
[12]; /* 197-208 */
119 guint16 magic50
; /* 209-210: 0x30, 0x00 */
120 char pad50
[6]; /* 211-216 */
121 guint16 magic55
; /* 217-218: 0x30, 0x00 */
122 char pad55
[2]; /* 219-220 */
123 char data
[0]; /* Dummy end marker, no real data required */
127 char pad1
[4]; /* 39-42 */
128 guint16 magic1
; /* 43-44 */
129 guint32 magic2
; /* 45-48 */
130 char pad2
[8]; /* 49-56 */
131 guint16 magic3
; /* 57-58 */
132 char pad3
[6]; /* 59-64 */
133 guint16 magic4
; /* 65-66 */
134 guint16 boundport
; /* 67-68 */
135 char pad4
[104]; /* 69-172 */
136 char NTLMSSP
[sizeof("NTLMSSP")]; /* 173-180: "NTLMSSP" */
137 guint32 msgtype
; /* 181-184: NTLM message type = 3 */
138 struct ntlm_buffer lm_resp
; /* 185-192: LM response security buffer */
139 struct ntlm_buffer ntlm_resp
; /* 193-200: NTLM response security buffer */
140 struct ntlm_buffer ntdomain_buf
; /* 201-208: domain name security buffer */
141 struct ntlm_buffer username_buf
; /* 209-216: username security buffer */
142 struct ntlm_buffer clienthost_buf
; /* 217-224: hostname security buffer */
143 struct ntlm_buffer sessionkey_buf
; /* 225-232: session key security buffer */
144 guint32 flags
; /* 233-236: message flags */
145 char data
[1024]; /* 237-EOP: data area */
149 guint16 magic1
; /* 39-40 */
150 char pad1
[2]; /* 41-42 */
151 guint16 magic2
; /* 43-44 */
152 guint32 magic3
; /* 45-48 */
153 char pad5
[8]; /* 48-56 */
154 guint16 magic6
; /* 57-58: 0x0200 */
155 guint16 destport
; /* 59-60 */
156 guint32 destaddr
; /* 61-64 */
157 char pad10
[4]; /* 65-68 */
158 guint16 magic10
; /* 69-70 */
159 char pad15
[2]; /* 71-72 */
160 guint16 srcport
; /* 73-74: port client connects from */
161 char pad20
[82]; /* 75-156 */
162 char executable
[256]; /* 76-EOP: application name */
166 guint16 magic1
; /* 39-40 */
167 char pad5
[2]; /* 41-42 */
168 guint16 magic5
; /* 43-44 */
169 guint32 magic10
; /* 45-48 */
170 char pad10
[2]; /* 49-50 */
171 guint16 magic15
; /* 51-52 */
172 guint32 magic16
; /* 53-56 */
173 guint16 magic20
; /* 57-58 */
174 guint16 clientport
; /* 59-60: forwarded port. */
175 guint32 clientaddr
; /* 61-64: forwarded address. */
176 guint32 magic30
; /* 65-68 */
177 guint32 magic35
; /* 69-72 */
178 guint16 serverport
; /* 73-74: port server will connect to us from. */
179 guint16 srcport
; /* 75-76: connect request; port used on client behalf. */
180 guint16 boundport
; /* 77-78: bind request; port used on client behalf. */
181 guint32 boundaddr
; /* 79-82: addr used on client behalf */
182 char pad30
[90]; /* 83-172 */
183 char data
[0]; /* End marker */
189 struct msproxy_response_t
{
190 guint32 packetid
; /* 1-4 */
191 guint32 magic5
; /* 5-8 */
192 guint32 serverid
; /* 9-12 */
193 char clientack
; /* 13: ack of last client packet. */
194 char pad5
[3]; /* 14-16 */
195 unsigned char sequence
; /* 17: sequence # of this packet. */
196 char pad10
[7]; /* 18-24 */
197 char RWSP
[4]; /* 25-28: 0x52,0x57,0x53,0x50 */
198 char pad15
[8]; /* 29-36 */
199 guint16 command
; /* 37-38 */
203 char pad5
[18]; /* 39-56 */
204 guint16 magic20
; /* 57-58: 0x02, 0x00 */
205 char pad10
[6]; /* 59-64 */
206 guint16 magic30
; /* 65-66: 0x74, 0x01 */
207 char pad15
[2]; /* 67-68 */
208 guint16 magic35
; /* 69-70: 0x0c, 0x00 */
209 char pad20
[6]; /* 71-76 */
210 guint16 magic50
; /* 77-78: 0x04, 0x00 */
211 char pad30
[6]; /* 79-84 */
212 guint16 magic60
; /* 85-86: 0x65, 0x05 */
213 char pad35
[2]; /* 87-88 */
214 guint16 magic65
; /* 89-90: 0x02, 0x00 */
215 char pad40
[8]; /* 91-98 */
216 guint16 udpport
; /* 99-100 */
217 guint32 udpaddr
; /* 101-104 */
221 char pad1
[6]; /* 39-44 */
222 guint32 magic10
; /* 45-48 */
223 char pad3
[10]; /* 49-58 */
224 guint16 boundport
; /* 59-60: port server bound for us. */
225 guint32 boundaddr
; /* 61-64: addr server bound for us. */
226 char pad10
[4]; /* 65-68 */
227 guint16 magic15
; /* 69-70 */
228 char pad15
[102]; /* 70-172 */
229 char NTLMSSP
[sizeof("NTLMSSP")]; /* 173-180: "NTLMSSP" */
230 guint32 msgtype
; /* 181-184: NTLM message type = 2 */
231 struct ntlm_buffer target
; /* 185-192: target security buffer */
232 guint32 flags
; /* 193-196: NTLM message flags */
233 char challenge
[8]; /* 197-204: NTLM challenge request */
234 char context
[8]; /* 205-212: NTLM context */
235 char data
[1024]; /* 213-EOP: target information data */
239 guint16 magic1
; /* 39-40 */
240 char pad5
[18]; /* 41-58 */
241 guint16 clientport
; /* 59-60: forwarded port. */
242 guint32 clientaddr
; /* 61-64: forwarded address. */
243 guint32 magic10
; /* 65-68 */
244 guint32 magic15
; /* 69-72 */
245 guint16 serverport
; /* 73-74: port server will connect to us from. */
246 guint16 srcport
; /* 75-76: connect request; port used on client behalf. */
247 guint16 boundport
; /* 77-78: bind request; port used on client behalf. */
248 guint32 boundaddr
; /* 79-82: addr used on client behalf */
249 char pad10
[90]; /* 83-172 */
256 int traverse_msproxy (int sok
, char *serverAddr
, int port
, struct msproxy_state_t
*state
, netstore
*ns_proxy
, int csok4
, int csok6
, int *csok
, char bound
);
257 void msproxy_keepalive (void);