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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#ifndef __NTLMSSP_H__
#define __NTLMSSP_H__
#define MAX_HOSTLEN 32
#define MAX_DOMLEN 32
#define MAX_USERLEN 32
#define RESP_LEN 24
#define NONCE_LEN 8
/* fhz, 01-10-15 : borrowed from samba code */
/* NTLMSSP negotiation flags */
#define NTLMSSP_NEGOTIATE_UNICODE 0x00000001
#define NTLMSSP_NEGOTIATE_OEM 0x00000002
#define NTLMSSP_REQUEST_TARGET 0x00000004
#define NTLMSSP_NEGOTIATE_SIGN 0x00000010
#define NTLMSSP_NEGOTIATE_SEAL 0x00000020
#define NTLMSSP_NEGOTIATE_LM_KEY 0x00000080
#define NTLMSSP_NEGOTIATE_NTLM 0x00000200
#define NTLMSSP_NEGOTIATE_00001000 0x00001000
#define NTLMSSP_NEGOTIATE_00002000 0x00002000
#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x00008000
#define NTLMSSP_TARGET_TYPE_DOMAIN 0x00010000
#define NTLMSSP_TARGET_TYPE_SERVER 0x00020000
#define NTLMSSP_NEGOTIATE_NTLM2 0x00080000
#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x00800000
#define NTLMSSP_NEGOTIATE_128 0x20000000
#define NTLMSSP_NEGOTIATE_KEY_EXCH 0x40000000
#define SMBD_NTLMSSP_NEG_FLAGS 0x000082b1
#define NTLM_NTLMSSP_NEG_FLAGS 0x00008206
/* 8201 8207 */
#define LEN_NTLMSSP_FLAGS 4
#define OFFSET_MSG1_NTLMSSP_FLAGS 12
struct ntlm_msg1 {
unsigned char protocol[8];
unsigned char type; /* 1 */
unsigned char zero1[3];
unsigned char flags[2];
unsigned char zero2[2];
unsigned char dom_len[4];
unsigned char dom_off[4];
unsigned char host_len[4];
unsigned char host_off[4];
#if 0
unsigned char data[0];
#endif
} __attribute__((packed));
struct ntlm_msg2 {
unsigned char protocol[8];
unsigned char type; /* 2 */
unsigned char zero1[7];
unsigned char msg_len[4];
unsigned char flags[2];
unsigned char zero2[2];
unsigned char nonce[8];
unsigned char zero3[8];
} __attribute__((packed));
struct ntlm_msg3 {
unsigned char protocol[8];
unsigned char type; /* 3 */
unsigned char zero1[3];
unsigned char lm_len[4];
unsigned char lm_off[4];
unsigned char nt_len[4];
unsigned char nt_off[4];
unsigned char dom_len[4];
unsigned char dom_off[4];
unsigned char user_len[4];
unsigned char user_off[4];
unsigned char host_len[4];
unsigned char host_off[4];
unsigned char msg_len[4]; /* Win9x: data begins here! */
#if 0
unsigned char data[0];
#endif
} __attribute__((packed));
struct ntlm_msg2_win9x {
unsigned char protocol[8];
unsigned char type; /* 2 */
unsigned char zero1[3];
unsigned char dom_len1[2];
unsigned char dom_len2[2];
unsigned char dom_off[4];
unsigned char flags[2];
unsigned char zero2[2];
unsigned char nonce[8];
unsigned char zero3[8];
unsigned char zero4[4];
unsigned char msg_len[4];
unsigned char dom[MAX_DOMLEN];
} __attribute__((packed));
/* size without dom[] : */
#define NTLM_MSG2_WIN9X_FIXED_SIZE (sizeof(struct ntlm_msg2_win9x)-MAX_DOMLEN)
typedef struct ntlmssp_info {
int msg_type;
unsigned char user[MAX_USERLEN + 1];
unsigned char host[MAX_HOSTLEN + 1];
unsigned char domain[MAX_DOMLEN + 1];
unsigned char lm[RESP_LEN];
unsigned char nt[RESP_LEN];
} ntlmssp_info_rec;
int ntlmssp_decode_msg(struct ntlmssp_info *info, unsigned char *raw_msg, unsigned msglen, unsigned *ntlmssp_flags);
int ntlmssp_encode_msg2(unsigned char *nonce, struct ntlm_msg2 *msg);
int ntlmssp_encode_msg2_win9x(unsigned char *nonce, struct ntlm_msg2_win9x *msg,char *domainname,unsigned ntlmssp_flags);
#define NTV_NO_ERROR 0
#define NTV_SERVER_ERROR 1
#define NTV_PROTOCOL_ERROR 2
#define NTV_LOGON_ERROR 3
int ntlmssp_validuser(const char* username, const char* password, const char* server, const char* backup, const char* domain);
void* ntlmssp_connect(const char* server, const char* backup, const char* domain, char* nonce);
int ntlmssp_auth(void* handle, const char* user, const char* password, int flag);
void ntlmssp_disconnect(void* handle);
#endif /* __NTLMSSP_H__ */
|