Question

Binary Bomb Phase 2

Asked by: purewin

I'm trying to get the value of the register of eax at the address  0x8048dc0. The assembler dump is below. Basically it reads 6 numbers and compares them to value of eax and the above memory location if I'm correct. I can't quite figure out how to iterate through the loop to get the register value each time it loops.

Right now the is what I'm doing:

(gdb) disas phase_2
Dump of assembler code for function phase_2:
0x08048d91 <phase_2+0>: push   %ebp
0x08048d92 <phase_2+1>: mov    %esp,%ebp
0x08048d94 <phase_2+3>: push   %esi
0x08048d95 <phase_2+4>: push   %ebx
0x08048d96 <phase_2+5>: sub    $0x30,%esp
0x08048d99 <phase_2+8>: lea    -0x20(%ebp),%eax
0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
0x08048da6 <phase_2+21>:        call   0x8048f56 <read_six_numbers>
0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
0x08048daf <phase_2+30>:        je     0x8048db6 <phase_2+37>
0x08048db1 <phase_2+32>:        call   0x8048f2c <explode_bomb>
0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
0x08048dbe <phase_2+45>:        mov    %ebx,%eax
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>:        je     0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>:        call   0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx
0x08048dd3 <phase_2+66>:        cmp    $0x7,%ebx
0x08048dd6 <phase_2+69>:        jne    0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>:        add    $0x30,%esp
0x08048ddb <phase_2+74>:        pop    %ebx
0x08048ddc <phase_2+75>:        pop    %esi
0x08048ddd <phase_2+76>:        pop    %ebp
0x08048dde <phase_2+77>:        ret    
End of assembler dump.
(gdb) break *0x08048dc0
Breakpoint 4 at 0x8048dc0
(gdb) r input.txt
Starting program: /home/jalexanb/lab1/bomb72/bomb-quiet input.txt
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
Phase 1 defused. How about the next one?

Breakpoint 3, 0x08048d96 in phase_2 ()
(gdb) info registers
eax            0x804a890        134523024
ecx            0xd      13
edx            0x2      2
ebx            0xbffe9cb4       -1073832780
esp            0xbffe9bf0       0xbffe9bf0
ebp            0xbffe9bf8       0xbffe9bf8
esi            0x941ca0 9706656
edi            0x0      0
eip            0x8048d96        0x8048d96 <phase_2+5>
eflags         0x282    [ SF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) step
Single stepping until exit from function phase_2,
which has no line number information.

BOOM!!!
The bomb has blown up.

Program exited with code 010.


I'm not sure what I'm not doing correctly any thoughts?

Dump of assembler code for function phase_2:
0x08048d91 <phase_2+0>: push   %ebp
0x08048d92 <phase_2+1>: mov    %esp,%ebp
0x08048d94 <phase_2+3>: push   %esi
0x08048d95 <phase_2+4>: push   %ebx
0x08048d96 <phase_2+5>: sub    $0x30,%esp
0x08048d99 <phase_2+8>: lea    -0x20(%ebp),%eax
0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
0x08048da6 <phase_2+21>:        call   0x8048f56 <read_six_numbers>
0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
0x08048daf <phase_2+30>:        je     0x8048db6 <phase_2+37>
0x08048db1 <phase_2+32>:        call   0x8048f2c <explode_bomb>
0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
0x08048dbe <phase_2+45>:        mov    %ebx,%eax
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>:        je     0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>:        call   0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx
0x08048dd3 <phase_2+66>:        cmp    $0x7,%ebx
0x08048dd6 <phase_2+69>:        jne    0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>:        add    $0x30,%esp
0x08048ddb <phase_2+74>:        pop    %ebx
0x08048ddc <phase_2+75>:        pop    %esi
0x08048ddd <phase_2+76>:        pop    %ebp
0x08048dde <phase_2+77>:        ret    
End of assembler dump.
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-18 at 10:04:56ID24821814
Tags

