首页
社区
课程
招聘
[原创]如何安全快速地部署多道ctf pwn比赛题目
2018-10-9 21:46 14122

[原创]如何安全快速地部署多道ctf pwn比赛题目

2018-10-9 21:46
14122

这个题目其实这个已经在《信安之路》发过

 

https://mp.weixin.qq.com/s/UDgBYTeQqjpqK0D1CFThMA

 

在这里发主要是看看大家对catflag程序还有没有其他需要改善的地方,还有顺便说说怎么用这个项目(欢迎star和在线上赛使用),项目地址:

 

https://github.com/giantbranch/pwn_deploy_chroot

pwn_deploy_chroot介绍

特点

  1. 一次可以部署多个题目到一个docker容器中
  2. 自动生成flag,并备份到当前目录
  3. 也是基于xinted + docker + chroot
  4. 利用python脚本根据pwn的文件名自动化地生成3个文件:pwn.xinetd,Dockerfile和docker-compose.yml
  5. 在/bin目录,利用自己编写的静态编译的catflag程序作为/bin/sh,这样的话,system("/bin/sh")实际执行的只是读取flag文件的内容,完全不给搅屎棍任何操作的余地
  6. 默认从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步:

  1. 将所有pwn题目放入bin目录,可以1个,也可以n个(注意名字不带特殊字符,因为会将文件名作为linux用户名)
  2. python initialize.py
  3. 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编辑 ,原因:
收藏
点赞1
打赏
分享
最新回复 (5)
雪    币: 210
活跃值: (155)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Art1cuno 2018-10-14 20:18
2
0
你好,部署时出现如下问题:
ERROR: for pwn_deploy_chroot  Cannot start service pwn_deploy_chroot: driver failed programming external connectivity on endpoint pwn_deploy_chroot (75294936683ca1185f919a571a57a3afc930cb61cadc6752cb00cc40290ea436): Error starting userland proxy: listen tcp 0.0.0.0:10002: bind: address already in use
ERROR: Encountered errors while bringing up the project.

请问如何解决

解决了,但是将system转换成cat flag,我远程跑exp一直失败,未部署之前是好的
最后于 2018-10-14 20:24 被Art1cuno编辑 ,原因:
雪    币: 413
活跃值: (274)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
giantbranch 2018-10-15 20:04
3
0
dqy行者 你好,部署时出现如下问题:ERROR:&nbsp;for&nbsp;pwn_deploy_chroot&nbsp;&nbsp;Cannot&nbsp;start ...
你好,贴下你的exp,还有截图吧,谢谢
雪    币: 1433
活跃值: (380)
能力值: ( LV3,RANK:34 )
在线值:
发帖
回帖
粉丝
勇士小蓝 2018-10-20 15:58
4
0
您好,部署时出现Temporary failure resolving,相关exp已经提issue(https://github.com/giantbranch/pwn_deploy_chroot/issues/1),请问如何解决?
雪    币: 413
活跃值: (274)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
giantbranch 2018-10-21 20:57
5
0
勇士小蓝 您好,部署时出现Temporary failure resolving,相关exp已经提issue(https://github.com/giantbranch/pwn_deploy_chroot/i ...
好滴,那边已回复
最后于 2018-10-21 20:59 被giantbranch编辑 ,原因:
雪    币: 32404
活跃值: (18830)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
kanxue 8 2020-4-12 10:41
6
0
pwn需要如下环境:
sudo apt-get install google-perftools
echo "LD_PRELOAD=/usr/lib/libtcmalloc.so.4" | tee -a /etc/environment

config.py里加上了:
RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && apt update   &&  apt-get install  -y google-perftools &&   echo "LD_PRELOAD=/usr/lib/libtcmalloc.so.4" | tee -a /etc/environment && 

python initialize.py
docker-compose up --build -d
docker创建加载成功。


远程连接这个pwn,仍会报错:

nc xxx.xxx.xxx.xxx   *** 


./XXXXX: error while loading shared libraries: libtcmalloc.so.4: cannot open shared object file: No such file or directory


后来,config.py时又加上如下环境,还是加载成功,但pwn还是出错:
apt-get install libprotobuf-dev 
apt-get install libtcmalloc-minimal4 
apt-get install libgoogle-perftools-dev 

希望知道的给个思路,谢谢!
最后于 2020-4-12 11:13 被kanxue编辑 ,原因:
游客
登录 | 注册 方可回帖
返回