LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-20-2005, 06:12 PM   #1
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
overflows and hax: how does it work?


heya... i think this would be the best spot to post this, so here i am.

OK:
my question is about hackers/hacking and buffer overflows.
how does this work? alot of security notices i have seen (regardless of system/os) are related to buffer/integer overflows, and they say that it can lead to remote execution of arbitrary code, usually.
so for example... in some c program, say its a simple console app' and it is asking for a input of a name. the program internally has a string (character array) with max length of 10 characters.. if i enter an 11-character name, this can somehow be accomplished? (i know thats very simple example) or in what-case scenarios?
how is the remote code executed and where is it stored? is the code some command-line statement? or is the code a call to some function in the source code file it resides in, with the supplied paramaters?
just in general.. i have been wondering how this works. if someone could share their knowledge on this, or point me to a good link about it (not one intended for someone with a phD, however).. that would be appreciated.

NOTE:
this post is strictly for informational purposes... i do _not_ intend to go 'leet haxor' into someones computer with any knowledge i gain from this. in fact, it could only benefit me for future programming too (writing safer code). if this post is inapproprite on this site, i understand and apologize.

BTW..
i would say im still very new to linux (i guess it isnt really a linux-directed question though), and i use ubuntu whenever i have spare time to fool around and break stuff , all other times i run xp pro. i am just finishing 2nd year of college for computer programming, so i do have knowledge in programming.

Last edited by nadroj; 03-20-2005 at 06:50 PM.
 
Old 03-20-2005, 10:06 PM   #2
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
When a program is executed it's allocated an array in memory called a stack. As the code is executed by the processor, things like variables and pointers are temporarily stored in the stack. Each time a new set of instructions is pushed onto the stack, a pointer to the memory location of where the program is currently being executed is loaded onto the stack as well, that way the system can know where to return to once it is done executing the current set of instructions and get new ones. This is important, because if you "overflow" a buffer (assign a value too large for the buffer memory size you've declared/allocated it) then you can fill the buffer that the program was expecting and overwrite other values in the stack (just like you can do with any other array). Normally this just results in a segmentation fault that you've probably done 1000 times already in your programming classes without realizing what's actually is happening. The trick is to then overwrite the address in the return pointer with an address that you already know contains the memory position of the arbitrary code you want to execute. There are shortcuts such as using the NOP instruction or using a debugger to identify memory addresses.

So from a programmers perspective you can avoid this by checking the size of values you plan to assign to variables (especially anything that is user supplied). Usually this concept isn't really introduced until more advanced programming classes and unfortunately they often let novice programmers use dangerous functions like strcpy and scanf. That's a very brief and cursory description and this forum isn't really the place for a more detailed description.

For more info go read "Smashing the Stack for Fun and Profit" at phrack or go buy the book "Hacking: The Art of Exploitation" and above all remember to only use your powers for good.

Last edited by Capt_Caveman; 03-20-2005 at 10:09 PM.
 
Old 03-20-2005, 11:09 PM   #3
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Original Poster
Rep: Reputation: 60
alright caveman.. thank you for the insight.

ill look into that first resource you mentioned, and hopefully others. i remember talking about the stack... theres the stack and the heap in ram, eh?
 
Old 03-20-2005, 11:27 PM   #4
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Yeah there are two types of overflows like I mentioned, stack and heap overflows (there's actually a third called bss overflows that I'm not that familiar with). They both function in a similar manner except stacks and heaps "grow" in different directions. So when the stack is overflowed, the data you push onto the stack overwrites values moving towards the position of the return pointer. With a heap-based overflow you are moving away from them, so what you are usually overwriting is some other variable in the actual executing code (say for example UID number or something).

Last edited by Capt_Caveman; 03-20-2005 at 11:29 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPC msgrcv - writing overflows memory extra 4 bytes tara Programming 1 11-08-2005 11:40 PM
Validate input and preventing buffur overflows Bluesuperman Programming 1 02-04-2005 12:55 AM
Buffer Overflows question vexer General 8 05-04-2004 08:44 PM
burning cd: buffer overflows in the OS?? drenal Linux - Software 1 01-27-2004 06:23 PM
CERTŪ Advisory CA-2003-01 Buffer Overflows in ISC DHCPD Minires Library Astro Slackware 1 01-21-2003 06:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration