The
C machine has deliberately been placed in a public address range
so that it is accessible from the Internet.
The subnet containing services that are directly accessible from outside
is commonly referred to as the
“DMZ” (
“demilitarised zone”).
This subnet requires particularly careful attention because, unlike
hosts using private addresses, which are inaccessible, hosts in the
“DMZ” are directly exposed to malicious attempts originating
from the Internet.
It is therefore essential to secure these particularly exposed hosts
as well as their subnet.
A first step is to decouple the public addresses visible from the Internet
from the private addresses actually used by these machines.
Indeed, malicious activity generally begins with network reconnaissance to
identify vulnerabilities: making things less obvious makes this process
more difficult.
Now begin by modifying the addresses of your
“DMZ” so that they
belong to the private subnet
192.168.30.0/24.
To do this, run the command
sh SHARED/tuto_05_setup.sh XX priv on
machines
C and
D, replacing
XX with the number you
have recorded from your host system.
Check the address changes with
ip addr, the new route on
C with
ip route, and verify with
ping 192.168.30.2 that your
A
and
B machines can communicate correctly with the new address of
your
C machine.
Your
C machine is therefore no longer directly accessible from
the
“outside”.
To make it accessible again, it is necessary to perform
Destination
Network Address Translation (DNAT, address forwarding).
To do this, complete the firewall configuration on your
D router as
follows
For convenience, these lines can be edited in a
SHARED/script.sh file on the host system and then executed
with bash SHARED/script.sh from the virtual machine.
:
XX=1234 # substitute with your host number
cat <<EOF >>/etc/custom/20_firewall_setup.sh
iptables -t nat -A PREROUTING -d 100.64.${XX}.2 \\
-j DNAT --to-destination 192.168.30.2
EOF
/etc/custom/20_firewall_setup.sh
Be sure to set the
XX variable to the number you recorded from your
host system.
Regardless of the command's rather complicated syntax
The iptables tool has a very extensive command set that makes it
possible to express highly sophisticated rules.
, it instructs the firewall to translate (modify on the fly) the
destination IP addresses to the specified private address whenever
IP packets are addressed to the chosen public address.
Naturally, the firewall keeps track of the translations it performs for
incoming packets and carries out the corresponding reverse translations
(on the source IP address) when replies to those packets are generated.
In coordination with another participant, verify that your
C machine
is indeed accessible from an
“outside” A machine using
ping 100.64.XX.2 (replacing
XX with the number
you have recorded from your host system).
Carefully observe, on your
D router, the IP addresses of the packets
captured by
tcpdump -eni eth0 and
tcpdump -eni eth3; observe
the address translations on both the incoming and return paths.
From the point of view of the outside of your network, it appears as though
your
C machine has the chosen public IP address, but that is not
actually the case!
Indeed, if from your
C machine you try to reach another participant's
public IP address using
ping, you end up in the same situation as
the
B machine.
Your
“DMZ”, now using private addresses, cannot initiate traffic
leaving your site; it merely responds to incoming requests.
This property is extremely valuable from a security perspective because
malicious activity often attempts to spread from compromised sites
In particular, if malicious traffic originates from your site, you are
considered responsible for it!
This could happen if one of your “DMZ” machines were compromised and
then attempted to generate malicious traffic itself.
It would then be difficult to prove to the authorities that the
origin of this illegitimate traffic was not your responsibility.
.
Under these conditions, even if your
“DMZ” machine is compromised, it
will not be able to send any traffic to the rest of the world.
Another significant advantage of decoupling the visible public addresses
from the private addresses actually used lies in the flexibility it
provides when reconfiguring the network.
The
“DMZ” could be divided into multiple subnets (for security reasons),
or conversely several services that apparently run on different machines
could be consolidated onto a single machine (for example, due to hardware
availability).
From the outside, these architectural details are invisible, allowing them
to be modified at any time, for any reason, without the changes being
noticeable.
The previous
DNAT translation applied to an entire machine, but for
security reasons it is recommended to be more specific.
On your
D router, edit the firewall configuration using
nano /etc/custom/20_firewall_setup.sh
(or
vi if you are already familiar with it).
Adjust the previous
DNAT rule by adding
-p tcp --dport 80 right
after the public address (before the
\ symbol).
Reload this configuration with
/etc/custom/20_firewall_setup.sh.
Start a simple TCP server listening on port 80 on your
C machine with
ncat -lp 80.
Ask another participant to connect to this server from their
A machine
using
ncat 100.64.XX.2 80 (replacing
XX with the
number you have recorded from your host system).
Lines typed on the keyboard should be transmitted and displayed on both
sides.
Verify that, although TCP communication to port 80 of the public address
100.64.XX.2 is possible, a
ping command to that same
address does not succeed.
You have just selected very precisely which service you are exposing in
the
“DMZ”.