RecordIDのチェック,構造体の名称変更
This commit is contained in:
48
src/detections/common.rs
Normal file
48
src/detections/common.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use crate::models::event;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Common {
|
||||||
|
record_id: u64,
|
||||||
|
date: String,
|
||||||
|
record_id_list : HashMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Common {
|
||||||
|
pub fn new() -> Common {
|
||||||
|
Common {
|
||||||
|
record_id: 0,
|
||||||
|
date: "".to_string(),
|
||||||
|
record_id_list: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disp(&self) {
|
||||||
|
for (record_id, date) in self.record_id_list.iter() {
|
||||||
|
println!("date:{:?} record-id: {:?}", date, record_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn detection(&mut self, system: &event::System, event_data: &HashMap<String, String>) {
|
||||||
|
|
||||||
|
&self.check_record_id(system);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Record IDがシーケンスになっているかチェック
|
||||||
|
//
|
||||||
|
fn check_record_id(&mut self, system: &event::System) {
|
||||||
|
|
||||||
|
let event_record_id: u64 = system.event_record_id.parse().unwrap();
|
||||||
|
if self.record_id > 0 && event_record_id - self.record_id > 1 {
|
||||||
|
self.record_id_list.insert(self.record_id.to_string() + " - " + &system.event_record_id.to_string(),
|
||||||
|
self.date.to_string() + " - " + &system.time_created.system_time.to_string());
|
||||||
|
}
|
||||||
|
self.record_id = event_record_id;
|
||||||
|
self.date = system.time_created.system_time.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod common;
|
||||||
pub mod security;
|
pub mod security;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod application;
|
pub mod application;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::models::event;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Security {
|
pub struct Security {
|
||||||
@@ -26,7 +27,7 @@ impl Security {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detection(&mut self, event_id: String, event_data: HashMap<String, String>) {
|
pub fn detection(&mut self, event_id: String, system: &event::System, event_data: HashMap<String, String>) {
|
||||||
|
|
||||||
if event_id == "4672" {
|
if event_id == "4672" {
|
||||||
&self.se_debug_privilege(event_data);
|
&self.se_debug_privilege(event_data);
|
||||||
@@ -41,7 +42,7 @@ impl Security {
|
|||||||
match event_data.get("PrivilegeList") {
|
match event_data.get("PrivilegeList") {
|
||||||
Some(privileage_list) => {
|
Some(privileage_list) => {
|
||||||
match privileage_list.find("SeDebugPrivilege") {
|
match privileage_list.find("SeDebugPrivilege") {
|
||||||
Some(data) => {
|
Some(_data) => {
|
||||||
|
|
||||||
// alert_all_adminが有効であれば、標準出力して知らせる
|
// alert_all_adminが有効であれば、標準出力して知らせる
|
||||||
// DeepBlueCLIでは必ず0になっていて、基本的には表示されない。
|
// DeepBlueCLIでは必ず0になっていて、基本的には表示されない。
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -7,6 +7,7 @@ use std::process;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use quick_xml::de::{DeError};
|
use quick_xml::de::{DeError};
|
||||||
use yamato_event_analyzer::models::event;
|
use yamato_event_analyzer::models::event;
|
||||||
|
use yamato_event_analyzer::detections::common;
|
||||||
use yamato_event_analyzer::detections::security;
|
use yamato_event_analyzer::detections::security;
|
||||||
use yamato_event_analyzer::detections::system;
|
use yamato_event_analyzer::detections::system;
|
||||||
use yamato_event_analyzer::detections::application;
|
use yamato_event_analyzer::detections::application;
|
||||||
@@ -15,13 +16,13 @@ fn main() -> Result<(), DeError> {
|
|||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let fp: PathBuf;
|
let fp: PathBuf;
|
||||||
if (args.len() > 1) {
|
if args.len() > 1 {
|
||||||
fp = PathBuf::from(args[1].to_string());
|
fp = PathBuf::from(args[1].to_string());
|
||||||
} else {
|
} else {
|
||||||
fp = PathBuf::from(format!("./samples/security.evtx"));
|
fp = PathBuf::from(format!("./samples/security.evtx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut common = common::Common::new();
|
||||||
let mut security = security::Security::new();
|
let mut security = security::Security::new();
|
||||||
let mut system = system::System::new();
|
let mut system = system::System::new();
|
||||||
let mut application = application::Application::new();
|
let mut application = application::Application::new();
|
||||||
@@ -37,15 +38,18 @@ fn main() -> Result<(), DeError> {
|
|||||||
match record {
|
match record {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
let event: event::Evtx = quick_xml::de::from_str(&r.data)?;
|
let event: event::Evtx = quick_xml::de::from_str(&r.data)?;
|
||||||
let event_id = event.System.EventID.to_string();
|
let event_id = event.system.event_id.to_string();
|
||||||
|
let channel = event.system.channel.to_string();
|
||||||
if event.System.Channel == "Security" {
|
|
||||||
let event_data = event.parse_event_data();
|
let event_data = event.parse_event_data();
|
||||||
&security.detection(event_id, event_data);
|
&common.detection(&event.system, &event_data);
|
||||||
} else if event.System.Channel == "System" {
|
if channel == "Security" {
|
||||||
|
&security.detection(event_id, &event.system, event_data);
|
||||||
|
} else if channel == "System" {
|
||||||
&system.detection();
|
&system.detection();
|
||||||
} else if event.System.Channel == "Application" {
|
} else if channel == "Application" {
|
||||||
&application.detection();
|
&application.detection();
|
||||||
|
} else {
|
||||||
|
//&other.detection();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => eprintln!("{}", e),
|
Err(e) => eprintln!("{}", e),
|
||||||
@@ -55,6 +59,7 @@ fn main() -> Result<(), DeError> {
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
// 表示
|
// 表示
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
common.disp();
|
||||||
security.disp();
|
security.disp();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -4,55 +4,78 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub Name: Option<String>,
|
#[serde(rename = "Name")]
|
||||||
|
pub name: Option<String>,
|
||||||
#[serde(rename = "$value")]
|
#[serde(rename = "$value")]
|
||||||
pub Text: Option<String>,
|
pub text: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
struct TimeCreated {
|
pub struct TimeCreated {
|
||||||
SystemTime: String,
|
#[serde(rename = "SystemTime")]
|
||||||
|
pub system_time: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
struct Execution {
|
struct Execution {
|
||||||
ProcessID: i32,
|
#[serde(rename = "ProcessID")]
|
||||||
ThreadID: i32,
|
process_id: i32,
|
||||||
|
#[serde(rename = "ThreadID")]
|
||||||
|
thread_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
struct Provider {
|
struct Provider {
|
||||||
Name: Option<String>,
|
#[serde(rename = "Name")]
|
||||||
Guid: Option<String>,
|
name: Option<String>,
|
||||||
|
#[serde(rename = "Guid")]
|
||||||
|
guid: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
pub struct System {
|
pub struct System {
|
||||||
Provider: Provider,
|
#[serde(rename = "Provider")]
|
||||||
pub EventID: String,
|
provider: Provider,
|
||||||
Version: Option<String>,
|
#[serde(rename = "EventID")]
|
||||||
Level: String,
|
pub event_id: String,
|
||||||
Task: String,
|
#[serde(rename = "Version")]
|
||||||
Opcode: Option<String>,
|
version: Option<String>,
|
||||||
Keywords: String,
|
#[serde(rename = "Level")]
|
||||||
TimeCreated: TimeCreated,
|
level: String,
|
||||||
EventRecordID: String,
|
#[serde(rename = "Task")]
|
||||||
Correlation: Option<String>,
|
task: String,
|
||||||
Execution: Option<Execution>,
|
#[serde(rename = "Opcode")]
|
||||||
pub Channel: String, // Security, System, Application ...etc
|
opcode: Option<String>,
|
||||||
Computer: String,
|
#[serde(rename = "Keywords")]
|
||||||
Security: String,
|
keywords: String,
|
||||||
|
#[serde(rename = "TimeCreated")]
|
||||||
|
pub time_created: TimeCreated,
|
||||||
|
#[serde(rename = "EventRecordID")]
|
||||||
|
pub event_record_id: String,
|
||||||
|
#[serde(rename = "Correlation")]
|
||||||
|
correlation: Option<String>,
|
||||||
|
#[serde(rename = "Execution")]
|
||||||
|
execution: Option<Execution>,
|
||||||
|
#[serde(rename = "Channel")]
|
||||||
|
pub channel: String, // Security, System, Application ...etc
|
||||||
|
#[serde(rename = "Computer")]
|
||||||
|
computer: String,
|
||||||
|
#[serde(rename = "Security")]
|
||||||
|
security: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
pub struct EventData {
|
pub struct EventData {
|
||||||
pub Data: Option<Vec<Data>>,
|
#[serde(rename = "Data")]
|
||||||
|
pub data: Option<Vec<Data>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, PartialEq)]
|
#[derive(Debug, Deserialize, PartialEq)]
|
||||||
pub struct Evtx {
|
pub struct Evtx {
|
||||||
pub System: System,
|
#[serde(rename = "System")]
|
||||||
pub EventData: Option<EventData>,
|
pub system: System,
|
||||||
|
#[serde(rename = "EventData")]
|
||||||
|
pub event_data: Option<EventData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Evtx {
|
impl Evtx {
|
||||||
@@ -62,7 +85,7 @@ impl Evtx {
|
|||||||
//
|
//
|
||||||
fn get_string(v: &Data) -> String {
|
fn get_string(v: &Data) -> String {
|
||||||
|
|
||||||
match &v.Text {
|
match &v.text {
|
||||||
Some(text) => {
|
Some(text) => {
|
||||||
return text.to_string();
|
return text.to_string();
|
||||||
},
|
},
|
||||||
@@ -73,15 +96,15 @@ impl Evtx {
|
|||||||
//
|
//
|
||||||
// EventDataをHashMapとして取得する
|
// EventDataをHashMapとして取得する
|
||||||
//
|
//
|
||||||
pub fn parse_event_data(self) -> HashMap<String,String> {
|
pub fn parse_event_data(&self) -> HashMap<String,String> {
|
||||||
let mut values = HashMap::new();
|
let mut values = HashMap::new();
|
||||||
|
|
||||||
match self.EventData {
|
match &self.event_data {
|
||||||
Some(event_data) =>
|
Some(event_data) =>
|
||||||
match event_data.Data {
|
match &event_data.data {
|
||||||
Some(data) => {
|
Some(data) => {
|
||||||
for v in data.iter() {
|
for v in data.iter() {
|
||||||
match &v.Name {
|
match &v.name {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
values.insert(name.to_string(), Evtx::get_string(v));
|
values.insert(name.to_string(), Evtx::get_string(v));
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user