C:/Web/smbrelay3/src/ntlm.cpp File Reference

#include "ntlm.h"
#include "misc.h"
#include <openssl/md4.h>
#include <openssl/des.h>

Include dependency graph for ntlm.cpp:

Go to the source code of this file.

Defines

#define _CRT_SECURE_NO_DEPRECATE
#define WORD   unsigned short
#define RW_PCVAL(read, inbuf, outbuf, len)
#define RW_PIVAL(read, big_endian, inbuf, outbuf, len)
#define RW_PSVAL(read, big_endian, inbuf, outbuf, len)
#define RW_CVAL(read, inbuf, outbuf, offset)
#define RW_IVAL(read, big_endian, inbuf, outbuf, offset)
#define RW_SVAL(read, big_endian, inbuf, outbuf, offset)
#define CAREFUL_ALIGNMENT   1
#define CVAL(buf, pos)   (((unsigned char *)(buf))[pos])
#define PVAL(buf, pos)   ((unsigned)CVAL(buf,pos))
#define SCVAL(buf, pos, val)   (CVAL(buf,pos) = (val))
#define SVAL(buf, pos)   (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
#define IVAL(buf, pos)   (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
#define SSVALX(buf, pos, val)   (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
#define SIVALX(buf, pos, val)   (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
#define SVALS(buf, pos)   ((int16)SVAL(buf,pos))
#define IVALS(buf, pos)   ((int32)IVAL(buf,pos))
#define SSVAL(buf, pos, val)   SSVALX((buf),(pos),((uint16)(val)))
#define SIVAL(buf, pos, val)   SIVALX((buf),(pos),((uint32)(val)))
#define SSVALS(buf, pos, val)   SSVALX((buf),(pos),((int16)(val)))
#define SIVALS(buf, pos, val)   SIVALX((buf),(pos),((int32)(val)))
#define SMBMACRO(macro, buf, pos, val, len, size)   { int l; for (l = 0; l < (len); l++) (val)[l] = macro((buf), (pos) + (size)*l); }
#define SSMBMACRO(macro, buf, pos, val, len, size)   { int l; for (l = 0; l < (len); l++) macro((buf), (pos) + (size)*l, (val)[l]); }
#define PCVAL(buf, pos, val, len)   SMBMACRO(CVAL,buf,pos,val,len,1)
#define PSVAL(buf, pos, val, len)   SMBMACRO(SVAL,buf,pos,val,len,2)
#define PIVAL(buf, pos, val, len)   SMBMACRO(IVAL,buf,pos,val,len,4)
#define PCVALS(buf, pos, val, len)   SMBMACRO(CVALS,buf,pos,val,len,1)
#define PSVALS(buf, pos, val, len)   SMBMACRO(SVALS,buf,pos,val,len,2)
#define PIVALS(buf, pos, val, len)   SMBMACRO(IVALS,buf,pos,val,len,4)
#define PSCVAL(buf, pos, val, len)   SSMBMACRO(SCVAL,buf,pos,val,len,1)
#define PSSVAL(buf, pos, val, len)   SSMBMACRO(SSVAL,buf,pos,val,len,2)
#define PSIVAL(buf, pos, val, len)   SSMBMACRO(SIVAL,buf,pos,val,len,4)
#define PSCVALS(buf, pos, val, len)   SSMBMACRO(SCVALS,buf,pos,val,len,1)
#define PSSVALS(buf, pos, val, len)   SSMBMACRO(SSVALS,buf,pos,val,len,2)
#define PSIVALS(buf, pos, val, len)   SSMBMACRO(SIVALS,buf,pos,val,len,4)
#define SREV(x)   ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
#define IREV(x)   ((SREV(x)<<16) | (SREV((x)>>16)))
#define RSVAL(buf, pos)   SREV(SVAL(buf,pos))
#define RSVALS(buf, pos)   SREV(SVALS(buf,pos))
#define RIVAL(buf, pos)   IREV(IVAL(buf,pos))
#define RIVALS(buf, pos)   IREV(IVALS(buf,pos))
#define RSSVAL(buf, pos, val)   SSVAL(buf,pos,SREV(val))
#define RSSVALS(buf, pos, val)   SSVALS(buf,pos,SREV(val))
#define RSIVAL(buf, pos, val)   SIVAL(buf,pos,IREV(val))
#define RSIVALS(buf, pos, val)   SIVALS(buf,pos,IREV(val))
#define RPSVAL(buf, pos, val, len)   SMBMACRO(RSVAL,buf,pos,val,len,2)
#define RPIVAL(buf, pos, val, len)   SMBMACRO(RIVAL,buf,pos,val,len,4)
#define RPSVALS(buf, pos, val, len)   SMBMACRO(RSVALS,buf,pos,val,len,2)
#define RPIVALS(buf, pos, val, len)   SMBMACRO(RIVALS,buf,pos,val,len,4)
#define RPSSVAL(buf, pos, val, len)   SSMBMACRO(RSSVAL,buf,pos,val,len,2)
#define RPSIVAL(buf, pos, val, len)   SSMBMACRO(RSIVAL,buf,pos,val,len,4)
#define RPSSVALS(buf, pos, val, len)   SSMBMACRO(RSSVALS,buf,pos,val,len,2)
#define RPSIVALS(buf, pos, val, len)   SSMBMACRO(RSIVALS,buf,pos,val,len,4)
#define DBG_RW_PCVAL(charmode, string, depth, base, read, inbuf, outbuf, len)
#define DBG_RW_PSVAL(charmode, string, depth, base, read, big_endian, inbuf, outbuf, len)
#define DBG_RW_PIVAL(charmode, string, depth, base, read, big_endian, inbuf, outbuf, len)
#define DBG_RW_CVAL(string, depth, base, read, inbuf, outbuf)
#define DBG_RW_SVAL(string, depth, base, read, big_endian, inbuf, outbuf)
#define DBG_RW_IVAL(string, depth, base, read, big_endian, inbuf, outbuf)
#define ROUND1(a, b, c, d, k, s)   a = lshift(a + F(b,c,d) + X[k], s)
#define ROUND2(a, b, c, d, k, s)   a = lshift(a + G(b,c,d) + X[k] + (uint32)0x5A827999,s)
#define ROUND3(a, b, c, d, k, s)   a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
#define uchar   unsigned char
#define int16   signed short
#define False   0
#define True   1
#define DEBUG(a, b)   ;
#define AddBytes(ptr, header, buf, count)
#define AddString(ptr, header, string)
#define AddUnicodeString(ptr, header, string)
#define GetUnicodeString(structPtr, header)   unicodeToString(((char*)structPtr) + IVAL(&structPtr->header.offset,0) , SVAL(&structPtr->header.len,0)/2)
#define GetString(structPtr, header)   toString((((char *)structPtr) + IVAL(&structPtr->header.offset,0)), SVAL(&structPtr->header.len,0))
#define DumpBuffer(fp, structPtr, header)   dumpRaw(fp,((unsigned char*)structPtr)+IVAL(&structPtr->header.offset,0),SVAL(&structPtr->header.len,0))
#define ChallengeHash(structPtr, header)   ((unsigned char*)structPtr)+IVAL(&structPtr->header.offset,0)
#define BAD   -1
#define DECODE64(c)   (isascii(c) ? base64val[c] : BAD)

Typedefs

typedef int BOOL

Functions

static uint32 F (uint32 X, uint32 Y, uint32 Z)
static uint32 G (uint32 X, uint32 Y, uint32 Z)
static uint32 H (uint32 X, uint32 Y, uint32 Z)
static uint32 lshift (uint32 x, int s)
static void mdfour64 (uint32 *M)
static void copy64 (uint32 *M, unsigned char *in)
static void copy4 (unsigned char *out, uint32 x)
void mdfour (unsigned char *out, unsigned char *in, int n)
static void permute (char *out, char *in, uchar *p, int n)
static void l_shift (char *d, int count, int n)
static void concat (char *out, char *in1, char *in2, int l1, int l2)
static void xorFunction (char *out, char *in1, char *in2, int n)
static void dohash (char *out, char *in, char *key, int forw)
static void str_to_key (unsigned char *str, unsigned char *key)
static void smbhash (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
void E_P16 (unsigned char *p14, unsigned char *p16)
void E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24)
void D_P16 (unsigned char *p14, unsigned char *in, unsigned char *out)
void E_old_pw_hash (unsigned char *p14, unsigned char *in, unsigned char *out)
void cred_hash1 (unsigned char *out, unsigned char *in, unsigned char *key)
void cred_hash2 (unsigned char *out, unsigned char *in, unsigned char *key)
void cred_hash3 (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
void SamOEMhash (unsigned char *data, unsigned char *key, int val)
char * StrnCpy (char *dest, const char *src, size_t n)
size_t skip_multibyte_char (char c)
char * safe_strcpy (char *dest, const char *src, size_t maxlength)
void strupper (char *s)
void SMBOWFencrypt (uchar passwd[16], uchar *c8, uchar p24[24])
void SMBencrypt (uchar *passwd, uchar *c8, uchar *p24)
static int _my_wcslen (int16 *str)
static int _my_mbstowcs (int16 *dst, uchar *src, int len)
void E_md4hash (uchar *passwd, uchar *p16)
void nt_lm_owf_gen (char *pwd, uchar nt_p16[16], uchar p16[16])
void NTLMSSPOWFencrypt (uchar passwd[8], uchar *ntlmchalresp, uchar p24[24])
void SMBNTencrypt (uchar *passwd, uchar *c8, uchar *p24)
static void dumpRaw (FILE *fp, unsigned char *buf, size_t len)
static char * unicodeToString (char *p, size_t len)
static unsigned char * strToUnicode (char *p)
static unsigned char * toString (char *p, size_t len)
void BuildAuthRequest (tSmbNtlmAuthRequest *request, long flags, char *host, char *domain)
void setup_des_key (unsigned char key_56[], des_key_schedule ksch)
void calc_resp (unsigned char *keys, unsigned char *plaintext, unsigned char *results)
void buildAuthResponse (tSmbNtlmAuthChallenge *challenge, tSmbNtlmAuthResponse *response, long flags, char *user, char *password, char *domainname, char *host, tSmbNtlmAuthResponse *OptionalNtlmPacket3)
void dumpAuthRequest (FILE *fp, tSmbNtlmAuthRequest *request)
void Widetochar (char *destination, char *source, int len)
void chartoWide (char *destination, char *source, int len)
__inline void SetChallengeKey (tSmbNtlmAuthChallenge *challenge, uint8 *SpoofedChallenge)
void BuildAuthChallenge (tSmbNtlmAuthChallenge *pChallenge, char *DomainName, char *ServerName, char *DNS, char *FQDN, uint8 flags, uint8 *SpoofedChallenge)
void dumpAuthChallenge (FILE *fp, tSmbNtlmAuthChallenge *challenge)
void dumpAuthResponse (FILE *fp, tSmbNtlmAuthResponse *response)
void GetNTLMPacketInfo (tSmbNtlmAuthResponse *NtlmAuthResponse, char *UserName, char *DomainName, char *WorkstationName, int verbose)
void to64frombits (unsigned char *out, const unsigned char *in, int inlen)
int from64tobits (char *out, const char *in)

Variables

static uint32 A
static uint32 B
static uint32 C
static uint32 D
static uchar perm1 [56]
static uchar perm2 [48]
static uchar perm3 [64]
static uchar perm4 [48]
static uchar perm5 [32]
static uchar perm6 [64]
static uchar sc [16] = {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1}
static uchar sbox [8][4][16]
static const char base64digits []
static const char base64val []


Define Documentation

#define _CRT_SECURE_NO_DEPRECATE

Definition at line 42 of file ntlm.cpp.

#define AddBytes ( ptr,
header,
buf,
count   ) 

