This shows you the differences between two versions of the page.
rl:labs:08:contents:07 [2020/12/01 10:13] iulia.florea created |
rl:labs:08:contents:07 [2023/11/05 12:56] (current) vlad_iulius.nastase |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== 7. [5p] Blocare SSH ==== | + | ==== 07. [10p] Format de pachete la port forwarding ==== |
- | Ne propunem ca stația ''green'' să nu fie acesibilă nici prin SSH. Pentru aceasta adăugați pe stația ''host'' o regulă ''iptables'' care va bloca traficul aferent serviciului SSH (portul 22). | + | La exercițiul [[rl:labs:09:contents:03|]] am observat cum se modifică adresa IP sursă și portul sursă în cazul translatării de adrese. La port forwarding vom observa cum se modifică adresa IP destinație (de aici și numele DNAT: ''Destination NAT''). |
- | <hidden> | + | Vom captura traficul SSH inițiat din exterior către stația ''red'', prin intermediul portului ''10022'' al stației ''host''. Este vorba de traficul înainte de //port forwarding//. Pentru aceasta, pe stația ''host'' vom folosi comanda<code bash> |
- | <solution> | + | root@host:~# tcpdump -n -i eth0 tcp dst port 10022 -w /home/student/portfwd_eth0_output.pcap |
- | <code bash> | + | |
- | root@host:~# iptables -A FORWARD -d green -p tcp --dport ssh -j DROP | + | |
</code> | </code> | ||
- | </solution> | ||
- | </hidden> | ||
- | Verificați adăugarea regulii ''iptables'' și apoi verificați de pe stația ''red'' blocarea traficului SSH către stația ''green''. | + | Pe un alt terminal, tot pe stația ''host'' capturăm traficul **după** //port forwarding//, pe interfața ''veth-red'' către portul SSH (''22'') al stației red. Pe stația ''host'' folosim comanda<code bash> |
+ | root@host:~# tcpdump -n -i veth-red tcp dst port 22 -w /home/student/portfwd_veth-red_output.pcap | ||
+ | </code> | ||
- | <hidden> | + | Pentru a genera trafic, de pe ''fep.grid.pub.ro'' realizăm o conexiune SSH la stația ''host'' pe portul ''10022'', conexiune ce va fi redirectată la portul ''22'' al stației ''red'':<code bash> |
- | <solution> | + | mihai.carabas@fep:~$ ssh -l student $ADRESA_IP_VM -p 10022 |
+ | root@host.local's password: | ||
+ | [...] | ||
+ | root@red:~# | ||
+ | </code> | ||
+ | |||
+ | <note important> | ||
+ | Pentru a vizualiza capturile salvate în cele două fișiere copiați-le la voi local (pe calculatorul vostru) folosind ''scp'' și deschideți-le cu utilitarul ''wireshark''. | ||
+ | |||
+ | <spoiler (click pentru expandare) Copiere fișiere din VM pe local> | ||
<code bash> | <code bash> | ||
- | root@host:~# iptables -L FORWARD -n -v | ||
- | Chain FORWARD (policy ACCEPT 94 packets, 10307 bytes) | ||
- | pkts bytes target prot opt in out source destination | ||
- | 2 120 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:23 | ||
- | 0 120 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:21 | ||
- | 0 0 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:22 | ||
- | root@red:~# ssh green | + | $USER_FEP@fep:~$ scp -i ~/.ssh/openstack.key student@$ADRESA_IP_VM:portfwd_eth0_output.pcap ./ # Dacă fișierul pf_eth0_output.pcap se află în directorul /home/student/ |
- | ^C | + | $USER_FEP@fep:~$ scp -i ~/.ssh/openstack.key student@$ADRESA_IP_VM:portfwd_veth-red_output.pcap ./ # Dacă fișierul pf_veth-red_output.pcap se află în directorul /home/student/ |
+ | |||
+ | student@lab-EG207-EG208:~$ scp $USER_FEP@fep.grid.pub.ro:portfwd_eth0_output.pcap ./ # Dacă fișierul portfwd_eth0_output.pcap se află în home-ul utilizatorului de pe fep. | ||
+ | student@lab-EG207-EG208:~$ scp $USER_FEP@fep.grid.pub.ro:portfwd_veth-red_output.pcap ./ # Dacă fișierul portfwd_veth-red_output.pcap se află în home-ul utilizatorului de pe fep. | ||
- | root@host:~# iptables -L FORWARD -n -v | ||
- | Chain FORWARD (policy ACCEPT 94 packets, 10307 bytes) | ||
- | pkts bytes target prot opt in out source destination | ||
- | 2 120 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:23 | ||
- | 2 120 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:21 | ||
- | 3 180 DROP tcp -- * * 0.0.0.0/0 192.168.2.2 tcp dpt:22 | ||
</code> | </code> | ||
- | </solution> | + | </spoiler> |
- | </hidden> | + | </note> |
+ | |||
+ | <note> | ||
+ | Exemplu instalare și pornire ''Wireshark'' (pe sisteme Debian): | ||
+ | <code bash> | ||
+ | student@mjolnir:~$ apt-get install wireshark | ||
+ | student@mjolnir:~$ wireshark portfwd_eth0_output.pcap & | ||
+ | student@mjolnir:~$ wireshark portfwd_veth-red_output.pcap & | ||
+ | </code> | ||
+ | </note> | ||
+ | |||
+ | În capturile realizate de comenzile de mai sus, observăm cum se translatează adresa IP și portul destinație din perechea ''<$ADRESA_IP_VM, 10022>'' în perechea ''<192.168.1.2, 22>''. |