-
Notifications
You must be signed in to change notification settings - Fork 606
/
weevely.py
executable file
·116 lines (92 loc) · 3.46 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
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
import glob
import os
import pprint
import sys
from core import generate
from core import messages
from core import modules
from core.argparsers import CliParser
from core.config import agent_templates_folder_path, obfuscators_templates_folder_path
from core.loggers import log, dlog
from core.sessions import SessionURL, SessionFile
from core.terminal import Terminal
from core.weexceptions import FatalException, ArgparseError
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)
if 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:
term = Terminal(session)
term.precmd(arguments.cmd)
term.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 = 'phar'
)
generateparser.add_argument(
'-agent', #The agent channel type
choices = agents_available,
default = 'obfpost_php'
)
parser.set_default_subparser('terminal')
try:
arguments = parser.parse_args()
except ArgparseError:
parser.exit()
try:
main(arguments)
except (KeyboardInterrupt, EOFError):
log.info('Exiting.')
except FatalException as e:
log.critical('Exiting: %s' % e)