当前位置: 首页 > news >正文

CTF: 在本地虚拟机内部署CTF题目docker

step 1 安装基本依赖

sudo apt-get update
sudo apt-get install -y \ca-certificates \curl \gnupg \lsb-release

step 2 安装docker

sudo apt-get remove docker docker.io containerd runc
sudo apt-get update
sudo apt-get install \apt-transport-https \ca-certificates \curl \gnupg \lsb-release \software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin

step 3 换源

sudo nano /etc/docker/daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://docker.unsee.tech" ] } EOF
sudo systemctl daemon-reload && sudo systemctl restart docker

step 4 测试

sudo docker run hello-world
a5rz@a5rz-virtual-machine ~/桌面% sudo docker run hello-world                                  
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:305243c734571da2d100c8c8b3c3167a098cab6049c9a5b066b6021a60fcb966
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/

step 5 拉取/构建题目镜像

方法一:从 Docker Hub 或其他镜像仓库拉取

如果您要试验的 CTF 题目已经有现成的 Docker 镜像,可以直接拉取:

sudo docker pull your_image_name

将 your_image_name 替换为实际的镜像名称,例如 ctfchallenge/web_challenge

方法二:使用 Dockerfile 构建镜像

如果您有题目的源码和 Dockerfile,需要自行构建镜像:

cd /path/to/your/ctf_challenge
sudo docker build -t your_image_name .
  • cd 命令切换到包含 Dockerfile 的目录。
  • -t your_image_name 为构建的镜像指定一个名称。

step 6 运行

使用以下命令运行容器:

sudo docker run -d -p HostPort:ContainerPort --name ContainerName your_image_name
  • -d:后台运行容器(守护态)。
  • -p HostPort:ContainerPort:将宿主机端口映射到容器端口。
  • --name ContainerName:为容器指定一个名称,方便管理。

示例:

如果您的题目在容器的 80 端口提供服务,您希望通过宿主机的 1337 端口访问:

sudo docker run -d -p 1337:80 --name ctf_challenge your_image_name

查看正在运行的容器:

sudo docker ps

查看所有容器(包括已停止的):

sudo docker ps -a

停止容器:

sudo docker stop ContainerName

启动已停止的容器:

sudo docker start ContainerName

删除容器:

sudo docker rm ContainerName

查看镜像列表:

sudo docker images

删除镜像:

sudo docker rmi your_image_name

step 7 进入容器获得shell

docker exec 命令允许在正在运行的容器中执行命令或启动交互式 Shell,从而直接对容器内部进行操作。

获取容器 ID 或名称

首先,您需要知道容器的名称或 ID,可以使用以下命令查看正在运行的容器:

sudo docker ps

您将看到类似以下的输出:

CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS          PORTS                  NAMES
abc123def456   your_image_name   "/bin/sh -c 'service…"   15 minutes ago   Up 15 minutes   0.0.0.0:1337->80/tcp   ctf_challenge

进入容器的交互式 Shell

使用 docker exec 命令进入容器的交互式终端:

sudo docker exec -it ContainerName /bin/bash

ContainerName 替换为您的容器名称或 ID,例如:

sudo docker exec -it ctf_challenge /bin/bash

在容器内操作文件

现在,您已经进入了容器内部,可以像操作普通 Linux 系统一样操作文件系统。例如:

cd /path/to/your/directory
ls -la

当您完成操作后,输入 exit 退出容器终端:

exit

使用 docker cp 复制文件

docker cp 命令允许在宿主机和容器之间复制文件或目录。

2.1 从宿主机复制文件到容器

语法:

sudo docker cp /宿主机/的文件/或目录 容器名称:/容器内的目标路径

示例:

sudo docker cp /home/user/flag.txt ctf_challenge:/app/flag.txt

将宿主机的 /home/user/flag.txt 复制到容器内的 /app/flag.txt

2.2 从容器复制文件到宿主机

语法:

sudo docker cp 容器名称:/容器内的文件/或目录 /宿主机/的目标路径

示例:

sudo docker cp ctf_challenge:/app/logs /home/user/container_logs

将容器内的 /app/logs 目录复制到宿主机的 /home/user/container_logs

http://www.lryc.cn/news/502130.html

相关文章:

  • 视频推拉流EasyDSS无人机直播技术巡查焚烧、烟火情况
  • SpringBoot【十一】mybatis-plus实现多数据源配置,开箱即用!
  • 【嵌入式linux基础】关于linux文件多次的open
  • TPAMI 2023:When Object Detection Meets Knowledge Distillation: A Survey
  • 2024前端面试题(持续更新)
  • apache转nginx访问变成下载解决方法
  • 【iOS】OC高级编程 iOS多线程与内存管理阅读笔记——自动引用计数(三)
  • Oracle数据库使用dblink是时出现 ORA-12170:TNS:连接超时
  • OpenHarmony系统中实现Android虚拟化、模拟器相关的功能,包括桌面显示,详细解决方案
  • 决策曲线分析(DCA)中平均净阈值用于评价模型算法(R自定义函数)
  • 《经验分享 · 软考系统分析师》
  • 记录一下 js encodeURI和encodeURIComponent URL转码问题
  • 【C语言】二维前缀和/求子矩阵之和
  • SRS 服务器入门:实时流媒体传输的理想选择
  • 【ETCD】【源码阅读】configurePeerListeners() 函数解析
  • 1_ssrf总结
  • 深入解析 Redis
  • Visual Studio 2022发布UWP应用证书绑定失败
  • K8S对接ceph的RBD块存储
  • ragflow连不上ollama的解决方案
  • ACL与Prefix List(前缀列表)
  • OpenSSH和OpenSSL升级
  • 数据库继续学习
  • 车载以太网-UDPNM
  • 网页核心页面设计(第8章)
  • 在PowerShell下运行curl命令出现错误:Invoke-WebRequest : 无法处理参数,因为参数名称“u”具有二义性
  • 医疗花费预测——协方差矩阵和热力图
  • react antd tabs router 基础管理后台模版
  • 【数据结构——栈与队列】环形队列的基本运算(头歌实践教学平台习题)【合集】
  • 【数据结构——栈与队列】链栈的基本运算(头歌实践教学平台习题)【合集】