Binary

,

Bomb

,

Phase 2

Topics

Assembly Programming Language

,

C Programming Language

,

Linux Programming

Participating Experts
2
Points
500
Comments
23

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Binary Bomb Phase 4
    Alright i'm on phase 4 of the binary bomb problem, have analyzed the assembly and this is what I have. Dump of assembler code for function phase_4: 0x08048c2c <phase_4+0>: push %ebp 0x08048c2d <phase_4+1>: mov %esp,%ebp 0x08048c2f <phase_4+3>: sub $...
  2. Binary Bomb Final Phase
    Alright, on the last phase of the binary bomb. I have the code commented and just wanted to know if what I think is happening really is. So far I just think it is a bunch of nested loops and that the input will be 5 or less numbers. Alright any feedback would be very appre...
  3. Binary Bomb Final Phase
    I am working through the CS:APP textbook (auditing a class at the local state U) and I'm trying to complete the final phase of the binary bomb lab. Basically, I need to figure out what string to send to this function (in C) so that the "bomb" doesn't "explode....
  4. Binary Bomb Phase One
    I am working on the cvlassic binary bomb assignment, and I am having a little bit of difficulty on the first phase. I have a pretty good understanding of what each individual line of code represents and does, but the logic flow is confusing, and I don't know how to paste the...
  5. diffusing a bomb
    hey, I need to diffuse a "bomb", I was hoping I could get some advice, I have a vague idea of what I need to do. 080519c4 <phase_1>: 80519c4: 55 push %ebp 80519c5: 89 e5 mov %esp,%ebp 80519c7: 83 ec 10 s...
  6. binary bomb phase 3
    i am having trouble with these two lines 0x08048ef2 <phase_3+49>: cmpl $0x7,-0x4(%ebp) 0x08048ef6 <phase_3+53>: ja 0x8048f61 <phase_3+160> i'm not sure what the first line is.... it looks like it compares something to 7. I am afraid t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: purewinPosted on 2009-10-18 at 12:36:16ID: 25601057

Any help would be appreciated. :)

 

by: purewinPosted on 2009-10-18 at 14:07:46ID: 25601422

I've been looking it over and I think that the actual change in the numbers takes place in read_six_numbers.
from read_six_numbers+3 to read_six_numbers+56
Here is the code...am I correct?

Dump of assembler code for function read_six_numbers:
0x08048f56 <read_six_numbers+0>:        push   %ebp
0x08048f57 <read_six_numbers+1>:        mov    %esp,%ebp
0x08048f59 <read_six_numbers+3>:        sub    $0x28,%esp
0x08048f5c <read_six_numbers+6>:        mov    0xc(%ebp),%edx
0x08048f5f <read_six_numbers+9>:        lea    0x14(%edx),%eax
0x08048f62 <read_six_numbers+12>:       mov    %eax,0x1c(%esp)
0x08048f66 <read_six_numbers+16>:       lea    0x10(%edx),%eax
0x08048f69 <read_six_numbers+19>:       mov    %eax,0x18(%esp)
0x08048f6d <read_six_numbers+23>:       lea    0xc(%edx),%eax
0x08048f70 <read_six_numbers+26>:       mov    %eax,0x14(%esp)
0x08048f74 <read_six_numbers+30>:       lea    0x8(%edx),%eax
0x08048f77 <read_six_numbers+33>:       mov    %eax,0x10(%esp)
0x08048f7b <read_six_numbers+37>:       lea    0x4(%edx),%eax
0x08048f7e <read_six_numbers+40>:       mov    %eax,0xc(%esp)
0x08048f82 <read_six_numbers+44>:       mov    %edx,0x8(%esp)
0x08048f86 <read_six_numbers+48>:       movl   $0x80497af,0x4(%esp)
0x08048f8e <read_six_numbers+56>:       mov    0x8(%ebp),%eax
0x08048f91 <read_six_numbers+59>:       mov    %eax,(%esp)
0x08048f94 <read_six_numbers+62>:       call   0x8048828 <sscanf@plt>
0x08048f99 <read_six_numbers+67>:       cmp    $0x5,%eax
0x08048f9c <read_six_numbers+70>:       jg     0x8048fa3 <read_six_numbers+77>
0x08048f9e <read_six_numbers+72>:       call   0x8048f2c <explode_bomb>
0x08048fa3 <read_six_numbers+77>:       leave  
0x08048fa4 <read_six_numbers+78>:       ret    
End of assembler dump.

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

