ENGINEERING BLOG | CYBERSECURITY & AI

AI in Cybersecurity

How machine learning is changing the way we detect, investigate and stop cyber attacks, and what it means for you as an engineering student

1. Introduction: A Race Between Defenders and Attackers

Every day, a typical organisation's security systems record millions of events: logins, file accesses, DNS lookups, network connections and emails. Hidden somewhere in that ocean of data may be a handful of events that signal a real attack. Finding them manually is like searching for a few specific grains of sand on a beach, and attackers know it.

This is why Artificial Intelligence (AI) has become one of the most important topics in modern cybersecurity. AI, and especially its subfield Machine Learning (ML), can learn patterns from huge volumes of data, spot behaviour that looks unusual, and react in seconds instead of hours. At the same time, attackers are using the same technology to write convincing phishing emails, clone voices and probe defences automatically. Cybersecurity has become a race in which both sides are armed with AI.

In this blog, we look at the topic from an engineering student's point of view. You will learn how AI-based security systems are built, where they are used in the real world, how to build a small anomaly detector yourself, what can go wrong, and how you can prepare for a career in this exciting field.

What you will learn: the core ideas behind AI-driven detection, five practical use cases, a working Python example with results, the new attacks aimed at AI systems, and a roadmap for getting started.

2. Why Traditional Security Is Not Enough

For decades, security tools relied mainly on signatures and rules. An antivirus program kept a database of known malware fingerprints (hashes or byte patterns). A firewall or intrusion detection system (IDS) matched traffic against hand-written rules such as "block any packet to port 23 from an external address". These methods are fast, precise and easy to explain, but they have three big weaknesses:

They only catch what is already known. A brand-new (zero-day) attack has no signature, so it passes straight through.

They are easy to evade. Malware authors change a few bytes, repack the file or obfuscate scripts, and the signature no longer matches. Polymorphic malware can generate thousands of variants automatically.

They do not scale with human effort. Rules must be written and updated by experts. With the volume of data today, analysts suffer from "alert fatigue" and may ignore or miss genuine warnings.

AI-based systems address these gaps by learning what normal and malicious behaviour look like from data, rather than relying only on a fixed list. Figure 1 compares the two approaches qualitatively. Notice that AI does not win everywhere: signature-based tools remain excellent for known threats and are easier to explain, which is why modern security stacks combine both.

Word document image

Figure 1: Signature-based vs AI-based detection. Scores are a qualitative illustration, not measured data.

3. How AI-Based Security Systems Work

Although products differ, most AI security systems follow a similar pipeline, shown in Figure 2. Understanding this pipeline helps you reason about both the strengths and the failure points of any AI security tool.

Word document image

Figure 2: A typical AI-driven threat detection pipeline with an analyst feedback loop.

Data collection. Network packets and flow records, system and application logs, endpoint telemetry, email metadata and threat intelligence feeds.

Pre-processing. Cleaning missing values, removing duplicates, normalising scales and labelling data where labels are available.

Feature extraction. Converting raw data into numbers a model can use, for example bytes per second, number of failed logins, URL length, entropy of a domain name, or API-call sequences from a program.

Model training and inference. The model learns from historical data and then scores new events in real time.

Alerting and response. High-risk events raise alerts or trigger automatic actions, and analyst decisions feed back to improve the model.

Main learning approaches

Approach

How it works

Security example

Supervised learning

Learns from labelled examples (malicious / benign) to classify new data

Random forest or neural network classifying files as malware or clean; spam and phishing filters

Unsupervised learning

Finds structure or outliers in unlabelled data, with no attack labels required

Isolation Forest or clustering to flag unusual network traffic and detect unknown attacks

Deep learning

Neural networks learn features automatically from raw data such as bytes, images or text

CNNs on malware binaries visualised as images; LSTMs on system-call sequences

Reinforcement learning

An agent learns by trial and reward in an environment

Automated penetration testing and adaptive defence research

Natural language processing

Understands and generates text

Phishing email detection, threat-report summarisation, SOC assistants built on large language models


4. Real-World Use Cases

4.1 Phishing and spam detection

Phishing remains one of the most common ways attackers gain a foothold. ML models examine many signals at once: the sender's reputation, the structure of the URL, suspicious wording, mismatched link text, the age of the domain, and even the visual layout of a landing page. Large email providers have publicly described using machine learning in their spam and phishing filters, which allows them to adapt as attackers change their wording. A simple student project is to train a logistic regression or random forest on URL features such as length, number of dots, presence of an IP address and use of the "@" symbol.

4.2 Malware detection and classification

Instead of matching a hash, an ML classifier looks at behaviour and structure: which system calls a program makes, which libraries it imports, how its bytes are distributed, or what its control-flow graph looks like. Because these features are similar across variants of the same malware family, the model can recognise a new variant it has never seen. Modern endpoint protection products from major vendors use this kind of ML alongside traditional signatures.

4.3 Network intrusion and anomaly detection

An anomaly detector learns what normal traffic looks like for a network and flags significant deviations: a sudden burst of traffic (possible DDoS), one host contacting hundreds of ports (a port scan), or a server sending large amounts of data to an unfamiliar address at 3 a.m. (possible data exfiltration). Public datasets such as NSL-KDD, CIC-IDS2017 and UNSW-NB15 are widely used to practise this. We build a small version of this in Section 5.

4.4 User and entity behaviour analytics (UEBA)

Stolen credentials are hard to catch because the attacker looks like a legitimate user. UEBA builds a behavioural profile for each account: usual login hours, locations, devices and accessed systems. If a finance employee suddenly logs in from a new country at midnight and downloads the entire customer database, the risk score rises sharply even though the password was correct.

4.5 Security Operations Centre (SOC) automation

Security teams are overwhelmed by alerts. AI helps by deduplicating related alerts, enriching them with context such as asset importance and threat intelligence, and ranking them by risk. Combined with SOAR (Security Orchestration, Automation and Response) playbooks, routine actions like isolating an infected laptop or blocking a malicious IP can be automated, while humans approve high-impact steps. Figure 3 illustrates this workflow.

Word document image

Figure 3: AI-assisted SOC workflow. AI handles volume and speed; humans handle judgement.

4.6 Notable examples from history and industry

DARPA Cyber Grand Challenge (2016). Seven fully autonomous systems competed to find, patch and exploit software vulnerabilities in real time with no human help. It was an early demonstration that machines can take part in both attack and defence.

Deepfake voice fraud (2019). Media reports described criminals using AI-generated audio that imitated a chief executive's voice to convince a UK energy company employee to transfer a large sum of money. It showed how generative AI makes social engineering more convincing.

AI-assisted vulnerability research. Fuzzing guided by ML, and increasingly by large language models, is being used to find bugs in code faster, helping both defenders and attackers.

5. Hands-On: Build a Network Anomaly Detector in Python

Let us make this concrete. We will use Isolation Forest, an unsupervised algorithm that isolates outliers by randomly splitting the data. Points that are easy to isolate with few splits are likely anomalies. We simulate 2,000 network observations with two features: traffic volume (KB/s) and new connections per minute. Of these, 1,900 are normal, 60 mimic a DDoS-style burst (high volume, many connections) and 40 mimic a port scan (low volume, many connections).

import numpy as np

from sklearn.ensemble import IsolationForest

from sklearn.metrics import precision_score, recall_score

rng = np.random.default_rng(42)

normal = np.column_stack([rng.normal(500,120,1900), rng.normal(40,12,1900)])

ddos = np.column_stack([rng.normal(1500,200,60), rng.normal(160,25,60)])

scan = np.column_stack([rng.normal(150,40,40), rng.normal(110,15,40)])

X = np.vstack([normal, ddos, scan])

y = np.r_[np.zeros(1900), np.ones(100)] # 1 = attack (used only to evaluate)

Xs = (X - X.mean(0)) / X.std(0) # standardise features

model = IsolationForest(n_estimators=200, contamination=0.05, random_state=42)

pred = (model.fit(Xs).predict(Xs) == -1).astype(int) # -1 means anomaly

print(precision_score(y, pred), recall_score(y, pred))


Running this experiment flagged 100 of the 2,000 observations as anomalous. 98 were genuine attacks (true positives), 2 were false alarms, and 2 attacks were missed. That gives a precision of 0.98 and a recall of 0.98. The model never saw a single attack label while training; the labels were used only to score the result. Figure 4 visualises the outcome.

Word document image

Figure 4: Isolation Forest results on synthetic traffic. Orange points are detected attacks, squares are false alarms, crosses are missed attacks.

Reality check: these results are excellent because the data is synthetic and the attacks are cleanly separated from normal traffic. Real networks are noisier, attacks are subtler, and traffic patterns change over time. Always test on realistic datasets such as CIC-IDS2017 before drawing conclusions, and pay attention to precision and recall rather than accuracy alone, since attacks are rare.

Why accuracy is a misleading metric

In our data only 5% of events are attacks. A lazy model that labels everything as normal would be 95% "accurate" yet would detect zero attacks. This is the class imbalance problem, common in security. Prefer these metrics instead:

Precision: of all alerts raised, how many were real attacks? Low precision means analysts drown in false alarms.

Recall (detection rate): of all real attacks, how many did we catch? Low recall means breaches go unnoticed.

F1-score: the harmonic mean of precision and recall, useful when both matter.

6. The Other Side: AI as a Weapon and AI as a Target

6.1 Attackers using AI

Smarter phishing. Generative models can write fluent, personalised messages without the spelling mistakes that once gave scams away, in any language.

Deepfakes and voice cloning. Realistic synthetic audio and video are used for impersonation, fraud and disinformation.

Automated reconnaissance and exploitation. Scripts that scan, fingerprint and probe thousands of targets faster than any human.

Malware that adapts. Code that mutates to evade ML-based detectors.

6.2 Attacks against AI systems (Adversarial Machine Learning)

An ML model is software, and software can be attacked. Figure 5 maps where adversaries target an ML-based security system.

Word document image

Figure 5: Attack points in an ML-based security pipeline.

Evasion attacks: the attacker modifies an input slightly so the model misclassifies it, for instance adding harmless-looking code to a malware sample so a classifier labels it benign.

Data poisoning: the attacker slips crafted samples into the training data so the model learns the wrong lesson or a hidden backdoor.

Model stealing and inversion: by querying a model repeatedly, an attacker can copy its behaviour or recover sensitive information from its training data.

Prompt injection (for LLM-based tools): hidden instructions in an email, web page or document trick an AI assistant into leaking data or taking unwanted actions. It is currently listed among the top risks for LLM applications by OWASP.

The key lesson: an AI security tool expands your attack surface as well as your defences. Models need the same engineering care as any critical system: access control, input validation, monitoring and testing.

7. Challenges and Limitations

Challenge

Why it matters

False positives

Too many wrong alerts waste analyst time and lead to real alerts being ignored.

Data quality and labels

Good labelled attack data is scarce; biased or stale data produces a biased or weak model.

Concept drift

Networks, users and attackers change. A model trained last year may fail today unless it is monitored and retrained.

Explainability

Deep models are often black boxes. Analysts and auditors need to know why something was flagged.

Privacy and compliance

Behavioural monitoring uses personal data and must follow laws and organisational policy.

Adversarial robustness

Attackers actively try to fool the model, unlike in most other ML applications.

Over-reliance

Treating AI as a magic solution can create a false sense of security and weaken basic hygiene such as patching and strong authentication.


8. Best Practices for Building Trustworthy AI Security Systems

Use defence in depth. Combine AI with signatures, firewalls, patching, multi-factor authentication and backups. AI is one layer, not the whole wall.

Keep humans in the loop for high-impact actions such as shutting down servers or locking accounts.

Measure the right things. Track precision, recall, false-positive rate and time-to-detect, not just accuracy.

Monitor for drift and retrain on fresh data on a schedule.

Prefer explainable outputs such as feature importance or the top reasons for an alert, so analysts can trust and verify decisions.

Secure the ML pipeline itself: protect training data, version models, and test them against adversarial inputs.

9. Your Roadmap: How to Get Started as a Student

Skills to build

Security foundations: networking (TCP/IP, DNS, HTTP), operating systems, cryptography basics, common attacks (SQL injection, XSS, phishing, DoS) and the CIA triad.

Programming: Python is the main language, with NumPy, pandas, scikit-learn and later PyTorch or TensorFlow.

Machine learning basics: supervised vs unsupervised learning, evaluation metrics, overfitting, and feature engineering.

Tools: Wireshark for packets, Zeek or Suricata for network monitoring, and a SIEM such as Splunk or the open-source ELK stack for logs.

Five mini-project ideas

Phishing URL classifier using URL-based features and a random forest.

Network intrusion detector trained on NSL-KDD or CIC-IDS2017, comparing Isolation Forest with a supervised model.

Malware family classifier using public benchmark datasets of static features.

Log anomaly detector for web-server or SSH logs to spot brute-force logins.

Adversarial test: take your own classifier and show how small input changes can fool it, then try a defence.

Many of these can be built entirely on public datasets and free tools, so there is no need for expensive infrastructure. Document your work on GitHub; a well-explained project often speaks louder than a certificate.

Ethics first

Practise only on systems you own or have written permission to test, and use isolated lab environments or legal platforms. Unauthorised scanning or testing is illegal in most countries, including under India's Information Technology Act. Security professionals are trusted precisely because they follow ethical rules.

10. Conclusion

AI is not replacing cybersecurity professionals; it is changing what they do. Machines are better at sifting through millions of events, while people are better at judgement, context and creativity. The strongest defences combine both. At the same time, AI introduces new risks, from AI-written phishing to attacks on the models themselves, so tomorrow's security engineers need to understand both security and machine learning.

If you are an engineering student, this is a good moment to start. Learn the fundamentals, build small projects, test them honestly, and always keep ethics at the centre of what you do.

Key takeaways

AI learns normal and malicious behaviour from data, helping detect new and unknown threats that signatures miss.

Practical uses include phishing detection, malware classification, intrusion detection, UEBA and SOC automation.

Precision and recall matter more than accuracy because attacks are rare.

Attackers use AI too, and AI models themselves can be attacked.

The best strategy is layered defence with humans in the loop.

Further reading

NIST AI Risk Management Framework (AI RMF 1.0) and NIST Adversarial Machine Learning taxonomy.

OWASP Top 10 for Large Language Model Applications.

MITRE ATT&CK and MITRE ATLAS knowledge bases of adversary tactics, including those targeting AI systems.

scikit-learn documentation on anomaly detection and the CIC-IDS2017 dataset from the Canadian Institute for Cybersecurity.