Skip to content

Commit 68b2f0e

Browse files
authored
Change tcpdump rotate by time interval. (#4)
1 parent 7bee333 commit 68b2f0e

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ RUN chmod +x /etc/service/xinetd/run && chmod +x /etc/service/tcpdump/run
3434

3535
ADD ctf.xinetd.example /etc/xinetd.d/ctf
3636

37+
VOLUME /var/lib/tcpdump

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# ctf-xinetd
22
A docker image to hold pwn challenges in ctf war
33

4-
# Introduction
4+
## Introduction
55
This image contains xinetd to provide remote access services for pwn challenges, and also contains tcpdump to dump network traffics into pcap file.
66

7-
Notice: we use a modified xinetd version from our team to restrict syscalls called by xinetd services. ~~In order to use this feature, docker container must run with `--privileged` option.~~ No more `--privileged` needed now.
7+
Notice:
8+
1. we use a modified [xinetd](https://github.com/Asuri-Team/xinetd-kafel) version from our team to restrict syscalls called by xinetd services. ~~In order to use this feature, docker container must run with `--privileged` option.~~ No more `--privileged` needed now.
9+
2. This docker image will produce docker volume each you create container from it. Better specify one using `-v your_dump_volume:/var/lib/tcpdump`.
810

9-
10-
# Usage
11+
## Usage
1112
Please check Dockerfile.example
1213

13-
# Env Vars
14+
## Env Vars
1415
| Key | Default Value | Description |
1516
| --- | ------------- | ----------- |
1617
| TCPDUMP_ENABLE | (empty) | Whether enable tcpdump or not |
17-
| TCPDUMP_DIR | /var/lib/tcpdump | Directory to write dump files (name=capture.pcap) |
18-
| TCPDUMP_SPLIT_SIZE | 10m | Max size of single capture file |
18+
| TCPDUMP_DIR | /var/lib/tcpdump | Directory to write dump files (name=capture-$timestr.pcap) |
19+
| TCPDUMP_ROTATE_SEC | 600 | Rotate time interval of capture file |
1920
| CTF_PORT | 20000 | Port to capture traffic from |
2021

21-
# CAUTION!
22+
## CAUTION!
2223
1. Please DO NOT use your own start CMD or entrypoint for this docker image. If you really need to change it, please check [phusion/baseimage](https://github.com/phusion/baseimage-docker) for more details.
2324

README.zh-CN.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# ctf-xinetd
22
一个用于CTF线上赛运行PWN题目的Docker镜像
33

4-
# 简介
4+
## 简介
55
这个镜像中包括了运行PWN题目的xinetd服务和用于记录流量的tcpdump服务。
66

7-
注意: 我们使用了修改版的[xinetd](https://github.com/Asuri-Team/xinetd-kafel). 在这个版本的xinetd中,可以很方便的限制服务所可以调用的系统调用。
8-
~~为了使用这一功能,在开启docker容器的时候必须添加`--privileged`选项。~~ 现已无需`--privileged`选项。
7+
注意:
8+
1. 我们使用了修改版的[xinetd](https://github.com/Asuri-Team/xinetd-kafel). 在这个版本的xinetd中,可以很方便的限制服务所可以调用的系统调用。~~为了使用这一功能,在开启docker容器的时候必须添加`--privileged`选项。~~ 现已无需`--privileged`选项。
9+
2. 这个docker镜像将在每次创建容器的时候自动新建volume,并挂载到tcpdump路径。最好添加启动参数`-v your_dump_volume:/var/lib/tcpdump`手动指定一个docker volume。
910

10-
# 用法
11+
12+
## 用法
1113
查看Dockerfile.example了解更多
1214

13-
# 环境变量
15+
## 环境变量
1416
| Key | Default Value | Description |
1517
| --- | ------------- | ----------- |
1618
| TCPDUMP_ENABLE | (empty) | 是否启用tcpdump |
1719
| TCPDUMP_DIR | /var/lib/tcpdump | 记录流量的文件夹 (文件名=capture.pcap) |
18-
| TCPDUMP_SPLIT_SIZE | 10m | 流量文件的分割大小 |
20+
| TCPDUMP_ROTATE_SEC | 600 | 流量文件的分割时间间隔 (秒) |
1921
| CTF_PORT | 20000 | 记录流量的端口 |
2022

21-
# 注意!
23+
## 注意!
2224
1. 一定不要修改本image的ENTRYPOINT或CWD, 如果你确定你在做什么,请阅读 [phusion/baseimage](https://github.com/phusion/baseimage-docker) 的文档获取更多信息。
2325

tcpdump.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
if [ -z $TCPDUMP_ENABLE ]; then
44
echo "Set TCPDUMP_ENABLE to enable packet capture."
5+
sv stop tcpdump
56
sleep 1d
67
exit 0
78
fi
89

9-
if [ -z $TCPDUMP_DIR ]; then
10-
TCPDUMP_DIR=/var/lib/tcpdump
11-
fi
10+
TCPDUMP_DIR=/var/lib/tcpdump
1211

13-
if [ -z $TCPDUMP_SPLIT_SIZE ]; then
14-
TCPDUMP_SPLIT_SIZE=10m
12+
if [ -z $TCPDUMP_ROTATE_SEC ]; then
13+
TCPDUMP_ROTATE_SEC=600
1514
fi
1615

1716
if [ -z $CTF_PORT ]; then
1817
CTF_PORT=20000
1918
fi
2019

20+
TCPDUMP_FILENAME="capture-%F-%H-%M-%S.pcap"
21+
2122
mkdir -p $TCPDUMP_DIR
22-
echo "TCPDUMP: capture port: $CTF_PORT, split size: $TCPDUMP_SPLIT_SIZE"
23-
exec /usr/sbin/tcpdump -i eth0 port $CTF_PORT -w $TCPDUMP_DIR/capture.pcap -C $TCPDUMP_SPLIT_SIZE
23+
echo "TCPDUMP: capture port: $CTF_PORT, rotate interval: ${TCPDUMP_ROTATE_SEC}s, capture filename: capture-\$time.pcap"
24+
exec /usr/sbin/tcpdump -i eth0 port $CTF_PORT -U -w $TCPDUMP_DIR/$TCPDUMP_FILENAME -G $TCPDUMP_ROTATE_SEC
2425

2526

0 commit comments

Comments
 (0)