Skip to content

Commit

Permalink
Added: volumes with host, tmux, nmap and symlinks to /usr/local/bin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Christophe Baptiste committed May 3, 2016
1 parent 597a339 commit 0cc413e
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 10 deletions.
22 changes: 16 additions & 6 deletions Dockerfile
Expand Up @@ -13,21 +13,24 @@ RUN apt-get update && apt-get -y install \
ncurses-dev bison curl wget xsel postgresql \
postgresql-contrib postgresql-client libpq-dev \
libapr1 libaprutil1 libsvn1 \
libpcap-dev libsqlite3-dev libgmp3-dev
libpcap-dev libsqlite3-dev libgmp3-dev \
nasm tmux vim nmap

ADD ./init.sh /usr/local/bin/init.sh
# startup script
ADD ./scripts/init.sh /usr/local/bin/init.sh
# tmux configuration file
ADD ./conf/tmux.conf /root/.tmux.conf

# Get Metasploit
WORKDIR /opt
RUN git clone https://github.com/rapid7/metasploit-framework.git msf
WORKDIR msf

# Install PosgreSQL
ADD db.sql /tmp/
ADD ./scripts/db.sql /tmp/
RUN /etc/init.d/postgresql start && su postgres -c "psql -f /tmp/db.sql"

USER root
ADD database.yml /opt/msf/config/
ADD ./conf/database.yml /opt/msf/config/

# RVM
RUN curl -sSL https://rvm.io/mpapis.asc | gpg --import
Expand All @@ -45,6 +48,13 @@ RUN /bin/bash -l -c "BUNDLEJOBS=$(expr $(cat /proc/cpuinfo | grep vendor_id | wc
RUN /bin/bash -l -c "bundle config --global jobs $BUNDLEJOBS"
RUN /bin/bash -l -c "bundle install"

ADD config /root/.msf4/
# Symlink tools to $PATH
RUN for i in `ls /opt/msf/tools/*/*`; do ln -s $i /usr/local/bin/; done
RUN ln -s /opt/msf/msf* /usr/local/bin

# settings and custom scripts folder
VOLUME /root/.msf4/
VOLUME /tmp/data/

# Starting script (DB + updates)
CMD /usr/local/bin/init.sh
47 changes: 44 additions & 3 deletions README.md
Expand Up @@ -9,7 +9,13 @@ MSF is started automatically with:
- all dependencies installed,
- automatic updates at startup,
- a connection with the local Postgres database,
- an improved prompt with timestamping and sessions/jobs status.
- volumes, to share data and get access to your custom Metasploit scripts.

It also includes:

- tmux, to use multiple windows (msfconsole, shell, etc.) inside the container;
- nmap, the famous network scanner (along with ncat);
- a configuration file to get an improved prompt in Metasploit, with timestamping and sessions/jobs status.

# Build

Expand All @@ -21,18 +27,53 @@ docker build -t debian-msf .

Docker will download the Debian image and then execute the installation steps.

**Be patient, the process can be quite long the first time.**

Note that you may want to:

- copy the *contrib/config* file to the *~/.msf4* folder to get a nice prompt.
- customize the *conf/tmux* file, if you plan to use this tool.

*The configuration of Tmux maps the keyboard as in Screen (CTRL-A). It also makes a few cosmetic changes to the status bar.
Note that you could adjust the init script to automatically launch Tmux with a msf window and a bash one, for instance. I don't make it the default, because I don't want to bother people who don't need/want Tmux.*

# Run

Once the build process is over, get and enjoy a neat msf prompt with this command:

```
docker run -i -t -p 9990-9999:9990-9999 debian-msf
docker run -i -t -p 9990-9999:9990-9999 -v /home/<USER>/.msf4:/root/.msf4 -v /tmp/msf:/tmp/data debian-msf
```

Here, we map the port range from 9990 to 9999 to our host, to catch reverse shells back.
Explanations:

- We map the port range from 9990 to 9999 to our host, to catch reverse shells back.
- We mount the local .msf4 folder, where you can set your prompt and put custom scripts and modules, to */root/.msf4* inside the container (if you want to make some changes at runtime, beware to do it from your host, not from within the container).
- Similarly, we mount a */tmp/data folder* to exchange data (a dump from a successful exploit, for instance).

Of course, it is up to you to adjust it to your taste or need.

At any time, you can exit, which only stops (suspend) the container.

You can restart it anytime:

```
docker restart <id>
```

And then attach to it:

```
docker attach <id>
```

Once you are done, you can stop and delete the container for good. In that case, all you data will be lost (settings, cache, logs):

```
docker rm <id>
```

# Shell access

If for some reason, you need to access to the shell, type this command from within the msf instance :
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions conf/tmux.conf
@@ -0,0 +1,50 @@
# color
set -g default-terminal "screen-256color"

# Make it use C-a, similar to screen..
unbind C-b
unbind l
set -g prefix C-a
bind-key C-a last-window
bind-key a send-prefix

# Set Copy mode to escape key
unbind [
bind Escape copy-mode

# Use Vi mode
set-window-option -g mode-keys vi

# More straight forward key bindings for splitting
unbind %
bind | split-window -h
bind h split-window -h
unbind '"'
bind - split-window -v
bind v split-window -v

# Reload key
bind r source-file ~/.tmux.conf

# History
set-option -g history-limit 1000

# Terminal emulator window title
set-option -g set-titles on
set-option -g set-titles-string '#S:#I.#P #W'

# Status Bar
set-option -g status-bg green
set-option -g status-fg black
set-option -g status-right ' #[fg=white]#(whoami)@#H #[fg=black]%k:%M #[fg=black]%a,%d-%b#[default] '
set-window-option -g window-status-current-attr bold
set-window-option -g window-status-current-fg red
set-window-option -g window-status-current-bg white

# Notifying if other windows has activities
set-option -g visual-activity on
set-window-option -g monitor-activity on

# Clock
set-window-option -g clock-mode-colour green
set-window-option -g clock-mode-style 24
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion init.sh → scripts/init.sh
Expand Up @@ -3,4 +3,5 @@
source /usr/local/rvm/scripts/rvm
/etc/init.d/postgresql start
/opt/msf/msfupdate
/opt/msf/msfconsole
#/opt/msf/msfconsole
/bin/bash

0 comments on commit 0cc413e

Please sign in to comment.