Skip to content

Instantly share code, notes, and snippets.

@tuantmb
Last active March 15, 2022 14:34
Show Gist options
  • Save tuantmb/700dd07e0d7089b1a709fdebf5bb5aff to your computer and use it in GitHub Desktop.
Save tuantmb/700dd07e0d7089b1a709fdebf5bb5aff to your computer and use it in GitHub Desktop.
Create msf-* from exploit tools path in metasploit framework
#!/bin/bash
#MSF_TOOLS_PATH=/opt/metasploit-framework/embedded/framework/tools/exploit
command -v dirname >/dev/null 2>&1 || { echo >&2 "Require dirname for automatically detect path. Comment this line of code for manual set your mSF_TOOLS_PATH"; exit 1; }
command -v locate >/dev/null 2>&1 || { echo >&2 "Require locate for automatically detect path. Comment this line of code for manual set your mSF_TOOLS_PATH"; exit 1; }
# Automatic detect msf exploit tools path
MSF_TOOLS_PATH=$(dirname $(locate pattern_create.rb))
if [ ! -z "$MSF_TOOLS_PATH" ]
then
echo "[+] Automatically detect path \"$MSF_TOOLS_PATH\""
else
echo "[x] Not found pattern_create.rb of metasploit framework"
exit 1
fi
# Detect ruby path
MSF_RUBY_PATH=$(realpath $(find $MSF_TOOLS_PATH/../../.. -name ruby -type f -executable -print))
if [ -f $MSF_RUBY_PATH ]; then
echo "[+] Detect msf ruby path as \"$MSF_RUBY_PATH\""
else
echo "[x] Not found msf ruby path at \"$MSF_RUBY_PATH\""
exit 1
fi
# create /usr/bin/script-exploit content
SCRIPT_PATH=/usr/bin/script-exploit
cat >$SCRIPT_PATH <<EOL
#!/bin/sh
name_script=\$(basename \$0)
tool_name=\${name_script##msf-}
exec $MSF_RUBY_PATH $MSF_TOOLS_PATH/\$tool_name.rb "\$@"
EOL
echo "[+] Create/overwrite content of $SCRIPT_PATH"
chmod +x $SCRIPT_PATH
# list and create msf tools
MSF_TOOLS_NAMES=($(find ${MSF_TOOLS_PATH} -name *.rb -exec basename {} .rb ';'))
for TOOL in ${MSF_TOOLS_NAMES[@]}
do
ln -sf /usr/bin/script-exploit /usr/bin/msf-$TOOL
RESULT=$?
if [ $RESULT -eq 0 ];
then
echo "[+] Created msf-$TOOL"
else
echo "[x] FAILED to create msf-$TOOL"
fi
done
@tuantmb
Copy link
Author

tuantmb commented Mar 15, 2022

** update 16/03/2022 - slowly detect embedded ruby by find (because ruby could be installed in non-bin directory in some metasploit versions)

@tuantmb
Copy link
Author

tuantmb commented Mar 15, 2022

#TODO: Process MSF_TOOLS_PATH when detect more than one path contains pattern_create.rb (many metasploit framework be installed)

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