forked from epinna/weevely3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weevely.py
executable file
·108 lines (85 loc) · 3.23 KB
/
weevely.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
from core.terminal import Terminal
from core.weexceptions import FatalException
from core.loggers import log, dlog
from core.sessions import SessionURL, SessionFile
from core.config import agent_templates_folder_path, obfuscators_templates_folder_path
from core import generate
from core import modules
from core import messages
from core.argparsers import CliParser
import pprint
import glob
import os
import sys
if sys.stdout.encoding is None:
print("Please set PYTHONIOENCODING=UTF-8 running 'export PYTHONIOENCODING=UTF-8' before starting Weevely.")
exit(1)
def main(arguments):
if arguments.command == 'generate':
obfuscated = generate.generate(
password = arguments.password,
obfuscator = arguments.obfuscator,
agent = arguments.agent
)
generate.save_generated(obfuscated, arguments.path)
log.info(
messages.generate.generated_backdoor_with_password_s_in_s_size_i %
(arguments.path,
arguments.password, len(obfuscated))
)
return
elif arguments.command == 'terminal':
session = SessionURL(
url = arguments.url,
password = arguments.password
)
elif arguments.command == 'session':
session = SessionFile(arguments.path)
dlog.debug(
pprint.pformat(session)
)
modules.load_modules(session)
if not arguments.cmd:
Terminal(session).cmdloop()
else:
Terminal(session).onecmd(arguments.cmd)
if __name__ == '__main__':
parser = CliParser(prog='weevely')
subparsers = parser.add_subparsers(dest = 'command')
terminalparser = subparsers.add_parser('terminal', help='Run terminal or command on the target')
terminalparser.add_argument('url', help = 'The agent URL')
terminalparser.add_argument('password', help = 'The agent password')
terminalparser.add_argument('cmd', help = 'Command', nargs='?')
sessionparser = subparsers.add_parser('session', help='Recover an existing session')
sessionparser.add_argument('path', help = 'Session file path')
sessionparser.add_argument('cmd', help = 'Command', nargs='?')
agents_available = [
os.path.split(agent)[1].split('.')[0] for agent in
glob.glob('%s/*.tpl' % agent_templates_folder_path)
]
obfuscators_available = [
os.path.split(agent)[1].split('.')[0] for agent in
glob.glob('%s/*.tpl' % obfuscators_templates_folder_path)
]
generateparser = subparsers.add_parser('generate', help='Generate new agent')
generateparser.add_argument('password', help = 'Agent password')
generateparser.add_argument('path', help = 'Agent file path')
generateparser.add_argument(
'-obfuscator', #The obfuscation method
choices = obfuscators_available,
default = 'obfusc1_php'
)
generateparser.add_argument(
'-agent', #The agent channel type
choices = agents_available,
default = 'obfpost_php'
)
parser.set_default_subparser('terminal')
arguments = parser.parse_args()
try:
main(arguments)
except (KeyboardInterrupt, EOFError):
log.info('Exiting.')
except FatalException as e:
log.critical('Exiting: %s' % e)