-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmemexec-bash-32.nasm
More file actions
56 lines (48 loc) · 1.73 KB
/
memexec-bash-32.nasm
File metadata and controls
56 lines (48 loc) · 1.73 KB
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
global _start
section .text
_start:
; Create memory file (memfd_create)
push 0x00676765 ; "egg"
mov eax, 356 ; memfd_create syscall number (x86)
mov ebx, esp ; arg 1: name [egg]
xor ecx, ecx ; arg 2: 0 = no MFD_CLOEXEC
int 0x80
mov ebx, eax ; save the file descriptor of the memfd
; Open target file (open)
mov eax, 5 ; open syscall number (x86)
mov ebx, esp ; arg 1: name [egg]
xor ecx, ecx ; arg 2: 0 = O_RDONLY
int 0x80
mov ecx, eax ; save the file descriptor of the opened file
loop:
; Allocate buffer on the stack
sub esp, 0x400 ; allocate 1024 bytes on the stack for the buffer
; Read from target file (read)
mov eax, 3 ; read syscall number (x86)
mov ebx, ecx ; arg 1: FD [egg]
mov ecx, esp ; arg 2: buffer
mov edx, 0x400 ; arg 3: length
int 0x80
; Check for EOF
cmp eax, 0x00
jle done ; EOF
; Write to memory file (write)
mov edx, eax ; arg 3: length (from read())
mov eax, 4 ; write syscall number (x86)
mov ebx, ebx ; arg 1: FD [memfd]
int 0x80
jmp loop
done:
; Execute memory file (execveat)
mov eax, 357 ; execveat syscall number (x86)
mov ebx, ebx ; arg 1: memfd
push 0x00 ; an empty string
mov ecx, esp ; arg 2: path (empty string)
mov edx, esp ; arg 3: ARGV points to empty string
xor esi, esi ; arg 4: ENV
mov edi, 0x1000 ; arg 5: AT_EMPTY_PATH
int 0x80
; Exit program (exit)
mov eax, 1 ; exit syscall number (x86)
xor ebx, ebx ; exit status 0
int 0x80