返回列表 回复 发帖

超越ADMINISTRATOR

[这个帖子最后由俊儿在 2003/11/30 02:03pm 第 1 次编辑]

出处:http://lu0.126.com
NT的安全组件里有一个叫Local Security Authority Protected Subsystem.当我们以ADMINISTRATOR登陆时,系统根据缺省的授权,赋予ADMINISTRATOR16个授权.下面乃是详细的清单.
SeChangeNotifyPrivilege
SeSecurityPrivilege
SeBackupPrivilege
SeRestorePrivilege
SeSystemtimePrivilege
SeShutdownPrivilege
SeRemoteShutdownPrivilege
SeTakeOwnershipPrivilege
SeDebugPrivilege
SeSystemEnvironmentPrivilege
SeSystemProfilePrivilege
SeProfileSingleProcessPrivilege
SeIncreaseBasePriorityPrivilege
SeLoadDriverPrivilege
SeCreatePagefilePrivilege
SeIncreaseQuotaPrivilege
其中 SeChangeNotifyPrivilege是缺省打开的.其他则需要调整TOKEN来打开.拥有了这么多的权限后,ADMIN真可谓强大,没有任何其他用户拥有这么多的权限了.但是,仍然有几个更有威力的权限没有赋予ADMIN.那就是SeTcbPrivilege和SeCreateTokenPrivilege. SeTcbPrivilege表示当前用户的操作代表了系统的操作,SeCreateTokenPrivilege更可赤裸裸地为任意令牌创建权限.乃是无上的特权.如果任何人拥有了这两个权限,在NT世界的权利就太夸张了.所以,NT根本就不给任何用户以这两个权限.
出于对权利的渴望,通常病毒,HACKER都会想法获取最高权限.现在,由于NT的保护,直接地获取这2个权限是不行了.那么就需要饶个弯子了.
由于没有直接的API可以增加TOKEN的特权,我们只好通过LSA POLICY库调整用户权限.因为用户权限在LSA POLICY库里被提取出来.当LSA POLICY库里增加了一个特权,用户可以在下一个进程里打开该特权.HEHE... ADMIN组对LSA POLICY库有写权.DD ADMIN没有超级特权,LSA对用户的特权从POLICY库里提取... 真是个可爱的连环套啊.
下面是陆麟写的程序,打开ADMINISTRATOR的SeTcbPrivilege特权.尽管我在程序里面设置了ADMIN检查,但是通过少量的改写就可以时普通用户获取一些超级权限.里面的小技巧大家自己通常可以动出脑筋的.当然并不是通过删除ADMINISTRATOR检验就可以完成的.
当然,这里有编译好的版本供下载.
  1. /*++
  2. sec.cpp
  3.   Written by Lu Lin. 2000.1.30
  4.   A security program demo.
  5.   Show Administrator's SID, and privileges.
  6.   At last we add SE_TCB_NAME right to administrator.
  7.   Of course, this right is almost useless to administrator,
  8.   but you can port it for other users. :)
  9.   You should logon as administrator for run this program
  10.   though ADMIN group's authority is enough.
  11.   Tip: We may get a authority beyound admin for a normal
  12.   user through this demo by a small trick. Think about it
  13.   yourself.:)
  14. --*/
  15. #define UNICODE
  16. #include <windows.h>
  17. #include <iostream.h>
  18. #include <stdio.h>
  19. #include <ntsecapi.h>
  20. //
  21. //Global vars
  22. //
  23. LSA_HANDLE PolicyHandle;
  24. PSID Sid=0;
  25. DWORD cbSid=0;
  26. LPTSTR ReferencedDomainName=0;
  27. DWORD cbReferencedDomainName=0;
  28. SID_NAME_USE peUse;
  29. PUNICODE_STRING UserRights=0; //UnicodeString Pointer to PRIVILEGE
  30. ULONG Count=0; //
  31. WCHAR textSid[200];
  32. HANDLE token=0;
  33. PTOKEN_PRIVILEGES TokenInformation=0;
  34. BOOL owned=0;
  35. //
  36. //quit
  37. //
  38. void quit(int err){
  39. if (Sid) delete Sid;
  40. if (ReferencedDomainName) delete ReferencedDomainName;
  41. if (UserRights) delete UserRights;
  42. if (TokenInformation) delete TokenInformation;
  43. if (token) CloseHandle(token);
  44. if (PolicyHandle) LsaClose(PolicyHandle);
  45. wprintf(L"\n\nWritten by Lu Lin. 2000.1.30\nLicence: Freeware.\n");
  46. if (err){
  47.   exit(0xc0000000);
  48. }
  49. else {
  50.   exit(0);
  51. }
  52. }
  53. void printprivilege(LUID_AND_ATTRIBUTES* luid){
  54. WCHAR dispname[100];
  55. ULONG cb=100;
  56. if (!LookupPrivilegeName(
  57.   0,
  58.   &(luid->Luid),
  59.   dispname,
  60.   &cb)){
  61.   wprintf(L"I can't translate SOME LUID to privilege!\n");
  62.   exit(1);
  63. }
  64. wprintf(L"\tPrivilege: %s\n",dispname);
  65. if (!_wcsicmp(dispname,L"SeTcbPrivilege")) owned=1;
  66. switch (luid->Attributes){
  67. case SE_PRIVILEGE_ENABLED_BY_DEFAULT:
  68.   wprintf(L"\t\tThis privilege is enabled by default\n");
  69.   break;
  70. case SE_PRIVILEGE_ENABLED:
  71.   wprintf(L"\t\tThis privilege is enabled.\n");
  72.   break;
  73. case SE_PRIVILEGE_USED_FOR_ACCESS:
  74.   wprintf(L"\t\tThis privilege is used for access.\n");
  75.   break;
  76. case 3:
  77.   wprintf(L"\t\tThis privilege is always on for you.\n");
  78.   break;
  79. case 0:
  80.   wprintf(L"\t\tThis privilege you owned has not been enabled yet.\n");
  81. }
  82. }
  83. void init(){
  84. WCHAR username[30];
  85. ULONG cb;
  86. OSVERSIONINFO osv;
  87. //if nt?
  88. ZeroMemory(&osv,sizeof(osv));
  89. osv.dwOSVersionInfoSize=sizeof(osv);
  90. GetVersionEx(&osv);
  91. if (!osv.dwPlatformId&VER_PLATFORM_WIN32_NT){
  92.   wprintf(L"This program only runs on NT");
  93.   quit(1);
  94. }
  95. //
  96. //Check if this thread is executed inside administrator's context.
  97. //
  98. cb=30;
  99. GetUserName(username,&cb);
  100. if (_wcsicmp(username,L"administrator")){
  101.   wprintf(L"Logon as administrator first!\n");
  102.   quit(1);
  103. }
  104. wprintf(L"WINDOWS NT %i.%i Build %i %s\n\n",
  105.   osv.dwMajorVersion,
  106.   osv.dwMinorVersion,
  107.   osv.dwBuildNumber,
  108.   osv.szCSDVersion);
  109. }
  110. BOOL GetTextualSid(
  111.     PSID pSid,            // binary Sid
  112.     LPTSTR TextualSid,    // buffer for Textual representation of Sid
  113.     DWORD dwBufferLen // required/provided TextualSid buffersize
  114.     )
  115. {
  116.     PSID_IDENTIFIER_AUTHORITY psia;
  117.     DWORD dwSubAuthorities;
  118.     DWORD dwSidRev=SID_REVISION;
  119.     DWORD dwCounter;
  120.     DWORD dwSidSize;
  121.     // Validate the binary SID.
  122.     if(!IsValidSid(pSid)) return FALSE;
  123.     // Get the identifier authority value from the SID.
  124.     psia = GetSidIdentifierAuthority(pSid);
  125.     // Get the number of subauthorities in the SID.
  126.     dwSubAuthorities = *GetSidSubAuthorityCount(pSid);
  127.     // Compute the buffer length.
  128.     // S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL
  129.     dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
  130.     // Check input buffer length.
  131.     // If too small, indicate the proper size and set last error.
  132.     if (dwBufferLen < dwSidSize)
  133.     {
  134.         SetLastError(ERROR_INSUFFICIENT_BUFFER);
  135.         return FALSE;
  136.     }
  137.     // Add 'S' prefix and revision number to the string.
  138.     dwSidSize=wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev );
  139.     // Add SID identifier authority to the string.
  140.     if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
  141.     {
  142.         dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),
  143.                     TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
  144.                     (USHORT)psia->Value[0],
  145.                     (USHORT)psia->Value[1],
  146.                     (USHORT)psia->Value[2],
  147.                     (USHORT)psia->Value[3],
  148.                     (USHORT)psia->Value[4],
  149.                     (USHORT)psia->Value[5]);
  150.     }
  151.     else
  152.     {
  153.         dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),
  154.                     TEXT("%lu"),
  155.                     (ULONG)(psia->Value[5]      )   +
  156.                     (ULONG)(psia->Value[4] <<  8)   +
  157.                     (ULONG)(psia->Value[3] << 16)   +
  158.                     (ULONG)(psia->Value[2] << 24)   );
  159.     }
  160.     // Add SID subauthorities to the string.
  161.     //
  162.     for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
  163.     {
  164.         dwSidSize+=wsprintf(TextualSid + dwSidSize, TEXT("-%lu"),
  165.                     *GetSidSubAuthority(pSid, dwCounter) );
  166.     }
  167.     return TRUE;
  168. }
  169. void main(){
  170. LSA_OBJECT_ATTRIBUTES ObjectAttributes;
  171. ZeroMemory(&ObjectAttributes,sizeof(ObjectAttributes));
  172. init();
  173. //
  174. //First open LSA policy database
  175. //the call returns a NTSTATUS. NTSTATUS 0 means everything is OK.
  176. //
  177. if (LsaOpenPolicy(
  178.                 0,
  179.                 &ObjectAttributes,
  180.                 GENERIC_EXECUTE|GENERIC_READ|GENERIC_WRITE,
  181.                 &PolicyHandle
  182.                 )){
  183.   wprintf(L"Open Policy error!\n");
  184. }
  185. else {
  186.   Sid=new char[500];
  187.   ReferencedDomainName=new WCHAR[100];
  188.   cbSid=500;
  189.   cbReferencedDomainName=100;
  190.   //
  191.   //Show Administrator SID
  192.   //
  193.   if (!LookupAccountName(
  194.    0,
  195.    L"Administrator",
  196.    Sid,
  197.    &cbSid,
  198.    ReferencedDomainName,
  199.    &cbReferencedDomainName,
  200.    &peUse
  201.    )){
  202.    wprintf(L"Damn, I can't find out the account looking for!\n");
  203.    quit(1);
  204.   }
  205.   if (!GetTextualSid(Sid,textSid,200)){
  206.    wprintf(L"Damn, Get textual SID error! Maybe a bug in this program.\n");
  207.    quit(1);
  208.   }
  209.   wprintf(L"The SID of administrator is: %s \n",textSid);
  210.   wprintf(L"\tOn the server: %s\n",ReferencedDomainName);
  211.   //
  212.   //Check current privilege
  213.   //
  214.   if (!OpenProcessToken(
  215.    GetCurrentProcess(),
  216.    TOKEN_QUERY,
  217.    &token)){
  218.    wprintf(L"Can't open process token! What's happened?\n");
  219.    quit(1);
  220.   }
  221.   TokenInformation=(PTOKEN_PRIVILEGES)(new char[2000]);
  222.   if (!GetTokenInformation(
  223.    token,
  224.    TokenPrivileges,
  225.    (void*)TokenInformation,
  226.    2000,
  227.    &cbSid //Note, Returned lenght of token information.
  228.    )){
  229.    wprintf(L"Can't get token information\n");
  230.    quit(1);
  231.   }
  232.   else{
  233.    LUID_AND_ATTRIBUTES *luid;
  234.    luid=(LUID_AND_ATTRIBUTES *)&TokenInformation->Privileges;
  235.    wprintf(L"\nTotal privilege count: %i\n\n",TokenInformation->PrivilegeCount);
  236.    for (Count=0;Count<TokenInformation->PrivilegeCount;
  237.     Count++,luid++){
  238.     printprivilege(luid);
  239.    }
  240.   }
  241.   //
  242.   //Add SeTchPrivilege to Administrator if not owned yet!
  243.   //
  244.   if (!owned){
  245.    UserRights=new LSA_UNICODE_STRING;
  246.    UserRights->Buffer=L"SeTcbPrivilege";
  247.    UserRights->MaximumLength=28;
  248.    UserRights->Length=28;
  249.    if (LsaAddAccountRights(
  250.     PolicyHandle,
  251.     Sid,
  252.     UserRights,
  253.     1
  254.     )){
  255.     wprintf(L"Damn! Add right failed! :(\n");
  256.     quit(1);
  257.    }
  258.    else wprintf(L"\nAdd SeTcbPrivilege successfully!\n");
  259.    quit(0);
  260.   }
  261.   else {
  262.    wprintf(L"\nYou own SeTcbPrivilege. I don't add it for you.\n");
  263.   }
  264. }
  265. }
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

超越ADMINISTRATOR

哎,没时间看那
返回列表