Skip to content

Instantly share code, notes, and snippets.

@xkon
Created September 18, 2017 01:33
Show Gist options
  • Save xkon/230b22120bf56a6fe218b7449b9d0215 to your computer and use it in GitHub Desktop.
Save xkon/230b22120bf56a6fe218b7449b9d0215 to your computer and use it in GitHub Desktop.
更改apk源为中科大,ruby源为ruby-china,以加快build速度的 metasploit-framework Dockerfile 。源Dockerfile地址:https://github.com/rapid7/metasploit-framework
FROM ruby:2.4.1-alpine
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=""
WORKDIR $APP_HOME
COPY Gemfile* m* Rakefile $APP_HOME
COPY lib $APP_HOME/lib
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
apk update && \
apk add \
sqlite-libs \
nmap \
nmap-scripts \
nmap-nselibs \
postgresql-libs \
ncurses \
libcap \
&& apk add --virtual .ruby-builddeps \
autoconf \
bison \
build-base \
ruby-dev \
openssl-dev \
readline-dev \
sqlite-dev \
postgresql-dev \
libpcap-dev \
libxml2-dev \
libxslt-dev \
yaml-dev \
zlib-dev \
ncurses-dev \
git \
&& echo "gem: --no-ri --no-rdoc" > /etc/gemrc \
&& gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ \
&& gem update --system \
&& gem install bundler \
&& bundle config mirror.https://rubygems.org https://gems.ruby-china.org \
&& bundle install --system $BUNDLER_ARGS \
&& apk del .ruby-builddeps \
&& rm -rf /var/cache/apk/*
RUN adduser -g msfconsole -D $MSF_USER
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 /usr/bin/nmap
USER $MSF_USER
ADD ./ $APP_HOME
CMD ["./msfconsole", "-r", "docker/msfconsole.rc"]
@xkon
Copy link
Author

xkon commented Sep 18, 2017

与原文件diff结果:

➜  metasploit-framework git:(master) ✗ git diff Dockerfile
diff --git a/Dockerfile b/Dockerfile
index 141513b..30eae94 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,7 +10,8 @@ WORKDIR $APP_HOME
 COPY Gemfile* m* Rakefile $APP_HOME
 COPY lib $APP_HOME/lib
 
-RUN apk update && \
+RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
+    apk update && \
     apk add \
       sqlite-libs \
       nmap \
@@ -36,8 +37,10 @@ RUN apk update && \
       ncurses-dev \
       git \
     && echo "gem: --no-ri --no-rdoc" > /etc/gemrc \
+    && gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ \
     && gem update --system \
     && gem install bundler \
+    && bundle config mirror.https://rubygems.org https://gems.ruby-china.org \
     && bundle install --system $BUNDLER_ARGS \
     && apk del .ruby-builddeps \
     && rm -rf /var/cache/apk/*

@xkon
Copy link
Author

xkon commented Sep 18, 2017

更改进入MSF后的工作目录为 /home/msf/.msf4

➜  metasploit-framework git:(master) ✗ git diff docker/msfconsole.rc
diff --git a/docker/msfconsole.rc b/docker/msfconsole.rc
index 2ced959..da12e89 100644
--- a/docker/msfconsole.rc
+++ b/docker/msfconsole.rc
@@ -7,4 +7,5 @@ else
 end
 run_single("setg LHOST #{lhost}")
 run_single("db_connect #{ENV['DATABASE_URL']}") if ENV['DATABASE_URL']
+run_single("cd /home/msf/.msf4")
 </ruby>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment