Closed ghost closed 7 years ago
I know this does not support OpenBSD but I think it will work. I think it would be good to share the following information.
$ ./stub_openbsd_amd64
starting stub ...
[1] 71161 segmentation fault ./stub_openbsd_amd64
~/Downloads/midgetpack/build/src/stub
(gdb) > i fil
Symbols from
"/home/ucharfli/Downloads/midgetpack/build/src/stub/stub_openbsd_amd64".
Local exec file:
`/home/ucharfli/Downloads/midgetpack/build/src/stub/stub_openbsd_amd64', file type elf64-x86-64.
Entry point: 0x2a8
0x00000000000002a8 - 0x000000000000473e is .text
0x0000000000104740 - 0x0000000000104770 is .note.openbsd.ident
0x0000000000104770 - 0x00000000001047b0 is .hash
0x00000000001047b0 - 0x00000000001048b8 is .dynsym
0x00000000001048b8 - 0x00000000001048eb is .dynstr
0x00000000001048f0 - 0x0000000000104908 is .rela.dyn
0x0000000000104940 - 0x0000000000104da0 is .rodata
0x0000000000104da0 - 0x0000000000105540 is .eh_frame
0x0000000000205ef0 - 0x0000000000205fe0 is .dynamic
0x0000000000205fe0 - 0x0000000000206000 is .got
0x0000000000206000 - 0x0000000000206140 is .data
0x0000000000206140 - 0x0000000000206170 is .bss
(gdb) > r
Starting program:
/home/ucharfli/Downloads/midgetpack/build/src/stub/stub_openbsd_amd64
starting stub ...
Program received signal SIGSEGV, Segmentation fault.
0x0000064c4170447c in ?? ()
(gdb) > bt
#0 0x0000064c4170447c in ?? ()
#1 0x0000064c4170105d in ?? ()
#2 0x0000064c417002b8 in ?? () = file pack_amd64.s
#3 0x0000000000000000 in ?? ()
(gdb) > disas 0x0000064c4170447c,0x0000064c417044a7
Dump of assembler code from 0x64c4170447c to 0x64c417044a7:
=> 0x0000064c4170447c: mov BYTE PTR [rbp+rax*4+0x3],dl
0x0000064c41704480: shr ecx,0x8
0x0000064c41704483: mov BYTE PTR [rbp+rax*4+0x2],cl
0x0000064c41704487: mov ecx,edx
0x0000064c41704489: shr edx,0x18
0x0000064c4170448c: shr ecx,0x10
0x0000064c4170448f: mov BYTE PTR [rbp+rax*4+0x0],dl
0x0000064c41704493: mov BYTE PTR [rbp+rax*4+0x1],cl
0x0000064c41704497: inc rax
0x0000064c4170449a: cmp rax,0x8
0x0000064c4170449e: jne 0x64c41704477
0x0000064c417044a0: mov rdi,rbx
0x0000064c417044a3: mov ecx,0x1a
End of assembler dump.
(gdb) > disas 0x0000064c4170105d,0x0000064c417010a7
Dump of assembler code from 0x64c4170105d to 0x64c417010a7:
0x0000064c4170105d: mov edx,DWORD PTR [rip+0x204fbd] # 0x64c41906020
0x0000064c41701063: test edx,edx
0x0000064c41701065: je 0x64c41701078
0x0000064c41701067: mov rsi,QWORD PTR [rip+0x204faa] # 0x64c41906018
0x0000064c4170106e: mov edi,0x1
0x0000064c41701073: call 0x64c417002ed
0x0000064c41701078: xor eax,eax
0x0000064c4170107a: xor r13d,r13d
0x0000064c4170107d: call 0x64c41700c8b
0x0000064c41701082: movzx r14d,WORD PTR [rbp+0x38]
0x0000064c41701087: mov r15,QWORD PTR [rip+0x204f7a] # 0x64c41906008
0x0000064c4170108e: add r15,QWORD PTR [rbp+0x20]
0x0000064c41701092: imul r14,r14,0x38
0x0000064c41701096: lea r12,[r15+0x10]
0x0000064c4170109a: add r14,r12
0x0000064c4170109d: cmp r12,r14
0x0000064c417010a0: je 0x64c41701128
0x0000064c417010a6: cmp DWORD PTR [r12-0x10],0x1
End of assembler dump.
(gdb) > disas 0x0000064c417002b8,0x0000064c417002e7
Dump of assembler code from 0x64c417002b8 to 0x64c417002e7:
0x0000064c417002b8: pop rdi
0x0000064c417002b9: pop rsi
0x0000064c417002ba: pop rdx
0x0000064c417002bb: pop rcx
0x0000064c417002bc: pop rbx
0x0000064c417002bd: xor rbp,rbp
0x0000064c417002c0: push rax
0x0000064c417002c1: xor rax,rax
0x0000064c417002c4: ret
0x0000064c417002c5: rdtsc
0x0000064c417002c7: mov DWORD PTR [rdi],eax
0x0000064c417002c9: mov DWORD PTR [rdi+0x4],edx
0x0000064c417002cc: ret
0x0000064c417002cd: nop
0x0000064c417002ce: nop
0x0000064c417002cf: nop
0x0000064c417002d0: push r10
0x0000064c417002d2: mov r10,rcx
0x0000064c417002d5: mov rax,0x1dd
0x0000064c417002dc: syscall
0x0000064c417002de: pop r10
0x0000064c417002e0: ret
0x0000064c417002e1: syscall
0x0000064c417002e3: ret
0x0000064c417002e4: mov rax,0x49
$ file test test: data
Someone reported me a similar bug but was not allowed to share the sample. It's hard to say what is happening here. It's possible the text and data offsets aren't right.
Thank you for the answer, but I was inadequate.I think I have to work a bit more on this topic. Finally, you will be editing for OpenBSD?
you're welcome. Unfortunately I have little time to spend on midgetpack right now, but OpenBSD is an important enough platform that I should at least have a look. I have very little ELF experience with OpenBSD so I'm not sure how it would differ from FreeBSD. IMO the W^X will cause some troubles when mmaping rwx segments.
I understand. Thanks for everything.
Where is the problem? $ uname -a OpenBSD tested.com 6.1 GENERIC.MP#49 amd64
$ file test test: data