Value:

{ \
if (buf && count) \
  { \
  SSVAL(&ptr->header.len,0,count); \
  SSVAL(&ptr->header.maxlen,0,count); \
  SIVAL(&ptr->header.offset,0,((ptr->buffer - ((uint8*)ptr)) + ptr->bufIndex)); \
  memcpy(ptr->buffer+ptr->bufIndex, buf, count); \
  ptr->bufIndex += count; \
  } \
else \
  { \
  ptr->header.len = \
  ptr->header.maxlen = 0; \
  SIVAL(&ptr->header.offset,0,ptr->bufIndex); \
  } \
}

Definition at line 1118 of file ntlm.cpp.

#define AddString ( ptr,
header,
string   ) 

Value:

{ \
char *p = string; \
int len = 0; \
if (p) len = strlen(p); \
AddBytes(ptr, header, ((unsigned char*)p), len); \
}

Definition at line 1136 of file ntlm.cpp.

#define AddUnicodeString ( ptr,
header,
string   ) 

Value:

{ \
char *p = string; \
unsigned char *b = NULL; \
int len = 0; \
if (p) \
  { \
  len = strlen(p); \
  b = strToUnicode(p); \
  } \
AddBytes(ptr, header, b, len*2); \
}

Definition at line 1144 of file ntlm.cpp.

#define BAD   -1

Definition at line 1656 of file ntlm.cpp.

#define CAREFUL_ALIGNMENT   1

Definition at line 162 of file ntlm.cpp.

#define ChallengeHash ( structPtr,
header   )     ((unsigned char*)structPtr)+IVAL(&structPtr->header.offset,0)

#define CVAL ( buf,
pos   )     (((unsigned char *)(buf))[pos])

Definition at line 165 of file ntlm.cpp.

#define DBG_RW_CVAL ( string,
depth,
base,
read,
inbuf,
outbuf   ) 

Value:

{ RW_CVAL(read,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %02x\n", \
             tab_depth(depth), base, string, outbuf)); }

Definition at line 275 of file ntlm.cpp.

#define DBG_RW_IVAL ( string,
depth,
base,
read,
big_endian,
inbuf,
outbuf   ) 

Value:

{ RW_IVAL(read,big_endian,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %08x\n", \
             tab_depth(depth), base, string, outbuf)); }

Definition at line 285 of file ntlm.cpp.

#define DBG_RW_PCVAL ( charmode,
string,
depth,
base,
read,
inbuf,
outbuf,
len   ) 

Value:

{ RW_PCVAL(read,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
             tab_depth(depth), base,string)); \
    if (charmode) print_asc(5, (unsigned char*)(outbuf), (len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%02x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n")); }

Definition at line 251 of file ntlm.cpp.

#define DBG_RW_PIVAL ( charmode,
string,
depth,
base,
read,
big_endian,
inbuf,
outbuf,
len   ) 

Value:

{ RW_PIVAL(read,big_endian,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
             tab_depth(depth), base,string)); \
    if (charmode) print_asc(5, (unsigned char*)(outbuf), 4*(len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%08x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n")); }

Definition at line 267 of file ntlm.cpp.

#define DBG_RW_PSVAL ( charmode,
string,
depth,
base,
read,
big_endian,
inbuf,
outbuf,
len   ) 

Value:

{ RW_PSVAL(read,big_endian,inbuf,outbuf,len) \
        DEBUG(5,("%s%04x %s: ", \
             tab_depth(depth), base,string)); \
    if (charmode) print_asc(5, (unsigned char*)(outbuf), 2*(len)); else \
        { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%04x ", (outbuf)[idx])); } } \
        DEBUG(5,("\n")); }

Definition at line 259 of file ntlm.cpp.

#define DBG_RW_SVAL ( string,
depth,
base,
read,
big_endian,
inbuf,
outbuf   ) 

Value:

{ RW_SVAL(read,big_endian,inbuf,outbuf,0) \
        DEBUG(5,("%s%04x %s: %04x\n", \
             tab_depth(depth), base, string, outbuf)); }

Definition at line 280 of file ntlm.cpp.

#define DEBUG ( a,
 )     ;

Definition at line 832 of file ntlm.cpp.

Referenced by safe_strcpy(), and SMBencrypt().

#define DECODE64 (  )     (isascii(c) ? base64val[c] : BAD)

Definition at line 1667 of file ntlm.cpp.

#define DumpBuffer ( fp,
structPtr,
header   )     dumpRaw(fp,((unsigned char*)structPtr)+IVAL(&structPtr->header.offset,0),SVAL(&structPtr->header.len,0))

Definition at line 1162 of file ntlm.cpp.

#define False   0

Definition at line 445 of file ntlm.cpp.

#define GetString ( structPtr,
header   )     toString((((char *)structPtr) + IVAL(&structPtr->header.offset,0)), SVAL(&structPtr->header.len,0))

Definition at line 1160 of file ntlm.cpp.

#define GetUnicodeString ( structPtr,
header   )     unicodeToString(((char*)structPtr) + IVAL(&structPtr->header.offset,0) , SVAL(&structPtr->header.len,0)/2)

Definition at line 1158 of file ntlm.cpp.

#define int16   signed short

Definition at line 443 of file ntlm.cpp.

Referenced by _my_mbstowcs(), and E_md4hash().

#define IREV (  )     ((SREV(x)<<16) | (SREV((x)>>16)))

Definition at line 228 of file ntlm.cpp.

#define IVAL ( buf,
pos   )     (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)

