Skip to content

Commit

Permalink
Refactor projects to ~/.poshc2, add posh-project script for managing …
Browse files Browse the repository at this point in the history
…projects
  • Loading branch information
riskydissonance committed Jul 30, 2020
1 parent 681d063 commit c8d7c9a
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 255 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# From the Kali Linux base image
FROM kalilinux/kali-rolling

ENV TERM="xterm"
# Update and apt install programs
RUN apt-get update && apt-get full-upgrade -y && apt-get autoremove -y && apt-get install -y git
RUN apt-get update && apt-get full-upgrade -y && apt-get autoremove -y
RUN apt-get install -y curl gnupg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list
RUN apt-get update
RUN apt-get install -y git screen python3 python3-dev python3-pip build-essential mingw-w64-tools mingw-w64 mingw-w64-x86-64-dev mingw-w64-i686-dev mingw-w64-common espeak graphviz mono-complete apt-transport-https vim nano python2.7 libpq-dev sudo sqlite3 dotnet-runtime-2.2 dotnet-hostfxr-2.2 dotnet-host libssl1.1 libicu63

# Install PoshC2
# Install PoshC2
ADD . /opt/PoshC2
RUN /opt/PoshC2/Install.sh
RUN /opt/PoshC2/Install.sh

# Working directory
WORKDIR /opt/PoshC2
54 changes: 28 additions & 26 deletions Install-for-Docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Install PoshC2
echo ""
echo """
echo """
__________ .__. _________ ________
\_______ \____ _____| |__ \_ ___ \ \_____ \\\\
| ___/ _ \/ ___/ | \ / \ \/ / ____/
Expand Down Expand Up @@ -50,31 +50,33 @@ if [[ ! -d "$POSH_DIR" ]]; then
fi

echo ""
echo "[+] Copying useful scripts to /usr/bin"
cp "$POSH_DIR/resources/scripts/fpc" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-config" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-docker" /usr/bin/posh
cp "$POSH_DIR/resources/scripts/posh-docker-server" /usr/bin/posh-server
cp "$POSH_DIR/resources/scripts/posh-docker-build" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-docker-clean" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-docker-service" /usr/bin/posh-service
cp "$POSH_DIR/resources/scripts/posh-stop-service" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-log" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-update" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-cookie-decrypter" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-project-clean" /usr/bin
chmod +x /usr/bin/fpc
chmod +x /usr/bin/posh-config
chmod +x /usr/bin/posh
chmod +x /usr/bin/posh-server
chmod +x /usr/bin/posh-docker-build
chmod +x /usr/bin/posh-docker-clean
chmod +x /usr/bin/posh-service
chmod +x /usr/bin/posh-log
chmod +x /usr/bin/posh-stop-service
chmod +x /usr/bin/posh-update
chmod +x /usr/bin/posh-cookie-decrypter
chmod +x /usr/bin/posh-project-clean
echo "[+] Symlinking useful scripts to /usr/bin"
ln -s "$POSH_DIR/resources/scripts/fpc" /usr/bin/fpc
ln -s "$POSH_DIR/resources/scripts/posh-docker" /usr/bin/posh
ln -s "$POSH_DIR/resources/scripts/posh-docker-server" /usr/bin/posh-server
ln -s "$POSH_DIR/resources/scripts/posh-config" /usr/bin/posh-config
ln -s "$POSH_DIR/resources/scripts/posh-log" /usr/bin/posh-log
ln -s "$POSH_DIR/resources/scripts/posh-docker-service" /usr/bin/posh-service
ln -s "$POSH_DIR/resources/scripts/posh-stop-service" /usr/bin/posh-stop-service
ln -s "$POSH_DIR/resources/scripts/posh-update" /usr/bin/posh-update
ln -s "$POSH_DIR/resources/scripts/posh-cookie-decrypter" /usr/bin/posh-cookie-decryptor
ln -s "$POSH_DIR/resources/scripts/posh-project" /usr/bin/posh-project
ln -s "$POSH_DIR/resources/scripts/posh-docker-build" /usr/bin/posh-docker-build
ln -s "$POSH_DIR/resources/scripts/posh-docker-clean" /usr/bin/posh-docker-clean
ln -s "$POSH_DIR/resources/scripts/posh-docker-debug" /usr/bin/posh-docker-debug
chmod +x "$POSH_DIR/resources/scripts/fpc"
chmod +x "$POSH_DIR/resources/scripts/posh-docker"
chmod +x "$POSH_DIR/resources/scripts/posh-docker-server"
chmod +x "$POSH_DIR/resources/scripts/posh-config"
chmod +x "$POSH_DIR/resources/scripts/posh-log"
chmod +x "$POSH_DIR/resources/scripts/posh-docker-service"
chmod +x "$POSH_DIR/resources/scripts/posh-stop-service"
chmod +x "$POSH_DIR/resources/scripts/posh-update"
chmod +x "$POSH_DIR/resources/scripts/posh-cookie-decrypter"
chmod +x "$POSH_DIR/resources/scripts/posh-project"
chmod +x "$POSH_DIR/resources/scripts/posh-docker-build"
chmod +x "$POSH_DIR/resources/scripts/posh-docker-clean"
chmod +x "$POSH_DIR/resources/scripts/posh-docker-debug"

