Table of Contents
This document contains information to provide an NT workstation with login services, without the need for an NT server. It is the sgml version of http://mailhost.cb1.com/~lkcl/cifsntdomain.txt, controlled by Luke.
It should be possible to select a domain instead of a workgroup (in the NT workstation's TCP/IP settings) and after the obligatory reboot, type in a username, password, select a domain and successfully log in. I would appreciate any feedback on your experiences with this process, and any comments, corrections and additions to this document.
The packets described here can be easily derived from (and are probably better understood using) Netmon.exe. You will need to use the version of Netmon that matches your system, in order to correctly decode the NETLOGON, lsarpc and srvsvc Transact pipes. This document is derived from NT Service Pack 1 and its corresponding version of Netmon. It is intended that an annotated packet trace be produced, which will likely be more instructive than this document.
Also needed, to fully implement NT Domain Login Services, is the document describing the cryptographic part of the NT authentication. This document is available from comp.protocols.smb; from the ntsecurity.net digest and from the samba digest, amongst other sources.
A copy is available from:
http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935
http://mailhost.cb1.com/~lkcl/crypt.html
A c-code implementation, provided by Linus Nordberg of this protocol is available from:
http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html
http://mailhost.cb1.com/~lkcl/crypt.txt
Also used to provide debugging information is the Check Build version of NT workstation, and enabling full debugging in NETLOGON. This is achieved by setting the following REG_SZ registry key to 0x1ffffff:
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters
Incorrect direct editing of the registry can cause your machine to fail. Then again, so can incorrect implementation of this protocol. See "Liability:" above.
Bear in mind that each packet over-the-wire will have its origin in an API call. Therefore, there are likely to be structures, enumerations and defines that are usefully documented elsewhere.
This document is by no means complete or authoritative. Missing sections include, but are not limited to:
Mappings of RIDs to usernames (and vice-versa).
What a User ID is and what a Group ID is.
The exact meaning/definition of various magic constants or enumerations.
The reply error code and use of that error code when a workstation becomes a member of a domain (to be described later). Failure to return this error code will make the workstation report that it is already a member of the domain.
the cryptographic side of the NetrServerPasswordSet command, which would allow the workstation to change its password. This password is used to generate the long-term session key. [It is possible to reject this command, and keep the default workstation password].
cket Traces from Netmonitor (Service Pack 1 and above) |
ul Ashton and Luke Leighton's other "NT Domain" doc. |
FS documentation - cifs6.txt |
FS documentation - cifsrap2.txt |
Paul Ashton: loads of work with Net Monitor; understanding the NT authentication system; reference implementation of the NT domain support on which this document is originally based. |
Duncan Stansfield: low-level analysis of MSRPC Pipes. |
Linus Nordberg: producing c-code from Paul's crypto spec. |
Windows Sourcer development team |
In the SMB Transact pipes, some "Structures", described here, appear to be 4-byte aligned with the SMB header, at their start. Exactly which "Structures" need aligning is not precisely known or documented.
In the UDP NTLOGON Mailslots, some "Structures", described here, appear to be 2-byte aligned with the start of the mailslot, at their start.
Domain SID is of the format S-revision-version-auth1-auth2...authN. e.g S-1-5-123-456-789-123-456. the 5 could be a sub-revision.
any undocumented buffer pointers must be non-zero if the string buffer it refers to contains characters. exactly what value they should be is unknown. 0x0000 0002 seems to do the trick to indicate that the buffer exists. a NULL buffer pointer indicates that the string buffer is of zero length. If the buffer pointer is NULL, then it is suspected that the structure it refers to is NOT put into (or taken out of) the SMB data stream. This is empirically derived from, for example, the LSA SAM Logon response packet, where if the buffer pointer is NULL, the user information is not inserted into the data stream. Exactly what happens with an array of buffer pointers is not known, although an educated guess can be made.
an array of structures (a container) appears to have a count and a pointer. if the count is zero, the pointer is also zero. no further data is put into or taken out of the SMB data stream. if the count is non-zero, then the pointer is also non-zero. immediately following the pointer is the count again, followed by an array of container sub-structures. the count appears a third time after the last sub-structure.
command number in the msrpc packet header
0x00
0x02
0x0B
0x0C
UTIME is 32 bits, indicating time in seconds since 01jan1970. documented in cifs6.txt (section 3.5 page, page 30).
num of sub-authorities in domain SID
SID revision number
num of sub-authorities in domain SID
6 bytes for domain SID - Identifier Authority.
domain SID sub-authorities
Note: the domain SID is documented elsewhere.
length of unicode string
max length of unicode string
4 - undocumented.
unicode string header
undocumented buffer pointer
length of unicode string
null-terminated string of unicode characters.
padding to get unicode string 4-byte aligned with the start of the SMB header.
max length of unicode string
0 - undocumented
length of unicode string
string of uncode characters
0x18 - length (in bytes) including the length field.
0 - root directory (pointer)
0 - object name (pointer)
0 - attributes (undocumented)
0 - security descriptior (pointer)
0 - security quality of service
5 - SID type
0 - undocumented
domain SID unicode string header
domain SID unicode string
Note: there is a conflict between the unicode string header and the unicode string itself as to which to use to indicate string length. this will need to be resolved.
Note: the SID type indicates, for example, an alias; a well-known group etc. this is documented somewhere.
5 - well-known SID. 1 - user SID (see ShowACLs)
5 - undocumented
domain RID
0 - domain index out of above reference domains
Note: logon server name starts with two '\' characters and is upper case.
Note: account name is the logon client name from the LSA Request Challenge, with a $ on the end of it, in upper case.
undocumented buffer pointer
logon server unicode string
account name unicode string
sec_chan - security channel type
logon client machine unicode string
Note: logon server name starts with two '\' characters and is upper case.
undocumented buffer pointer
logon server unicode string
undocumented buffer pointer
logon client machine unicode string
Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will beused in subsequent credential checks. the presumed intention is to maintain an authenticated request/response trail.
client and server names
???? padding, for 4-byte alignment with SMB header.
pointer to client credentials.
client-calculated credentials + client time
Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will be used in subsequent credential checks. the presumed intention is to maintain an authenticated request/response trail.
logon account info
client-calculated credentials + client time
ptr_id_info_1
domain name unicode header
param control
logon ID
user name unicode header
workgroup name unicode header
arc4 LM OWF Password
arc4 NT OWF Password
domain name unicode string
user name unicode string
workstation name unicode string
Note: presumably, the return credentials is supposedly for the server to verify that the credential chain hasn't been compromised.
client identification/authentication info
pointer to return credentials.
return credentials - ignored.
logon level
switch value
switch (switch_value) case 1: { ID_INFO_1 id_info_1; }
undocumented buffer pointer.
num referenced domains?
undocumented domain name buffer pointer.
32 - max number of entries
4 - num referenced domains?
domain name unicode string header
referenced domain unicode string headers
domain name unicode string
referenced domain SIDs
??? padding to get 4-byte alignment with start of SMB header
domain name string length * 2
domain name string length * 2
undocumented domain name string buffer pointer
undocumented domain SID string buffer pointer
domain name (unicode string)
domain SID
Note: it would be nice to know what the 16 byte user session key is for.
logon time
logoff time
kickoff time
password last set time
password can change time
password must change time
username unicode string header
user's full name unicode string header
logon script unicode string header
profile path unicode string header
home directory unicode string header
home directory drive unicode string header
logon count
bad password count
User ID
Group ID
num groups
undocumented buffer pointer to groups.
user flags
user session key
logon server unicode string header
logon domain unicode string header
undocumented logon domain id pointer
40 undocumented padding bytes. future expansion?
0 - num_other_sids?
NULL - undocumented pointer to other domain SIDs.
username unicode string
user's full name unicode string
logon script unicode string
profile path unicode string
home directory unicode string
home directory drive unicode string
num groups
group info
logon server unicode string
logon domain unicode string
domain SID
other domain SIDs?
Note: see cifsrap2.txt section5, page 10.
0 for shi1_type indicates a Disk. |
1 for shi1_type indicates a Print Queue. |
2 for shi1_type indicates a Device. |
3 for shi1_type indicates an IPC pipe. |
0x8000 0000 (top bit set in shi1_type) indicates a hidden share. |
shi1_netname - pointer to net name
shi1_type - type of share. 0 - undocumented.
shi1_remark - pointer to comment.
shi1_netname - unicode string of net name
shi1_remark - unicode string of comment.
share container with 0 entries:
0 - EntriesRead
0 - Buffer
share container with > 0 entries:
EntriesRead
non-zero - Buffer
EntriesRead
share entry pointers
share entry strings
padding to get unicode string 4-byte aligned with start of the SMB header.
EntriesRead
0 - padding
Note: see cifs6.txt section 6.4 - the fields described therein will be of assistance here. for example, the type listed below is the same as fServerType, which is described in 6.4.1.
0x00000001 All workstations
0x00000002 All servers
0x00000004 Any server running with SQL server
0x00000008 Primary domain controller
0x00000010 Backup domain controller
0x00000020 Server running the timesource service
0x00000040 Apple File Protocol servers
0x00000080 Novell servers
0x00000100 Domain Member
0x00000200 Server sharing print queue
0x00000400 Server running dialin service.
0x00000800 Xenix server
0x00001000 NT server
0x00002000 Server running Windows for
0x00008000 Windows NT non DC server
0x00010000 Server that can run the browser service
0x00020000 Backup browser server
0x00040000 Master browser server
0x00080000 Domain Master Browser server
0x40000000 Enumerate only entries marked "local"
0x80000000 Enumerate Domains. The pszServer and pszDomain parameters must be NULL.
500 - platform_id
pointer to name
5 - major version
4 - minor version
type (SV_TYPE_... bit field)
pointer to comment
sv101_name - unicode string of server name
sv_101_comment - unicode string of server comment.
padding to get unicode string 4-byte aligned with start of the SMB header.
For details on the SMB Transact Named Pipe, see cifs6.txt
The MSRPC is conducted over an SMB Transact Pipe with a name of \PIPE\. You must first obtain a 16 bit file handle, by sending a SMBopenX with the pipe name \PIPE\srvsvc for example. You can then perform an SMB Trans, and must carry out an SMBclose on the file handle once you are finished.
Trans Requests must be sent with two setup UINT16s, no UINT16 params (none known about), and UINT8 data parameters sufficient to contain the MSRPC header, and MSRPC data. The first UINT16 setup parameter must be either 0x0026 to indicate an RPC, or 0x0001 to indicate Set Named Pipe Handle state. The second UINT16 parameter must be the file handle for the pipe, obtained above.
The Data section for an API Command of 0x0026 (RPC pipe) in the Trans Request is the RPC Header, followed by the RPC Data. The Data section for an API Command of 0x0001 (Set Named Pipe Handle state) is two bytes. The only value seen for these two bytes is 0x00 0x43.
MSRPC Responses are sent as response data inside standard SMB Trans responses, with the MSRPC Header, MSRPC Data and MSRPC tail.
It is suspected that the Trans Requests will need to be at least 2-byte aligned (probably 4-byte). This is standard practice for SMBs. It is also independent of the observed 4-byte alignments with the start of the MSRPC header, including the 4-byte alignment between the MSRPC header and the MSRPC data.
First, an SMBtconX connection is made to the IPC$ share. The connection must be made using encrypted passwords, not clear-text. Then, an SMBopenX is made on the pipe. Then, a Set Named Pipe Handle State must be sent, after which the pipe is ready to accept API commands. Lastly, and SMBclose is sent.
To be resolved:
lkcl/01nov97 there appear to be two additional bytes after the null-terminated \PIPE\ name for the RPC pipe. Values seen so far are listed below:
initial SMBopenX request: RPC API command 0x26 params: "\\PIPE\\lsarpc" 0x65 0x63; 0x72 0x70; 0x44 0x65; "\\PIPE\\srvsvc" 0x73 0x76; 0x4E 0x00; 0x5C 0x43;
[section to be rewritten, following receipt of work by Duncan Stansfield]
Interesting note: if you set packed data representation to 0x0100 0000 then all 4-byte and 2-byte word ordering is turned around!
The start of each of the NTLSA and NETLOGON named pipes begins with:
reply same as request (0x05)
reply same as request (0x00)
one of the MSRPC_Type enums
reply same as request (0x00 for Bind, 0x03 for Request)
reply same as request (0x00000010)
the length of the data section of the SMB trans packet
call identifier. (e.g. 0x00149594)
the remainder of the packet depending on the "type"
the interfaces are numbered. as yet I haven't seen more than one interface used on the same pipe name srvsvc
abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003) transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
the remainder of the packet after the header if "type" was Bind in the response header, "type" should be BindAck
maximum transmission fragment size (0x1630)
max receive fragment size (0x1630)
associated group id (0x0)
the number of elements (0x1)
presentation context identifier (0x0)
the number of syntaxes (has always been 1?)(0x1)
4-byte alignment padding, against SMB header
num and vers. of interface client is using
num and vers. of interface to use for replies
length of the string including null terminator
the string above in single byte, null terminated form
the response to place after the header in the reply packet
same as request
same as request
zero
the address string, as described earlier
4-byte alignment padding, against SMB header
the number of results (0x01)
4-byte alignment padding, against SMB header
result (0x00 = accept)
reason (0x00 = no reason specified)
the transfer syntax from the request
the remainder of the packet after the header for every other other request
the size of the stub data in bytes
presentation context identifier (0x0)
operation number (0x15)
a packet dependent on the pipe name (probably the interface) and the op number)
The end of each of the NTLSA and NETLOGON named pipes ends with:
end of data
return code
RPC Binds are the process of associating an RPC pipe (e.g \PIPE\lsarpc) with a "transfer syntax" (see RPC_Iface structure). The purpose for doing this is unknown.
Note: The RPC_ResBind SMB Transact request is sent with two uint16 setup parameters. The first is 0x0026; the second is the file handle returned by the SMBopenX Transact response.
Note: The RPC_ResBind members maxtsize, maxrsize and assocgid are the same in the response as the same members in the RPC_ReqBind. The RPC_ResBind member transfersyntax is the same in the response as the
Note: The RPC_ResBind response member secondaddr contains the name of what is presumed to be the service behind the RPC pipe. The mapping identified so far is:
RPC_ResBind response:
"\\PIPE\\ntsvcs"
"\\PIPE\\lsass"
"\\PIPE\\lsass"
"\\PIPE\\wksvcs"
"\\PIPE\\NETLOGON"
Note: The RPC_Packet fraglength member in both the Bind Request and Bind Acknowledgment must contain the length of the entire RPC data, including the RPC_Packet header.
Request:
RPC_Packet |
RPC_ReqBind |
Response:
RPC_Packet |
RPC_ResBind |
The sequence of actions taken on this pipe are:
Establish a connection to the IPC$ share (SMBtconX). use encrypted passwords. |
Open an RPC Pipe with the name "\\PIPE\\lsarpc". Store the file handle. |
Using the file handle, send a Set Named Pipe Handle state to 0x4300. |
Send an LSA Open Policy request. Store the Policy Handle. |
Using the Policy Handle, send LSA Query Info Policy requests, etc. |
Using the Policy Handle, send an LSA Close. |
Close the IPC$ share. |
Defines for this pipe, identifying the query are:
0x2c
0x07
0x0d
0xff
0xfe
0xfd
0x00
Note: The policy handle can be anything you like.
buffer pointer
server name - unicode string starting with two '\'s
object attributes
1 - desired access
Note: The info class in response must be the same as that in the request.
Note: num_entries in response must be same as num_entries in request.
LSA policy handle
num_entries
undocumented domain SID buffer pointer
undocumented domain name buffer pointer
DOM_SID[num_entries] domain SIDs to be looked up.
completely undocumented 16 bytes.
Note: num_entries in response must be same as num_entries in request.
LSA policy handle
num_entries
num_entries
undocumented domain SID buffer pointer
undocumented domain name buffer pointer
names to be looked up.
undocumented bytes - falsely translated SID structure?
The sequence of actions taken on this pipe are:
tablish a connection to the IPC$ share (SMBtconX). use encrypted passwords. |
en an RPC Pipe with the name "\\PIPE\\NETLOGON". Store the file handle. |
ing the file handle, send a Set Named Pipe Handle state to 0x4300. |
eate Client Challenge. Send LSA Request Challenge. Store Server Challenge. |
lculate Session Key. Send an LSA Auth 2 Challenge. Store Auth2 Challenge. |
lc/Verify Client Creds. Send LSA Srv PW Set. Calc/Verify Server Creds. |
lc/Verify Client Creds. Send LSA SAM Logon . Calc/Verify Server Creds. |
lc/Verify Client Creds. Send LSA SAM Logoff. Calc/Verify Server Creds. |
ose the IPC$ share. |
Defines for this pipe, identifying the query are
0x04
0x06
0x02
0x03
0x0f
0x0e
Note: logon server name starts with two '\' characters and is upper case.
Note: logon client is the machine, not the user.
Note: the initial LanManager password hash, against which the challenge is issued, is the machine name itself (lower case). there will becalls issued (LSA Server Password Set) which will change this, later. refusing these calls allows you to always deal with the same password (i.e the LM# of the machine name in lower case).
undocumented buffer pointer
logon server unicode string
logon client unicode string
client challenge
Note: in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).
Note: neg_flags in the response is the same as that in the request.
Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.
client identification info
client-calculated credentials
padding to 4-byte align with start of SMB header.
neg_flags - negotiated flags (usual value is 0x0000 01ff)
Note: the new password is suspected to be a DES encryption using the old password to generate the key.
Note: in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).
Note: the server credentials are constructed from the client-calculated credentials and the client time + 1 second.
Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.
Note: valid_user is True iff the username and password hash are valid for the requested domain.
undocumented buffer pointer
server credentials. server time stamp appears to be ignored.
if (valid_user) { UINT16 3 - switch value indicating USER_INFO structure. VOID* non-zero - pointer to USER_INFO structure USER_INFO user logon information UINT32 1 - Authoritative response; 0 - Non-Auth? return 0 - indicates success } else { UINT16 0 - switch value. value to indicate no user presumed. VOID* 0x0000 0000 - indicates no USER_INFO structure. UINT32 1 - Authoritative response; 0 - Non-Auth? return 0xC000 0064 - NT_STATUS_NO_SUCH_USER. }
Note: presumably, the SAM_INFO structure is validated, and a (currently undocumented) error code returned if the Logoff is invalid.
Note: mailslots will contain a response mailslot, to which the response should be sent. the target NetBIOS name is REQUEST_NAME<20>, where REQUEST_NAME is the name of the machine that sent the request.
Note: NTversion, LMNTtoken, LM20token in response are the same as those given in the request.
0x0007 - Query for PDC
machine name
response mailslot
padding to 2-byte align with start of mailslot.
machine name
NTversion
LMNTtoken
LM20token
0x000A - Respose to Query for PDC
machine name (in uppercase)
padding to 2-byte align with start of mailslot.
machine name
domain name
NTversion (same as received in request)
LMNTtoken (same as received in request)
LM20token (same as received in request)
Note: machine name in response is preceded by two '\' characters.
Note: NTversion, LMNTtoken, LM20token in response are the same as those given in the request.
Note: user name in the response is presumably the same as that in the request.
0x0012 - SAM Logon
request count
machine name
user name
response mailslot
alloweable account
domain SID size
domain SID, of sid_size bytes.
???? padding to 4? 2? -byte align with start of mailslot.
NTversion
LMNTtoken
LM20token
Defines for this pipe, identifying the query are:
0x0f
0x15
Note: share level and switch value in the response are presumably the same as those in the request.
Note: cifsrap2.txt (section 5) may be of limited assistance here.
pointer (to server name?)
server name
padding to get unicode string 4-byte aligned with the start of the SMB header.
share level
switch value
pointer to SHARE_INFO_1_CTR
share info with 0 entries
preferred maximum length (0xffff ffff)
Intel byte ordered addition of corresponding 4 byte words in arrays A1 and A2
DES ECB encryption of 8 byte data D using 7 byte key K
Lan man hash
NT hash
md4(machine_password) == md4(lsadump $machine.acc) == pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))
ARC4 encryption of data D of length Ld with key K of length Lk
subset of v from bytes m to n, optionally padded with zeroes to length l
E(K[7..7,7],E(K[0..6],D)) computes a credential
4 byte current time
8 byte client and server challenges Rc,Rs: 8 byte client and server credentials
C->S ReqChal,Cc S->C Cs
C & S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))
C: Rc = Cred(Ks,Cc) C->S Authenticate,Rc S: Rs = Cred(Ks,Cs), assert(Rc == Cred(Ks,Cc)) S->C Rs C: assert(Rs == Cred(Ks,Cs))
On joining the domain the client will optionally attempt to change its password and the domain controller may refuse to update it depending on registry settings. This will also occur weekly afterwards.
C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C->S ServerPasswordSet,Rc',Tc,arc4(Ks[0..7,16],lmowf(randompassword()) C: Rc = Cred(Ks,Rc+Tc+1) S: assert(Rc' == Cred(Ks,Rc+Tc)), Ts = Time() S: Rs' = Cred(Ks,Rs+Tc+1) S->C Rs',Ts C: assert(Rs' == Cred(Ks,Rs+Tc+1)) S: Rs = Rs'
User: U with password P wishes to login to the domain (incidental data such as workstation and domain omitted)
C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C->S NetLogonSamLogon,Rc',Tc,U,arc4(Ks[0..7,16],16,ntowf(P),16), arc4(Ks[0..7,16],16,lmowf(P),16) S: assert(Rc' == Cred(Ks,Rc+Tc)) assert(passwords match those in SAM) S: Ts = Time()
S->C Cred(Ks,Cred(Ks,Rc+Tc+1)),userinfo(logon script,UID,SIDs,etc) C: assert(Rs == Cred(Ks,Cred(Rc+Tc+1)) C: Rc = Cred(Ks,Rc+Tc+1)
On first joining the domain the session key could be computed by anyone listening in on the network as the machine password has a well known value. Until the machine is rebooted it will use this session key to encrypt NT and LM one way functions of passwords which are password equivalents. Any user who logs in before the machine has been rebooted a second time will have their password equivalent exposed. Of course the new machine password is exposed at this time anyway.
None of the returned user info such as logon script, profile path and SIDs *appear* to be protected by anything other than the TCP checksum.
The server time stamps appear to be ignored.
The client sends a ReturnAuthenticator in the SamLogon request which I can't find a use for. However its time is used as the timestamp returned by the server.
The password OWFs should NOT be sent over the network reversibly encrypted. They should be sent using ARC4(Ks,md4(owf)) with the server computing the same function using the owf values in the SAM.
SIDs and RIDs are well documented elsewhere.
A SID is an NT Security ID (see DOM_SID structure). They are of the form:
revision-NN-SubAuth1-SubAuth2-SubAuth3... |
revision-0xNNNNNNNNNNNN-SubAuth1-SubAuth2-SubAuth3... |
currently, the SID revision is 1. The Sub-Authorities are known as Relative IDs (RIDs).
S-1-0-0
S-1-1-0
S-1-2-0
S-1-3-0
S-1-3-1
S-1-3-2
S-1-3-3
S-1-4
A RID is a sub-authority value, as part of either a SID, or in the case of Group RIDs, part of the DOM_GID structure, in the USER_INFO_1 structure, in the LSA SAM Logon response.