Skip to main content

astrum_deus_package_sdk/
lib.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize, Default)]
6pub struct ScanResult {
7    pub port: Vec<PortResultItem>,
8
9    // 以下字段尚未用到
10    pub vulns: Vec<VulnResultItem>,
11    pub domain: Vec<DomainResultItem>,
12    pub dir: Vec<DirResultItem>,
13}
14
15/// 端口扫描的结果对应的结构体
16#[derive(Debug, Serialize, Deserialize)]
17pub struct PortResultItem {
18    pub ip: String,
19    pub port: u16,
20    pub protocol: String,
21    // 指纹、banner信息
22    pub banner: Option<String>,
23    pub extra: Option<String>,
24}
25
26/// 域名扫描结果对应的结构体
27#[derive(Debug, Serialize, Deserialize)]
28pub struct DomainResultItem {
29    pub domain: String,
30    pub record_type: String,
31    pub record: String,
32    pub status_code: Option<u16>,
33    pub title: Option<String>,
34    pub content: Option<String>,
35    pub screenshot: Option<String>,
36    pub extra: Option<String>,
37}
38
39/// 目录扫描的结果对应的结构体
40#[derive(Debug, Serialize, Deserialize)]
41pub struct DirResultItem {
42    pub path: String,
43    pub status_code: u16,
44    pub method: String,
45    pub title: Option<String>,
46    pub content: Option<String>,
47    pub screenshot: Option<String>,
48    pub extra: Option<String>,
49}
50
51/// 漏洞扫描结果对应的结构体
52#[derive(Debug, Serialize, Deserialize)]
53pub struct VulnResultItem {
54    pub title: String,
55    pub url: String,
56    pub description: String,
57}
58
59/// Package 输出用的结构体
60#[derive(Debug, Serialize)]
61pub struct PackageStdoutResult {
62    success: bool,
63    result_path: Option<String>,
64    error: Option<String>,
65}
66
67impl PackageStdoutResult {
68    pub fn ok(result_path: impl Into<String>) {
69        let s = Self {
70            success: true,
71            result_path: Some(result_path.into()),
72            error: None,
73        };
74
75        println!("{}", serde_json::to_string(&s).unwrap());
76    }
77
78    pub fn err(error: impl Into<String>) {
79        let s = Self {
80            success: false,
81            result_path: None,
82            error: Some(error.into()),
83        };
84
85        println!("{}", serde_json::to_string(&s).unwrap());
86    }
87}
88
89/// Package 的输入相关
90#[derive(Debug, Deserialize)]
91pub struct PackageArgs {
92    pub target: String,
93    pub task_id: String,
94    pub params: HashMap<String, String>,
95}
96
97impl PackageArgs {
98    pub fn parse_args() -> Result<Self, String> {
99        let args: Vec<String> = std::env::args().collect();
100        if args.len() < 2 {
101            return Err(format!(
102                "Not enough arguments. required: ./{} params_json",
103                args[0]
104            ));
105        }
106
107        serde_json::from_str::<Self>(&args[1]).map_err(|e| {
108            format!("Error while deserialize argument to PackageArgs. Err: {e:?}. args: {args:?}")
109        })
110    }
111}