Skip to content

Commit 5035132

Browse files
committed
more docker work
1 parent 65412cd commit 5035132

File tree

11 files changed

+49
-109
lines changed

11 files changed

+49
-109
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ config/database.yml
3434
# target config file for testing
3535
features/support/targets.yml
3636
# simplecov coverage data
37-
coverage
37+
coverage/
3838
doc/
3939
external/source/meterpreter/java/bin
4040
external/source/meterpreter/java/build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ data/meterpreter/ext_server_pivot.*.dll
8888

8989
# local docker compose overrides
9090
docker-compose.local*
91+
.env
9192

9293
# Ignore python bytecode
9394
*.pyc

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
FROM ruby:2.4.2-alpine
2-
MAINTAINER Rapid7
2+
LABEL maintainer="Rapid7"
33

44
ARG BUNDLER_ARGS="--jobs=8 --without development test coverage"
55
ENV APP_HOME /usr/src/metasploit-framework/
66
ENV MSF_USER msf
77
ENV NMAP_PRIVILEGED=""
8+
ENV BUNDLE_IGNORE_MESSAGES="true"
89
WORKDIR $APP_HOME
910

10-
COPY Gemfile* m* Rakefile $APP_HOME
11-
COPY lib $APP_HOME/lib
11+
COPY Gemfile* metasploit-framework.gemspec Rakefile $APP_HOME
12+
COPY lib/metasploit/framework/version.rb $APP_HOME/lib/metasploit/framework/version.rb
13+
COPY lib/metasploit/framework/rails_version_constraint.rb $APP_HOME/lib/metasploit/framework/rails_version_constraint.rb
14+
COPY lib/msf/util/helper.rb $APP_HOME/lib/msf/util/helper.rb
1215

1316
RUN apk update && \
1417
apk add \
@@ -36,8 +39,7 @@ RUN apk update && \
3639
ncurses-dev \
3740
git \
3841
&& echo "gem: --no-ri --no-rdoc" > /etc/gemrc \
39-
# this currently fails: https://github.com/rubygems/rubygems/issues/2064
40-
# && gem update --system \
42+
&& gem update --system \
4143
&& gem install bundler \
4244
&& bundle install --system $BUNDLER_ARGS \
4345
&& apk del .ruby-builddeps \
@@ -46,7 +48,7 @@ RUN apk update && \
4648
RUN adduser -g msfconsole -D $MSF_USER
4749

4850
RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which ruby)
49-
RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip /usr/bin/nmap
51+
RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which nmap)
5052

5153
USER $MSF_USER
5254

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
version: '2'
1+
version: '3'
22

33
services:
44
ms:
55
build:
6+
context: .
7+
dockerfile: ./Dockerfile
68
args:
79
BUNDLER_ARGS: --jobs=8
810
image: metasploit:dev
911
environment:
1012
DATABASE_URL: postgres://postgres@db:5432/msf_dev
11-
1213
volumes:
1314
- .:/usr/src/metasploit-framework

docker-compose.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
version: '2'
1+
version: '3'
22
services:
33
ms:
4-
image: metasploit
5-
build:
6-
context: .
7-
dockerfile: ./Dockerfile
4+
image: metasploitframework/metasploit-framework:latest
85
environment:
96
DATABASE_URL: postgres://postgres@db:5432/msf
107
links:
@@ -16,7 +13,7 @@ services:
1613
- /etc/localtime:/etc/localtime:ro
1714

1815
db:
19-
image: postgres:9-alpine
16+
image: postgres:10-alpine
2017
volumes:
2118
- pg_data:/var/lib/postgresql/data
2219

docker/README.md

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,36 @@
33

44
To run `msfconsole`
55
```bash
6+
docker-compose build
67
docker-compose run --rm --service-ports ms
78
```
8-
9-
To run `msfvenom`
9+
or
1010
```bash
11-
docker-compose run --rm ms ./msfvenom
11+
./docker/bin/msfconsole
1212
```
1313

