首页 技术 正文
技术 2022年11月7日
0 收藏 692 点赞 824 浏览 2108 个字

有了shellcode,就可以进行攻击了,但是要有漏洞才行,真实世界中的漏洞很复杂,并且很难发现,因此我专门做一个漏洞来进行攻击。

具体来说就是做一个简单的tcp server,里面包含明显的栈溢出漏洞。

具体如下:

 /* server.c */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
void showClientInf(struct sockaddr_in client_addr) {
printf("\nThe IP of client is:%s",inet_ntoa(client_addr.sin_addr));
printf("\nThe Port of client is:%d\n",ntohs(client_addr.sin_port));
}
unsigned long get_sp(void)
{
__asm__("movl %esp,%eax");
}
void testf()
{
printf("ttttt\n");
} void recvastring(int new_fd)
{
unsigned char buff[];
int i=;
printf("sp=0x%x,addr=0x%x bytes.\n",get_sp(),&buff);
int numbytes = recv(new_fd,buff,,);
if(numbytes==-)
{
perror("recv");
exit();
}
}
int main() {
int sockfd,new_fd;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int flag=,len=sizeof(int);
int sin_size;
char buff[];
int numbytes;
printf("socket\n");
if((sockfd = socket(AF_INET,SOCK_STREAM,))==-) {
perror("socket");
exit();
}
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons();
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(my_addr.sin_zero),);
printf("bind\n");
if( setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, len) ==-)
{
perror("setsockopt");
exit();
}
if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-)
{
perror("bind");
exit();
}
printf("listen\n");
if(listen(sockfd,)==-) {
perror("listen");
exit();
}
printf("server is run...\n");
while() {
sin_size = sizeof(struct sockaddr_in);
printf("accept\n");
if((new_fd = accept(sockfd,(struct sockaddr *)
&their_addr,&sin_size))==-)
{
perror("accept");
exit();
}
showClientInf(their_addr);
if(!fork()) {
printf("recv\n");
recvastring(new_fd);
printf("close-new_fd 1\n");
close(new_fd);
exit();
}
printf("close-new_fd 2\n");
close(new_fd);
}
printf("close-sockfd\n");
close(sockfd);
}

这个核心就是我们关注的recvastring函数,包含明显的栈溢出漏洞。我们专门看一下:

 void recvastring(int new_fd)
{
unsigned char buff[];
int i=;
printf("sp=0x%x,addr=0x%x bytes.\n",get_sp(),&buff);
int numbytes = recv(new_fd,buff,,);
if(numbytes==-)
{
perror("recv");
exit();
}
}

同样编译生成:

bai@ubuntu:/mnt/hgfs/r/stack$ gcc -fno-stack-protector -z execstack -g -o server socketserver.c
bai@ubuntu:/mnt/hgfs/r/stack$ ./server
socket
bind
listen
server is run...
accept
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,918
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,444
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,255
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,069
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,701
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,741