Skip to content

Servers & Networks

Port forwarding

Using SSH

The example.com machine has a web server running on port 8000 internally (not exposed to the internet). With the following command you can now access the web server from http://localhost:4444.

ssh -L 4444:localhost:8000 user@example.com

SMTP Server

Setup a SMTP server with Python.

$ sudo python3 -m smtpd -n -c DebuggingServer 0.0.0.0:25
---------- MESSAGE FOLLOWS ----------
b'Date: Sun, 26 Sep 2021 18:21:06 +0200'
b'To: user@example.com'
b'From: me@example.com'
b'Subject: test Sun, 26 Sep 2021 18:21:06 +0200'
b'Message-Id: <20210926182106.026180@arch.localdomain>'
b'X-Mailer: swaks vDEVRELEASE jetmore.org/john/code/swaks/'
b'X-Peer: 127.0.0.1'
b''
b'This is a test mailing'
b''
------------ END MESSAGE ------------

Command to send the mail :

$ swaks --to user@example.com --from me@example.com --server localhost

HTTP Server

Setup a HTTP server with Python.

$ python3 -m http.server --bind 0.0.0.0 4444
Serving HTTP on 0.0.0.0 port 4444 (http://0.0.0.0:4444/) ...
127.0.0.1 - - [26/Sep/2021 18:24:47] code 404, message File not found
127.0.0.1 - - [26/Sep/2021 18:24:47] "GET /hello HTTP/1.1" 404 -

Command to the the HTTP request :

$ curl localhost:4444/hello

Ping

Use tcpdump to listen for ping request and reply.

$ sudo tcpdump icmp -n
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
18:53:25.737055 IP 192.168.117.150 > 192.168.117.58: ICMP echo request, id 1, seq 1, length 64
18:53:25.737224 IP 192.168.117.58 > 192.168.117.150: ICMP echo reply, id 1, seq 1, length 64

TCP connections

Add iptables rule that listen for new TCP connections.

$ sudo iptables -A INPUT -p tcp -m state --state NEW -j LOG --log-prefix "New TCP connection: " -i wlp3s0

Info

To remove the rule from iptables, execute the same commands but replace the -A with -D.

View the log :

$ journalctl -k --grep='New TCP connection: '
Sep 26 19:04:24 arch kernel: [NEW TCP connection] IN=wlp3s0 OUT= MAC=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SRC=192.168.117.150 DST=192.168.117.58 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=25957
...
Back to top