完成事项
未完成的事项
下周待做的事
本周知识分享
[TQLCTF 2022]simple_bypass
少见给我写笑了的题目
一个注册框,注册一下

到了后台,这前后段交互写的也太好了

一时半会没找到漏洞点,那么对系统进行更深的发掘还是发现了漏洞点
在杰哥这里找道了任意文件读写的漏洞点,大致原理就是找到指定文件并以base64的方式编码最后以jpg的方式显示

读到了index.php文件

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php error_reporting(0); if(isset($_POST['user']) && isset($_POST['pass'])){ $hash_user = md5($_POST['user']); $hash_pass = 'zsf'.md5($_POST['pass']); if(isset($_POST['punctuation'])){ if (strlen($_POST['user']) > 6){ echo("<script>alert('Username is too long!');</script>"); } elseif(strlen($_POST['website']) > 25){ echo("<script>alert('Website is too long!');</script>"); } elseif(strlen($_POST['punctuation']) > 1000){ echo("<script>alert('Punctuation is too long!');</script>"); } else{ if(preg_match('/[^\w\/\(\)\*<>]/', $_POST['user']) === 0){ if (preg_match('/[^\w\/\*:\.\;\(\)\n<>]/', $_POST['website']) === 0){ $_POST['punctuation'] = preg_replace("/[a-z,A-Z,0-9>\?]/","",$_POST['punctuation']); $template = file_get_contents('./template.html'); $content = str_replace("__USER__", $_POST['user'], $template); $content = str_replace("__PASS__", $hash_pass, $content); $content = str_replace("__WEBSITE__", $_POST['website'], $content); $content = str_replace("__PUNC__", $_POST['punctuation'], $content); file_put_contents('sandbox/'.$hash_user.'.php', $content); echo("<script>alert('Successed!');</script>"); } else{ echo("<script>alert('Invalid chars in website!');</script>"); } } else{ echo("<script>alert('Invalid chars in username!');</script>"); } } } else{ setcookie("user", $_POST['user'], time()+3600); setcookie("pass", $hash_pass, time()+3600); Header("Location:sandbox/$hash_user.php"); } } ?>
|
简单概括一下上面的源码,无字母webshell,会创建一个以你用户名的hash值命名的php文件,在sanbox目录下

拿到flag

贷齐乐错误的waf引起的SQL注入漏洞复现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?php header("Content-type: text/html; charset=utf-8"); require 'db.inc.php'; function dhtmlspecialchars($string) { if (is_array($string)) { foreach ($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } } else { $string = str_replace(array('&', '"', '<', '>', '(', ')'), array('&', '"', '<', '>', '(', ')'), $string); if (strpos($string, '&#') !== false) { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string); } } return $string; } function dowith_sql($str) { $check = preg_match('/select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/is', $str); if ($check) { echo "非法字符!"; exit(); } return $str; } foreach ($_REQUEST as $key => $value) { $_REQUEST[$key] = dowith_sql($value); } $request_uri = explode("?", $_SERVER['REQUEST_URI']); if (isset($request_uri[1])) { $rewrite_url = explode("&", $request_uri[1]); foreach ($rewrite_url as $key => $value) { $_value = explode("=", $value); if (isset($_value[1])) { $_REQUEST[$_value[0]] = dhtmlspecialchars(addslashes($_value[1])); } } } if (isset($_REQUEST['submit'])) { $user_id = $_REQUEST['i_d']; $sql = "select * from ctf.users where id=$user_id"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "</tr>"; } } ?>
|
1 2 3 4 5 6 7
| <?php $mysql_server_name="localhost"; $mysql_database="ctf"; $mysql_username="root"; $mysql_password="200"; $conn = mysqli_connect($mysql_server_name, $mysql_username,$mysql_password,'utf-8'); ?>
|
1 2 3 4 5 6 7 8 9
| CREATE DATABASE ctf; CREATE TABLE `users` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, `flag` varchar(255) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 INSERT INTO `users` (`name`, `pass`, `flag`) VALUES ('admin', 'qwer!@#zxca', 'hrctf{R3qu3st_Is_1nterEst1ng}');
|
大体上是复现了

1 2 3 4 5 6 7 8 9
| <?php header("Content-type: text/html; charset=utf-8"); require 'db.inc.php'; function dhtmlspecialchars($string) { if (is_array($string)) { foreach ($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } }
|
通过第18行的过滤,那么我们知道了下面的函数漏洞点,是关于php下划线特性的
1 2 3 4 5 6 7 8 9 10 11 12 13
| if (isset($_REQUEST['submit'])) { $user_id = $_REQUEST['i_d']; $sql = "select * from ctf.users where id=$user_id"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "</tr>"; } } ?>
|
还有这一段,差点忘了,这一段这里使用了危险函数exploade,只对传入的参数进行了简单的处理
1 2 3 4 5 6 7 8 9 10
| $request_uri = explode("?", $_SERVER['REQUEST_URI']); if (isset($request_uri[1])) { $rewrite_url = explode("&", $request_uri[1]); foreach ($rewrite_url as $key => $value) { $_value = explode("=", $value); if (isset($_value[1])) { $_REQUEST[$_value[0]] = dhtmlspecialchars(addslashes($_value[1])); } } }
|
那么大致思路如下
测出回显位

所有库

表名,这里需要再处理一下payload因为源代码里对“=”,做了处理,可以用like进行绕过,再有就是exlode函数的原因需要对字符串进行编码绕过

得到flag字段

得到flag

挖洞
偶然间挖到的一个edu src

嗯?sql报错,直接一把梭了

到这里本来打算交了,但我还想再扩大成果,看能不能写shell

嗯?sql路径能读出来而且,根据路径可以得知这个站的的部署的所有资产应该全是默认路径,而且select @@secure_file_priv 正常回显

那行了,直接–os-shell,但是翻车了,为什么呢

问了下学长,应该是这么回事

感想
上周ccb没打好,校队团队内部出现了一些小状况,心态有点炸了,现在想开了觉得也就那样,人生又不会一两次的变故而结束,人生何处不青山