Python › Module 3 › Lesson 1
Automating Security Tasks
Spot repetitive SOC and admin chores that scripts should handle instead of humans
Opening
If you typed the same grep three nights in a row, a script should own the fourth — humans keep the judgment.
A SOC analyst opens the same auth log every morning, searches Failed password, counts the hits, copies a few source addresses into a ticket, and repeats. A lab admin generates “temporary” passwords by mashing the keyboard, then pastes them into a shared doc. A sysadmin hashes a download by clicking through a website instead of running one command. None of those jobs is intelligence work. They are toil: the same well-defined motion, the same failure modes, the same chance a tired human skips a line. Python is the glue language you already started in Modules 1 and 2 — files, loops, sockets on localhost — applied to chores you already do on systems you own. This lesson is the filter, not a weapons catalog. You will learn which SOC and admin chores are script-shaped, why automation still sits under change control and written rules of engagement, and why a script that “just checks” a neighbor’s router or a production login page is still unauthorized access. You will inventory YOUR repetitive chores into $HOME/cyberlium-lab. You will not write Hydra, you will not spray passwords at live logins, you will not scrape someone else’s production logs, and you will not schedule a scanner against the public internet because cron made it easy. Next lesson is a password generator that uses secrets for YOUR passwords — not a cracker.
1. Toil has a shape: same input, same rule, same output — that is a script candidate
A chore is script-shaped when you can write the rule in one sentence without a meeting. “Count lines that contain Failed password in the copy of auth.log I exported.” “Generate a 20-character password from letters, digits, and a small symbol set, print it once, put it in my password manager.” “SHA-256 this file I downloaded and compare the digest to the vendor’s published hash.” Those sentences name an input you already have, a transformation with no taste involved, and an output a human will read. If the next step is “decide whether to isolate the host,” that step stays human. Scripts surface signal. Humans still own quarantine, disclosure, and business risk. Module 1’s loops and file handling exist so the boring half of that sentence becomes a for-line-in-file instead of a pair of eyes at 02:00.
The opposite shape is a judgment call dressed as a checklist. “Is this login attempt actually the CEO traveling?” “Should we page the on-call for this spike?” “Is this hash mismatch a malware drop or an honest vendor patch?” A script can count, extract, and diff. It cannot hold the context that makes those questions answerable. Teams that confuse the two either automate nothing (and drown) or automate the decision (and ship a false-positive storm, or worse, an auto-block that bricks a lab). Your job in this module is the first kind: toil you already repeat on YOUR sample files, YOUR lab passwords, YOUR hashes in cyberlium-lab. If you cannot name the file you own, you do not have a script candidate — you have a temptation.
2. SOC and admin chores that pay: logs, housekeeping, glue — not guessing, not spraying
Log triage is the classic win. You already printed matching lines in the Module 1 first-script lab. Automation is the next gear: count the matches, group them, write a ten-line report you can paste into notes. Housekeeping is the second win: generate a strong secret with the secrets module (next lesson), hash a file you control (Module 4 lab), verify a download against a published digest. Glue is the third: read a CSV you exported, write a summary text file, call an API you are authorized to use with a key that is not in the source. None of those require a new protocol. They require the loops, open(), and localhost discipline you already practiced — plus the ethics line this whole topic repeats: only data and hosts you own or have in writing.
What is not a SOC chore for this course: password spraying a live login, running Hydra or any online brute-force tool, scraping production logs you were not given, scanning the internet because a tutorial used nmap -p- on a famous hostname, or “practicing” against a classmate’s SSH. Those are attacks or unauthorized access, even if the file is named helper.py and even if cron launches it. Automation multiplies whatever you pointed it at. Pointed at toil, it saves hours. Pointed at a login page you do not own, it is a credential attack with a scheduler. You will not be taught crack workflows, rainbow tables, or live-login tests. If a chore only works by touching someone else’s authentication, it is out of scope.
3. Change control still applies: dry-run, fail loud, keep secrets out of the repo
A script that runs unattended is a change. In a real SOC, that means a ticket, a reviewer, and a rollback. In your lab, the cheap version is: run it once by hand against a copy, read the output, then consider scheduling. Idempotent when you can — running twice should not destroy the only log. Fail clearly: if the input file is missing, exit with a message, do not silently scan the current directory. Log what the script did (which file, which counts), not the passwords it generated and not API keys. Schedule with cron or Task Scheduler only after the dry run matches what you expected. Convenience is how people accidentally leave a scanner pointed at 0.0.0.0/0.
Secrets in source are an automation own-goal. An API token pasted into monitor.py will be copied, screenshotted, and committed. Environment variables and chmod 600 files exist so the script can run without the key living in git. Module 4 spends a whole lesson on that. For this lesson, the rule is shorter: if your chore inventory would need a production key, you do not put the key in the inventory file either. Notes in $HOME/cyberlium-lab get mode 600. They hold chore names and fictional examples — not live SOC_API_KEY values, not real user passwords, not production log dumps you were not authorized to copy.
4. Humans still decide: scripts report, they do not isolate, disclose, or “hack back”
The fantasy is a script that sees a failed-login spike and automatically shuts the firewall, pages legal, and scans the “attacker.” The reality is that the spike might be you mistyping in the lab, a scheduled scanner you authorized, or a VPN flap. Auto-response without a human is how labs lose SSH access to themselves and how unauthorized counter-scans start. Your analyzer will print counts. You will read them. You will not pipe them into a blocking action against an address you do not own. You will not “investigate” a documentation IP from a teaching sample as if it were a person. RFC 5737 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) in sample logs are labels, not targets.
5. Wrong vs right: automating an attack vs automating toil you already own
Worked failure — same Python skill, opposite legality. Right never includes Hydra, live-login tests, or production scraping.
Wrong
Script a password guesser and point it at a public SSH or a work VPN “to see if it works.” Run Hydra, Medusa, or a homemade spray against any live login. Pull production auth logs without a ticket and commit them to git. Schedule Module 2’s scanner against random internet hosts because cron is convenient. Put API keys in the script. Delete backups as a “cleanup job.” Claim automation made it authorized. This course forbids all of that. “I was just practicing” is not a defense — Module 4 will nail that sentence.
Right
List chores you already repeat on YOUR machine or YOUR exported copies: failed-login counts on a fictional sample_auth.log you create, password generation for YOUR accounts via secrets, hashing YOUR files. Dry-run before any schedule. Keep secrets out of source. Leave isolate / disclose / block decisions to a human. Write the inventory to $HOME/cyberlium-lab/toil-inventory.txt and chmod 600. Next lesson generates strong passwords with secrets — for you, not against a login.
6. Practical: inventory YOUR toil into cyberlium-lab — no scanners, no crackers
Create $HOME/cyberlium-lab if it does not exist. Write a short inventory: three chores you actually repeat (or would, in a home lab), whether each is script-shaped, and the ethical scope (file you own / localhost / written authorization). Include one explicit non-chore: “spray passwords at live logins — out of scope.” The Python stub below only prints the file. It does not connect to anything. Fill the notes in your own words. chmod 600 so a shared Windows account does not read them. Empty files fail the mission. Pasting a real production log, a live API key, or a Hydra command line also fails ethics.
Command guide
Toil inventory — YOUR chores, YOUR lab, never a live-login attack
DEFENSIVE inventory. YOUR repetitive chores only. NEVER Hydra / spray / crack / test passwords against live logins. NEVER scrape production logs you were not given. NEVER schedule a scanner at the public internet.
Command — copy this
mkdir -p "$HOME/cyberlium-lab" NOTES="$HOME/cyberlium-lab/toil-inventory.txt"
Command — copy this
{
echo "=== TOIL INVENTORY (mine, not a weapon) ==="
echo "date: $(date -Iseconds 2>/dev/null || date)"
echo "rule: script the repeatable count/filter/generate/hash — human keeps isolate/disclose"Command — copy this
echo "" echo "chore_1_name: count Failed password lines in MY sample_auth.log" echo "script_shaped: yes — same needle, same file I created" echo "scope: $HOME/cyberlium-lab copy I own — not production, not someone else's host" echo "human_still_decides: whether a spike is lab noise or worth a note"
Command — copy this
echo "" echo "chore_2_name: generate a strong password for MY password manager" echo "script_shaped: yes — secrets.choice, print once, do not commit" echo "scope: MY accounts — never test the output against a live login"
Command — copy this
echo "" echo "chore_3_name: SHA-256 a file I downloaded and compare to vendor digest" echo "script_shaped: yes — hashlib on MY bytes" echo "scope: files in cyberlium-lab — not rainbow tables, not password cracking"
Command — copy this
echo "" echo "explicit_non_chore: password spray / Hydra / live SSH guess — OUT OF SCOPE" echo "explicit_non_chore: scrape prod logs or scan internet hosts — OUT OF SCOPE" echo "change_control: dry-run by hand before any cron / Task Scheduler" echo "secrets: no API keys in this file or in .py source" } > "$NOTES"
Command — copy this
chmod 600 "$NOTES"
Windows without chmod: WSL/Git Bash, or restrict the file in your profile.
Command — copy this
python3 - <<'PY'
from pathlib import Path
p = Path.home() / "cyberlium-lab" / "toil-inventory.txt"
text = p.read_text(encoding="utf-8")
print("inventory_lines:", len(text.splitlines()))
print("mentions_out_of_scope:", "OUT OF SCOPE" in text)
print("ok: this stub reads YOUR notes — it does not open sockets or logins")
PYNEVER: hydra, medusa, ncrack, or a homemade spray NEVER: curl a production login with generated passwords NEVER: put live SOC_API_KEY or real passwords in NOTES
Mission: toil-inventory.txt (mode 600) naming three YOUR chores
1) In your own words, define a script-shaped chore: same input, same rule, same output, human still decides response. 2) Write three chores you own (log count on a sample you create, password generation for you, hashing your files) plus at least one explicit OUT OF SCOPE item (live-login spray / Hydra / prod scrape). 3) Note dry-run-before-cron and no secrets in source. Save to $HOME/cyberlium-lab/toil-inventory.txt and chmod 600. Never point a script at a live login. Never scrape production without authorization.
Stuck? Ask Cyberlium AI Mentor
If “a script that tries passwords would save time” still feels like a SOC chore, ask for a hint — not a Hydra line. Try: "Hint only: why is counting Failed password lines in MY sample_auth.log script-shaped, while spraying those passwords at a live SSH is unauthorized access even if Python is doing it?" You still fill the inventory. No crackers, no live logins, no production scrapes.
You now treat repetition as a signal for a script, and you treat live logins, Hydra, and production scrapes as out of scope even when they would be “automated.” Change control, dry-runs, and no keys in git travel with every chore you list. Humans still isolate and disclose. Next — Password Generator Script — secrets.choice versus random.random, a long alphabet, print once, never log the result to git, never test it against a live login.
Knowledge Check
APPLY: Every morning you grep Failed password on an exported copy of a log you created in cyberlium-lab. A classmate wants to “automate” by spraying generated passwords at a public SSH. Which is the script-shaped chore?
Multiple choice
Knowledge Check
APPLY: You want to cron a checker tonight. The script needs an API token and might lock a file if pointed at the only copy of a log. Best pair of habits?
Multiple choice
Knowledge Check
APPLY: True or False: A script that prints a failed-login count should also auto-scan the “attacker” IP and isolate the host, because otherwise automation is incomplete.
True or False