Dockerfile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. FROM ruby:3.1.4-alpine3.18 AS builder
  2. LABEL maintainer="Rapid7"
  3. ARG BUNDLER_CONFIG_ARGS="set no-cache 'true' set system 'true' set without 'development test coverage'"
  4. ARG BUNDLER_FORCE_CLEAN="true"
  5. ENV APP_HOME=/usr/src/metasploit-framework
  6. ENV TOOLS_HOME=/usr/src/tools
  7. ENV BUNDLE_IGNORE_MESSAGES="true"
  8. WORKDIR $APP_HOME
  9. COPY Gemfile* metasploit-framework.gemspec Rakefile $APP_HOME/
  10. COPY lib/metasploit/framework/version.rb $APP_HOME/lib/metasploit/framework/version.rb
  11. COPY lib/metasploit/framework/rails_version_constraint.rb $APP_HOME/lib/metasploit/framework/rails_version_constraint.rb
  12. COPY lib/msf/util/helper.rb $APP_HOME/lib/msf/util/helper.rb
  13. RUN apk add --no-cache \
  14. autoconf \
  15. bash \
  16. bison \
  17. build-base \
  18. curl \
  19. ruby-dev \
  20. openssl-dev \
  21. readline-dev \
  22. sqlite-dev \
  23. postgresql-dev \
  24. libpcap-dev \
  25. libxml2-dev \
  26. libxslt-dev \
  27. yaml-dev \
  28. zlib-dev \
  29. ncurses-dev \
  30. git \
  31. go \
  32. && echo "gem: --no-document" > /etc/gemrc \
  33. && gem update --system \
  34. && bundle config $BUNDLER_CONFIG_ARGS \
  35. && bundle install --jobs=8 \
  36. && if [ "${BUNDLER_FORCE_CLEAN}" == "true" ]; then \
  37. bundle clean --force; \
  38. fi \
  39. # temp fix for https://github.com/bundler/bundler/issues/6680
  40. && rm -rf /usr/local/bundle/cache \
  41. # needed so non root users can read content of the bundle
  42. && chmod -R a+r /usr/local/bundle
  43. ENV GO111MODULE=off
  44. RUN mkdir -p $TOOLS_HOME/bin && \
  45. cd $TOOLS_HOME/bin && \
  46. curl -O https://dl.google.com/go/go1.21.1.src.tar.gz && \
  47. tar -zxf go1.21.1.src.tar.gz && \
  48. rm go1.21.1.src.tar.gz && \
  49. cd go/src && \
  50. ./make.bash
  51. FROM ruby:3.1.4-alpine3.18
  52. LABEL maintainer="Rapid7"
  53. ARG TARGETARCH
  54. ENV APP_HOME=/usr/src/metasploit-framework
  55. ENV TOOLS_HOME=/usr/src/tools
  56. ENV NMAP_PRIVILEGED=""
  57. ENV METASPLOIT_GROUP=metasploit
  58. # used for the copy command
  59. RUN addgroup -S $METASPLOIT_GROUP
  60. RUN apk add --no-cache bash sqlite-libs nmap nmap-scripts nmap-nselibs \
  61. postgresql-libs python3 py3-pip ncurses libcap su-exec alpine-sdk \
  62. openssl-dev nasm
  63. RUN\
  64. if [ "${TARGETARCH}" = "arm64" ];\
  65. then apk add --no-cache gcc musl-dev python3-dev libffi-dev gcompat;\
  66. else apk add --no-cache mingw-w64-gcc;\
  67. fi
  68. RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which ruby)
  69. RUN /usr/sbin/setcap cap_net_raw,cap_net_bind_service=+eip $(which nmap)
  70. COPY --from=builder /usr/local/bundle /usr/local/bundle
  71. RUN chown -R root:metasploit /usr/local/bundle
  72. COPY . $APP_HOME/
  73. COPY --from=builder $TOOLS_HOME $TOOLS_HOME
  74. RUN chown -R root:metasploit $APP_HOME/
  75. RUN chmod 664 $APP_HOME/Gemfile.lock
  76. RUN gem update --system
  77. RUN cp -f $APP_HOME/docker/database.yml $APP_HOME/config/database.yml
  78. RUN curl -L -O https://raw.githubusercontent.com/pypa/get-pip/f84b65709d4b20221b7dbee900dbf9985a81b5d4/public/get-pip.py && python3 get-pip.py && rm get-pip.py
  79. RUN pip install impacket
  80. RUN pip install requests
  81. ENV GOPATH=$TOOLS_HOME/go
  82. ENV GOROOT=$TOOLS_HOME/bin/go
  83. ENV PATH=${PATH}:${GOPATH}/bin:${GOROOT}/bin
  84. WORKDIR $APP_HOME
  85. # we need this entrypoint to dynamically create a user
  86. # matching the hosts UID and GID so we can mount something
  87. # from the users home directory. If the IDs don't match
  88. # it results in access denied errors.
  89. ENTRYPOINT ["docker/entrypoint.sh"]
  90. CMD ["./msfconsole", "-r", "docker/msfconsole.rc", "-y", "$APP_HOME/config/database.yml"]