Script em Python - Verificando se um site está infectado
Dica publicada em Linux / Introdução
Script em Python - Verificando se um site está infectado
Script em Python para verificar se um determinado site está infectado com algum malware.
Para que o script funcione, são necessárias duas coisas:
Para usá-lo, basta salvar o script como alguma-coisa.py, e executá-lo com o comando:
# python alguma-coisa.py
O script vai carregar todas as URLs que houverem no arquivo TXT e consultar o SiteCheck da Sucuri.
Segue abaixo o código em Python:
Espero aproveitem.
E para quem quiser brincar, sinta-se à vontade para melhorar o script e usá-lo como quiser.
Código
Há vários meses atrás, fiz um script em Python que verificava se determinado site estava infectado com algum Malware. Como base para essa verificação, o script consulta uma ferramenta gratuita da Sucuri.net, que é o SiteCheck.Para que o script funcione, são necessárias duas coisas:
- Colocar o arquivo urls.txt no mesmo diretório onde estiver o script Python;
- E o beatifulsoup.py também, no mesmo local.
Para usá-lo, basta salvar o script como alguma-coisa.py, e executá-lo com o comando:
# python alguma-coisa.py
O script vai carregar todas as URLs que houverem no arquivo TXT e consultar o SiteCheck da Sucuri.
Segue abaixo o código em Python:
#Imports
import sys
import httplib
from BeautifulSoup import BeautifulSoup
USER_AGENT = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1"
PRAGMA = "no-cache"
ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
def blacklist(dat):
url = dat.replace("\n","")
print "[*] Checking blacklist Database -> ",url
type =None
status = "[*] "
host = "sitecheck.sucuri.net"
path = "/results/"
path +=url
data = ""
http = httplib.HTTP(host)
http.putrequest("GET", path)
http.putheader("Host", host)
http.putheader("User-Agent", USER_AGENT)
http.putheader("Accept", ACCEPT)
http.putheader("Accept-Encoding", "gzip, deflate")
http.putheader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
http.putheader("Connection", "keep-alive")
http.putheader("","\n")
http.putheader("","\n")
http.endheaders()
http.send(data)
errcode, errmsg, headers = http.getreply()
f = http.getfile()
html = f.read()
soup = BeautifulSoup(html)
tag = soup.findAll('b')
for item in tag:
if item.text != "Not Listed":
if item.text != "Listed.":
status += item.text
status += "\n"
status += "[*] "
print status
empty = open('urls.txt','r')
if empty.read() == "":
print "[*] No host found to test"
empty.close()
file_url = open('urls.txt','r')
line = file_url.readlines()
for url in line:
print "#######################################################"
print "## Verificando a URL ",url
print "#######################################################"
blacklist(str(url));
file_url.close()
import sys
import httplib
from BeautifulSoup import BeautifulSoup
USER_AGENT = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20100101 Firefox/6.0.1"
PRAGMA = "no-cache"
ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
def blacklist(dat):
url = dat.replace("\n","")
print "[*] Checking blacklist Database -> ",url
type =None
status = "[*] "
host = "sitecheck.sucuri.net"
path = "/results/"
path +=url
data = ""
http = httplib.HTTP(host)
http.putrequest("GET", path)
http.putheader("Host", host)
http.putheader("User-Agent", USER_AGENT)
http.putheader("Accept", ACCEPT)
http.putheader("Accept-Encoding", "gzip, deflate")
http.putheader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
http.putheader("Connection", "keep-alive")
http.putheader("","\n")
http.putheader("","\n")
http.endheaders()
http.send(data)
errcode, errmsg, headers = http.getreply()
f = http.getfile()
html = f.read()
soup = BeautifulSoup(html)
tag = soup.findAll('b')
for item in tag:
if item.text != "Not Listed":
if item.text != "Listed.":
status += item.text
status += "\n"
status += "[*] "
print status
empty = open('urls.txt','r')
if empty.read() == "":
print "[*] No host found to test"
empty.close()
file_url = open('urls.txt','r')
line = file_url.readlines()
for url in line:
print "#######################################################"
print "## Verificando a URL ",url
print "#######################################################"
blacklist(str(url));
file_url.close()
Espero aproveitem.
E para quem quiser brincar, sinta-se à vontade para melhorar o script e usá-lo como quiser.