Definition at line 173 of file ntlm.cpp.

Referenced by dumpAuthRequest().

#define IVALS ( buf,
pos   )     ((int32)IVAL(buf,pos))

Definition at line 177 of file ntlm.cpp.

#define PCVAL ( buf,
pos,
val,
len   )     SMBMACRO(CVAL,buf,pos,val,len,1)

Definition at line 210 of file ntlm.cpp.

#define PCVALS ( buf,
pos,
val,
len   )     SMBMACRO(CVALS,buf,pos,val,len,1)

Definition at line 213 of file ntlm.cpp.

#define PIVAL ( buf,
pos,
val,
len   )     SMBMACRO(IVAL,buf,pos,val,len,4)

Definition at line 212 of file ntlm.cpp.

#define PIVALS ( buf,
pos,
val,
len   )     SMBMACRO(IVALS,buf,pos,val,len,4)

Definition at line 215 of file ntlm.cpp.

#define PSCVAL ( buf,
pos,
val,
len   )     SSMBMACRO(SCVAL,buf,pos,val,len,1)

Definition at line 218 of file ntlm.cpp.

#define PSCVALS ( buf,
pos,
val,
len   )     SSMBMACRO(SCVALS,buf,pos,val,len,1)

Definition at line 221 of file ntlm.cpp.

#define PSIVAL ( buf,
pos,
val,
len   )     SSMBMACRO(SIVAL,buf,pos,val,len,4)

Definition at line 220 of file ntlm.cpp.

#define PSIVALS ( buf,
pos,
val,
len   )     SSMBMACRO(SIVALS,buf,pos,val,len,4)

Definition at line 223 of file ntlm.cpp.

#define PSSVAL ( buf,
pos,
val,
len   )     SSMBMACRO(SSVAL,buf,pos,val,len,2)

Definition at line 219 of file ntlm.cpp.

#define PSSVALS ( buf,
pos,
val,
len   )     SSMBMACRO(SSVALS,buf,pos,val,len,2)

Definition at line 222 of file ntlm.cpp.

#define PSVAL ( buf,
pos,
val,
len   )     SMBMACRO(SVAL,buf,pos,val,len,2)

Definition at line 211 of file ntlm.cpp.

#define PSVALS ( buf,
pos,
val,
len   )     SMBMACRO(SVALS,buf,pos,val,len,2)

Definition at line 214 of file ntlm.cpp.

#define PVAL ( buf,
pos   )     ((unsigned)CVAL(buf,pos))

Definition at line 166 of file ntlm.cpp.

#define RIVAL ( buf,
pos   )     IREV(IVAL(buf,pos))

Definition at line 232 of file ntlm.cpp.

#define RIVALS ( buf,
pos   )     IREV(IVALS(buf,pos))

Definition at line 233 of file ntlm.cpp.

#define ROUND1 ( a,
b,
c,
d,
k,
 )     a = lshift(a + F(b,c,d) + X[k], s)

Definition at line 322 of file ntlm.cpp.

Referenced by mdfour64().

#define ROUND2 ( a,
b,
c,
d,
k,
 )     a = lshift(a + G(b,c,d) + X[k] + (uint32)0x5A827999,s)

Definition at line 323 of file ntlm.cpp.

Referenced by mdfour64().

#define ROUND3 ( a,
b,
c,
d,
k,
 )     a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)

Definition at line 324 of file ntlm.cpp.

Referenced by mdfour64().

#define RPIVAL ( buf,
pos,
val,
len   )     SMBMACRO(RIVAL,buf,pos,val,len,4)

Definition at line 241 of file ntlm.cpp.

#define RPIVALS ( buf,
pos,
val,
len   )     SMBMACRO(RIVALS,buf,pos,val,len,4)

Definition at line 243 of file ntlm.cpp.

#define RPSIVAL ( buf,
pos,
val,
len   )     SSMBMACRO(RSIVAL,buf,pos,val,len,4)

Definition at line 247 of file ntlm.cpp.

#define RPSIVALS ( buf,
pos,
val,
len   )     SSMBMACRO(RSIVALS,buf,pos,val,len,4)

Definition at line 249 of file ntlm.cpp.

#define RPSSVAL ( buf,
pos,
val,
len   )     SSMBMACRO(RSSVAL,buf,pos,val,len,2)

