Linux, Windows & Networking Internals for Hackers
Automated security scanners are useful, but they only scratch the surface. When a firewall drops your probe, a reverse shell dies silently, or a privilege escalation path hides inside a misconfigured file permission, you cannot rely on push-button tools—you need to understand what the operating system and network stack are actually doing under the hood.
In this chapter, you will master the core networking protocols and Linux/Windows internals that every ethical hacker and security engineer relies on daily, then put them into practice with Bash, Python sockets, and Scapy.
- Networking Core: OSI vs. TCP/IP layers, the TCP three-way handshake, subnetting (CIDR), DNS resolution, HTTP/HTTPS, and TLS certificates.
- OS Internals: Linux and Windows file permissions, process management, and automation with Bash and PowerShell.
- Hands-On Labs: Build a Bash log parser, a Python TCP socket banner grabber, and a custom TCP SYN packet crafter using Scapy.
127.0.0.1 or an isolated private subnet). Unauthorized scanning or packet injection is illegal.1. OSI Layers & The TCP/IP Three-Way Handshake
Every packet you capture in Wireshark or craft in Scapy is wrapped in layers. Understanding the OSI Model tells you exactly where an attack or defense operates.
| OSI Layer | Protocols / Examples | Security Relevance |
|---|---|---|
| 7. Application | HTTP, HTTPS, DNS, SSH, SMB | SQLi, XSS, SSRF, credential stuffing, DNS tunneling |
| 6. Presentation | TLS/SSL, JSON, Base64 | Weak ciphers, expired or self-signed certificates |
| 5. Session | NetBIOS, RPC, Session Tokens | Session hijacking, token replay attacks |
| 4. Transport | TCP, UDP | SYN scans, port enumeration, SYN floods |
| 3. Network | IP, ICMP, IPSec | IP spoofing, subnet discovery, routing pivots |
| 2. Data Link | Ethernet, ARP, VLAN | ARP spoofing, MAC flooding, VLAN hopping |
| 1. Physical | Cables, Wi-Fi RF, USB | Rogue access points, hardware taps |
How the TCP Three-Way Handshake Works
Before a client and server exchange HTTP or SSH data over TCP, they establish a reliable connection using three control packets: SYN, SYN-ACK, and ACK. Security tools like Nmap abuse this exact sequence (for example, sending a SYN and resetting after receiving SYN-ACK to perform a half-open stealth scan).
Animated TCP/IP Three-Way Handshake & Session Setup
Once the 3-way handshake completes, both sides enter the ESTABLISHED state and can negotiate TLS or transmit application-layer payloads.
2. Subnetting, DNS, HTTP/HTTPS & TLS Certificates
Subnetting & CIDR Notation
IPv4 addresses are 32 bits long. CIDR notation (like 192.168.10.0/24) specifies how many leading bits belong to the network prefix, leaving the remaining bits for host addresses.
/24= 256 total IPs (254 usable hosts) – standard office or lab LAN./26= 64 total IPs (62 usable hosts) – segmented VLAN or DMZ./32= 1 single host IP – used in firewall rules and host routes.
DNS Resolution
DNS translates human-readable domains into IP addresses (typically over UDP port 53, or TCP port 53 for zone transfers). Hackers inspect DNS records during reconnaissance using dig or nslookup: A (IPv4), AAAA (IPv6), MX (mail servers), TXT (SPF/verification tokens), and CNAME (aliases).
HTTP/HTTPS & TLS Certificates
HTTP is a plaintext request/response protocol (methods like GET, POST, PUT, headers, and status codes like 200 OK, 403 Forbidden). HTTPS wraps HTTP inside TLS (Transport Layer Security).
During a TLS handshake, the server presents an X.509 digital certificate signed by a trusted Certificate Authority (CA). Security analysts inspect TLS certificates (openssl s_client -connect host:443) to discover hidden subdomains listed in the Subject Alternative Name (SAN) field or detect weak/expired certificates.
3. Linux & Windows Internals: Permissions, Processes & Scripting
Post-exploitation and defensive triage both depend on knowing how Linux and Windows enforce access control and run background processes.
| Concept | Linux Internals | Windows Internals |
|---|---|---|
| File Permissions | Owner/Group/Other (rwx, octal e.g. 755, 600), plus special bits like SUID (4755) |
NTFS ACLs (Access Control Lists) managed via icacls or PowerShell Get-Acl |
| Process Management | ps aux, ss -tulpn, kill -9 <PID>, inspect /proc/<PID> |
Get-Process, tasklist /svc, netstat -ano, Stop-Process -Id <PID> |
| Native Scripting | Bash (grep, awk, sed, find) |
PowerShell (object-oriented pipelines: Where-Object, Select-Object) |
Quick PowerShell Example: Audit Listening Ports & Owning Processes (Windows)
# List all listening TCP ports and resolve the owning process name
Get-NetTCPConnection -State Listen | ForEach-Object {
$proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
[PSCustomObject]@{
LocalPort = $_.LocalPort
PID = $_.OwningProcess
ProcessName = $proc.ProcessName
}
} | Sort-Object LocalPort | Format-Table -AutoSize
4. Hands-On Lab: Bash Log Parsing, Python Sockets & Scapy
Let's build three practical automation scripts you can run in a local Linux or WSL2 lab environment.
Lab 1: Automated Log Parsing with Bash
When defending a Linux server or analyzing a compromised host, you often need to spot brute-force attempts fast. Create a sample log file and a Bash script to extract the top offending IPs.
File: parse_ssh_logs.sh
#!/usr/bin/env bash
set -euo pipefail
LOG_FILE="${1:-sample_auth.log}"
# Create a sample log if none exists so you can test immediately
if [ ! -f "$LOG_FILE" ]; then
cat <<EOF > "$LOG_FILE"
Nov 18 10:01:12 lab-host sshd[2101]: Failed password for invalid user admin from 192.168.1.45 port 51234 ssh2
Nov 18 10:01:14 lab-host sshd[2102]: Failed password for root from 192.168.1.45 port 51235 ssh2
Nov 18 10:01:19 lab-host sshd[2105]: Accepted publickey for devops from 10.0.0.12 port 49811 ssh2
Nov 18 10:01:22 lab-host sshd[2109]: Failed password for root from 192.168.1.45 port 51238 ssh2
Nov 18 10:01:30 lab-host sshd[2114]: Failed password for invalid user test from 172.16.0.88 port 44120 ssh2
EOF
fi
echo "=== Top Failed SSH Login Sources ==="
grep "Failed password" "$LOG_FILE" \
| awk '{for(i=1;i<=NF;i++) if($i=="from") print $(i+1)}' \
| sort \
| uniq -c \
| sort -nr
Run & Expected Output
$ chmod +x parse_ssh_logs.sh && ./parse_ssh_logs.sh
=== Top Failed SSH Login Sources ===
3 192.168.1.45
1 172.16.0.88
Lab 2: TCP Socket Connection & Banner Grabber in Python
Python's built-in socket library lets you perform full TCP 3-way handshakes, check open ports, and read service banners without external dependencies.
File: banner_grabber.py
import socket
import sys
def probe_port(target_ip: str, port: int, timeout: float = 2.0) -> None:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(timeout)
result = sock.connect_ex((target_ip, port))
if result == 0:
print(f"[+] Port {port}/tcp is OPEN")
try:
# Send a minimal HTTP HEAD probe if the service waits for input
if port in (80, 8000, 8080):
sock.sendall(b"HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n")
banner = sock.recv(1024).decode("utf-8", errors="replace").strip()
if banner:
first_line = banner.splitlines()[0]
print(f" Banner: {first_line}")
except socket.timeout:
print(" Banner: (no immediate banner returned)")
else:
print(f"[-] Port {port}/tcp is CLOSED or FILTERED")
if __name__ == "__main__":
host = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1"
ports = [22, 80, 443, 8000]
print(f"Probing {host} ...")
for p in ports:
probe_port(host, p)
python3 -m http.server 8000, then run python3 banner_grabber.py 127.0.0.1 to see port 8000 report OPEN with its HTTP banner.Lab 3: Crafting a Custom TCP SYN Packet with Scapy
Standard sockets let the OS kernel manage the TCP handshake. Scapy gives you raw packet-level control so you can stack Layer 3 (IP) and Layer 4 (TCP) headers manually and inspect the exact flags returned.
Install Scapy (inside a virtual environment)
python3 -m venv .venv && source .venv/bin/activate
pip install scapy
File: syn_probe.py
from scapy.all import IP, TCP, sr1
import sys
def syn_check(target_ip: str, target_port: int) -> None:
# Build Layer 3 (IP) + Layer 4 (TCP SYN) packet
packet = IP(dst=target_ip) / TCP(dport=target_port, flags="S", seq=100)
print(f"[*] Sending TCP SYN to {target_ip}:{target_port} ...")
response = sr1(packet, timeout=2, verbose=0)
if response is None:
print("[-] No response (filtered by firewall or host unreachable)")
elif response.haslayer(TCP):
flags = response[TCP].flags
if flags == 0x12: # SYN + ACK
print(f"[+] Port {target_port} is OPEN (received SYN-ACK)")
# Politely tear down the half-open connection with RST
rst = IP(dst=target_ip) / TCP(dport=target_port, flags="R", seq=response[TCP].ack)
sr1(rst, timeout=1, verbose=0)
elif flags == 0x14: # RST + ACK
print(f"[-] Port {target_port} is CLOSED (received RST-ACK)")
else:
print(f"[?] Received unexpected TCP flags: {flags}")
if __name__ == "__main__":
ip = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1"
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
syn_check(ip, port)
Run with root/sudo privileges (required for raw sockets)
$ sudo .venv/bin/python syn_probe.py 127.0.0.1 8000 [*] Sending TCP SYN to 127.0.0.1:8000 ... [+] Port 8000 is OPEN (received SYN-ACK)
5. Hands-On Practice
Run openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -issuer -dates to view the Certificate Authority and expiration dates of a public HTTPS site.
Use find /usr/bin -perm -4000 2>/dev/null on your Linux lab machine to list binaries with the SUID bit set, and explain why an unintended SUID binary is a privilege escalation risk.
Modify syn_probe.py to accept a comma-separated list of ports (e.g. 22,80,443,8000) and print a summary table of all open ports found on your local lab host.
6. Interview Questions
Answer: A TCP Connect scan completes the full 3-way handshake (SYN → SYN-ACK → ACK) using the OS's standard connect() syscall. A SYN scan sends a raw SYN packet and, upon receiving SYN-ACK, immediately sends a RST instead of ACK, avoiding a full application-layer session.
4755 matter in Linux security?
Answer: The leading 4 sets the SUID (Set User ID) bit. When any user executes that file, the process runs with the privileges of the file's owner (often root). If the binary allows shell escapes or arbitrary file writes, a low-privileged user can escalate to root.
Answer: HTTPS uses TLS to encrypt the HTTP headers, URL paths, cookies, and body, preventing eavesdropping and tampering. However, it does not hide the destination IP address, port, packet sizes, or (unless Encrypted Client Hello is enabled) the domain name sent in the TLS SNI extension and DNS queries.
Conclusion
Mastering Linux, Windows, and networking internals transforms you from someone who blindly runs tools into an engineer who can read packets, audit operating systems, and write custom automation on demand. Practice these Bash, Python socket, and Scapy scripts in your home lab until reading headers, permissions, and process tables feels like second nature.
Official Documentation
- Scapy Official Documentation
- Python Standard Library – socket Module
- Microsoft Learn – PowerShell Documentation
Upgradix by Shrash Studio – Learn Technology. Build Your Future.
Discussion & Comments
0No comments yet
Start the discussion above — ask a question, share a tip, or reply to a comment.