Prepare representative logs
Collect real query logs or synthetically generate queries that include normal usage and deliberate probing sessions; include timestamps, requester IDs and model responses for richer signals.
Simulate model extraction attacks. Detect abnormal query patterns.
Model-extraction attacks attempt to recreate a target model by issuing many queries and collecting outputs. Practical simulation needs a victim model, a query-generation strategy, and metrics that capture how well a surrogate reproduces the target; anomaly detection on query logs can help surface suspicious behaviour but is not the complete attack simulation.
Learning concept · Not a validated service
Model-extraction attacks attempt to recreate a target model by issuing many queries and collecting outputs. Practical simulation needs a victim model, a query-generation strategy, and metrics that capture how well a surrogate reproduces the target; anomaly detection on query logs can help surface suspicious behaviour but is not the complete attack simulation.
A proposed use-case: prioritise analyst review by flagging query patterns that look like systematic probing. This should remain an analyst-assist tool — a human reviewer must stay in charge — and it is not suitable for making enforcement or operational decisions in production. This extension is not delivered by the supplied starter.
Collect real query logs or synthetically generate queries that include normal usage and deliberate probing sessions; include timestamps, requester IDs and model responses for richer signals.
Create scripted query bursts, adaptive queries and black-box probing that aim to recover a target model, and label those sessions for evaluation.
Fit anomaly detectors or supervised classifiers on session-level features (rate, diversity, response patterns) and review flagged sessions with human analysts.
If a surrogate model is created, measure fidelity to the victim (e.g. agreement, KL divergence) and balance detector recall against operational false positives.
The supplied starter creates two small synthetic numeric log sets (normal and suspicious), concatenates them, fits an IsolationForest, and prints the rows flagged as anomalies. It implements an anomaly-detection baseline on synthetic features but does not simulate a query-based model-extraction attack, does not include a victim model, and does not measure surrogate model fidelity.
detector = IsolationForest(contamination=0.05, random_state=42)
logs["anomaly_score"] = detector.fit_predict(logs)
alerts = logs[logs["anomaly_score"] == -1]
The code uses synthetic numeric records and an IsolationForest to flag outliers; it does not implement a model-extraction workflow (no victim model, no query-generation strategy, no surrogate training and no fidelity metrics). The tiny, fabricated dataset and single detector run cannot validate detection performance in realistic environments.
Proposed extension: implement a victim model, generate query sequences that try to recover it (random, adaptive, API-constrained), train surrogate models from collected pairs and measure surrogate fidelity and extraction cost.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its Cybersecurity Course, with placement support and hands-on labs.