Definition at line 246 of file ntlm.cpp.

#define RPSSVALS ( buf,
pos,
val,
len   )     SSMBMACRO(RSSVALS,buf,pos,val,len,2)

Definition at line 248 of file ntlm.cpp.

#define RPSVAL ( buf,
pos,
val,
len   )     SMBMACRO(RSVAL,buf,pos,val,len,2)

Definition at line 240 of file ntlm.cpp.

#define RPSVALS ( buf,
pos,
val,
len   )     SMBMACRO(RSVALS,buf,pos,val,len,2)

Definition at line 242 of file ntlm.cpp.

#define RSIVAL ( buf,
pos,
val   )     SIVAL(buf,pos,IREV(val))

Definition at line 236 of file ntlm.cpp.

#define RSIVALS ( buf,
pos,
val   )     SIVALS(buf,pos,IREV(val))

Definition at line 237 of file ntlm.cpp.

#define RSSVAL ( buf,
pos,
val   )     SSVAL(buf,pos,SREV(val))

Definition at line 234 of file ntlm.cpp.

#define RSSVALS ( buf,
pos,
val   )     SSVALS(buf,pos,SREV(val))

Definition at line 235 of file ntlm.cpp.

#define RSVAL ( buf,
pos   )     SREV(SVAL(buf,pos))

Definition at line 230 of file ntlm.cpp.

#define RSVALS ( buf,
pos   )     SREV(SVALS(buf,pos))

Definition at line 231 of file ntlm.cpp.

#define RW_CVAL ( read,
inbuf,
outbuf,
offset   ) 

Value:

{ if (read) { (outbuf) = CVAL (inbuf,offset); } \
        else      { SCVAL(inbuf,offset,outbuf); } }

Definition at line 141 of file ntlm.cpp.

#define RW_IVAL ( read,
big_endian,
inbuf,
outbuf,
offset   ) 

Value:

{ if (read) { (outbuf) = ((big_endian) ? RIVAL(inbuf,offset) : IVAL (inbuf,offset)); } \
        else      { if (big_endian) { RSIVAL(inbuf,offset,outbuf); } else { SIVAL(inbuf,offset,outbuf); } } }

Definition at line 145 of file ntlm.cpp.

#define RW_PCVAL ( read,
inbuf,
outbuf,
len   ) 

Value:

{ if (read) { PCVAL (inbuf,0,outbuf,len); } \
        else      { PSCVAL(inbuf,0,outbuf,len); } }

Definition at line 129 of file ntlm.cpp.

#define RW_PIVAL ( read,
big_endian,
inbuf,
outbuf,
len   ) 

Value:

{ if (read) { if (big_endian) { RPIVAL(inbuf,0,outbuf,len); } else { PIVAL(inbuf,0,outbuf,len); } } \
        else      { if (big_endian) { RPSIVAL(inbuf,0,outbuf,len); } else { PSIVAL(inbuf,0,outbuf,len); } } }

Definition at line 133 of file ntlm.cpp.

#define RW_PSVAL ( read,
big_endian,
inbuf,
outbuf,
len   ) 

Value:

{ if (read) { if (big_endian) { RPSVAL(inbuf,0,outbuf,len); } else { PSVAL(inbuf,0,outbuf,len); } } \
        else      { if (big_endian) { RPSSVAL(inbuf,0,outbuf,len); } else { PSSVAL(inbuf,0,outbuf,len); } } }

Definition at line 137 of file ntlm.cpp.

#define RW_SVAL ( read,
big_endian,
inbuf,
outbuf,
offset   ) 

Value:

{ if (read) { (outbuf) = ((big_endian) ? RSVAL(inbuf,offset) : SVAL (inbuf,offset)); } \
        else      { if (big_endian) { RSSVAL(inbuf,offset,outbuf); } else { SSVAL(inbuf,offset,outbuf); } } }

Definition at line 149 of file ntlm.cpp.

#define SCVAL ( buf,
pos,
val   )     (CVAL(buf,pos) = (val))

Definition at line 167 of file ntlm.cpp.

#define SIVAL ( buf,
pos,
val   )     SIVALX((buf),(pos),((uint32)(val)))

Definition at line 179 of file ntlm.cpp.

#define SIVALS ( buf,
pos,
val   )     SIVALX((buf),(pos),((int32)(val)))

Definition at line 181 of file ntlm.cpp.

#define SIVALX ( buf,
pos,
val   )     (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))

Definition at line 175 of file ntlm.cpp.

#define SMBMACRO ( macro,
buf,
pos,
val,
len,
size   )     { int l; for (l = 0; l < (len); l++) (val)[l] = macro((buf), (pos) + (size)*l); }

Definition at line 203 of file ntlm.cpp.

#define SREV (  )     ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))

Definition at line 227 of file ntlm.cpp.

Referenced by BuildSmbPacket().

#define SSMBMACRO ( macro,
buf,
pos,
val,
len,
size   )     { int l; for (l = 0; l < (len); l++) macro((buf), (pos) + (size)*l, (val)[l]); }

Definition at line 206 of file ntlm.cpp.

#define SSVAL ( buf,
pos,
val   )     SSVALX((buf),(pos),((uint16)(val)))

Definition at line 178 of file ntlm.cpp.

Referenced by _my_mbstowcs().

#define SSVALS ( buf,
pos,
val   )     SSVALX((buf),(pos),((int16)(val)))

