-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
push.asm
63 lines (57 loc) · 1.96 KB
/
push.asm
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
<%
from pwnlib import shellcraft
from pwnlib.util.packing import flat, unpack
from pwnlib.util.iters import group
%>
<%page args="value, register1='x14', register2='x15'"/>
<%docstring>
Pushes a value onto the stack without using null bytes or newline characters.
If src is a string, then we try to evaluate using :func:`pwnlib.constants.eval`
before determining how to push it.
Note that this means that this shellcode can change behavior depending on
the value of `context.os`.
Note:
AArch64 requires that the stack remain 16-byte aligned at all times,
so this alignment is preserved.
Args:
value(int,str): The value or register to push
register1(str): Scratch register to use
register2(str): Second scratch register to use
Example:
>>> print(pwnlib.shellcraft.push(0).rstrip())
/* push 0 */
mov x14, xzr
str x14, [sp, #-16]!
>>> print(pwnlib.shellcraft.push(9).rstrip())
/* push 9 */
mov x14, #9
str x14, [sp, #-16]!
>>> print(pwnlib.shellcraft.push(256).rstrip())
/* push 0x100 */
mov x14, #256
str x14, [sp, #-16]!
>>> print(pwnlib.shellcraft.push('SYS_execve').rstrip())
/* push SYS_execve (0xdd) */
mov x14, #221
str x14, [sp, #-16]!
>>> print(pwnlib.shellcraft.push('SYS_sendfile').rstrip())
/* push SYS_sendfile (0x47) */
mov x14, #71
str x14, [sp, #-16]!
>>> with context.local(os = 'freebsd'):
... print(pwnlib.shellcraft.push('SYS_execve').rstrip())
...
/* push SYS_execve (0x3b) */
mov x14, #59
str x14, [sp, #-16]!
</%docstring>
<%
if isinstance(value, str):
value = shellcraft.eval(value)
pretty = shellcraft.pretty(value, comment=False)
%>
${shellcraft.pushstr(flat(value),
append_null = False,
register1 = register1,
register2 = register2,
pretty = pretty)}