14-
### I don't like typing `docker-compose --rm ...`
15-
16-
We have included some binstubs `./bin`, you can symlink them to your path.
17-
18-
Assuming you have `$HOME/bin`, and it's in your `$PATH`. You can run this from the project root:
19-
14+
To run `msfvenom`
2015
```bash
21-
ln -s `pwd`/docker/bin/msfconsole $HOME/bin/
22-
ln -s `pwd`/docker/bin/msfvenom $HOME/bin/
16+
docker-compose build
17+
docker-compose run --rm --no-deps ms ./msfvenom
2318
```
24-
25-
If you set the environment variable `MSF_BUILD` the container will be rebuilt.
26-
19+
or
2720
```bash
28-
MSF_BUILD=1 ./docker/bin/msfconsole
29-
MSF_BUILD=1 ./docker/bin/msfconsole-dev
21+
./docker/bin/msfvenom
3022
```
3123

24+
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.
25+
3226
### But I want reverse shells...
3327

34-
By default we expose port `4444`. You'll need to set `LHOST` to be a hostname/ip
35-
of your host machine.
28+
By default we expose port `4444`.
3629

3730
If you want to expose more ports, or have `LHOST` prepopulated with a specific
3831
value; you'll need to setup a local docker-compose override for this.
3932

40-
Create `docker/docker-compose.local.override.yml` with:
33+
Create `docker-compose.local.override.yml` with:
4134
```yml
42-
version: '2'
35+
version: '3'
4336
services:
4437
ms:
4538
environment:
@@ -56,19 +49,6 @@ Now you need to set the `COMPOSE_FILE` environment variable to load your local
5649
override.
5750

5851
```bash
59-
echo "COMPOSE_FILE=./docker-compose.yml:./docker/docker-compose.local.override.yml" >> .env
52+
echo "COMPOSE_FILE=./docker-compose.yml:./docker-compose.override.yml:./docker-compose.local.override.yml" >> .env
6053
```
6154
Now you should be able get reverse shells working
62-
63-
## Developing
64-
65-
To setup you environment for development, you need to add `docker/docker-compose.development.override.yml`
66-
to your `COMPOSE_FILE` environment variable.
67-
68-
If you don't have a `COMPOSE_FILE` environment variable, you can set it up with this:
69-
70-
```bash
71-
echo "COMPOSE_FILE=./docker-compose.yml:./docker/docker-compose.development.override.yml" >> .env
72-
```
73-
74-
Alternatively you can also use the `msfconsole-dev` binstub.

docker/bin/msfconsole

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ fi
1919

2020
cd $MSF_PATH
2121

22-
if [[ -n "$MSF_BUILD" ]]; then
23-
docker-compose -f $MSF_PATH/docker-compose.yml build
22+
PARAMS="$@"
23+
24+
if [[ $PARAMS == *"--rebuild"* ]]; then
25+
echo "Rebuilding image"
26+
docker-compose build
27+
exit $?
2428
fi
2529

26-
docker-compose run --rm --service-ports ms ./msfconsole -r docker/msfconsole.rc "$@"
30+
docker-compose run --rm --service-ports ms ./msfconsole -r docker/msfconsole.rc "$PARAMS"

docker/bin/msfconsole-dev

Lines changed: 0 additions & 27 deletions
This file was deleted.

docker/bin/msfvenom

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ if [[ -z "$MSF_PATH" ]]; then
1717
MSF_PATH=$(dirname $(dirname $path))
1818
fi
1919

20-
if [[ -n "$MSF_BUILD" ]]; then
21-
docker-compose -f $MSF_PATH/docker-compose.yml build
20+
cd $MSF_PATH
21+
22+
PARAMS="$@"
23+
24+
if [[ $PARAMS == *"--rebuild"* ]]; then
25+
echo "Rebuilding image"
26+
docker-compose build
27+
exit $?
2228
fi
2329

24-
cd $MSF_PATH
25-
docker-compose run --rm --service-ports ms ./msfvenom "$@"
30+
# we need no database here
31+
docker-compose run --rm --no-deps ms ./msfvenom "$PARAMS"

docker/bin/msfvenom-dev

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)