GRAY HAT PYTHON をmacでも 今回は windows2010/07/11 09:38

GRAY HAT PYTHON をMACで行うつもりだったが Debuggerの使い方で
Windowsなので

でもまだ 性格に動いていない?打ち込みミスったかな

$python my_test.pyで

[*] Error: 0x00000002.

が出力

# --- my_debugger_defines.py start ----
from ctypes import *
WORD = c_ushort
DWORD = c_ulong
LPBYTE = POINTER(c_ubyte)
LPTSTR = POINTER(c_char)
HANDLE = c_void_p

DEBUG_PROCESS = 0x00000001
CREATE_NEW_CONSOLE = 0x00000010

class STARTUPINFO(Structure):
_fields_ = [
("cb", DWORD),
("lpReserved", LPTSTR),
("LPDesktop", LPTSTR),
("lpTitle", LPTSTR),
("dwX", DWORD),
("dwY", DWORD),
("dwXSize", DWORD),
("dwYSize", DWORD),
("dwXCountChars", DWORD),
("dwYCountChars", DWORD),
("dwFillAttribute", DWORD),
("dwFlags", DWORD),
("wShowWindow", WORD),
("cbReserved2", WORD),
("lpReserved2", LPBYTE),
("hStdInput", HANDLE),
("hStdOutput", HANDLE),
("hStdError", HANDLE),
]
class PROCESS_INFORMATION(Structure):
_fields_ = [
("hProcess", HANDLE),
("hTread", HANDLE),
("dwProcessId", DWORD),
("dwTreadId", DWORD),
]
# --- my_debugger_defines.py end----

# --- my_debugger.py start ---
from ctypes import *
from my_debugger_defines import *

kernel32 = windll.kernel32

class debugger():
def __int__(self):
pass

def load(self,path_to_exec):

creation_flags = DEBUG_PROCESS

startupinfo = STARTUPINFO()
process_information = PROCESS_INFORMATION()

startupinfo.dwFlags = 0x1
startupinfo.wShowWindow = 0x0

startupinfo.cb = sizeof(startupinfo)

if kernel32.CreateProcessA(path_to_exec,
None,
None,
None,
None,
creation_flags,
None,
None,
byref(startupinfo),
byref(process_information)):
print('[*] We have successfully launched the process!')
print('[*] PID %d' % process_information.dwProcessId)

else:
print("[*] Error: 0x%08x." % kernel32.GetLastError())
# --- my_debugger.py end ---

# --- my_test.py start ---
import my_debugger

debugger = my_debugger.debugger()

#debugger.load("C:\\WINDOWS\\system32\\calc.exe")
# --- my_test.py end ---