echo ""
echo "[+] Setup complete"
Expand Down
46 changes: 23 additions & 23 deletions Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Install PoshC2
echo ""
echo """
echo """
__________ .__. _________ ________
\_______ \____ _____| |__ \_ ___ \ \_____ \\\\
| ___/ _ \/ ___/ | \ / \ \/ / ____/
Expand Down Expand Up @@ -53,7 +53,7 @@ fi
echo ""
echo "[+] Installing requirements using apt"
apt-get install -y screen python3 python3-dev python3-pip build-essential mingw-w64-tools mingw-w64 mingw-w64-x86-64-dev mingw-w64-i686-dev mingw-w64-common espeak graphviz mono-complete apt-transport-https vim nano python2.7 libpq-dev curl sudo sqlite3
apt-get install -y python3.8-dev python3-distutils python3-lib2to3 python3.7-dev python3.7 2>/dev/null
apt-get install -y python3.8-dev python3-distutils python3-lib2to3 python3.7-dev python3.7 2>/dev/null

# Setting the minimum protocol to TLS1.0 to allow the python server to support TLSv1.0+
echo ""
Expand All @@ -79,27 +79,27 @@ cd "$POSH_DIR"
python3 -m pipenv --three install >/dev/null

echo ""
echo "[+] Copying useful scripts to /usr/bin"
cp "$POSH_DIR/resources/scripts/fpc" /usr/bin
cp "$POSH_DIR/resources/scripts/posh" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-server" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-config" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-log" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-service" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-stop-service" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-update" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-cookie-decrypter" /usr/bin
cp "$POSH_DIR/resources/scripts/posh-project-clean" /usr/bin
chmod +x /usr/bin/fpc
chmod +x /usr/bin/posh
chmod +x /usr/bin/posh-server
chmod +x /usr/bin/posh-config
chmod +x /usr/bin/posh-log
chmod +x /usr/bin/posh-service
chmod +x /usr/bin/posh-stop-service
chmod +x /usr/bin/posh-update
chmod +x /usr/bin/posh-cookie-decrypter
chmod +x /usr/bin/posh-project-clean
echo "[+] Symlinking useful scripts to /usr/bin"
ln -s "$POSH_DIR/resources/scripts/fpc" /usr/bin/fpc
ln -s "$POSH_DIR/resources/scripts/posh" /usr/bin/posh
ln -s "$POSH_DIR/resources/scripts/posh-server" /usr/bin/posh-server
ln -s "$POSH_DIR/resources/scripts/posh-config" /usr/bin/posh-config
ln -s "$POSH_DIR/resources/scripts/posh-log" /usr/bin/posh-log
ln -s "$POSH_DIR/resources/scripts/posh-service" /usr/bin/posh-service
ln -s "$POSH_DIR/resources/scripts/posh-stop-service" /usr/bin/posh-stop-service
ln -s "$POSH_DIR/resources/scripts/posh-update" /usr/bin/posh-update
ln -s "$POSH_DIR/resources/scripts/posh-cookie-decrypter" /usr/bin/posh-cookie-decryptor
ln -s "$POSH_DIR/resources/scripts/posh-project" /usr/bin/posh-project
chmod +x "$POSH_DIR/resources/scripts/fpc"
chmod +x "$POSH_DIR/resources/scripts/posh"
chmod +x "$POSH_DIR/resources/scripts/posh-server"
chmod +x "$POSH_DIR/resources/scripts/posh-config"
chmod +x "$POSH_DIR/resources/scripts/posh-log"
chmod +x "$POSH_DIR/resources/scripts/posh-service"
chmod +x "$POSH_DIR/resources/scripts/posh-stop-service"
chmod +x "$POSH_DIR/resources/scripts/posh-update"
chmod +x "$POSH_DIR/resources/scripts/posh-cookie-decrypter"
chmod +x "$POSH_DIR/resources/scripts/posh-project"

echo "[+] Adding service files"
cp "$POSH_DIR/resources/scripts/poshc2.service" /lib/systemd/system/poshc2.service
Expand Down
33 changes: 23 additions & 10 deletions poshc2/server/Config.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
import os, yaml, glob
import os, yaml, glob, sys
from poshc2.server.UrlConfig import UrlConfig
from poshc2.Utils import string_to_array

