Thanks, great articles! A small correction (or I looked wrong): Somewhere at a third, you write “Directly below 0×0012DA14, we see 7E41882A, which is the address of the default SE handler for the application. ” I think that should be “Directly above 0xFFFFFFFF, …”
Hi. The tutorial was really useful. Actually, I found a case in which the only pop pop ret addresses that I found are all starting with null bytes ( by ex. 0x00112233 )… in this case how can we do? I found an example of exploit against an old version of surgemail in which they were solving the problem overwriting partially the SEH… but I don’t understand the concept behind it. Is there some paper or link where they talk about it?
Hi, Can you create a forum topic about this ? (http://www.corelan.be:8800/index.php/forum/writing-exploits/) thanks
iam a newbie in exploit writing… this tutorial helped me a lot, in understanding the SEH based Exploits..,
What programming language is the source code written in (top of the tutorial)? It looks kinda like Java but I don’t get it to compile.
it’s pseudo code 🙂 each language (except for C I believe) has their own syntax to build an exception handler are you looking at any language in particular ?
Nope. I’m just puzzled what I should do with the code supplied. I know some python. Basically, you want us to translate that psuedo code to any language we know that uses an exception handler? I know Python does, so I guess I could try port the code.
great tutorial. i replicated it using XP SP3 – virtual box. offset is the same. all addresses are the same as in this example, and exploit worked on a restart. correct me if i am wrong, windows xp sp3 does not use ASLR.
i dont understand why you calling jump to nextseh – “fake exception”. exception handler prototype is handler(EXCEPTION_RECORD *, EXCEPTION_REGISTRATION *, … ) and stack into handler function is esp+0 ret to ntdll esp+4 EXCEPTION_RECORD * <- info about exception, code, etc esp+8 EXCEPTION_REGISTRATION * by pop reg/pop reg/ret we can jmp to memory of EXCEPTION_REGISTRATION struct, and if we put some code (e.g. jmp) into EXCEPTION_REGISTRATION.next_seh, he executed. PS sorry for my very bad english =\ PPSS i am very confused by "fake exception" ^_____^ PPPSSS Thanks for article =))
Hey, It’s just a matter of wording. But I agree – it may be somewhat misplaced. It’s not really a fake exception. You need a real exception (typically an access violation) to trigger the seh handler, and you can take advantage of the fact that you control the pointer (SEH) and you can make it jump back to a controlled area (easiest way is going back to esp+8, but it does not have to be this location really. If you can jump to an area that is under your control, then it will work just fine.
hi great tutorial!!! anyway i was wondering is it possible to place the shellcode directly at the SEH pointer instead of pop, pop, ret?
it’s not – you can only put a pointer at seh (and use the 4 bytes at nseh as code to jump to your shellcode)
Hello Peter, great tutorial. I Have a question: How I can compile the code in the first example with DevC++ ? Thanks. Sorry for my bad inglish.
Hello Peter, I think Nahucito may have been referring to the example with __try and __except, not the try/catch pseudo-code. The example can be compiled using Visual C++ but not Dev-C++. Reason is __try/__except is a Microsoft extension to C, but Dev-C++ uses gnu compilers. Just thought to mention this in case others would like to try out the code. Btw, thanks for the great write-ups.
Hi! I can`t run a program into Immunity. I was disassembling a code, and found, that all registers is XOR… What can I fix it???
Can you please create a forum post about this ? I will need a lot more info in order to figure out what is wrong
Hello corelan Team, As shown in the first figure, it is obvious that the address of the seh handler is put insided the stack frame of a function. However, later you mention that “They form a linked list chain on the stack, and sit relatively close to the bottom of the stack. (SEH chain)” Thus, which is correct? How can the SEH chain located at the bottom of the stack but also each record put inside a stack frame? One more thing is that I really cannot understand, how are we able to overflow the seh handler ? If the first figure is the correct one, then i guess the local variables of the function overflow all the stack frame and eventually the seh handler? Is my thought correct? But if the second sentence is correct (i.e., the seh chain located at the bottom of the stack), then how we are able to reach there? do we overflow the entire stack? Thank you for your time, I am really being confused with the SEH exploitation techniques, because i feel that there are very few articles clarifying issues regarding the SEH chain.
hi, would you mind posting your questions in our forums ? alternatively you can hang out on IRC (freenode, channel #corelan) and we can talk about this in detail online cheers Peter
I was able to get this to work on Win7 with some dlls from dll-files.com. The addresses were the same and I used Immunity through the entire process. Great work on mona by the way… !mona seh -n -o is making me extra lazy, but I really need to go learn to do that work manually. I used a much shorter shellcode for calc… any reason you chose the encoding that you did? Finally, I was able to get this to work while running in Immunity, but when I run it outside of a debugger, it essentially locks up my machine… mouse chops around the screen and I have to hard reboot. Any ideas what could cause that? Thanks for all your hard work.