Git Product home page Git Product logo

flare-fakenet-ng's Introduction

 ______      _  ________ _   _ ______ _______     _   _  _____
|  ____/\   | |/ /  ____| \ | |  ____|__   __|   | \ | |/ ____|
| |__ /  \  | ' /| |__  |  \| | |__     | |______|  \| | |  __
|  __/ /\ \ |  < |  __| | . ` |  __|    | |______| . ` | | |_ |
| | / ____ \| . \| |____| |\  | |____   | |      | |\  | |__| |
|_|/_/    \_\_|\_\______|_| \_|______|  |_|      |_| \_|\_____|

       D   O   C   U   M   E   N   T   A   T   I   O   N

FakeNet-NG 3.2 is a next generation dynamic network analysis tool for malware analysts and penetration testers. It is open source and designed for the latest versions of Windows (and Linux, for certain modes of operation). FakeNet-NG is based on the excellent Fakenet tool developed by Andrew Honig and Michael Sikorski.

The tool allows you to intercept and redirect all or specific network traffic while simulating legitimate network services. Using FakeNet-NG, malware analysts can quickly identify malware's functionality and capture network signatures. Penetration testers and bug hunters will find FakeNet-NG's configurable interception engine and modular framework highly useful when testing application's specific functionality and prototyping PoCs.

Installation

You can install FakeNet-NG in a few different ways. Note that the following installation processes will retrieve third-party open-source libraries used by FakeNet-NG to your system. These libraries will be dynamically loaded at runtime, and some of these libraries may be LGPL licensed.

Stand-alone executable

It is easiest to simply download the compiled version which can be obtained from the releases page:

https://github.com/mandiant/flare-fakenet-ng/releases

Execute FakeNet-NG by running 'fakenet.exe'.

This is the preferred method for using FakeNet-NG on Windows as it does not require you to install any additional modules, which is ideal for a malware analysis machine.

Installing module

Installation on Linux requires the following dependencies:

  • Python pip package manager (e.g. python-pip for Ubuntu).
  • Python development files (e.g. python-dev for Ubuntu).
  • OpenSSL development files (e.g. libssl-dev for Ubuntu).
  • libffi development files (e.g. libffi-dev for Ubuntu).
  • libnetfilterqueue development files (e.g. libnetfilter-queue-dev for Ubuntu).

Install these dependencies using the following command:

sudo apt-get install build-essential python-dev libnetfilter-queue-dev

Install FakeNet-NG as a Python module using pip:

pip install https://github.com/mandiant/flare-fakenet-ng/zipball/master

Or by obtaining the latest source code and installing it manually:

git clone https://github.com/mandiant/flare-fakenet-ng/

Change directory to the downloaded flare-fakenet-ng and run:

python setup.py install

Execute FakeNet-NG by running 'fakenet' in any directory.

No installation

Finally if you would like to avoid installing FakeNet-NG and just want to run it as-is (e.g. for development), then you would need to obtain the source code and install dependencies as follows:

  1. Install 64-bit or 32-bit Python 3.7.x for the 64-bit or 32-bit versions of Windows respectively.

  2. Install Python dependencies:

    pip install pydivert dnslib dpkt pyopenssl pyftpdlib netifaces

    NOTE: pydivert will also download and install WinDivert library and driver in the %PYTHONHOME%\DLLs directory. FakeNet-NG bundles those files so they are not necessary for normal use.

2b) Optionally, you can install the following module used for testing:

pip install requests
  1. Download the FakeNet-NG source code:

    git clone https://github.com/mandiant/flare-fakenet-ng

Execute FakeNet-NG by running it with a Python interpreter in a privileged shell:

python -m fakenet.fakenet

Usage

The easiest way to run FakeNet-NG is to simply execute the provided executable as an Administrator. You can provide --help command-line parameter to get simple help:

C:\tools\fakenet-ng>fakenet.exe --help
  ______      _  ________ _   _ ______ _______     _   _  _____
 |  ____/\   | |/ /  ____| \ | |  ____|__   __|   | \ | |/ ____|
 | |__ /  \  | ' /| |__  |  \| | |__     | |______|  \| | |  __
 |  __/ /\ \ |  < |  __| | . ` |  __|    | |______| . ` | | |_ |
 | | / ____ \| . \| |____| |\  | |____   | |      | |\  | |__| |
 |_|/_/    \_\_|\_\______|_| \_|______|  |_|      |_| \_|\_____|

                         Version  3.2
  _____________________________________________________________
                   Developed by FLARE Team
    Copyright (C) 2016-2024 Mandiant, Inc. All rights reserved.
  _____________________________________________________________
Usage: python -m fakenet.fakenet [options]:

Options:
  -h, --help            show this help message and exit
  -c FILE, --config-file=FILE
                        configuration filename
  -v, --verbose         print more verbose messages.
  -l LOG_FILE, --log-file=LOG_FILE

As you can see from the simple help above it is possible to configure the configuration file used to start FakeNet-NG. By default, the tool uses configs\default.ini; however, it can be changed with the -c parameter. There are several example configuration files in the configs directory. Due to the large number of different settings, FakeNet-NG relies on the configuration files to control its functionality.

NOTE: FakeNet-NG will attempt to locate the specified configuration file, first by using the provided absolute or relative path in case you want to store all of your configurations. If the specified configuration file is not found, then it will try to look in its configs directory.

The rest of the command-line options allow you to control the amount of logging output displayed as well as redirecting it to a file as opposed to dumping it on the screen.

Simple run

Before we dive in and run FakeNet-NG let's go over a few basic concepts. The tool consists of several modules working together. One such important module is the Diverter which is responsible for redirecting traffic to a collection of listeners. The Diverter forces applications to interact with FakeNet-NG as opposed to real servers. Listeners are individual services handling incoming connections and allowing us to examine application's traffic (e.g. malware signatures).

Let's launch FakeNet-NG using default settings by running the following command:

C:\tools\fakenet-ng>fakenet.exe

Below is the annotated output log illustrating a sample intercepted DNS request and an HTTP connection:

  ______      _  ________ _   _ ______ _______     _   _  _____
 |  ____/\   | |/ /  ____| \ | |  ____|__   __|   | \ | |/ ____|
 | |__ /  \  | ' /| |__  |  \| | |__     | |______|  \| | |  __
 |  __/ /\ \ |  < |  __| | . ` |  __|    | |______| . ` | | |_ |
 | | / ____ \| . \| |____| |\  | |____   | |      | |\  | |__| |
 |_|/_/    \_\_|\_\______|_| \_|______|  |_|      |_| \_|\_____|

                         Version  3.2
  _____________________________________________________________
                   Developed by FLARE Team
    Copyright (C) 2016-2024 Mandiant, Inc. All rights reserved.
  _____________________________________________________________

07/06/16 10:20:52 PM [           FakeNet] Loaded configuration file: configs/default.ini
                                                                        /
                                            default configuration file /

07/06/16 10:20:52 PM [          Diverter] Capturing traffic to packets_20160706_222052.pcap
                                                                        /
                                                      PCAP output file /

07/06/16 10:20:52 PM [           FakeNet] Anonymous Forwarder listener on TCP port 8080...
                                    \
                                     \ Anonymous Listener rule

07/06/16 10:20:52 PM [    RawTCPListener] Starting...
07/06/16 10:20:52 PM [    RawUDPListener] Starting...
07/06/16 10:20:52 PM [  FilteredListener] Starting...
07/06/16 10:20:52 PM [        DNS Server] Starting...
07/06/16 10:20:52 PM [    HTTPListener80] Starting...
07/06/16 10:20:52 PM [   HTTPListener443] Starting...
07/06/16 10:20:52 PM [      SMTPListener] Starting...
07/06/16 10:20:52 PM [          Diverter] Starting...
                                       \
                                        \ Listeners starting up

07/06/16 10:20:52 PM [          Diverter] Diverting ports:
07/06/16 10:20:52 PM [          Diverter] TCP: 1337, 80, 443, 25
07/06/16 10:20:52 PM [          Diverter] UDP: 1337, 53
                                          /
               Summary of diverted ports /

07/06/16 10:21:03 PM [          Diverter] Modifying outbound external UDP request packet:
07/06/16 10:21:03 PM [          Diverter]   from: 192.168.250.140:49383 -> 4.2.2.1:53
07/06/16 10:21:03 PM [          Diverter]   to:   192.168.250.140:49383 -> 192.168.250.140:53
07/06/16 10:21:03 PM [          Diverter]   pid:  456 name: malware.exe
                                                            /
    Intercepted traffic to the DNS server from malware.exe /

07/06/16 10:21:03 PM [        DNS Server] Received A request for domain 'evil.com'.
                                       \
                                        \ Fake DNS Listener handling the above request

07/06/16 10:21:04 PM [          Diverter] Modifying outbound external TCP request packet:
07/06/16 10:21:04 PM [          Diverter]   from: 192.168.250.140:2179 -> 192.0.2.123:80
07/06/16 10:21:04 PM [          Diverter]   to:   192.168.250.140:2179 -> 192.168.250.140:80
07/06/16 10:21:04 PM [          Diverter]   pid:  456 name: malware.exe
                                                            /
    Intercepted traffic to the web server from malware.exe /

07/06/16 10:21:08 PM [    HTTPListener80] Received a GET request.
07/06/16 10:21:08 PM [    HTTPListener80] --------------------------------------------------------------------------------
07/06/16 10:21:08 PM [    HTTPListener80] GET / HTTP/1.0
07/06/16 10:21:08 PM [    HTTPListener80]
07/06/16 10:21:08 PM [    HTTPListener80] --------------------------------------------------------------------------------
                                       \
                                        \ Fake HTTP Listener handling the above request

Notice that each log line has a name of the currently running FakeNet-NG modules. For example, when it is diverting traffic, the logs will be prefixed with the Diverter label:

07/06/16 10:21:03 PM [          Diverter] Modifying outbound external UDP request packet:
07/06/16 10:21:03 PM [          Diverter]   from: 192.168.250.140:49383 -> 4.2.2.1:53
07/06/16 10:21:03 PM [          Diverter]   to:   192.168.250.140:49383 -> 192.168.250.140:53
07/06/16 10:21:03 PM [          Diverter]   pid:  456 name: malware.exe

At the same time, whenever individual listeners are handling diverted traffic, logs will be labeled with the name set in the configuration file:

07/06/16 10:21:03 PM [        DNS Server] Received A request for domain 'evil.com'.

To stop FakeNet-NG and save the generated PCAP file and HTML report to disk simply press CTRL-C:

07/06/16 10:21:41 PM [           FakeNet] Stopping...
07/06/16 10:21:42 PM [    HTTPListener80] Stopping...
07/06/16 10:21:42 PM [   HTTPListener443] Stopping...
07/06/16 10:21:42 PM [      SMTPListener] Stopping...
07/06/16 10:21:43 PM [          Diverter] Stopping...
07/06/16 10:21:43 PM [          Diverter] Generated new HTML report: report_20160607_102143.html

User Interface

With each session of FakeNet-NG, an HTML report containing the Network-Based Indicators (NBIs) captured throughout the session is generated. Upon termination of FakeNet by pressing CTRL-C, this HTML file will be saved to the root directory of FakeNet. A user can review the NBIs by viewing this HTML file in a browser such as Chrome or Firefox.

The HTML report serves as an interactive Graphical User Interface (GUI) that presents the NBI summary in a user-friendly manner. It includes various features to select, filter, and copy NBIs, making network analysis easier. The UI organizes all NBIs based on their process information and then further categorizes them by the application layer or transport layer protocol they use.

NBI Summary Table

The information in the NBI summary table is presented in a tabular format and includes the following details:

  • Select: Clicking on the checkbox selects the corresponding NBI. You can select multiple NBIs across different or the same protocols. The entire row can also be selected by clicking anywhere within the row. Selected NBIs can be copied using the "Copy Selected NBIs" button.

  • NBI: This cell represents the actual captured NBI. It includes commands, parameters, URIs, and other significant activity generated by the client against the listener. This cell summarizes malware behavior for better understanding.

  • Additional Information: This cell provides extra information about each NBI request such as the transport layer protocol used, destination IP, port, and SSL encryption.

  • Actions: This cell allows you to perform actions on individual NBIs. Currently, only copying is supported. Clicking the copy button copies the specific NBI cell data in a markdown format suitable for creating reports.

Interactive Features

The UI also includes various interactive features:

  • Checkbox Selection: Checkboxes are available before each process and protocol block. Ticking a checkbox selects all NBIs under that process or protocol. This is useful when you want to select all NBIs from a particular process or protocol. You can then use the Copy Selected NBIs button to copy the selected data.

  • Search Bar: The search bar lets you type keywords, and only the rows containing these keywords in the process name, NBI, or additional information will be displayed in the HTML page. You can then use the "Copy Filtered Data" button to copy the displayed data in markdown format. Clearing the search query restores the original table view.

  • Copy Buttons:

    • Copy Selected Data: Copies all the selected NBIs in markdown format. You can select individual NBIs or all NBIs under a process by ticking checkboxes.
    • Copy Filtered Data: Copies the filtered NBIs' data in markdown format. If no search query is used, this button copies the entire data.
    • Copy All NBIs: Copies all the NBIs in markdown format present in the HTML page. Even if a filter is applied, clicking this button copies all NBIs.
  • Disclaimer Button: Displays the disclaimer, which outlines important facts for the user to consider before making assumptions about the displayed NBI summary.

  • Go To Top Button: Appears when the page's content exceeds the viewable area. Clicking this button takes you to the top of the page, where you can access important buttons like Copy Selected NBIs, Copy All NBIs, Copy Filtered NBIs, and the search bar.

Configuration

In order to take full advantage of FakeNet-NG's capabilities we must understand its configuration file structure and settings. Below is a sample configuration file:

###############################################################################
# Fakenet Configuration

[FakeNet]

DivertTraffic: Yes

###############################################################################
# Diverter Configuration

[Diverter]

NetworkMode:            Auto

LinuxRedirectNonlocal:  *
LinuxFlushIptables:     Yes
LinuxFlushDNSCommand:   service dns-clean restart

DumpPackets:            Yes
DumpPacketsFilePrefix:  packets

ModifyLocalDNS:         No
StopDNSService:         Yes

RedirectAllTraffic:     Yes
DefaultTCPListener:     RawTCPListener
DefaultUDPListener:     RawUDPListener

###############################################################################
# Listener Configuration

[DNS Server]
Enabled:     True
Port:        53
Protocol:    UDP
Listener:    DNSListener
DNSResponse: 192.0.2.123
NXDomains:   0
Hidden:      False

[RawTCPListener]
Enabled:     True
Port:        1337
Protocol:    TCP
Listener:    RawListener
UseSSL:      No
Timeout:     10
Hidden:      False

The configuration file is broken up into several sections.

  • [FakeNet] - Controls the behavior of the application itself. The only valid option at this point is DivertTraffic. When enabled, it instructs the tool to launch the appropriate Diverter plugin and intercept traffic. If this option is disabled, FakeNet-NG will still launch listeners, but will rely on another method to direct traffic to them (e.g. manually change DNS server).

  • [Diverter] - Settings for redirecting traffic. Covered in detail below.

  • [Listener Name] - A collection of listener configurations. Each listener has a set of default settings (e.g. port, protocol) as well as listener specific configurations (e.g. DumpHTTPPosts for the HTTPListener).

Diverter Configuration

Supposing you have enabled the DivertTraffic setting in the [FakeNet] configuration block, the tool will enable its traffic redirection engine to which we will call Diverter from now on as a reference to the excellent WinDivert library used to perform the magic behind the scenes on Windows platforms (the Linux implementation of the Diverter uses python-netfilterqueue).

The Diverter will examine all of the outgoing packets and match them against a list of protocols and ports of enabled listeners. If there is a listener listening on the packet's port and protocol, then the destination address will be changed to the local machine's IP address where the listener will handle the request. At the same time, responses coming from the listener will be changed so that the source IP address would appear as if the packet is coming from the originally requested host.

You can optionally enable the DumpPackets setting to store all traffic observed by FakeNet-NG (redirected or forwarded) to a PCAP file. It is possible to decrypt SSL traffic between an intercepted application and one of the listeners with SSL support. Use the instructions at the following page:

https://wiki.wireshark.org/SSL

The keys privkey.pem and server.pem used by FakeNet-NG's servers are in the application's root directory.

  • NetworkMode - Specify the network mode in which to run FakeNet-NG.
    • Valid settings are:
      • SingleHost: manipulate traffic from local processes.
      • MultiHost: manipulate traffic from other systems.
      • Auto: use whatever NetworkMode is most functional on the current platform.
    • Not all platforms currently support all NetworkMode settings. Here is the current status of support:
      • Windows supports only SingleHost
      • Linux supports MultiHost and experimentally supports SingleHost mode (works with the exception of process, port, and host blacklisting and whitelisting).
    • For now, leave this set to Auto to get SingleHost mode on Windows and MultiHost mode on Linux.

The Diverter generally supports the following DNS-related setting:

  • ModifyLocalDNS - point local machine's DNS service to FakeNet-NG's DNS listener.

The Windows implementation of Diverter supports the following DNS-related setting:

  • StopDNSService - stops the Windows DNS client service (Dnscache). This allows FakeNet-NG to see the actual processes resolving domains as opposed to the generic 'svchost.exe' process.

The Linux implementation of Diverter supports the following settings:

  • LinuxRedirectNonlocal - When using FakeNet-NG to simulate Internet connectivity for a different host, this specifies which externally facing network interfaces to re-route to FakeNet-NG.

  • LinuxFlushIptables - Flush all iptables rules before adding rules for FakeNet-NG. The Linux Diverter will restore the old rules as long as its termination sequence is not interrupted.

  • LinuxFlushDnsCommand - Specify the correct command for your Linux distribution to flush the DNS resolver cache if applicable.

  • DebugLevel - Specify fine-grained debug events to display. Refer to fakenet/diverters/linutil.py for valid labels.

Redirecting All Traffic

By default the Diverter will only intercept traffic that has a dedicated listener created for it. However, by enabling RedirectAllTraffic setting and configuring the default TCP and UDP handlers with the DefaultTCPListener and DefaultUDPListener settings it is possible to dynamically handle traffic going to ports not explicitly defined in one of the listeners. For example, let's look at a sample configuration which redirects all traffic to local TCP and UDP listeners on ports 1234:

RedirectAllTraffic: Yes
DefaultTCPListener: TCPListener1234
DefaultUDPListener: UDPListener1234

NOTE: We are jumping a bit ahead with listener definitions, but just consider that TCPListener1234 and UDPListener1234 will be defined in the section below.

With the RedirectAllTraffic setting, FakeNet-NG will modify not only the destination address, but also the destination port so it can be handled by one of the default listeners. Below is a sample log of traffic destined to an external host IP address 1.1.1.1 on port 4444 which was redirected to the default listener on port 1234 instead:

07/06/16 01:13:47 AM [          Diverter] Modifying outbound external TCP request packet:
07/06/16 01:13:47 AM [          Diverter]   from: 192.168.66.129:1650 -> 1.1.1.1:4444
07/06/16 01:13:47 AM [          Diverter]   to:   192.168.66.129:1650 -> 192.168.66.129:1234
07/06/16 01:13:47 AM [          Diverter]   pid:  3716 name: malware.exe

It is important to note that traffic destined to the port from one of the explicitly defined listeners will still be handled by that listener and not the default listener. For example, default UDP listener will not handle DNS traffic if a separate UDP port 53 DNS listener is defined.

One issue when enabling the RedirectAllTraffic options is that you may still want to let some traffic through to ensure normal operation of the machine. Consider a scenario where you are trying to analyze an application that still needs to connect to an external DNS server. You can utilize the BlackListPortsTCP and BlackListPortsUDP settings to define a list of ports to which traffic will be ignored and forwarded unaltered:

BlackListPortsUDP: 53

Some other Diverter settings that you may consider are ProcessBlackList and HostBlackList which allow Diverter to ignore and forward traffic coming from a specific process name or destined for a specific host respectively.

Listener Configurations

Listener configurations define the behavior of individual listeners. Let's look at a sample listener configuration:

[TCPListener1234]
Enabled:     True
Port:        1234
Protocol:    TCP
Listener:    RawListener
UseSSL:      Yes
Timeout:     10
Hidden:      False

The configuration above consists of the listener name TCPListener1234. It will be used for logging purposes so you can distinguish between different listeners handling connections even if they are handling the same protocol.

The following settings are generic for all listeners:

  • Enabled - specify whether or not the listener is enabled.
  • Port - TCP or UDP port to listen on.
  • Protocol - TCP or UDP
  • Listener - Listener name to handle traffic.
  • ProcessWhiteList - Only traffic from these processes will be modified and the rest will simply be forwarded.
  • ProcessBlackList - Traffic from all but these processes will be simply forwarded and the rest will be modified as needed.
  • HostWhiteList - Only traffic to these hosts will be modified and the rest will be simply forwarded.
  • HostBlackList - Traffic to these hosts will be simply forwarded and the rest will be modified as needed.
  • ExecuteCmd - Execute command on the first connection packet. This feature is useful for extending FakeNet-NG's functionality (e.g. launch a debugger on the connecting pid to help with unpacking and decoding.)
  • Hidden - Do not allow traffic to be directed to this listener without going through the proxy which will determine the protocol based on the packet contents

The Port and Protocol settings are necessary for the listeners to know to which ports to bind and, if they support multiple protocol (e.g RawListener), decide which protocol to use. They are also used by the Diverter to figure out which ports and protocols to redirect.

The Listener setting defines one of the available listener plugins to handle redirected traffic. The current version of FakeNet-NG comes with the following listeners:

  • DNSListener - supports DNS protocol and replies to A records with either a local machine's IP address or a configurable address in the DNSResponse setting. You can also set the NXDomains attribute to the number of requests the listener should ignore. This way you may be able to get the malware to request all of its backup C2 controller names. The listener supports both TCP and UDP protocols.
  • RawListener - supports basic TCP and UDP binary protocols. The default behavior is to simply echo the received packets back to the client. Supports SSL connections.
  • HTTPListener - supports HTTP and HTTPS protocols. Responds with different files in the configurable Webroot directory based on the requested file extension. Optionally dumps POST requests to a configurable file which can be specified using DumpHTTPPosts and DumpHTTPPostsFilePrefix settings.
  • SMTPListener - supports SMTP protocol.
  • ProxyListener- Detects protocol based on packet contents and redirects packets accordingly.

NOTE: FakeNet-NG will attempt to locate the webroot directory, first by using the provided absolute or relative paths. If the specified webroot path is not found, then it will try to look in its defaultFiles directory.

As a special case, the Windows Diverter implementation automatically responds to all ICMP requests while running. So in case a malware attempts to ping a host to test connectivity it will get a valid response. The Linux Diverter logs and forwards all ICMP packets to localhost.

NOTE: Some listeners can handle file uploads (e.g. TFTPListener and BITSListener). All uploaded files will be stored in the current working directory with a configurable prefix (e.g. "tftp_" for TFTP uploads).

Listener Filtering

FakeNet-NG supports several filtering rules consisting of process and host blacklists and whitelists. The whitelists are treated as the rules that allow connections to the listeners while the blacklists are used to ignore the incoming connections and let them to be simply forwarded.

For example, consider the configuration below with process and host filters:

[FilteredListener]
Enabled:     True
Port:        31337
Protocol:    TCP
Listener:    RawListener
UseSSL:      No
Timeout:     10
ProcessWhiteList: malware.exe, ncat.exe
HostBlackList: 5.5.5.5

The FilteredListener above will only handle connection coming from the processes malware.exe and ncat.exe, but will ignore any connections destined for the host 5.5.5.5. Meaning that if a process called test.exe attempted to connect on port 31337 it will not be redirected to the listener and will be forwarded to wherever it was originally intended if the route is available.

At the same time of the process malware.exe attempted to connect to port 31337 on any host other than 5.5.5.5 it will be diverted to the FilteredListener. Any connections from the process malware.exe destined to 5.5.5.5 would be allowed through.

Listener Command Execution

Another powerful configuration setting is ExecuteCmd. It essentially allows you to execute an arbitrary command on the first detected packet of the connection. The value of ExecuteCmd can use several format string variables:

  • {pid} - process id
  • {procname} - process executable name
  • {src_addr} - source address
  • {src_port} - source port
  • {dst_addr} - destination address
  • {dst_port} - destination port

Consider a scenario of a packed malware sample which connects to a configured C2 server on port 8443 (Use RedirectAllTraffic if the port is not known). In many cases the malware would unpack itself by the time it makes the connection making that point in execution ideal to attach to the process with a debugger and dump an unpacked version of it for further analysis.

Let's see how this can be used to automatically launch a debugger on the first connection:

[C2Listener]
Enabled:     True
Port:        8443
Protocol:    TCP
Listener:    RawListener
UseSSL:      Yes
Timeout:     300
ProcessWhiteList: malware.exe
ExecuteCmd:  C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\windbg.exe -p {pid}

Once FakeNet-NG detects a new connection coming from the whitelisted process malware.exe (this setting is optional), it will automatically launch windbg and attach it to the connecting process.

NOTE: You might want to extend the normal Timeout setting in case the malware needs to further interact with the listener.

Anonymous Listener

There is a special use case where you can create a new listener configuration without defining the actual listener to handle it:

[Forwarder]
Enabled:     True
Port:        8080
Protocol:    TCP
ProcessWhiteList: chrome.exe

Without a listener defined, FakeNet-NG will still divert traffic to the local machine, but a separate listener must be launched by the user. For example, you could have an HTTP proxy listening for connections on port 8080 and let FakeNet-NG intercept all the traffic from applications which do not use system's proxy server settings or use hard-coded IP addresses. Using anonymous listeners you can bring FakeNet-NG's advanced traffic and process filtering capabilities to 3rd party tools.

You may also want to enable Diverter's ProcessBlackList setting to allow the external tool to communicate out to the Internet. For example, to allow an HTTP proxy to forward proxied traffic add its process name to the process blacklist. For example, add the following process to let Burp Proxy to communicate out to the Internet:

ProcessBlackList: java.exe

In the scenario where application communicates on an unknown port, but you still want to redirect it to the anonymous listener on port 8080 you can define the default listener as follows:

RedirectAllTraffic: Yes
DefaultTCPListener: ForwarderTCP
DefaultUDPListener: RawUDPListener

Finally, to allow DNS traffic to still go to the default DNS server on the Internet, while redirecting all other traffic, add port 53 to the Diverter's UDP port blacklist as follows:

BlackListPortsUDP:

Proxy Listener

The latest release of FakeNet-NG implements a new proxy listener which is capable of dynamically detecting communicating protocol (including SSL traffic) and redirecting the connecting to an appropriate listener.

You can configure the proxy listener to work on a specific port as illustrated in the configuration below:

[ProxyTCPListener]
Enabled:    True
Protocol:   TCP
Listener:   ProxyListener
Port:       38926
Listeners:  HTTPListener, RawListener, FTPListener, DNSListener, POPListener, SMTPListener, TFTPListener, IRCListener, BITSListener
Hidden:     False

Note, the new Listeners parameter which defines a list of potential protocol handlers to try for all incoming connections.

It is also recommended to define a proxy listener as your default handler by updating the following diverter configurations:

RedirectAllTraffic:    Yes
DefaultTCPListener:    ProxyTCPListener
DefaultUDPListener:    ProxyUDPListener

With the default listener pointing to the proxy listener, all unknown connections will be appropriately handled. You can still assign specific listeners to ports to enforce a specific protocol (e.g. always use HTTP listener for port 80).

The Proxy determines the protocol of packets by polling all available listeners with the function taste(). Each Listener that implements taste() will respond with a score indicating the likelihood that the protocol handled by that listener matches the packet contents. The Proxy will forward the packet to the Listener that returned the highest score. The RawListener will always return a score of 1, so it will be chosen in the case that all other Listeners return 0, thus serving as the default.

Users can alter the configuration parameter 'Hidden' in each Listener's configuration. If Hidden is 'False', the Listener will be bound to a specific port and automatically receive all traffic on that port. With Hidden set to 'True', the Listener can only receive traffic that is redirected through the Proxy.

Development

FakeNet-NG is developed in Python which allows you to rapidly develop new plugins and extend existing functionality. For details, see Developing for FakeNet-NG.

Known Issues

Does not work on VMWare with host-only mode enabled

See "Not Intercepting Traffic" below.

Not Intercepting Traffic

In order to for FakeNet-NG to intercept and modify the packet, there must exist a valid network route for the packet to reach its destination.

There is an easy way to check whether or not you have routes set up correctly. Without the tool running attempt to ping the destination host. You should observe either a valid response or a timeout message. If you receive a destination not reachable error instead, then you do not have a valid route.

This is usually caused by your gateway being either not set or not reachable. For example, on a VMWare machine with host-only mode your machine will not have the gateway configured thus preventing FakeNet-NG from seeing any traffic.

To correct this issue, manually configure your primary interface to the gateway in the same subnet. First check the interface name:

C:\>netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        Local Area Connection

In this case the interface name is "Local Area Connection" so we will use it for the rest of the commands.

Manually configure the interface IP address and gateway as follows:

C:\>netsh interface ip set address name="Local Area Connection" static 192.168.249.123 255.255.255.0 192.168.249.254

Manually set the DNS server IP address

C:\>netsh interface ip set dns name="Local Area Connection" static 4.2.2.2

If you are still having issue ensure that the gateway IP address itself is routable.

DNS Not Resolving Names

Ensure that the DNS Listener successfully bound to its port. Errors such as the following indicate that the DNS Listener did not successfully bind:

05/01/17 11:11:16 AM [           FakeNet] Error starting DNSListener listener:
05/01/17 11:11:16 AM [           FakeNet]  [Errno 98] Address already in use

Use netstat, tcpview, or other tools to discover what application is bound to the port, and refer to the corresponding operating system or application documentation to disable the service.

It may make sense to capture a VM snapshot before undertaking reconfiguration.

For example, Ubuntu commonly enables the dnsmasq service in /etc/NetworkManager/NetworkManager.conf with the line dns=dnsmasq. Disabling this (such as by commenting it out) and restarting the network-manager service (e.g. service network-manager restart) is sufficient to free the port before re-launching FakeNet-NG.

In newer versions of Ubuntu or in other distributions, using lsof -i may reveal that systemd-resolved is used instead. In these cases, you may try these steps adapted from https://askubuntu.com/questions/907246/how-to-disable-systemd-resolved-in-ubuntu:

sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved

Then in /etc/NetworkManager/NetworkManager.conf under the [main] section, add a line specifying:

dns=default

Delete the symlink /etc/resolv.conf, i.e. rm /etc/resolv.conf.

Finally, restart NetworkManager:

sudo systemctl restart NetworkManager

Error: Could not locate WinDivert DLL or one of its components

Please ensure that FakeNet-NG is extracted to the local C: drive to make sure the WinDivert driver is loaded correctly.

Error: The application has failed to start because its side-by-side configuration is incorrect.

This error may occur when running a stand-alone executable version of Fakenet. Please download and install Visual C++ 2008 runtime executable.

Limitations

  • Only Windows Vista+ is supported for SingleHost mode. Please use the original Fakenet for Windows XP/2003 operating systems.

  • Only Linux is supported for MultiHost mode.

  • Old versions of python-netfilterqueue can cause a segmentation fault in python. If you experience this issue, check that you are using the latest version of python-netfilterqueue.

  • Due to the hard-coded buffer size used by python-netfilterqueue, the Linux Diverter does not correctly handle packets greater than 4,016 bytes in size. In practice, this does not affect Linux MultiHost mode for interfaces configured with the conventional 1,500 byte maximum transmittal unit (MTU). If the Linux interface you are using with FakeNet-NG supports an MTU greater than 4016, you will need to recompile python-netfilterqueue to support a buffer size of <your_mtu> + 80 (python-netfilterqueue devotes 80 bytes of the buffer to overhead).

  • Local machine only traffic is not intercepted on Windows (e.g. if you tried to connect directly to one of the listeners).

  • Only traffic using TCP, UDP, and ICMP protocols is intercepted.

Credits

  • FakeNet-NG was designed and developed by Peter Kacherginsky.
  • Special thanks to Andrew Honig, Michael Sikorski and others for the original FakeNet which was the inspiration to develop this tool.
  • The Linux Diverter was designed and developed by Michael Bailey.
  • Thanks to Matthew Haigh for developing the proxy protocol autodetection feature.
  • Thanks to Cody Pierce and Antony Saba for reporting and fixing a file system traversal vulnerability.

Contact

For bugs, crashes, or other comments please contact [email protected].

flare-fakenet-ng's People

Contributors

3v3ryone avatar antman1p avatar emtuls avatar htnhan avatar iphelix avatar mikesiko avatar mlhaigh avatar mwilliams31 avatar strictlymike avatar tinajn avatar vavarachen 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  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

flare-fakenet-ng's Issues

HTTP digest authentication

@evil-e was able to quickly add digest auth by modifying the do_POST method of HTTPListerner as follows:

        self.send_response(401)
        s = 'Digest realm="[email protected]",qop="auth,auth-int",nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",opaque="5ccc069c403ebaf9f0171e9517f40e41"'
        self.send_header('WWW-Authenticate', s)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write('<html><body>send_auth</body></html>')
        return

He cites a more mature code example at http://svn.python.org/projects/sandbox/trunk/digestauth/httpserver.py.

And a relevant RFC: An Extension to HTTP : Digest Access Authentication

The code sample at the former URL, in case of URL rot, is:

import SimpleHTTPServer, BaseHTTPServer

import digestauth

digester = digestauth.DigestAuthServer(default_realm='TestAuth')
digester.parse_apache_digest_authfile('/var/www/passwords')

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self, *args):
	path = self.path

	if path.startswith("/test"):
            if not self.headers.has_key('Authorization'):
                self.send_auth('auth required')
                return
            else:
                auth = self.headers['Authorization']
                if auth.split()[0].lower() == 'digest':
                    ok, reason = digester.check_auth(auth[7:])
                    if not ok:
                        self.send_auth('auth failed: %s'%reason)
                        return
	else:
	    self.send_response(200)
	self.send_header("Content-type", "text/plain")
	self.end_headers()
	self.wfile.write("all good: %s\n"%path)

    def send_auth(self, text):
        self.send_response(401)
        chal = digester.generate_challenge()
        self.send_header('WWW-Authenticate', 'Digest %s'%(chal))
        self.send_header('Content-type', 'text/html')
        self.end_headers()
        self.wfile.write('<html><body><p>'+text+'\n\n</p></body></html>')
        return


def run(server_class=BaseHTTPServer.HTTPServer,
        handler_class=Handler):
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

run()

Feature request: NBI summary

Malware with a lot of activity can generate long FakeNet logs. To save analysts from having to read or grep long FakeNet logs, it would be nice if we collected a summary of network-based indicators that FakeNet would print as it closes out (or on demand through SIGUSR1 or similar).

Minimum requirements:

  • All nonlocal IP addresses that were communicated with (to catch malware hard-coded C2 IPs)

Nice to have:

  • Per-listener NBI callback
    ** DNS A/AAAA requests
    ** HTTP fields
    *** HTTP User-Agent field
    *** URI
    *** HTTP Host header field

For backward compatibility, we could limit this callback to listeners that indicate their awareness of this API by implementing a new interface e.g. ListenerNbiSummary. This would prevent listeners that people have developed prior to this feature from throwing an exception when we try to call the nonexistent callback.

Fakenet-ng not running on Windows 7 x64 SP1

If I run fakenet32.exe, I get the following error (note 64-bit python is installed):

11/23/16 02:01:39 PM [ FakeNet] Error: Please install 64-bit Python interpreter to support diverter functions.

If I run fakenet64.exe, I get the error:
image

I've been unable to resolve either of these issues.

Thanks!

IRCListener WHOIS command

The IRCListener returns Unknown command when a client sends the WHOIS command. Client was irssi

Server output:

 08/04/17 01:45:34 PM [         IRCServer] Client issued an unknown command WHOIS asdf

Client output (irssi):

13:45 -!- Unknown command

icmp host blacklisting

When specifying an host in HostBlackList, ICMP traffic to that host is not ignored.
Is this done deliberately or should be considered a bug?

Users want to restrict which interfaces FakeNet-NG listens on

Users like @garsim and @DigiAngel would like a setting that governs what interfaces the FakeNet-NG listeners can receive traffic from.

Note that LinuxRedirectNonlocal (on Linux) is not sufficient because that setting only concerns the network interfaces where the Linux Diverter implements packet redirection. Meanwhile, the listeners all bind to 0.0.0.0 irrespective of that setting, which is why users don't see the behavior they are hoping for when modifying that setting from its default value of *.

HTTPListener does not serve FakeNetMini.exe in response to GET *.exe

HTTPListener responds to HTTP requests for any .exe extension with a MIME type of application/x-msdos-program but the content from FakeNet.html. Adding an entry to the MIME_FILE_RESPONSE dictionary for application/x-msdos-program pointing to FakeNetMini.exe induces the correct behavior. I believe this is the correct fix.

IRCListener ServerName configuration is read multiple times

The IRCListener class uses .get('servername', 'localhost') to get its ServerName configuration value the first time in order to make the setting optional with the default value 'localhost'; but its ThreadedTCPRequestHandler accesses self.server.config['servername'] directly, resulting in a KeyError that winds up closing connections to the IRC service. Replacing direct references to self.server.config['servername'] with self.server.servername in the ThreadedTCPRequestHandler seems to resolve this and make the ServerName setting truly optional.

Logging to file issue

When running fakenet.py with the --log-file option, logging only seems to happen when the application exits. Could you research whether this is the case or whether there is a buffering thing going on?

Syslog?

If you're operating fakenet as a sinkhole, the ability to write to syslog, so it could be sent to a SIEM would be a great capability.

SingleHost NetworkMode on Linux does not support blacklists/whitelists

The SingleHost network mode on Linux is adequate for simulating an Internet connection but does not yet properly support host, port, or process blacklists or whitelists. I propose that we leave this issue in tracking until these features are complete to aid those who may be troubleshooting FakeNet-NG on Linux in SingleHost mode but who have not seen the caveat in README.md or elsewhere regarding this deficiency.

Suspected race condition in FTPListener

I observed this traceback when shutting down FakeNet-NG on Ubuntu Linux 14.04.1 LTS but could not reproduce it. Ostensibly, the FTPListener is not accurately coordinating shutdown with pyftpdlib leading to a sporadic exception when FakeNet-NG is being shut down. Trace follows.

Exception in thread Thread-7 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 763, in run
  File "/usr/local/lib/python2.7/dist-packages/pyftpdlib/servers.py", line 418, in serve_forever
  File "/usr/local/lib/python2.7/dist-packages/pyftpdlib/ioloop.py", line 344, in loop
  File "/usr/local/lib/python2.7/dist-packages/pyftpdlib/ioloop.py", line 121, in poll
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

Requesting "large" file using ProxyListener either fails or is slowed

Using the current version of FakeNet and running the default config, any request of a file (using ProxyListener) that utilizes chunked encoding in its transmission will either fail or be throttled by FakeNet.

For example:

  • With the HTTPListener listening on port 80, requesting a file over port 80 that uses chunked encoding (ex. http://localhost/file.exe) in its transmission will download quickly and successfully.
  • On the other hand, with the HTTPListener still listening on port 80 and HTTPListener listed as first priority on the ProxyListener config, requesting the same file over a port picked up by ProxyListener (ex. http://localhost:1234/file.exe) will either fail or be throttled in its transmission - both results have happened in practice.

Has this issue been encountered before? Any idea of where/how to fix it in the source? I am struggling to find the location of the problem.

Note: attributing this issue to chunked encoding over ProxyListener is mostly just a suspicion at this point because I have not been able to find the root cause yet.

[Feature] Configurable pcap verbosity

FakeNet-NG currently records datagrams at various intermediate stages within the pcap it creates:

  • Before any modification
  • After IP redirection
  • After port redirection

Users would like to be able to configure FakeNet-NG to omit some of the duplicate (modified) datagrams. It is easy to imagine that users might want at least these three pre-set modes of behavior:

  • Before any modification
  • After all modifications
  • Verbose

Furthermore, users may foreseeably wish to configure FakeNet-NG to write multiple pcaps, selecting the mode (from the above) for each.

IRCListener MODE command

The IRCListener returns Unknown command when a client sends the MODE command. Client was irssi

Server output:

 +i04/17 01:45:34 PM [         IRCServer] Client issued an unknown command MODE asdf

Client output (irssi):

13:45 -!- Unknown command

IRCListener times out idle connections

Listener IRCListener indicates Connection timeout and causes the client to indicate Connection lost when using irssi as the client.

Server output:

 +i04/17 01:45:34 PM [         IRCServer] Client issued an unknown command MODE asdf
 08/04/17 01:45:34 PM [         IRCServer] Client issued an unknown command WHOIS asdf
 08/04/17 01:45:35 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:35 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:35 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:35 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:37 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:37 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:37 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:45:37 PM [          Diverter]   pid:  13391 name: irssi
 08/04/17 01:46:07 PM [         IRCServer] Connection timeout

Client output (multiple reconnects/disconnects observed):

 Irssi v0.8.15 - http://www.irssi.org
 13:45 -!- Irssi: Looking up localhost
 13:45 -!- Irssi: Connecting to localhost [127.0.0.1] port 6667
 13:45 -!- Irssi: Connection to localhost established
 13:45 -!- Welcome to FakeNet Internet Relay Chat Network.
 13:45 -!- End of /MOTD command.
 13:45 -!- Unknown command
 13:45 -!- Unknown command
 13:46 -!- Irssi: Connection lost to localhost
 13:50 -!- Irssi: Removed reconnection to server localhost port 6667
 13:50 -!- Irssi: Looking up localhost
 13:50 -!- Irssi: Reconnecting to localhost [127.0.0.1] port 6667 - use /RMRECONNS to abort
 13:50 -!- Irssi: Connection to localhost established
 13:50 -!- Welcome to FakeNet Internet Relay Chat Network.
 13:50 -!- End of /MOTD command.
 13:50 -!- Unknown command
 13:50 -!- Unknown command
 13:51 -!- Irssi: Connection lost to localhost
 13:55 -!- Irssi: Removed reconnection to server localhost port 6667
 13:55 -!- Irssi: Looking up localhost
 13:55 -!- Irssi: Reconnecting to localhost [127.0.0.1] port 6667 - use /RMRECONNS to abort
 13:55 -!- Irssi: Connection to localhost established
 13:55 -!- Welcome to FakeNet Internet Relay Chat Network.
 13:55 -!- End of /MOTD command.
 13:55 -!- Unknown command
 13:55 -!- Unknown command
 13:56 -!- Irssi: Connection lost to localhost
 14:00 -!- Irssi: Removed reconnection to server localhost port 6667
 14:00 -!- Irssi: Looking up localhost
 14:00 -!- Irssi: Reconnecting to localhost [127.0.0.1] port 6667 - use /RMRECONNS to abort
 14:00 -!- Irssi: Connection to localhost established
 14:00 -!- Welcome to FakeNet Internet Relay Chat Network.
 14:00 -!- End of /MOTD command.
 14:00 -!- Unknown command
 14:00 -!- Unknown command
 14:00 -!- Irssi: Disconnecting from server localhost: [leaving]
 14:00 -!- Irssi: Connection lost to localhost
``

SMTP over SSL does not work

SMTP over SSL using the UseSSL configuration setting yields the following error:

ssl.SSLError: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol

Here is a test snippet:

def do_smtp_ssl_port(portno=None):
    s_portno = (':' + str(portno)) if portno else ''
    server = smtplib.SMTP_SSL('localhost' + s_portno)
    server.sendmail('[email protected]', '[email protected]', 'message contents')
    server.quit()

This was tested with SMTPListener in isolation from FakeNet-NG using:

sudo python -m listeners.SMTPListener

The configuration for SMTPListener was:

config = {'port': '465', 'usessl': 'Yes', 'timeout': 10 }

HTTPListener and FTPListener are never used

I'm trying to handle some basic requests to download files or to list a ftp address but in both cases FakeNet replies always with the DNSServer. Why? I've tried also to force all traffic to HTTPListener or FTPListener but nothing happens (FakeNet doesn't replies to the requests).

Any advise?

Release version does not allow custom listener development

The release binaries currently don't allow custom listener development because they don't import .py files. Furthermore, no sample code is present in the release archives which I think will make it harder to hack on FakeNet once that is rectified.

It would be nice to revisit the release process to (1) allow users to directly add new listeners to the release version and (2) include the .py code for the "stock" listeners alongside the release binaries as a body of examples and so that users can directly modify the stock listener code if desired.

Implement Microsoft NCSI

Implement Microsoft NCSI as described at Appendix K: Network Connectivity Status Indicator and Resulting Internet Communication in Windows Vista

I noticed the following traffic with a Windows 7 client and did a little research.

04/25/17 11:57:40 AM [        DNS Server] Received A request for domain 'www.msftncsi.com'.
04/25/17 11:57:40 AM [        DNS Server] Responding with '192.168.19.222'
04/25/17 11:57:40 AM [          Diverter]   pid:  6535 name: python
04/25/17 11:57:40 AM [          Diverter]   pid:  6535 name: python
04/25/17 11:57:40 AM [    HTTPListener80] Received a GET request.
04/25/17 11:57:40 AM [    HTTPListener80] --------------------------------------------------------------------------------
04/25/17 11:57:40 AM [    HTTPListener80] GET /ncsi.txt HTTP/1.1
04/25/17 11:57:40 AM [    HTTPListener80] Connection: Close
04/25/17 11:57:40 AM [    HTTPListener80] User-Agent: Microsoft NCSI
04/25/17 11:57:40 AM [    HTTPListener80] Host: www.msftncsi.com
04/25/17 11:57:40 AM [    HTTPListener80]
04/25/17 11:57:40 AM [    HTTPListener80] --------------------------------------------------------------------------------

Configuration to let malware retrieve a HTTP response

Is there any configuration in Fakenet-NG that is similar to INetSim 's Fake Mode?
Description:
Delivers configured fake files based on the file extension in the HTTP request (e.g. .html or .exe) or static paths

SMTPListener STARTTLS support

The SMTP Listener does not seem to support the STARTTLS extension.

Here is a test snippet:

def do_smtp_starttls():
    server = smtplib.SMTP('localhost')
    server.starttls()
    server.login('user', 'pass')
    server.sendmail('[email protected]', '[email protected]', 'message contents')
    server.quit()

When running python -m listeners.SMTPListener with port set to 25 and usessl set to No, the result is an SMTPServerDisconnect exception: STARTTLS extension not supported by server.

DNS filtering/pass-through

Users would like to be able to allow the DNS listener to pass selected requests through to an actual DNS server.

Regular expressions stand out as a way for users to specify what requests to pass through without having to revisit this if requirements become more complex.

It would be worthwhile to allow users to also specify whether the default behavior will be to pass through vs. simulate.

Thanks to @dzzie and @garsim for pointing out the utility of such a feature. Please feel free to add a follow-on comment if you would like to elaborate on the specification above.

Only handles packets up to 4,012 in size on Linux

This ticket is being logged as an advisory to users that, as of this writing, python-netfilterqueue (which FakeNet-NG uses on Linux) has a hard-coded buffer size of 4,096 bytes. After "overhead", this leaves 4,012 bytes available for the octets of any given datagram traversing the network stack. As a result, users may experience truncated datagrams when using FakeNet-NG on Linux over interfaces (such as lo) that are configured with a maximum transmittal unit (MTU) greater than 4,012. The work-around is to recompile python-netfilterqueue with a larger buffer size or to adjust the MTU of the desired interface to a number that does not exceed the hard-coded buffer size used by python-netfilterqueue. The maintainer of this repository may opt to mark this issue as "wontfix" or its equivalent. It has been logged here primarily so that users may find it in the event that they are searching for information about troubleshooting FakeNet-NG on Linux.

Tunnel VM traffic into FakeNet on host

So I've got a bit of an unusual use-case.

I have a Linux Host which is running a virtual machine. What I want to do is redirect all of the traffic from the virtual machine to FakeNet, which is running on the Host, without interfering with the other traffic on the host.

I thought I could easily accomplish this by leaving the guest in the default NAT configuration and simply adding a couple of iptables rules to the nat or mangle table to redirect all traffic to the FakeNet UDP and TCP proxies.

But all my attempts to do so have been met with a FakeNet error related to an un-instantiated diverter.

Exception happened during processing of request from ('127.0.0.1', 41482)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 596, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/home/reee/tools/flare-fakenet-ng/fakenet/listeners/ProxyListener.py", line 276, in handle
    orig_src_ip, orig_src_port, 'TCP')
  File "/home/reee/tools/flare-fakenet-ng/fakenet/listeners/ProxyListener.py", line 203, in get_top_listener
    dport = diverter.getOriginalDestPort(orig_src_ip, orig_src_port, proto)
AttributeError: 'NoneType' object has no attribute 'getOriginalDestPort'

I get this error on for both TCP and UDP traffic when I turn the "DivertTraffic" configuration setting off. Of course, I turn this setting off because I don't want FakeNet to intercept the other traffic on my Host.

I've attempted to use the "LinuxRedirectNonlocal" option to only divert traffic coming from the bridge interface that the Guest (VM) sends its traffic through, this setup doesn't produce any errors, but it makes the internet non-functional on both my Host and the Guest. My initial thought was this was because of some DNS issues, but I can't get pings to 8.8.8.8 to return anything on the Guest in this configuration.

So after perusing the source and documentation, I think my only remaining option is to add a configuration line to the config file that would restrict the inserted iptables rules for diversion to a specific source subnet. In my case, the guest is assigned IP addresses from the 192.168.122.0/24 subnet.

I'm posting this as an issue for awareness. I'd like to know if I'm just doing something dumb and there's already and easy way to operate FakeNet in this fashion, and if not, I would like some advice on fixing the issue myself.

I can paste my FakeNet configs, iptables rules, and other log files for more information if requested.

Barring some feedback from the community, I will go ahead and modify the source in a way that is hopefully suitable enough for a pull request.

WinDivert error 577, Windows cannot verify digital signature

When you start FakeNet-NG, you see the following error:

ERROR: Failed to open a handle to the WinDivert driver: [Error 577] Windows cannot verify the digital signature for
this file. A recent hardware or software change might have installed a file that is signed incorrectly or damaged,
or that might be malicious software from an unknown source.

This is an issue relating to WinDivert (as opposed to FakeNet-NG), but as it impedes using FakeNet-NG, I am documenting it here.

It appears that new Windows driver signing practices are at issue here. See this comment from the WinDivert Driver Signing discussion. For me, it was sufficient to bring my VM out of isolation, run Windows Update, and then retry. The updated VM ran FakeNet-NG without any Windows driver signing error.

Thanks to @garsim for noticing this as well, and @tankbusta for noting the relevant conversation about the issue including the work-around.

Failed to open handle to WinDivert driver / error 1753 / no more endpoints available

If you get this error:

12/20/17 09:18:30 AM [          Diverter] ERROR: Failed to open a handle to the
WinDivert driver: [Error 1753] There are no more endpoints available from the
endpoint mapper.

You may not have the Base Filtering Engine (BFE) service enabled. See: ffalcinelli/pydivert#28

I have reproduced this condition in a VM by stopping the BFE service, and rectified it by setting its startup to Automatic and restarting Windows.

HTTPListener: Hanging

HTTPListener has a tendency to hang on connections. FireFox especially seems to kill the particular listener.

Proxy listener hangs for server-first protocols

The proxy listener works in part by reading from the socket to determine what protocol the client is looking for and forward traffic to the correct port. In the case of protocols like SMTP that require the server to send data first, the client awaits a server message before sending any data, and consequently this state machine never advances and the client hangs.

In cases such as this, the proxy might do best by implementing a work-around in which it implements a timeout after which it would pass an empty byte string to the taste callback of each listener. Since the taste callback also accepts a port number, the listener could then indicate a score based only on the port number, and the connection process could continue with only a small delay due to the timeout.

Thanks to @garsim for indicating an issue with SMTPListener and SSL, which caused me to look into why this hang occurs.

Quick question

Wanting to just have fakenet respond like inetsim on a virtual interface...how do I tell fakenet to just listen on that interface? Thanks.

Upon exiting, DNS settings not restored correctly under certain conditions (Windows)

When Fakenet is run on a Windows machine with multiple DNS servers configured (for instance, via DHCP), the following error message is encountered early on:

04/09/18 04:18:16 PM [          Diverter] External IP: 192.168.0.29 Loopback IP: 127.0.0.1
04/09/18 04:18:16 PM [          Diverter] Failed calling GetNetworkParams
04/09/18 04:18:16 PM [          Diverter] WARNING: No DNS servers configured!
04/09/18 04:18:17 PM [          Diverter]          Setting DNS 192.168.0.29 on interface Ethernet0

Then, when finishing up, Fakenet indicates the following:

04/09/18 04:18:57 PM [          Diverter] Restored DNS on interface Ethernet0
04/09/18 04:18:57 PM [          Diverter] Restored DNS server 192.168.0.29 on the adapter: Ethernet0

192.168.0.29 is the IP address of my machine, though, which is not running a DNS server. This causes DNS lookups to fail, and I have to go into the adapter settings and specify that the DNS server information should be received via DHCP.

Pull request #72 addresses this issue. The problem is that the underlying call to GetNetworkParams (to retrieve the DNS server information) passes in too small of a buffer (the buffer is big enough only in the case where there is only one DNS server configured.) The example code on the following page shows how this case should be handled, which is ultimately what I implemented:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365900(v=vs.85).aspx

sending raw files in HTTP

Hi.
I started to implement in the code the possibility to optionally send RAW html files, I mean something like

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.it/?gfe_rd=cr&dcr=0&ei=-hMOWpvLOuzBXtDhiegJ
Content-Length: 266
Date: Thu, 16 Nov 2017 22:40:58 GMT

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>

In this way you can have more control on the replies and sending specific codes or formats.
For the time being I started to do it in a very naive way:

for example if I do a GET /myfile

I search in the "defaultFiles" for a file named "myfile.RAW". If it exists, it send it without additional headers or config (assuming that they are in the file).
Do you have any suggestion on a better approach on this? Then, as soon as I'll have this cleaned up, I'll share it if you are interested.

Thanks,

Proxy hangs unxutils wget.exe (but not IE)

I am logging this issue because although this client may be rare, it could be exercising a flaw in the new Proxy Listener that we might not otherwise notice until later. When I use wget.exe from UnxUtils to browse to an arbitrary URL at a non-HTTP port, the transfer is successful (despite the command-line output indicating 0% complete) but it appears as if the connection does not close.

Theory: Perhaps the HTTP Listener closes the connection but the Proxy Listener does not do the same? In any case, here is an example of me trying to do this.

C:\Users\player2\>wget http://www.floogle.com:81/
--15:08:49--  http://www.floogle.com:81/
           => `index.html.3'
Resolving www.floogle.com... done.
Connecting to www.floogle.com[192.0.2.123]:81... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,479 [text/html]

 0% [                                     ] 0             --.--K/s    ETA --:--

FakeNetMini.dll

It would be nice if requests for files ending in .dll would receive a response with a FakeNetMini.dll whose DLLMain would help the reverser, perhaps by halting the malware. I think that it's illegal to call the user32!MessageBox API in DLLMain, but for purposes of malware analysis, this might generally suffice to allow the analyst to attach a debugger or just dismiss the event.

Delays downloading FakeNetMini.exe on Windows

Downloading the FakeNetMini.exe file by browsing to a URL such as http://blah.com/hahahax.exe sporadically hits some sort of delay, and sometimes can even time out.

@iphelix indicates this has been observed prior to now in other browsers and it was dismissed as a transient latency issue perhaps due to the tendencies of browsers to download lots of extraneous content upon startup.

I am tracking this issue in case it is a problem with FakeNet-NG itself, and if it becomes a recurring theme, we can prioritize and address it.

Details:

  • Windows 7 Professional SP1 amd64
  • IE8 (version 8.0.7601.17514).
  • Installed:
    • python-2.7.12.amd64
    • Git-2.14.1-32-bit
    • gvim80-586
    • VCForPython27

See image below (the "Navigation Canceled" message applies to the page prior to this browse; no content is shown because this browse went directly to the download sequence in IE).

fakenet-win7-exe-download-delay

Port range request

The ability to define a range of ports could be extremely useful, especially when investigating things that are truly unknown or operating a sinkhole. I envision two ideas in the config file, one that accepts a comma-separated list of values and another that specifies starting and ending port values. Examples follow.

[HTTP Common Ports]
Enabled:               True
Port:                  80,81,88,8080,8081,8088
Protocol:              TCP
Listener:              HTTPListener
UseSSL:                Yes
Webroot:               defaultFiles/
DumpHTTPPosts:         Yes
DumpHTTPPostFilePrefix:            http

[Custom VNC listener]
Enabled:               True
Port:                  5901-5999
Protocol:              TCP
Listener:              customVnc
UseSSL:                No

Installation on Windows fails unless cryptography is installed separately

When I install FakeNet-NG on Windows 7 by running python setup.py install in an elevated command prompt, installation fails with the following error:

Installed c:\users\username\appdata\local\temp\easy_install-feuwer\cryptography-2.0.3\.eggs\pycparser-2.18-py2.7.egg
no previously-included directories found matching 'docs\_build'
warning: no previously-included files matching '*' found under directory 'vectors'
_openssl.c
build\temp.win-amd64-2.7\Release\_openssl.c(434) : fatal error C1083: Cannot open include file: 'openssl/opensslv.h': No such file or directory
error: [Error 5] Access is denied: 'c:\\users\\username\\appdata\\local\\temp\\easy_install-feuwer\\cryptography-2.0.3\\.eggs\\cffi-1.10.0-py2.7-win-amd64.egg\\_cffi_backend.pyd'

A work-around is to induce the installation to succeed by first running pip install cryptography. After that, running python setup.py install terminates successfully and FakeNet-NG works when I invoke it by typing simply fakenet in an elevated command prompt.

This is on

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.