Select allOpen in new window

 

by: purewinPosted on 2009-10-18 at 16:42:24ID: 25601899

Could still use some help on this....

Here is what I have determine the instructions in phase_2 to do. Correct me if I'm wrong. I need help figuring out determining what exactly the increment the numbers are increased by for each iteration to get the correct input.

Dump of assembler code for function phase_2:
0x08048d91 <phase_2+0>: push   %ebp
pushes ebp on the stack ebp = input
0x08048d92 <phase_2+1>: mov    %esp,%ebp
ebp = esp    (esp =*input)
0x08048d94 <phase_2+3>: push   %esi
pushes esi onto the stack
0x08048d95 <phase_2+4>: push   %ebx
pushes ebx onto the stack
0x08048d96 <phase_2+5>: sub    $0x30,%esp
esp = esp - 48
0x08048d99 <phase_2+8>: lea    -0x20(%ebp),%eax
eax = ebp - 32
0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
eax = esp + 4
0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
eax = ebp + 8
0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
esp = eax
0x08048da6 <phase_2+21>:        call   0x8048f56 <read_six_numbers>
calls read_six_numbers with eax as parameter
0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
compares ebp  32 to see if its equal to 1
0x08048daf <phase_2+30>:        je     0x8048db6 <phase_2+37>
if ebp  32 is = 1 jump to ,phase_2+37
0x08048db1 <phase_2+32>:        call   0x8048f2c <explode_bomb>
calls explode_bomb() if ebp  32 != 1
0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
ebx = 2
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
esi = edp - 32
0x08048dbe <phase_2+45>:        mov    %ebx,%eax
eax = ebx
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
eax = (esi + ebx * 4  8) * (esi + ebx * 4  8)
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
compares if (esi + ebx * 4  4) == eax
0x08048dc9 <phase_2+56>:        je     0x8048dd0 <phase_2+63>
jumps to <phase_2> if (esi + ebx * 4  8) == eax
0x08048dcb <phase_2+58>:        call   0x8048f2c <explode_bomb>
if (esi + ebx * 4  8) != eax 	exploded_bomb() is called
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx
ebx = ebx + 1
0x08048dd3 <phase_2+66>:        cmp    $0x7,%ebx
checks if ebx != 7
0x08048dd6 <phase_2+69>:        jne    0x8048dbe <phase_2+45>
if ebx is != 7	then jump to phase_2+45
0x08048dd8 <phase_2+71>:        add    $0x30,%esp
esp = esp + 30
0x08048ddb <phase_2+74>:        pop    %ebx
0x08048ddc <phase_2+75>:        pop    %esi
0x08048ddd <phase_2+76>:        pop    %ebp
0x08048dde <phase_2+77>:        ret    
End of assembler dump.
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:

Select allOpen in new window

 

by: purewinPosted on 2009-10-18 at 18:15:16ID: 25602165

Could reallly use some help with this...I've looked at the other solutions posted and they aren't very helpful for me....

 

by: Infinity08Posted on 2009-10-19 at 02:26:59ID: 25603654

I see you've made some progress.


>> I'm not sure what I'm not doing correctly any thoughts?

The bomb explodes because the input you gave is not correct. In order to continue, you'll have to pass the right input. More directly, you'll have to make that it never calls explode_bomb :) The loop won't continue when the bomb explodes.


