├── docker-compose.yml ├── README.md ├── .github └── workflows │ └── docker-publish.yml ├── start.sh └── Dockerfile /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | app: 3 | build: 4 | context: . 5 | dockerfile: Dockerfile 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alpine-metasploit 2 | 3 | This Docker image allow to run the latest metasploit on Alpine Linux. 4 | 5 | This image can work with or without database support, but having a DB is highly reccomended. 6 | 7 | alpine-metasploit works out-of-the-box with official Postgresql docker image. 8 | 9 | You can start the alpine-metasploit with PostgreSQL support with the commands: 10 | 11 | ``` 12 | docker network create msf 13 | docker container run -d --name postgres --network msf -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres postgres:16.1-alpine3.19 14 | docker container run -it --name metasploit --network msf fcolista/alpine-metasploit:alpine-3.22 15 | ``` 16 | 17 | Enjoy, Francesco 18 | -------------------------------------------------------------------------------- /.github/workflows/docker-publish.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | on: 4 | push: 5 | branches: 6 | - main 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v4 13 | - name: Login to Docker Hub 14 | uses: docker/login-action@v3 15 | with: 16 | username: ${{ secrets.DOCKERHUB_USERNAME }} 17 | password: ${{ secrets.DOCKERHUB_PASSWORD }} 18 | - name: Set up Docker Buildx 19 | uses: docker/setup-buildx-action@v3 20 | - name: Build and push 21 | uses: docker/build-push-action@v5 22 | with: 23 | context: . 24 | push: true 25 | tags: fcolista/alpine-metasploit:alpine-3.22 26 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd /usr/share/metasploit-framework 4 | git config --global user.name "msf" 5 | git config --global user.email "msf@localhost" 6 | /usr/share/metasploit-framework/msfupdate 7 | 8 | MSFUSER=${MSFUSER:-postgres} 9 | MSFPASS=${MSFPASS:-postgres} 10 | DB_PORT_5432_TCP_ADDR=postgres 11 | 12 | echo "${DB_PORT_5432_TCP_ADDR}:5432:postgres:${MSFUSER}:${MSFPASS}" > /root/.pgpass && chmod 0600 /root/.pgpass 13 | 14 | if ping -c 1 -W 1 "postgres" &>/dev/null; then 15 | if ! [ $(psql -h $DB_PORT_5432_TCP_ADDR -p 5432 -U postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$MSFUSER'") == "1" ]; then 16 | psql -h $DB_PORT_5432_TCP_ADDR -p 5432 -U postgres -c "create role $MSFUSER login password '$MSFPASS'" 17 | fi 18 | if ! [ $(psql -h $DB_PORT_5432_TCP_ADDR -p 5432 -U postgres -lqtA | grep "^msf|" | wc -l) == "1" ]; then 19 | psql -h $DB_PORT_5432_TCP_ADDR -p 5432 -U postgres -c "CREATE DATABASE msf OWNER $MSFUSER;" 20 | fi 21 | 22 | sh -c "echo 'production: 23 | adapter: postgresql 24 | database: msf 25 | username: $MSFUSER 26 | password: $MSFPASS 27 | host: $DB_PORT_5432_TCP_ADDR 28 | port: 5432 29 | pool: 75 30 | timeout: 5' > /usr/share/metasploit-framework/config/database.yml" 31 | /usr/share/metasploit-framework/msfconsole 32 | else 33 | /usr/share/metasploit-framework/msfconsole -n 34 | fi 35 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.22 2 | LABEL org.opencontainers.image.authors="francesco.colista@gmail.com" 3 | COPY ./start.sh /usr/local/bin/start.sh 4 | ARG ALPINE_VER=3.22 5 | ENV PATH=$PATH:/usr/share/metasploit-framework 6 | RUN chmod +x /usr/local/bin/start.sh && \ 7 | echo "http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VER}/community" >> /etc/apk/repositories && \ 8 | apk add -U --no-cache \ 9 | build-base \ 10 | ruby \ 11 | ruby-bigdecimal \ 12 | ruby-bundler \ 13 | ruby-webrick \ 14 | ruby-dev \ 15 | libffi-dev\ 16 | openssl-dev \ 17 | readline-dev \ 18 | sqlite-dev \ 19 | postgresql-dev \ 20 | libpcap-dev \ 21 | libxml2-dev \ 22 | libxslt-dev \ 23 | yaml-dev \ 24 | zlib-dev \ 25 | ncurses-dev \ 26 | autoconf \ 27 | bison \ 28 | subversion \ 29 | git \ 30 | sqlite \ 31 | nmap \ 32 | libxslt \ 33 | postgresql \ 34 | ncurses 35 | 36 | RUN cd /usr/share && \ 37 | git clone https://github.com/rapid7/metasploit-framework.git && \ 38 | cd /usr/share/metasploit-framework && \ 39 | /usr/bin/bundle update --bundler && \ 40 | /usr/bin/bundle install 41 | 42 | RUN apk del \ 43 | build-base \ 44 | ruby-dev \ 45 | libffi-dev\ 46 | openssl-dev \ 47 | readline-dev \ 48 | sqlite-dev \ 49 | postgresql-dev \ 50 | libpcap-dev \ 51 | libxml2-dev \ 52 | libxslt-dev \ 53 | yaml-dev \ 54 | zlib-dev \ 55 | ncurses-dev \ 56 | bison \ 57 | autoconf && \ 58 | rm -rf /var/cache/apk/* 59 | 60 | VOLUME [ "/usr/share/metasploit-framework" ] 61 | CMD [ "/usr/local/bin/start.sh" ] 62 | --------------------------------------------------------------------------------