From d78b61e3efaea197a6e5b2b72bf2981a9ed69461 Mon Sep 17 00:00:00 2001 From: Rob Funk Date: Tue, 8 Jun 2004 03:59:01 +0000 Subject: Add files from ESR's dev directory that weren't under version control svn path=/trunk/; revision=3881 --- libntlm-0.21/test/dumper.c | 237 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 libntlm-0.21/test/dumper.c (limited to 'libntlm-0.21/test/dumper.c') diff --git a/libntlm-0.21/test/dumper.c b/libntlm-0.21/test/dumper.c new file mode 100644 index 00000000..aa84d127 --- /dev/null +++ b/libntlm-0.21/test/dumper.c @@ -0,0 +1,237 @@ +#include +#include +#include +#include + +#include "getargs.h" + +int from64tobits(char *out, const char *in); +void to64frombits(unsigned char *out, const unsigned char *in, int inlen); + +int dumpReq; +int dumpChal; +int dumpResp; +int genResp; +int dumpRaw; +int dumpb64only; +int genReq; + +char *username = "joeuser"; +char *password = "joespw"; + +argSpec argSpecArray[] = +{ + {'q', OptionBoolean, &dumpReq, NULL, "dump NTLM request", NULL}, + {'Q', OptionBoolean, &genReq, NULL, "generate (and dump) NTLM request", NULL}, + {'c', OptionBoolean, &dumpChal, NULL, "dump NTLM challange", NULL}, + {'g', OptionBoolean, &genResp, NULL, "generate (and dump) NTLM response given a challenge", NULL}, + {'r', OptionBoolean, &dumpResp, NULL, "dump NTLM response", NULL}, + {'R', OptionBoolean, &dumpRaw, NULL, "dump raw bytes", NULL}, + {'6', OptionBoolean, &dumpb64only, NULL, "dump generated base64 only", NULL}, + {'u', OptionString, &username, NULL, "username", NULL}, + {'p', OptionString, &password, NULL, "password", NULL}, +}; + +int argSpecCount = (sizeof argSpecArray / sizeof argSpecArray[0]); +char *progName; + +void usage(void) +{ + printf("usage: %s [options] [base-64-string]\n", progName); + printf(" %s -? will display options\n", progName); +} + +unsigned char buf[4096]; +unsigned char buf2[4096]; + +int main(int argc, char *argv[]) +{ + int rawLen = 0; + int argsUsed; + int i; + + progName = argv[0]; + + argsUsed = getargs(argc, argv, argSpecArray, argSpecCount); + + if (argsUsed < 0) + { + usage(); + exit(1); + } + + argc -= argsUsed; + argv += argsUsed; + + if (argc != 1 && argc != 0) + { + usage(); + exit(1); + } + + + if (argc == 1) + { + rawLen = from64tobits(buf,argv[0]); + if (genReq) + fprintf(stderr,"%s: extra argument with -Q ignored\n",progName); + } + else + { + if (dumpReq || dumpChal || dumpResp || dumpRaw) + { + fprintf(stderr,"%s: -q -r -c -R specified but no base64 data\n",progName); + return 1; + } + } + + + printf("Converted base64 string to %d data bytes\n",rawLen); + + if (dumpReq) + dumpSmbNtlmAuthRequest(stdout,(tSmbNtlmAuthRequest*)buf); + else if (dumpChal) + dumpSmbNtlmAuthChallenge(stdout,(tSmbNtlmAuthChallenge*)buf); + else if (dumpResp) + dumpSmbNtlmAuthResponse(stdout,(tSmbNtlmAuthResponse*)buf); + + if (dumpRaw) + for (i=0; i= 3; inlen -= 3) + { + *out++ = base64digits[in[0] >> 2]; + *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; + *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; + *out++ = base64digits[in[2] & 0x3f]; + in += 3; + } + if (inlen > 0) + { + unsigned char fragment; + + *out++ = base64digits[in[0] >> 2]; + fragment = (in[0] << 4) & 0x30; + if (inlen > 1) + fragment |= in[1] >> 4; + *out++ = base64digits[fragment]; + *out++ = (inlen < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c]; + *out++ = '='; + } + *out = '\0'; +} + +int from64tobits(char *out, const char *in) +/* base 64 to raw bytes in quasi-big-endian order, returning count of bytes */ +{ + int len = 0; + register unsigned char digit1, digit2, digit3, digit4; + + if (in[0] == '+' && in[1] == ' ') + in += 2; + if (*in == '\r') + return(0); + + do { + digit1 = in[0]; + if (DECODE64(digit1) == BAD) + return(-1); + digit2 = in[1]; + if (DECODE64(digit2) == BAD) + return(-1); + digit3 = in[2]; + if (digit3 != '=' && DECODE64(digit3) == BAD) + return(-1); + digit4 = in[3]; + if (digit4 != '=' && DECODE64(digit4) == BAD) + return(-1); + in += 4; + *out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4); + ++len; + if (digit3 != '=') + { + *out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2); + ++len; + if (digit4 != '=') + { + *out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4); + ++len; + } + } + } while + (*in && *in != '\r' && digit4 != '='); + + return (len); +} + +/* base64.c ends here */ -- cgit v1.2.3