>> I've been looking it over and I think that the actual change in the numbers takes place in read_six_numbers.

All the read_six_numbers function does, is exactly what it says ... It reads 6 numbers from the provided string, and places them on the stack.


>> Here is what I have determine the instructions in phase_2 to do. Correct me if I'm wrong.

>> 0x08048d91 <phase_2+0>: push   %ebp
>> pushes ebp on the stack ebp = input
>> 0x08048d92 <phase_2+1>: mov    %esp,%ebp
>> ebp = esp    (esp =*input)

%ebp is the base pointer ... This is just the standard way to start a new stack frame at the start of a function. It is not your input, although some of the input might be found relative to the (new) base pointer.


>> 0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
>> eax = esp + 4

The mov instruction moves the value of the left argument to the location specified in the right argument. Not the other way around.


>> 0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
>> eax = ebp + 8
>> 0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
>> esp = eax

There is a dereferencing operation that you missed. With C-like syntax :

        eax = *(ebp + 8)
        *(esp) = eax

(ebp + 8) is an address, but we're not interested in the address - we're interested in the value that is located at that address. Hence the dereference operation. Similarly for (esp).


>> 0x08048da6 <phase_2+21>:        call   0x8048f56 <read_six_numbers>
>> calls read_six_numbers with eax as parameter

The parameter is passed on the stack, not in eax.


>> 0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
>> compares ebp  32 to see if its equal to 1

Don't forget the dereference operation again ...


>> 0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
>> eax = (esi + ebx * 4  8) * (esi + ebx * 4  8)

imul multiplies its both arguments, ie. :

        imul a, b

means :

        b = b * a

Also don't forget to dereference ...

>> 0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
>> compares if (esi + ebx * 4  4) == eax

dereference ...


>> 0x08048dd8 <phase_2+71>:        add    $0x30,%esp
>> esp = esp + 30

hex vs. decimal mistake here ...

 

by: duncan_roePosted on 2009-10-19 at 02:43:16ID: 25603731

I think you need to use si (step one instruction exactly) rather than s (step) which steps a 3GL instruction (where assembler is a 2GL).

 

by: purewinPosted on 2009-10-19 at 07:24:45ID: 25605379

The bomb explodes because the input you gave is not correct. In order to continue, you'll have to pass the right input. More directly, you'll have to make that it never calls explode_bomb :) The loop won't continue when the bomb explodes.

>>>Right I understand that.

All the read_six_numbers function does, is exactly what it says ... It reads 6 numbers from the provided string, and places them on the stack.

>>Right I understand this.

>> Here is what I have determine the instructions in phase_2 to do. Correct me if I'm wrong.

>> 0x08048d91 <phase_2+0>: push   %ebp
>> pushes ebp on the stack ebp = input
>> 0x08048d92 <phase_2+1>: mov    %esp,%ebp
>> ebp = esp    (esp =*input)

%ebp is the base pointer ... This is just the standard way to start a new stack frame at the start of a function. It is not your input, although some of the input might be found relative to the (new) base pointer.

0x08048d91 <phase_2+0>: push   %ebp
puashes ebp onto the stack
 0x08048d92 <phase_2+1>: mov    %esp,%ebp
ebp = *esp  esp pointer is being pointed at ebp on the stack

>> 0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
>> eax = esp + 4

The mov instruction moves the value of the left argument to the location specified in the right argument. Not the other way around.
0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
eax = (%esp+4)  moves eax to the position (%esp+4) on the stack

>> 0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
>> eax = ebp + 8
>> 0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
>> esp = eax

There is a dereferencing operation that you missed. With C-like syntax :
0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
move the value of (ebp+8) to = eax
0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
*(esp) = eax  sets stack pointer esp to eax

        eax = *(ebp + 8)
        *(esp) = eax

