-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More additions, need to fix CI and do Windows things
- Loading branch information
Showing
21 changed files
with
220 additions
and
144 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
#[cfg(feature = "internal")] | ||
mod internal; | ||
pub mod internal; | ||
|
||
#[cfg(feature = "internal")] | ||
pub use internal::*; | ||
|
||
//#[cfg(feature = "system")] | ||
mod system; | ||
|
||
//#[cfg(feature = "system")] | ||
pub use system::*; | ||
#[cfg(feature = "system")] | ||
pub mod system; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
Payload_Type/thanatos/agent/cryptolib/src/hash/system/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
//#[cfg(target_os = "linux")] | ||
//mod linux; | ||
#[cfg(target_os = "linux")] | ||
mod linux; | ||
|
||
//#[cfg(target_os = "linux")] | ||
//pub use linux::Sha256; | ||
#[cfg(target_os = "linux")] | ||
pub use linux::Sha256; | ||
|
||
//#[cfg(target_os = "windows")] | ||
#[cfg(target_os = "windows")] | ||
mod windows; | ||
|
||
//#[cfg(target_os = "windows")] | ||
#[cfg(target_os = "windows")] | ||
pub use windows::Sha256; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Payload_Type/thanatos/agent/ffiwrappers/src/windows/domain.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use errors::ThanatosError; | ||
|
||
use windows::{ | ||
core::PSTR, | ||
Win32::{ | ||
Foundation::ERROR_MORE_DATA, | ||
System::SystemInformation::{ComputerNameDnsDomain, GetComputerNameExA}, | ||
}, | ||
}; | ||
|
||
/// Get the domain name of the system | ||
pub fn domain() -> Result<String, ThanatosError> { | ||
let mut domainname_length = 0u32; | ||
|
||
// Get the length of the computer's domain name. | ||
// | ||
// SAFETY: This will return an error from Windows which needs to be checked. | ||
// If this is "successful", then the Windows error should contain 'ERROR_MORE_DATA'. | ||
// This is the error code returned when the buffer is not large enough. | ||
match unsafe { | ||
GetComputerNameExA( | ||
ComputerNameDnsDomain, | ||
PSTR(std::ptr::null_mut()), | ||
&mut domainname_length, | ||
) | ||
} { | ||
// Check if 'ERROR_MORE_DATA' was returned | ||
Err(e) if e.code() == windows::core::Error::from(ERROR_MORE_DATA).code() => (), | ||
|
||
// Check if any other error was returned | ||
Err(e) => return Err(ThanatosError::from_windows(e)), | ||
|
||
// This function should never return successfully since the length is 0 | ||
_ => unreachable!(), | ||
}; | ||
|
||
// Create a buffer for storing the domain name | ||
// | ||
// The length can safely be casted to a usize using as since the maximum length | ||
// of a Windows domain name is 255 characters. | ||
// ref: https://learn.microsoft.com/en-US/troubleshoot/windows-server/identity/naming-conventions-for-computer-domain-site-ou#dns-domain-names | ||
let mut domainname_buffer = vec![0u8; domainname_length as usize]; | ||
|
||
// Get the computer's domain name. | ||
// | ||
// SAFETY: A buffer needs to be allocated for holding the domain name. The | ||
// length of the domain was found above. The domain name length must match the | ||
// length of the allocated buffer! An error needs to be checked in case the function fails | ||
unsafe { | ||
GetComputerNameExA( | ||
ComputerNameDnsDomain, | ||
PSTR(domainname_buffer.as_mut_ptr()), | ||
&mut domainname_length, | ||
) | ||
} | ||
.map_err(ThanatosError::from_windows)?; | ||
|
||
// Cast the domain name length. | ||
// The domain name length value now contains the length of the system's domain name | ||
// without the NULL terminator. | ||
// ref: https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getcomputernameexa | ||
let domainname_length = domainname_length as usize; | ||
|
||
// Convert the domain name buffer to a string | ||
let s = String::from_utf8_lossy(&domainname_buffer[..domainname_length]); | ||
Ok(s.into_owned()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn domainname() { | ||
let domain = super::domain().unwrap(); | ||
dbg!(domain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.