📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Debuggers  >>  PyDbg Memory Breakpoint on Stack

Topic created on: September 6, 2006 03:15 CDT by xz .

Hi,

When I try to put a breakpoint on stack memory, it doesn't get hit, could somebody explain me why that is?
example code:


$ cat stackm.c
int main(){

        int i=5;
        while (i--)
                printf("%i\n");
}

$cl stackm.c

$ cat stackbp.py
from pydbg.defines import *
from pydbg import *
dbg=pydbg()
dbg.load('stackm.exe')
def bp_h(dbg):
    print 'breakpoint hit'

for i in dbg.disasm_around(0x40101B):
    print "0x%08x  %s" % i


dbg.bp_set_mem(0x12FF64,40,"memb",bp_h)
def bp_h2(dbg):
    esp=dbg.context.Esp
    eip=dbg.context.Eip
    print "esp: 0x%08x" % dbg.context.Esp
    print "eip: 0x%08x >> %s" % (eip , dbg.disasm(eip ))
    return DBG_CONTINUE

dbg.bp_set(0x401020,"codebp",True,bp_h2)
print "bp is ours mem @ 0x%08x" % dbg.bp_is_ours_mem(0x0012ff68)
dbg.run()

$ python stackbp.py
0x0040100e  mov ecx,[ebp-0x4]
0x00401011  sub ecx,0x1
0x00401014  mov [ebp-0x4],ecx
0x00401017  test eax,eax
0x00401019  jz 0x40102a
0x0040101b  push 0x40c000
0x00401020  call 0x401030
0x00401025  add esp,0x4
0x00401028  jmp 0x40100b
0x0040102a  xor eax,eax
0x0040102c  mov esp,ebp
bp is ours mem @ 0x0012ff64
esp: 0x0012ff68
eip: 0x00401020 >> call 0x401030
4
esp: 0x0012ff68
eip: 0x00401020 >> call 0x401030
3
esp: 0x0012ff68
eip: 0x00401020 >> call 0x401030
2
esp: 0x0012ff68
eip: 0x00401020 >> call 0x401030
1
esp: 0x0012ff68
eip: 0x00401020 >> call 0x401030
0

  pedram     September 7, 2006 15:57.09 CDT
I should (and will) add this to the bp_set() documentation, but you shouldn't set memory breakpoints on the stack. The page-size granularity causes a huge number of false positives, bringing the debuggee to a crawl.

I've made some changes to the various internal exception handlers, so it doesn't make any sense for me to debug the current version. I am in the midst of debugging memory breakpoints some more and will be delaying the next PyDbg update until that happens. On that note, if there are any bugs, feature requests and ideally patches, please submit them to me now and it might make it in.

  assert0   November 6, 2006 15:29.56 CST
Moreover, guard pages are used by the system to detect stack overflow and enlarge it so using them as memory breakpoints on the stack is pretty impossible.

Anyway, you can use PAGE_NOACCESS instead. It requires little modification, you just have to use the access violation handler, store the original protections bits of the pages you trace and remember that PAGE_NOACCESS flags are not reset when hit.

  pedram     November 6, 2006 20:08.16 CST
> Anyway, you can use PAGE_NOACCESS instead. It requires little modification, you just have to use the access violation handler, store the original protections bits of the pages you trace and remember that PAGE_NOACCESS flags are not reset when hit.

I originally implemented both methods and found the PAGE_GUARD technique to work better. One obvious reason is that by using a guard page you save one step of having to restore memory permissions. There were some other reasons that I should have probably better noted. Perhaps it's time to revisit the technique.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit