assembly - Using gas, how can I get the offset to a particular label? -
i'm using pwnlib
write small shellcode challenge. shellcode needs modify pass application filters. first wrote nasm, , did that:
sub edx, edx mov dl, 0x82 add al, do_mov_rdi_rax sub dword [rax], edx mov dh, 0x82 add al, do_syscall - do_mov_rdi_rax sub dword [rax], edx shr edi, 31 do_mov_rdi_rax: ; mov rsi, rax ; (with 0x82 added first byte pass validation) db 0xca, 0x89, 0xc6 sub eax, eax do_syscall: ; syscall ; (with 0x82 added both bytes pass validation) db 0x91, 0x87
pwnlib uses gas
, however, assembly code has conform syntax. besides obvious (//
instead of ;
, .byte
instead of db
), i'm stuck 1 last problem: while nasm
happily converted labels integers (for add al, do_mov_rdi_rax
, add al, do_syscall - do_mov_rdi_rax
), gas
keeps telling me can't represent addressing type bfd_reloc_8
, or (i somehow ended french version of gas
, sorry lacking error message).
how can address of labels integers? shellcode based @ address 0 (and gas told .org 0x0
).
what you're doing unusual , looks requires relocation mach-o object format used os x doesn't support. problem isn't you're trying use label integer, it's you're trying use label 8-bit integer. that's not useful in practice, , compiler never do.
if want add lower 8 bits of address of symbol (or difference between 2 symbols) lower 8 bits of rax you're going use label 32-bit integer first.
for example move 32-bit register first:
mov $do_mov_rdi_rax, %ecx add %cl, %al ... mov $(do_syscall - do_mov_rdi_rax), %ecx add %cl, %al
if don't have free register load memory:
add indirect_do_mov_rdi_rax, %al ... add indirect_difference, %al indirect_do_mov_rdi_rax: .long do_mov_rdi_rax indirect_difference: .long do_syscall - do_mov_rdi_rax
if didn't want using 8-bit arithmetic , want addition using 64-bits of address use 64-bit register rax instead:
add $do_mov_rdi_rax, %rax ... add $(do_syscall - do_mov_rdi_rax), %rax
Comments
Post a Comment