“Hacking: The Art of Exploitation” - Assembly Inconsistencies in book examples vs. my system's gcc

怎甘沉沦 提交于 2021-02-16 09:18:07

问题


I am studying "Hacking: The Art of Exploitation". I am trying to follow the code examples, but for some reason the assembly codes simply does not match the one on my actual Linux (running on Virtual Box as Guest). I have made sure that I have installed 32 bit Linux OS. Is there any args that I can pass to gcc that lets me compile the code into an assembly that matches closely with the ones given in the book?

I would be fine reconciling the code differences between the book & what I see if they were minor, but the difference I see is stark. I somehow don't like to run the code from the "Preconfigured incubator environment" as this inhibits my skill development.


回答1:


for some reason the assembly codes simply does not match the one on my actual linux

The most likely reason is that the book was published in 2008, and used then-stable GCC (you can see GCC release history here).

GCC that you are using now is likely much newer, and so generates significantly different (and one hopes better) code.

Is there any args that I can pass to gcc that lets me compile the code into an assembly that matches closely with the ones given in the book?

No. You can try to compile and install a version from 2008, perhaps 4.2.3 or 4.3.0, and check whether that gives you closer output.

P.S. It looks like the first revision of the book is from 2003, and it's unlikely that the authors rebuilt all of their examples for the second edition in 2008, so perhaps try GCC 3.3 instead?




回答2:


I've actually been in the same boat--for the last week or two I've tried a ton of ways to produce comparable assembly code in my normal development environment (LMDE), including chroot, compiling with the -m32 flag, installing an x86 ubuntu, etc, and nothing really worked. Today I found http://www.nostarch.com/hackingCD.htm and I followed the instructions and was able to get the livecd to boot in vmware workstation 10. Here's what I did:

  1. Download the iso from the link above (though it should work with the livecd as well)
  2. Create a .vmx file and copy and paste the config from the link
  3. I took out the section defining the cdrom device, since I was using an iso
  4. Open the file with VmWare Workstation--if you are using the iso, go to "Edit VM Settings" and set up a cdrom device and point it to the iso
  5. VM booted without any issues

I know this isn't as convenient as going through the examples in your main OS/system, and that you were trying to avoid using the LiveCD, but after doing a lot of research I've discovered that this is an extremely common issue and hopefully this answer helps someone. Using the LiveCD might not be ideal but it is still a heck of a lot better than dual booting.




回答3:


This is why the book comes with a LiveCD with a linux distro and all of the example source code from the book on there. All of the examples in the book match exactly with what will happen in the LiveCD.

Just run the included LiveCD using VirtualBox or VMware and follow along with the book using that. If you don't have the CD, it can be downloaded from a torrent provided by No Starch (linked from their website)




回答4:


it doesn´t matter whether the output of gcc is different, the only thing it changes is the memory addresses; plus, you said u r using a VM to run it, meaning that the memory u will get is dummy memory, try booting the iso and run it directly, it will almost the same.

https://www.youtube.com/watch?v=pIN7oFkz5rM



来源:https://stackoverflow.com/questions/27053865/hacking-the-art-of-exploitation-assembly-inconsistencies-in-book-examples-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!