A fake DNS server for malware analysis written in Python3
Project description
FakeDNS
A fake DNS server for malware analysis written in Python3.
In contrast to other fakedns scripts, this one supports not only answering all requests with the same IP as answer. It is flexible and configurable to fit the needs of an analyst, and includes the following features:
- Supported RR Types: A, AAAA, PTR, TXT
- Respond to incoming queries based on a predefined configuration which allows pattern matching on domain names
- Proxy DNS queries to a predefined DNS server
- A CLI-tool which simplifies config editing (in particular a baseline script which allows ignoring noise in further analysis)
This fakedns script is implemented on basis of the Python3 package dns-messages
which implements parsing and generating DNS packages.
Installation
Install the package with pip:
pip3 install fakedns
Setup & Configuration with fakedns-config
The fakedns script requires a config file for running. If you don't specify a config file, fakedns tries to load the global config from one of the following two locations (depending on your OS):
- %ProgramData%\fakedns\global.conf (Windows)
- /etc/fakedns/global.conf (Linux)
The fakedns-config CLI-tool simplifies the creation and editing config files for fakedns. It accepts the following commands and parameters:
fakedns-config help
> displays the help page with detailed command descriptions
fakedns-config edit [<path_to_config>]
> opens a text editor to edit the config file manually
fakedns-config init [<path_to_config>]
> create a new default config
fakedns-config fork [<path_to_new_config_file>]
> copies the global config file and saves it at the
> given location. Useful if config has to be temporarily
> customized for a special use case
fakedns-config pattern add [<path_to_config>]
> a new pattern is added to the config interactively
> so that the config has not to be changed manually
fakedns-config pattern show [<path_to_config>]
> lists all patterns which the config file contains
> in a table format which makes it suitable to quickly
> check the correctness of the used patterns and their
> attributes
fakedns-config pattern baseline [<path_to_config>]
> listens to incoming queries and whitelists all received
> query patterns in the selected config file until the
> user aborts the process via Strg + C.
> This command makes it easy to create a baseline
> and filter out the "normal" noise from a machine of interest
> (e.g. baseline the DNS-requests made from a Windows machine
> in a laboratory environment before executing malware on the
> machine - in this way only requests are shown which were
> triggered by the malware)
Note:
If no path to config file is given the default location of the global config is used, which is
/etc/fakedns/global.conf (in Linux) or %ProgramData%\fakedns\global.conf (in Windows)
By entering fakedns-config init a default config is created in the default location mentioned above.
To view the existing patterns in this new config use fakedns-config pattern show.
Adding a new pattern manually can either be done by editing the config file directly or by executing fakedns-config pattern add.
Structure of a pattern in the config
A section of a pattern in the config starts with the [DomainPattern] tag followed by the specified options.
Possible options:
prioritythe lower the priority the earlier the pattern will be checked for a match. If one pattern matches, all the following patterns will not be checked. So the priority for the default pattern should be a high number, and for patterns of a baseline it should be a low number.name_patternpattern to match an incoming domain name of a query.*can be used as wildcard.log_requestdefines if a query should be logged. Possible values areyesandno. This option is useful to suppress noise from baseline patterns in the logs while enabling logging for a default (catch-all) patterntype_filtera list of query types this pattern should match; should be comma-separated, e.g.A,AAAAmatches only queries forAandAAAArecords - other types are ignoredproxy_queriesproxy this query to a predefined DNS server. Possible values areyesandno.not_existing_domainrespond to queries with annxdomainerror. Possible values areyesandno.ttltime to live for the RR of an answer, in secondsanswer_AIP address of theArecord. The default value isDefaultIPv4whose value is defined in the config file.answer_AAAAIP address of theAAAArecord. The default value isDefaultIPv6whose value is defined in the config file.answer_PTRdomain name of thePTRrecord
Output formatting
It is also possible to configure the output of fakedns in the config file.
The attribute format defines the general structure of one log line. response_format defines the output if an answer contains a RR within the %RESPONSE% log.
The possible placeholders are:
# defines the output of fakedns
# available placeholders are:
# - %DATETIME%
# - %RR_TYPE% (from the query)
# - %RR_CLASS% (from the query)
# - %DOMAINNAME% (from the query)
# - %RESPONSE%
# - %TTL% (from the response)
format = %DATETIME% - %RR_TYPE% - %DOMAINNAME% => %RESPONSE%
# - %TTL%
# - %RR_VALUE%
response_format = %RR_VALUE%
An example for log lines produced by fakedns using the default config:
[+] 2022-02-20 08:17:58 - PTR - 1.96.18.172.in-addr.arpa => Response: fakedns.com
[+] 2022-02-20 08:17:58 - AAAA - example.com => Response: No Record
[+] 2022-02-20 08:24:40 - AAAA - google.com => Response (from Proxy): 2a00:1450:4016:809::200e
Creating a baseline
To create a baseline type fakedns-config pattern baseline.
Then you can specify how the generated patterns should be handled.
For example, it could be useful to proxy all baseline patterns or not respond to them at all, depending on your needs.
Start fakedns
To start the fakedns script just type fakedns :smiley:
The following excerpt from the help page shows all CLI argument options:
usage: fakedns [OPTIONS...]
fakedns is a script which mimicks DNS resolution
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
path to config file (if not set the default global one is used)
--log-query-only-once
prevents that the same query is logged multiple times
--log-domain-only-once
prevents that the same domain name is logged multiple times
--nxdomain-response respond to all queries with an nxdomain response (overrides settings from the config)
--no-response do not respond to any queries (overrides settings from the config)
--proxy proxy all incoming queries (overrides settings from the config)
--verbose logs more details of each queries
--version shows version info
foo@bar:~$ fakedns
[+] fakedns starts listening on 172.18.96.1:53
[+] 2022-02-20 08:17:58 - PTR - 1.96.18.172.in-addr.arpa => Response: fakedns.com
[+] 2022-02-20 08:17:58 - A - example.com => Response: 172.18.96.1
[+] 2022-02-20 08:17:58 - AAAA - example.com => Response: No Record
[+] 2022-02-20 08:18:00 - TXT - example.com => Response: No Record
[+] 2022-02-20 08:24:40 - A - google.com => Response (from Proxy): 142.251.36.206
[+] 2022-02-20 08:24:40 - AAAA - google.com => Response (from Proxy): 2a00:1450:4016:809::200e
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fakedns-1.2.tar.gz.
File metadata
- Download URL: fakedns-1.2.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fa0d445fe1b9a0e31ca4e41f72501b369b56a5b7abf98b83157c723bf8c4055
|
|
| MD5 |
73623d72befb5890796c57693c55a5c5
|
|
| BLAKE2b-256 |
ca790255f68b0e6a7e924093ae070e850aecb055f8ea03f2af601ca54b942972
|
File details
Details for the file fakedns-1.2-py3-none-any.whl.
File metadata
- Download URL: fakedns-1.2-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e496f74bfa0cbebdd921627349c63e4bb35bd3a50b7202750709ee7bf1c47b2
|
|
| MD5 |
1a4e7777bb698cf173a9e36c572d93e7
|
|
| BLAKE2b-256 |
8e68384cb2c66e1ac9a583bf89e079227937efb9900c2469e25bdde1308f20a5
|