Skip to content

Instantly share code, notes, and snippets.

@santrancisco
Last active May 28, 2020 05:42
Show Gist options
  • Save santrancisco/a6d84756f984a6a9b0d5fca1ad5737a4 to your computer and use it in GitHub Desktop.
Save santrancisco/a6d84756f984a6a9b0d5fca1ad5737a4 to your computer and use it in GitHub Desktop.
pchrome.sh - bash script to create/manage multiple chrome profiles base on single one - useful for starting new pentest.
#!/bin/bash
## pchrome.sh is a snippet to create various pentest profiles base on 1 single chrome profile.
## The new profiles will have the same Extension, extension setting as the base profile
# Bail if there is an error
set -e
# Uncomment line below if you want to see the command being run
# set -x
# Change to the directory of the script
cd "$(dirname "$0")"
export CHROMEPROFILES="$HOME/chromeprofiles"
# # set trap to always call cleanup function whether it fails or not
# trap cleanup EXIT
# # Note: trap can be used with signal number, eg "trap cleanup 9" will only be called on sigkill
# # Run `trap -l` to know what the list of all signals are.
# #cleanup function is called at the end of the script whether it fails or not
# function cleanup {
# echo "[+] cleanup code was called"
# }
# Example usage
function createusage() {
echo -e "\n########## USAGE ##########
Usage: $0 create {BASEPROFILE_LOCATION} {PROJECT}/{NEW_PROFILE_NAME} {PROFILE_AVATAR_ID} {DEFAULT_URL}
Examples:
$0 \"~/.config/chromium/Profile 1\" ADMIN 46 \"https://login.example.com\"\n
Some default avatar id choices:
- 55 - lowpriv
- 46 - admin1
- 52 - otheradmin
"
exit 1
}
## Create new chrome profile
function create {
if [ $# -lt 4 ];
then
createusage
fi
BASEPROFILE=$1
PROFILENAME=$2
PROFILEAVATAR=$3
DEFAULTURL=$4
if [[ $PROFILENAME != *"/"* ]]; then
echo "MISSING {PROJECT} !"
createusage
exit 1
fi
DOWNLOADFOLDER="$CHROMEPROFILES/Downloads"
## Folder under ~/.config/chromium/ is structure a little different compare to standalone profile and has no Default folder.
if [ -d "$BASEPROFILE/Default" ];
then
export BASEPROFILE="$BASEPROFILE/Default"
fi
PROFILEFOLDER="$CHROMEPROFILES/$PROFILENAME"
mkdir -p $PROFILEFOLDER/Default
mkdir -p $DOWNLOADFOLDER
cp -r "$BASEPROFILE"/* "$PROFILEFOLDER/Default/"
cat "$BASEPROFILE/Preferences" | \
jq '.session.restore_on_startup=4' | \
jq ".session.startup_urls=[\"$DEFAULTURL\"]" | \
jq ".profile.name=\"$PROFILENAME\"" | \
jq ".download.default_directory = \"$DOWNLOADFOLDER\"" |\
jq ".profile.avatar_index = $PROFILEAVATAR" > "$PROFILEFOLDER/Default/Preferences"
echo -e "Run the following command to start the chromium profile:
chromium-browser --user-data-dir=$PROFILEFOLDER"
}
## Start a pentest project - Run all the profiles under same project.
function start {
if [ $# -lt 1 ];
then
echo -e "\n########## USAGE ##########
Usage: $0 start {ProjectName}
List of projects:\n"
ls $CHROMEPROFILES | grep -v -w "Downloads\|baseprofile"
exit 1
fi
PROJECT=$1
ls $CHROMEPROFILES/$PROJECT | while read -r PROFILE; do
chromium-browser --user-data-dir=$CHROMEPROFILES/$PROJECT/$PROFILE &
done
}
# Create a new project with a bunch of profiles (2 admin, 2 low priv)
function createproject(){
if [ $# -lt 3 ];
then
echo -e "\n########## USAGE ##########\n
Usage: \n $0 createproject {BASEPROFILE_LOCATION} {PROJECT} {DEFAULT_URL}\n
Examples create project EBFE:\n
$0 \"~/.config/chromium/Profile 1\" EBFE \"https://login.example.com\"\n"
exit 1
fi
BASEPROFILE=$1
PROJECT=$2
DEFAULTURL=$3
create "$BASEPROFILE" "$PROJECT/ADMIN_A" 46 "$DEFAULTURL"
create "$BASEPROFILE" "$PROJECT/LOWPRIV_A" 55 "$DEFAULTURL"
create "$BASEPROFILE" "$PROJECT/ADMIN_B" 52 "$DEFAULTURL"
create "$BASEPROFILE" "$PROJECT/LOW_PRIV_B" 23 "$DEFAULTURL"
echo -e " The following profiles were created:
$CHROMEPROFILES/$PROJECT/ADMIN_A
$CHROMEPROFILES/$PROJECT/LOWPRIV_A
$CHROMEPROFILES/$PROJECT/ADMIN_B
$CHROMEPROFILES/$PROJECT/LOWPRIV_B
"
}
function help {
echo "$0 <task> <args>"
echo "Tasks: "
compgen -A function | egrep -v 'cleanup|createusage|help' |cat -n
}
# execute the function and arguments pass to this script.
# If nothing provided, run help function
${@:-help}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment