xct's notes
Search…
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 gt;<
  • 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

1
!py mona config -set workingfolder c:\users\xct\desktop\%p_%i
Copied!

Fix Symbols

1
.symfix+ c:\symbols
2
.reload /f
Copied!

List all running processes

1
!dml_proc
Copied!

Find string in memory

1
s -a 0 L?80000000 "w00t"
Copied!

Change value at address

1
eq addr value
Copied!

Address show as x

1
da // string
2
dq // qword
3
dd // word
Copied!

Reboot (useful in kernel debugging)

1
.reboot
Copied!

Setup Mona

1
PS C:\Program Files (x86)\Windows Kits\10\Debuggers\x86 > iwr https://raw.githubusercontent.com/corelan/windbglib/master/windbglib.py -OutFile windbglib.py
2
PS C:\Program Files (x86)\Windows Kits\10\Debuggers\x86 > iwr https://github.com/corelan/mona/raw/master/mona.py -OutFile mona.py
Copied!
1
https://github.com/corelan/windbglib/raw/master/pykd/pykd.zip |--pykd.pyd--> C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext
Copied!

Set Symbol Path

1
_NT_SYMBOL_PATH=srv*c:\symbols*http://msdl.microsoft.com/download/symbols
Copied!

Register DLL

1
cd "C:\Program Files (x86)\Common Files\Microsoft Shared\VC"
2
regsvr32 msdia90.dll
Copied!
1
0:004> .load pykd.pyd
2
0:004> !py mona
Copied!

Change Memory

Change string

1
eu 0x002e1952 "This has been changed, pretty cool"
Copied!

Exploitable

To install download the extension from https://archive.codeplex.com/?p=msecdbg and put into the windbg folder under "winext".
1
!load winext/msec.dll
2
!exploitable
Copied!

Mona Commands

1
.load pykd.pyd
2
!py mona pattern_create 2000
3
!py mona pattern_offset 37694136
Copied!

Find SEH Overwrite

1
!py mona findmsp
Copied!
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

1
!py mona seh -n
Copied!

Find Register Jump

1
!py mona jmp -r EAX
Copied!

Find jmp in specific module

1
!mona jmp -r esp -m MSRMfilter03.dll
Copied!

Generate Rop Chain

1
!py mona rop
Copied!

Generate Bad Byte Pattern

1
!mona bytearray
Copied!
1
buf := ""
2
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"
3
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"
4
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"
5
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"
6
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"
7
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"
8
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"
9
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"`
Copied!
Formatted with shorter lines:
1
buf = (
2
b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c"
3
b"\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
4
b"\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26"
5
b"\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33"
6
b"\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
7
b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d"
8
b"\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a"
9
b"\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67"
10
b"\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74"
11
b"\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81"
12
b"\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e"
13
b"\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b"
14
b"\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8"
15
b"\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5"
16
b"\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2"
17
b"\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
18
b"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc"
19
b"\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9"
20
b"\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6"
21
b"\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")
Copied!

Compare bad bytes automatically

1
!py mona ba -cpb '\x00'
Copied!

Show Heap:

1
!heap -s
Copied!

Don't break on every exception

e.g. for access violation:
1
sxi av
Copied!

Narly

1
.load narly
2
.nmod # show loaded modules and their protections
Copied!
Last modified 9mo ago