Definition at line 180 of file ntlm.cpp.

#define SSVALX ( buf,
pos,
val   )     (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)

Definition at line 174 of file ntlm.cpp.

#define SVAL ( buf,
pos   )     (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)

Definition at line 172 of file ntlm.cpp.

#define SVALS ( buf,
pos   )     ((int16)SVAL(buf,pos))

Definition at line 176 of file ntlm.cpp.

#define True   1

Definition at line 446 of file ntlm.cpp.

#define uchar   unsigned char

Definition at line 442 of file ntlm.cpp.

Referenced by SMBencrypt().

#define WORD   unsigned short

Definition at line 48 of file ntlm.cpp.


Typedef Documentation

typedef int BOOL

Definition at line 444 of file ntlm.cpp.


Function Documentation

static int _my_mbstowcs ( int16 *  dst,
uchar *  src,
int  len 
) [static]

Definition at line 924 of file ntlm.cpp.

References int16, and SSVAL.

Referenced by E_md4hash().

static int _my_wcslen ( int16 *  str  )  [static]

Definition at line 909 of file ntlm.cpp.

Referenced by E_md4hash().

void BuildAuthChallenge ( tSmbNtlmAuthChallenge pChallenge,
char *  DomainName,
char *  ServerName,
char *  DNS,
char *  FQDN,
uint8  flags,
uint8 SpoofedChallenge 
)

Definition at line 1437 of file ntlm.cpp.

References tSmbStrItem::buffer, tSmbNtlmAuthChallenge::buffer, tSmbNtlmAuthChallenge::challengeData, chartoWide(), DNSITEM, DOMAINNAMEITEM, tSmbNtlmAuthChallenge::emptyString, tSmbNtlmAuthChallenge::flags, FQDNITEM, tSmbNtlmAuthChallenge::ident, tSmbStrItem::ItemLength, tSmbStrItem::ItemType, tSmbStrHeader::len, tSmbStrHeader::maxlen, tSmbNtlmAuthChallenge::msgType, tSmbStrHeader::offset, tSmbNtlmAuthChallenge::reserved, SERVERNAMEITEM, and tSmbNtlmAuthChallenge::uDomain.

Here is the call graph for this function:

void BuildAuthRequest ( tSmbNtlmAuthRequest request,
long  flags,
char *  host,
char *  domain 
)

Definition at line 1224 of file ntlm.cpp.

Referenced by BuildSmbPacket1().

void buildAuthResponse ( tSmbNtlmAuthChallenge challenge,
tSmbNtlmAuthResponse response,
long  flags,
char *  user,
char *  password,
char *  domainname,
char *  host,
tSmbNtlmAuthResponse OptionalNtlmPacket3 
)

Definition at line 1298 of file ntlm.cpp.

Referenced by GetSmbPacket3(), HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), and HandleIncommingSMTPRequest().

void calc_resp ( unsigned char *  keys,
unsigned char *  plaintext,
unsigned char *  results 
)

Definition at line 1286 of file ntlm.cpp.

References setup_des_key().

Here is the call graph for this function:

void chartoWide ( char *  destination,
char *  source,
int  len 
)

Definition at line 1417 of file ntlm.cpp.

Referenced by BuildAuthChallenge(), BuildSmbPacket(), BuildTreeConnectAndXStub(), ChangeServiceConfigWStub(), InitDataBlock(), and OpenScManagerWStub().

static void concat ( char *  out,
char *  in1,
char *  in2,
int  l1,
int  l2 
) [static]

Definition at line 564 of file ntlm.cpp.

static void copy4 ( unsigned char *  out,
uint32  x 
) [static]

Definition at line 383 of file ntlm.cpp.

static void copy64 ( uint32 M,
unsigned char *  in 
) [static]

Definition at line 374 of file ntlm.cpp.

void cred_hash1 ( unsigned char *  out,
unsigned char *  in,
unsigned char *  key 
)

Definition at line 734 of file ntlm.cpp.

References smbhash().

Here is the call graph for this function:

void cred_hash2 ( unsigned char *  out,
unsigned char *  in,
unsigned char *  key 
)

Definition at line 742 of file ntlm.cpp.

void cred_hash3 ( unsigned char *  out,
unsigned char *  in,
unsigned char *  key,
int  forw 
)

Definition at line 752 of file ntlm.cpp.

void D_P16 ( unsigned char *  p14,
unsigned char *  in,
unsigned char *  out 
)

Definition at line 722 of file ntlm.cpp.

static void dohash ( char *  out,
char *  in,
char *  key,
int  forw 
) [static]

Definition at line 581 of file ntlm.cpp.

void dumpAuthChallenge ( FILE *  fp,
tSmbNtlmAuthChallenge challenge 
)

Definition at line 1511 of file ntlm.cpp.

Referenced by HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), HandleIncommingSmbRequest(), HandleIncommingSMTPRequest(), and StablishNTLMSession().

void dumpAuthRequest ( FILE *  fp,
tSmbNtlmAuthRequest request 
)

Definition at line 1391 of file ntlm.cpp.

References tSmbNtlmAuthRequest::ident, IVAL, and tSmbNtlmAuthRequest::msgType.

Referenced by HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), and HandleIncommingSMTPRequest().

void dumpAuthResponse ( FILE *  fp,
tSmbNtlmAuthResponse response 
)

Definition at line 1591 of file ntlm.cpp.

Referenced by HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), and HandleIncommingSMTPRequest().