(ebp + 8) is an address, but we're not interested in the address - we're interested in the value that is located at that address. Hence the dereference operation. Similarly for (esp).


>> 0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
>> compares ebp  32 to see if its equal to 1

Don't forget the dereference operation again ...
Not sure about the dereference here...Should this be
0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
(ebp - 32) : : 1?? Not sure where the dereferencign comes in...


>> 0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
>> eax = *(esi + ebx * 4 - 8) *  *(esi + ebx * 4 - 8)

imul multiplies its both arguments, ie. :

        imul a, b

means :

        b = b * a

Also don't forget to dereference ...
eax = *(esi + ebx * 4 - 8) *  *(esi + ebx * 4 - 8)

>> 0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
>> compares if (esi + ebx * 4  4) == eax

dereference ...


>> 0x08048dd8 <phase_2+71>:        add    $0x30,%esp
 esp = esp + 48

hex vs. decimal mistake here ...
esp = esp +48


Could you explain dereferencing? Maybe with an example? This is probably not clicking for me because I am learning C and Assembly at the same time...thanks.

 

by: purewinPosted on 2009-10-19 at 07:35:54ID: 25605473

Am I wrong in thinking that this is the loop for the phase?

0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
0x08048dbe <phase_2+45>:        mov    %ebx,%eax
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>:        je     0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>:        call   0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx
0x08048dd3 <phase_2+66>:        cmp    $0x7,%ebx
0x08048dd6 <phase_2+69>:        jne    0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>:        add    $0x30,%esp

And that the after the input is put through the read_six_numbers function each of the values will be incremented by some amount. Which I need to find and then applying to the first input number to find the next number and so on?

 

by: Infinity08Posted on 2009-10-19 at 07:39:44ID: 25605514

>>  0x08048d92 <phase_2+1>: mov    %esp,%ebp
>> ebp = *esp  esp pointer is being pointed at ebp on the stack

What this means is that the current base pointer (ebp) is set to the top of the stack (esp), so a new stack frame can be started for the function.

If you're not sure about what a stack frame is, take a look here :

        http://en.wikipedia.org/wiki/Call_stack


>> 0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
>> eax = (%esp+4)  moves eax to the position (%esp+4) on the stack

Although your pseudo code is misleading (the assignment is still the wrong way around, and the dereference operation is still not there), your explanation in words sounds correct.


>> 0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
>> move the value of (ebp+8) to = eax

Not the value of (ebp+8), but the value that is located at address (ebp+8). There's an important distinction there.


>> 0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
>> *(esp) = eax  sets stack pointer esp to eax

No, you're missing the dereference operation again. This instruction places the value in eax at the top of the stack. It does not modify the stack pointer (esp), but rather the memory that it's pointing to.


>> 0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
>> (ebp - 32) : : 1?? Not sure where the dereferencign comes in...

Always the same ... It's not (ebp-32), but it's *(ebp-32). Do you understand what the * means ? Do you know the C language, and what the dereference operator (*) does there ?


>> eax = *(esi + ebx * 4 - 8) *  *(esi + ebx * 4 - 8)

That's only one half of my remark. Did you understand what I said about how the imul instruction works, and which values it multiplies ?



>> Could you explain dereferencing? Maybe with an example? This is probably not clicking for me because I am learning C and Assembly at the same time...thanks.

Dereferencing means that you have a pointer (a memory address), and instead of using that address, you get the value that is located at that address in memory. You follow the pointer to get to the value it's pointing to - ie. you're dereferencing the pointer.

 

by: Infinity08Posted on 2009-10-19 at 07:43:45ID: 25605558

>> Am I wrong in thinking that this is the loop for the phase?

That's a loop indeed, which performs some calculations and checks based on the six numbers that were entered by the user.


>> And that the after the input is put through the read_six_numbers function each of the values will be incremented by some amount.