with open('./config.yml', 'r') as fileio:
try:
config = yaml.safe_load(fileio)
except yaml.YAMLError as e:
print("Error parsing config.yml: ", e)
if not os.path.exists(os.path.expanduser("~/.poshc2/CURRENT_PROJECT")):
print("PoshC2 current project file does not exist, please run posh-project")
sys.exit(1)

# Directory & file locations
PoshInstallDirectory = config["PoshInstallDirectory"]
PoshInstallDirectory = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + "../../../")

if not PoshInstallDirectory.endswith("/"):
PoshInstallDirectory = PoshInstallDirectory + "/"

PoshProjectDirectory = config["PoshProjectDirectory"]
with open(os.path.expanduser("~/.poshc2/CURRENT_PROJECT"), 'r') as current_project_file:
current_project = current_project_file.read().strip()

PoshProjectDirectory = os.path.expanduser(f"~/.poshc2/{current_project}")
if not PoshProjectDirectory.endswith("/"):
PoshProjectDirectory = PoshInstallDirectory + "/"

PoshProjectDirectory = PoshProjectDirectory + "/"

if not os.path.exists(f"{PoshProjectDirectory}config.yml"):
print("Current project configuration does not exist, please create it using posh-project")
sys.exit(1)

with open(f'{PoshProjectDirectory}config.yml', 'r') as config_file:
try:
config = yaml.safe_load(config_file)
except yaml.YAMLError as e:
print("Error parsing config.yml: ", e)
sys.exit(1)

ResourcesDirectory = "%sresources%s" % (PoshInstallDirectory, os.sep)
PayloadTemplatesDirectory = "%spayload-templates%s" % (ResourcesDirectory, os.sep)
BeaconDataDirectory = "%sbeacon-data%s" % (ResourcesDirectory, os.sep)
Expand Down
3 changes: 0 additions & 3 deletions config.yml → resources/config-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
# Server Config
BindIP: '0.0.0.0'
BindPort: 443
PoshInstallDirectory: "/opt/PoshC2/"
PoshProjectDirectory: "/opt/PoshC2_Project/"

# Database Config
DatabaseType: SQLite # or Postgres
PostgresConnectionString: "dbname='poshc2_project_x' port='5432' user='admin' host='192.168.111.111' password='XXXXXXX'" # Only used if Postgres in use


# Payload Comms
PayloadCommsHost: "https://127.0.0.1:443,https://127.0.0.1" # "https://www.domainfront.com:443,https://www.direct.com"
DomainFrontHeader: "127.0.0.1,127.0.0.1" # "axpejfaaec.cloudfront.net,www.direct.com"
Expand Down
24 changes: 16 additions & 8 deletions resources/scripts/fpc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ function ctrl_c() {
exit
}

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR=${POSHC2_DIR}
SCRIPT_LOCATION=`readlink -f -n $0`
POSH_DIR="`dirname $SCRIPT_LOCATION`/../../"

POSH_PROJECT=`cat $HOME/.poshc2/CURRENT_PROJECT 2>/dev/null`
if [ -z "$POSH_PROJECT" ]; then
echo "No PoshC2 project set, please run posh-project"
exit 1
fi

POSH_PROJECT_DIR="$HOME/.poshc2/$POSH_PROJECT"
if [ ! -d "$POSH_PROJECT_DIR" ]; then
echo "No PoshC2 project directory, please run posh-project"
exit 1
fi

POSH_PROJECT_DIR=`cat $POSH_DIR/config.yml | grep "PoshProjectDirectory: " | cut -d "\"" -f 2`
DATABASE_TYPE=`cat $POSH_DIR/config.yml | grep "DatabaseType: " | cut -d "\"" -f 2`
DATABASE_STRING=`cat $POSH_DIR/config.yml | grep "PostgresConnectionString: " | cut -d "\"" -f 2`
DATABASE_TYPE=`cat $POSH_PROJECT_DIR/config.yml | grep "DatabaseType: " | cut -d "\"" -f 2`
DATABASE_STRING=`cat $POSH_PROJECT_DIR/config.yml | grep "PostgresConnectionString: " | cut -d "\"" -f 2`

pushd "$POSH_DIR" >/dev/null

Expand All @@ -25,4 +33,4 @@ if [ "$?" -eq "0" ]; then
python3 -m pipenv run python3 "resources/scripts/fpc.py" -p "$POSH_PROJECT_DIR" -d "$DATABASE_TYPE" -pg "$DATABASE_STRING" $@
popd > /dev/null