static void dumpRaw ( FILE *  fp,
unsigned char *  buf,
size_t  len 
) [static]

Definition at line 1166 of file ntlm.cpp.

void E_md4hash ( uchar *  passwd,
uchar *  p16 
)

Definition at line 944 of file ntlm.cpp.

References _my_mbstowcs(), _my_wcslen(), and int16.

Here is the call graph for this function:

void E_old_pw_hash ( unsigned char *  p14,
unsigned char *  in,
unsigned char *  out 
)

Definition at line 728 of file ntlm.cpp.

References smbhash().

Here is the call graph for this function:

void E_P16 ( unsigned char *  p14,
unsigned char *  p16 
)

Definition at line 708 of file ntlm.cpp.

Referenced by SMBencrypt().

void E_P24 ( unsigned char *  p21,
unsigned char *  c8,
unsigned char *  p24 
)

Definition at line 715 of file ntlm.cpp.

static uint32 F ( uint32  X,
uint32  Y,
uint32  Z 
) [static]

Definition at line 301 of file ntlm.cpp.

int from64tobits ( char *  out,
const char *  in 
)

Definition at line 1695 of file ntlm.cpp.

Referenced by HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), and HandleIncommingSMTPRequest().

static uint32 G ( uint32  X,
uint32  Y,
uint32  Z 
) [static]

Definition at line 306 of file ntlm.cpp.

void GetNTLMPacketInfo ( tSmbNtlmAuthResponse NtlmAuthResponse,
char *  UserName,
char *  DomainName,
char *  WorkstationName,
int  verbose 
)

Definition at line 1622 of file ntlm.cpp.

Referenced by HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), HandleIncommingSMTPRequest(), and WriteDataToReportFile().

static uint32 H ( uint32  X,
uint32  Y,
uint32  Z 
) [static]

Definition at line 311 of file ntlm.cpp.

static void l_shift ( char *  d,
int  count,
int  n 
) [static]

Definition at line 554 of file ntlm.cpp.

static uint32 lshift ( uint32  x,
int  s 
) [static]

Definition at line 316 of file ntlm.cpp.

void mdfour ( unsigned char *  out,
unsigned char *  in,
int  n 
)

Definition at line 392 of file ntlm.cpp.

static void mdfour64 ( uint32 M  )  [static]

Definition at line 327 of file ntlm.cpp.

References A, B, C, D, ROUND1, ROUND2, and ROUND3.

void nt_lm_owf_gen ( char *  pwd,
uchar  nt_p16[16],
uchar  p16[16] 
)

Definition at line 963 of file ntlm.cpp.

void NTLMSSPOWFencrypt ( uchar  passwd[8],
uchar *  ntlmchalresp,
uchar  p24[24] 
)

Definition at line 1010 of file ntlm.cpp.

static void permute ( char *  out,
char *  in,
uchar *  p,
int  n 
) [static]

Definition at line 547 of file ntlm.cpp.

char* safe_strcpy ( char *  dest,
const char *  src,
size_t  maxlength 
)

Definition at line 833 of file ntlm.cpp.

References DEBUG.

void SamOEMhash ( unsigned char *  data,
unsigned char *  key,
int  val 
)

Definition at line 761 of file ntlm.cpp.

__inline void SetChallengeKey ( tSmbNtlmAuthChallenge challenge,
uint8 SpoofedChallenge 
)

Definition at line 1427 of file ntlm.cpp.

void setup_des_key ( unsigned char  key_56[],
des_key_schedule  ksch 
)

Definition at line 1265 of file ntlm.cpp.

Referenced by calc_resp().

size_t skip_multibyte_char ( char  c  ) 

Definition at line 822 of file ntlm.cpp.

void SMBencrypt ( uchar *  passwd,
uchar *  c8,
uchar *  p24 
)

Definition at line 887 of file ntlm.cpp.

References DEBUG, E_P16(), SMBOWFencrypt(), StrnCpy(), strupper(), and uchar.

Here is the call graph for this function:

static void smbhash ( unsigned char *  out,
unsigned char *  in,
unsigned char *  key,
int  forw 
) [static]

Definition at line 680 of file ntlm.cpp.

Referenced by cred_hash1(), and E_old_pw_hash().

void SMBNTencrypt ( uchar *  passwd,
uchar *  c8,
uchar *  p24 
)

Definition at line 1030 of file ntlm.cpp.

void SMBOWFencrypt ( uchar  passwd[16],
uchar *  c8,
uchar  p24[24] 
)

Definition at line 999 of file ntlm.cpp.

Referenced by SMBencrypt().

static void str_to_key ( unsigned char *  str,
unsigned char *  key 
) [static]

Definition at line 662 of file ntlm.cpp.

char* StrnCpy ( char *  dest,
const char *  src,
size_t  n 
)

Definition at line 809 of file ntlm.cpp.

Referenced by SMBencrypt().

static unsigned char* strToUnicode ( char *  p  )  [static]

Definition at line 1193 of file ntlm.cpp.

void strupper ( char *  s  ) 

Definition at line 861 of file ntlm.cpp.

Referenced by SMBencrypt().

void to64frombits ( unsigned char *  out,
const unsigned char *  in,
int  inlen 
)

Definition at line 1669 of file ntlm.cpp.

Referenced by HandleIncommingHTTPRequest(), HandleIncommingIMAPRequest(), HandleIncommingPOP3Request(), and HandleIncommingSMTPRequest().

