forked from moloch--/wire-transfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.py
executable file
·58 lines (47 loc) · 1.61 KB
/
embed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
@author: moloch
Copyright 2019
"""
import os
import sys
import logging
from english2bin import Binary2DictlessEnglish
from tornado.ioloop import IOLoop
from tornado.template import Template
from tornado.options import define, options
define("target",
group="application",
default=os.environ.get('WIRE_TRANSFER_TARGET', "shell.exe"),
help="target file to transfer")
define("output",
group="application",
default=os.environ.get('WIRE_TRANSFER_OUTPUT', "legit-embed.html"),
help="target file to transfer")
define("dictionary",
group="application",
default=os.environ.get('WIRE_TRANSFER_DICTIONARY', "dictionary.txt"),
help="encode file with dictionary")
define("template",
group="application",
default=os.environ.get('WIRE_TRANSFER_TEMPLATE', "templates/embed.html"),
help="encode file into embedable .html file")
def main():
""" Starts the app based on cli arguments """
encoder = Binary2DictlessEnglish(options.dictionary)
with open(options.target, "rb") as in_file:
data = encoder.encode_file(in_file)
with open(options.template) as templ_file:
templ = Template(templ_file.read())
with open(options.output, "wb") as out_file:
out_file.write(templ.generate(data=data))
if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.abspath(__file__)))
try:
options.parse_command_line()
assert os.path.exists(options.target)
assert os.path.exists(options.dictionary)
main()
except IOError as error:
print(str(error))
sys.exit()