在W2K中提升权限的几个攻击实例之成败心得

作者:莫大

 1<master_moda@yahoo.com>   
 2日期:2002-12-02 
 3
 4引子: 
 5
 6  
 7讲到Exploit都会涉及到提升权限的问题,所谓提升权限就是利用系统的漏洞来获得更高的Privilege。比如说,你用一般用户的账号登录Windows NT/Windows 2000后,你就只能作有限的操作,却不能加减用户,不能往系统目录中存写文件等等;但等到你通过系统的漏洞获得了Administrator或者Local System的权限以后,你也就可以作这些事了。 
 8
 9我研究Exploit的时间并不是很长,但看到有关在Windows操作系统中提升权限的方法与实例还真不少。刚才到Google上用关键词“microsoft”、“Windows”、“privilege”、“elevation”去搜索一下,居然返回3000多个结果。要知道,这还只是公布出来的部分,江湖中还有很多必杀绝技是不轻易示人的。 
10
11要想在这里详细地介绍所有Windows中提升权限的方法,我的功力是远远不够的----估计相当于丐帮一袋弟子的水平而已。所以呢,这一章所针对的读者应该是丐帮的入门弟子,如果你们哪位功力要用两个以上的麻袋来装的话,请尽管跳过这一章。 
12
13我在选择这一章的Exploit例子时,有意选择针对W2K操作系统、附带有源程序的例子,这样方便大家在自己的机器上试验。这些Exploit并不是每个都成功,但是我感觉它们有不少可借鉴之处,可以通过学习它们来了解黑客的思路,从而提高自己的反入侵能力。 
14
15记住我的机器dallasW2K Service Pack 1,如果你们的计算机运行不同版本的W2K Service Pack,这些Exploit可能需要改动。 
16
17顺便说一句,实际上在第一章里面我们已经提到一种在Unix或者Linux中提升权限的方法,就是去Exploit超级用户Root所有的、具有SUID位的执行程序。在Windows操作系统中,没有SUID这种说法,但是有一种RunAs服务(Service)进程可以提供类似于SUID的功能,而且是有可能被Exploit的。 
18
19  
20利用Windows 2000中的Named Pipe来提升权限 
21
22  
23Windows 2000中的RunAs服务进程可以让用户甲以用户乙的权限运行程序,这类似于UnixLinux系统中SUID位功能。W2K中的一个APICreateProcessWithLogonW就利用了RunAs服务进程,用户甲调用这个CreateProcessWithLogonW时把用户乙的账号(Account)、域(Domain)、密码(Password)提交给Windows操作系统作Authentication,如果Authentication成功,那么就接着运行指定的程序,而且这个程序运行时具有用户乙的权限。 
24
25CreateProcessWithLogonW API的定义如下:   
26BOOL CreateProcessWithLogonW(   
27LPCWSTR , // 用户乙的账号(Account)   
28LPCWSTR , //用户乙的域(Domain)   
29LPCWSTR , // 用户乙的密码(Password)   
30DWORD , // logon option   
31LPCWSTR , // executable module name   
32LPWSTR , // command-line string   
33DWORD , // creation flags   
34LPVOID , // new environment block   
35LPCWSTR , // current directory name   
36LPSTARTUPINFOW , // startup information   
37LPPROCESS_INFORMATION // process information   
38); 
39
40那么CreateProcessWithLogonW是如何把用户乙的账号信息传给RunAs服务进程的呢?在Windows操作系统中有很多Interprocess Communication的方法,大概最常见的就是 Pipe了。我们在上一章对IISExploit中也用到了Pipe,不过那是没有名字的pipe (Anonymous Pipe);在这里CreateProcessWithLogonW是用有名字的Pipe(named Pipe)RunAs联络的,这个named Pipe就是“\\\\.\pipe\secondarylogon”。 
41
42到目前为止,一切都正常。大家要问:RunAs的漏洞在哪里呢?它的漏洞是如何被Exploit的呢?根据RADIX Team的解释:当用户甲用CreateProcessWithLogonW创建具有用户乙权限的进程时,它是不会核实“\\\\.\pipe\secondarylogon”的Server端究竟是连通到RunAs进程还是连通到其它的进程。如果RunAs服务进程在某一时刻停止运行的话,黑客进程可以趁机创建一个也叫“\\\\.\pipe\secondarylogon”的named Pipe,然后黑客进程就假装成RunAs服务进程在PipeServer端等着接受信息。接着我们无辜而无知的用户甲调用CreateProcessWithLogonW了,它也不先调查一下Named Pipe另一端的进程身份,就把用户乙的账号信息由伪造的named Pipe传了过去,传呀传,传呀传,一直传到黑客程序的耳朵里。 
43
44RADIX Team还编写了一个Exploit程序radix1112200101,这个程序把通过Named Pipe “\\\\.\pipe\secondarylogon”传来的用户乙账号信息(包括用户名、域名、密码)统统显示出来。限于篇幅,我就不转载这个程序了,大家可以到他们的网站去看。不过这里我准备演示一下在dallas上如何使用radix1112200101来获得dallas本地域(Local Domain)的超级用户Administrstor的密码。被Exploit的程序(就是因为使用CreateProcessWithLogonW而泄密的家伙)radixvictim.cpp,它以超级用户Administrator的权限启动一个NotePad程序。 
45
46  
47&lt;==========================radixvictim.cpp===============================&gt;
48
49// radixvictim.cpp : Defines the entry point for the application.   
50// 
51
52#define _WIN32_WINNT 0x0500   
53#define UNICODE 
54
55#include <windows.h>   
56#include <winbase.h>   
57#include <stdio.h>   
58#include <winuser.h>
59
60int APIENTRY WinMain(HINSTANCE hInstance,   
61HINSTANCE hPrevInstance,   
62LPSTR lpCmdLine,   
63int nCmdShow = SW_SHOW)   
64{   
65// TODO: Place code here. 
66
67LPCWSTR lpUsername = L"Administrator"; // user's name   
68LPCWSTR lpDomain = L"dallas"; // user's domain   
69LPCWSTR lpPassword = L"moda"; // user's password   
70DWORD dwLogonFlags = LOGON_NETCREDENTIALS_ONLY; // logon option   
71LPCWSTR lpApplicationName = L"D:\\\Winnt\\\NotePad.exe";   
72LPWSTR lpCommandLine = L"NotePad.exe"; // command-line string   
73DWORD dwCreationFlags = CREATE_NEW_CONSOLE; // creation flags   
74LPVOID lpEnvironment = NULL; // new environment block   
75LPCWSTR lpCurrentDirectory = NULL; // current directory name   
76STARTUPINFO StartupInfo; // startup information   
77PROCESS_INFORMATION ProcessInfo; // process information 
78
79BOOL ret; 
80
81ZeroMemory(&amp;StartupInfo, sizeof(Sta</winuser.h></stdio.h></winbase.h></windows.h></master_moda@yahoo.com>
Published At
Categories with 网络技术
comments powered by Disqus