Ethical Hacking & Cyber Defense · Unit 2 of 8
Unit 2: Networking for security
Ports and protocols, the TCP handshake scanners rely on, DNS, HTTP and TLS through a security lens, and how firewalls and segmentation limit an attacker.
Opens the first lesson of this unit in Ethical Hacking & Cyber Defense. Every lesson is open from the start.
Lesson 1: IP addresses, ports and protocols
Goal: Explain how IP addresses and ports identify a service, and name the common ports and the services behind them.
Every device on a network has an IP address, like a street address. A single server usually runs several services at once: a website, remote login, email and so on. Ports tell traffic which service it is for, like apartment numbers in one building. A port is a number from 0 to 65,535, and the combination of address and port, such as 203.0.113.10:443, identifies one service on one machine.
Two transport protocols carry most traffic. TCP sets up a connection first and makes sure data arrives complete and in order, so it is used for websites, email and file transfer. UDP just sends packets without a connection, which is faster but less reliable, so it is used for DNS lookups, video calls and games. Security tools treat them differently, so you always need to know which one a service uses.
| Port | Protocol | Service | Security note |
|---|---|---|---|
| 22 | TCP | SSH (secure remote login) | Should use keys, not passwords; often targeted by password guessing |
| 23 | TCP | Telnet | Sends everything, including passwords, unencrypted; should be disabled |
| 25 | TCP | SMTP (sending email) | Misconfigured servers can be abused to relay spam |
| 53 | UDP/TCP | DNS | Translates names to addresses; can leak information about a network |
| 80 / 443 | TCP | HTTP / HTTPS | Websites; HTTP is unencrypted, HTTPS uses TLS |
| 445 | TCP | SMB (Windows file sharing) | Should never be open to the internet; used by several famous worms |
| 3389 | TCP | RDP (Windows remote desktop) | A frequent target when exposed to the internet |
Worked example: reading a service address
- A ticket mentions traffic to 198.51.100.25:3389.
- The address identifies the machine; port 3389 is the standard port for Windows Remote Desktop.
- So someone is trying to reach a remote desktop service on that machine. If it is exposed to the whole internet, that is a finding: it should sit behind a VPN with multi-factor authentication.
Knowing the common ports lets you read logs and scan results at a glance. Standard ports are conventions, though: a service can be moved to any port, so always confirm what is really listening.
Hands-on lab in the room: Port and service matcher. Match each port to its service and its usual security concern.
- IP address
- The number that identifies a device on a network, such as 192.0.2.15.
- Port
- A number from 0 to 65,535 that identifies which service on a machine traffic is for.
- TCP
- Transmission Control Protocol: a connection-based transport that delivers data complete and in order.
- UDP
- User Datagram Protocol: a connectionless transport that is fast but does not guarantee delivery.
- SSH
- Secure Shell: an encrypted protocol for remote command-line login, usually on port 22.
Remember: Address finds the machine, port finds the service. Learn 22, 53, 80, 443, 445 and 3389 by heart.
Lesson 2: The TCP handshake and what scanners see
Goal: Describe the three-way handshake and explain how a scanner decides whether a port is open, closed or filtered.
Before two computers exchange data over TCP, they perform a three-way handshake. The client sends a SYN (synchronize) packet: “I would like to talk.” If a service is listening, the server replies with SYN-ACK (synchronize-acknowledge): “Sure, I am here.” The client finishes with an ACK: “Great, let's start.” Only then does real data flow.
| What the scanner sends | What comes back | What the scanner reports | What it means |
|---|---|---|---|
| SYN | SYN-ACK | open | A service is listening on that port |
| SYN | RST (reset) | closed | The host is reachable, but nothing is listening there |
| SYN | Nothing, or an ICMP “unreachable” error | filtered | Something, usually a firewall, is blocking the probe |
Port scanners use this behaviour. A SYN scan sends the first packet and watches the reply, then resets the connection instead of finishing it, which is fast and quieter. A connect scan completes the full handshake through the operating system, which is simpler but more likely to appear in application logs. UDP has no handshake, so UDP scanning is slower and less certain: silence might mean open or filtered.
For defenders, the table is just as useful. A port that shows as filtered from the internet tells you the firewall is doing its job. A port that shows as open should be one you meant to expose. Every open port is a service someone must patch and watch, which is why “close what you do not need” is one of the most effective security rules there is.
Worked example: interpreting three probes
- Port 443 replies SYN-ACK: open. The company's website is listening, as expected.
- Port 8080 replies RST: closed. The host answered, but no service is running there.
- Port 3306 gives no reply at all: filtered. A firewall is silently dropping the probe, so the database is not exposed to this network.
Three different answers tell three different stories. Reading them correctly is the foundation of every scan report.
- Three-way handshake
- The SYN, SYN-ACK, ACK exchange that opens a TCP connection.
- SYN
- The first packet of a TCP handshake, asking to start a connection.
- RST
- A TCP reset packet, sent when no service is listening or to abort a connection.
- Filtered port
- A port where probes get no useful reply, usually because a firewall blocks them.
- SYN scan
- A scan that sends SYN packets and reads the replies without completing the handshake.
Remember: SYN-ACK means open, RST means closed, silence usually means a firewall.
Lesson 3: DNS, HTTP and TLS through a security lens
Goal: Read DNS records, HTTP methods and status codes, and explain what TLS does and does not protect.
DNS turns names into addresses. Its records reveal a lot about an organization, which is why reconnaissance starts here. An A record maps a name to an IPv4 address and AAAA to an IPv6 address. MX records name the mail servers. CNAME points one name at another. TXT records hold text, often email security settings and proofs of domain ownership for cloud services, which can hint at which providers a company uses.
HTTP is how browsers and apps talk to web servers. A request has a method (GET to read, POST to send data, PUT and DELETE in many APIs), a path, headers and sometimes a body. The response has a status code: 200 means OK, 301 and 302 are redirects, 401 means you need to log in, 403 means you are not allowed, 404 means not found and 500 means the server hit an error. Testers watch for 500 errors because an input that crashes the server often points at a weakness.
GET /account/settings HTTP/1.1
Host: portal.example.com
Cookie: session=7f3a91c2...
HTTP/1.1 403 Forbidden
Content-Type: text/html
TLS (the “S” in HTTPS) encrypts traffic between browser and server and lets the browser check the server's certificate, so people on the same network cannot read or quietly change the data. TLS protects the data in transit only. It does not make the website itself secure: a site with a padlock can still have broken logins or injection bugs. And certificates are public; certificate transparency logs list every certificate issued, which can reveal subdomains such as test or staging servers.
Worked example: what DNS records reveal
- The MX record for example.com points to a well-known cloud email provider.
- A TXT record contains a verification string for a cloud file-sharing service.
- Certificate transparency logs show certificates for portal.example.com, vpn.example.com and staging-portal.example.com.
Without touching a single company server, you now know the email provider, a cloud service, a VPN and a staging site that may be less protected. Defenders should review the same public information about themselves.
- DNS
- Domain Name System: the service that translates names like example.com into IP addresses.
- MX record
- A DNS record that names the mail servers for a domain.
- HTTP status code
- A three-digit number in an HTTP response, such as 200 OK, 403 Forbidden or 500 Server Error.
- TLS
- Transport Layer Security: the protocol that encrypts web traffic and verifies the server's certificate.
- Certificate transparency
- Public logs of every TLS certificate issued, which can reveal a domain's subdomains.
Remember: DNS and certificates leak the map; status codes leak the behaviour; TLS only protects the trip.
Lesson 4: Firewalls, segmentation and the network map
Goal: Read simple firewall rules and explain how default deny, segmentation and a DMZ limit what an attacker can reach.
A firewall decides which traffic may pass, using rules that match on things like source address, destination address, port and protocol. Rules are usually checked from top to bottom and the first match wins. The safest design is default deny: block everything, then allow only what is needed. The opposite, “allow everything and block known-bad things”, always misses something.
| # | Source | Destination | Port | Action |
|---|---|---|---|---|
| 1 | Any | Web server 203.0.113.10 | 443/TCP | Allow |
| 2 | IT subnet 192.0.2.0/24 | All servers | 22/TCP | Allow |
| 3 | Web server | Database 192.0.2.50 | 5432/TCP | Allow |
| 4 | Any | Any | Any | Deny |
Segmentation splits a network into zones so a problem in one does not spread to all. Public-facing servers often sit in a DMZ (demilitarized zone), a separate segment between the internet and the internal network. Office computers, servers, guest Wi-Fi and payment systems each get their own segment, often using VLANs, with firewall rules between them. If an attacker compromises a laptop on guest Wi-Fi, segmentation means they still cannot reach the payroll database.
Two more terms complete the picture. NAT (network address translation) lets many internal devices share one public address; it hides internal addresses but is not a security control on its own. A VPN creates an encrypted tunnel so remote staff can reach internal systems as if they were in the office, which is why exposed remote desktop and admin panels should sit behind one, ideally with multi-factor authentication.
Worked example: reading the rule set
- Can someone on the internet reach the database on port 5432? Rule 1 only allows 443 to the web server, rules 2 and 3 do not match an internet source, so rule 4 denies it.
- Can the web server reach the database? Rule 3 allows it, which the website needs.
- Can an office laptop outside the IT subnet use SSH on a server? Rule 2 does not match its address, so rule 4 denies it.
Only the traffic the business needs is allowed. Everything else falls through to the final deny rule, which is exactly what default deny means.
- Firewall
- A device or software that allows or blocks network traffic according to rules.
- Default deny
- A firewall design that blocks everything unless a rule explicitly allows it.
- Segmentation
- Dividing a network into separate zones with controlled traffic between them.
- DMZ
- A separate network segment for public-facing servers, between the internet and the internal network.
- VPN
- Virtual private network: an encrypted tunnel that lets remote users reach an internal network securely.
Remember: Block everything, allow only what is needed, and wall off zones so one breach stays small.
Practise it in Ethical Hacking & Cyber Defense
Each lesson ends with three questions that check you can use the idea, not just recognise it. Wrong answers explain why and come back in Review. The unit ends with a 6-question quiz; pass it with 80% or more to master the unit. Hands-on lab: Port and service matcher.
Every lesson is free: no ads, no lives and no paywall.