1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use crate::{MD5, Sha1, Sha256, Sid, JsonMap, SSDeepHash, datastore::file::URIInfo, config::ServiceSafelist};
/// File Information
#[derive(Serialize, Deserialize)]
pub struct FileInfo {
/// The output from libmagic which was used to determine the tag
pub magic: String,
/// MD5 of the file
pub md5: MD5,
/// The libmagic mime type
pub mime: Option<String>,
/// SHA1 hash of the file
pub sha1: Sha1,
/// SHA256 hash of the file
pub sha256: Sha256,
/// Size of the file in bytes
pub size: u64,
/// SSDEEP hash of the file"
pub ssdeep: Option<SSDeepHash>,
/// TLSH hash of the file"
pub tlsh: Option<String>,
/// Type of file as identified by Assemblyline
#[serde(rename="type")]
pub file_type: String,
/// URI structure to speed up specialty file searching
pub uri_info: Option<URIInfo>,
}
/// Tag Item
#[derive(Serialize, Deserialize)]
pub struct TagItem {
/// Type of tag item
#[serde(rename="type")]
pub tag_type: String,
/// Value of tag item
pub value: String,
/// Score of tag item
pub score: Option<i32>,
}
/// Data Item
#[derive(Serialize, Deserialize)]
pub struct DataItem {
pub name: String,
pub value: serde_json::Value,
}
/// Service Task Model
#[derive(Serialize, Deserialize)]
pub struct Task {
pub task_id: u64,
pub dispatcher: String,
/// Submission ID
pub sid: Sid,
/// Metadata associated to the submission
pub metadata: HashMap<String, String>,
/// Minimum classification of the file being scanned
pub min_classification: String,
/// File info block
pub fileinfo: FileInfo,
/// File name
pub filename: String,
/// Service name
pub service_name: String,
/// Service specific parameters
pub service_config: JsonMap,
/// File depth relative to initital submitted file
pub depth: u32,
/// Maximum number of files that submission can have
pub max_files: u32,
/// Task TTL
pub ttl: u32,
/// List of tags
pub tags: Vec<TagItem>,
/// Temporary submission data
pub temporary_submission_data: Vec<DataItem>,
/// Perform deep scanning
pub deep_scan: bool,
/// Whether the service cache should be ignored during the processing of this task
pub ignore_cache: bool,
/// Whether the service should ignore the dynamic recursion prevention or not
pub ignore_dynamic_recursion_prevention: bool,
/// Should the service filter it's output?
pub ignore_filtering: bool,
/// Priority for processing order
pub priority: i32,
/// Safelisting configuration (as defined in global configuration)
#[serde(default="task_default_safelist_config")]
pub safelist_config: ServiceSafelist, // ", default={'enabled': False})
}
pub fn task_default_safelist_config() -> ServiceSafelist {
ServiceSafelist {
enabled: false,
..Default::default()
}
}
impl Task {
// @staticmethod
// def make_key(sid, service_name, sha):
// return f"{sid}_{service_name}_{sha}"
// def key(self):
// return Task.make_key(self.sid, self.service_name, self.fileinfo.sha256)
pub fn signature(&self) -> TaskSignature {
TaskSignature {
task_id: self.task_id,
sid: self.sid,
service: self.service_name.clone(),
hash: self.fileinfo.sha256.clone()
}
}
}
#[derive(Hash, PartialEq, Eq)]
pub struct TaskSignature {
pub task_id: u64,
pub sid: Sid,
pub service: String,
pub hash: Sha256,
}
/// Service Task Model
#[derive(Serialize, Deserialize)]
pub struct TaskToken {
pub task_id: u64,
pub dispatcher: String,
}