sudo apt update
sudo apt install apache2
sudo apt install telnetd -y
sudo apt install openssh-server
sudo apt install nmap
choi@it430b:~$ nmap 192.168.172.4
Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 14:18 EST
Nmap scan report for 192.168.172.4
Host is up (0.00082s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
80/tcp open http
111/tcp open rpcbind
Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds
sudo iptables -L -v shows the iptable
rules. Here, -L is for listing and -v is for being verbose. You can use three
chains when you construct rules for the IPTables firewall.
choi@it430a:~/Desktop$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
|
|
sudo iptables -A INPUT -p tcp --dport 1337 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 3389 -j DROP
ipt_rules.sh.
#!/bin/bash #ipt_rules.sh sudo iptables -A INPUT -p tcp --dport 1337 -j ACCEPT sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 3389 -j DROP
chmod 755 ipt_rules.sh
./ipt_rules.sh
choi@it430a:~/Desktop$ sudo iptables -L -v Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:1337 0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:domain 0 0 DROP tcp -- any any anywhere anywhere tcp dpt:ms-wbt-server Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination
choi@it430a:~/Desktop$ sudo iptables -L -v --line-numbers
Chain INPUT (policy ACCEPT 2 packets, 146 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:1337
2 0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:domain
3 0 0 DROP tcp -- any any anywhere anywhere tcp dpt:ms-wbt-server
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 1 packets, 73 bytes)
num pkts bytes target prot opt in out source destination
sudo iptables -D INPUT 2After executing the above command, you will see:
choi@it430a:~/Desktop$ sudo iptables -L -v --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:1337
2 0 0 DROP tcp -- any any anywhere anywhere tcp dpt:ms-wbt-server
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
sudo iptables -I INPUT 1 -p udp --dport 53 -j ACCEPTYou will see:
choi@it430a:~/Desktop$ sudo iptables -L -v --line-numbers Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:domain 2 0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:1337 3 0 0 DROP tcp -- any any anywhere anywhere tcp dpt:ms-wbt-server Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination
sudo iptables -F
choi@it430a:~/Desktop$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
|
From it430a, you can access the webserver on it430b.
|
Likewise, from it430b, you can access the webserver on it430a.
|
ipt_rules_wrong.sh that configures your iptables
firewall on VM it430a to the following specification:
For this, we may think about adding the following rules in the OUTPUT channel:
sudo iptables -P OUTPUT ACCEPTHere, -P is used to set the policy (default) rule.
For this, we may think about adding the following rules in the INPUT channel:
sudo iptables -P INPUT DROP
#!/bin/bash #ipt_rules_wrong.sh sudo iptables -P OUTPUT ACCEPT sudo iptables -P INPUT DROPIf you run the above script on it430a, you will see the following results:
choi@it430a:~$ chmod 755 ipt_rules_wrong.sh choi@it430a:~$ ./ipt_rules_wrong.sh choi@it430a:~$ sudo iptables -L -v Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination
sudo iptables -P INPUT DROP
ipt_rules_wrong2.sh so that the firewall allows the incoming TCP
packets as long is it's source port number is 80. The results should look as
follows:
choi@it430a:~$ ./ipt_rules_wrong2.sh choi@it430a:~$ sudo iptables -L -v Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- any any anywhere anywhere tcp spt:http Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destinationNow, let's run Firefox from it430a to it430b. It should work fine!
choi@it430b:~$ nmap 192.168.172.4
Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 13:08 EST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.15 seconds
So, it still seems that no access trials from it430b to it430 are allowed.
choi@it430b:~$ sudo nmap --source-port 80 192.168.172.4
Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 13:09 EST
Nmap scan report for 192.168.172.4
Host is up (0.00080s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
80/tcp open http
111/tcp open rpcbind
MAC Address: 08:00:27:50:76:69 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 0.38 seconds
Deliverables: ipt_rules_wrong2.sh and a screenshot proving
the correctness of your script and more screenshots showing the results of
running Firefox and nmaps.

IPTables Firewall can be configured through a kernel moduel called "conntrack" to track these kinds of outbound connections that are initiated from the internal host.
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPTThere are several states that
conntrack considers, but here we
just explain the two states we are concerned with:
ipt_rules_wrong2.sh and write
ipt_rules_fixed.sh.
When running the script, the rules should look as follows:
choi@it430a:~$ sudo iptables -L -v Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- any any anywhere anywhere ctstate RELATED,ESTABLISHED Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destinationYou may want to flush all previous rules first by using the following statement:
sudo iptables -F # flush all rulesThen, the namp from it430b will look as follows:
choi@it430b:~$ sudo nmap --source-port 80 192.168.172.4
Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 13:25 EST
Nmap scan report for 192.168.172.4
Host is up (0.00072s latency).
All 1000 scanned ports on 192.168.172.4 are filtered
MAC Address: 08:00:27:50:76:69 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 23.22 seconds
Deliverables: ipt_rules_fixed.sh and the screenshot showing
the rules of iptables and the nmap result.
ipt_rules2.sh that configures your iptables
firewall on VM it430a to the following specification:
conntrack module is used in the previous parts.
#!/bin/bash #ipt_rules2.sh sudo iptables -F # flush all rules sudo iptables -A INPUT -i lo -j ACCEPT # free pass for traffic with the loop back interface (lo) # add more rules...
Your nmap results should look something like the following:
From it430a
choi@it430a:~/$ nmap 192.168.172.5 ...(omitted)... PORT STATE SERVICE 22/tcp filtered ssh 23/tcp filtered telnet 80/tcp open http 111/tcp open rpcbind Nmap done: 1 IP address (1 host up) scanned in 1.56 seconds choi@it430a:~$/ nmap 192.168.172.6 ...(omitted)... PORT STATE SERVICE 22/tcp open ssh 23/tcp filtered telnet 80/tcp open http 111/tcp open rpcbind Nmap done: 1 IP address (1 host up) scanned in 1.57 seconds |
From it430b:
choi@it430b:~/$ sudo nmap --source-port 80 192.168.172.4
...(omitted)...
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 4.09 seconds
|
From it430c
choi@it430c:~/$ sudo nmap --source-port 80 192.168.172.4
...(omitted)...
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 5.01 seconds
|
ipt_rules3.sh that configures your iptables
firewall on VM it430a to the following specification:
#!/bin/bash #ipt_rules3.sh sudo iptables -F # flush all rules sudo iptables -A INPUT -i lo -j ACCEPT # free pass for traffic with the loop back interface (lo) # add more rules...
Your nmap results should look something like the following:
From it430a
choi@it430a:~/$ sudo nmap --source-port 80 192.168.172.5 Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 14:01 EST sendto in send_ip_packet_sd: sendto(5, packet, 44, 0, 192.168.172.5, 16) => Operation not permitted Offending packet: TCP 192.168.172.4:80 > 192.168.172.5:1723 S ttl=42 id=37542 iplen=44 seq=197578923 win=1024sendto in send_ip_packet_sd: sendto(5, packet, 44, 0, 192.168.172.5, 16) => Operation not permitted (...omitted...) Nmap scan report for 192.168.172.5 Host is up (0.00086s latency). All 1000 scanned ports on 192.168.172.5 are filtered MAC Address: 08:00:27:6F:C1:40 (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 34.94 seconds choi@it430a:~$/ sudo nmap --source-port 80 192.168.172.6 Starting Nmap 7.80 ( https://nmap.org ) at 2024-02-21 14:06 EST sendto in send_ip_packet_sd: sendto(5, packet, 44, 0, 192.168.172.6, 16) => Operation not permitted Offending packet: TCP 192.168.172.4:80 > 192.168.172.6:554 S ttl=44 id=21516 iplen=44 seq=2695886880 win=1024 sendto in send_ip_packet_sd: sendto(5, packet, 44, 0, 192.168.172.6, 16) => Operation not permitted (...omitted...) Nmap scan report for 192.168.172.6 Host is up (0.00069s latency). All 1000 scanned ports on 192.168.172.6 are filtered MAC Address: 08:00:27:13:F0:C6 (Oracle VirtualBox virtual NIC) Nmap done: 1 IP address (1 host up) scanned in 34.94 seconds
From it430b:
choi@it430b:~/$ nmap 192.168.172.4
...(omitted)...
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 4.09 seconds
From it430c
choi@it430c:~/$ nmap 192.168.172.4
...(omitted)...
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 5.01 seconds
~/bin/submit -c=IT430 -p=lab07 *.sh lab07_report.docx