Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 64 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Network Pen Testingarrow Trying to understand i686 architecture
EH-Net
May 20, 2013, 12:52:58 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: 1 [2]   Go Down
  Print  
Author Topic: Trying to understand i686 architecture  (Read 10293 times)
0 Members and 1 Guest are viewing this topic.
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #15 on: February 25, 2010, 11:34:40 AM »

Skip the 2nd question... I should have been using "x/8x", duh. This is the output I get...

(gdb) x/8x buffer1
0xbffff467:   0x04846000   0xfff48808   0xfff488bf   0x04842bbf
0xbffff477:   0x00000108   0x00000200   0x00000300   0x00000000

And then main:

(gdb) disas main
Dump of assembler code for function main:
0x08048402 <main+0>:   push   %ebp
0x08048403 <main+1>:   mov    %esp,%ebp
0x08048405 <main+3>:   sub    $0x10,%esp
0x08048408 <main+6>:   movl   $0x0,-0x4(%ebp)
0x0804840f <main+13>:   movl   $0x3,0x8(%esp)
0x08048417 <main+21>:   movl   $0x2,0x4(%esp)
0x0804841f <main+29>:   movl   $0x1,(%esp)
0x08048426 <main+36>:   call   0x80483e4 <function>
0x0804842b <main+41>:   movl   $0x1,-0x4(%ebp)
0x08048432 <main+48>:   mov    $0x8048510,%eax
0x08048437 <main+53>:   mov    -0x4(%ebp),%edx
0x0804843a <main+56>:   mov    %edx,0x4(%esp)
0x0804843e <main+60>:   mov    %eax,(%esp)
0x08048441 <main+63>:   call   0x804831c <printf@plt>
0x08048446 <main+68>:   leave 
0x08048447 <main+69>:   ret   
End of assembler dump.


Something definitely isn't right if you look at the last address for buffer1
Logged
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #16 on: February 25, 2010, 11:39:37 AM »

Doh! Yea x/8 doesn't work on every system. Maybe you should try "x/16x" to show more of the stack.

ZF
Logged

ZF
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #17 on: February 25, 2010, 12:51:51 PM »

Ok, so I got this all figured out.

In case anyone else ever reads this, I was using gcc version 4.. and Ubuntu 9.04... so there's clearly some things I don't understand there. Going back to Ubuntu 7.10, I was able to get this working using zeroflaw's directions.

Thanks!!
Logged
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #18 on: February 25, 2010, 01:32:30 PM »

I'm getting a little closer on Ubuntu 9.04.

If you compile as follows:
Code:
gcc -g -mpreferred-stack-boundary=2 -o e3 example3.c

and then do the following with gdb:

(gdb) b 2
Breakpoint 1 at 0x804844a: file example3.c, line 2.
(gdb) run
Starting program: /home/joel/hacking/stacksmash/e3

Breakpoint 1, function (a=1, b=2, c=3) at example3.c:2
2   void function(int a, int b, int c) {
(gdb) x/8x buffer1
0xbffff457:   0xfff48808   0x0484f9bf   0x6fe30408   0x6fdff400
0xbffff467:   0x0484e000   0xfff48808   0xfff488bf     0x0484a7bf
(gdb) disas main
Dump of assembler code for function main:
0x0804847e <main+0>:   push   %ebp
0x0804847f <main+1>:   mov    %esp,%ebp
0x08048481 <main+3>:   sub    $0x10,%esp
0x08048484 <main+6>:   movl   $0x0,-0x4(%ebp)
0x0804848b <main+13>:   movl   $0x3,0x8(%esp)
0x08048493 <main+21>:   movl   $0x2,0x4(%esp)
0x0804849b <main+29>:   movl   $0x1,(%esp)
0x080484a2 <main+36>:   call   0x8048444 <function>
0x080484a7 <main+41>:   movl   $0x1,-0x4(%ebp)
0x080484ae <main+48>:   mov    $0x8048590,%eax
0x080484b3 <main+53>:   mov    -0x4(%ebp),%edx
0x080484b6 <main+56>:   mov    %edx,0x4(%esp)
0x080484ba <main+60>:   mov    %eax,(%esp)
0x080484bd <main+63>:   call   0x8048364 <printf@plt>
0x080484c2 <main+68>:   leave 
0x080484c3 <main+69>:   ret   
End of assembler dump.


.... you will see that you can find most of the return address... but something is a bit weird since it is offset a bit. It is almost 28 bytes away from the start of buffer1... but not quite. Almost seems like it's 27 bytes away... but that doesn't seem to make much sense to me!

Not sure if this helps any...
Logged
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #19 on: February 25, 2010, 03:47:33 PM »

I'm not getting it to work on 9.* either. The funny thing is that I tried to compile it on a Ubuntu 9.10 x64 virtual machine. Used the same methods to find the distance between buffer1 and the return address etc. It actually worked!

It has something to do with the alignment on the stack. It just has to be some option or maybe a bug  Huh Huh Huh

ZF
Logged

ZF
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #20 on: February 25, 2010, 04:04:26 PM »

Did you type that wrong? Do you mean you tried it on Ubuntu 7.10 x64 and it really worked?
Logged
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #21 on: February 25, 2010, 04:56:17 PM »

Lol I did mean 9.10. I recently upgraded Tongue Still confused about 32 bit version and stack alignment.

ZF
Logged

ZF
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #22 on: February 25, 2010, 05:06:57 PM »

Oh... wow, my apologies! I didn't think it was reasonable to not work on 9.04, but work on 9.10!! Maybe it is a bug then. Weird.

I'll give it a shot as well.

Joel
Logged
jacksmash
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #23 on: February 26, 2010, 08:01:01 AM »

Ok, the problem I posted in "Reply #18" equally applies to 9.10 for me:
Code:
uname -a
Linux my-ubuntu 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/Linux
Logged
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.084 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.