preparing for release of 1.9.18alpha2
[samba.git] / docs / textdocs / cifsntdomain.txt
1 !==
2 !== cifsntdomain.txt for Samba release 1.9.18alpha2 22 Oct 1997
3 !==
4 NT Domain Authentication
5 ------------------------
6
7 Authors:        - Luke Kenneth Casson Leighton (lkcl@switchboard.net)
8                 Copyright (C) 1997 Luke Kenneth Casson Leighton
9                 - Paul Ashton                  (paul@argo.demon.co.uk)
10                 Copyright (C) 1997 Paul Ashton
11
12 Version:                0.017 (20oct97)
13
14 Distribution:   Unlimited and encouraged, for the purposes of implementation
15                 and comments.  Feedback welcomed by the authors.
16
17 Liability:      Absolutely none accepted implicitly or explicitly, direct
18                 or consequentially, for use, abuse, misuse, lack of use,
19                 misunderstandings, mistakes, omissions, mis-information for
20                 anything in or not in, related to or pertaining to this
21                 document or anything else that a lawyer can think of or not
22                 think of.
23
24 Warning:        Please bear in mind that an incorrect implementation of this
25                 protocol can cause NT workstation to fail irrevocably, for
26                 which the authors accept no liability (see above).  Please
27                 contact your vendor if you have any problems.
28
29 Sources:        - Packet Traces from Netmonitor (Service Pack 1 and above)
30                 - Paul Ashton and Luke Leighton's other "NT Domain" doc.
31                 - CIFS documentation - cifs6.txt
32                 - CIFS documentation - cifsrap2.txt
33
34 Original:       http://mailhost.cb1.com/~lkcl/cifsntdomain.txt.
35                 (Controlled copy maintained by lkcl@switchboard.net)
36
37 Credits:        - Paul Ashton: loads of work with Net Monitor; 
38                   understanding the NT authentication system;
39                   reference implementation of the NT domain support on which
40                   this document is originally based.
41                 - Linus Nordberg: producing c-code from Paul's crypto spec.
42                 - Windows Sourcer development team
43
44 Contents:
45
46 1) Introduction
47
48 2) Structures and notes
49
50    2.1) Notes
51    2.2) Structures
52
53 3) Transact Named Pipe Header/Tail
54
55    3.1) Header
56    3.2) Tail
57
58 4) NTLSA Transact Named Pipe
59
60    4.1) LSA Open Policy
61    4.2) LSA Query Info Policy
62    4.3) LSA Enumerate Trusted Domains
63    4.4) LSA Open Secret
64    4.5) LSA Close
65    4.6) LSA Lookup SIDS
66    4.7) LSA Lookup Names
67
68 5) NETLOGON rpc Transact Named Pipe
69
70    5.1) LSA Request Challenge
71    5.2) LSA Authenticate 2
72    5.3) LSA Server Password Set
73    5.4) LSA SAM Logon
74    5.5) LSA SAM Logoff
75
76 6) \\MAILSLOT\NET\NTLOGON
77
78    6.1) Query for PDC
79    6.2) SAM Logon
80
81 7) SRVSVC Transact Named Pipe
82
83    7.1) Net Share Enum
84    7.2) Net Server Get Info
85
86 Appendix:
87
88 A1) Cryptographic side of NT Domain Authentication
89
90
91
92 1) Introduction
93 ---------------
94
95
96 This document contains information to provide an NT workstation with login
97 services, without the need for an NT server.
98
99 It should be possible to select a domain instead of a workgroup (in the NT
100 workstation's TCP/IP settings) and after the obligatory reboot, type in a
101 username, password, select a domain and successfully log in.  I would
102 appreciate any feedback on your experiences with this process, and any
103 comments, corrections and additions to this document.
104
105
106 The packets described here can be easily derived from (and are probably
107 better understood using) Netmon.exe.  You will need to use the version
108 of Netmon that matches your system, in order to correctly decode the
109 NETLOGON, lsarpc and srvsvc Transact pipes.  This document is derived from
110 NT Service Pack 1 and its corresponding version of Netmon.  It is intended
111 that an annotated packet trace be produced, which will likely be more
112 instructive than this document.
113
114 Also needed, to fully implement NT Domain Login Services, is the 
115 document describing the cryptographic part of the NT authentication.
116 This document is available from comp.protocols.smb; from the ntsecurity.net
117 digest and from the samba digest, amongst other sources.
118
119 A copy is available from:
120
121 http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708&L=ntbugtraq&O=A&P=2935
122 http://mailhost.cb1.com/~lkcl/crypt.html
123
124
125 A c-code implementation, provided by Linus Nordberg <linus@incolumitas.se>
126 of this protocol is available from:
127
128 http://samba.anu.edu.au/cgi-bin/mfs/01/digest/1997/97aug/0391.html
129 http://mailhost.cb1.com/~lkcl/crypt.txt
130
131
132 Also used to provide debugging information is the Check Build version of
133 NT workstation, and enabling full debugging in NETLOGON.  This is
134 achieved by setting the following REG_SZ registry key to 0x1ffffff:
135
136 HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters
137
138 - Incorrect direct editing of the registry can cause your machine to fail.
139   Then again, so can incorrect implementation of this protocol.
140   See "Liability:" above.
141
142
143 Bear in mind that each packet over-the-wire will have its origin in an
144 API call.  Therefore, there are likely to be structures, enumerations
145 and defines that are usefully documented elsewhere.
146
147
148 This document is by no means complete or authoritative.  Missing sections
149 include, but are not limited to:
150
151 - the meaning (and use by NT) of SIDs and RIDs.
152
153 - mappings of RIDs to usernames (and vice-versa).
154
155 - what a User ID is and what a Group ID is.
156
157 - the exact meaning/definition of various magic constants or enumerations.
158
159 - the reply error code and use of that error code when a workstation
160   becomes a member of a domain (to be described later).  Failure to
161   return this error code will make the workstation report that it is
162   already a member of the domain.
163
164 - the cryptographic side of the NetrServerPasswordSet command, which would
165   allow the workstation to change its password.  This password is used to
166   generate the long-term session key.  [It is possible to reject this
167   command, and keep the default workstation password].
168    
169
170 2) Notes and Structures
171 -----------------------
172
173
174 2.1) Notes
175 ----------
176
177 - In the SMB Transact pipes, some "Structures", described here, appear to be
178   4-byte aligned with the SMB header, at their start.  Exactly which
179   "Structures" need aligning is not precisely known or documented.
180
181 - In the UDP NTLOGON Mailslots, some "Structures", described here, appear to be
182   2-byte aligned with the start of the mailslot, at their start.
183
184 - Domain SID is of the format S-revision-version-auth1-auth2...authN.
185   e.g S-1-5-123-456-789-123-456.  the 5 could be a sub-revision.
186
187 - any undocumented buffer pointers must be non-zero if the string buffer it
188   refers to contains characters.  exactly what value they should be is unknown.
189   0x0000 0002 seems to do the trick to indicate that the buffer exists.  a
190   NULL buffer pointer indicates that the string buffer is of zero length.
191   If the buffer pointer is NULL, then it is suspected that the structure it
192   refers to is NOT put into (or taken out of) the SMB data stream.  This is
193   empirically derived from, for example, the LSA SAM Logon response packet,
194   where if the buffer pointer is NULL, the user information is not inserted
195   into the data stream.  Exactly what happens with an array of buffer pointers
196   is not known, although an educated guess can be made.
197
198 - an array of structures (a container) appears to have a count and a pointer.
199   if the count is zero, the pointer is also zero.  no further data is put
200   into or taken out of the SMB data stream.  if the count is non-zero, then
201   the pointer is also non-zero.  immediately following the pointer is the
202   count again, followed by an array of container sub-structures.  the count
203   appears a third time after the last sub-structure.
204
205   
206
207 2.2) Structures
208 ---------------
209
210 - sizeof VOID* is 32 bits.
211
212 - sizeof char is 8 bits.
213
214 - UTIME is 32 bits, indicating time in seconds since 01jan1970.  documented
215   in cifs6.txt (section 3.5 page, page 30).
216
217 - NTTIME is 64 bits.  documented in cifs6.txt (section 3.5 page, page 30).
218
219 - DOM_SID (domain SID structure) :
220
221         UINT32             num of sub-authorities in domain SID
222         UINT8              SID revision number
223         UINT8              num of sub-authorities in domain SID
224         UINT8[6]           6 bytes for domain SID - Identifier Authority.
225         UINT16[n_subauths] domain SID sub-authorities
226
227   Note: the domain SID is documented elsewhere.
228
229 - STR (string) :
230
231         char[]             null-terminated string of ascii characters.
232
233 - UNIHDR (unicode string header) :
234
235         UINT16             length of unicode string
236         UINT16             max length of unicode string
237         UINT32             4 - undocumented.
238    
239 - UNIHDR2 (unicode string header plus buffer pointer) :
240
241         UNIHDR             unicode string header
242         VOID*              undocumented buffer pointer
243
244 - UNISTR (unicode string) :
245
246         UINT16[]           null-terminated string of unicode characters.
247
248 - NAME (length-indicated unicode string) :
249
250         UINT32             length of unicode string
251         UINT16[]           null-terminated string of unicode characters.
252
253 - UNISTR2 (aligned unicode string) :
254
255         UINT8[]            padding to get unicode string 4-byte aligned
256                            with the start of the SMB header.
257         UINT32             max length of unicode string
258         UINT32             0 - undocumented
259         UINT32             length of unicode string
260         UINT16[]           string of uncode characters.
261
262 - POL_HND (LSA policy handle) :
263
264     char[20]           policy handle
265
266 - DOM_SID2 (domain SID structure, SIDS stored in unicode) :
267
268         UINT32             5 - SID type
269         UINT32             0 - undocumented
270         UNIHDR2            domain SID unicode string header
271         UNISTR             domain SID unicode string
272
273   Note: there is a conflict between the unicode string header and the
274         unicode string itself as to which to use to indicate string
275         length.  this will need to be resolved.
276
277   Note: the SID type indicates, for example, an alias; a well-known group etc.
278         this is documented somewhere.
279
280 - DOM_RID (domain RID structure) :
281
282         UINT32             5 - well-known SID.  1 - user SID (see ShowACLs)
283         UINT32             5 - undocumented
284         UINT32             domain RID 
285         UINT32             0 - domain index out of above reference domains
286         
287
288 - LOG_INFO (server, account, client structure) :
289
290   Note: logon server name starts with two '\' characters and is upper case.
291
292   Note: account name is the logon client name from the LSA Request Challenge,
293         with a $ on the end of it, in upper case.
294
295         VOID*       undocumented buffer pointer
296         UNISTR2     logon server unicode string
297         UNISTR2     account name unicode string
298         UINT16      sec_chan - security channel type
299         UNISTR2     logon client machine unicode string
300
301 - CLNT_SRV (server, client names structure) :
302
303   Note: logon server name starts with two '\' characters and is upper case.
304
305         VOID*       undocumented buffer pointer
306         UNISTR2     logon server unicode string
307         VOID*       undocumented buffer pointer
308         UNISTR2     logon client machine unicode string
309
310 - CREDS (credentials + time stamp)
311
312         char[8]     credentials
313         UTIME       time stamp
314     
315 - CLNT_INFO2 (server, client structure, client credentials) :
316
317   Note: whenever this structure appears in a request, you must take a copy
318         of the client-calculated credentials received, because they will be
319         used in subsequent credential checks.  the presumed intention is to
320         maintain an authenticated request/response trail.
321         
322         CLNT_SRV     client and server names
323         UINT8[]      ???? padding, for 4-byte alignment with SMB header.
324         VOID*        pointer to client credentials.
325         CREDS        client-calculated credentials + client time
326
327 - CLNT_INFO (server, account, client structure, client credentials) :
328
329   Note: whenever this structure appears in a request, you must take a copy
330         of the client-calculated credentials received, because they will be
331         used in subsequent credential checks.  the presumed intention is to
332         maintain an authenticated request/response trail.
333         
334         LOG_INFO    logon account info
335         CREDS       client-calculated credentials + client time
336
337 - ID_INFO_1 (id info structure, auth level 1) :
338
339     VOID*         ptr_id_info_1
340     UNIHDR        domain name unicode header
341     UINT32        param control
342     UINT64        logon ID
343     UNIHDR        user name unicode header
344     UNIHDR        workgroup name unicode header
345     char[16]      rc4 LM OWF Password
346     char[16]      rc4 NT OWF Password
347     UNISTR2       domain name unicode string
348     UNISTR2       user name unicode string
349     UNISTR2       workgroup name unicode string
350
351 - SAM_INFO (sam logon/logoff id info structure) :
352
353         CLNT_INFO2  client identification/authentication info
354         VOID*       pointer to return credentials.
355         CRED        return credentials - ignored.
356         UINT16      logon level
357         UINT16      switch value
358
359         switch (switch_value)
360         case 1:
361         {
362             ID_INFO_1     id_info_1;
363         }
364
365 - GID (group id info) :
366
367         UINT32      group id
368         UINT32      user attributes (only used by NT 3.1 and 3.51)
369
370 - DOM_REF (domain reference info) :
371
372         VOID*                    undocumented buffer pointer.
373         UINT32                   num referenced domains?
374         VOID*                    undocumented domain name buffer pointer.
375         UINT32                   32 - max number of entries
376         UINT32                   4 - num referenced domains?
377
378         UNIHDR2                  domain name unicode string header
379         UNIHDR2[num_ref_doms-1]  referenced domain unicode string headers
380
381         UNISTR                   domain name unicode string
382         DOM_SID[num_ref_doms]    referenced domain SIDs
383
384 - DOM_INFO (domain info, levels 3 and 5 are the same)) :
385
386         UINT8[]     ??? padding to get 4-byte alignment with start of SMB header
387         UINT16      domain name string length * 2
388         UINT16      domain name string length * 2
389         VOID*       undocumented domain name string buffer pointer
390         VOID*       undocumented domain SID string buffer pointer
391         UNISTR2     domain name (unicode string)
392         DOM_SID     domain SID
393
394 - USER_INFO (user logon info) :
395
396         NTTIME            logon time
397         NTTIME            logoff time
398         NTTIME            kickoff time
399         NTTIME            password last set time
400         NTTIME            password can change time
401         NTTIME            password must change time
402
403         UNIHDR            username unicode string header
404         UNIHDR            user's full name unicode string header
405         UNIHDR            logon script unicode string header
406         UNIHDR            profile path unicode string header
407         UNIHDR            home directory unicode string header
408         UNIHDR            home directory drive unicode string header
409
410         UINT16            logon count
411         UINT16            bad password count
412
413         UINT32            User ID
414         UINT32            Group ID
415         UINT32            num groups
416         VOID*             undocumented buffer pointer to groups.
417
418         UINT32            user flags
419         char[16]          unused user session key
420
421         UNIHDR            logon server unicode string header
422         UNIHDR            logon domain unicode string header
423         VOID*             undocumented logon domain id pointer
424         char[40]          40 undocumented padding bytes.  future expansion?
425
426         UINT32            0 - num_other_sids?
427         VOID*             NULL - undocumented pointer to other domain SIDs.
428         
429         UNISTR2           username unicode string
430         UNISTR2           user's full name unicode string
431         UNISTR2           logon script unicode string
432         UNISTR2           profile path unicode string
433         UNISTR2           home directory unicode string
434         UNISTR2           home directory drive unicode string
435
436         UINT32            num groups
437         GID[num_groups]   group info
438
439         UNISTR2           logon server unicode string
440         UNISTR2           logon domain unicode string
441
442         DOM_SID           domain SID
443         DOM_SID[num_sids] other domain SIDs?
444
445 - SH_INFO_1_PTR (pointers to level 1 share info strings):
446
447 Note:   see cifsrap2.txt section5, page 10.
448
449         0 for shi1_type indicates a  Disk.
450         1 for shi1_type indicates a  Print Queue.
451         2 for shi1_type indicates a  Device.
452         3 for shi1_type indicates an IPC pipe.
453         0x8000 0000 (top bit set in shi1_type) indicates a hidden share.
454
455         VOID*        shi1_netname - pointer to net name
456         UINT32       shi1_type    - type of share.  0 - undocumented.
457         VOID*        shi1_remark  - pointer to comment.
458
459 - SH_INFO_1_STR (level 1 share info strings) :
460
461         UNISTR2      shi1_netname - unicode string of net name
462         UNISTR2      shi1_remark  - unicode string of comment.
463
464 - SHARE_INFO_1_CTR :
465
466     share container with 0 entries:
467
468         UINT32        0 - EntriesRead
469         UINT32        0 - Buffer
470
471     share container with > 0 entries:
472
473         UINT32                      EntriesRead
474         UINT32                      non-zero - Buffer
475         UINT32                      EntriesRead
476
477         SH_INFO_1_PTR[EntriesRead]  share entry pointers
478         SH_INFO_1_STR[EntriesRead]  share entry strings
479
480         UINT8[]                     padding to get unicode string 4-byte
481                                     aligned with start of the SMB header.
482         UINT32                      EntriesRead
483         UINT32                      0 - padding
484
485 - SERVER_INFO_101 :
486
487 Note:   see cifs6.txt section 6.4 - the fields described therein will be
488         of assistance here.  for example, the type listed below is the
489         same as fServerType, which is described in 6.4.1.
490
491         SV_TYPE_WORKSTATION        0x00000001  All workstations
492         SV_TYPE_SERVER             0x00000002  All servers
493         SV_TYPE_SQLSERVER          0x00000004  Any server running with SQL
494                                                server
495         SV_TYPE_DOMAIN_CTRL        0x00000008  Primary domain controller
496         SV_TYPE_DOMAIN_BAKCTRL     0x00000010  Backup domain controller
497         SV_TYPE_TIME_SOURCE        0x00000020  Server running the timesource
498                                                service
499         SV_TYPE_AFP                0x00000040  Apple File Protocol servers
500         SV_TYPE_NOVELL             0x00000080  Novell servers
501         SV_TYPE_DOMAIN_MEMBER      0x00000100  Domain Member
502         SV_TYPE_PRINTQ_SERVER      0x00000200  Server sharing print queue
503         SV_TYPE_DIALIN_SERVER      0x00000400  Server running dialin service.
504         SV_TYPE_XENIX_SERVER       0x00000800  Xenix server
505         SV_TYPE_NT                 0x00001000  NT server
506         SV_TYPE_WFW                0x00002000  Server running Windows for
507
508         SV_TYPE_SERVER_NT          0x00008000  Windows NT non DC server
509         SV_TYPE_POTENTIAL_BROWSER  0x00010000  Server that can run the browser
510                                                service
511         SV_TYPE_BACKUP_BROWSER     0x00020000  Backup browser server
512         SV_TYPE_MASTER_BROWSER     0x00040000  Master browser server
513         SV_TYPE_DOMAIN_MASTER      0x00080000  Domain Master Browser server
514         SV_TYPE_LOCAL_LIST_ONLY    0x40000000  Enumerate only entries marked
515                                                "local"
516         SV_TYPE_DOMAIN_ENUM        0x80000000  Enumerate Domains. The pszServer
517                                                and pszDomain parameters must be
518                                                NULL.
519
520         UINT32        500 - platform_id
521         VOID*         pointer to name
522         UINT32        5 - major version
523         UINT32        4 - minor version
524         UINT32        type (SV_TYPE_... bit field)
525         VOID*         pointer to comment
526
527         UNISTR2       sv101_name - unicode string of server name
528         UNISTR2       sv_101_comment  - unicode string of server comment.
529
530         UINT8[]       padding to get unicode string 4-byte
531                       aligned with start of the SMB header.
532
533
534
535 3) Transact Named Pipe Header/Tail
536 ----------------------------------
537
538 Interesting note: if you set packed data representation to 0x0100 0000 then
539 all 4-byte and 2-byte word ordering is turned around.
540
541 3.1) Header
542 -----------
543
544 The start of each of the NTLSA and NETLOGON named pipes begins with:
545
546 00  UINT8         5 - RPC major version
547 01  UINT8         0 - RPC minor version
548 02  UINT8         2 - RPC response packet
549 03  UINT8         3 - first frag + last frag
550 04  UINT32        0x1000 0000 - packed data representation
551 08  UINT16        fragment length - data size (bytes) inc header and tail.
552 0A  UINT16        0 - authentication length 
553 0C  UINT32        call identifier.  matches 12th UINT32 of incoming RPC data.
554 10  UINT32        allocation hint - data size (bytes) minus header and tail.
555 14  UINT16        0 - presentation context identifier
556 16  UINT8         0 - cancel count
557 17  UINT8         0 - reserved
558 18  ......        start of data (goes on for allocation_hint bytes)
559
560
561 3.2 Tail
562 --------
563
564 The end of each of the NTLSA and NETLOGON named pipes ends with:
565
566     ......        end of data
567     UINT32        return code
568
569
570
571 4) NTLSA Transact Named Pipe
572 ----------------------------
573         
574 Defines for this pipe, identifying the query are:
575
576 - LSA Open Policy:               0x2c
577 - LSA Query Info Policy:         0x07
578 - LSA Enumerate Trusted Domains: 0x0d
579 - LSA Open Secret:               0xff
580 - LSA Lookup SIDs:               0xfe
581 - LSA Lookup Names:              0xfd
582 - LSA Close:                     0x00
583
584
585 4.1) LSA Open Policy
586 --------------------
587
588 Note:   The policy handle can be anything you like.
589
590 Request:
591
592     no extra data.
593
594 Response:
595
596     POL_HND   LSA policy handle
597
598     return    0 - indicates success
599
600
601 4.2) LSA Query Info Policy
602 --------------------------
603
604 Note:   The info class in response must be the same as that in the request.
605
606 Request:
607
608     POL_HND   LSA policy handle
609     UINT16    info class (also a policy handle?)
610
611 Response:
612
613     VOID*     undocumented buffer pointer
614     UINT16    info class (same as info class in request).
615     
616     switch (info class)
617     case 3:
618     case 5:
619     {
620         DOM_INFO domain info, levels 3 and 5 (are the same).
621     }
622
623     return    0 - indicates success
624
625
626 4.3) LSA Enumerate Trusted Domains
627 ----------------------------------
628
629 Request:
630
631     no extra data
632
633 Response:
634
635     UINT32     0 - enumeration context
636     UINT32     0 - entries read
637     UINT32     0 - trust information
638
639     return     0x8000 001a - "no trusted domains" success code
640
641
642 4.4) LSA Open Secret
643 --------------------
644
645 Request:
646
647     no extra data
648
649 Response:
650
651     UINT32    0 - undocumented
652     UINT32    0 - undocumented
653     UINT32    0 - undocumented
654     UINT32    0 - undocumented
655     UINT32    0 - undocumented
656
657     return    0x0C00 0034 - "no such secret" success code
658
659
660 4.5) LSA Close
661 --------------
662
663 Request:
664
665     no extra data
666
667 Response:
668
669     UINT32    0 - undocumented
670     UINT32    0 - undocumented
671     UINT32    0 - undocumented
672     UINT32    0 - undocumented
673     UINT32    0 - undocumented
674
675     return    0 - indicates success
676
677
678 4.6) LSA Lookup SIDS
679 --------------------
680
681 Note:   num_entries in response must be same as num_entries in request.
682
683 Request:
684
685     POL_HND            LSA policy handle
686     UINT32             num_entries
687     VOID*              undocumented domain SID buffer pointer
688     VOID*              undocumented domain name buffer pointer
689     VOID*[num_entries] undocumented domain SID pointers to be looked up.
690     DOM_SID[num_entries] domain SIDs to be looked up.
691     char[16]           completely undocumented 16 bytes.
692
693 Response:
694
695     DOM_REF               domain reference response
696
697     UINT32                num_entries (listed above)
698     VOID*                 undocumented buffer pointer
699
700     UINT32                num_entries (listed above)
701     DOM_SID2[num_entries] domain SIDs (from Request, listed above).
702
703     UINT32                num_entries (listed above)
704
705     return                0 - indicates success
706
707
708 4.7) LSA Lookup Names
709 ---------------------
710
711 Note:   num_entries in response must be same as num_entries in request.
712
713 Request:
714
715     POL_HND            LSA policy handle
716     UINT32             num_entries
717     UINT32             num_entries
718     VOID*              undocumented domain SID buffer pointer
719     VOID*              undocumented domain name buffer pointer
720     NAME[num_entries]  names to be looked up.
721     char[]             undocumented bytes - falsely translated SID structure?
722
723 Response:
724
725     DOM_REF               domain reference response
726
727     UINT32                num_entries (listed above)
728     VOID*                 undocumented buffer pointer
729
730     UINT32                num_entries (listed above)
731     DOM_RID[num_entries]  domain SIDs (from Request, listed above).
732
733     UINT32                num_entries (listed above)
734
735     return                0 - indicates success
736
737
738
739 5) NETLOGON rpc Transact Named Pipe
740 -----------------------------------
741
742 Defines for this pipe, identifying the query are:
743
744 - LSA Request Challenge:         0x04
745 - LSA Server Password Set:       0x06
746 - LSA SAM Logon:                 0x02
747 - LSA SAM Logoff:                0xfc
748 - LSA Auth 2:                    0x0f
749 - LSA Logon Control:             0x0e
750
751
752 5.1) LSA Request Challenge
753 --------------------------
754
755 Note:   logon server name starts with two '\' characters and is upper case.
756
757 Note:   logon client is the machine, not the user.
758
759 Note:   the initial LanManager password hash, against which the challenge
760         is issued, is the machine name itself (lower case).  there will be
761         calls issued (LSA Server Password Set) which will change this, later.
762         refusing these calls allows you to always deal with the same password
763         (i.e the LM# of the machine name in lower case).
764
765 Request:
766
767     VOID*       undocumented buffer pointer
768     UNISTR2     logon server unicode string
769     UNISTR2     logon client unicode string
770     char[8]     client challenge
771
772 Response:
773
774     char[8]     server challenge
775
776     return    0 - indicates success
777
778
779
780 5.2) LSA Authenticate 2
781 -----------------------
782
783 Note:   in between request and response, calculate the client credentials,
784         and check them against the client-calculated credentials (this
785         process uses the previously received client credentials).
786
787 Note:   neg_flags in the response is the same as that in the request.
788
789 Note:   you must take a copy of the client-calculated credentials received
790         here, because they will be used in subsequent authentication packets.
791
792 Request:
793
794     LOG_INFO    client identification info
795
796     char[8]     client-calculated credentials
797     UINT8[]     padding to 4-byte align with start of SMB header.
798     UINT32      neg_flags - negotiated flags (usual value is 0x0000 01ff)
799
800 Response:
801
802     char[8]     server credentials.
803     UINT32      neg_flags - same as neg_flags in request.
804
805     return    0 - indicates success.  failure value unknown.
806
807
808 5.3) LSA Server Password Set
809 ----------------------------
810
811 Note:   the new password is suspected to be a DES encryption using the old
812         password to generate the key.
813
814 Note:   in between request and response, calculate the client credentials,
815         and check them against the client-calculated credentials (this
816         process uses the previously received client credentials).
817
818 Note:   the server credentials are constructed from the client-calculated
819         credentials and the client time + 1 second.
820
821 Note:   you must take a copy of the client-calculated credentials received
822         here, because they will be used in subsequent authentication packets.
823
824 Request:
825
826     CLNT_INFO   client identification/authentication info
827     char[]      new password - undocumented.
828     
829 Response:
830
831     CREDS       server credentials.  server time stamp appears to be ignored.
832
833     return    0 - indicates success; 0xC000 006a indicates failure
834
835
836 5.4) LSA SAM Logon
837 ------------------
838
839 Note:   valid_user is True iff the username and password hash are valid for
840         the requested domain.
841
842 Request:
843
844     SAM_INFO    sam_id structure
845
846 Response:
847
848     VOID*       undocumented buffer pointer
849     CREDS       server credentials.  server time stamp appears to be ignored.
850     
851     if (valid_user)
852     {
853                 UINT16      3 - switch value indicating USER_INFO structure.
854         VOID*     non-zero - pointer to USER_INFO structure
855         USER_INFO user logon information
856
857         UINT32    1 - Authoritative response; 0 - Non-Auth?
858
859         return    0 - indicates success
860     }
861     else
862     {
863                 UINT16    0 - switch value.  value to indicate no user presumed.
864         VOID*     0x0000 0000 - indicates no USER_INFO structure.
865
866         UINT32    1 - Authoritative response; 0 - Non-Auth?
867
868         return    0xC000 0064 - NT_STATUS_NO_SUCH_USER.
869     }
870
871
872 5.5) LSA SAM Logoff
873 --------------------
874
875 Note:   presumably, the SAM_INFO structure is validated, and a (currently
876         undocumented) error code returned if the Logoff is invalid.
877
878 Request:
879
880     SAM_INFO    sam_id structure
881
882 Response:
883
884     VOID*       undocumented buffer pointer
885     CREDS       server credentials.  server time stamp appears to be ignored.
886
887     return      0 - indicates success.  undocumented failure indication.
888
889
890 6) \\MAILSLOT\NET\NTLOGON
891 -------------------------
892
893 Note:   mailslots will contain a response mailslot, to which the response
894         should be sent.  the target NetBIOS name is REQUEST_NAME<20>, where
895         REQUEST_NAME is the name of the machine that sent the request.
896
897
898 6.1) Query for PDC
899 ------------------
900
901 Note:   NTversion, LMNTtoken, LM20token in response are the same as those
902         given in the request.
903
904 Request:
905
906     UINT16         0x0007 - Query for PDC
907     STR            machine name
908     STR            response mailslot
909     UINT8[]        padding to 2-byte align with start of mailslot.
910     UNISTR         machine name
911     UINT32         NTversion
912     UINT16         LMNTtoken
913     UINT16         LM20token
914
915 Response:
916
917     UINT16         0x000A - Respose to Query for PDC
918     STR            machine name (in uppercase)
919     UINT8[]        padding to 2-byte align with start of mailslot.
920     UNISTR         machine name
921     UNISTR         domain name
922     UINT32         NTversion (same as received in request)
923     UINT16         LMNTtoken (same as received in request)
924     UINT16         LM20token (same as received in request)
925
926
927 6.2) SAM Logon
928 --------------
929
930 Note:   machine name in response is preceded by two '\' characters.
931
932 Note:   NTversion, LMNTtoken, LM20token in response are the same as those
933         given in the request.
934
935 Note:   user name in the response is presumably the same as that in the request.
936
937 Request:
938
939     UINT16         0x0012 - SAM Logon
940     UINT16         request count
941     UNISTR         machine name
942     UNISTR         user name
943     STR            response mailslot
944     UINT32         alloweable account
945     UINT32         domain SID size
946     char[sid_size] domain SID, of sid_size bytes.
947     UINT8[]        ???? padding to 4? 2? -byte align with start of mailslot.
948     UINT32         NTversion
949     UINT16         LMNTtoken
950     UINT16         LM20token
951     
952 Response:
953
954     UINT16         0x0013 - Response to SAM Logon
955     UNISTR         machine name
956     UNISTR         user name - workstation trust account
957     UNISTR         domain name 
958     UINT32         NTversion
959     UINT16         LMNTtoken
960     UINT16         LM20token
961
962
963
964 7) SRVSVC Transact Named Pipe
965 -----------------------------
966
967
968 Defines for this pipe, identifying the query are:
969
970 - Net Share Enum :              0x0f
971 - Net Server Get Info :         0x15
972
973
974 7.1) Net Share Enum
975 ------------------
976
977 Note:   share level and switch value in the response are presumably the 
978         same as those in the request.
979
980 Note:   cifsrap2.txt (section 5) may be of limited assistance here.
981
982 Request:
983
984     VOID*             pointer (to server name?)
985         UNISTR2           server name
986
987     UINT8[]           padding to get unicode string 4-byte aligned
988                       with the start of the SMB header.
989
990     UINT32            share level
991     UINT32            switch value
992
993     VOID*             pointer to SHARE_INFO_1_CTR
994     SHARE_INFO_1_CTR  share info with 0 entries
995
996     UINT32            preferred maximum length (0xffff ffff)
997
998 Response:
999
1000     UINT32            share level
1001     UINT32            switch value
1002
1003     VOID*             pointer to SHARE_INFO_1_CTR
1004     SHARE_INFO_1_CTR  share info (only added if share info ptr is non-zero)
1005
1006     return            0 - indicates success
1007
1008
1009 7.2) Net Server Get Info
1010 ------------------
1011
1012 Note:   level is the same value as in the request.
1013
1014 Request:
1015
1016         UNISTR2           server name
1017     UINT32            switch level
1018
1019 Response:
1020
1021     UINT32            switch level
1022     VOID*             pointer to SERVER_INFO_101
1023
1024     SERVER_INFO_101   server info (only added if server info ptr is non-zero)
1025
1026     return            0 - indicates success
1027
1028
1029
1030 Appendix
1031 --------
1032
1033 A1) Cryptographic side of NT Domain Authentication
1034 --------------------------------------------------
1035
1036 Definitions
1037 -----------
1038
1039 Add(A1,A2): Intel byte ordered addition of corresponding 4 byte
1040             words in arrays A1 and A2
1041
1042 E(K,D): DES ECB encryption of 8 byte data D using 7 byte key K
1043
1044 lmowf(): Lan man hash
1045
1046 ntowf(): NT hash
1047
1048 PW: md4(machine_password) =3D=3D md4(lsadump $machine.acc)
1049                           =3D=3D pwdump(machine$)
1050               (initially) =3D=3D md4(lmowf(unicode(machine)))
1051
1052 RC4(K,Lk,D,Ld): RC4 encryption of data D of length Ld with key K
1053                 of length Lk
1054
1055 v[m..n(,l)]: subset of v from bytes m to n, optionally padded
1056              with zeroes to length l
1057
1058 Cred(K,D): E(K[7..7,7],E(K[0..6],D)) computes a credential
1059
1060 Time(): 4 byte current time
1061
1062 Cc,Cs: 8 byte client and server challenges
1063 Rc,Rs: 8 byte client and server credentials
1064