Skip to content

Instantly share code, notes, and snippets.

@MilesQLi
Forked from islem-esi/detect_packer_cryptor.py
Created April 17, 2022 14:42
Show Gist options
  • Save MilesQLi/42fe2d4dbd01178b1768094c60a911a0 to your computer and use it in GitHub Desktop.
Save MilesQLi/42fe2d4dbd01178b1768094c60a911a0 to your computer and use it in GitHub Desktop.
yara rules applied
import yara
#Path to the folder containing downloaded files in the first part
rules_path = 'path/to/the/folder/containing/downloaded/rules'
#Read files
peid_rules = yara.compile(rules_path + 'peid.yar')
packer_rules = yara.compile(rules_path + 'packer.yar')
crypto_rules = yara.compile(rules_path + 'crypto.yar')
#Path to the exe file you want to analyze
exe_file_path = 'path/to/exe/file'
#Now we will try to find out if yara rules match with the exe
#file, if so that means that yara has detected a packer or a cryptor
#first we try to detect cryptors
try:
#the function match will return the list of detected cryptors
matches = crypto_rules.match(exe_file_path)
if matches:
print('Cryptors detected')
print(matches)
except:
#I always add this exception thing, because I don't know what could happen
print('cryptor exception, you must read yara docs')
#detect packers
try:
matches = packer_rules.match(exe_file_path)
if matches:
print('packers detected')
print(matches)
except:
print('packer exception, you must read yara docs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment