Utils
encode(data)
Encode strings or integers into a raw byte format safely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | int | bytes
|
The payload to encode. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The sanitized byte array. |
Source code in src/pwninit/helpers/utils.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
getb(d, a, b)
Extract a substring between two delimiters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
bytes | str
|
The data to search in. |
required |
a
|
bytes | str
|
The start delimiter. |
required |
b
|
bytes | str
|
The end delimiter. |
required |
Returns:
| Type | Description |
|---|---|
bytes | str
|
bytes | str: The isolated substring. |
Example:
>>> getb(b"Here is the [secret] data", b"[", b"]")
b'secret'
Source code in src/pwninit/helpers/utils.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
getr(d, p)
Extract the first match of a regex pattern from the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
bytes | str
|
The data to search in. |
required |
p
|
str
|
The regex pattern. |
required |
Returns:
| Type | Description |
|---|---|
bytes | str
|
bytes | str: The first match of the pattern. |
Example:
>>> getr("Leak: 0x7ffff7e45000", r"0x[0-9a-f]+")
'0x7ffff7e45000'
Source code in src/pwninit/helpers/utils.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
hexdump(data, s=context.word_size // 8)
Print an aligned hexdump of the specified data payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The data to dump. |
required |
s
|
int
|
The size of each chunk in bytes (default: machine word size). |
word_size // 8
|
Source code in src/pwninit/helpers/utils.py
220 221 222 223 224 225 226 227 228 229 | |
jitspray(code, size=8, jmp=b'\xeb\x03')
Perform a jitspray with movabs on x64 by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Multi-line assembly code string. |
required |
size
|
int
|
Maximum code part size (default 8 for movabs). |
8
|
jmp
|
bytes
|
Stub for jumping between code parts. |
b'\xeb\x03'
|
Returns:
| Type | Description |
|---|---|
list[int]
|
list[int]: Array of packed integer values representing the spray. |
Source code in src/pwninit/helpers/utils.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
printx(**kwargs)
Print hex formatted values for debugging specified keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Key-value pairs to print. |
{}
|
Example:
>>> printx(libc_base=0x7ffff7e00000, heap=0x555555559000)
[+] libc_base: 0x7ffff7e00000
[+] heap: 0x555555559000
Source code in src/pwninit/helpers/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
ptr_cookie(mangled, demangled)
Compute the thread-local pointer guard cookie given a known pointer pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mangled
|
int
|
The protected value found in memory. |
required |
demangled
|
int
|
The expected/known original value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The underlying cookie guard value. |
Source code in src/pwninit/helpers/utils.py
276 277 278 279 280 281 282 283 284 285 286 | |
ptr_demangle(addr, cookie=0)
Demangle a pointer previously protected by a TLS pointer guard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
int
|
The mangled memory address. |
required |
cookie
|
int
|
The thread-local pointer guard cookie. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The resolved raw memory address. |
Source code in src/pwninit/helpers/utils.py
263 264 265 266 267 268 269 270 271 272 273 | |
ptr_mangle(addr, cookie=0)
Mangle a pointer (e.g., setjmp/longjmp or exit handlers) with a TLS cookie.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
int
|
The raw memory address. |
required |
cookie
|
int
|
The thread-local pointer guard cookie. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The heavily mangled value. |
Source code in src/pwninit/helpers/utils.py
250 251 252 253 254 255 256 257 258 259 260 | |
safelink(addr, ptr)
Compute the glibc >= 2.32 safelink value for a fastbin/tcache pointer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
int
|
The storage address of the pointer. |
required |
ptr
|
int
|
The actual target pointer value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The masked value to write to memory. |
Example:
>>> safelink(0x555555559010, 0x555555559050)
0x55555000c040
Source code in src/pwninit/helpers/utils.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
safelink_bf64(ptr)
Recover a safelinked next pointer assuming both next & addr are in the same page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ptr
|
int
|
The mangled/safelinked next value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The brute-forced original pointer. |
Source code in src/pwninit/helpers/utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
solve_hashcash(data)
Solve hashcash proof of work.
Source code in src/pwninit/helpers/utils.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
solve_hxp(data)
Solve hxp proof of work.
Source code in src/pwninit/helpers/utils.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
solve_kctf(data)
Solve kctf proof of work.
Source code in src/pwninit/helpers/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
solve_pow(data)
Take a buffer, detect the proof of work type, and solve it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The buffer containing the PoW challenge string. |
required |
Source code in src/pwninit/helpers/utils.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
solve_redpwn(data)
Solve redpwn proof of work.
Source code in src/pwninit/helpers/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
solve_sossette(data)
Solve sossette proof of work.
Source code in src/pwninit/helpers/utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
HouseOfMuney
Exploitation helper for the House of Muney technique.
This class facilitates dynamic symbol table (.dynsym) rewriting
to hijack function resolution in dynamically linked ELF binaries.
Source code in src/pwninit/helpers/muney.py
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 | |
__init__(elf)
Initialize the HouseOfMuney context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elf
|
ELF
|
The target ELF binary. |
required |
Source code in src/pwninit/helpers/muney.py
12 13 14 15 16 17 18 19 20 21 | |
get_sym(name)
Retrieve the raw symbol entry via the GNU hash table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes
|
The target symbol name. |
required |
Source code in src/pwninit/helpers/muney.py
46 47 48 49 50 51 52 | |
read(addr, size)
Read a chunk from the internal ELF payload memory representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
int
|
The starting address offset. |
required |
size
|
int
|
Amount of bytes to read. |
required |
Source code in src/pwninit/helpers/muney.py
110 111 112 113 114 115 116 117 | |
set_call(name, offset, data=b'sh\x00')
Hijack a symbol to act as a GNU indirect function (IFUNC) call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes
|
The symbol to hijack. |
required |
offset
|
int
|
The target execution offset. |
required |
data
|
bytes
|
Data to inject into the string table (default: |
b'sh\x00'
|
Source code in src/pwninit/helpers/muney.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
set_offset(name, offset)
Directly patch the virtual value offset of a specific symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes
|
The symbol to patch. |
required |
offset
|
int
|
The new offset value. |
required |
Source code in src/pwninit/helpers/muney.py
82 83 84 85 86 87 88 89 90 91 | |
set_sym(name, sym)
Overwrite an existing symbol entry in the ELF data payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes
|
The symbol name. |
required |
sym
|
str
|
The struct built entry to write back. |
required |
Source code in src/pwninit/helpers/muney.py
54 55 56 57 58 59 60 61 62 | |
strtab()
Get the offset to the string table.
Source code in src/pwninit/helpers/muney.py
23 24 25 | |
symbol_offset(name)
Locate the exact binary offset of a specific symbol inside .dynsym.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | bytes
|
The name of the symbol to find. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The absolute offset, or -1 if not found. |
Source code in src/pwninit/helpers/muney.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
write(addr, data)
Patch the internal ELF payload memory representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
int
|
The starting address offset. |
required |
data
|
bytes | str
|
The raw bytes to write. |
required |
Source code in src/pwninit/helpers/muney.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |