Network programming for security: sockets and asyncio
You write fast, polite checking tools for your own network’s hosts with TCP, UDP and asyncio.
Level 201 · 17 lessons · 15 practice labs
Lessons
Inside the socket
- The TCP handshake in code: connect, accept, close
- UDP sockets and protocols that may not answer
- Writing a small TCP server
- Bytes, encodings and binary data with struct
- Short task: add a simple command protocol to your server
An audit scanner
- Scope and permission: scanning only networks you own
- A connection checker that looks at many ports
- asyncio basics: hundreds of connections at once
- Rate limits and semaphores: scanning without flooding
- Short task: list the live services in the lab subnet
Speaking protocols
- DNS queries and record checks with dnspython
- TLS connections and reading certificates with the ssl module
- Collecting version details from SMTP and SSH services
- Bulk checks over SSH with paramiko
- Short task: find the servers that accept old TLS versions
Wrap-up
- Comparing results with the inventory file
- Capstone: an async service auditor for your own network
Practice labs
- A small server that understands commands: Write a TCP server that answers PING, TIME and QUIT, and show with nc that each command gets the right reply.
- Messages that arrive in pieces: Fix a server that expects each message in one recv call and breaks on fragmented data by adding line buffering, and show it works with a slow-sending client.
- A protocol with a binary header: Implement a protocol with a binary header carrying length and type fields on both server and client with struct, and show the server survives a bad length value.
- A UDP service that does not answer: Write a script that sends DNS queries over UDP to lab hosts and separates those that answer from those that time out.
- Clock offset of NTP servers: Query the NTP servers in the Windy Ridge Energy lab network with raw UDP packets, decode the time in the reply with struct, and report those that drift from local time.
- An async service auditor: Write an auditor that reads the inventory file, checks every host with asyncio, finds unexpected open ports and missing services, and outputs JSON.
- A scanner that stays in scope: Add a list of permitted subnets to your connection checker and show it stops before scanning when given an out-of-scope address.
- A live service list with asyncio: Write an asyncio checker that tries common ports concurrently across your own lab subnet, and output the results as a host-port table.
- Slow down a scanner that floods the network: Add a semaphore and rate limit to a checker that opens thousands of connections and knocks over a fragile lab service, and show the service stays up and results are complete.
- Missing DNS records: Write a dnspython script that queries the lab domain’s A, MX and TXT records, compares them to the expected list and reports what is missing.
- DNS and the inventory disagree: Resolve the hostnames in the Saltmarsh Fisheries inventory file in DNS and list separately those pointing to the wrong address, those that do not resolve and records missing from the inventory.
- A bulk SSH audit with paramiko: Write a tool that connects to five lab servers with a key, collects kernel version, whether root login is allowed and pending updates, and does not stop on an unreachable host.
- Read a certificate with the ssl module: Write a script that connects to the lab HTTPS server with the ssl module and prints the certificate subject, issuer and expiry date.
- Servers that accept old TLS: Write a script that tries each lab server with different maximum TLS versions and lists those that accept TLS 1.0 or 1.1.
- Find services on old versions: Collect version details from SMTP and SSH services in the lab network, compare them with the given minimum-version table, and report those needing an update with reasons.
About this course
You write fast, polite checking tools for your own network’s hosts with TCP, UDP and asyncio.
What you will learn
- Inside the socket
- An audit scanner
- Speaking protocols
- Wrap-up
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.