第二阶段第二题代码(比较弱)(看雪金山2007逆向分析挑战赛)
by aker
说老实话,第二题要想做的话,是个费时间的题目,不想动手去做很多,都是拷贝的代码,大家
随便看看吧.
使用IDA载入那个sys,发现没有做什么其他的,就是常规的工作,然后hook了NtOpenProcess
,这样你OpenProcess的时候,他判断是不是打开的自己,如果是就返回Deny。也就是说,只
是限制了你不能打开进程,获取句柄。原理这个帖子里面有,大家可以先看看那个;)
http://bbs.pediy.com/showthread.php?t=40832
既然只是HOOK了,那么发送WM_CLOSE等可以关闭,修复ssdt也可以关闭
下面是我的一些代码。
来个最简单的吧
#include <windows.h>
int main(int argc, char *argv[])
{
HWND hwin = FindWindow(NULL,"crackmeapp");
SendMessage(hwin,WM_CLOSE,0,0);
return 0;
}
// 窗口置前,发送alt f4
#include <windows.h>
#pragma comment(lib,"user32")
int main(int argc, char *argv[])
{
HWND hwin = FindWindow(NULL,"crackmeapp");
SetForegroundWindow(hwin);
Sleep(20);
keybd_event(18,MapVirtualKey(18,0),0,0);
keybd_event(115,MapVirtualKey(115,0),0,0);
keybd_event(115,MapVirtualKey(115,0),KEYEVENTF_KEYUP,0);
keybd_event(115,MapVirtualKey(115,0),0,0);
keybd_event(115,MapVirtualKey(115,0),KEYEVENTF_KEYUP,0);
keybd_event(18,MapVirtualKey(18,0),KEYEVENTF_KEYUP,0);
return 0;
}
////////////头文件////////////////////////////////////////////////////////////
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
////////////宏定义////////////////////////////////////////////////////////////
////////////全局变量//////////////////////////////////////////////////////////
////////////函数定义//////////////////////////////////////////////////////////
DWORD WINAPI GetPIDbyName(LPTSTR lpName)
{
HANDLE m_Snap = INVALID_HANDLE_VALUE;
PROCESSENTRY32 pe = {sizeof(pe)};
DWORD ret = NULL;
{
m_Snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
if (m_Snap == INVALID_HANDLE_VALUE) goto finally;
if (!Process32First(m_Snap, &pe)) goto finally;
do if(!lstrcmpi(pe.szExeFile,lpName))
{
ret = pe.th32ProcessID;
goto finally;
}
while (Process32Next(m_Snap, &pe));
}
finally: {
if (m_Snap != INVALID_HANDLE_VALUE)
CloseHandle(m_Snap);
}
return ret;
}
bool TerminateAProcess(DWORD dwPid)
{
HANDLE hThreadSnap = NULL;
THREADENTRY32 te32;
BOOL bThreadFind = FALSE;
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,NULL);
if(hThreadSnap)
{
te32.dwSize = sizeof(THREADENTRY32);
bThreadFind = Thread32First(hThreadSnap,&te32);
while(bThreadFind)
{
if(te32.th32OwnerProcessID == dwPid)
{
HANDLE hThread = NULL;
hThread = OpenThread(THREAD_ALL_ACCESS,FALSE,te32.th32ThreadID);
if(hThread)
{
TerminateThread(hThread,0);
CloseHandle(hThread);
}
}
te32.dwSize = sizeof(THREADENTRY32);
bThreadFind = Thread32Next(hThreadSnap,&te32);
}
CloseHandle(hThreadSnap);
}
return TRUE;
}
int main(int argc, char *argv[])
{
TerminateAProcess(GetPIDbyName("crackmeapp.exe"));
return 0;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)