/
push.asm
67 lines (60 loc) · 1.87 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
64
65
66
67
<%
from pwnlib.util import packing
from pwnlib.shellcraft import thumb, registers
from pwnlib import constants
from pwnlib.context import context as ctx # Ugly hack, mako will not let it be called context
import re
%>
<%page args="value"/>
<%docstring>
Pushes a value onto the stack without using
null bytes or newline characters.
If src is a string, then we try to evaluate with `context.arch = 'thumb'` 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`.
Args:
value (int,str): The value or register to push
Example:
>>> print pwnlib.shellcraft.thumb.push('r0').rstrip()
push {r0}
>>> print pwnlib.shellcraft.thumb.push(0).rstrip()
/* push 0 */
eor r7, r7
push {r7}
>>> print pwnlib.shellcraft.thumb.push(1).rstrip()
/* push 1 */
mov r7, #1
push {r7}
>>> print pwnlib.shellcraft.thumb.push(256).rstrip()
/* push 256 */
mov r7, #0x100
push {r7}
>>> print pwnlib.shellcraft.thumb.push('SYS_execve').rstrip()
/* push 'SYS_execve' */
mov r7, #0xb
push {r7}
>>> with context.local(os = 'freebsd'):
... print pwnlib.shellcraft.thumb.push('SYS_execve').rstrip()
/* push 'SYS_execve' */
mov r7, #0x3b
push {r7}
</%docstring>
<%
value_orig = value
is_register = value in registers.arm
if not is_register and isinstance(value, (str, unicode)):
try:
with ctx.local(arch = 'thumb'):
value = constants.eval(value)
except (ValueError, AttributeError, NameError):
pass
%>
% if is_register:
push {${value}}
% elif isinstance(value, (int,long)):
/* push ${repr(value_orig)} */
${re.sub(r'^\s*/.*\n', '', thumb.pushstr(packing.pack(value), False), 1)}
% else:
push ${value}
% endif