Files
Andrea Cristaldi 492ffc428b First commit
2025-08-28 17:14:35 +02:00

63 lines
2.0 KiB
C#

// DefenderRuleParser
// Author: Andrea Cristaldi 2025 - https://github.com/andreacristaldi/DefenderRuleParser
// This project is licensed under the Apache 2.0 License.
/*
* Summary: NSCRIPT “SP” variant parser (scanning/probing flavored data).
* Origin: dump-driven; record types and lengths derived from hex evidence.
* Role: Formats command-like items for human review.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using DefenderRuleParser2.Models;
namespace DefenderRuleParser2.Parsers
{
public class NscriptSpParser : ISignatureParser
{
public void Parse(BinaryReader reader, int size, uint threatId)
{
long offset = reader.BaseStream.Position;
try
{
if (size != 14)
{
Logger.Warn($"[NSCRIPT_SP] ! Unexpected size: {size} bytes. Expected: 14.");
return;
}
byte[] data = reader.ReadBytes(14);
string hex = BitConverter.ToString(data).Replace("-", " ");
Logger.Info($"[NSCRIPT_SP] Threat ID: {threatId}, Size: 14 bytes");
Logger.Info($" > Hex: {hex}");
if (ThreatDatabase.TryGetThreat(threatId, out var threat))
{
threat.Signatures.Add(new SignatureEntry
{
Type = "SIGNATURE_TYPE_NSCRIPT_SP",
Offset = offset,
Pattern = new List<string> { hex },
Parsed = true,
Logic = null,
ConditionType = "PRESENCE",
ConditionValue = 1
});
}
}
catch (Exception ex)
{
Logger.Error($"[!] NSCRIPT_SP Error parsing at offset 0x{offset:X}: {ex.Message}");
}
finally
{
reader.BaseStream.Seek(offset + size, SeekOrigin.Begin);
}
}
}
}