Glastopf

brain-Z / 2024-01-26 / 原文

Glastopf

web应用蜜罐

github:https://github.com/mushorg/glastopf

这回整的是纯用docker起Glastopf,遇上不少麻烦

编写dockerfile

首先他原作者就有提供docker的安装方法和dockerfile,但是版本是U14,加上dockerfile安装时大大小小的网络问题不少,其中还涉及在dockerfile里的git clone操作,由于懂的都懂的原因,需要特殊设置proxy。

最终我选择根据他的dockerfile进行魔改,且镜像选择U16,php版本7.0

FROM

FROM ubuntu:16.04

这个没啥说的,拉取镜像,但是这镜像busybox缺斤少两的,功能不全

ENV

设置环境变量

ENV DEBIAN_FRONTEND=noninteractive

https://blog.csdn.net/oguro/article/details/102840215

DEBIAN_FRONTEND这个环境变量,告知操作系统应该从哪儿获得用户输入。如果设置为”noninteractive”,你就可以直接运行命令,而无需向用户请求输入(所有操作都是非交互式的)。这在运行apt-get命令的时候格外有用,因为它会不停的提示用户进行到了哪步并且需要不断确认。非交互模式会选择默认的选项并以最快的速度完成构建。请确保只在Dockerfile中调用的RUN命令中设置了该选项,而不是使用ENV命令进行全局的设置。因为ENV命令在整个容器运行过程中都会生效,所以当你通过BASH和容器进行交互时,如果进行了全局设置那就会出问题。

正确的做法 – 只为这个命令设置ENV变量
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3

错误地做法 – 为接下来的任何命令都设置ENV变量,包括正在运行地容器(偷懒)

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get install -y python3
我的示例如下:

FROM ubuntu:trusty
MAINTAINER mryqu
RUN
DEBIAN_FRONTEND=noninteractive apt-get update &&
DEBIAN_FRONTEND=noninteractive apt-get -y install wget curl &&
DEBIAN_FRONTEND=noninteractive apt-get -y autoremove &&
DEBIAN_FRONTEND=noninteractive apt-get clean

RUN

在docker build时期运行指令。相对的,CMD是在docker run时期运行的指令,且只会生效最后一个CMD

RUN sed -i "s/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \
    sed -i "s/http:\/\/security.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list
RUN apt-get update 

换源然后更新包列表,加速apt下载速度

RUN apt-get install -y python2.7 python-openssl python-gevent libevent-dev python2.7-dev build-essential make && \
    apt-get install -y python-chardet python-requests python-sqlalchemy python-lxml && \
    apt-get install -y python-beautifulsoup mongodb python-pip python-dev python-setuptools && \
    apt-get install -y g++ git php php-dev liblapack-dev gfortran libmysqlclient-dev && \
    apt-get install -y libxml2-dev libxslt-dev wget netcat xinetd && \
    python -m pip install --user --upgrade pip==20.3.4 && \
    pip install --upgrade distribute 

装Glastopf需要的各种前置,其中有不少奇怪问题,这个是最后总结出的,需要高版本pip才能正常升级distribute

如果提示无法安装php5php5-dev,则改用apt-get install -y g++ git php php-dev liblapack-dev gfortran libmysqlclient-dev,系统将自动安装php7php7-dev.

RUN mkdir gitrepositories && \
    git clone http://github.com/mushorg/BFR.git /gitrepositories/BFR 

git clone下前置BFR,装的时候发现缺东西,还要装libzip

libzip安装:https://blog.csdn.net/ichen820/article/details/119323081

wget失败原因:https://blog.csdn.net/enweitech/article/details/80847030

于是选择单独下载下来COPY进去

COPY ./libzip-1.2.0.tar.gz /gitrepositories/BFR/
RUN tar -zxvf /gitrepositories/BFR/libzip-1.2.0.tar.gz -C /gitrepositories/BFR && \
    cd /gitrepositories/BFR/libzip-1.2.0 && \
    ./configure && \
    make -j4 && make install 

这样装好后就要准备设置phpize了,执行这个指令需要WORKDIR下有config.m4,正好BFR里面就有一个,执行完产生configure文件,对应执行安装后

  • 根据下面可能的地址,分别找到php.ini文件和bfr.so文件的位置,将bfr.so添加到php.ini的build输出中:

    #此处是github上面提示的内容,根据不同情况分别使用下面的命令来编辑php.ini
    
    #Ubuntu 16.04 LTS
    vim /etc/php/5.6/cli/php.ini
    
    #Ubuntu 14.04 LTS with apache
    vim /etc/php5/apache2/php.ini
    
    #在php.ini中添加的语句为
    zend_extension = /usr/lib/php5/20090626+lfs/bfr.so
    

    而我的系统是Ubuntu16.04,安装的php版本为7.0,找到bfr.so位置后,使用如下命令来编辑:
    img

    vim /etc/php/7.0/cli/php.ini
    #添加的语句为
    zend_extension = /usr/lib/php/20151012/bfr.so
    
WORKDIR /gitrepositories/BFR
RUN phpize
WORKDIR /
RUN cd /gitrepositories/BFR && \
    ./configure --enable-bfr && \
    make && make install && \
    sed -i '$a zend_extension = /usr/lib/php/20151012/bfr.so' /etc/php/7.0/cli/php.ini && \


然后我发现glastopf怎么装都容易报错,最后发现pip install git+https://github.com/mushorg/glastopf.git没报错

	pip install git+https://github.com/mushorg/glastopf.git && \
    cat /etc/php/7.0/cli/php.ini && \
    mkdir myhoneypot 

然后就是把xinetd文件复制到对应的文件夹里,让端口启用了,最后启动glastopf服务

COPY ./ctf.xinetd /etc/xinetd.d/ctf
WORKDIR /myhoneypot
EXPOSE 80
CMD ["glastopf-runner"]

docker指令

docker build --rm --tag glastopf . --progress=plain

docker run -d -p "9999:80" glastopf   #内机80端口映射到外机9999端口

#--progress=plain这个是让每一步dockerfile详细显示

dockerfile:

FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
RUN sed -i "s/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \
    sed -i "s/http:\/\/security.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list
RUN apt-get update 


RUN useradd -m ctf
RUN mkdir -p /home/ctf



RUN apt-get install -y python2.7 python-openssl python-gevent libevent-dev python2.7-dev build-essential make && \
    apt-get install -y python-chardet python-requests python-sqlalchemy python-lxml && \
    apt-get install -y python-beautifulsoup mongodb python-pip python-dev python-setuptools && \
    python -m pip install --user --upgrade pip==20.3.4 && \
    apt-get install -y g++ git php php-dev liblapack-dev gfortran libmysqlclient-dev && \
    apt-get install -y libxml2-dev libxslt-dev wget netcat xinetd curl && \
    
    pip install --upgrade distribute 




RUN mkdir gitrepositories && \
    git clone http://github.com/mushorg/BFR.git /gitrepositories/BFR 

COPY ./libzip-1.2.0.tar.gz /gitrepositories/BFR/
RUN tar -zxvf /gitrepositories/BFR/libzip-1.2.0.tar.gz -C /gitrepositories/BFR && \
    cd /gitrepositories/BFR/libzip-1.2.0 && \
    ./configure && \
    make -j4 && make install 

WORKDIR /gitrepositories/BFR
#RUN cp /gitrepositories/BFR/config.m4 /
RUN phpize
WORKDIR /
RUN cd /gitrepositories/BFR && \
    ./configure --enable-bfr && \
    make && make install && \
    sed -i '$a zend_extension = /usr/lib/php/20151012/bfr.so' /etc/php/7.0/cli/php.ini && \

#RUN git clone https://github.com/mushorg/glastopf.git /gitrepositories/glastopf/

    pip install git+https://github.com/mushorg/glastopf.git && \
    cat /etc/php/7.0/cli/php.ini && \
    mkdir myhoneypot 


COPY ./ctf.xinetd /etc/xinetd.d/ctf
WORKDIR /myhoneypot
EXPOSE 80
CMD ["glastopf-runner"]

ctf.xinetd:

service ctf
{
    disable = no
    socket_type = stream
    protocol    = tcp
    wait        = no
    user        = root
    type        = UNLISTED
    port        = 80
    bind        = 0.0.0.0
    server      = /usr/sbin/chroot
    server_args = --userspec=1000:1000 /myhoneypot /bin/bash
    banner_fail = /etc/banner_fail

    # safety options
    per_source	  = 10 # the maximum instances of this service per source IP address
    rlimit_cpu	  = 60 # the maximum number of CPU seconds that the service may use
    rlimit_as     = 1024M # the Address Space resource limit for the service
    #access_times = 2:00-9:00 12:00-24:00

    Instances   = 20 #process limit
    per_source  = 5 #link ip limit

    #log warning die
    log_on_success  = PID HOST EXIT DURATION
    log_on_failure  = HOST ATTEMPT
    log_type =FILE /var/log/myservice.log 8388608 15728640

}

效果演示

image-20240126013957203