OpSec Operating Systems environment
Setup overview
The following setup is described in the present note:
An host Windows operating system using an
Hyper-V
hypervisor. theIPv4
andIPv6
connectivity is disabled on the host.A Linux virtual machine (such as
Kali Linux
). The VM is configured with two network adapters: one bridged on the targeted network and the other as an internal / private adapter that can only be used by local VMs on the host.A
Windows 10
virtual machine (such asCommandoVM
). The VM is configured with only the internal / private adapter and network traffic from the VM is routed to the targeted network through the Linux VM.
In the aforementioned configuration:
The host operating system should not leak network traffic on the targeted network.
Only the Linux VM is bridged on the network, limiting the use of a single
MAC
address in the targeted network. Switches might otherwise detect that multipleMAC
addresses are used over a single physical port (such as throughDHCP
requests).
Host configuration
Hyper-V virtual switches configuration
Two virtual Hyper-V
switches should be configured for the setup: an External
virtual switch bridged on the host system network adapter (<HYPERV_EXTERNAL_BRIDGED>
), and a Private
virtual switch (<HYPERV_PRIVATE>
), that will only be used by the local virtual machines.
The procedure to create virtual switches in Hyper-V
using the Hyper-V Manager
graphical utility is as follow:
Disabling IPv4 and IPv6 connectivity
The connectivity of the host operating system to the targeted network should be disabled, so that only the Linux VM is (directly) connected to the targeted network. In order to do so, IPv4
and IPv6
support on both the physical Ethernet network adapter and the Hyper-V
bridged external virtual switch <HYPERV_EXTERNAL_BRIDGED>
should be disabled.
It is also recommended to disable the Wi-Fi
network adapter (on systems having such network adapter):
Linux VM guest configuration
As described in the setup above, the Linux VM will have two network interfaces:
<ETH_EXTERNAL>
(example:eth0
) that will be bridged to the targeted network.<ETH_INTERNAL>
(example:eth1
) that will be internal / private to the host.
Hyper-V Enhanced Session Mode for Linux
Hyper-V
's Enhanced Session Mode
provides a number of feature (shared drives, better screen resolution,...) and gives a better user experience with the virtual machine guest. To more easily install the Enhanced Session Mode
feature in a Linux VM, it is recommended to use a Kali Linux
distro, as support for the feature is provided by the Kali
mainteners.
The kali-tweaks
utility can be used from kali
to install the hyperv-daemons
and enable support for Enhanced Session Mode
:
The Linux VM should then be shutdown and the following PowerShell cmdlet executed (with Administrators privileges):
Futher access to the Linux VM will be done through the Remote Desktop Protocol (RDP)
with the xrdp
utility. If the session is opened with user privileges, the root
user must be given access control to the current session in order to be able to open graphical utility. Otherwise an cannot open display: :1.0
error message may arise.
Updating the machine's hostname (to match the environment / context)
It is recommended to update the hostname of the system that will connect to the internal network, to help blend in normal traffic.
The Linux VM hostname can be updated by editing the /etc/hostname
file. The system must be rebooted for the hostname change to be effective.
Updating the network interface MAC address
It is recommenced to change the MAC address
associated with the <ETH_EXTERNAL>
network adapter, in order to bypass simple Network Access Control (NAC)
solutions and blend in the usual network traffic. The MAC
address of the <ETH_EXTERNAL>
network adapter should be changed through the hypervisor (or eventually the guest operating system).
By default Hyper-V
assign a MAC
address to virtual machines from a range defined globally and common to all virtual switches. The default MAC
addresses range start with 00-15-5D
(associated with Microsoft), and so even Linux VMs will appear to have a network adapter manufactured by Microsoft.
A custom static MAC
address can be assigned to a (shutdown) specific virtual machine through Hyper-V
::
The ifconfig
utility can be used to change the MAC address
from the Linux guest operating system (if spoofing of MAC
address is enabled from Hyper-V
):
If an Device or resource busy - you may need to down the interface
error occurs, the network interface will need to be shutdown:
Disabling IPv6 connectivity (if not needed)
If IPv6
is not used in the target environment, it is recommended to disable its support at a system level. IPv6
can be disabled from grub
as the Linux kernel has a boot option to disable IPv6
from startup. The grub
configuration file should be modified to add the ipv6.disable=1
boot option:
Following the modification, grub
should be updated using sudo update-grub
and the system rebooted.
IPv6
connectivity can also be disabled on a network adapter basis, for example using the Network Manager
:
Avoiding DNS request leaks
Avoiding self-hostname DNS requests.
By default, the Linux operating system may try to retrieve the current machine IP
. In order to avoid leaking unwanted DNS
requests on the targeted network, an entry for the system's hostname should be added in the /etc/hosts
file:
Setting DNS nameservers to localhost.
It is recommended to set the system-wide DNS
nameservers to localhost
, in order to avoid leaking DNS
requests (from the operating system, Web browsers, security products, ...) that may indicate an unusual traffic and generate alerts (from solutions such as DarkTrace
or Vectra
).
Setting the DNS nameservers
through the /etc/resolv.conf
is not sufficient as the file is indirectly managed by the systemd-resolved
service as well as the networking.service
(for instance for updates made through the NetworkManager
).
The reolvconf
utility can be used to permanently define the system's DNS nameservers
(and so even if no network adapters are configured at the of configuration):
Deploying a third-party local DNS server.
By default, glibc
sends all DNS
requests to the first DNS nameserver
specified in the /etc/resolv.conf
file. Using the aforementioned command, the nameserver 127.0.0.1
entry should be defined at the top of the resolv.conf
file, superseding eventual other DNS nameservers
(notably the eventual DNS nameservers
provided by the targeted network DHCP
servers).
As the Linux operating system does natively not support the definition of DNS nameservers
for specific domains. A third-party utility such as dnsmasq
must thus be used to associate specific DNS nameservers
with specific domains.
The following configuration file restrict can be used as a template for /etc/dnsmasq.conf
that configure 127.0.0.1
as the default DNS server
while defining specific domain and DNS
mappings as required.
The dnsmasq
service should then be enabled and started / restarted for the configuration to be effective:
Blocking inbound / outbound network traffic using UFW
The Uncomplicated Firewall (UFW)
utility can be used to block all inbound / outbound connections that do not match a rule, which allow to strictly control the network footprint of the system on the targeted network. UFW
translates rules into an iptables
chain, which follows the first-match policy.
IPv6
support for UFW
should first be enabled by adding IPV6=yes
to the UFW
configuration file /etc/default/ufw
:
Before adding any new rules, UFW
configuration should be restored to its initial state using:
The following entries in the UFW
default configuration file /etc/ufw/before.rules
(rules added before any other rule) should be deleted / commented out:
If UFW
is deployed and the Linux VM is used to forward network traffic from the Windows VM, the /etc/ufw/before.rules
file should be modified (as detailed in the "Forwarding of network traffic from the private interface" section below) at this stage (after the reset
operation and before applying any other rule).
The following commands can then be used as a template to configure blocking inbound / outbound rules with rules to allow network traffic through the <ETH_INTERNAL>
.
Forwarding of network traffic from the private network
IP Forwarding
should be enabled to allow the transfer of network packets received from the Windows VM (on the <ETH_INTERNAL>
network adapter) to the targeted network (through the <ETH_EXTERNAL>
network adapter):
If UFW
is used on the system, iptables
rules - first option below - should be created directly but added in the /etc/ufw/before.rules
file - second option below - (as existing iptables
rules are overwritten by the UFW
utility).
If UFW is not used to filter network traffic.
The following iptables
rules can be configured to route packets from <ETH_INTERNAL>
to <ETH_EXTERNAL>
:
If UFW is used to filter network traffic.
To configure equivalent forwarding using UFW
, the following settings should be configured:
In the default
UFW
configuration file/etc/default/ufw
, theDEFAULT_FORWARD_POLICY
parameter should be set toACCEPT
:In the
/etc/ufw/sysctl.conf
file,IPv4
and (if required)IPv6
forwarding should be enabled by uncommenting the following entries:In the
/etc/ufw/before.rules
file, the followingiptables
forwarding rules should be added at the top of the file:
Network interfaces configuration
The <ETH_EXTERNAL>
adapter should be configured appropriately depending on the context of the operation, and only after the Linux and Windows VMs are configured. For instance, the <ETH_EXTERNAL>
adapter could rely on the target network DHCP
servers to obtain an IPv4
or a static IPv4
could be specified.
A static IPv4
should be configured on the <ETH_INTERNAL>
adapter. The static IP
can be assigned by modifying the /etc/network/interfaces
file:
Following the modification of the /etc/network/interfaces
file, the networking
service must be restarted for the change to be effective: sudo systemctl restart networking
.
Then routes
should be configured to route all network traffic through <ETH_EXTERNAL>
, except for network traffic on the VMs private subnet. The ip
built-in utility can be used to this end. The routes configured this way will not persist across reboots.
Note: the Windows VM firewall may block inbound ICMP
packets, thus ping
should not be used to determine if the VMs can communicate with each others.
Windows VM guest configuration
As described in the setup above, the Windows VM will only have a <ETH_INTERNAL>
network adapter internal / private to the host (example Ethernet 1
). The network traffic from the Windows VM will be routed to the targeted network through the Linux VM.
Network configuration and routing traffic to the Linux VM
Not required for standalone Windows VM configuration.
The default gateway of the Windows VM should be configured to point the the IP
of the Linux VM (of the Linux VM's internal network interface).
Updating the machine's hostname (to match the environment / context)
It is recommended to update the hostname of the system that will connect to the internal network, to help blend in normal traffic.
Updating the network interface MAC address
Not required if the Windows VM is not bridged to the targeted network (as described in the setup specified in this note).
If the Windows VM is bridged to the targeted network, it is recommenced to change the MAC address
associated with the network adapter bridged to the network, in order to bypass simple Network Access Control (NAC)
solutions and blend in the usual network traffic. The MAC
address of the network adapter should be changed through the hypervisor (or eventually the guest operating system).
A custom static MAC
address can be assigned to a (shutdown) specific virtual machine through Hyper-V
:
The ipconfig
utility can be used to change the MAC address
from the Windows guest operating system (if spoofing of MAC
address is enabled from Hyper-V
):
Disabling IPv6 connectivity (if not needed)
If IPv6
is not used in the target environment, it is recommended to disable its support at a network interface level.
Disabling the LLMNR and NetBIOS protocols
It is recommended to disable the LLMNR
and NetBIOS
protocols that may leak broadcast requests (including Net-NTLM(v1|v2)
credentials) on the local subnet.
Disabling the Web Proxy Auto Discovery protocol
It is recommended to disable the Web Proxy Auto Discovery (WPAD)
protocol as it may leak DNS
and LLMNR
requests (for wpad*
) on the network. The WPAD
protocol can be disabled through the Windows settings or an host
file entry (advised to do both):
Disabling 802.1x authentication (if supported by the network adapter)
It is recommended to disable 802.1x
authentication (on a network interface / adapter basis), as it may leak Extensible Authentication Protocol (EAP)
responses on the network. If 802.1x
authentication is not supported by the <ETH_INTERNAL>
network adapter, the Authentication
tab will not appear in the adapter properties.
Disabling File and Printer Sharing & Link Layer Topology Discovery
The Link Layer Topology Discovery (LLTD)
protocol is used to determine / map a network's topology. The usage of the protocol is disabled by default for "Domain" and "Public" networks. It is however recommended to disable the usage of the protocol at a network adapter level to be certain that no LLTD
requests will be leaked.
It is also recommended to disable File and Printer Sharing at a adapter level.
Disabling the Simple Service Discovery Protocol
The Simple Service Discovery Protocol (SSDP)
is used as the discovery protocol in the Universal Plug and Play (UPnP)
protocols suite and may result in multicast SSDP
alive messages being sent over the network.
It is recommended to disable the support of the SSDP
protocol by stopping and disabling the SSDPSRV
Windows service:
Disabling the Internet Group Management Protocol
The Internet Group Management Protocol (IGMP)
is used to establish multicast group memberships on the local subnet and may result in multicast IGMP
membership requests / reports being sent over the network.
It is recommended to disable the support of the IGMP
protocol and to add a Firewall rule blocking all outbound IGMP
traffic:
Avoiding DNS request leaks by setting DNS nameservers to localhost
It is recommended to set the system-wide DNS nameservers
to localhost
or the DNS
server hosted by the Linux VM, in order to avoid leaking DNS
requests (from Windows, Web browsers, or security products) that may indicate an unusual traffic and generate alerts (from solutions such as DarkTrace
or Vectra
).
Windows VM configuration for setup with a Linux VM hosting a DNS service.
Standalone Windows VM configuration.
Then Name Resolution Policy Table (NRPT)
rules, host
file entries, or tools that allow DNS nameservers
specification can be used to make controlled DNS
requests.
Blocking inbound / outbound network traffic using the Windows Firewall
The Windows Firewall can be configured to block all inbound / outbound connections that do not match a rule, which allow to strictly control the network footprint of the system on the targeted network.
Even if the UFW
firewall is used to define firewalling iptables
rules on the Linux VM, the Windows VM network traffic will be forwarded directly and will not be subject to network filtering defined on the Linux VM.
The following netsh
commands or PowerShell cmdlets can be used to enable the Windows Firewall, and block all inbound / outbound traffic:
The following commands can be used to allow inbound / outbound traffic on a remote host or program basis:
The settings of the Windows Firewall can be restored to their default values:
References
https://www.tecmint.com/set-permanent-dns-nameservers-in-ubuntu-debian/
https://github.com/imp/dnsmasq/blob/master/dnsmasq.conf.example
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04
https://www.marmosetelectronics.com/computing/ufw-allow-outbound-connections/
https://gist.github.com/kimus/9315140
https://help.ubuntu.com/community/Router#Enable_IP_forwarding_and_Masquerading
http://woshub.com/manage-windows-firewall-powershell/
https://infinitelogins.com/2020/11/23/disabling-llmnr-in-your-network/
https://its.uiowa.edu/support/article/3576
Last updated