Thursday, October 15, 2009

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:

Thursday, June 11, 2009

#1005 - Can't create table (errno: 150)

http://www.verysimple.com/blog/2006/10/22/mysql-error-number-1005-cant-create-table-mydbsql-328_45frm-errno-150/

http://forums.mysql.com/read.php?22,19755,29094#msg-29094

MySQL should be renamed to MySaddisticLittleFucker, what a misleading error message...

Labels:

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

Keywords: "#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key", PHP My Admin, MySQL Primary Key, Primary Key Not auto increment.

When trying to create a table through PMA I got the following error:
"#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key".

MySQL Version: 5.0

It happened because I decided to use not the auto_increment(ed) column as the primary key.

"""
CREATE TABLE IF NOT EXISTS `table_name` (
`id` int(11) NOT NULL auto_increment,
`nome` varchar(255) NOT NULL,
`cod` int(11) NOT NULL,
`othercod` int(11) NOT NULL,
PRIMARY KEY(`nome`, `cod`, `othercod`),
FOREIGN KEY(cod) REFERENCES table_1(COD),
FOREIGN KEY(othercod) REFERENCES table_2(OTHERCOD)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
"""

Well, that doesn't work, so... off to Google I went.

After a while I came across the following result on Google: http://bugs.mysql.com/bug.php?id=35874

Oh crap... guess this part of the error message would make sense to me if I were a DBA "and it must be defined as a key" (or not... he).

So, the fixed query:

"""
CREATE TABLE IF NOT EXISTS `table_name` (
`id` int(11) NOT NULL auto_increment,
`nome` varchar(255) NOT NULL,
`cod` int(11) NOT NULL,
`othercod` int(11) NOT NULL,
KEY `table_id`(`id`), -- HERE --
PRIMARY KEY(`nome`, `cod`, `othercod`),
FOREIGN KEY(cod) REFERENCES table_1(COD),
FOREIGN KEY(othercod) REFERENCES table_2(OTHERCOD)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
"""

BTW, MySQL will make KEYs for the fields inserted on the PRIMARY KEY and will make then NOT NULL, so check if it applies to your usage case ;-)

P.S.:
"""
Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion. The size and sign of integer types must be the same. The length of string types need not be the same. For nonbinary (character) string columns, the character set and collation must be the same.
"""

Don't you just fucking love MySQL too?

Labels:

Sunday, May 24, 2009

"Gumblar" Work Around

Keywords: gumblar, gumblar.cn, virus FTP, trojan

Additional information:


Recently a friend's website got infected by this "gumblar", so I hacked the script below to work around the issue, DISCLAIMER: the code is not so clean :-P


#/usr/bin/python

import sys

fd = open("/var/log/xferlog", "r");

suspects = {};

# 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:
#print "Suspect: %s" % holder; print line;
suspects[holder] = 1;

fileName = holder;
line = fd.readline();

# Modifica os arquivos "infectados"
for i in suspects.keys():
#print i;

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(" print "MODIFICADO: [%s]" % i;

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;
else:
line = fd.readline();

elif( i.endswith("html") ):
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;
else:
line = fd.readline();
fd.close();
# END_for

sys.exit();


Labels:

Thursday, September 18, 2008

Thread pool mixin class for use with SocketServer.TCPServer - Now Killable :-D

Keywords: python, SocketServer, ThreadingMixIn, multi-thread, pool of threads, killable server

When working on a multi-thread project recently I liked the idea of changing SocketServer.ThreadingMixIn to reserve a pool of threads instead of instantiating a new one each time a request is received.

So i tweaked a bit the recipe on the link below, and posted it as a comment:

http://code.activestate.com/recipes/574454/

Labels:

Monday, May 05, 2008

M.A.D. Doctrine

Upon reading about Von Newman, you can't help but think that the world is a really fucked up place.

Von Newman was a genius, on the level of Einstein and others, and still was an avid defensor of military policy and actions, hell, the guy voted to choose where the atomic bomb should be deployed...

If a man who is a genius can't see the stupidity of this "mine dick is bigger than yours" mentality, a.k.a M.A.D, what can we expect of the average guy?

Maybe if actions/decisions on the government level (military, economic, ...) were made like they're made on the FLOSS/Open Source World, out on the open, they would be lesser shitty, for instance, taking a quote of a Wikipedia page (http://en.wikipedia.org/wiki/Deterrence_theory):

"""
The United States refused to obey this warning and pay the fine.
"""


There's no such thing as the "US made the decision", someone, at some hierarchy level made the decision, if, instead, the decision were publicised as:

"""
John Somethin made the shitty decision of not obeying some lousy Court, since he thinks he is a god, there are disposable soldiers to kill for nothing upon his decision and the rest of the world sucks anyway.
"""

Well, maybe things were a bit different by now.

Tuesday, January 08, 2008

Fedora 8

Keywords: ALC883, rt73, cce, ncl-c2h4, fedora 8, ralink, 0x6877, 0db0:6877 Micro Star International, uniwill,

Todas as acoes como root.

Para controlar o audio do falante embutido e do headphone separados:

No arquivo "/etc/modprobe.conf" adicione a linha:
- options snd-hda-intel model=laptop-eapd
No meu arquivo haviam outras linhas referentes a placa Intel de audio as comentei, exemplo: #options snd-hda-intel model=laptop-eacd



Para utilizar o wireless segui estes passos:
- http://ubuntuforums.org/showthread.php?t=400236
ou
- http://forums.fedoraforum.org/showpost.php?p=821656&postcount=1
Compilei usando os headers do kernel 2.6.23.1-42.fc8-i686; tive que efetuar o strip;

ToDo:
- Verificar como o Insigne utiliza o botao com o 'i' do lado do botao de (des)ligar o note;
- Verificar pra q serve o iwpriv, tem um .txt no tar do driver;

Ainda nao testei se com esse driver funciona WEP nem DHCP, configuro meu IP usando o script abaixo:

"""
#/usr/bin/python

import os

#os.system("modprobe rt73");
#IP configuado como fixo pro meu MAC no roteador
os.system("ifconfig wlan1 192.168.1.2");
#roteador
os.system("route add default gw 192.168.1.1")

"""

Labels: ,

Saturday, June 16, 2007

CCE NCL-C2H4 wireless no Fedora 7

Embora o Fedora 7 venha com o driver para a placa wireless ralink do NCL-C2H4 o arquivo rt73.bin está faltando:

Para efetuar os comandos abaixo descritos você precisará ter permissão de root.

Baixe o driver do projeto rt2x00:



Descompacte o arquivo:



Mude o diretório atual para dentro do diretório criado:




Mova o arquivo rt73.bin:



Reinsira o módulo:



Pronto. ;-)

Labels: ,