Unit Summary and Quick Reference
| Topic | Core idea |
|---|---|
| Three tests for a feature | Discriminative, available at decision time, and robust to trivial evasion |
| Network-flow features | Duration, packet rate, size statistics, and byte ratios summarise raw packets into fixed vectors |
| Malware static features | Imported APIs, section entropy, and header anomalies expose structure without executing the file |
| Phishing NLP features | TF-IDF text features combined with structural features (link mismatch, sender age, urgency words) |
| BEC case study | Roughly $2.9 billion in 2023 IC3-reported losses, often with no malware payload at all, by FBI IC3 reporting |
| Feature leakage | A feature that reflects how data was collected, not the label itself, destroys a model's real-world performance |
Self-Study Questions
Q1. State the three tests a good security feature should pass, and give an example feature that fails each one.
A good feature must be discriminative, available at decision time, and robust to trivial evasion. A feature that fails discriminative: the day of the week an email arrived, which rarely differs meaningfully between spam and legitimate mail. A feature that fails available at decision time: whether a file was eventually confirmed malicious by an antivirus vendor weeks later, which does not exist yet when the file first needs to be scored. A feature that fails robust to evasion: checking for the exact phrase "URGENT ACTION REQUIRED" in all capitals, which an attacker defeats by simply changing the capitalisation.
Q2. Why is section entropy such an effective single feature for detecting packed or encrypted malware payloads?
Shannon entropy measures randomness in a byte distribution. Ordinary executable code and readable strings sit well below the theoretical maximum of 8 bits per byte, because real code and text have structure and repetition. A packed or encrypted payload looks statistically close to random data, so its entropy sits close to the maximum, around 7.0 bits per byte or higher, making it a strong, cheap-to-compute single signal that a file is hiding its real content.
Q3. Explain why business email compromise is a strong argument for structural, not just textual, phishing features.
A BEC attack is often just a carefully worded email with no malicious attachment and no malware payload at all, impersonating an executive or vendor to request an urgent wire transfer. Since there is frequently no file to analyse and the text itself may read as ordinary business correspondence, structural signals, a mismatch between the sender's display name and actual address, an unusual request pattern, urgency language, become essential, because text content alone may not look suspicious.
Q4. Describe, with an original example, how feature leakage could make a phishing classifier look excellent in testing and fail in production.
Suppose a training dataset of phishing emails is scraped entirely from a corporate abuse-reporting mailbox, and every forwarded report happens to include a specific "Reported-By:" header the reporting tool automatically adds, which legitimate email never has. A model could learn to key heavily on the presence of that header rather than any genuine property of phishing content. It would score near-perfectly on the test set, since the header is present in every phishing example there too, but fail completely in production, where incoming phishing emails never carry that artefact.
Q5. Compare WannaCry and Mirai as case studies: why does WannaCry's spread argue for behavioural detection, while Mirai argues for network-traffic features specifically?
WannaCry spread automatically and extremely fast using the EternalBlue exploit, infecting roughly 200,000 computers across 150 countries within days with no phishing click required, which was too fast for a purely file-based static signature response, pushing defenders toward behavioural and network-anomaly detection instead. Mirai's payload was trivial, just default-credential logins to IoT devices, so traditional file-based malware features barely apply to it; detecting it instead requires network-traffic features, specifically unusual outbound scanning on IoT-typical ports.
Q6. Explain the trade-off between lexical (TF-IDF over URL tokens) and structured (hand-engineered) features for phishing-URL detection, and describe a situation where you would prefer each.
Structured features are interpretable and cheap to compute but require a human to think of every useful pattern in advance. Lexical TF-IDF features discover patterns automatically, including ones a human would never think to hand-code, but are harder to explain to a non-technical stakeholder and can overfit to coincidental vocabulary in a particular training set. You would prefer structured features when a model's decisions need to be explained to a compliance team or end user; you would prefer lexical features when you have a large labelled dataset and want to catch novel phishing patterns a hand-written rule set would miss.
Q7. Why is the SMS Spam Collection dataset a useful benchmark despite being much smaller than a production email dataset would be?
It contains 5,574 real, hand-labelled English SMS messages with a realistic spam rate of about 13 percent, making it small enough to train on a laptop in seconds while still being realistic enough that a model's performance on it transfers meaningfully to real deployment. Its small size makes it ideal for quickly testing a pipeline end to end before scaling up to a much larger production dataset.
Lab: Build Your Own Structural Phishing Feature
- Gather sample emails. Using any public phishing-email dataset, or a small set built from your own spam folder with personal data stripped, assemble a labelled set of phishing and legitimate emails.
- Write the mismatch function. Write a function that parses an email's HTML body and returns
Trueif the visible text of any link differs from the domain its actualhreftarget points to. - Add it to the pipeline. Concatenate this new structural feature onto the TF-IDF and other structural features from this unit, exactly as the combined feature pipeline describes.
- Check its importance. Train a random forest on the combined feature set and inspect
feature_importances_. Does your new mismatch feature rank near the top, the way sender-link mismatch did in this unit's own real chart? - Write up what you found. In two or three sentences, state whether your feature behaved as expected, and if not, suggest one reason why its importance might differ from this unit's result.

