delta offset:
fpu_addr:
fnop
call GetPhAddr
sub ebp,fpu_addr
GetPhAddr:
sub esp,16
fnstenv [esp-12]
pop ebp
add esp,12
ret
[BITS 32]
global _start
_start:
fabs ;fabs指令
fnstenv [esp] ;保存环境,该结构偏移12字节处就是最后执行的浮点指令的运行时地址
pop edx
pop edx
pop edx
pop edx ;此处将fabs指令的运行时地址传给edx
sub dl, -25 ; offset from fabs -> xor buffer edx = edx + 25,25的大小指的是从shllcode到fabs的偏移
short_xor_beg:
xor ecx,ecx ;清零ecx
sub cx, -0x15F ;size of xor'd payload 设置ecx大小为0x15F
short_xor_xor:
xor byte [edx], 0x99 ; the byte to xor with ;开始循环解码
inc edx
loop short_xor_xor
shellcode:
db ...........................
global _start
_start:
jmp short getdata ; Get data pointer 跳转到getdata
begin:
pop ebx ; Pop the data address ;弹出codestart的地址,call begin时会压入eip地址
xor ecx,ecx ; Set up loop counter ;清零ecx
sub cx, -0x15F ; size of data payload ;设置ecx为0x15F
decode:
xor byte [ebx], 0x99 ; XOR ;开始循环解码
inc ebx ; Increment data address
loop decode ; Loop back to decode if cx > 0
jmp short codestart ; Jump into decoded code
getdata:
call begin ; Push the address of data in stack and jump
; to label begin
codestart: ; This is where the XOR'ed shellcode begins
db ..........................
;
; hello.asm -- simple non-optimized Linux/x86 shellcode
; Compile: nasm -f bin -o hello.s hello.asm
;
[BITS 32]
global _start
_start:
jmp short data ; Jump to our data section
begin:
mov eax, 4 ; syscall #4 = write()
mov ebx, 1 ; stdout
pop ecx ; Pop the data address in ecx
mov edx, 15 ; 15 bytes of data
int 0x80
mov eax, 1 ; syscall #1 = exit()
mov ebx, 0 ; status = 0
int 0x80
data:
call begin ; Call will return our data address
db "Hello, hacker!", 0x0a