Skip to main content

Command & Control Trojan With Python


INTRODUCTION
Command and Control Trojan : With this Trojan we will be able to asynchronously control ,udpate and recieve data from deployed implants.So we will use Github as a way to store implant configuration information and exfiltrated data as well as any modules that the implanted needs in order to execute tasks.Since Github is encrypted over SSL ,and there are very few enterprises which might have blocked github itself.
Let's have a walkthrough of the code on how we can build our github based command and control trojan from scratch.
NOTE : you can integrate any module or features availble in this hacking scripts like keylogger ,backdoor etc with this Trojan
##
Required Libraries :
github3 : To connect authenticate and communicate between the trojan and the attacker via github repo which holds the configuration file
threading : To perform some task in threads
os : To runs some system commands
importlib : to import the library if not exist
base64 : to perform the hash encoding operation

##
First step will be to build the necessary code to handle (Connecting ,Authentication ,Communicating) via Github Api.
'trojan_id' variable which generally uniquely identifies this trojan .So Let's say if sometime at point we want to explode this technique out to a full botnet ,you'd want the capability to generate trojans ,set their ID ,automatically create config file that's pushed to GitHub and then compile the code into executable form.

##
This function first authenticates the user to the repository ,and retrieves the current 'repo' and 'branch' objects for use by other function.
once you write the code ,you have to set your username and password in the args and as well as the repository name.
Do make sure that your this repository is private.

##
This function fetch the files from the repository and then read as This is used both for reading configuration options as well as reading module source code.

##
This Method is responsible for retrieving the remote configuration docs from the repository so that our trojan knows which modules to run.
The idea here is that ,let's say you have deployed this trojan to victim's system and you decide that trojan should perform the different task ,then you can simply change the configuration file and ask the trojan to perform different Task. That's why this trojan is known as command and control trojan since we can control the action trojan by changing the configuration file which you have stored in your repository.

##
This method is used to push data that Trojan have collected on the target machine.Since Trojan will upload the data in your specified repository path.

##
Every time the interpreter attempts to load a module that isn't available ,GitImporter class is used. 'find_module' function is called in an attempt to locate the module .We will pass this call to our remote file loader ,as if we can locate this file in our repository ,we base64decode the code and store it in our class and return self ,it means we indicate to the python interepreter that we found the module and then we can proceed to call 'load_module()' to actually load it. Then in-order to import it we will use native imp module to create new empty module object and then shovel the code we retrieved from Github into that new empty object.And then the last step will be to add the module in 'sys.modules' list.

##
Firstly add the custom module importer before we begin our main-loop of this Trojan.
Then the execution of the Tojan is as follows :
Grab the configuration file from the repository and then we kick off the module in its own thread and while we're in the 'module_runner' function ,we simply call the module's run function to kick off its code. Then Tojan will collect the data acc to configuration file using dirlister which will help to iterate over the directories and will push to our Private github repository.


You can find the full code along with configuration file in the following github link : cmd_cntrl_trojan



Checkout some more hacking scripts


SECURING SYSTEM BLUETOOTH ATTACKS STEALING AND SNIFFING ATTACKS KALI LINUX HACKING COMMANDS CHEATSHEET TROJAN AND BACKDOORS DICTIONARY AND BURTEFORCING ATTACKS MAN IN THE MIDDLE ATTACKS
1. Sign & Verify message 1. Bluetooth discovery 1. Stealing saved wifi password from windows 1. Pentesting commands with Kali Linux 1. Command and Control Trojan 1. Dictionary Attack 1. Man in Browser Attack
2. SandBox Detection 2. Bluetooth SDP browsing 2. Sniffing packets 2. Reverse shell in python
3. TCP Proxy 3. Bluetooth OBEX 3. Email Credential sniffers 3. Keylogger
4. Bluetooth RCOMM channel scanner 4. Screenshot with Python
5. Blue Bug Exploit 5. Backdoor with Python
6. Blue Snarf Exploit
7. Bluetooth spoofing
8. Bluetooth sniffing