2.1. Processes and Threads¶
2.1.1. CurrentProcess¶
Note
See sample windows.current_process
-
class
windows.winobject.process.CurrentProcess[source]¶ Bases:
windows.winobject.process.ProcessThe current process
-
allocated_memory(*args, **kwds)¶ ContextManager to allocate memory and free it
Type: int– the address of the allocated memory
-
create_thread(lpStartAddress, lpParameter, dwCreationFlags=0)[source]¶ Create a new thread
Return type: WinThreadorDeadThread
-
execute(code, parameter=0)[source]¶ Execute native code
codein the current thread.Return type: intthe return value of the native code
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
memory_state()¶ Yield the memory information for the whole address space of the process
Yield: MEMORY_BASIC_INFORMATION
-
query_memory(addr)¶ Query the memory informations about page at
addrReturn type: MEMORY_BASIC_INFORMATION
-
read_byte(addr)¶ Read a
CHARataddr
-
read_dword(addr)¶ Read a
DWORDataddr
-
read_ptr(addr)¶ Read a
PTRataddr
-
read_qword(addr)¶ Read a
ULONG64ataddr
-
read_short(addr)¶ Read a
SHORTataddr
-
read_string(addr)¶ Read an ascii string at
addr
-
read_wstring(addr)¶ Read a windows UTF16 string at
addr
-
time_info¶ The time information of the process (creation, kernel/user time, exit time)
Type: TimeInfo
-
virtual_alloc(size, prot=PAGE_EXECUTE_READWRITE(0x40L))[source]¶ Allocate memory in the process
Returns: The address of the allocated memory Return type: int
-
virtual_protect(addr, size, protect, old_protect)¶ Change the access right of one or more page of the process
-
virtual_protected(*args, **kwds)¶ A context manager for local virtual_protect (old Protection are restored at exit)
-
write_byte(addr, byte)¶ write a byte at
addr
-
write_dword(addr, dword)¶ write a dword at
addr
-
write_qword(addr, qword)¶ write a qword at
addr
-
write_short(addr, word)¶ write a word at
addr
-
2.1.2. CurrentThread¶
-
class
windows.winobject.process.CurrentThread[source]¶ Bases:
windows.winobject.process.AutoHandleThe current thread
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
owner¶ The current process
Type: CurrentProcess
-
2.1.3. WinProcess¶
Note
See sample Remote process : WinProcess
-
class
windows.winobject.process.WinProcess(pid=None, handle=None, name=None, ppid=None)[source]¶ Bases:
windows.winobject.process.ProcessA Process on the system
-
allocated_memory(*args, **kwds)¶ ContextManager to allocate memory and free it
Type: int– the address of the allocated memory
-
create_thread(addr, param)[source]¶ Create a remote thread
Return type: WinThreadorDeadThread
-
execute(code, parameter=0)¶ Execute some native code in the context of the process
Returns: The thread executing the code Return type: WinThreadorDeadThread
-
execute_python(pycode)[source]¶ Execute Python code into the remote process.
This function waits for the remote process to end and raises an exception if the remote thread raised one
-
execute_python_unsafe(pycode)[source]¶ Execute Python code into the remote process.
Return type: rtype: WinThreadorDeadThread: The thread executing the python code
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
memory_state()¶ Yield the memory information for the whole address space of the process
Yield: MEMORY_BASIC_INFORMATION
-
query_memory(addr)¶ Query the memory informations about page at
addrReturn type: MEMORY_BASIC_INFORMATION
-
read_byte(addr)¶ Read a
CHARataddr
-
read_dword(addr)¶ Read a
DWORDataddr
-
read_ptr(addr)¶ Read a
PTRataddr
-
read_qword(addr)¶ Read a
ULONG64ataddr
-
read_short(addr)¶ Read a
SHORTataddr
-
read_string(addr)¶ Read an ascii string at
addr
-
read_wstring(addr)¶ Read a windows UTF16 string at
addr
-
time_info¶ The time information of the process (creation, kernel/user time, exit time)
Type: TimeInfo
-
virtual_alloc(size, prot=PAGE_EXECUTE_READWRITE(0x40L))[source]¶ Allocate memory in the process
Returns: The address of the allocated memory Return type: int
-
virtual_protect(addr, size, protect, old_protect)¶ Change the access right of one or more page of the process
-
virtual_protected(*args, **kwds)¶ A context manager for local virtual_protect (old Protection are restored at exit)
-
wait(timeout=INFINITE(0xffffffffL))¶ Wait for the object
-
write_byte(addr, byte)¶ write a byte at
addr
-
write_dword(addr, dword)¶ write a dword at
addr
-
write_qword(addr, qword)¶ write a qword at
addr
-
write_short(addr, word)¶ write a word at
addr
-
2.1.4. WinThread¶
-
class
windows.winobject.process.WinThread(tid=None, handle=None, owner_pid=None, owner=None)[source]¶ Bases:
windows.winobject.process.AutoHandleRepresent a thread
-
context¶ The context of the thread, type depend of the target process.
Type: windows.exception.ECONTEXT32orwindows.exception.ECONTEXT64orwindows.exception.ECONTEXTWOW64
-
context_syswow¶ The 64 bits context of a syswow thread.
Type: windows.exception.ECONTEXT64
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
owner¶ The Process owning the thread
Type: WinProcess
-
wait(timeout=INFINITE(0xffffffffL))¶ Wait for the object
-
-
class
windows.winobject.process.DeadThread(handle, tid=None)[source]¶ Bases:
windows.winobject.process.AutoHandleAn already dead thread (returned only by API returning a new thread if thread die before being returned)
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
wait(timeout=INFINITE(0xffffffffL))¶ Wait for the object
-
2.1.5. Token¶
-
class
windows.winobject.process.Token(handle)[source]¶ The token of a process
-
computername¶ The computername of the token
-
handle¶ An handle on the object
Type: HANDLE
Note
The handle is automaticaly closed when the object is destroyed
-
is_elevated¶ Trueif process is Admin
-
username¶ The username of the token
-
wait(timeout=INFINITE(0xffffffffL))¶ Wait for the object
-
2.2. PEB Exploration¶
The windows module is able to parse the PEB of the current process or remote process.
The PEB is accessible via process.peb and is of type PEB.
Note
See sample PEB exploration
2.2.1. PEB¶
-
class
windows.winobject.process.PEB[source]¶ The PEB (Process Environment Block) of the current process
-
commandline¶ The CommandLine of the PEB
Type: WinUnicodeString
-
exe¶ The executable of the process, as pointed by PEB.ImageBaseAddress
Type: windows.pe_parse.PEFile
-
imagepath¶ The ImagePathName of the PEB
Type: WinUnicodeString
-
modules¶ The loaded modules present in the PEB
Type: [ LoadedModule] – List of loaded modules
-
2.3. PEFile - Parsing loaded PE¶
2.3.1. windows.pe_parse¶
-
windows.pe_parse.GetPEFile(baseaddr, target=None, force_bitness=None)[source]¶ Returns a
PEFileto explore a PE loaded at baseaddr in process target.Return type: PEFileNote
If target is
Noneit refers to the curent process
2.3.1.1. PEFile¶
-
class
windows.pe_parse.PEFile(target, baseaddr, targetedbitness, transformers)[source]¶ Represent a PE loaded in a process (current or remote)
-
export_name¶ The Name attribute of the
EXPORT_DIRECTORY
-
2.3.1.2. IATEntry¶
-
class
windows.pe_parse.IATEntry[source]¶ Represent an entry in the IAT of a module Can be used to get resolved value and setup hook
-
value¶ int: The content (destination) of the IAT entryWarning
value is a descriptor. Setting its value will actually CHANGE THE IAT ENTRY, resulting in a segfault if no VirtualProtect have been done.
Note
-
set_hook(callback, types=None)[source]¶ Setup a hook on the entry and return it. You MUST keep a reference to the hook while the hook is enabled.
Parameters: callback – the hook
Note
see Hook protocol
Return type: windows.hooks.IATHookWarning
This works only for PEFile with the current process as target.
-