- Grep Like Feature
- ASCII to DWORDS
- Levels not Implemented for This Platform
- SMAP During Debugging
- Mona in WinDbg
- Conditional Breakpoints
- Finding the Pool
- Enable Debug Print
- Misc Commands
- Grep like feature by using
.shellcommand
.shell -ci "lm" findstr /i kern - Create DWORDS from an ASCII string, useful for in terms of, e.g. shellcoding
- Same works for
unicodewitheu - Be aware it might be more reasonbale to use
.dvallocto allocate some space and use this, instead of messing around withrsp
ea rsp+8 "\\\\192.168.73.128\\pwn\\met.dll"
da rsp+8
00000044`cf0ffef0 "\\192.168.73.128\pwn\met.dll"
dd rsp+8 L8
00000044`cf0ffef0 39315c5c 36312e32 33372e38 3832312e
00000044`cf0fff00 6e77705c 74656d5c 6c6c642e 00000000- If
ptecommand, e.g!pte 0x0reportsLevels not implemented for this platform, a reboot of the system might help - If this happens during kernel debugging, it might help to reboot both, debugger and debuggee
!pte 0x0
Levels not implemented for this platform
# reboot
!pte 0x0
VA 0000000000000000
PXE at FFFFADD6EB75B000 PPE at FFFFADD6EB600000 PDE at FFFFADD6C0000000 PTE at FFFFAD8000000000
contains 8A00000082A29867 contains 0000000000000000
pfn 82a29 ---DA--UW-V contains 0000000000000000
not valid- If Supervisor Mode Access Prevention (SMAP, bit 21) comes in your way during debugging, this might be useful
- For Supervisor Mode Execution Prevention (SMEP, bit 20) needs to be zeroed out
r cr4
cr4=0000000000370678
# switch 3 to 1, zero'ing out bit 21
r cr4=0000000000170678
r cr4
cr4=0000000000170678-
If you want ot use
monainWinDbg... writeup provided by @yurgiur -
Installation:
Monaneeds python2 -> Path to python2 should be in PATH variable- Be sure that
Windows Modules InstallerService is running - Install python2 and add it to PATH variable
- Download pykd.zip and save it to a temporary location on your computer
- Check the properties of the file and "Unblock" the file if necessary
- Extract the archive, you should get two files:
pykd.pydandvcredist_x86.exe - Run
vcredist_x86.exewith administrator privileges and accept the default values - Copy
pykd.pydtoC:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\winextorC:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext - Open a command prompt with administrator privileges and run the following commands:
c: cd "C:\Program Files (x86)\Common Files\Microsoft Shared\VC" regsvr32 msdia90.dll (You should get a messagebox indicating that the dll was registered successfully)- Download windbglib.py
- Save the file under
C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86orC:\Program Files (x86)\Windows Kits\10\Debuggers\x86("Unblock" the file if necessary) - Download mona.py
- Save
mona.pyunderC:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86orC:\Program Files (x86)\Windows Kits\10\Debuggers\x86("Unblock" the file if necessary)
-
Basic options:
- Set workdir:
!py mona config -set workingfolder c:\logs\%p -o: Ignore OS modules-m: Specify module names to search in, e.g.-m "gtk*,*win*,shell32.dll"-cm: Set criteria a module should comply with, e.g.-cm aslr=false,safeseh=false,rebase=false-cp: Set criteria a pointer should match, e.g.-cp asciipint-> only show pointers with pritable bytes-cpb: Specify bad chars, e.g.-cpb '\x00\x0a\x0d'
- Set workdir:
-
Locate EIP:
- Pattern create:
!py mona pattern_create 5000(pattern is generated in text file in workdir) - Pattern offset:
!py mona pattern_offset [EIP_VALUE]
- Pattern create:
-
Generate rop chain without bad chars
!py mona rop -m "[Module names]" -cpb '[Bad chars]'!py mona rop -m "libeay32IBM019" -cpb '\x00\x09\x0a\x0b\x0c\x0d\x20'- Files:
rop.txt: All gadgets, interessting and otherrop_suggestions.txt: Suggested gadgets grouped by meaningrop_chains.txt: ROP chains for VirtualAlloc and VirtualProtect in ruby, python, javascript and Cstackpivot.txt: Instructions that add a value to ESP; organized in two sections: Non-Safeseh protected, Safeseh protected
-
Find references to a module name with filter
- Find all references to a module name in all non-ASLR/non-rebase modules
!py mona getiat -cm aslr=false,rebase=false -s [MODULE NAME]
- Simple software breakpoint to print some values (no conditional breakpoint)
bp ntdll+31337 ".printf \"alloc(0x%x) = 0x%p from 0x%p \\n\", poi(rsp+50), rax, poi(rsp); g"- Compare
QWORDin registerrcxat offset0x18with value0x300(processor breakpoint)
ba e1 /p <process> example+1337 ".if ( qwo(@rcx+0x18) != 0x300 ) { dqs @rcx+0x18 L1; } .else { gc; }"- To find the
poolfor a certain address, object etc. some can use the!poolfindcommand with a giventag - Since the command might be slow as hell, tuning the cache a bit might be useful
# Default 0x1000 KB
.cache 0x99999
!poolfind NpFs -nonpaged- Another option might be to use
PoolHitTag
ed nt!PoolHitTag 'NpFs'- Enabling
DbgPrintmonitoring can be done either byregistry keyor inWinDbg
# WinDbg
ed kd_default_mask 0xf
# Registry
- Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter
- Add DWORD
- Value name: Default
- Value data: 0xf- Just some commands
# Help
.hh <command>
.hh !<command>
# Infos on structs
dt <module>!<struct>
dt <module>!<struct> <address>
dt <module>!<struct> <address> -y <keyword/attribute>
dt nt!_EPROCESS
dt nt!_EPROCESS <address by e.g. !process command> -y Unique
dt nt!_EPROCESS <address by e.g. !process command> -y Unique -y Header
# dq vs !dq --> virt vs phy addr
dq <address>
!dq <address>
# Convert virt to phy
!vtop <dirbase> <virtualaddr>
# Module Infos
lm
lm m <keyword/modulename>
lm a <address to check if belongs to a module>
# Process (at the time of writing: 0x4 is system)
!process <processid> <details>
!process <processid> <details> <image>
!process 4 0
!process 0 0 <application.exe>
# Stepping
## Single step "over"
p
## Single step "into"
t
## Til next branching instr
ph
## Til return instr
pt
# Examine symbols
x <module>
x <module>!<function>
# Search
s <type> <from> <to> <what>
s -a 0 L?80000000 w00tw00t
s -d 0 L?80000000 0x90909090
s -q 0 L?80000000 0x9090909090909090
# Formats (prefix: "0y" = binary, "0n" = dec , "default" = hex)
.formats <value>
.formats <value1> <operator> <value2>
.formats 41414141
.formats 41414141 >> 18
.formats 41414141 & 2
.formats 41414141 + 90909090
# pool
!pool <address>
!poolused <flags> <tag>
!poolfind <tag> -<pool>
!poolfind NpFs -nonpaged
!poolused 2 Np*
# Get last error
!gle