📄 ntsec.sgml
字号:
root:S-1-5-32-544:0:</screen></example></listitem></itemizedlist><para>The tools <command>mkpasswd</command> and <command>mkgroup</command>create the needed entries by default. If you don't want that you can usethe options <literal>-s</literal> or <literal>--no-sids</literal>. I suggestnot to do this since ntsec works better when having the SIDs available.</para><para>Please note that the pw_gecos field in <filename>/etc/passwd</filename>is defined as a comma seperated list. The SID has to be the last field!</para><para>As aforementioned you are able to use cygwin account names differentfrom the NT account names. If you want to login thru `telnet' or somethingelse you have to use the special <command>login</command>. You may thenadd another field to pw_gecos which contains the NT user name includingit's domain. So you are able to login as each domain user. The syntaxis easy: Just add an entry of the form U-ntdomain\ntusername to the pw_gecosfield. Note that the SID must still remain the last field in pw_gecos!</para><screen>the_king::1:1:Elvis Presley,U-STILLHERE\elvis,S-1-5-21-1234-5678-9012-1000:/bin/sh</screen><para>For a local user just drop the domain:</para><screen>the_king::1:1:Elvis Presley,U-elvis,S-1-5-21-1234-5678-9012-1000:/bin/sh</screen><para>In either case the password of the user is taken from the NT userdatabase, NOT from the passwd file!</para><para>As in the previous chapter I give my personal<filename>/etc/passwd</filename> and <filename>/etc/group</filename> asexamples. Please note that I've changed these files heavily! There's noneed to change them that way, it's just for testing purposes and...for fun.</para><example><title>/etc/passwd</title><screen>root:*:0:0:Administrators group,S-1-5-32-544::SYSTEM:*:18:18:,S-1-5-18:/home/system:/bin/bashadmin:*:500:513:,S-1-5-21-1844237615-436374069-1060284298-500:/home/Administrator:/bin/bashcorinna:*:100:0:Corinna Vinschen,S-1-5-21-1844237615-436374069-1060284298-1003:/home/corinna:/bin/tcshGuest:*:501:546:,S-1-5-21-1844237615-436374069-1060284298-501:/home/Guest:/bin/bash</screen></example><example><title>/etc/group</title><screen>root:S-1-5-32-544:0:local:S-1-2-0:2:network:S-1-5-2:3:interactive:S-1-5-4:4:authenticatedusers:S-1-5-11:5:SYSTEM:S-1-5-18:18:local_svc:S-1-5-19:19:netwrk_svc:S-1-5-20:20:none:S-1-5-21-1844237615-436374069-1060284298-513:513:bckup_op:S-1-5-32-551:551:guests:S-1-5-32-546:546:pwrusers:S-1-5-32-547:547:replicator:S-1-5-32-552:552:users:S-1-5-32-545:545:</screen></example><para>If you want to do similar changes to your files, please do that onlyif you're feeling comfortably with the concepts. Otherwise don't be surprisedif some stuff doesn't work anymore. If you screwed up things, revert to filescreated by mkpasswd and mkgroup. Especially don't change the uid or the nameof user SYSTEM. Even if that works mostly, some Cygwin applications runningas local service under that account could behave strangly suddenly.</para></sect2><sect2 id="ntsec-mapping"><title>The mapping leak</title><para>Now its time to point out the leak in the NT permissions.The official documentation explains in short the following:</para><itemizedlist spacing="compact"><listitem><para>access allow ACEs are accumulated regarding to thegroup membership of the caller.</para></listitem><listitem><para>The order of ACEs is important. The system reads themin sequence until either any needed right is denied or all needed rightsare granted. Later ACEs are then not taken into account.</para></listitem><listitem><para>All access denied ACEs _should_ precede anyaccess allowed ACE.</para></listitem></itemizedlist><para>Note that the last rule is a preference, not a law. NT will correctlydeal with the ACL regardless of the sequence order. The second rule isnot modified to get the ACEs in the prefered order.</para><para>Unfortunately the security tab of the NT4 explorer is completelyunable to deal with access denied ACEs while the explorer of W2K rearrangesthe order of the ACEs before you can read them. Thank God, the sort orderremains unchanged if one presses the Cancel button.</para><para>You still ask "Where is the leak?" NT ACLs are unable to reflect eachpossible combination of POSIX permissions. Example:</para><screen>rw-r-xrw-</screen><para>1st try:</para><screen>UserAllow: 110GroupAllow: 101OthersAllow: 110</screen><para>Hmm, because of the accumulation of allow rights the user mayexecute because the group may execute.</para><para>2st try:</para><screen>UserDeny: 001GroupAllow: 101OthersAllow: 110</screen><para>Now the user may read and write but not execute. Better? No!Unfortunately the group may write now because others may write.</para><para>3rd try:</para><screen>UserDeny: 001GroupDeny: 010GroupAllow: 001OthersAllow: 110</screen><para>Now the group may not write as intended but unfortunately the user maynot write anymore, too. How should this problem be solved? According tothe official rules a UserAllow has to follow the GroupDeny but it'seasy to see that this can never be solved that way.</para><para>The only chance:</para><screen>UserDeny: 001UserAllow: 010GroupDeny: 010GroupAllow: 001OthersAllow: 110</screen><para>Again: This works for both, NT4 and W2K. Only the GUIs aren'table to deal with that order.</para></sect2><sect2 id="ntsec-aclfuncs"><title>New acl API</title><para>For dealing with ACLs Cygwin now has the acl API as it'simplemented in newer versions of Solaris. The new data structurefor a single ACL entry (ACE in NT terminology) is defined in<filename>sys/acl.h</filename> as:</para><screen>typedef struct acl { int a_type; /* entry type */ uid_t a_id; /* UID | GID */ mode_t a_perm; /* permissions */} aclent_t;</screen><para>The a_perm member of the aclent_t type contains only the bitsfor read, write and execute as in the file mode. If eg. read permissionis granted, all read bits (S_IRUSR, S_IRGRP, S_IROTH) are set.CLASS_OBJ or MASK ACL entries are not fully implemented yet.</para><para>The new API calls are</para><screen>acl(2), facl(2)aclcheck(3),aclsort(3),acltomode(3), aclfrommode(3),acltopbits(3), aclfrompbits(3),acltotext(3), aclfromtext(3)</screen><para>Like in Solaris, Cygwin has two new commands for working withACLs on the command line: <command>getfacl</command> and<command>setfacl</command>.</para><para>Online man pages for the aforementioned commands and API callscan be found on eg. http://docs.sun.com</para></sect2><sect2 id="ntsec-setuid"><title>New setuid concept</title><para>UNIX applications which have to switch the user context are usingthe <command>setuid</command> and <command>seteuid</command> calls whichare not part of the Windows API.Nevertheless these calls are supported under Windows NT/W2K since Cygwinrelease 1.1.3. Because of the nature of NT security an application whichneeds the ability has to be patched, though.</para><para>NT uses so called `access tokens' to identify a user and it'spermissions. To switch the user context the application has to requestsuch an `access token'. This is typically done by calling the NT APIfunction <command>LogonUser</command>. The access token is returned andeither used in <command>ImpersonateLoggedOnUser</command> to change usercontext of the current process or in <command>CreateProcessAsUser</command>to change user context of a spawned child process. An important restrictionis that the application using <command>LogonUser</command> must have specialpermissions:</para><screen>"Act as part of the operating system""Replace process level token""Increase quotas"</screen><para>Note that administrators do not have all these user rights set by default.</para><para>Two new Cygwin calls are introduced to support porting<command>setuid</command> applications with a minimum of effort. You onlygive Cygwin the right access token and then you can call<command>seteuid</command> or <command>setuid</command> as usual in POSIXapplications. The call to <command>sexec</command> is not neededanymore. Porting a <command>setuid</command> application is illustrated bya short example:</para><screen>/* First include all needed cygwin stuff. */#ifdef __CYGWIN__#include <windows.h>#include <sys/cygwin.h>/* Use the following define to determine the Windows version */#define is_winnt (GetVersion() < 0x80000000)#endif[...] struct passwd *user_pwd_entry = getpwnam (username); char *cleartext_password = getpass ("Password:");[...]#ifdef __CYGWIN__ /* Patch the typical password test. */ if (is_winnt) { HANDLE token; /* Try to get the access token from NT. */ token = cygwin_logon_user (user_pwd_entry, cleartext_password); if (token == INVALID_HANDLE_VALUE) error_exit; /* Inform Cygwin about the new impersonation token. Cygwin is able now, to switch to that user context by setuid or seteuid calls. */ cygwin_set_impersonation_token (token); } else#endif /* CYGWIN */ /* Use standard method for W9X as well. */ hashed_password = crypt (cleartext_password, salt); if (!user_pwd_entry || strcmp (hashed_password, user_pwd_entry->pw_password)) error_exit;[...] /* Everything else remains the same! */ setegid (user_pwd_entry->pw_gid); seteuid (user_pwd_entry->pw_uid); execl ("/bin/sh", ...);</screen><para>The new Cygwin call to retrive an access token is defined as follows:</para><screen>#include <windows.h>#include <sys/cygwin.h>HANDLEcygwin_logon_user (struct passwd *pw, const char *cleartext_password)</screen><para>You can call that function as often as you want for different userlogons and remeber the access tokens for further calls to the second function.</para><screen>#include <windows.h>#include <sys/cygwin.h>voidcygwin_set_impersonation_token (HANDLE hToken);</screen><para> is the call to inform Cygwin about the user context to which furthercalls to <command>setuid</command>/<command>seteuid</command> should switch to.While you need always the correct access token to do a<command>setuid</command>/<command>seteuid</command> to another users context,you are always able to use <command>setuid</command>/<command>seteuid</command>to return to your own user context by giving your own uid as parameter.</para><para>If you have remembered several access tokens from calls to<command>cygwin_logon_user</command> you can switch to different usercontexts by observing the following order:</para><screen> cygwin_set_impersonation_token (user1_token); seteuid (user1_uid);[...] seteuid (own_uid); cygwin_set_impersonation_token (user2_token); seteuid (user2_uid);[...] seteuid (own_uid); cygwin_set_impersonation_token (user1_token); seteuid (user1_uid);etc.</screen></sect2><sect2 id="ntsec-release1.3.3"><title>New since Cygwin release 1.3.3</title><para>Since Cygwin release 1.3.3, applications having the<command>Create a process level token</command> user right can switch usercontext without giving a password by just calling the usual<command>setuid</command>, <command>seteuid</command>,<command>setgid</command> and <command>setegid</command> functions. This istypically only given to the SYSTEM user. However, this now allows to switchthe user context using e. g. rhosts authentication or (when running sshdunder SYSTEM account as service) public key authentication.</para><para>An important restriction of this method is, that a process started underSYSTEM account can't access network shares which require authentication.This also applies to the subprocesses which switched the user context without a password. People using network home drives are typically notable to access it when trying to login using ssh or rsh without password.</para></sect2></sect1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -