asm - shellcode中的打印问题?

查看:150
本文介绍了asm - shellcode中的打印问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

64位linux(ubuntu)
一个简单的汇编程序:test.asm (调用write打印"/bin/sh",然后退出):

global _start:
_start:
    jmp what
are:
    mov rbx,0x68732f6e69622fff
    shr rbx,0x8
    push rbx
    mov rsi,rsp
    mov dl,0x8
    xor rax,rax
    mov al,1
    syscall
    xor rax,rax
    mov al,0x3c
    syscall
what:
    call are

编译后运行是没问题的:

nasm -f elf64 test.asm
ld -o test test.o

但是提取shellcode后直接用c运行却没有打印,gdb进去看也是运行了shellcode,但是就是没有打印:

test.c :

 

unsigned char shellcode[] = "\x48\xbb\xff\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe6\xb2\x08\x48\x31\xc0\xb0\x01\x0f\x05\x48\x31\xc0\xb0\x3c\x0f\x05"

int main(){
    ( (void (*)(void))&shellcode )();
    return 0;
}

编译通过

gcc -fno-stack-protector -z execstack -o test2 test.c

运行就是没打印


gdb 调试截图

可以看到系统调用是成功的,并且调用exit是成功推出了,但是就是没打印

是不是shellcode中的标准输出流有问题?还是别的

解决方案

恩,问题找到了,是我智障了,汇编代码太多,只是把问题的一部分截取出来,看昏了,坐下来吃个布丁,看看就明白了。。。。

问题有两个,一个是rdi没致1(stdout),第二个是rdx没清空就赋值

所以应该是这样的:

global _start:
_start:
    jmp what
are:
    mov rbx,0x68732f6e69622fff
    shr rbx,0x8
    push rbx
    mov rsi,rsp
    xor rdx,rdx
    mov dl,0x8
    xor rdi,rdi
    mov dil,1
    xor rax,rax
    mov al,1
    syscall
    xor rax,rax
    mov al,0x3c
    syscall
what:
    call are

这里为了防止截断,rdi和rdx都是用的低位寄存器

shellcode应该是这样的:

somnus@somnus:~/Project/asm$ ./../shell/xer.sh test are what

\x48\xbb\xff\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe6\x48\x31\xd2\xb2\x08\x48\x31\xff\x40\xb7\x01\x48\x31\xc0\xb0\x01\x0f\x05\x48\x31\xc0\xb0\x3c\x0f\x05

是我智障了 =。=

这篇关于asm - shellcode中的打印问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