Bueno, esta semana podría decirse que me la tome de descanso y tube un rato para poder escribir algún script que no tenga que ver con ninguna de los proyectos que tengo activos y coincidio que revisando udtools me tome con un post de FQV en el que posteaba un programa que buscaba el hash de tu archivo en virustotal para comprobar si alguien lo habia subido o no y tambien buscaba los hash de los procesos activos en tu winbug para comprobar si tenias algún ejecutable previamente subido en VT ejecutandose en tu máquina.
Como era de esperar , el source no estaba y como sentí curiosidad por la Public API de VT me decidí a hacer ambos scripts y que ideas como estas puedan prosperar tomando una base y no perder el tiempo codeando todo desde 0.
PD: Iva a esperar a hacer otro script más para publicar los 3 pero surgierón imprevistos y debo volver al "trabajo" así que solamente subo el file checker y el process checker.
VT File Checker :
# -*- coding: utf-8 *-*
#It's a simple script to search the hash of the file in VirusTotal
#and check if your file has been uploaded to VT
#Sanko
import urllib, urllib2, hashlib, sys
import simplejson as json
class VT_File_Checker():
def __init__(self, apikey, sFileName):
self.apikey = apikey
self.sFileName = sFileName
self._ms_do()
def _ms_do(self):
try:
self.__hash_extractor()
self._report_check()
self.__DataShower()
except:
print "Error, extracting the hash of the file"
def _report_check(self):
url = "https://www.virustotal.com/vtapi/v2/file/report"
parameters = {"resource": self.md5.hexdigest(), "apikey": self.apikey}
data = urllib.urlencode(parameters)
try:
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
re_json = response.read()
except:
print "Error connecting with the VT Api"
sys.exit(0)
#Parsing Json Data returned...
self.report = json.loads(re_json)
re_scan = self.report["scans"]
for self.av in re_scan:
self.detections = re_scan[self.av]["detected"]
self.results = re_scan[self.av]["result"]
try:
self.__parser()
except:
print "Error showing the returned data"
sys.exit(0)
def __parser(self):
if self.detections == True:
print "%s : %s"%(self.av, self.results)
elif self.detections == False:
print "%s : Ok"%(self.av)
else:
print "ERROR Parsing the scan results"
def __DataShower(self):
show = """
Extra Data :
------------
Name : %s
Scan_id : %s
Scan_date : %s
Permalink : %s
--------------
Detections : %s/%s
"""
print show%(self.sFileName, self.report["scan_id"], self.report["scan_date"],
self.report["permalink"], self.report["positives"], self.report["total"])
def __hash_extractor(self):
#opening sFileName
sFile = open(self.sFileName, 'rb')
self.md5 = hashlib.md5()
while True:
data = sFile.read(8192)
if not data:
break
self.md5.update(data)
#self.sha1 = hashlib.sha1()
#self.sha256 = hashlib.sha256()
VT_File_Checker('Aqui la key api', 'aquituejecutable.exe')
Imágen(Working):
(http://i.imgur.com/Ih18o9f.png)
VT Process Checker :
# -*- coding: utf-8 *-*
#It's a simple script to search the hash of the active processes in VirusTotal
#and check if your active processes are uploaded in VT or not
#Sanko
import urllib, urllib2, hashlib, sys, wmi
import simplejson as json
class VT_Process_Checker():
def __init__(self, apikey, sFileName):
self.apikey = apikey
self.sFileName = sFileName
self._ms_do()
def _ms_do(self):
try:
self.__hash_extractor()
self._process_report()
self.__DataShower()
except:
pass
def _process_report(self):
url = "https://www.virustotal.com/vtapi/v2/file/report"
parameters = {"resource": self.md5.hexdigest(), "apikey": self.apikey}
data = urllib.urlencode(parameters)
try:
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
re_json = response.read()
except:
print "Error connecting with the VT Api"
sys.exit(0)
#Parsing Json Data returned...
self.report = json.loads(re_json)
def __DataShower(self):
data = """
---------------------
Name : %s
MD5 Hash : %s
Scan_date : %s
Detections : %s/%s
Permanent Link : %s
---------------------
"""
print data%(self.sFileName, self.report["md5"], self.report["scan_date"],
self.report["positives"], self.report["total"], self.report["permalink"])
def __hash_extractor(self):
#opening sFileName
sFile = open(self.sFileName, 'rb')
self.md5 = hashlib.md5()
while True:
data = sFile.read(8192)
if not data:
break
self.md5.update(data)
#self.sha1 = hashlib.sha1()
#self.sha256 = hashlib.sha256()
c = wmi.WMI()
for process in c.Win32_Process ():
if process.executablepath == None:
continue
#Into my virtual machine some process have None value
else:
try:
VT_Process_Checker('Aqui tu api', process.executablepath)
except:
continue
Imágen(Working):
(http://i.imgur.com/axrClBw.png)
Saludos ! :drinking:
Muy bueno brother, debería ser muy útil, menos mal no uso winbugs.
Sólo una cosa, no es necesario comparar en esta parte:
if self.detections == True:
Lo puedes dejar sólo con:
if self.detections:
Ya que self.detections sería true
Saludos!