Skip to content

Commit bb86342

Browse files
authored
Merge pull request #3
Merge Public Release
2 parents a040c3f + 33c6058 commit bb86342

25 files changed

+1427
-465
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,6 @@ dmypy.json
223223

224224
# Cython debug symbols
225225
cython_debug/
226+
227+
# Project-specific files
228+
client.cfg

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [1.0.0] - 2021-11-19
8+
- Public release

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Python 3 HTTPS Reverse Shell
2+
3+
![Python Version](https://img.shields.io/badge/python-3.9+-blue?style=for-the-badge&logo=python)
4+
![OS](https://img.shields.io/badge/GNU%2FLinux-red?style=for-the-badge&logo=linux)
5+
![OS](https://img.shields.io/badge/Windows-blue?style=for-the-badge&logo=windows)
6+
7+
[![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)
8+
[![License](https://img.shields.io/github/license/EONRaider/BCA-HTTPS-Reverse-Shell?style=for-the-badge)](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/blob/master/LICENSE)
9+
10+
[![Reddit](https://img.shields.io/badge/Reddit-EONRaider-FF4500?style=flat-square&logo=reddit)](https://www.reddit.com/user/eonraider)
11+
[![Discord](https://img.shields.io/badge/Discord-EONRaider-7289DA?style=flat-square&logo=discord)](https://discord.gg/KVjWBptv)
12+
[![Twitter](https://img.shields.io/badge/Twitter-eon__raider-38A1F3?style=flat-square&logo=twitter)](https://twitter.com/intent/follow?screen_name=eon_raider)
13+
14+
A **cross-platform HTTPS Reverse Shell** server and client in Python 3. Binaries for
15+
Linux and Windows platforms can be built through an embedded script that implements
16+
PyInstaller.
17+
18+
This application also includes a helper shell script that enables fast generation of
19+
self-signed certificates for use of both servers and clients. After generation, the
20+
server and certificate authority certificates required for encrypted connections
21+
are bundled in the binaries for portability and ease of execution.
22+
23+
## Try it out!
24+
If you just need to see the tool in action on a local environment, simply head over
25+
to the [demo-files](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/tree/master/demo-files)
26+
directory and download the pre-built Linux/Unix/macOS or Windows binaries.
27+
28+
The files are all bundled with certificates for `localhost` and work straight out-of-the-box. *Just
29+
set them with permissions to execute and run.*
30+
31+
## Build
32+
Encrypted communication through HTTPS requires at least two certificates: One for
33+
the server, named `server.pem` by default, and another for the certificate authority, or `ca.pem`.
34+
This HTTPS Reverse Shell bundles both files in binaries for fast deployment. They can be
35+
generated by [multiple methods](https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs)
36+
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.
37+
38+
Once the certificates are ready you only need to (I) install the dependencies and (II)
39+
run `build.py` to build the `server` and `client` binaries.
40+
41+
### I. Install Dependencies
42+
Dependency management works with both [Poetry](https://python-poetry.org/) (recommended)
43+
and [Virtualenv](https://virtualenv.pypa.io/en/latest/)
44+
```shell
45+
git clone https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell.git
46+
cd BCA-HTTPS-Reverse-Shell
47+
poetry install <--or--> pip install -r requirements.txt
48+
```
49+
50+
### II. Build Server and Client binaries
51+
The `build.py` file takes care of it all.
52+
```shell
53+
python build.py server --server-cert /path/to/server.pem
54+
python build.py client --ca-cert /path/to/ca.pem
55+
```
56+
57+
## Usage
58+
![usage](https://github.com/EONRaider/static/blob/97b0e81aee6eb0f2b255a26cd138299e2361d025/https-reverse-shell/usage.gif)
59+
60+
## Development mode (optional)
61+
You could optionally run the HTTPS Reverse Shell directly from a local Python 3
62+
interpreter. [Install all dependencies](https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell/tree/master#i-install-dependencies)
63+
and run the `server.py` and `client.py` files. All required certificates will be
64+
automatically generated for `localhost`.
65+
66+
Execute the **Server** on one shell...
67+
```shell
68+
python src/server/server.py localhost 4443
69+
```
70+
71+
... And the **Client** on another shell:
72+
```shell
73+
python src/client/client.py \
74+
--host localhost \
75+
--port 4443 \
76+
--ca-cert src/server/ca.pem
77+
```
78+
79+
## Legal Disclaimer
80+
81+
The use of code contained in this repository, either in part or in its totality,
82+
for engaging targets without prior mutual consent is illegal. **It is
83+
the end user's responsibility to obey all applicable local, state and
84+
federal laws.**
85+
86+
Developers assume **no liability** and are not
87+
responsible for misuses or damages caused by any code contained
88+
in this repository in any event that, accidentally or otherwise, it comes to
89+
be utilized by a threat agent or unauthorized entity as a means to compromise
90+
the security, privacy, confidentiality, integrity, and/or availability of
91+
systems and their associated resources. In this context the term "compromise" is
92+
henceforth understood as the leverage of exploitation of known or unknown vulnerabilities
93+
present in said systems, including, but not limited to, the implementation of
94+
security controls, human- or electronically-enabled.
95+
96+
The use of this code is **only** endorsed by the developers in those
97+
circumstances directly related to **educational environments** or
98+
**authorized penetration testing engagements** whose declared purpose is that
99+
of finding and mitigating vulnerabilities in systems, limiting their exposure
100+
to compromises and exploits employed by malicious agents as defined in their
101+
respective threat models.

build.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python3
2+
# https://github.com/EONRaider/BCA-HTTPS-Reverse-Shell
3+
4+
__author__ = "EONRaider @ keybase.io/eonraider"
5+
6+
import argparse
7+
import configparser
8+
import functools
9+
import platform
10+
from pathlib import Path
11+
from typing import Container
12+
13+
import PyInstaller.__main__
14+
15+
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+
23+
def pyinstaller(func):
24+
"""Decorator that takes a container of strings returned by a
25+
function and passes them as arguments to the PyInstaller runner."""
26+
@functools.wraps(func)
27+
def build_binary(*args, **kwargs):
28+
cmd: Container[str] = func(*args, **kwargs)
29+
PyInstaller.__main__.run(cmd)
30+
return build_binary
31+
32+
33+
@pyinstaller
34+
def server(args: argparse.Namespace) -> list[str]:
35+
"""Set-up the arguments required by PyInstaller to build the
36+
server binary."""
37+
cmd = ["server/server.py", "--onefile"]
38+
if args.server_cert is not None:
39+
cmd.extend(["--add-data", f"{args.server_cert}{os_sep()}."])
40+
return cmd
41+
42+
43+
@pyinstaller
44+
def client(args: argparse.Namespace) -> list[str]:
45+
"""Set-up the arguments required by PyInstaller to build the
46+
client binary."""
47+
48+
'''A configuration file named 'client.cfg' is created with
49+
hard-coded server address, port and CA information that allows
50+
seamless connection of the binary client to the server. This file
51+
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}."]
67+
68+
return cmd
69+
70+
71+
if __name__ == "__main__":
72+
parser = argparse.ArgumentParser()
73+
subparsers = parser.add_subparsers()
74+
75+
server_parser = subparsers.add_parser("server")
76+
server_parser.add_argument(
77+
"--server-cert",
78+
type=str,
79+
metavar="<path>",
80+
help="Path to a file containing the server certificate in PEM format. "
81+
"This certificate will be packaged with the compiled server "
82+
"binary for deployment."
83+
)
84+
server_parser.set_defaults(func=server)
85+
86+
client_parser = subparsers.add_parser("client")
87+
client_parser.add_argument(
88+
"host",
89+
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."
98+
)
99+
client_parser.add_argument(
100+
"--ca-cert",
101+
type=str,
102+
metavar="<path>",
103+
help="Path to a file containing the certificate for the Certificate "
104+
"Authority (CA) in PEM format. This certificate will be packaged "
105+
"with the compiled client binary for deployment."
106+
)
107+
client_parser.set_defaults(func=client)
108+
109+
_args = parser.parse_args()
110+
_args.func(_args)

demo-files/client

6.92 MB
Binary file not shown.

demo-files/client.exe

6.64 MB
Binary file not shown.

demo-files/server

10.8 MB
Binary file not shown.

demo-files/server.exe

8.82 MB
Binary file not shown.

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
altgraph==0.17.2
2+
cffi==1.15.0
3+
cryptography==35.0.0
4+
idna==3.3
5+
pycparser==2.21
6+
pyinstaller==4.7
7+
pyinstaller-hooks-contrib==2021.3
8+
trustme==0.9.0

src/build.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/ca.pem

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)