Skip to content

Commit

Permalink
another approach
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Feb 17, 2018
1 parent d19ee7a commit 70ad419
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ LABEL maintainer="Rapid7"

ARG BUNDLER_ARGS="--jobs=8 --without development test coverage"
ENV APP_HOME /usr/src/metasploit-framework/
ENV MSF_USER msf
ENV NMAP_PRIVILEGED=""
ENV BUNDLE_IGNORE_MESSAGES="true"
WORKDIR $APP_HOME
Expand All @@ -15,6 +14,7 @@ COPY lib/msf/util/helper.rb $APP_HOME/lib/msf/util/helper.rb

RUN apk update && \
apk add \
bash \
sqlite-libs \
nmap \
nmap-scripts \
Expand All @@ -24,6 +24,7 @@ RUN apk update && \
python3 \
ncurses \
libcap \
su-exec \
&& apk add --virtual .ruby-builddeps \
autoconf \
bison \
Expand All @@ -47,13 +48,16 @@ RUN apk update && \
&& apk del .ruby-builddeps \
&& rm -rf /var/cache/apk/*

RUN adduser -g msfconsole -D $MSF_USER -u 1000

RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which ruby)
RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which nmap)

USER $MSF_USER

ADD ./ $APP_HOME

# we need this entrypoint to dynamically create a user
# matching the hosts UID and GID so we can mount something
# from the users home directory. If the IDs don't match
# it results in access denied errors. Once docker has
# a solution for this we can revert it back to normal
ENTRYPOINT ["docker/entrypoint.sh"]

CMD ["./msfconsole", "-r", "docker/msfconsole.rc"]
17 changes: 10 additions & 7 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@

To run `msfconsole`
```bash
docker-compose build
docker-compose run --rm --service-ports ms
./docker/bin/msfconsole
```

or

```bash
./docker/bin/msfconsole
docker-compose build
docker-compose run --rm --service-ports -e MSF_UID=$(id -u) -e MSF_GID=$(id -g) ms
```

To run `msfvenom`
```bash
docker-compose build
docker-compose run --rm --no-deps ms ./msfvenom
./docker/bin/msfvenom
```

or

```bash
./docker/bin/msfvenom
docker-compose build
docker-compose run --rm --no-deps -e MSF_UID=$(id -u) -e MSF_GID=$(id -g) ms ./msfvenom
```

You can pass any command line arguments to the binstubs or the docker-compose command and they will be passed to `msfconsole` or `msfvenom`. If you need to rebuild an image (for example when the Gemfile changes) you need to build the docker image using `docker-compose build` or supply the `--rebuild` parameter to the binstubs.
Expand Down
8 changes: 1 addition & 7 deletions docker/bin/msfconsole
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,4 @@ if [[ $PARAMS == *"--rebuild"* ]]; then
exit $?
fi

# workaround if current user id is not the same as in the container.
# Otherwise the ~/.msf4 folder is not writeable
if [[ $EUID -ne 1000 ]]; then
docker-compose run --rm -u root --service-ports ms ./msfconsole -r docker/msfconsole.rc "$PARAMS"
else
docker-compose run --rm --service-ports ms ./msfconsole -r docker/msfconsole.rc "$PARAMS"
fi
docker-compose run --rm --service-ports -e MSF_UID=$(id -u) -e MSF_GID=$(id -g) ms ./msfconsole -r docker/msfconsole.rc "$PARAMS"
20 changes: 20 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

MSF_USER=msf
MSF_GROUP=msf
TMP=${MSF_UID:=1000}
TMP=${MSF_GID:=1000}

# don't recreate system users like root
if [ "$MSF_UID" -lt "1000" ]; then
MSF_UID=1000
fi

if [ "$MSF_GID" -lt "1000" ]; then
MSF_GID=1000
fi

addgroup -g $MSF_GID $MSF_GROUP
adduser -u $MSF_UID -D $MSF_USER -g $MSF_USER -G $MSF_GROUP $MSF_USER

su-exec $MSF_USER "$@"

0 comments on commit 70ad419

Please sign in to comment.