Hola.
Comparto con ustedes una aplicación para detectar y desarmar un exploit en archivos con formato PDF. 
Básicamente, tomé las aplicaciones pdfid y pdf-parser (que kalilinux tiene incorporadas por defecto) y automaticé el proceso de análisis y desconstrucción del objeto malware (exploit).
Agregué la función de obtener el hash del archivo analizado.
Añadí la creación de archivos .txt para hacer el dump de los reportes generados por las aplicaciones mencionadas líneas arriba sobre los cuales se lleva a cabo la búsqueda de strings que señalan objetos maliciosos.
Imagen
Imagen
Imagen
Imagen
Imagen
Imagen
Imagen
Imagen
Reportes:
Imagen
Imagen
Imagen
Imagen
Objeto exploit desarmado:
Imagen
Analizo el PDF sin el exploit:
Imagen
Imagen

Como se puede apreciar, el PDF quedó limpio.

Imagen

Source code:

Imagen
Imagen
Imagen
Imagen
Imagen
Source code:

Código: Seleccionar todo

import pyinputplus as pyip import sys import os import subprocess from colorama import init, Fore, Style import hashlib import webbrowser from tkinter import filedialog from datetime import datetime YELLOW = Fore.YELLOW RED = Fore.RED BLUE = Fore.BLUE GREEN = Fore.GREEN CYAN = Fore.CYAN Magenta = Fore.MAGENTA init() os.system('clear') #Defino tres funciones para no usar tanto print. def space(): print("") def pausa(): input('Presione una tecla para continuar') def resetcolor(): print(Style.RESET_ALL, end="") print(' - PDF exploit analyzer & deconstructor (for linux) -'+ Fore.BLUE +'[Indetectables.net]') space() resetcolor() space() ya = datetime.now() print(ya.strftime(BLUE+"%d/%m/%Y %H:%M:%S")) resetcolor() menu = """ Opciones: 1-Analizar archivo PDF 2-Deshabilitar object exploit (file result on directory execution) 3-Virustotal (manual send) 4.-Salir """ bucle= True while bucle == True: print(menu) respuesta = pyip.inputInt(prompt='Seleccione una opción: ') if respuesta == 1: filedialogo = filedialog.askopenfilename() commandFileA = subprocess.run(["pdfid", filedialogo], stdout=subprocess.PIPE) outFiledialogo = str(commandFileA.stdout, 'UTF-8') space() print('Análisis con pdfid:') space() print(outFiledialogo) pausa() print(Magenta) fanalizeda = open('Log_archivo analizado-con-PDFID-.txt', "w") fanalizeda.write(outFiledialogo) fanalizeda.close() print(CYAN + 'Log_archivo analizado-con-PDFID-.txt '+ BLUE + filedialogo + CYAN + ' fue guardado') print('en esta carpeta de ejecucíon.') resetcolor() space() print(" -****************-") print('Análisis con pdf-parser:') space() print(Magenta) commandFileB = subprocess.run(["pdf-parser", "-o", "10", filedialogo], stdout=subprocess.PIPE) outFileB = str(commandFileB.stdout, 'UTF-8') print(outFileB) fanalizedB = open('Log_archivo analizado-con-PDF-PARSER.txt', "w") fanalizedB.write(outFileB) fanalizedB.close() print(Fore.MAGENTA) print(CYAN + 'Log_archivo analizado-con-PDF-PARSER-.txt '+ BLUE + filedialogo + CYAN +' fue grabado') print('en esta carpeta de ejecución.') space() resetcolor() with open(filedialogo, "rb") as f: bytes = f.read() sys.redirect_stdout = hash_textFOrig = hashlib.sha256(bytes).hexdigest() print(Fore.YELLOW +'El hash del archivo ' + BLUE + filedialogo + CYAN+' es: ') print(YELLOW + hash_textFOrig) archivoHash = open("Hash_PDF_file.txt", "w") archivoHash.write('Hash del archivo ' + filedialogo+ ' es: ') archivoHash.write(sys.redirect_stdout) space() print(YELLOW +'El hash del archivo '+ BLUE + filedialogo + CYAN + ' fue grabado') print('en esta carpeta de ejecución.') resetcolor() space() space() # Buscar strings (exploit) en el txt generado. stringA = " /JS 1" stringB = " /JavaScript 1" stringC = " /Launch 1" with open('Log_archivo analizado-con-PDFID-.txt', 'r') as filedata: for line in filedata: if stringA in line: resetcolor() print('Resultado:') print(RED + 'Exploit detected_string_1') if stringB in line: resetcolor() print('Resultado:') print(RED + 'Exploit detected_string_2') if stringC in line: resetcolor() print('Resultado:') print(RED + 'Exploit detected_string_3') break else: resetcolor() print('Resultado:') print(GREEN + 'Exploit no found') space() #--------------------------------------------Opción 2 DISARMED EXPLOIT--------------------------------------------------- resetcolor() if respuesta == 2: space() filenameDisable = filedialog.askopenfilename() commandFDisable = subprocess.run(["pdfid", "-d", filenameDisable], stdout=subprocess.PIPE) outDisableEx = str(commandFDisable.stdout, 'UTF-8') print(outDisableEx) print(CYAN+'Archivo ' + BLUE+ filenameDisable + RED +' sin el objeto exploit' + CYAN + ' fue guardado en carpeta de ejecución') resetcolor() if respuesta == 3: webbrowser.open('https://www.virustotal.com/gui/home/upload') elif respuesta == 4: bucle = False 

