Windbg
Commands
General
set breakpoint bp <addr>
on resolved function, bu <addr>
for unresolved (set when module is loaded)
set hardware breakpoint: ba <e,r,w> <size> <addr>
enable/disable breakpoint be/ba
clear breakpoint bc
list breakpoints: bl
exception info: !analyze
memory mapping: !address
heap info: !heap
dereference pointer poi(<addr>)
dump call stack: k
continue: g
step over: p
step into: t
finish function: pt
continue until next branch: ph
search memory s -a 0 L?80000000 "<string>"
searches the entire 32-bit user address space for the ascii string (a
) , use -u
for unicode
show specific module: lm m <modulename>
, show all: lm
Show current exception handler: !exchain
Load WinDBG Script $><
Convert number to different formats .formats <number>
Show memory protections !vprot
Displaying Data
disassemble: u <addr>
,uf <addr>
disassemble at symbol: u kernel32!GetCurrentThread
dump memory: dq <addr>
, dd <addr>
, dw <addr>
, db addr
dump memory, show ascii: dc <addr>
, dW <addr>
(add e.g. L2 at the end to limit the amount displayed)
dereference pointer poi(<addr>)
dump structures: dt <addr>
(display type), e.g. dt ntdll!_TEB
, to display nested structures use dt -r <symbol> @$teb
(teb is a pseudo register)
show size of struct: ?? sizeof(<symbol>)
dump registers: r
Editing Data
edit memory: ed rsp 42424242
, for asci: ea
, for unicode eu
set register value r eip=41414141
Automate Commands on Breakpoints
bp <addr> ".printf \"Hello World\";.echo;g"
, there are also .if
and .else
for more logic
Set Working Dir
!py mona config -set workingfolder c:\users\xct\desktop\%p_%i
Fix Symbols
.symfix+ c:\symbols
.reload /f
List all running processes
!dml_proc
Find string in memory
s -a 0 L?80000000 "w00t"
Change value at address
eq addr value
Address show as x
da // string
dq // qword
dd // word
Reboot (useful in kernel debugging)
.reboot
Setup Mona
https://github.com/corelan/windbglib/issues/23
PS C:\Program Files (x86)\Windows Kits\10\Debuggers\x86 > iwr https://raw.githubusercontent.com/corelan/windbglib/master/windbglib.py -OutFile windbglib.py
PS C:\Program Files (x86)\Windows Kits\10\Debuggers\x86 > iwr https://github.com/corelan/mona/raw/master/mona.py -OutFile mona.py
https://github.com/corelan/windbglib/raw/master/pykd/pykd.zip |--pykd.pyd--> C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext
Set Symbol Path
_NT_SYMBOL_PATH=srv*c:\symbols*http://msdl.microsoft.com/download/symbols
Register DLL
cd "C:\Program Files (x86)\Common Files\Microsoft Shared\VC"
regsvr32 msdia90.dll
0:004> .load pykd.pyd
0:004> !py mona
Change Memory
Change string
eu 0x002e1952 "This has been changed, pretty cool"
Exploitable
To install download the extension from https://archive.codeplex.com/?p=msecdbg and put into the windbg folder under âwinextâ.
!load winext/msec.dll
!exploitable
Mona Commands
.load pykd.pyd
!py mona pattern_create 2000
!py mona pattern_offset 37694136
Find SEH Overwrite
!py mona findmsp
E.g: SEH record (nseh field) at 0x0019fab4 overwritten with normal pattern : 0x31684630 (offset 4112), followed by 16 bytes of cyclic data after the handler
Find Pop Pop Ret Gadget
!py mona seh -n
Find Register Jump
!py mona jmp -r EAX
Find jmp in specific module
!mona jmp -r esp -m MSRMfilter03.dll
Generate Rop Chain
!py mona rop
Generate Bad Byte Pattern
!mona bytearray
buf := ""
buf += "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
buf += "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
buf += "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
buf += "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
buf += "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
buf += "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
buf += "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
buf += "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"`
Formatted with shorter lines:
buf = (
b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c"
b"\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
b"\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26"
b"\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33"
b"\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d"
b"\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a"
b"\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67"
b"\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74"
b"\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81"
b"\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e"
b"\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b"
b"\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8"
b"\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5"
b"\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2"
b"\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
b"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc"
b"\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9"
b"\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6"
b"\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")
Compare bad bytes automatically
!py mona ba -cpb '\x00'
Show Heap:
!heap -s
Donât break on every exception
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/controlling-exceptions-and-events?redirectedfrom=MSDN
e.g. for access violation:
sxi av
Narly
https://code.google.com/archive/p/narly/
.load narly
.nmod # show loaded modules and their protections
Links
https://alecmaly.com/blog/2021/10/22/Exploring-the-WinDbg-Preview-JavaScript-API.html#configuring-pykddll
Find Instructions & Gadgets
You can either use mona or windbg script (or ropper/ropgadget if you want to do it outside windbg). The following looks for pop pop ret gadgets for SEH overwrites:
.block
{
.for (r $t0 = 0x58; $t0 < 0x5F; r $t0 = $t0 + 0x01)
{
.for (r $t1 = 0x58; $t1 < 0x5F; r $t1 = $t1 + 0x01)
{
s-[1]b startAddr endAddr $t0 $t1 c3
}
}
}
Load via: `$><path`
Error Codes
0x000000fc (ATTEMPTED EXECUTE OF NOEXECUTE MEMORY)
Download Symbols
https://shakuganz.com/2019/10/18/symchk-usage-windows-os/
downloading a specific file symbol from Microsoft:
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64
.\symchk.exe C:\Windows\system32\drivers\WdFilter.sys /s SRV*"C:\symbols"*"https://msdl.microsoft.com/download/symbols"
SYMCHK: FAILED files = 0
SYMCHK: PASSED + IGNORED files = 1