Debian 11
FakeNet-NG
Mitmproxy 8.0
I use mitmproxy for proper certificates generation on-the-fly with preinstalled on VM root cert and exporting preshared SSL keys for traffic decryption.
FakeNet-NG by default using self-signed certificates.
In /mnt/public
mounted shared folder for extracted preshared SSL keys.
Interface ens3
- NATed to external Internet, IP address acquired by DHCP.
Interface ens4
- for malware network, static IP-address 192.168.19.53.
All traffic to other IP-address redirect to out address.
cat /etc/iptables.rules
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [1:61]
:OUTPUT ACCEPT [2:214]
:POSTROUTING ACCEPT [2:214]
-A PREROUTING ! -d 192.168.19.0/24 -j DNAT --to-destination 192.168.19.53
COMMIT
cat /etc/network/interfaces
allow-hotplug ens3
iface ens3 inet dhcp
auto ens4
iface ens4 inet static
pre-up iptables-restore < /etc/iptables.rules
netmask 255.255.255.0
address 192.168.19.53
apt update
apt install iptables
FakeNet-NG uses python2.7 for work.
apt install python2
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py --output-document get-pip.py
python2 get-pip.py
apt-get install build-essential python-dev libnetfilter-queue-dev
python2 -m pip install https://github.com/mandiant/flare-fakenet-ng/archive/refs/heads/master.zip
- Copy configs to
/usr/local/etc/fakenet
cp -r cd /usr/local/lib/python2.7/dist-packages/fakenet /usr/local/etc/
- Change config
/usr/local/etc/fakenet/configs/default.ini
Diff with default configuration.
...
LinuxRestrictInterface: ens4
...
DumpPacketsFilePrefix: fakenet
...
FixGateway: No
FixDNS: No
...
ModifyLocalDNS: No
...
BlackListPortsTCP: 22, 139, 443
...
[HTTPListener443]
Enabled: False
...
Don't forget to check path to defaultFiles
. By default, fakenet use defaultFiles
from python module. You may create symlink to
defaultFiles in /usr/local/etc/fakenet
.
ln -s /usr/local/lib/python2.7/dist-packages/fakenet/defaultFiles /usr/local/etc/fakenet/
Or just replace all relative paths to absolute by next sed command:
sed -ni 's| defaultFiles|/usr/local/etc/fakenet/defaultFiles|'
HTTPListener443 disabled because Mitmproxy used instead.
Blacklist 443 port for proper mitmproxy work, port 22 for SSH.
Traffic of network interaction will be saved in /var/lib/fakenet
.
/etc/systemd/system/fakenet-ng.service
[Unit]
Description=FakeNet-NG service
Requires=
Wants=network-online.target
After=network-online.target
[Service]
SyslogIdentifier=fakenet
# Environment=SYSTEMD_LOG_LEVEL=debug
WorkingDirectory=/var/lib/fakenet
Type=simple
User=root
ExecStartPre=-/bin/sh -c '/sbin/iptables-save > iptables.rules'
ExecStart=/usr/local/bin/fakenet --config-file /usr/local/etc/fakenet/configs/default.ini --no-console-output --log-syslog
KillSignal=SIGINT
ExecStopPost=-/sbin/iptables-restore iptables.rules
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
Different services in different log files in /var/log/fakenet
.
/etc/rsyslog.d/41-fakenet.conf
if ($programname contains 'FakeNet-NG') then {
action(type="omfile" file="/var/log/fakenet/main.log")
if $msg contains '"moduleName":"HTTPListener"' then {
action(type="omfile" file="/var/log/fakenet/http.log")
}
if $msg contains '"moduleName":"DNSListener"' then {
action(type="omfile" file="/var/log/fakenet/dns.log")
}
if $msg contains '"moduleName":"RawListener"' then {
action(type="omfile" file="/var/log/fakenet/raw.log")
}
if $msg contains '"moduleName":"IRCListener"' then {
action(type="omfile" file="/var/log/fakenet/irc.log")
}
if $msg contains '"moduleName":"SMTPListener"' then {
action(type="omfile" file="/var/log/fakenet/smtp.log")
}
if $msg contains '"moduleName":"FTPListener"' then {
action(type="omfile" file="/var/log/fakenet/ftp.log")
}
if $msg contains '"moduleName":"TFTPListener"' then {
action(type="omfile" file="/var/log/fakenet/tftp.log")
}
if $msg contains '"moduleName":"POPListener"' then {
action(type="omfile" file="/var/log/fakenet/pop.log")
}
stop
}
systemctl restart rsyslog
systemctl daemon-reload
systemctl enable fakenet-ng
systemctl start fakenet-ng
My configuration
- standalone app in
/usr/local/bin/
; - config and certs in
/usr/local/etc/mitmproxy
; - autostart via sysmemctl as service;
- write generated preshared SSL keys to directory
/mnt/public
; - log to
/var/log/mitm.log
wget https://snapshots.mitmproxy.org/8.0.0/mitmproxy-8.0.0-linux.tar.gz --output-document=mitmproxy.tgz
tar -xzvf mitmproxy.tgz -C /usr/local/bin/
mkdir -p /usr/local/etc/mitmproxy
cd /usr/local/etc/mitmproxy
openssl req -nodes -days 3650 -new -x509 -newkey rsa:2048 -keyout mitmproxy-ca-key.pem -out mitmproxy-ca-cert.pem -subj "/C=US/ST=California/L=Berkeley/O=DigiCert Inc/OU=DigiCert Inc Root CA/CN=www.digicert.com"
openssl pkcs12 -export -in mitmproxy-ca-cert.pem -inkey mitmproxy-ca-key.pem -name "Root Cert" -out mitmproxy-ca-cert.p12 --passout pass:
cat mitmproxy-ca-cert.pem mitmproxy-ca-key.pem > mitmproxy-ca.pem
cp mitmproxy-ca-cert.pem mitmproxy-ca-cert.cer
/usr/local/etc/mitmproxy/config.yaml
confdir: /usr/local/etc/mitmproxy
# keep hostname to inetsim
keep_host_header: true
# listen connections on default HTTPS port
listen_port: 443
# NB! change <server> to your http server address
mode: reverse:http://192.168.19.53:80
# extra details (full header and content) in console log
flow_detail: 3
/etc/systemd/system/mitmdump.service
[Unit]
Description=mitmdump service
Wants=network-online.target fakenet-ng.service
Requires=
After=fakenet-ng.service
RequiresMountsFor=/mnt/public
[Service]
SyslogIdentifier=mitmdump
Environment=MITMPROXY_SSLKEYLOGFILE=/mnt/public/ssl-keys.log
Type=simple
User=root
ExecStart=/usr/local/bin/mitmdump --set confdir=/usr/local/etc/mitmproxy
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
/etc/rsyslog.d/mitmdump.conf
if ($programname == 'mitmdump') then {
action(type="omfile" file="/var/log/mitm.log")
stop
}
systemctl restart rsyslog
systemctl daemon-reload
systemctl enable mitmdump.service
systemctl start mitmdump.service
Configure interfaces. GW 192.168.19.53, DNS 192.168.19.53
Via browser go to https:\\mitm.it.
If browser asks Accept risk and continue.
Install prepared certificates and enjoy.
By default Wireshark can't decrypt TLS/SSL traffic without preshared keys from mitmproxy.
For decrypting captured traffic you must set tls.keylog_file
by filename with extracted keys (/mnt/public/ssl-keys.log
).
After that you can view decrypted packets.
Or you can simply analyse dumped packets in /var/lib/fakenet
. They must be without SSL at all.