十九、Shellcode应用实践 | 您所在的位置:网站首页 › dir-619l路由器密码 › 十九、Shellcode应用实践 |
首先,我们编写一个存在缓冲区溢出漏洞的程序,功能比较简单:从passwd文件中读取密码,如果密码为“adminpwd”即有权限执行系统命令“ls -l”列出当前目录,否则提示密码错误后直接退出。 源码vuln_system.c: #include #include #include #include void do_system(int code, char *cmd) { char buf[255]; system(cmd); } void A(char *content) { char buf[32]; strcpy(buf, content); printf("buf: %s\n", buf); if(0 == strcmp(buf, "adminpwd")) { do_system(0, "ls /"); } } void main(int argc, char **argv) { char buf[1024] = {0}; char ch; int count = 0; unsigned int fileLen = 0; struct stat fileData; FILE *fp; if (0 == stat("passwd", &fileData)) { fileLen = fileData.st_size; } else { return 1; } if ( (fp = fopen("passwd", "rb")) == NULL) { printf("Cannot open file passwd!\n"); exit(1); } ch = fgetc(fp); while( count |
CopyRight 2018-2019 实验室设备网 版权所有 |