TExcelTAD
Home › Programming for Security: Python, Bash, PowerShell & C Tools › Programming for Security: Introduction

Programming for Security: Introduction

A security analyst spends a surprising part of the day writing small programs. An alert fires and someone needs the forty log lines around it, a vendor ships a certificate and someone needs to know when it expires, a server is suspected of having been changed and someone needs to compare its files with yesterday's. None of these jobs needs a large application. Each one needs a short, careful tool that reads untrusted input, does one thing correctly and prints a result that another person, or another program, can trust.

This course teaches you to write those tools and to read the code that other people wrote, looking for the bugs that matter. It is the third course of the Cybersecurity track, after Security Foundations and alongside Networking for Security.

The languages and what each is for

No single language covers security work. The table lists the ten that the track uses, in the order you are most likely to need them.

Language What security people use it for In this course
Python the default for analysis and tooling: parsing logs and packets, hashing, crypto, quick scripts that grow into tools; Scapy, cryptography, pandas most examples, and all eight projects
Bash gluing tools together on Linux: grep, awk, find, sha256sum, openssl, nmap in pipelines; incident-response one-liners safe scripting, log pipelines, tool sessions
PowerShell the same job on Windows, with objects instead of text: event logs, file hashes, Active Directory, configuration audits objects, Get-FileHash, event exports
C the language of operating systems, network daemons and embedded firmware, and therefore of most memory-safety bugs reading buffers, lengths and integer types
C++ browsers, game engines, large desktop software: the same memory risks as C, plus object lifetimes std::string and bounds-checked access as the fix
JavaScript everything in the browser: the language of cross-site scripting and of most web front ends you will review DOM sinks, innerHTML versus textContent, eval
SQL every database-backed application; injection when queries are built from strings string-built versus parameterised queries
Assembly reading what the compiler really produced: reverse engineering, malware analysis, exploit mitigations reading compiler output for a bounds check
Rust new systems code without memory-safety bugs: parts of Linux, Windows, Android and Firefox are moving to it what the borrow checker and bounds checks buy
Go network services, cloud tooling and many security tools (scanners, proxies, agents), shipped as one static binary slices with bounds checks and recovered panics

If you only have time for two, learn Python and Bash well: together they cover most of the day-to-day work. Add PowerShell when you work with Windows fleets, and enough C to read a crash report. The other languages appear when you review code written in them.

The map

Python for security bytes, struct, regexhashes, pandas, CLIs Bash and PowerShell quoting, pipelinesobjects, event exports reading code C buffers and integersJS sinks, SQL, asmGo and Rust eight projects TCP checkerpacket analyserlogging proxypassword strength log analyserintegrity monitorcertificate inspectorconfig checker mini project: one CLI, two tools, tests every tool reads untrusted input and is tested on synthetic data
Section What you learn What you run
Getting started the languages, and how a small security tool is designed: inputs, outputs, exit codes, failure modes a tool skeleton with a test
Python for security bytes and encodings, hex and Base64, struct for binary headers, regular expressions on logs, hashlib, hmac and secrets, pandas for logs, subprocess without a shell, argparse CLIs, tests parsers, a constant-time token check, a log summary, a command-injection demo and its fix
Bash and PowerShell quoting and set -euo pipefail, find/grep/awk pipelines, sha256sum; PowerShell objects, Get-FileHash, CSV and JSON exports tool sessions in a sandbox and PowerShell 7.6 on Linux
Reading code C buffers and unsafe functions, integer overflow, compiler output, DOM sinks, SQL injection, Go and Rust bounds checks AddressSanitizer reports, a sandboxed XSS demo, injection on an in-memory database
Projects the roadmap's eight analyst tools each one built and tested in its lesson
Practice exercises over the whole course; a mini project your own CLI with tests and a README

The safety line, for tool writers

The track's safety line applies to code as much as to attacks. In this course it means:

  1. Tools touch only what they are pointed at, and only in scope. The connectivity checker in this course talks to listeners it starts itself on 127.0.0.1, the packet analyser reads sample capture files, the proxy sits between two programs in the same sandbox. Running a tool against someone else's system needs the written authorization described in Authorization, Scope and Rules of Engagement.
  2. Every bug shown is followed by how to detect it and how to fix it. The C lessons show overflows through sanitizer reports, then the safe replacement; the injection lessons end with the parameterised query.
  3. Nothing here is malicious. No scanners of the Internet, no credential stealers, no evasion. Defensive tools only, on synthetic data.

How examples run here

  • ```python run examples run in your browser (Python 3.13 in WebAssembly, with hashlib, hmac, secrets, struct, sqlite3, cryptography and pandas). The browser can't read files on the sandbox image, so data is embedded in the code.
  • ```bash run blocks are recorded tool sessions from a sandbox image with no network and no root. Python inside those sessions (python3 3.12 with Scapy and cryptography) can read the sample files in $SAMPLES.
  • ```powershell run blocks are recorded with PowerShell 7.6 on Linux; ```c run, ```go run and ```rust run compile on Compiler Explorer; ```html run runs in a sandboxed frame on this page.

Here is the toolbox you will use, as the sandbox reports it:

bash · try it yourself
python3 --version
python3 -c "import scapy, cryptography; print('scapy', scapy.__version__, '| cryptography', cryptography.__version__)"
bash --version | head -n 1
gcc --version | head -n 1
openssl version
nmap --version | head -n 1
ls "$SAMPLES"
Python 3.12.3
scapy 2.5.0 | cryptography 41.0.7
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)
Nmap version 7.94SVN ( https://nmap.org )
SHA256SUMS
dns
files
pcap
pki
rules

What you should know first

You should be comfortable with Python at the level of functions, dictionaries, exceptions and files, and with the shell from Linux & Bash. Security Foundations gives the vocabulary (threat, vulnerability, risk), the law, and the OS internals the C lessons rely on. Where a lesson leans on a language you have not met, it links to the language course (C, JavaScript, SQL, PowerShell, Rust, Go).

Start with Designing a Small Security Tool: every later lesson reuses its skeleton.

Test yourself

Which pair of languages covers most day-to-day security tooling on Linux?

  1. C and Assembly
  2. Python and Bash
  3. Rust and Go
  4. SQL and JavaScript

Why does a security analyst need to read C even if they never write it?

  1. C is the only compiled language
  2. Operating systems, daemons and firmware are written in it, and most memory-safety bugs live there
  3. Python is written in C, so Python bugs are C bugs
  4. C programs cannot be analysed with tools

A Python example in the browser needs a log file. Where does the data come from?

  1. From /opt/sec-samples on the sandbox image
  2. From a URL on the Internet
  3. It is embedded in the code of the example
  4. From your computer's /var/log

The connectivity checker in this course connects to which hosts?

  1. Any host the user names
  2. Well-known public servers, to test the Internet
  3. Only listeners it starts itself on 127.0.0.1, or a simulated network
  4. The lab range 10.10.0.0/24 over the real network