fi
fi
7 changes: 2 additions & 5 deletions resources/scripts/posh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ function ctrl_c() {
exit
}

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR=${POSHC2_DIR}
fi
SCRIPT_LOCATION=`readlink -f -n $0`
POSH_DIR="`dirname $SCRIPT_LOCATION`/../../"

pushd "$POSH_DIR" >/dev/null

Expand Down
20 changes: 13 additions & 7 deletions resources/scripts/posh-config
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR=${POSHC2_DIR}
POSH_PROJECT=`cat $HOME/.poshc2/CURRENT_PROJECT 2>/dev/null`
if [ -z "$POSH_PROJECT" ]; then
echo "No PoshC2 project set, please run posh-project"
exit 1
fi

POSH_PROJECT_DIR="$HOME/.poshc2/$POSH_PROJECT"
if [ ! -d "$POSH_PROJECT_DIR" ]; then
echo "No PoshC2 project directory, please run posh-project"
exit 1
fi

if [[ "$EDITOR" != "" ]]; then
sudo $EDITOR "$POSH_DIR/config.yml"
sudo $EDITOR "$POSH_PROJECT_DIR/config.yml"
elif [[ "$*" == *"--nano"* ]]; then
sudo nano "$POSH_DIR/config.yml"
sudo nano "$POSH_PROJECT_DIR/config.yml"
else
sudo vim "$POSH_DIR/config.yml"
sudo vim "$POSH_PROJECT_DIR/config.yml"
fi
11 changes: 4 additions & 7 deletions resources/scripts/posh-cookie-decrypter
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ function ctrl_c() {
popd > /dev/null
exit
}

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR=${POSHC2_DIR}
fi

SCRIPT_LOCATION=`readlink -f -n $0`
POSH_DIR="`dirname $SCRIPT_LOCATION`/../../"

pushd $POSH_DIR >/dev/null
if [ "$?" -eq "0" ]; then

sudo python3 -m pipenv run python3 "$POSH_DIR/cookie_decrypter.py"
popd > /dev/null

fi
fi

14 changes: 1 addition & 13 deletions resources/scripts/posh-docker
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#!/bin/bash

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR="${POSHC2_DIR}"
fi

POSH_PROJECT_DIR=`cat $POSH_DIR/config.yml | grep "PoshProjectDirectory: " | cut -d "\"" -f 2`

if [[ ! -d "$POSH_PROJECT_DIR" ]]; then
sudo mkdir -p "$POSH_PROJECT_DIR"
fi

sudo -E docker run -ti --rm -v "$POSH_PROJECT_DIR:$POSH_PROJECT_DIR" -v "$POSH_DIR:$POSH_DIR" -e POSHC2_DIR="${POSH_DIR}" nettitude/poshc2 /usr/bin/posh "$@"
sudo -E docker run -ti --rm -v "$HOME/.poshc2:/root/.poshc2" m0rv4i/poshc2 /usr/bin/posh "$@"
13 changes: 5 additions & 8 deletions resources/scripts/posh-docker-build
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ function ctrl_c() {
popd > /dev/null
exit
}

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR="${POSHC2_DIR}"
fi

SCRIPT_LOCATION=`readlink -f -n $0`
POSH_DIR="`dirname $SCRIPT_LOCATION`/../../"

pushd "$POSH_DIR" >/dev/null

if [ "$?" -eq "0" ]; then
posh-docker-clean
sudo -E docker build -t nettitude/poshc2 . "$@"
sudo -E docker build -t m0rv4i/poshc2 . "$@"
popd > /dev/null
fi
fi

20 changes: 1 addition & 19 deletions resources/scripts/posh-docker-debug
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
#!/bin/bash

if [[ "$1" -ne "" ]]; then
port="$1"
else
port="443"
fi

if [[ -z "${POSHC2_DIR}" ]]; then
POSH_DIR="/opt/PoshC2"
else
POSH_DIR="${POSHC2_DIR}"
fi

POSH_PROJECT_DIR=`cat $POSH_DIR/config.yml | grep "PoshProjectDirectory: " | cut -d "\"" -f 2`

if [[ ! -d "$POSH_PROJECT_DIR" ]]; then
mkdir -p "$POSH_PROJECT_DIR"
fi

sudo -E docker run -ti --rm -v "$POSH_PROJECT_DIR:$POSH_PROJECT_DIR" -v "$POSH_DIR:$POSH_DIR" -e POSHC2_DIR="${POSH_DIR}" nettitude/poshc2 /bin/bash
sudo -E docker run -ti --rm -v "$HOME/.poshc2:/root/.poshc2" m0rv4i/poshc2 /bin/bash

Loading

0 comments on commit c8d7c9a

Please sign in to comment.