static unsigned char* toString ( char *  p,
size_t  len 
) [static]

Definition at line 1210 of file ntlm.cpp.

static char* unicodeToString ( char *  p,
size_t  len 
) [static]

Definition at line 1176 of file ntlm.cpp.

void Widetochar ( char *  destination,
char *  source,
int  len 
)

Definition at line 1405 of file ntlm.cpp.

Referenced by HandleIncommingSmbRequest().

static void xorFunction ( char *  out,
char *  in1,
char *  in2,
int  n 
) [static]

Definition at line 572 of file ntlm.cpp.


Variable Documentation

uint32 A [static]

Definition at line 299 of file ntlm.cpp.

Referenced by mdfour64().

uint32 B [static]

Definition at line 299 of file ntlm.cpp.

Referenced by mdfour64().

const char base64digits[] [static]

Initial value:

   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Definition at line 1653 of file ntlm.cpp.

const char base64val[] [static]

Initial value:

 {
    BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
    BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
    BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63,
     52, 53, 54, 55,  56, 57, 58, 59,  60, 61,BAD,BAD, BAD,BAD,BAD,BAD,
    BAD,  0,  1,  2,   3,  4,  5,  6,   7,  8,  9, 10,  11, 12, 13, 14,
     15, 16, 17, 18,  19, 20, 21, 22,  23, 24, 25,BAD, BAD,BAD,BAD,BAD,
    BAD, 26, 27, 28,  29, 30, 31, 32,  33, 34, 35, 36,  37, 38, 39, 40,
     41, 42, 43, 44,  45, 46, 47, 48,  49, 50, 51,BAD, BAD,BAD,BAD,BAD
}

Definition at line 1657 of file ntlm.cpp.

uint32 C [static]

Definition at line 299 of file ntlm.cpp.

Referenced by mdfour64().

uint32 D [static]

Definition at line 299 of file ntlm.cpp.

Referenced by mdfour64().

uchar perm1[56] [static]

Initial value:

 {57, 49, 41, 33, 25, 17,  9,
                         1, 58, 50, 42, 34, 26, 18,
                        10,  2, 59, 51, 43, 35, 27,
                        19, 11,  3, 60, 52, 44, 36,
                        63, 55, 47, 39, 31, 23, 15,
                         7, 62, 54, 46, 38, 30, 22,
                        14,  6, 61, 53, 45, 37, 29,
                        21, 13,  5, 28, 20, 12,  4}

Definition at line 448 of file ntlm.cpp.

uchar perm2[48] [static]

Initial value:

 {14, 17, 11, 24,  1,  5,
                         3, 28, 15,  6, 21, 10,
                        23, 19, 12,  4, 26,  8,
                        16,  7, 27, 20, 13,  2,
                        41, 52, 31, 37, 47, 55,
                        30, 40, 51, 45, 33, 48,
                        44, 49, 39, 56, 34, 53,
                        46, 42, 50, 36, 29, 32}

Definition at line 457 of file ntlm.cpp.

uchar perm3[64] [static]

Initial value:

 {58, 50, 42, 34, 26, 18, 10,  2,
                        60, 52, 44, 36, 28, 20, 12,  4,
                        62, 54, 46, 38, 30, 22, 14,  6,
                        64, 56, 48, 40, 32, 24, 16,  8,
                        57, 49, 41, 33, 25, 17,  9,  1,
                        59, 51, 43, 35, 27, 19, 11,  3,
                        61, 53, 45, 37, 29, 21, 13,  5,
                        63, 55, 47, 39, 31, 23, 15,  7}

Definition at line 466 of file ntlm.cpp.

uchar perm4[48] [static]

Initial value:

 {   32,  1,  2,  3,  4,  5,
                            4,  5,  6,  7,  8,  9,
                            8,  9, 10, 11, 12, 13,
                           12, 13, 14, 15, 16, 17,
                           16, 17, 18, 19, 20, 21,
                           20, 21, 22, 23, 24, 25,
                           24, 25, 26, 27, 28, 29,
                           28, 29, 30, 31, 32,  1}

Definition at line 475 of file ntlm.cpp.

uchar perm5[32] [static]

Initial value:

 {      16,  7, 20, 21,
                              29, 12, 28, 17,
                               1, 15, 23, 26,
                               5, 18, 31, 10,
                               2,  8, 24, 14,
                              32, 27,  3,  9,
                              19, 13, 30,  6,
                              22, 11,  4, 25}

Definition at line 484 of file ntlm.cpp.

uchar perm6[64] [static]

Initial value:

{ 40,  8, 48, 16, 56, 24, 64, 32,
                        39,  7, 47, 15, 55, 23, 63, 31,
                        38,  6, 46, 14, 54, 22, 62, 30,
                        37,  5, 45, 13, 53, 21, 61, 29,
                        36,  4, 44, 12, 52, 20, 60, 28,
                        35,  3, 43, 11, 51, 19, 59, 27,
                        34,  2, 42, 10, 50, 18, 58, 26,
                        33,  1, 41,  9, 49, 17, 57, 25}

Definition at line 494 of file ntlm.cpp.

uchar sbox[8][4][16] [static]

Definition at line 506 of file ntlm.cpp.

uchar sc[16] = {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1} [static]

Definition at line 504 of file ntlm.cpp.


Generated on Wed Nov 12 22:04:28 2008 for Smbrelay version 3 by  doxygen 1.5.4