بنقرة واحدة
embedding-scorer
Score DNS queries for anomalies using the trained embedding similarity model.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Score DNS queries for anomalies using the trained embedding similarity model.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Merge Stage 2 DNS analysis scores and calculate final exfiltration verdicts.
Capture live DNS queries with tcpdump for a configurable duration, save the traffic to a PCAP file, and process it through the existing PCAP reader. Use when a user explicitly requests timed live DNS capture from a network interface.
Compute DGA probabilities using a pre-trained RandomForest model.
Calculate DNS subdomain entropy scores for exfiltration and DGA detection.
Generate a Markdown security report from aggregated DNS exfiltration scores.
Normalize DNS input from PCAP or CSV into one unified JSON dataset.
| name | embedding-scorer |
| description | Score DNS queries for anomalies using the trained embedding similarity model. |
Calculate embedding-based anomaly scores for DNS queries using a hybrid TF-IDF
character n-gram model. The scorer uses subdomain similarity by default and
falls back to full-domain similarity when the subdomain is missing or too
short. Used by embedding_agent in Stage 2 parallel analysis.
calculate_embed_scores(input_path: str, output_path: str, model_path: str) -> dict
Input is a JSON file containing DNS queries. The scorer reads the full domain
for every query and uses the subdomain field when it is available and
informative. A trained hybrid model must exist at model_path.
| Parameter | Type | Required | Description |
|---|---|---|---|
input_path | str | yes | Path to dns_queries.json (Stage 1 out) |
output_path | str | yes | Path to write embedding scores JSON |
model_path | str | no | Path to trained model (default: models/embed_model.pkl) |
Returns a dict with processing summary:
| Field | Type | Description |
|---|---|---|
total_processed | integer | Number of queries processed |
subdomain_path_count | integer | Queries scored via subdomain branch |
domain_fallback_count | integer | Queries scored via full-domain fallback |
high_distance_count | integer | Count where embed_score > 0.6 |
output_file | string | Path where results were written |
Also writes a JSON array to output_path. Each entry contains:
| Field | Type | Description |
|---|---|---|
query_id | integer | Matching the input query_id |
domain | string | Full domain from input |
label | string | Ground truth label (benign/malicious) if known |
embed_score | float | Distance from the nearest benign reference |
source | string | Data source: "pcap" or "csv" |
char(3, 5)subdomaindomain3model_pathbest_similarity = max(similarities) and embed_score = 1 - best_similarityembed_score > 0.6 → suspiciousBefore running inference, train the model ONCE:
python tools/embed_score.py train data/input/merged.csv models/embed_model.pkl
This generates models/embed_model.pkl containing:
subdomain_branch: TF-IDF vectorizer + benign references for subdomain scoringdomain_branch: TF-IDF vectorizer + benign references for full-domain fallback scoringembedding_model: tfidf-char-ngram-hybrid-knnanalyzer: charngram_range: (3, 5)input_unit: hybridscoring_method: max_benign_similarity_with_domain_fallbackfallback_rule: use_domain_when_subdomain_missing_or_shortshort_subdomain_threshold: 3pip install numpy pandas scikit-learn tldextract
Includes:
numpypandasscikit-learntldextractfrom tools.embed_score import calculate_embed_scores
result = calculate_embed_scores(
input_path="data/output/dns_queries.json",
output_path="outputs/<run_timestamp>/embed_scores.json",
model_path="models/embed_model.pkl"
)
print(f"Processed {result['total_processed']} queries")
print(f"Subdomain path: {result['subdomain_path_count']}")
print(f"Domain fallback: {result['domain_fallback_count']}")
print(f"Found {result['high_distance_count']} high-distance domains")
from tools.embed_score import train_embedding_model
result = train_embedding_model(
csv_path="data/input/merged.csv",
model_output_path="models/embed_model.pkl"
)
print(f"Trained on {result['benign_count']} benign domains")
print(f"Benign subdomains: {result['subdomain_count']}")
print(f"Model saved to {result['model_file']}")
entropy_agent and dga_classifier_agent.orchestrator_agent in Stage 3.