-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e886f44
commit cca593c
Showing
20 changed files
with
248 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
FROM php:7.3-fpm-alpine | ||
|
||
# 制作者信息 | ||
LABEL auther_template="CTF-Archives" | ||
|
||
# 安装必要的软件包 | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \ | ||
apk add --update --no-cache tar nginx mysql mysql-client bash | ||
|
||
# 配置mysql | ||
RUN docker-php-source extract && \ | ||
docker-php-ext-install pdo_mysql mysqli && \ | ||
docker-php-source delete && \ | ||
mysql_install_db --user=mysql --datadir=/var/lib/mysql && \ | ||
sh -c 'mysqld_safe &' && \ | ||
sleep 5s && \ | ||
mysqladmin -uroot password 'root' | ||
|
||
# 复制nginx+mysql配置文件 | ||
COPY ./config/nginx.conf /etc/nginx/nginx.conf | ||
COPY ./config/docker-php-ext-mysqli.ini /usr/local/etc/php/conf.d | ||
COPY ./config/docker-php-ext-pdo_mysql.ini /usr/local/etc/php/conf.d | ||
|
||
# 复制web项目源码 | ||
COPY src /var/www/html | ||
|
||
# 重新设置源码路径的用户所有权 | ||
RUN chown -R www-data:www-data /var/www/html | ||
|
||
# 复制数据库配置文件 | ||
COPY ./data/db.sql /var/db.sql | ||
|
||
# 拷贝容器入口点脚本 | ||
COPY ./service/docker-entrypoint.sh /docker-entrypoint.sh | ||
RUN chmod +x /docker-entrypoint.sh | ||
|
||
# 配置数据库数据 | ||
RUN sh -c 'mysqld_safe &' \ | ||
&& sleep 5s \ | ||
&& mysqladmin -uroot password '123456' \ | ||
&& mysql -e "source /var/db.sql;" -uroot -p123456 | ||
|
||
# 设置shell的工作目录 | ||
WORKDIR /var/www/html | ||
|
||
# [可选]指定对外暴露端口,对于GZCTF等平台,强制EXPOSE可能会造成非预期端口泄露,请酌情启用 | ||
# EXPOSE 80 | ||
|
||
# 设置nginx日志保存目录 | ||
VOLUME ["/var/log/nginx"] | ||
|
||
# 设置容器入口点 | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# web-nginx-php73 | ||
|
||
部分容器逻辑参考自:[CTFTraining / base_image_nginx_php_73](https://github.com/CTFTraining/base_image_nginx_php_73),在此感谢 [陌竹 - mozhu1024](https://github.com/mozhu1024) 师傅和 [赵总 - glzjin](https://github.com/glzjin) 师傅做出的贡献 | ||
|
||
## 环境说明 | ||
|
||
提供 `Nginx` +`PHP 7.3.33`+`10.6.14-MariaDB` 的基础环境,默认暴露端口位于 80 | ||
|
||
### Base Image LNMP | ||
|
||
- L: Linux alpine | ||
- N: Nginx | ||
- M: MySQL | ||
- P: PHP 7.3 | ||
- PHP MySQL Ext | ||
- mysql | ||
- mysqli | ||
|
||
> 请注意 !!! | ||
> | ||
> 需要注意的是,模板默认会将 flag 保存在 数据库中,如果 需要改变flag在数据库中的存放位置,请在./service/docker-entrypoint.sh 中修改相关操作语句 | ||
## 如何使用 | ||
|
||
直接将 PHP 项目放入 `./src` 目录即可 | ||
|
||
源码放置进 `./src` 目录之后,执行 | ||
|
||
```shell | ||
docker build . | ||
``` | ||
|
||
即可开始编译镜像 | ||
|
||
也可以在安放好相关项目文件之后,直接使用 `./docker/docker-compose.yml` 内的 `docker-compose` 文件实现一键启动测试容器 | ||
|
||
```shell | ||
cd ./docker | ||
docker-compose up -d | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extension=mysqli.so | ||
mysqli.default_socket = /run/mysqld/mysqld.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extension=pdo_mysql.so | ||
pdo_mysql.default_socket = /run/mysqld/mysqld.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# daemon off; | ||
|
||
worker_processes auto; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
sendfile on; | ||
keepalive_timeout 65; | ||
|
||
server { | ||
listen 80; | ||
server_name localhost; | ||
root /var/www/html; | ||
index index.php index.html index.htm; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php?$args; | ||
} | ||
|
||
location ~ \.php$ { | ||
try_files $uri =404; | ||
fastcgi_pass 127.0.0.1:9000; | ||
fastcgi_index index.php; | ||
include fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3" | ||
services: | ||
web: | ||
build: ../ | ||
# image: test | ||
ports: | ||
- "8080:80" | ||
environment: | ||
- FLAG=flag{3a4cc347-8475-46cd-9f3e-64b393749fd2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
rm -f /docker-entrypoint.sh | ||
|
||
mysqld_safe & | ||
|
||
mysql_ready() { | ||
mysqladmin ping --socket=/run/mysqld/mysqld.sock --user=root --password=root > /dev/null 2>&1 | ||
} | ||
|
||
while !(mysql_ready) | ||
do | ||
echo "waiting for mysql ..." | ||
sleep 3 | ||
done | ||
|
||
# Check the environment variables for the flag and assign to INSERT_FLAG | ||
if [ "$DASFLAG" ]; then | ||
INSERT_FLAG="$DASFLAG" | ||
elif [ "$FLAG" ]; then | ||
INSERT_FLAG="$FLAG" | ||
elif [ "$GZCTF_FLAG" ]; then | ||
INSERT_FLAG="$GZCTF_FLAG" | ||
else | ||
INSERT_FLAG="flag{TEST_Dynamic_FLAG}" | ||
fi | ||
|
||
echo "Run:insert into flag values('flag','$INSERT_FLAG');" | ||
|
||
# 将FLAG写入文件 请根据需要修改 | ||
# echo $INSERT_FLAG | tee /home/$user/flag /flag | ||
|
||
# 将FLAG写入数据库 | ||
|
||
if [[ -z $FLAG_COLUMN ]]; then | ||
FLAG_COLUMN="flag" | ||
fi | ||
|
||
if [[ -z $FLAG_TABLE ]]; then | ||
FLAG_TABLE="flag" | ||
fi | ||
|
||
mysql -u root -p123456 -e " | ||
USE ctf; | ||
create table $FLAG_TABLE (id varchar(300),data varchar(300)); | ||
insert into $FLAG_TABLE values('$FLAG_COLUMN','$INSERT_FLAG'); | ||
" | ||
|
||
php-fpm & nginx & | ||
|
||
echo "Running..." | ||
|
||
tail -F /var/log/nginx/access.log /var/log/nginx/error.log |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
$sql = "SELECT username,password FROM users WHERE id = ".$_GET["id"]; | ||
$result = $conn->query($sql); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
if(isset($_REQUEST['cmd'])){ | ||
echo "<pre>"; | ||
$cmd = ($_REQUEST['cmd']); | ||
@eval($cmd); | ||
echo "</pre>"; | ||
die; | ||
} | ||
else{ | ||
show_source(__FILE__); | ||
phpinfo(); | ||
} | ||
|
||
?> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.