Go to the documentation of this file.
63 #define SEND(X) debug("sending '%s' to squid\n",X); printf(X "\n");
65 #define SEND2(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
66 #define SEND3(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
69 #define SEND2(X,Y) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
70 #define SEND3(X,Y,Z) debug("sending '" X "' to squid\n",Y,Z); printf(X "\n",Y,Z);
84 "Usage: %s [-d] [-v] [-h]\n"
85 " -d enable debugging.\n"
86 " -v enable verbose Negotiate packet debugging.\n"
87 " -h this message\n\n",
94 int opt, had_error = 0;
97 while (-1 != (opt =
getopt(argc, argv,
"hdv"))) {
113 fprintf(stderr,
"ERROR: unknown option: -%c. Exiting\n", opt);
129 SEND(
"BH base64 decode failed");
130 fprintf(stderr,
"ERROR: base64 decoding failed for: '%s'\n", buf);
141 size_t decodedLen = 0;
142 char helper_command[3];
157 SEND(
"BH illegal request received");
158 fprintf(stderr,
"ERROR: Illegal request received: '%s'\n", buf);
163 fprintf(stderr,
"No newline in '%s'\n", buf);
171 strncpy(helper_command, buf, 2);
172 debug(
"Got '%s' from Squid with data:\n", helper_command);
173 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
175 debug(
"Got '%s' from Squid\n", buf);
177 if (memcmp(buf,
"YR ", 3) == 0) {
179 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
181 if (decodedLen <
sizeof(
ntlmhdr)) {
182 SEND(
"NA * Packet format error");
186 c = (
char *) SSP_MakeNegotiateBlob(decoded, decodedLen, &Done, &status, cred);
196 debug(
"sending 'AF' %s to squid with data:\n", cred);
198 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
200 fprintf(stderr,
"No data available.\n");
201 printf(
"AF %s %s\n", c, cred);
203 SEND3(
"AF %s %s", c, cred);
208 debug(
"sending 'TT' to squid with data:\n");
209 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
210 printf(
"TT %s\n", c);
217 SEND(
"BH can't obtain server blob");
220 if (memcmp(buf,
"KK ", 3) == 0) {
222 SEND(
"BH invalid server blob");
226 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
228 if (decodedLen <
sizeof(
ntlmhdr)) {
229 SEND(
"NA * Packet format error");
233 c = (
char *) SSP_ValidateNegotiateCredentials(decoded, decodedLen, &Done, &status, cred);
236 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
237 FORMAT_MESSAGE_IGNORE_INSERTS,
240 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
241 (LPTSTR) & ErrorMessage,
244 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\n')
245 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
246 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\r')
247 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
248 SEND2(
"NA * %s", ErrorMessage);
249 LocalFree(ErrorMessage);
259 debug(
"sending 'AF' %s to squid with data:\n", cred);
261 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
263 fprintf(stderr,
"No data available.\n");
264 printf(
"AF %s %s\n", c, cred);
266 SEND3(
"AF %s %s", c, cred);
273 debug(
"sending 'TT' to squid with data:\n");
274 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
275 printf(
"TT %s\n", c);
282 SEND(
"BH illegal request received");
283 fprintf(stderr,
"Illegal request received: '%s'\n", buf);
286 SEND(
"BH detected protocol error");
301 fprintf(stderr,
"FATAL: %s: can't initialize SSPI, exiting.\n", argv[0]);
304 debug(
"SSPI initialized OK\n");
309 setbuf(stdout,
nullptr);
310 setbuf(stderr,
nullptr);
int main(int argc, char *argv[])
void debug(const char *format,...)
void base64_decode_init(struct base64_decode_ctx *ctx)
HMODULE LoadSecurityDll(int mode, const char *SSP_Package)
int getopt(int nargc, char *const *nargv, const char *ostr)
int base64_decode_final(struct base64_decode_ctx *ctx)
int Negotiate_packet_debug_enabled
void UnloadSecurityDll(void)
int base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, const char *src)
static int manage_request()
#define HELPER_INPUT_BUFFER
#define NEGOTIATE_PACKAGE_NAME
static void process_options(int argc, char *argv[])
static bool token_decode(size_t *decodedLen, uint8_t decoded[], const char *buf)
void hex_dump(unsigned char *data, int size)
static int have_serverblob