Linux汇编shellcode,从汇编生成shellcode的n种方法

第一种,添加asm代码到c中,然后gcc编译生成可执行代码,最后objdump:

void main() {

asm{

}

}

太麻烦,这里就不详细介绍了,基本上包含在第二种方法中

第二种,直接用NASM或者GAS生成elf文件,然后objdump:

nasm -f elf print.asm

ld -m elf_i386 -o print print.asm

as test.asm -o test.o

ld test.asm -o test

objdump生成shellcode:

objdump -d print2

grep “^ ”

cut -d$’\t’ -f 2

tr ‘\n’ ‘ ‘

sed -e ‘s/ *$//’

sed -e ‘s/ +/\x/g’

awk ‘{print “\x”$0}’

关于NASM和GAS的区别可以看:

https://www.ibm.com/developerworks/library/l-gas-nasm/

第三种,使用pwntools(https://github.com/Gallopsled/pwntools#readme)

example:

from pwn import *

code = """.global _start

_start:

jmp test1

test2:

pop ebx

mov al, 0xa

int 0x80

mov al, 0x1

xor ebx, ebx

int 0x80

test1:

call test2

.string "delfile" """

context(arch='x86', os='linux', endian='little', word_size=32)

shellcode = asm(code).encode('hex')

re = ''

while len(shellcode):

re += r'\x'+shellcode[:2]

shellcode = shellcode[2:]

print re

未完待补充

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值