تخطي إلى المحتوى الرئيسي
M.ALRASHID
AUTOMATIONINCIDENT RESPONSEPYTHON4 يونيو 20243 دقائق قراءة

Security automation: start with the repetitive part

I'd automate the prep work before I automate any response. A small script should save time without making a security decision harder to review.

The first security task I'd automate is usually the boring one: normalize the fields, remove exact duplicates, and put the useful context in one place.

That's a much smaller decision than automatically disabling an account or blocking an address, and it's easier to verify. If the preparation is wrong, I want to find that out before it changes a live system.

Keep the first script local

Say I have a text file with one IP address per line. This script normalizes the valid addresses, keeps their first-seen order, and reports invalid lines separately. It doesn't contact the addresses or send them to a reputation service.

import ipaddress
import json
import sys
from pathlib import Path
 
seen = set()
addresses = []
invalid = []
 
for number, raw in enumerate(
    Path(sys.argv[1]).read_text(encoding="utf-8").splitlines(), 1
):
    value = raw.strip()
    if not value:
        continue
    try:
        address = str(ipaddress.ip_address(value))
    except ValueError:
        invalid.append({"line": number, "value": value})
        continue
    if address not in seen:
        seen.add(address)
        addresses.append(address)
 
print(json.dumps({"addresses": addresses, "invalid": invalid}, indent=2))

An address showing up in a file says nothing on its own about malicious activity, so the script doesn't try to judge it. It just makes the input easier to review. Python's ipaddress documentation describes the parsing behavior.

Preserve the evidence behind the summary

For a real workflow, I'd keep the original input and enough context to find the source event. Normalization shouldn't erase distinctions that matter to the investigation. Two alerts sharing an IP address can still describe different activity.

If I add external enrichment later, I'd decide explicitly what leaves the environment. An internal hostname, a private URL, or a token shouldn't get sent to a service just because a parser found it.

Make failures visible

I'd test empty input, malformed values, duplicate records, and unexpected field types. For a networked integration, I'd add timeouts, rate limits, unavailable services, and partial results to that list.

The tool should tell me when it skipped a record or couldn't get context. Dropping the hard cases without saying so can make a neat report misleading.

Add response actions separately

If an automation eventually changes access or blocks traffic, I'd give that step its own scope, authorization, and audit record. I'd also define what happens when it runs twice and how to recover from a mistake.

What I want is a workflow someone can trust because they can see its inputs, its decisions, and where it failed. A shorter queue only helps if the work is still being done right.

محمد الراشد

مهندس أمن سيبراني في PassiveLogic. مهتم باختبار الاختراق والثقة الصفرية والتعلم في المختبر المنزلي.

تواصل

تابع القراءة