挥刀自宫术
本文来自:http://hi.baidu.com/zxhouse
一段自删除代码,写的很牛。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <windows.h> BOOL DeleteMyself(WCHAR *pHelper) { int ret; WCHAR helper[MAX_PATH]; ZeroMemory(helper, sizeof(helper)); if (pHelper) wcsncpy(helper, pHelper, MAX_PATH-2); else wcscpy(helper, L"calc.exe"); STARTUPINFOW si = {sizeof(STARTUPINFOW),0}; PROCESS_INFORMATION pi; HANDLE hSYNC = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId()); if (CreateProcessW(NULL, helper, 0, 0, TRUE, CREATE_SUSPENDED, 0, 0, &si, &pi)) { CONTEXT ctx = {CONTEXT_FULL,0}; ret = GetThreadContext(pi.hThread, &ctx); WCHAR MyselfPath[MAX_PATH]; int nPathLen = GetModuleFileNameW(NULL, MyselfPath, MAX_PATH); struct StackContext { DWORD_PTR DeleteFileW; DWORD_PTR WaitForSingleObject_argv1; DWORD_PTR WaitForSingleObject_argv2; DWORD_PTR ExitProcess; DWORD_PTR DeleteFileW_argv1; DWORD_PTR shit; DWORD_PTR ExitProcess_argv1; }stackctx; HMODULE hKernel32 = GetModuleHandleW(L"Kernel32.dll"); ctx.Eip = (DWORD_PTR)GetProcAddress(hKernel32, "WaitForSingleObject"); ctx.Esp = (DWORD_PTR)VirtualAllocEx(pi.hProcess, 0, 512*1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE); ctx.Esp += 256*1024; stackctx.DeleteFileW = (DWORD_PTR)GetProcAddress(hKernel32, "DeleteFileW"); stackctx.WaitForSingleObject_argv1 = (DWORD_PTR)hSYNC; stackctx.WaitForSingleObject_argv2 = (DWORD_PTR)-1; stackctx.ExitProcess = (DWORD_PTR)GetProcAddress(hKernel32, "ExitProcess"); stackctx.DeleteFileW_argv1 = (DWORD_PTR)VirtualAllocEx(pi.hProcess, 0, (nPathLen+1)*sizeof(WCHAR), MEM_COMMIT, PAGE_EXECUTE_READWRITE); ret = WriteProcessMemory(pi.hProcess, (LPVOID)stackctx.DeleteFileW_argv1, MyselfPath, (nPathLen+1)*sizeof(WCHAR), NULL); if (!ret) return FALSE; stackctx.shit = 0; stackctx.ExitProcess_argv1 = 0; ret = WriteProcessMemory(pi.hProcess, (LPVOID)(ctx.Esp), &stackctx, sizeof(stackctx), NULL); if (!ret) return FALSE; ret = SetThreadContext(pi.hThread, &ctx); if (!ret) return FALSE; ResumeThread(pi.hThread); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); return TRUE; }else { return FALSE; } } int main() { DeleteMyself(0); return 0; } //2000/xp/2003/vista 上已经测试通过 |
3 条评论
标题确实很邪恶。。。
To :Koma
兄弟,的回复比代码邪恶多了。:)
有点像“标题党”,以还为某些同志被嫂子“河蟹”了一顿……
代码貌似十分邪恶!