Not really. What is happening is that each of the numbers is compared to a specific (calculated) value, and if one of them has the wrong value, the bomb explodes. It's your job to figure out those values.

 

by: purewinPosted on 2009-10-19 at 08:10:12ID: 25605858

Okay so I need to look at the value of the memory addresses when the pointer is being dereferenced?

>>Always the same ... It's not (ebp-32), but it's *(ebp-32). Do you understand what the * means ? Do you >>know the C language, and what the dereference operator (*) does there ?
Does this mean *(ebp-32) is a memory location? Or does it mean that I would find the value at that memory location and then subtract 32 from it?

>>Although your pseudo code is misleading (the assignment is still the wrong way around, and the >>dereference operation is still not there), your explanation in words sounds correct

Yea sorry about that not really sure how to express most of what I want to say via assembly code...

>>No, you're missing the dereference operation again. This instruction places the value in eax at the top >>of the stack. It does not modify the stack pointer (esp), but rather the memory that it's pointing to.

That is what I was trying to say...because esp points to the top of the stack. So setting the pointer of esp to the value of eax would put that value at the top of the stack i.e. that memory location.

What command would I use to look up the value at a particular location?

>>Not really. What is happening is that each of the numbers is compared to a specific (calculated) value, >>and if one of them has the wrong value, the bomb explodes. It's your job to figure out those values.

If the calculation isn't done in the loop and it isn't done in the read_six_numbers function there doesn't seem to be anywhere else it could be done.

 

by: Infinity08Posted on 2009-10-19 at 08:19:03ID: 25605947

>> Does this mean *(ebp-32) is a memory location? Or does it mean that I would find the value at that memory location and then subtract 32 from it?

It means that (ebp-32) is a memory location (address), and that you get the value at that memory location.


>> So setting the pointer of esp to the value of eax

You seem to understand what happens, but this phrase is still wrong ... You don't actually set the stack pointer (esp), since that would imply modifying esp. But you set the value that esp points to.


>> What command would I use to look up the value at a particular location?

What do you mean ? In the debugger ? You can use the examine (x) command :

        http://sourceware.org/gdb/download/onlinedocs/gdb_11.html#SEC72


>> If the calculation isn't done in the loop

I never said it wasn't done in the loop.

 

by: purewinPosted on 2009-10-19 at 08:24:08ID: 25606016

So for example:
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
the value of esi would be found in memory location 0x08048dbb?

 

by: purewinPosted on 2009-10-19 at 08:29:42ID: 25606084

I feel like that's not right now...

 

by: purewinPosted on 2009-10-19 at 08:34:10ID: 25606135

So I know what I need to find is in the loop.
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
this is the only part that I see that different values are calculated and compared. But in order for me to figure out eax(the numbers I need) I would have to find the values of esi and ebx. Am I understanding this correctly?

 

by: Infinity08Posted on 2009-10-19 at 08:37:11ID: 25606179

>> 0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
>> the value of esi would be found in memory location 0x08048dbb?

The lea (load effective address) instruction is an exception. It skips the dereference operation, and just works with the address.

>> this is the only part that I see that different values are calculated and compared. But in order for me to figure out eax(the numbers I need) I would have to find the values of esi and ebx. Am I understanding this correctly?

You are :)

 

by: purewinPosted on 2009-10-19 at 09:05:09ID: 25606449

ebx would be found here correct?
0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
Which ebx would be equal to 2.But, it would be incremented by one each time the loop iterates by this
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx

As for esi
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
The value of esi would be found in the memory location 0x08048dbb correct? Or is the address (%ebp - 20) the value of esi. I'm thinking the later...

 

by: purewinPosted on 2009-10-19 at 09:09:50ID: 25606489

EDIT:
As for esi
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
The value of esi would be found in the memory location 0x08048dbb correct? Or is the address (%ebp - 32) the value of esi. I'm thinking the later...
Forgot to convert from hex.

 

