Commit efce21bb authored by blackle's avatar blackle
Browse files

Add 32-bit version of packer

parent 0858d885
header_test-32: header-32 Makefile
lzma --format=lzma -9 --extreme --lzma1=preset=9,lc=1,lp=0,pb=0 --keep --stdout /bin/ls > ls.xz
cat header-32 ls.xz > header_test-32
chmod +x header_test-32
wc -c header_test-32
header-32 : header-32.asm Makefile
nasm -f bin -o header-32 header-32.asm -l header-32.list
chmod +x header-32
wc -c header-32
header_test: header Makefile
gzip -c /bin/ls > ls.gz
cat header ls.gz > header_test
lzma --format=lzma -9 --extreme --lzma1=preset=9,lc=1,lp=0,pb=0 --keep --stdout /bin/ls > ls.xz
cat header ls.xz > header_test
chmod +x header_test
wc -c header_test
......
; ==========================================
; ========= MACROS AND BOILERPLATE =========
; ==========================================
BITS 32
org 0x08048000
%include "syscalls-32.asm"
; ==============================
; ========= ELF HEADER =========
; ==============================
ehdr: ; Elf64_Ehdr
e_ident:
db 0x7F, "ELF", 1, 1, 1, 0
e_padding:
; times 8 db 0
mov ax, 356
mov ebx, esp
jmp e_shoff
e_type:
dw 2
e_machine:
dw 3
e_version:
dd 1
e_entry:
dd e_padding
e_phoff:
dd phdr - $$
e_shoff:
e_flags:
int 0x80
mov al, sys_fork
pop ebp
int 0x80
e_ehsize: ;begins halfway into jmp
jmp p_paddr
db 0
; dd 0
; dd 0
; dw ehdrsize
e_phentsize:
dw phdrsize
; e_phnum:
; dw 1
; e_shentsize:
; dw 0
; e_shnum:
; dw 0
; e_shstrndx:
; dw 0
ehdrsize equ $ - ehdr
; ==================================
; ========= PROGRAM HEADER =========
; ==================================
phdr: ; Elf32_Phdr
p_type:
dd 1
p_offset:
dd 0
p_vaddr:
dd $$
p_paddr:
test eax, eax
jz _child
; dd $$
p_filesz:
jmp _parent
dw 0
; dd filesize
p_memsz:
jmp _parent+4
dw 0
; dd filesize
p_flags:
dd 5
p_align:
dd 0x1000
phdrsize equ $ - phdr
; ===========================
; ========= CODE!!! =========
; ===========================
_start:
; mov ax, 356
; mov ebx, esp
; int 0x80
; mov al, sys_fork
; pop ecx
; int 0x80
; test eax, eax
; jz _child
_parent:
xor ebx, ebx
mov ax, sys_waitid
mov si, 4
int 0x80
; gets pointer to __memfd from stack
mov ebx, __memfd
; get environ pointer from stack into rdx
; assume argc == 1
mov dl, 16+8
add edx, esp
; execve demo
mov eax, sys_execve
mov ecx, esp ;use our args as args
int 0x80
_child:
; open self
mov ebx, __self
mov al, sys_open ;open
int 0x80
;fd1
push eax
;seek
mov al, sys_lseek ;lseek
pop ebx
push ebx
mov cl, filesize
int 0x80
;dup2 demo->stdout
mov al, sys_dup2
dec ebx
mov cl, 1 ;1 = stdout
int 0x80
;dup2 self->stdin
mov al, sys_dup2
pop ebx
dec ecx ; 1 minus 1 equals zero!
int 0x80
;execve
mov al, sys_execve
; mov edi, __gzip
push 0
push __gzip
pop ebx
push ebx
; use our arguments
mov ecx, esp
; xor rdx, rdx ;empty environ
int 0x80
; ; ===========================
; ; ========= STRINGS =========
; ; ===========================
__gzip:
db '/usr/bin/xzcat',0,
__self:
db '/proc/self/exe',0
__memfd:
db '/dev/fd/3',0
filesize equ $ - $$
\ No newline at end of file
%define sys_restart_syscall 0
%define sys_exit 1
%define sys_fork 2
%define sys_read 3
%define sys_write 4
%define sys_open 5
%define sys_close 6
%define sys_waitpid 7
%define sys_creat 8
%define sys_link 9
%define sys_unlink 10
%define sys_execve 11
%define sys_chdir 12
%define sys_time 13
%define sys_mknod 14
%define sys_chmod 15
%define sys_lchown 16
%define sys_oldstat 18
%define sys_lseek 19
%define sys_getpid 20
%define sys_mount 21
%define sys_umount 22
%define sys_setuid 23
%define sys_getuid 24
%define sys_stime 25
%define sys_ptrace 26
%define sys_alarm 27
%define sys_oldfstat 28
%define sys_pause 29
%define sys_utime 30
%define sys_access 33
%define sys_nice 34
%define sys_sync 36
%define sys_kill 37
%define sys_rename 38
%define sys_mkdir 39
%define sys_rmdir 40
%define sys_dup 41
%define sys_pipe 42
%define sys_times 43
%define sys_brk 45
%define sys_setgid 46
%define sys_getgid 47
%define sys_signal 48
%define sys_geteuid 49
%define sys_getegid 50
%define sys_acct 51
%define sys_umount2 52
%define sys_ioctl 54
%define sys_fcntl 55
%define sys_setpgid 57
%define sys_umask 60
%define sys_chroot 61
%define sys_ustat 62
%define sys_dup2 63
%define sys_getppid 64
%define sys_getpgrp 65
%define sys_setsid 66
%define sys_sigaction 67
%define sys_sgetmask 68
%define sys_ssetmask 69
%define sys_setreuid 70
%define sys_setregid 71
%define sys_sigsuspend 72
%define sys_sigpending 73
%define sys_sethostname 74
%define sys_setrlimit 75
%define sys_getrlimit 76
%define sys_getrusage 77
%define sys_gettimeofday 78
%define sys_settimeofday 79
%define sys_getgroups 80
%define sys_setgroups 81
%define sys_symlink 83
%define sys_oldlstat 84
%define sys_readlink 85
%define sys_uselib 86
%define sys_swapon 87
%define sys_reboot 88
%define sys_readdir 89
%define sys_mmap 90
%define sys_munmap 91
%define sys_truncate 92
%define sys_ftruncate 93
%define sys_fchmod 94
%define sys_fchown 95
%define sys_getpriority 96
%define sys_setpriority 97
%define sys_statfs 99
%define sys_fstatfs 100
%define sys_socketcall 102
%define sys_syslog 103
%define sys_setitimer 104
%define sys_getitimer 105
%define sys_stat 106
%define sys_lstat 107
%define sys_fstat 108
%define sys_olduname 109
%define sys_vhangup 111
%define sys_wait4 114
%define sys_swapoff 115
%define sys_sysinfo 116
%define sys_ipc 117
%define sys_fsync 118
%define sys_sigreturn 119
%define sys_clone 120
%define sys_setdomainname 121
%define sys_uname 122
%define sys_cacheflush 123
%define sys_adjtimex 124
%define sys_mprotect 125
%define sys_sigprocmask 126
%define sys_init_module 128
%define sys_delete_module 129
%define sys_quotactl 131
%define sys_getpgid 132
%define sys_fchdir 133
%define sys_bdflush 134
%define sys_sysfs 135
%define sys_personality 136
%define sys_setfsuid 138
%define sys_setfsgid 139
%define sys__llseek 140
%define sys_getdents 141
%define sys__newselect 142
%define sys_memfd_create 356
%define sys_waitid 284
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment