tpotce/docker/cowrie/Dockerfile

85 lines
2.4 KiB
Text
Raw Normal View History

2024-11-19 17:06:23 +00:00
FROM alpine:3.20
2019-10-21 20:59:36 +00:00
#
# Include dist
2022-03-05 00:50:47 +00:00
COPY dist/ /root/dist/
2019-10-21 20:59:36 +00:00
#
2024-09-11 10:42:17 +00:00
# Install packages
2024-12-05 20:12:18 +00:00
RUN apk --no-cache -U upgrade && \
apk --no-cache -U add \
bash \
build-base \
git \
gmp-dev \
libcap \
libffi-dev \
mpc1-dev \
mpfr-dev \
openssl \
openssl-dev \
py3-appdirs \
py3-asn1-modules \
py3-attrs \
py3-bcrypt \
py3-cryptography \
py3-dateutil \
py3-greenlet \
py3-mysqlclient \
py3-openssl \
py3-packaging \
py3-parsing \
py3-pip \
py3-service_identity \
py3-treq \
py3-twisted \
python3 \
python3-dev && \
2019-10-21 20:59:36 +00:00
#
# Setup user
addgroup -g 2000 cowrie && \
2018-05-04 16:29:55 +00:00
adduser -S -s /bin/ash -u 2000 -D -g 2000 cowrie && \
2019-10-21 20:59:36 +00:00
#
2019-02-26 13:07:07 +00:00
# Install cowrie
mkdir -p /home/cowrie && \
cd /home/cowrie && \
2024-03-12 16:37:23 +00:00
git clone https://github.com/cowrie/cowrie && \
2019-02-26 13:07:07 +00:00
cd cowrie && \
2024-11-22 12:48:55 +00:00
git checkout 49c7c4aac87603e0d2449501c300841a1f59fd0f && \
2019-02-26 13:07:07 +00:00
mkdir -p log && \
2022-03-12 14:27:34 +00:00
cp /root/dist/requirements.txt . && \
2024-11-29 15:47:57 +00:00
pip3 install --break-system-packages --upgrade --no-cache-dir pip && \
pip3 install --break-system-packages --no-cache-dir -r requirements.txt && \
2019-10-21 20:59:36 +00:00
#
2018-05-04 16:29:55 +00:00
# Setup configs
setcap cap_net_bind_service=+ep $(readlink -f $(type -P python3)) && \
cp /root/dist/cowrie.cfg /home/cowrie/cowrie/cowrie.cfg && \
chown cowrie:cowrie -R /home/cowrie/* /usr/lib/$(readlink -f $(type -P python3) | cut -f4 -d"/")/site-packages/twisted/plugins && \
2019-10-21 20:59:36 +00:00
#
2018-05-04 16:29:55 +00:00
# Start Cowrie once to prevent dropin.cache errors upon container start caused by read-only filesystem
2019-02-26 13:07:07 +00:00
su - cowrie -c "export PYTHONPATH=/home/cowrie/cowrie:/home/cowrie/cowrie/src && \
cd /home/cowrie/cowrie && \
/usr/bin/twistd --uid=2000 --gid=2000 -y cowrie.tac --pidfile cowrie.pid cowrie &" && \
2018-05-04 16:29:55 +00:00
sleep 10 && \
rm -rf /home/cowrie/cowrie/etc && \
2019-10-21 20:59:36 +00:00
#
# Clean up
2018-05-04 16:29:55 +00:00
apk del --purge build-base \
git \
gmp-dev \
libcap \
2018-03-30 21:47:59 +00:00
libffi-dev \
2018-05-04 16:29:55 +00:00
mpc1-dev \
mpfr-dev \
2019-02-26 13:07:07 +00:00
openssl-dev \
2019-10-21 20:59:36 +00:00
python3-dev \
py3-mysqlclient && \
2024-09-11 10:42:17 +00:00
rm -rf /root/* /tmp/* \
/var/cache/apk/* \
/home/cowrie/cowrie/cowrie.pid \
/home/cowrie/cowrie/.git
2019-10-21 20:59:36 +00:00
#
# Start cowrie
2019-02-26 13:07:07 +00:00
ENV PYTHONPATH /home/cowrie/cowrie:/home/cowrie/cowrie/src
WORKDIR /home/cowrie/cowrie
2018-03-30 21:47:59 +00:00
USER cowrie:cowrie
2018-05-04 16:29:55 +00:00
CMD ["/usr/bin/twistd", "--nodaemon", "-y", "cowrie.tac", "--pidfile", "/tmp/cowrie/cowrie.pid", "cowrie"]