by: Infinity08Posted on 2009-10-19 at 11:38:29ID: 25607798

>> Which ebx would be equal to 2.But, it would be incremented by one each time the loop iterates by this

Correct.

>> Or is the address (%ebp - 32) the value of esi. I'm thinking the later...

It's the latter indeed. Remember that lea is the exception when it comes to dereferencing ...

 

by: purewinPosted on 2009-10-19 at 12:58:29ID: 25608414

Mmmm I'm not able to find the correct values, here is a copy of what I was doing, I kept getting really large negative numbers that just don't seem right. Any thoughts?

(gdb) disas phase_2
Dump of assembler code for function phase_2:
0x08048d91 <phase_2+0>: push   %ebp
0x08048d92 <phase_2+1>: mov    %esp,%ebp
0x08048d94 <phase_2+3>: push   %esi
0x08048d95 <phase_2+4>: push   %ebx
0x08048d96 <phase_2+5>: sub    $0x30,%esp
0x08048d99 <phase_2+8>: lea    -0x20(%ebp),%eax
0x08048d9c <phase_2+11>:        mov    %eax,0x4(%esp)
0x08048da0 <phase_2+15>:        mov    0x8(%ebp),%eax
0x08048da3 <phase_2+18>:        mov    %eax,(%esp)
0x08048da6 <phase_2+21>:        call   0x8048f56 <read_six_numbers>
0x08048dab <phase_2+26>:        cmpl   $0x1,-0x20(%ebp)
0x08048daf <phase_2+30>:        je     0x8048db6 <phase_2+37>
0x08048db1 <phase_2+32>:        call   0x8048f2c <explode_bomb>
0x08048db6 <phase_2+37>:        mov    $0x2,%ebx
0x08048dbb <phase_2+42>:        lea    -0x20(%ebp),%esi
0x08048dbe <phase_2+45>:        mov    %ebx,%eax
0x08048dc0 <phase_2+47>:        imul   -0x8(%esi,%ebx,4),%eax
0x08048dc5 <phase_2+52>:        cmp    %eax,-0x4(%esi,%ebx,4)
0x08048dc9 <phase_2+56>:        je     0x8048dd0 <phase_2+63>
0x08048dcb <phase_2+58>:        call   0x8048f2c <explode_bomb>
0x08048dd0 <phase_2+63>:        add    $0x1,%ebx
0x08048dd3 <phase_2+66>:        cmp    $0x7,%ebx
0x08048dd6 <phase_2+69>:        jne    0x8048dbe <phase_2+45>
0x08048dd8 <phase_2+71>:        add    $0x30,%esp
0x08048ddb <phase_2+74>:        pop    %ebx
0x08048ddc <phase_2+75>:        pop    %esi
0x08048ddd <phase_2+76>:        pop    %ebp
0x08048dde <phase_2+77>:        ret    
End of assembler dump.
(gdb) break *0x08048dbb
Breakpoint 1 at 0x8048dbb
(gdb) break *0x08048dc0
Breakpoint 2 at 0x8048dc0
(gdb) break *0x08048dc5
Breakpoint 3 at 0x8048dc5
(gdb) break *0x08048dc9
Breakpoint 4 at 0x8048dc9
(gdb) r input.txt
Starting program: /home/jalexanb/lab1/bomb72/bomb-quiet input.txt
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
Phase 1 defused. How about the next one?
1 2 3 4 5 6
 
