This lab will show you how to pull a Docker image, and run a new container from that image.
-
First, pull the
hello-worldDocker image.You can interact with Docker on the command line using the
dockercommand.The
dockercommand has a number of sub-commands that you specify like so:docker <subcommand>.In this case, we're going to run the Docker pull sub-command which will download the
hello-worldimage from Docker Hub.docker pull hello-worldYou should see output similar to the following:
Using default tag: latest latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:6d60b42fdd5a0aa8a718b5f2eab139868bb4fa9a03c9fe1a59ed4946317c4318 Status: Downloaded newer image for hello-world:latest docker.io/library/hello-world:latestNow the
hello-worldimage is on your computer. In the next step, we'll actually run the application inside the image. -
Create a new container and run it.
To create a new container, we use the
docker runsub-command. Withdocker run, we'll also specify--rm.--rmtells Docker to delete the container after the program inside the container terminates. If--rmis left off, Docker will keep the container around after the application terminates. Unless you have a reason to keep the container around, it's generally a good idea to delete it once it's done because containers use disk space.docker run --rm hello-world
You should see output similar to the following:
Hello 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 the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share 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/Congratulations, you've just run your first container! Now in the next lab, we'll create our own image.
This lab will show you how to build a Docker image for a toy program, push it to a Docker registry, and then use Mayhem to analyze the toy program in the image.
-
First, we need to setup Docker to enable pushing new images for a later step.
-
Navigate to https://github.com.
-
Click on your user account icon to reveal a drop down menu.
-
Click on settings in the drop down menu.
-
On the left side of the settings page, select "Developer Settings."
-
On the developer settings page, select "Personal Access Tokens" and then "Tokens (Classic)".
-
Click create new token.
-
Enter a note for the token, and check the repo, workflow, write:packages, and delete:packages scopes.
-
Scroll to the bottom and click "Generate New Token".
-
Click the copy button to copy the token to your clipboard.
-
Back on the command-line, we'll use the
docker logincommand to login to the GitHub container registry. When using your username relative to GitHub orghcr.io, make it all lowercase or you'll run into issues.docker login -u <Your GitHub Username> ghcr.ioWhen prompted for a password, paste your personal access token (PAT) that you copied in the previous step. Note the token will not echo. After pasting, press enter.
You should see something similar to the following:
Password: WARNING! Your password will be stored unencrypted in /home/nathan/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login SucceededMake sure to save your personal access token in a file somewhere on your machine. (I keep mine in my password store). You'll want to use it later!
In general, you shouldn't have to restart the Docker daemon, but if you do, this can be done with:
sudo systemctl restart dockerIf you're using Docker Desktop you can simply stop and restart the application.
Now that you've logged in to the GitHub container registry, we can build and push a Docker image.
-
In the lighttpd lab you should have already cloned the
hackathon-resourcesrepo. Change into thehackathon-resources/lab2bdirectory. -
List the contents of the lab2b directory.
lsYou should see the following:
Dockerfile Mayhemfile fuzzme.c -
Examine the Dockerfile.
cat DockerfileYou'll see that the Dockerfile is split up into two stages: the build stage, and the package stage.
# Build Stage: FROM --platform=linux/amd64 ubuntu:20.04 as builder ## Install build dependencies. RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y gcc ## Add Source Code ADD fuzzme.c / ## Build Step RUN gcc -g fuzzme.c -o fuzzme # Package Stage FROM --platform=linux/amd64 ubuntu:20.04 COPY --from=builder /fuzzme /
The build stage is where we will actually setup our build environment and compile the code.
The package stage copies the executable into our final image. Note that we could combine these into one stage, but our resulting docker image would be much larger. So the best practice here is to separate the build stage from the package stage.
-
Now, build the image using the
docker buildcommand.In the docker build command, we specify a tag name using
-t. The tag tells docker the registry (ghcr.io), the name (<Your GitHub Username>/fuzzme, and the version (latest).docker build -t ghcr.io/<Your GitHub Username>/fuzzme:latest .In the docker build command, we specify a tag name using
-t. The tag tells docker the registry (ghcr.io), the name (<Your GitHub Username>/fuzzme, and the version (latest) of the Docker image.The last argument
.specifies the build context, which in this case is the current directory. This tells Docker what directory it has access to on the host during the build process. -
Once the build completes. Push the image to the registry.
docker push ghcr.io/<Your GitHub Username>/fuzzme:latest -
Now, mark the package as public so Mayhem can see it:
-
Navigate to github.com/<Your username>
-
Click on "Packages".
-
In the packages tab, click on "fuzzme".
-
Now click "Package settings"
-
Under "Danger Zone" click "Change visibility"
-
In the Change package visibility dialog, set the visibility to public, type the name "fuzzme" to confirm, and click "I understand..."
-
Now that you've pushed your image to Mayhem, let's kick off a run.
-
Using your favorite text editor, modify the Mayhemfile. Replace with your GitHub username. Your Mayhemfile should look similar to this:
# Namespaced project name that the target belongs to project: hackathon # Target name (should be unique within the project) target: fuzzme # Base image to run the binary in. image: ghcr.io/<YOUR GITHUB USERNAME>/fuzzme:latest # List of commands used to test the target cmds: # Command used to start the target, "@@" is the input file # (when "@@" is omitted Mayhem defaults to stdin inputs) - cmd: /fuzzme @@
-
Now kick off the run!
mayhem run .You should see output similar to the following:
Run started: hackathon/fuzzme/1 Run URL: https://mayhem.forallsecure.com:443/nathanjackson/hackathon/fuzzme/1 hackathon/fuzzme/1