Código fuente:


import pyinputplus as pyip
import sys 
import os
import subprocess 
from colorama import init, Fore, Style
import hashlib
import webbrowser
from tkinter import filedialog
from datetime import datetime

 YELLOW = Fore.YELLOW
 RED = Fore.RED
 BLUE = Fore.BLUE  
 GREEN = Fore.GREEN 
 CYAN = Fore.CYAN
 Magenta = Fore.MAGENTA

 init() 
 os.system('clear')

 #Defino tres funciones para no usar tanto print.

 def space():
 print("")

 def pausa():
 input('Presione una tecla para continuar')

 def resetcolor():
 print(Style.RESET_ALL, end="") 

 print(' - PDF exploit analyzer & deconstructor (for linux) -'+ Fore.BLUE +'[Indetectables.net]')
 space()
 resetcolor() 
 space()
 ya = datetime.now() print(ya.strftime(BLUE+"%d/%m/%Y %H:%M:%S"))
 resetcolor()

 menu = """ Opciones:
 1-Analizar archivo PDF
 2-Deshabilitar object exploit (file result on directory execution)
 3-Virustotal (manual send)
 4.-Salir 

""" bucle= True while bucle == True: print(menu) respuesta = pyip.inputInt(prompt='Seleccione una opción: ') 
if respuesta == 1: filedialogo = filedialog.askopenfilename()
 commandFileA = subprocess.run(["pdfid", filedialogo], stdout=subprocess.PIPE)
 outFiledialogo = str(commandFileA.stdout, 'UTF-8') 
space()
 print('Análisis con pdfid:')
 space()
 print(outFiledialogo)
 pausa() 
 print(Magenta)
 fanalizeda = open('Log_archivo analizado-con-PDFID-.txt', "w")
 fanalizeda.write(outFiledialogo) 
fanalizeda.close() print(CYAN + 'Log_archivo analizado-con-PDFID-.txt '+ BLUE + filedialogo + CYAN + ' fue guardado')
 print('en esta carpeta de ejecucíon.')
 resetcolor()
 space()
 print(" -****************-")
 print('Análisis con pdf-parser:')
 space()
 print(Magenta)
 commandFileB = subprocess.run(["pdf-parser", "-o", "10", filedialogo], stdout=subprocess.PIPE)
 outFileB = str(commandFileB.stdout, 'UTF-8')
 print(outFileB)
 fanalizedB = open('Log_archivo analizado-con-PDF-PARSER.txt', "w")
 fanalizedB.write(outFileB)
 fanalizedB.close()
 print(Fore.MAGENTA)
 print(CYAN + 'Log_archivo analizado-con-PDF-PARSER-.txt '+ BLUE + filedialogo + CYAN +' fue grabado')
 print('en esta carpeta de ejecución.')
 space()
 resetcolor()
 with open(filedialogo, "rb") as f:
 bytes = f.read()
 sys.redirect_stdout = hash_textFOrig = hashlib.sha256(bytes).hexdigest()
 print(Fore.YELLOW +'El hash del archivo ' + BLUE + filedialogo + CYAN+' es: ')
 print(YELLOW + hash_textFOrig) archivoHash = open("Hash_PDF_file.txt", "w")
 archivoHash.write('Hash del archivo ' + filedialogo+ ' es: ')
 archivoHash.write(sys.redirect_stdout)
 space()
 print(YELLOW +'El hash del archivo '+ BLUE + filedialogo + CYAN + ' fue grabado')
 print('en esta carpeta de ejecución.')
 resetcolor()
 space()
 space()
 # Buscar strings (exploit) en el txt generado.
 stringA = " /JS 1"
 stringB = " /JavaScript 1"
 stringC = " /Launch 1"
 with open('Log_archivo analizado-con-PDFID-.txt', 'r') as filedata:
 for line in filedata: if stringA in line:
 resetcolor()
 print('Resultado:')
 print(RED + 'Exploit detected_string_1')
 if stringB in line:
 resetcolor()
 print('Resultado:')
 print(RED + 'Exploit detected_string_2')
 if stringC in line:
 resetcolor()
 print('Resultado:')
 print(RED + 'Exploit detected_string_3')
 break
 else:
 resetcolor()
 print('Resultado:')
 print(GREEN + 'Exploit no found')
 space()
 #--------------------------------------------Opción 2 DISARMED EXPLOIT---------------------------------------------------
 resetcolor()
 if respuesta == 2:
 space()
 filenameDisable = filedialog.askopenfilename()
 commandFDisable = subprocess.run(["pdfid", "-d", filenameDisable], stdout=subprocess.PIPE)
 outDisableEx = str(commandFDisable.stdout, 'UTF-8')
 print(outDisableEx)
 print(CYAN+'Archivo ' + BLUE+ filenameDisable + RED +' sin el objeto exploit' + CYAN + ' fue guardado en carpeta de ejecución')
 resetcolor()
 if respuesta == 3: webbrowser.open('[Enlace externo eliminado para invitados]')
 elif respuesta == 4:
 bucle = False 
 
Imagen
Imagen
Responder

Volver a “Fuentes”