天天看點

SQL注入分類:數值型or字元型

1、數字型注入:

當輸入的參數為整形時,如果存在注入漏洞,可以認為是數字型注入。

測試步驟:

1、加單引号,URL:www.text.com/text.php?id=3’

對應的sql:

select * from table where id=3'

這時sql語句出錯,程式無法正常從資料庫中查詢出資料,就會抛出異常;

2、 加

and 1=1

,URL:www.text.com/text.php?id=3 and 1=1

對應的sql:

select * from table where id=3 and 1=1

語句執行正常,與原始頁面如任何差異;

3、 加

and 1=2

,URL:www.text.com/text.php?id=3 and 1=2

對應的sql:

select * from table where id=3 and 1=2

語句可以正常執行,但是無法查詢出結果,是以傳回資料與原始網頁存在差異

如果滿足以上三點,則可以判斷該URL存在數字型注入。

2、字元型注入:

當輸入的參數為字元串時,稱為字元型。字元型和數字型最大的一個差別在于,數字型不需要單引号來閉合,而字元串一般需要通過單引号來閉合的。

例如

  • 數字型語句:

    select * from table where id =3

  • 字元型:

    select * from table where name= 'admin'

是以,在構造payload時通過閉合單引号可以成功執行語句:

測試步驟:

1、加單引号:

select * from table where name='admin''

由于加單引号後變成三個單引号,則無法執行,程式會報錯;

2、加

'and 1=1

此時sql 語句為:

select * from table where name='admin' and 1=1'

,也無法進行注入,還需要通過注釋符号将其繞過;

Mysql 有三種常用注釋符:

  1. --

    注意,這種注釋符後邊有一個空格
  2. #

    通過

    #

    進行注釋
  3. 注釋掉符号内的内容

是以,構造語句為:

select * from table where name ='admin' and 1=1-- '

可成功執行傳回結果正确;

3、加

'and 1=2--

此時sql語句為:

select * from table where name='admin' and 1=2-- '

則會報錯

如果滿足以上三點,可以判斷該url為字元型注入。