{"id":896,"date":"2019-10-07T09:58:17","date_gmt":"2019-10-07T13:58:17","guid":{"rendered":"https:\/\/blog.lamarranet.com\/?p=896"},"modified":"2019-10-08T10:08:33","modified_gmt":"2019-10-08T14:08:33","slug":"rop-emporium-setup","status":"publish","type":"post","link":"https:\/\/blog.lamarranet.com\/index.php\/rop-emporium-setup\/","title":{"rendered":"ROP Emporium | Setup"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p>After completing the <a href=\"https:\/\/blog.lamarranet.com\/index.php\/exploit-education-phoenix-solutions\/\">Exploit Education Phoenix challenges<\/a>, I started looking to advance my exploit development learning. A good next step would be learning about Return Oriented Programming (ROP) to defeat exploit mitigations such as Data Execution Prevention (DEP)\/No-Execute (NX). <a href=\"https:\/\/ropemporium.com\/\">ROP Emporium<\/a> should be a great place for that. There are a total of 8 challenges on the site that (sort of) progress in difficulty.<\/p>\n<h1>ROP Emporium Challenges<\/h1>\n<p>Of course, you should never run un-trusted binaries on your regular computer. I&#8217;ll be working in a <a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox<\/a> VM running <a href=\"https:\/\/www.archlinux.org\/\">Arch Linux<\/a>. It&#8217;s not that I don&#8217;t trust the ROP Emporium creators, it&#8217;s about maintaining good habits.<\/p>\n<p>Each challenge has a 32-bit and 64-bit version. If there&#8217;s a difference between the two (aside from addresses), I&#8217;ll try to complete the challenge for both.<\/p>\n<h1>radare2<\/h1>\n<p>Aside from learning ROP, my alternative goal is to learn how to use <a href=\"https:\/\/rada.re\/r\/\">radare2<\/a>, an open source, fully-featured reverse engineering and debugging framework. The ROP Emporium <a href=\"https:\/\/ropemporium.com\/guide.html\">Beginner&#8217;s Guide<\/a> even states that radare2 should have everything you need to complete every challenge on the site. So every challenge I attempt here, I&#8217;ll use radare2 as much as possible. Installing radare2 in Arch Linux is as simple as<span style=\"font-family:Courier New;color:#64e0e0;background:#001919\"> $ sudo pacman -S radare2<\/span>. I&#8217;m sure a package exists for most package managers in other distros. Otherwise, you can just install from their <a href=\"https:\/\/github.com\/radareorg\/radare2#install--update\">GitHub repo<\/a>.<\/p>\n<h2>Getting Help<\/h2>\n<p>One thing you&#8217;ll discover very quickly about radare2 is that it has a <em>very<\/em> steep learning curve. And as they say, the best way to learn something is to teach it to someone else. I think the hardest part of learning radare2 is remembering all the commands. Fortunately, it has a very good, hierarchical help system. Simply entering <code>?<\/code> without anything else gives you the top-level help menu. Since <a href=\"https:\/\/ropemporium.com\/challenge\/ret2win.html\">ret2win<\/a> is the first challenge, I&#8217;ll use that binary as an example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-907\" src=\"https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/10\/r2help.png\" alt=\"radare2 help menu\" width=\"785\" height=\"560\" srcset=\"https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/10\/r2help.png 785w, https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/10\/r2help-300x214.png 300w, https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/10\/r2help-768x548.png 768w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><\/p>\n<p>The radare2 prompt starts you off at the entrypoint address for the binary. Let&#8217;s use the help menus to figure out how we can verify that. I know that I want to get &#8220;information&#8221; on the binary. The entrypoint address is listed in the ELF header. With any of these commands, you can append a question mark to the end to get the next level of help. Another nice feature is the internal grep command. The tilde (~) character will allow you to grep the output. Following that with a plus (+) makes the search case insensitive:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;0x00400650]&gt; ? ~+ info\r\n| i&#x5B;?] &#x5B;file]             get info about opened file from r_bin\r\n<\/pre>\n<p>So we&#8217;ll probably want the &#8220;i&#8221; command. Let&#8217;s see what we can glean from that:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;0x00400650]&gt; i? ~+ entry\r\n| ie                 Entrypoint\r\n| iee                Show Entry and Exit (preinit, init and fini)\r\n&#x5B;0x00400650]&gt; ie\r\n&#x5B;Entrypoints]\r\nvaddr=0x00400650 paddr=0x00000650 haddr=0x00000018 hvaddr=0x00400018 type=program\r\n\r\n1 entrypoints\r\n<\/pre>\n<p>And there it is, the virtual entrypoint address is 0x00400650. As we move around the binary, that prompt will change.<\/p>\n<h2>Customization<\/h2>\n<p>There&#8217;s a lot you can do to customize radare2. I know I&#8217;ve only scratched the surface. Much like the <code>~\/.gdbinit<\/code> file that can customize your GDB environment, you can use a <code>~\/.radare2rc<\/code> file. Here are the customizations I&#8217;ve made so far. I&#8217;m sure I&#8217;ll keep modifying this file.<\/p>\n<pre class=\"brush: plain; light: false; title: ~\/.radare2rc; notranslate\" title=\"~\/.radare2rc\">\r\n# Disable fortunes\r\ne cfg.fortunes = false\r\n\r\n# Enable truecolor\r\ne scr.color = 3\r\n\r\n# Start at main() in debug mode\r\ne dbg.bep = main\r\n\r\n# Set the prompt to follow PC in debug mode\r\ne dbg.follow = 1\r\n\r\n# Do not show instruction bytes\r\ne asm.bytes = false\r\n\r\n# Use UTF-8 to have pretty arrows and borders\r\ne scr.utf8 = true\r\n\r\n# Set the color theme to bright\r\neco bright\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction After completing the Exploit Education Phoenix challenges, I started looking to advance my exploit development learning. A good next step would be learning about Return Oriented Programming (ROP) to<a href=\"https:\/\/blog.lamarranet.com\/index.php\/rop-emporium-setup\/\" class=\"more-link\"><span class=\"readmore\">Continue reading<span class=\"screen-reader-text\">ROP Emporium | Setup<\/span><\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-solutions"],"_links":{"self":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/comments?post=896"}],"version-history":[{"count":17,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":961,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/896\/revisions\/961"}],"wp:attachment":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/media?parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/categories?post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/tags?post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}