Skip to content

Commit 029e6bf

Browse files
committed
1.5.4 minor quality changes
+ aliases now support bytearrays fix #7 + changed from ataka to general ad template + added cpad alias
1 parent 37a28aa commit 029e6bf

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,4 @@ Using gdbserver and gdb to index libraries can be very slow. Therefore an experi
157157
### Better Docker integration
158158

159159
- migrate away from ssh (attach from host) to get lower latency
160-
- additionally virtualize containers (Qemu) in order to change the used kernel.
161-
162-
### Qemu user
163-
164-
- add templates that make use of pwntools qemu-user integration
160+
- additionally virtualize containers (Qemu) in order to change the used kernel

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "vagd"
3-
version = "1.5.3"
3+
version = "1.5.4"
44
authors = [{ name = "0x6fe1be2" }]
55
description = "VirtuAlization GDb integrations in pwntools"
66
readme = "README.md"

src/vagd/cli.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
VAGD_BOX = "Box.VAGRANT_JAMMY64"
2626
VAGD = "vm = Vagd(BINARY, {box}, {args}) # Vagrant"
2727

28-
ATAKA_ENV = """# ataka envs
29-
ATAKA = os.getenv('TARGET_IP') is not None # running on ataka
28+
AD_ENV = """# ad envs
29+
IS_AD = os.getenv('TARGET_IP') is not None # running on ad
3030
IP = os.getenv('TARGET_IP', IP) # remote ip
3131
EXTRA = json.loads(os.getenv('TARGET_EXTRA', '[]')) # flag ids"""
3232

@@ -128,9 +128,7 @@ def template(
128128
vbox: Optional[str] = typer.Option(VAGD_BOX, "--vbox", help="vagrant box to use"),
129129
shgd: Optional[bool] = typer.Option(False, "--shgd", "--ssh", "-s", help="create ssh template"),
130130
local: Optional[bool] = typer.Option(False, "--local", help="create local template"),
131-
ataka: Optional[bool] = typer.Option(
132-
False, "--ataka", help="create an ataka compatible template"
133-
),
131+
ad: Optional[bool] = typer.Option(False, "--ad", help="create an ad compatible template"),
134132
root: Optional[bool] = typer.Option(False, "--root", "-r", help="create a root environment"),
135133
no_aliases: Optional[bool] = typer.Option(
136134
False, "--no-aliases", help="no aliases in the template"
@@ -185,7 +183,7 @@ def template(
185183
args["files"] = "[" + ",".join(f"'{file}'" for file in files) + "]"
186184

187185
modules = list()
188-
if ataka:
186+
if ad:
189187
modules.append("json")
190188

191189
args["ex"] = "True"
@@ -228,12 +226,12 @@ def template(
228226
ip=quote(ip),
229227
port=str(port),
230228
env=repr(env),
231-
ataka_env=ATAKA_ENV if ataka else "",
229+
ad_env=AD_ENV if ad else "",
232230
vms=("\n" + " " * 4).join(vms),
233231
libc=quote(libc),
234232
aslr=repr(aslr),
235233
is_local=True if local else "args.LOCAL",
236-
is_ataka=" or ATAKA" if ataka else "",
234+
is_ad=" or IS_AD" if ad else "",
237235
info=info,
238236
)
239237

src/vagd/res/aliases.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ linfo = lambda x, *a: log.info(x, *a)
77
lwarn = lambda x, *a: log.warn(x, *a)
88
lerr = lambda x, *a: log.error(x, *a)
99
lprog = lambda x, *a: log.progress(x, *a)
10+
lhex = lambda x, y="leak": linfo(f"0x{x:016x} <- {y}")
11+
phex = lambda x, y="leak": print(f"0x{x:016x} <- {y}")
1012

1113
# type manipulation
12-
byt = lambda x: x if isinstance(x, bytes) else f"{x}".encode()
13-
phex = lambda x, y="leak": print(f"0x{x:016x} <- {y}")
14-
lhex = lambda x, y="leak": linfo("0x%016x <- %s", x, y)
14+
byt = lambda x: x if isinstance(x, (bytes, bytearray)) else f"{x}".encode()
1515
rpad = lambda x, s=8, v=b"\0": x.ljust(s, v)
1616
lpad = lambda x, s=8, v=b"\0": x.rjust(s, v)
17-
hpad = lambda x, s=None: f"%0{((x.bit_length() // 8) + 1) * 2 if s is None else s}x" % x
17+
hpad = lambda x, s=0: f"%0{s if s else ((x.bit_length() // 8) + 1) * 2}x" % x
1818
upad = lambda x: u64(rpad(x))
19+
cpad = lambda x, s: byt(x) + cyc(s)[len(byt(x)):]
1920
tob = lambda x: bytes.fromhex(hpad(x))
2021

2122
# elf aliases

src/vagd/res/template.txt

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PORT = {port:<44s} # remote PORT
1111
BINARY = {binary:<44s} # PATH to local binary
1212
ARGS = [] # ARGS supplied to binary
1313
ENV = {env:<44s} # ENV supplied to binary
14-
{ataka_env}
14+
{ad_env}
1515
# GDB SCRIPT, executed at start of GDB session (e.g. set breakpoints here)
1616
GDB = f"""
1717
set follow-fork-mode parent
@@ -23,28 +23,29 @@ context.aslr = {aslr:<5s} # ASLR enabled (only
2323

2424
{aliases}
2525

26-
vm = None
2726
# setup vagd vm
28-
def setup():
27+
def setup() -> object | None:
2928
global vm
30-
if args.REMOTE or {is_local}{is_ataka}:
31-
return
29+
if args.REMOTE or {is_local}{is_ad}:
30+
return None
3231

3332
try:
3433
# only load vagd if needed
3534
from vagd import {dependencies}, Box
36-
except:
37-
log.error('Failed to import vagd, either run locally using LOCAL or install it')
35+
except ModuleNotFoundError:
36+
log.error('Failed to import vagd, run LOCAL/REMOTE or install it')
3837
if not vm:
3938
{vms}
4039
if vm.is_new:
4140
# additional setup here
4241
log.info('new vagd instance')
4342

43+
return vm
44+
4445

4546
# get target (pwnlib.tubes.tube)
4647
def get_target(**kw) -> tubes.tube:
47-
if args.REMOTE{is_ataka}:
48+
if args.REMOTE{is_ad}:
4849
# context.log_level = 'debug'
4950
return remote(IP, PORT)
5051

@@ -56,7 +57,7 @@ def get_target(**kw) -> tubes.tube:
5657
return vm.start(argv=ARGS, env=ENV, gdbscript=GDB, **kw)
5758

5859

59-
setup()
60+
vm = setup()
6061

6162
#===========================================================
6263
# EXPLOIT STARTS HERE

test/test.py

+15
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ def virts():
143143
vm._ssh.close()
144144

145145
os.system("vagd clean")
146+
sleep(1)
147+
stage("Testing Docker for Alpine (root)")
148+
vm = Dogd(
149+
exe.path,
150+
image=Box.DOCKER_ALPINE,
151+
user='root',
152+
tmp=True,
153+
ex=True,
154+
fast=True,
155+
)
156+
assert vm.is_new, "vm should be new"
157+
yield vm
158+
vm._ssh.close()
159+
160+
os.system("vagd clean")
146161

147162
stage("Testing Qemu")
148163
vm = Qegd(

0 commit comments

Comments
 (0)