首页 新闻 会员 周边

c.js注入如何解决

0
悬赏园豆:100 [已关闭问题]

大家好,最近公司网站频繁被注入http://3b3.org/c.js,根本原因应该是是程序直接构造sql语句造成的漏洞,但是站点太多修改需要一定的时间,现在需要采取过渡的防注入方法(总不能把站点都关掉),写了个httpmodule过滤所有的get post数据,可是还是不行,请大家支支招啊,感激不尽!

简单不简单的主页 简单不简单 | 初学一级 | 园豆:0
提问于:2009-03-18 08:41
< >
分享
其他回答(6)
0

啊~~~~啊~~~~-_-!!!....

波波塔 | 园豆:638 (小虾三级) | 2009-03-18 08:57
0

我一个朋友的网站前一阵也出现挂c.js的挂马代码,他网站是找一个公司整的ASP程序,他向我求救,我做了一下处理,目前基本没问题了,所以我给你提供一些参考意见和建议(旧网站代码是ASP的,所以我帮他处理的也用ASP代码搞,呵呵,有点废话):

1、当然是用类似UPDATE dbo.tableName

SET fieldname = REPLACE(fieldname,'http://3b3.org/c.js', '') 把数据库里的已经注入的代码给整掉罗。当然可能不止http://3b3.org/c.js 这个,还有一些例如<script src=http://3b%6Fmb.com/c.js></script>;

2、就要从程序着手。我定义一个杀马sub,

 

Function KVRegJS(str)                '定义一个通过正则匹配来杀马函数

dim RegEx

Set RegEx = New RegExp 

RegEx.IgnoreCase =True 

RegEx.Global = True 

RegEx.Pattern = "<script src=('|""|)http(\S*).js('|""|)></script>" 

KVRegJS=RegEx.Replace(str,"") 

End Function

 

对文本型字段的输入输出,都调用这个sub(这样做对性能有所损失,当可以保证用户浏览时不会有挂马代码,即使数据库中有挂马代码也没关系),建议这个只作为临时应急措施使用,呵呵!

再定义个SQL防注的Sub

 

sub aspsql()'===================SQL防注

SQL_injdata = "cast|declare|0x4400|varchar|c.js|cn.js|and|exec|insert|select|set|(|)|
delete|update|count|chr|mid|master|truncate|char|declare"

SQL_inj = split(SQL_Injdata,"|")

If Request.QueryString<>"" Then

For Each SQL_Get In Request.QueryString

For SQL_Data=0 To Ubound(SQL_inj)

if instr(LCase(Request.QueryString(SQL_Get)),Sql_Inj(Sql_DATA))>0 Then

response.write "<script language='javascript'>"

response.write "alert('安全提示:请不要在参数中包含非法字符!');"

response.write "location.href='javascript:history.go(-1)';"

response.write "</script>"

response.end

end if

next

Next

end If

 

'===================Cookies防注入

If Request.Cookies<>"" Then

For Each XH_Cookie In Request.Cookies

For XH_Xh=0 To Ubound(SQL_inj)

If Instr(LCase(Request.Cookies(XH_Cookie)),SQL_inj(XH_Xh))<>0 Then

Request.Cookies(XH_Cookie)=""

response.write "<script language='javascript'>"

response.write "alert('安全提示:Cookie中含有恶意代码!');"

response.write "location.href='javascript:history.go(-1)';"

response.write "</script>"

response.end

End If

Next

Next

End If

end Sub

 

另外还定义一个IP黑名单过滤的Sub,因为通过分析IIS日志,发现这些IP有恶意攻击企图,当然也不一定是人为,可能是本身中毒

 

Sub denyIP()  '------------- IP黑名单

ipdata = "59.40.210.64|221.214.7.18|119.121.69.85|119.112.132.77|74.222.6.95|85.14.182.1|219.137.194.216|211.147.248.72|116.11.32.178|60.255.76.11
|219.146.103.91|211.95.72.184|218.108.10.70|218.75.49.242|121.14.148.30|221.231.138.90|59.42.254.95|124.16.151.178|121.28.255.234|
218.201.39.131|218.202.219.102|60.173.72.124|210.75.23.75|221.130.183.249|219.137.58.214|220.163.44.154|211.153.19.240|219.157.96.19|
219.157.96.20|219.157.96.21|219.157.96.22|219.157.96.18|61.151.239.174|220.200.170.137|125.208.21.12|220.181.68.133"

iparray = split(ipdata,"|")

clientIP=Request.ServerVariables("REMOTE_ADDR")

If clientIP<>"" Then

For ipindex=0 To Ubound(iparray)

If iparray(ipindex)=clientIP Then

response.write "<script language='javascript'>"

response.write "alert('安全提示:您的IP已经被列入黑名单!');"

response.write "location.href='javascript:history.go(-1)';"

response.write "</script>"

response.end

End If

Next

End If

End sub

 

这两个Sub都在

 

dim conn

set conn=server.createobject("ADODB.connection")

前调用

 

Call aspsql()

Call denyIP()

3、就是从IIS入手,不过如果服务器不是你的话这个就没操作性了。IIS主目录>配置,找到.asp的影射(当然你就是要找.aspx的影射了),将里面的中的HEAD操作与TRACE操作删除,只保留GET与POST,删除HEAD操作与TRACE操作不会影响正常的网站访问!

that's all,it's just for reference.

 

恩电 | 园豆:205 (菜鸟二级) | 2009-03-18 09:16
0

SQL注入漏洞,还是改程序吧。

小龙3 | 园豆:4 (初学一级) | 2009-03-18 09:17
0

2楼的注意不错!顶!!!

子夜星辰 | 园豆:1613 (小虾三级) | 2009-03-18 09:45
0

参数化查询才是治本的最终方法

四眼蒙面侠 | 园豆:504 (小虾三级) | 2009-03-18 10:24
0

二楼的能搞定on开头的脚本事件吗?

再给你一些正则:

            Regex regex1 = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase);//过滤<script></script>标记
            Regex regex2 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase);//过滤href=javascript: (<A>) 属性
            Regex regex3 = new Regex(@" on[\s\S]*=", RegexOptions.IgnoreCase); //过滤其它控件的on事件
            Regex regex4 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase);//过滤iframe
            Regex regex5 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase);//过滤frameset

风海迷沙 | 园豆:4453 (老鸟四级) | 2009-03-18 11:50
0

还要过滤cookies,通过伪造cookies来注入的

漂泊的小强 | 园豆:210 (菜鸟二级) | 2009-03-18 13:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册