rusthound_ce/json/maker/
mod.rs

1use std::collections::HashMap;
2use std::error::Error;
3
4extern crate zip;
5use crate::args::Options;
6use crate::utils::date::return_current_fulldate;
7use crate::objects::{
8   user::User,
9   computer::Computer,
10   group::Group,
11   ou::Ou,
12   container::Container,
13   gpo::Gpo,
14   domain::Domain,
15   ntauthstore::NtAuthStore,
16   aiaca::AIACA,
17   rootca::RootCA,
18   enterpriseca::EnterpriseCA,
19   certtemplate::CertTemplate,
20   inssuancepolicie::IssuancePolicie,
21};
22pub mod common;
23
24/// This function will create json output and zip output
25pub fn make_result(
26   common_args:            &Options,
27   vec_users:              Vec<User>,
28   vec_groups:             Vec<Group>,
29   vec_computers:          Vec<Computer>,
30   vec_ous:                Vec<Ou>,
31   vec_domains:            Vec<Domain>,
32   vec_gpos:               Vec<Gpo>,
33   vec_containers:         Vec<Container>,
34   vec_ntauthstores:       Vec<NtAuthStore>,
35   vec_aiacas:             Vec<AIACA>,
36   vec_rootcas:            Vec<RootCA>,
37   vec_enterprisecas:      Vec<EnterpriseCA>,
38   vec_certtemplates:      Vec<CertTemplate>,
39   vec_issuancepolicies:   Vec<IssuancePolicie>,
40) -> Result<(), Box<dyn Error>> {
41   // Format domain name
42   let filename = common_args.domain.replace(".", "-").to_lowercase();
43
44   // Hashmap for json files
45   let mut json_result: HashMap<String, String> = HashMap::new();
46
47   // Datetime for output file
48   let datetime = return_current_fulldate();
49
50   // Add all in json files
51   common::add_file(
52      &datetime,
53      "users".to_string(),
54		&filename,
55      vec_users,
56      &mut json_result,
57      common_args,
58   )?;
59   common::add_file(
60      &datetime,
61      "groups".to_string(),
62		&filename,
63      vec_groups,
64      &mut json_result,
65      common_args,
66   )?;
67   common::add_file(
68      &datetime,
69      "computers".to_string(),
70		&filename,
71      vec_computers,
72      &mut json_result,
73      common_args,
74   )?;
75   common::add_file(
76      &datetime,
77      "ous".to_string(),
78		&filename,
79      vec_ous,
80      &mut json_result,
81      common_args,
82   )?;
83   common::add_file(
84      &datetime,
85      "domains".to_string(),
86		&filename,
87      vec_domains,
88      &mut json_result,
89      common_args,
90   )?;
91   common::add_file(
92      &datetime,
93      "gpos".to_string(),
94      &filename,
95      vec_gpos,
96      &mut json_result,
97      common_args,
98   )?;
99   // }
100   common::add_file(
101      &datetime,
102      "containers".to_string(),
103		&filename,
104      vec_containers,
105      &mut json_result,
106      common_args,
107   )?;
108   common::add_file(
109      &datetime,
110      "ntauthstores".to_string(),
111		&filename,
112      vec_ntauthstores,
113      &mut json_result,
114      common_args,
115   )?;
116   common::add_file(
117      &datetime,
118      "aiacas".to_string(),
119		&filename,
120      vec_aiacas,
121      &mut json_result,
122      common_args,
123   )?;
124   common::add_file(
125      &datetime,
126      "rootcas".to_string(),
127		&filename,
128      vec_rootcas,
129      &mut json_result,
130      common_args,
131   )?;
132   common::add_file(
133      &datetime,
134      "enterprisecas".to_string(),
135		&filename,
136      vec_enterprisecas,
137      &mut json_result,
138      common_args,
139   )?;
140   common::add_file(
141      &datetime,
142      "certtemplates".to_string(),
143		&filename,
144      vec_certtemplates,
145      &mut json_result,
146      common_args,
147   )?;
148   common::add_file(
149      &datetime,
150      "issuancepolicies".to_string(),
151		&filename,
152      vec_issuancepolicies,
153      &mut json_result,
154      common_args,
155   )?;
156   // All in zip file
157   if common_args.zip {
158      common::make_a_zip(
159         &datetime,
160         &filename,
161         &common_args.path,
162         &json_result);
163   }
164   Ok(())
165}