惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 超晨

jacob的使用方法 飞秋软件的OA消息接口服务器 c#关于数据库自定义类型在存储过程中返回服务器端的问题 vs2010 sp1在win2003不能安装的问题 jquery插件Uploadify使用中的注意事项 adsl拨号vpn后,adsl就不能用了 - 超晨 坑爹啊!!!win2003 x64企业版不支持tfs2010的源代码管理服务 - 超晨 mysql真是不错! - 超晨 gui设计禁忌2.0读书笔记 tfs2010中文版下载 - 超晨 iisExpress的设置 vs08+ie8开发遇到的问题 - 超晨 sql命令行添加一个登陆给某数据库,并给予指定角色(备忘) - 超晨 数据绑定到分页的快速开发最佳实践 SQL冗余字段的策略和管理 - 超晨 dataset绑定翻页和泛型+实体类绑定翻页的性能比较 - 超晨 Windows 远程桌面不能连接解决办法zt Python企业应用的优缺点(zt) - 超晨 python应用领域介绍 (zt)
消除数据库JS入侵的脚本
超晨 · 2009-11-23 · via 博客园 - 超晨

这几天接连被问到网站数据库被sql注入后很多字段被改加了js代码,网上查了一下,看来也是批处理写入的,那么只有用同样的办法来解决了

 上代码


代码

CREATE PROCEDURE spCheckJsInjection AS  
declare @t varchar(
555),@c varchar(555)   
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=35 or b.xtype=99 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(
'  
if exists (select * from ['+@t+']  where ['+@c+'] like ''%<script%'')  
    begin  
 update [
'+@t+'set ['+@c+']=left(cast(['+@c+'as varchar),CHARINDEX(''<script'', ['+@c+'])-1where ['+@c+'] like ''%<script%''  
    end  
' )  
fetch next from table_cursor into @t,@c  
end  
close table_cursor  
deallocate table_cursor;  

上面判断凡是<script打头的内容,其后面全部过滤掉,这样可以解决这个问题。但如果要彻底解决问题,我认为比较快的解决办法不是要求所有人去改程序,这个不现实,自己的东西还好说,别人的东西是不允许你随便改的。那么怎么办呢?比较完美快速的办法就是readonly账号和owner账号分开用,select操作一律用readonly,这样通过url参数传递的注入可以有效屏蔽。同样,对于sql注入这类问题,我觉得与其只是在程序上注意外,数据库权限账号的合理设置是必须的,这个防线可以解决很大的开发问题带来的影响。

 另外,经过上述设置后,哪些网站数据库运行了相当长的时间也没有出现这种问题了。据说以前是几分钟就被改写。这些做木马的人也是太可恶的,为了赚钱不择手段啊。几分钟的频率去注入别人的数据库,当别人不用这个网站啊,呵呵。