mirror of
https://github.com/SpecterOps/Nemesis
synced 2026-06-08 12:36:42 +00:00
update dotnet model
This commit is contained in:
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator
|
||||
|
||||
from .logger import get_logger
|
||||
|
||||
@@ -97,20 +97,23 @@ class DotNetOutput(BaseModel):
|
||||
|
||||
object_id: str = Field(alias="objectId")
|
||||
decompilation: str | None = None
|
||||
analysis: str | None = None
|
||||
analysis: DotNetAssemblyAnalysis | None = None
|
||||
|
||||
def get_parsed_analysis(self) -> DotNetAssemblyAnalysis | None:
|
||||
"""Parse the analysis JSON string into a DotNetAssemblyAnalysis object"""
|
||||
if not self.analysis:
|
||||
@field_validator("analysis", mode="before")
|
||||
@classmethod
|
||||
def parse_analysis_json(cls, v):
|
||||
"""Parse analysis from JSON string if needed"""
|
||||
if v is None:
|
||||
return None
|
||||
try:
|
||||
if isinstance(v, str):
|
||||
import json
|
||||
|
||||
analysis_data = json.loads(self.analysis)
|
||||
return DotNetAssemblyAnalysis(**analysis_data)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to parse DotNet analysis: {e}")
|
||||
return None
|
||||
try:
|
||||
return json.loads(v)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to parse DotNet analysis JSON: {e}")
|
||||
return None
|
||||
return v
|
||||
|
||||
|
||||
##########################################
|
||||
@@ -233,7 +236,7 @@ class File(BaseModel):
|
||||
access_time: str | None = None
|
||||
modification_time: str | None = None
|
||||
|
||||
@field_serializer('timestamp', 'expiration')
|
||||
@field_serializer("timestamp", "expiration")
|
||||
def serialize_datetime(self, dt: datetime, _info):
|
||||
return dt.isoformat()
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ async def process_dotnet_event(dotnet_output: DotNetOutput, pool: asyncpg.Pool)
|
||||
|
||||
object_id = dotnet_output.object_id
|
||||
decompilation_object_id = dotnet_output.decompilation
|
||||
analysis = dotnet_output.get_parsed_analysis()
|
||||
analysis = dotnet_output.analysis
|
||||
|
||||
file_enriched = await get_file_enriched_async(object_id)
|
||||
|
||||
|
||||
@@ -74,7 +74,6 @@ async def save_file_message(file: File, pool: asyncpg.Pool):
|
||||
async def process_file_event(file: File, workflow_manager, module_execution_order: list, pool: asyncpg.Pool):
|
||||
"""Process incoming file events"""
|
||||
try:
|
||||
# Save the file message to database first for recovery purposes
|
||||
await save_file_message(file, pool)
|
||||
|
||||
workflow_input = {
|
||||
@@ -82,7 +81,6 @@ async def process_file_event(file: File, workflow_manager, module_execution_orde
|
||||
"execution_order": module_execution_order,
|
||||
}
|
||||
|
||||
# This will block if we're at max capacity, providing natural backpressure
|
||||
await workflow_manager.start_workflow(workflow_input)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -13,14 +13,12 @@ logger = get_logger(__name__)
|
||||
async def process_noseyparker_event(nosey_output: NoseyParkerOutput, pool: asyncpg.Pool):
|
||||
"""Process incoming Nosey Parker scan results"""
|
||||
try:
|
||||
# Now process the properly parsed output
|
||||
object_id = nosey_output.object_id
|
||||
matches = nosey_output.scan_result.matches
|
||||
stats = nosey_output.scan_result.stats
|
||||
|
||||
logger.debug(f"Found {len(matches)} matches for object {object_id}", pid=os.getpid())
|
||||
|
||||
# Store the findings in the database using our helper function
|
||||
await store_noseyparker_results(
|
||||
object_id=object_id,
|
||||
matches=matches,
|
||||
|
||||
Reference in New Issue
Block a user