这个题目其实这个已经在《信安之路》发过
https://mp.weixin.qq.com/s/UDgBYTeQqjpqK0D1CFThMA
在这里发主要是看看大家对catflag程序还有没有其他需要改善的地方,还有顺便说说怎么用这个项目(欢迎star和在线上赛使用),项目地址:
https://github.com/giantbranch/pwn_deploy_chroot
pwn_deploy_chroot介绍
特点
- 一次可以部署多个题目到一个docker容器中
- 自动生成flag,并备份到当前目录
- 也是基于xinted + docker + chroot
- 利用python脚本根据pwn的文件名自动化地生成3个文件:pwn.xinetd,Dockerfile和docker-compose.yml
- 在/bin目录,利用自己编写的静态编译的catflag程序作为/bin/sh,这样的话,system("/bin/sh")实际执行的只是读取flag文件的内容,完全不给搅屎棍任何操作的余地
- 默认从10000端口监听,多一个程序就+1,起始的监听端口可以在config.py配置,或者生成pwn.xinetd和docker-compose.yml后自己修改这两个文件
环境配置
# 安装docker
curl -s https://get.docker.com/ | sh
# 安装 docker compose 和git
apt install docker-compose git
# 下载
git clone https://github.com/giantbranch/pwn_deploy_chroot.git
使用
只需要3步:
- 将所有pwn题目放入bin目录,可以1个,也可以n个(注意名字不带特殊字符,因为会将文件名作为linux用户名)
- python initialize.py
- docker-compose up --build -d
讨论
catflag程序的源码如下:(编译后会作为/bin/sh程序)
//gcc -static -o catflag catflag.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>
void printflag(){
FILE *fp = NULL;
char buff[255];
fp = fopen("/flag.txt", "r");
fgets(buff, 255, (FILE*)fp);
printf("%s\n", buff);
fclose(fp);
}
int main(int argc,char **argv)
{
int ch;
int flag = 0;
// if you call system you go into while, because the source of system call :
// execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
while((ch = getopt(argc, argv, "c:")) != -1) {
flag = 1;
switch(ch) {
case 'c':
// printf("option c: %s\n", optarg);
if (!strcmp(optarg,"sh") || !strcmp(optarg,"/bin/sh"))
{
printflag();
}else{
printf("================================================\n\n");
printf("Only support this commands: sh, /bin/sh\n");
printf("So you must call system(\"sh\") or system(\"/bin/sh\")\n\n");
printf("================================================\n\n");
}
break;
case '?': // 输入未定义的选项, 都会将该选项的值变为 ?
default:
printf("Undefined parameter\n");
printf("Because I change /bin/sh,so if you get shell locally, please add issue on github: \nhttps://github.com/giantbranch/pwn_deploy_chroot\n\n");
}
}
// if you use one_gadget,argc will be 1
if (argc == 1)
{
printflag();
}else if (flag == 0)
{
printf("Because I change /bin/sh,so if you use one_gadget or other technique to get shell locally, please add issue on github: \nhttps://github.com/giantbranch/pwn_deploy_chroot\n\n");
}
return 0;
}
代码考虑了调用system,还有使用one_gadget的情况,而且使用system的时候,假如执行的不是sh,或者/bin/sh,则会输出相应的提示
system的话,我们可以看源码,实际执行的是
/bin/sh sh -c cmdstring
我们搜源码,可能搜到下面这样的,这可以说是简化版的
https://www.cnblogs.com/little-ant/archive/2011/07/26/2116872.html
int system(const char * cmdstring)
{
pid_t pid;
int status;
if(cmdstring == NULL)
{
return (1);
}
if ((pid = fork())<0)
{
status = -1;
}
else if (pid == 0)
{
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
_exit(127);
}
else
{
while(waitpid(pid, &status, 0) < 0)
{
if(errno != EINTR)
{
status = -1;
break;
}
}
}
return status;
}
你也可以看glibc源码
https://code.woboq.org/userspace/glibc/sysdeps/posix/system.c.html#137
假如大家有其他getshell方式,或者对catflag程序不足的地方,大家一起来完善啊~
假如大家有其他getshell方式,或者对catflag程序不足的地方,大家一起来完善啊~
假如大家有其他getshell方式,或者对catflag程序不足的地方,大家一起来完善啊~
[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法
最后于 2018-10-9 22:00
被giantbranch编辑
,原因: