Phân tích phần mềm độc hại Python

Nov 28 2022
Để phân tích phần mềm độc hại, mã thực hiện như sau: Thông tin băm được trích xuất. Kích thước tệp đang được in.
Ảnh của Michael Geiger trên Bapt

Để phân tích phần mềm độc hại, mã thực hiện như sau:

Thông tin băm được trích xuất.

Kích thước tệp đang được in.

Thông tin băm được kiểm tra trong Alienvault OTX.

Đầu ra chuỗi của tệp được in.

Phần lớn thông tin chứa trong tiêu đề tệp PE đều có thể truy cập được, cũng như các chi tiết và dữ liệu của tất cả các chương.

Đã thu được đầu ra của trình soạn thảo hex.

Để kiểm tra cách hoạt động của các công cụ trong phân tích phần mềm độc hại, bạn có thể xem lại mã bên dưới:

import pefile
from OTXv2 import OTXv2
import hashlib
import IndicatorTypes
import string
import binascii
import os
API_KEY = ""
filename=""
def hex_editor(filename):
    list_editor=""
    data_list=[]
    full_list=""
    counter=0
    try:
        with open(filename, "rb") as file:
            while 1:
                byte_s = file.read(1)
                data_bytes2ascii = binascii.b2a_hex(byte_s)
                list_editor+=str(data_bytes2ascii, 'UTF-8')+"\t"
                data_list.append(int(str(data_bytes2ascii, 'UTF-8'),16))
                full_list+= str(data_bytes2ascii, 'UTF-8') + " "
                if counter == 16:
                    print(list_editor)
                    print("\t".join(map(chr, data_list)))
                    counter=0
                    list_editor=""
                    data_list=[]
                    full_list+=str(data_bytes2ascii, 'UTF-8')+"\n"
                if not byte_s:
                    break
                counter+=1
    except:
        pass
    print("="*30)
    print(full_list)
def strings(filename, min=8):
    with open(filename, errors="ignore") as file:
        result = ""
        for character in file.read():
            if character in string.printable:
                result += character
                continue
            if len(result) >= min:
                yield result
            result = ""
        if len(result) >= min:
            yield result
size = os.path.getsize(filename)
print("File size:",size)
file=pefile.PE(filename)
print("File hashes:")
with open(filename, mode="rb") as File:
    hash_256 = hashlib.sha256(File.read()).hexdigest()
    hash_md5 = hashlib.md5(File.read()).hexdigest()
    hash_sha1 = hashlib.sha1(File.read()).hexdigest()
    print("MD5:",hash_md5)
    print("SAH-256",hash_256)
    print("SHA-1",hash_sha1)
print("Imphash:",file.get_imphash())
for dll in file.DIRECTORY_ENTRY_IMPORT:
    print(dll)
    for functions in dll.imports:
        print(functions.name)
print(file)
otx = OTXv2(API_KEY, server='https://otx.alienvault.com/')
result = otx.get_indicator_details_full(IndicatorTypes.FILE_HASH_MD5, hash_md5)
print("Alienvault Result:\n",result)
print("String Result:")
for string_line in strings(filename):
    print(string_line)
print("File Hex Editor:")
try:
    hex_editor(filename)
except:
    pass

https://twitter.com/anilyelken06
https://github.com/anil-yelken
https://anilyelken.medium.com/
https://medium.com/sibergvenlik

Từ Infosec Writeups: Rất nhiều thứ xuất hiện trong Infosec mỗi ngày mà thật khó để theo kịp. Tham gia bản tin hàng tuần của chúng tôi để nhận tất cả các xu hướng Infosec mới nhất dưới dạng 5 bài viết, 4 Chủ đề, 3 video, 2 Công cụ và Repos GitHub, cùng 1 thông báo việc làm MIỄN PHÍ!