dosyalar work around
keywords: aile_dosyalar
This was done in a midnight rush, I have *no idea* if it fucks up somewhere, so far it seems to have worked for me.
#/usr/bin/python
import sys
fd = open("/var/log/xferlog", "r");
def rmdosyalar (line, fd, i):
if(line.find("aile_dosyalar") != -1):
fd.seek(fd.tell() - len(line));
fd.seek(fd.tell() + line.find("src=http://75oal"));
fd.write(' ');
print "MODIFICADO: [%s]" % i;
#}
#}
def comment_aile_dosyalar(line, fd, i):
#
if(line.find("aile_dosyalar") != -1) and (line.find("script") != -1):
strippedLine = line[line.find("<script"):];
diff = len(line) - len(strippedLine);
strippedLine = strippedLine[:strippedLine.rfind("/script") + len("/script>")];
fd.seek(fd.tell() - (len(line) - diff));
fd.write(html_comment_start);
fd.seek(fd.tell() + len(strippedLine) - len(html_comment_start) - len(html_comment_end));
fd.write(html_comment_end);
print "MODIFICADO: [%s]" % i;
#break;
#}
#}
suspects = {};
html_comment_start = "<!-- ";
html_comment_end = " -->";
# Parser do xferlog
fileName = "";
line = fd.readline();
while( len(line) ):
l_holder = [];
line = line.split(" ");
for i in range( len(line) ):
if not len(line[i]):
l_holder.append(i);
for i in l_holder: del(line[i]); # ''
holder = line[8];
if fileName == holder:
#if(not holder.endswith("js")) and (not holder.endswith("php")) and (not holder.endswith("tpl")) and (not holder.endswith("html")) and (not holder.endswith("htm")):
#print "Suspect: %s" % holder;
#pass;
#print line;
suspects[holder] = 1;
fileName = holder;
line = fd.readline();
#
# Modifica os arquivos "infectados"
for i in suspects.keys():
try:
fd = open(i, "r+");
except IOError:
print "Erro no arquivo: [%s]" % i;
continue;
if( i.endswith("php") ):
line = fd.readline();
if(line.find("document.write") != -1) and (line.find("function_exists") != -1):
fd.seek(0);
fd.write("<?php //");
print "MODIFICADO: [%s]" % i;
#}
if(line.find("eval(base64_decode(") != -1):
fd.seek(0);
fd.write("<?php //");
print "MODIFICADO: [%s]" % i;
#}
#}
elif( i.endswith("tpl") ):
#print "TPL SUSPEITO: [%s]" % i;
line = fd.readline();
while(line):
comment_aile_dosyalar(line, fd, i);
if(line.find("function") != -1) and (line.find("replace") != -1) and (line.find("eval") != -1) and (line.find("unescape") != -1):
fd.seek(fd.tell() - len(line));
fd.write("//");
print "MODIFICADO: [%s]" % i;
#break;
#}
rmdosyalar(line, fd, i);
line = fd.readline();
#}
#}
elif( i.endswith("js") ):
#print "js SUSPEITO: [%s]" % i;
line = fd.readline();
while(line):
if(line.find("function") != -1) and (line.find("replace") != -1) and (line.find("eval") != -1) and (line.find("unescape") != -1):
fd.seek(fd.tell() - len(line));
fd.write("//");
print "MODIFICADO: [%s]" % i;
#break;
#}
#
elif(line.find("aile_dosyalar") != -1) and (line.find("script") != -1):
if(line.find("document.write") != -1):
fd.seek(fd.tell() - len(line));
fd.write("//");
print "MODIFICADO: [%s]" % i;
#}
#}
rmdosyalar(line, fd, i);
line = fd.readline();
#}
#}
elif( i.endswith("html") or i.endswith("htm") ):
#print "HTML SUSPEITO: [%s]" % i;
line = fd.readline();
while(line):
if(line.find("function") != -1) and (line.find("replace") != -1) and (line.find("eval") != -1) and (line.find("unescape") != -1):
fd.seek(fd.tell() - len(line));
fd.write("//");
print "MODIFICADO: [%s]" % i;
#break;
#}
comment_aile_dosyalar(line, fd, i);
rmdosyalar(line, fd, i);
line = fd.readline();
#}
#}
else:
print "Terminacao desconhecida: [%s]" % i;
#}
fd.close();
# END_for
sys.exit();
Labels: python

