Codebase list poshc2 / 39f6cef resources / scripts / posh-project
39f6cef

Tree @39f6cef (Download .tar.gz)

posh-project @39f6cefraw · history · blame

#!/bin/bash

# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

function ctrl_c() {
    popd >/dev/null
    exit
}

source /usr/local/bin/_posh-common
get_posh_projects_dir

if [ "$1" == "-n" ]; then

    if [ -z "$2" ]; then
        echo "[*] Usage: posh-project -n <new-project-name>"
        exit 1
    fi

    if [ -d "$POSH_PROJECTS_DIR/$2" ]; then
        echo "[-] Project directory already exists: $POSH_PROJECTS_DIR/$2"
        exit 1
    fi

    sudo mkdir -p "$POSH_PROJECTS_DIR/$2"
    echo "$2" | sudo tee "$POSH_PROJECTS_DIR/CURRENT_PROJECT" >/dev/null
    sudo cp "$POSH_PROJECTS_DIR/config-template.yml" "$POSH_PROJECTS_DIR/$2/config.yml"
    echo "[+] Created Project: $2"
    echo "[*] Now run posh-config to set your configuration"

elif [ "$1" == "-s" ]; then
    if [ -z "$2" ]; then
        echo "[*] Usage: posh-project -s <project-to-switch-to>"
        exit 1
    fi

    if [ ! -d "$POSH_PROJECTS_DIR/$2" ]; then
        echo "[-] Project directory does not exist: $POSH_PROJECTS_DIR/$2"
        exit 1
    fi
    echo "$2" | sudo tee $POSH_PROJECTS_DIR/CURRENT_PROJECT >/dev/null
    echo "[+] Switched to: $2"
    echo "[*] Restart the PoshC2 C2 server & ImplantHandler to use the new project."

elif [ "$1" == "-l" ]; then

    if [ ! -d "$POSH_PROJECTS_DIR" ]; then
        echo "[-] Project directory does not exist: $POSH_PROJECTS_DIR"
        exit 1
    fi

    current_project=`cat $POSH_PROJECTS_DIR/CURRENT_PROJECT`
    echo "[*] Listing PoshC2 Projects in $POSH_PROJECTS_DIR"
    check_if_mac
    if [ "$IS_MAC" = true ]; then
        projects=`command ls -dl $POSH_PROJECTS_DIR/*/ 2>/dev/null | cut -d '/' -f 5`
    else
        projects=`command ls -dl $POSH_PROJECTS_DIR/*/ 2>/dev/null | cut -d '/' -f 4`
    fi

    for project in $projects; do
        if [ "$project" == "$current_project" ]; then
            echo "$project*"
        else
            echo "$project"
        fi
    done

elif [ "$1" == "-c" ]; then

    if [ ! -f "$POSH_PROJECTS_DIR/CURRENT_PROJECT" ]; then
        echo "[-] No current project selected."
        exit 1
    fi

    echo "[*] Current project: "
    cat "$POSH_PROJECTS_DIR/CURRENT_PROJECT"

elif [ "$1" == "-g" ]; then

    if [ ! -f "$POSH_PROJECTS_DIR/CURRENT_PROJECT" ]; then
        echo "[-] No current project selected."
        exit 1
    fi

    current_project=`cat $POSH_PROJECTS_DIR/CURRENT_PROJECT`
    echo "$POSH_PROJECTS_DIR/$current_project"

elif [ "$1" == "-d" ]; then

    if [ -z "$2" ]; then
        echo "[*] Usage: posh-project -d <project-to-delete>"
        exit 1
    fi

    read -p "Are you sure you want to delete the project $2? y/N " -n 1 -r
    echo    # (optional) move to a new line
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "[*] Removal aborted"
    else
        sudo rm -rf "$POSH_PROJECTS_DIR/$2"
        echo "[+] Project removed"
    fi
else
    echo "[*] Usage: posh-project -n <new-project-name>"
    echo "[*] Usage: posh-project -s <project-to-switch-to>"
    echo "[*] Usage: posh-project -l (lists projects)"
    echo "[*] Usage: posh-project -d <project-to-delete>"
    echo "[*] Usage: posh-project -c (shows current project)"
    echo "[*] Usage: posh-project -g (quietly shows current project directory for scripting)"
fi