Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Docker example, fix server, and add Dockerfile for client #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:22.04 as builder

RUN apt-get update && apt-get install -y build-essential
COPY . /build
WORKDIR /build
RUN make


FROM ubuntu:22.04
COPY --from=builder /build/dnscat /app/dnscat
WORKDIR /app
ENV DNSCAT_SERVER=""
ENV DNSCAT_SECRET=""

RUN echo '#!/bin/sh' > run.sh && \
echo '/app/dnscat --dns server=${DNSCAT_SERVER},port=53 --secret=${DNSCAT_SECRET}' >> run.sh && \
chmod +x run.sh


ENTRYPOINT tail -f /dev/null
11 changes: 11 additions & 0 deletions examples/docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
up:
@docker compose up -d --build

down:
@docker compose down

run-server: up
@docker compose exec dnscat-server /app/run.sh

run-client: up
@docker compose exec dnscat-client /app/run.sh
34 changes: 34 additions & 0 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Docker Example
In this example, a server and a client are configured through Docker.
To understand how everything works, see the `Dockerfile`s in server and client.

## Usage
Run the stack with:
```bash
make up
```

it starts the client and server. Actually, no dnscat services are running.

Once the stack is executed, run the server with:
```bash
make run-server
```

Now, you have a `dnscat2` DNS server and a shell in the container.

The third step is to run the client:
```bash
make run-client
```

With this command, the client connects itself to the server.

### Environment variables
For the server:
- `DNSCAT_SECRET`: the secret that should be used by the client.
- `DNS_OPTS`: the `dns` options

For the client:
- `DNSCAT_SECRET`: the secret that should be used
- `DNSCAT_SERVER`: the dnscat2 server IP address.
33 changes: 33 additions & 0 deletions examples/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
dnscat-server:
platform: linux/amd64
build:
context: ../../server
environment:
- DNSCAT_SECRET=dnscat2
- DNS_OPTS=host=0.0.0.0,port=53

networks:
test-network:
ipv4_address: 10.254.0.2


dnscat-client:
build:
context: ../../client
environment:
- DNSCAT_SECRET=dnscat2
- DNSCAT_SERVER=10.254.0.2

networks:
test-network:
ipv4_address: 10.254.0.3


networks:
test-network:
driver: bridge
ipam:
config:
- subnet: 10.254.0.0/24

1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
17 changes: 14 additions & 3 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
FROM ruby:2.1-onbuild
MAINTAINER Mark Percival <[email protected]>
FROM ruby:3.0

LABEL MAINTAINER="Mark Percival <[email protected]>"

EXPOSE 53/udp
COPY . /app
WORKDIR /app
ENV DNSCAT_SECRET=""
ENV DNS_OPTS=""

RUN gem install bundler && bundle install
RUN echo '#!/bin/sh' > run.sh && \
echo 'ruby dnscat2.rb $( [ -n "$DNSCAT_SECRET" ] && echo --secret=$DNSCAT_SECRET ) $( [ -n "$DNS_OPTS" ] && echo --dns $DNS_OPTS )' >> run.sh && \
chmod +x run.sh

ENTRYPOINT tail -f /dev/null

CMD ["ruby ./dnscat2.rb"]

# Run it
# docker run -p 53:53/udp -it --rm mpercival/dnscat2 ruby ./dnscat2.rb foo.org