Breakpoint 1, 0x08048dbb in phase_2 ()
(gdb) print *(int *) (%ebp-32)
A syntax error in expression, near `%ebp-32)'.
(gdb) si
0x08048dbe in phase_2 ()
(gdb) print *(int *) (%ebp-32)
A syntax error in expression, near `%ebp-32)'.
(gdb) print /x (%ebp-32)
A syntax error in expression, near `%ebp-32)'.
(gdb) info registers
eax            0x6      6
ecx            0xbff27164       -1074630300
edx            0x0      0
ebx            0x2      2
esp            0xbff27260       0xbff27260
ebp            0xbff27298       0xbff27298
esi            0xbff27278       -1074630024
edi            0x0      0
eip            0x8048dbe        0x8048dbe <phase_2+45>
eflags         0x246    [ PF ZF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) x 0x08048dbb
0x8048dbb <phase_2+42>: 0x89e0758d
(gdb) x/x 0x080488dbb
0x80488dbb:     Cannot access memory at address 0x80488dbb
(gdb) x/x 0x08048dbb
0x8048dbb <phase_2+42>: 0x89e0758d
(gdb) x/d 0x08048dbb
0x8048dbb <phase_2+42>: -1981778547
(gdb) si
 
Breakpoint 2, 0x08048dc0 in phase_2 ()
(gdb) x/d (%edi-32)
A syntax error in expression, near `%edi-32)'.
(gdb) x/d 0x08048dc0
0x8048dc0 <phase_2+47>: -1639665905
(gdb) info registers
eax            0x2      2
ecx            0xbff27164       -1074630300
edx            0x0      0
ebx            0x2      2
esp            0xbff27260       0xbff27260
ebp            0xbff27298       0xbff27298
esi            0xbff27278       -1074630024
edi            0x0      0
eip            0x8048dc0        0x8048dc0 <phase_2+47>
eflags         0x246    [ PF ZF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) si
 
Breakpoint 3, 0x08048dc5 in phase_2 ()
(gdb) info registers
eax            0x2      2
ecx            0xbff27164       -1074630300
edx            0x0      0
ebx            0x2      2
esp            0xbff27260       0xbff27260
ebp            0xbff27298       0xbff27298
esi            0xbff27278       -1074630024
edi            0x0      0
eip            0x8048dc5        0x8048dc5 <phase_2+52>
eflags         0x202    [ IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) x/d 0x08048dc5
0x8048dc5 <phase_2+52>: -56736711
(gdb) si
 
Breakpoint 4, 0x08048dc9 in phase_2 ()
(gdb) info registers
eax            0x2      2
ecx            0xbff27164       -1074630300
edx            0x0      0
ebx            0x2      2
esp            0xbff27260       0xbff27260
ebp            0xbff27298       0xbff27298
esi            0xbff27278       -1074630024
edi            0x0      0
eip            0x8048dc9        0x8048dc9 <phase_2+56>
eflags         0x246    [ PF ZF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) x/d 0x08048dc9
0x8048dc9 <phase_2+56>: 1558709620
(gdb) 
0x8048dcd <phase_2+60>: -2097151999
(gdb) x/d (%esi-32)
A syntax error in expression, near `%esi-32)'.
(gdb) x/d %esi-32
A syntax error in expression, near `%esi-32'.
(gdb) x/d (esi-32)
No symbol "esi" in current context.
(gdb) si
0x08048dd0 in phase_2 ()
(gdb) info registers
eax            0x2      2
ecx            0xbff27164       -1074630300
edx            0x0      0
ebx            0x2      2
esp            0xbff27260       0xbff27260
ebp            0xbff27298       0xbff27298
esi            0xbff27278       -1074630024
edi            0x0      0
eip            0x8048dd0        0x8048dd0 <phase_2+63>
eflags         0x246    [ PF ZF IF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
(gdb) x/d 0x08048dd0
0x8048dd0 <phase_2+63>: -2097036413
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:

Select allOpen in new window

 

by: purewinPosted on 2009-10-19 at 13:26:53ID: 25608683

Phase two Complete!
Thanks for the help.
Now onto phase 3. :)

 

by: Infinity08Posted on 2009-10-19 at 13:28:39ID: 25608698

Good job :) Have fun with phase 3 !

 

by: purewinPosted on 2009-10-19 at 16:20:14ID: 31642650

incremented ebx was multiplied by the user input each time

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...