ArchStrike / ArchStrike

An Arch Linux repository for security professionals and enthusiasts. Done the Arch Way and optimized for i686, x86_64, ARMv6, ARMv7 and ARMv8.
https://archstrike.org/
GNU General Public License v3.0
494 stars 90 forks source link

[SUGGESTION] Speeding metasploit install process #137

Closed ETeissonniere closed 8 years ago

ETeissonniere commented 8 years ago

Hi archstrike, I think we can make minor changes to the mtasploit PKGBUILD. I suggest to build the gems into the build part (using bundle install -deploymen) then, in the install part we install metasploit with the gems. It might speed the install process and make it easier.

xorond commented 8 years ago

Thanks for the suggestion. I will be looking into it when available. Might add that in the next version for metasploit if it indeed improves the process.

ETeissonniere commented 8 years ago

Hey @xorond here is the modified PKGBUILD, it might be uncomplete but it is a start :smirk:

# Maintainer: ArchStrike <team@archstrike.org>

buildarch=212

pkgname=metasploit
pkgver=4.12.6
pkgrel=1
epoch=1
groups=('archstrike' 'archstrike-exploit' 'archstrike-fuzzers' 'archstrike-scanners')
pkgdesc="An open source platform that supports vulnerability research, exploit development and the creation of custom security tools representing the largest collection of quality-assured exploits"
arch=('i686' 'x86_64' 'armv6h' 'armv7h')
depends_x86_64+=('lib32-libxslt')
depends+=('ruby' 'ruby-bundler' 'git' 'libxslt' 'postgresql-libs' 'sqlite' 'libpcap' 'postgresql')
optdepends=('java-environment: msfgui'
            'dradis: dradisis database system')
# Dependencies to build the gems (maybe uncomplete)
makedepends=('sqlite', 'ruby', 'ruby-bundler', 'lippcap', 'postgresql-libs')
url='http://www.metasploit.com'
license=('BSD')
options=('!emptydirs' '!strip')
source=("https://github.com/rapid7/metasploit-framework/archive/$pkgver.tar.gz")
replaces=('metasploit-git')
conflicts=('metasploit-git')
provides=('metasploit-git')
backup=('usr/share/metasploit/log/production.log')
install="$pkgname.install"
sha512sums=('7c387c426394d90d876116c9fef1d44122348abf1e51e2bfe04539da08c7e2983dcb21f55dae95ccda43bac73771e1b98bb5c6505ba623e9417b130d03c85129')

build () {
  cd "$pkgname-framework-$pkgver"
  # Build the gems
  bundle install --deployment
  chmod 0644 vendor/bundle/ruby/2.3.0/gems/*/*/*.rb
}

package() {
  cd "$pkgname-framework-$pkgver"

  # Base directories.
  install -dm755 "${pkgdir}/usr/bin"
  install -dm755 "${pkgdir}/etc"
  install -dm755 "${pkgdir}/usr/share/metasploit"
  install -dm755 "${pkgdir}/usr/share/doc/metasploit"

  # Shareable.
  cp --no-preserve=ownership -a documentation/* "${pkgdir}/usr/share/doc/metasploit"
  cp --no-preserve=ownership README.md "${pkgdir}/usr/share/doc/metasploit"

  # Source + Bin.
  cp -a --no-preserve=ownership * "${pkgdir}/usr/share/metasploit"
  install -m644 .rspec "${pkgdir}/usr/share/metasploit"
  install -m644 .rubocop.yml "${pkgdir}/usr/share/metasploit"
  install -m644 .ruby-gemset "${pkgdir}/usr/share/metasploit"
  install -m644 .ruby-version "${pkgdir}/usr/share/metasploit"
  install -m644 .simplecov "${pkgdir}/usr/share/metasploit"
  install -m644 .travis.yml "${pkgdir}/usr/share/metasploit"
  install -m644 .yardopts "${pkgdir}/usr/share/metasploit"
  install -m644 .gitmodules "${pkgdir}/usr/share/metasploit"
  install -m644 .mailmap "${pkgdir}"/usr/share/metasploit
  # Commenting out the .git dir to shrink size. This will cause
  # a warning when starting about not being a git dir.
  #cp -a --no-preserve=ownership .git "${pkgdir}/usr/share/metasploit"
  # Conform to the FHS.
  mv "${pkgdir}/usr/share/metasploit/config" "${pkgdir}/etc/metasploit"
  ln -s /etc/metasploit "${pkgdir}/usr/share/metasploit/config"

  cd ${pkgdir}/usr/share/metasploit
  rm msfupdate
  install -Dm0666 /dev/null "${pkgdir}"/usr/share/metasploit/log/production.log

  cat > "${pkgdir}/usr/bin/msfbinscan" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfbinscan "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfcli" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfcli "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfconsole" <<EOF
#!/bin/sh
if ! [[ -f /usr/share/metasploit/database.yml ]]; then
    cd /usr/share/metasploit
    ruby ./msfconsole -y msfconsole/database.yml "\$@"
else
    cd /usr/share/metasploit
    ruby ./msfconsole "\$@"
fi
EOF

  cat > "${pkgdir}/usr/bin/msfd" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfd "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfelfscan" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfelfscan "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfencode" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfencode "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfmachscan" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfmachscan "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfpayload" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfpayload "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfpescan" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfpescan "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfrop" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfrop "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfrpc" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfrpc "\$@"
EOF

  cat > "${pkgdir}/usr/bin/msfrpcd" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfrpcd "\$@"
EOF

# Commenting out since we are locking out msfupdate
#  cat > "${pkgdir}/usr/bin/msfupdate" <<EOF
##!/bin/sh
#ruby /usr/share/metasploit/msfupdate "\$@"
#EOF

  cat > "${pkgdir}/usr/bin/msfvenom" <<EOF
#!/bin/sh
cd /usr/share/metasploit
ruby ./msfvenom "\$@"
EOF

  chmod +x "${pkgdir}"/usr/bin/*
}
xorond commented 8 years ago

Thanks, we will review it soon enough. We wouldn't want metasploit getting broken so it could take a while for us to test & apply this properly.

ETeissonniere commented 8 years ago

Okay @xorond thank. By the way if I can help, ask.

xorond commented 8 years ago

@DeveloppSoft I took a quick look at your PKGBUILD and it seems like it won't install the gems properly in /usr/share/metasploit as it's ran in the ${srcdir}/${pkgname}-framework-${pkgver} directory also it's missing the nokogiri gem. Also we don't need sqlite, libpcap (yours is misspelled, lippcap), and postgresql-libs on makedepends as they are already in the depends array. I am unable to test it right now but these are the issues I see for now. Maybe you can work on these and submit back.

ETeissonniere commented 8 years ago

Hi Oguz, I did it quickly without testing :smile:. Anyway I will work on it

archey commented 8 years ago

@DeveloppSoft Thanks for looking at it we will watch this thread and see what we can do to make it better

archey commented 8 years ago

Closing for now, please reopen if you have any more input

ETeissonniere commented 8 years ago

Sure, I need some time :smirk:

ETeissonniere commented 8 years ago

Hey guys, I made a pull -> #153