mirror of
https://github.com/mukul975/Anthropic-Cybersecurity-Skills.git
synced 2026-08-28 12:19:41 +03:00
chore: fix license, add disclaimer, quick start, GitHub topics, issue templates
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to the Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by the Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding any notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. Please do not remove or change
|
||||
the license header comment from a contributed file except when
|
||||
necessary.
|
||||
|
||||
Copyright 2026 mukul975
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: hunting-for-process-injection-techniques
|
||||
description: Detect process injection techniques (T1055) including CreateRemoteThread, process hollowing, and DLL injection via Sysmon Event IDs 8 and 10 and EDR process telemetry
|
||||
domain: cybersecurity
|
||||
subdomain: threat-hunting
|
||||
tags: [process-injection, t1055, sysmon, createremotethread, dll-injection, edr, threat-hunting]
|
||||
version: "1.0"
|
||||
author: mahipal
|
||||
license: Apache-2.0
|
||||
---
|
||||
|
||||
# Hunting for Process Injection Techniques
|
||||
|
||||
## Overview
|
||||
|
||||
Process injection (MITRE ATT&CK T1055) allows adversaries to execute code in the address space of another process, enabling defense evasion and privilege escalation. This skill detects injection techniques via Sysmon Event ID 8 (CreateRemoteThread), Event ID 10 (ProcessAccess with suspicious access rights), and analysis of source-target process relationships to distinguish legitimate from malicious injection.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Sysmon installed with Event IDs 8 and 10 enabled
|
||||
- Process creation logs (Sysmon Event ID 1 or Windows 4688)
|
||||
- Python 3.8+ with standard library
|
||||
- JSON-formatted Sysmon event logs
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Parse Sysmon Events** — Ingest Event IDs 1, 8, and 10 from JSON log files
|
||||
2. **Detect CreateRemoteThread** — Flag Event ID 8 with suspicious source-target process pairs
|
||||
3. **Analyze ProcessAccess Rights** — Identify Event ID 10 with dangerous access masks (PROCESS_VM_WRITE, PROCESS_CREATE_THREAD)
|
||||
4. **Build Process Relationship Graph** — Map source-to-target injection relationships
|
||||
5. **Filter Known Legitimate Pairs** — Exclude known benign injection patterns (AV, debuggers, system processes)
|
||||
6. **Score Injection Severity** — Apply risk scoring based on source process, target process, and access rights
|
||||
7. **Generate Hunt Report** — Produce structured report with MITRE sub-technique mapping
|
||||
|
||||
## Expected Output
|
||||
|
||||
- JSON report of detected injection events with severity scores
|
||||
- Process injection relationship graph
|
||||
- MITRE ATT&CK sub-technique mapping (T1055.001-T1055.012)
|
||||
- False positive exclusion recommendations
|
||||
@@ -0,0 +1,92 @@
|
||||
# Process Injection Detection API Reference
|
||||
|
||||
## Sysmon Event ID 8 — CreateRemoteThread
|
||||
|
||||
```xml
|
||||
<EventID>8</EventID>
|
||||
<Data Name="SourceImage">C:\Users\attacker\malware.exe</Data>
|
||||
<Data Name="TargetImage">C:\Windows\System32\svchost.exe</Data>
|
||||
<Data Name="StartFunction">LoadLibraryA</Data>
|
||||
<Data Name="StartModule">C:\Users\attacker\evil.dll</Data>
|
||||
<Data Name="NewThreadId">12345</Data>
|
||||
<Data Name="SourceProcessId">1234</Data>
|
||||
<Data Name="TargetProcessId">5678</Data>
|
||||
```
|
||||
|
||||
## Sysmon Event ID 10 — ProcessAccess
|
||||
|
||||
```xml
|
||||
<EventID>10</EventID>
|
||||
<Data Name="SourceImage">C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Data>
|
||||
<Data Name="TargetImage">C:\Windows\System32\lsass.exe</Data>
|
||||
<Data Name="GrantedAccess">0x1F0FFF</Data>
|
||||
<Data Name="SourceProcessId">4444</Data>
|
||||
<Data Name="TargetProcessId">680</Data>
|
||||
```
|
||||
|
||||
## Dangerous Access Rights Masks
|
||||
|
||||
| Hex Value | Meaning | Risk |
|
||||
|-----------|---------|------|
|
||||
| `0x1F0FFF` | PROCESS_ALL_ACCESS | Critical |
|
||||
| `0x0020` | PROCESS_VM_WRITE | High |
|
||||
| `0x0008` | PROCESS_VM_OPERATION | High |
|
||||
| `0x0002` | PROCESS_CREATE_THREAD | High |
|
||||
| `0x001A` | VM_WRITE + VM_OPERATION + CREATE_THREAD | Critical |
|
||||
| `0x143A` | Classic injection rights combo | Critical |
|
||||
| `0x0040` | PROCESS_DUP_HANDLE | Medium |
|
||||
| `0x0010` | PROCESS_VM_READ | Low |
|
||||
|
||||
## Sysmon Configuration for Injection Detection
|
||||
|
||||
```xml
|
||||
<Sysmon schemaversion="4.90">
|
||||
<EventFiltering>
|
||||
<!-- CreateRemoteThread -->
|
||||
<CreateRemoteThread onmatch="exclude">
|
||||
<SourceImage condition="is">C:\Windows\System32\csrss.exe</SourceImage>
|
||||
</CreateRemoteThread>
|
||||
|
||||
<!-- ProcessAccess to LSASS -->
|
||||
<ProcessAccess onmatch="include">
|
||||
<TargetImage condition="is">C:\Windows\System32\lsass.exe</TargetImage>
|
||||
</ProcessAccess>
|
||||
</EventFiltering>
|
||||
</Sysmon>
|
||||
```
|
||||
|
||||
## Splunk Detection Queries
|
||||
|
||||
```spl
|
||||
# CreateRemoteThread from Office apps
|
||||
index=sysmon EventCode=8
|
||||
| where match(SourceImage, "(?i)(winword|excel|powerpnt|outlook)\.exe$")
|
||||
| table _time SourceImage TargetImage StartFunction User
|
||||
|
||||
# Suspicious ProcessAccess to LSASS
|
||||
index=sysmon EventCode=10 TargetImage="*lsass.exe"
|
||||
GrantedAccess IN ("0x1F0FFF", "0x143A", "0x001A")
|
||||
| where NOT match(SourceImage, "(?i)(csrss|MsMpEng|avp)\.exe$")
|
||||
| stats count by SourceImage GrantedAccess
|
||||
```
|
||||
|
||||
## MITRE ATT&CK T1055 Sub-techniques
|
||||
|
||||
| ID | Name | API Calls |
|
||||
|----|------|-----------|
|
||||
| T1055.001 | DLL Injection | CreateRemoteThread, LoadLibrary |
|
||||
| T1055.002 | PE Injection | VirtualAllocEx, WriteProcessMemory |
|
||||
| T1055.003 | Thread Execution Hijacking | SuspendThread, SetThreadContext |
|
||||
| T1055.004 | APC Injection | QueueUserAPC |
|
||||
| T1055.005 | Thread Local Storage | TLS callbacks |
|
||||
| T1055.012 | Process Hollowing | NtUnmapViewOfSection, WriteProcessMemory |
|
||||
|
||||
## Atomic Red Team Tests
|
||||
|
||||
```bash
|
||||
# T1055.001 - DLL Injection via CreateRemoteThread
|
||||
Invoke-AtomicTest T1055.001
|
||||
|
||||
# T1055.012 - Process Hollowing
|
||||
Invoke-AtomicTest T1055.012
|
||||
```
|
||||
@@ -0,0 +1,214 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Detect process injection techniques (T1055) via Sysmon Event IDs 8 and 10."""
|
||||
|
||||
import json
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
|
||||
LEGITIMATE_INJECTION_PAIRS = {
|
||||
("csrss.exe", "svchost.exe"), ("lsass.exe", "svchost.exe"),
|
||||
("services.exe", "svchost.exe"), ("smss.exe", "csrss.exe"),
|
||||
("wininit.exe", "services.exe"), ("svchost.exe", "runtimebroker.exe"),
|
||||
("msmpeng.exe", "svchost.exe"), # Windows Defender
|
||||
("mbamservice.exe", "svchost.exe"), # Malwarebytes
|
||||
("avp.exe", "svchost.exe"), # Kaspersky
|
||||
}
|
||||
|
||||
SUSPICIOUS_SOURCE_PROCESSES = {
|
||||
"powershell.exe", "powershell_ise.exe", "pwsh.exe", "cmd.exe",
|
||||
"wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe",
|
||||
"regsvr32.exe", "msbuild.exe", "installutil.exe",
|
||||
"winword.exe", "excel.exe", "powerpnt.exe",
|
||||
}
|
||||
|
||||
HIGH_VALUE_TARGETS = {
|
||||
"lsass.exe", "svchost.exe", "explorer.exe", "winlogon.exe",
|
||||
"csrss.exe", "services.exe", "spoolsv.exe", "taskhost.exe",
|
||||
"dllhost.exe", "wininit.exe",
|
||||
}
|
||||
|
||||
DANGEROUS_ACCESS_RIGHTS = {
|
||||
"0x1F0FFF": "PROCESS_ALL_ACCESS",
|
||||
"0x001F0FFF": "PROCESS_ALL_ACCESS",
|
||||
"0x1FFFFF": "PROCESS_ALL_ACCESS",
|
||||
"0x0040": "PROCESS_DUP_HANDLE",
|
||||
"0x0020": "PROCESS_VM_WRITE",
|
||||
"0x0008": "PROCESS_VM_OPERATION",
|
||||
"0x0002": "PROCESS_CREATE_THREAD",
|
||||
"0x001A": "PROCESS_VM_WRITE|PROCESS_VM_OPERATION|PROCESS_CREATE_THREAD",
|
||||
"0x143A": "CLASSIC_INJECTION_RIGHTS",
|
||||
}
|
||||
|
||||
INJECTION_SUBTECHNIQUES = {
|
||||
"CreateRemoteThread": {"id": "T1055.001", "name": "DLL Injection"},
|
||||
"NtWriteVirtualMemory": {"id": "T1055.001", "name": "DLL Injection"},
|
||||
"QueueUserAPC": {"id": "T1055.004", "name": "APC Injection"},
|
||||
"NtMapViewOfSection": {"id": "T1055.012", "name": "Process Hollowing"},
|
||||
"SetWindowsHookEx": {"id": "T1055.001", "name": "DLL Injection via Hook"},
|
||||
}
|
||||
|
||||
|
||||
def parse_sysmon_events(log_path):
|
||||
"""Parse Sysmon JSON events, focusing on Event IDs 1, 8, and 10."""
|
||||
events = {"process_create": [], "create_remote_thread": [], "process_access": []}
|
||||
with open(log_path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
event = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
event_id = event.get("EventID", event.get("event_id", 0))
|
||||
if event_id == 1:
|
||||
events["process_create"].append(event)
|
||||
elif event_id == 8:
|
||||
events["create_remote_thread"].append(event)
|
||||
elif event_id == 10:
|
||||
events["process_access"].append(event)
|
||||
return events
|
||||
|
||||
|
||||
def detect_remote_thread_injection(events):
|
||||
"""Detect suspicious CreateRemoteThread (Sysmon Event ID 8)."""
|
||||
detections = []
|
||||
for event in events:
|
||||
source_image = event.get("SourceImage", "").lower()
|
||||
target_image = event.get("TargetImage", "").lower()
|
||||
source_name = source_image.rsplit("\\", 1)[-1] if "\\" in source_image else source_image
|
||||
target_name = target_image.rsplit("\\", 1)[-1] if "\\" in target_image else target_image
|
||||
|
||||
if (source_name, target_name) in LEGITIMATE_INJECTION_PAIRS:
|
||||
continue
|
||||
|
||||
severity = "medium"
|
||||
if source_name in SUSPICIOUS_SOURCE_PROCESSES:
|
||||
severity = "high"
|
||||
if target_name in HIGH_VALUE_TARGETS:
|
||||
severity = "critical" if severity == "high" else "high"
|
||||
|
||||
start_function = event.get("StartFunction", "")
|
||||
start_module = event.get("StartModule", "")
|
||||
subtechnique = INJECTION_SUBTECHNIQUES.get("CreateRemoteThread", {})
|
||||
|
||||
detections.append({
|
||||
"event_id": 8,
|
||||
"timestamp": event.get("UtcTime", event.get("TimeCreated", "")),
|
||||
"source_image": event.get("SourceImage", ""),
|
||||
"target_image": event.get("TargetImage", ""),
|
||||
"start_function": start_function,
|
||||
"start_module": start_module,
|
||||
"source_pid": event.get("SourceProcessId", ""),
|
||||
"target_pid": event.get("TargetProcessId", ""),
|
||||
"new_thread_id": event.get("NewThreadId", ""),
|
||||
"user": event.get("User", "unknown"),
|
||||
"severity": severity,
|
||||
"mitre_technique": subtechnique.get("id", "T1055"),
|
||||
"mitre_name": subtechnique.get("name", "Process Injection"),
|
||||
"indicator": f"CreateRemoteThread: {source_name} -> {target_name}",
|
||||
})
|
||||
return detections
|
||||
|
||||
|
||||
def detect_suspicious_process_access(events):
|
||||
"""Detect suspicious ProcessAccess (Sysmon Event ID 10)."""
|
||||
detections = []
|
||||
for event in events:
|
||||
source_image = event.get("SourceImage", "").lower()
|
||||
target_image = event.get("TargetImage", "").lower()
|
||||
source_name = source_image.rsplit("\\", 1)[-1] if "\\" in source_image else source_image
|
||||
target_name = target_image.rsplit("\\", 1)[-1] if "\\" in target_image else target_image
|
||||
granted_access = event.get("GrantedAccess", "").lower()
|
||||
|
||||
if (source_name, target_name) in LEGITIMATE_INJECTION_PAIRS:
|
||||
continue
|
||||
|
||||
access_label = DANGEROUS_ACCESS_RIGHTS.get(granted_access, "")
|
||||
if not access_label and granted_access not in {"0x1f0fff", "0x001a", "0x143a", "0x0020"}:
|
||||
continue
|
||||
|
||||
severity = "medium"
|
||||
if source_name in SUSPICIOUS_SOURCE_PROCESSES:
|
||||
severity = "high"
|
||||
if target_name == "lsass.exe":
|
||||
severity = "critical"
|
||||
if "ALL_ACCESS" in access_label:
|
||||
severity = "critical"
|
||||
|
||||
detections.append({
|
||||
"event_id": 10,
|
||||
"timestamp": event.get("UtcTime", event.get("TimeCreated", "")),
|
||||
"source_image": event.get("SourceImage", ""),
|
||||
"target_image": event.get("TargetImage", ""),
|
||||
"granted_access": granted_access,
|
||||
"access_label": access_label,
|
||||
"source_pid": event.get("SourceProcessId", ""),
|
||||
"target_pid": event.get("TargetProcessId", ""),
|
||||
"user": event.get("User", "unknown"),
|
||||
"severity": severity,
|
||||
"mitre_technique": "T1055",
|
||||
"indicator": f"Suspicious process access: {source_name} -> {target_name} ({access_label})",
|
||||
})
|
||||
return detections
|
||||
|
||||
|
||||
def build_injection_graph(thread_detections, access_detections):
|
||||
"""Build a source->target injection relationship graph."""
|
||||
graph = defaultdict(lambda: {"targets": set(), "event_count": 0})
|
||||
for d in thread_detections + access_detections:
|
||||
src = d["source_image"].rsplit("\\", 1)[-1] if "\\" in d["source_image"] else d["source_image"]
|
||||
tgt = d["target_image"].rsplit("\\", 1)[-1] if "\\" in d["target_image"] else d["target_image"]
|
||||
graph[src]["targets"].add(tgt)
|
||||
graph[src]["event_count"] += 1
|
||||
return {src: {"targets": list(info["targets"]), "event_count": info["event_count"]}
|
||||
for src, info in graph.items()}
|
||||
|
||||
|
||||
def generate_report(events, thread_detections, access_detections, injection_graph, log_path):
|
||||
"""Generate process injection hunt report."""
|
||||
all_detections = thread_detections + access_detections
|
||||
severity_counts = defaultdict(int)
|
||||
for d in all_detections:
|
||||
severity_counts[d["severity"]] += 1
|
||||
return {
|
||||
"report_time": datetime.utcnow().isoformat(),
|
||||
"log_source": log_path,
|
||||
"events_parsed": {
|
||||
"process_create": len(events["process_create"]),
|
||||
"create_remote_thread": len(events["create_remote_thread"]),
|
||||
"process_access": len(events["process_access"]),
|
||||
},
|
||||
"total_detections": len(all_detections),
|
||||
"severity_summary": dict(severity_counts),
|
||||
"create_remote_thread_detections": thread_detections,
|
||||
"process_access_detections": access_detections,
|
||||
"injection_graph": injection_graph,
|
||||
"mitre_techniques": ["T1055", "T1055.001", "T1055.004", "T1055.012"],
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Process Injection Detection Agent (T1055)")
|
||||
parser.add_argument("--log-file", required=True, help="Sysmon JSON event log file")
|
||||
parser.add_argument("--output", default="process_injection_report.json")
|
||||
args = parser.parse_args()
|
||||
|
||||
events = parse_sysmon_events(args.log_file)
|
||||
thread_detections = detect_remote_thread_injection(events["create_remote_thread"])
|
||||
access_detections = detect_suspicious_process_access(events["process_access"])
|
||||
injection_graph = build_injection_graph(thread_detections, access_detections)
|
||||
|
||||
report = generate_report(events, thread_detections, access_detections, injection_graph, args.log_file)
|
||||
with open(args.output, "w") as f:
|
||||
json.dump(report, f, indent=2, default=str)
|
||||
total = len(thread_detections) + len(access_detections)
|
||||
print(f"[+] Parsed {sum(len(v) for v in events.values())} Sysmon events")
|
||||
print(f"[+] CreateRemoteThread: {len(thread_detections)} | ProcessAccess: {len(access_detections)}")
|
||||
print(f"[+] Total injections detected: {total}")
|
||||
print(f"[+] Report saved to {args.output}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user