Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aab

Check warning on line 1 in .github/actions/spelling/expect.txt

View workflow job for this annotation

GitHub Actions / Check Spelling

Skipping `.github/actions/spelling/expect.txt` because it seems to have more noise (354) than unique words (0) (total: 355 / 0). (noisy-file)
AAFFBB
aarch
abe
Expand Down Expand Up @@ -158,7 +158,7 @@
Loggerhas
logon
Lrs
Lsa
lsa
ltsc
luid
macikgo
Expand Down Expand Up @@ -352,3 +352,3 @@
xxxx
xxxxxxxx
xxxxxxxxxxx
Expand Down
89 changes: 16 additions & 73 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions proxy_agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ winres = "0.1.12" # Rust Windows resource helper to add file version
static_vcruntime = "2.0.0" # Statically link the VCRuntime when using the MSVC toolchain

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.42.0"
version = "0.52.0"
features = [
"Wdk_Foundation",
"Wdk_System_Threading",
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_System_IO",
Expand All @@ -76,7 +78,7 @@ features = [
"Win32_System_ProcessStatus",
"Win32_System_Kernel",
"Win32_Security_Cryptography",
"Win32_System_Memory",
"Win32_System_Memory"
]

[features]
Expand Down
18 changes: 11 additions & 7 deletions proxy_agent/src/common/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use windows_sys::Win32::Security::Cryptography::{
// msasn1.dll (ASN.1 library) is also used by crypt32.dll
CryptProtectData,
CryptUnprotectData,
CRYPTOAPI_BLOB,
CRYPT_INTEGER_BLOB,
};
use windows_sys::Win32::System::SystemInformation::{
GetSystemInfo, // kernel32.dll
Expand Down Expand Up @@ -46,11 +46,11 @@ pub fn get_memory_in_mb() -> Result<u64> {

pub fn store_key_data(encrypted_file_path: &Path, key_data: String) -> Result<()> {
let data = key_data.as_bytes();
let data_in = CRYPTOAPI_BLOB {
let data_in = CRYPT_INTEGER_BLOB {
cbData: data.len() as u32,
pbData: data.as_ptr() as *mut u8,
};
let mut data_out = CRYPTOAPI_BLOB {
let mut data_out = CRYPT_INTEGER_BLOB {
cbData: 0,
pbData: std::ptr::null_mut(),
};
Expand All @@ -73,7 +73,9 @@ pub fn store_key_data(encrypted_file_path: &Path, key_data: String) -> Result<()

let encrypted_data =
unsafe { std::slice::from_raw_parts(data_out.pbData, data_out.cbData as usize).to_vec() };
unsafe { windows_sys::Win32::System::Memory::LocalFree(data_out.pbData as isize) };
unsafe {
windows_sys::Win32::Foundation::LocalFree(data_out.pbData as *mut ::core::ffi::c_void)
};
std::fs::write(encrypted_file_path, encrypted_data).map_err(|e| {
Error::Io(
format!(
Expand All @@ -97,11 +99,11 @@ pub fn fetch_key_data(encrypted_file_path: &Path) -> Result<String> {
e,
)
})?;
let data_in = CRYPTOAPI_BLOB {
let data_in = CRYPT_INTEGER_BLOB {
cbData: encrypted_data.len() as u32,
pbData: encrypted_data.as_ptr() as *mut u8,
};
let mut data_out = CRYPTOAPI_BLOB {
let mut data_out = CRYPT_INTEGER_BLOB {
cbData: 0,
pbData: std::ptr::null_mut(),
};
Expand All @@ -125,7 +127,9 @@ pub fn fetch_key_data(encrypted_file_path: &Path) -> Result<String> {
let decrypted_data = unsafe {
std::slice::from_raw_parts(data_out.pbData as *const u8, data_out.cbData as usize).to_vec()
};
unsafe { windows_sys::Win32::System::Memory::LocalFree(data_out.pbData as isize) };
unsafe {
windows_sys::Win32::Foundation::LocalFree(data_out.pbData as *mut ::core::ffi::c_void)
};
let key_data = String::from_utf8_lossy(&decrypted_data).to_string();

Ok(key_data)
Expand Down
15 changes: 10 additions & 5 deletions proxy_agent/src/proxy/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ use once_cell::sync::Lazy;
use std::mem::MaybeUninit;
use std::ptr::null_mut;
use std::{collections::HashMap, ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf};
use windows_sys::Wdk::System::Threading::{
NtQueryInformationProcess, // ntdll.dll
PROCESSINFOCLASS,
};
use windows_sys::Win32::Foundation::{BOOL, HANDLE, LUID, NTSTATUS, UNICODE_STRING};
use windows_sys::Win32::Security::Authentication::Identity;
use windows_sys::Win32::Security::Authentication::Identity::SECURITY_LOGON_SESSION_DATA;
use windows_sys::Win32::Security::Authentication::Identity::{
LSA_UNICODE_STRING, SECURITY_LOGON_SESSION_DATA,
};
use windows_sys::Win32::System::ProcessStatus::{
K32GetModuleBaseNameW, // kernel32.dll
K32GetModuleFileNameExW, // kernel32.dll
};
use windows_sys::Win32::System::Threading::PROCESS_BASIC_INFORMATION;
use windows_sys::Win32::System::Threading::{
NtQueryInformationProcess, // ntdll.dll
OpenProcess, //kernel32.dll
OpenProcess, //kernel32.dll
};
use windows_sys::Win32::System::Threading::{PROCESSINFOCLASS, PROCESS_BASIC_INFORMATION};

const LG_INCLUDE_INDIRECT: u32 = 1u32;
const MAX_PREFERRED_LENGTH: u32 = 4294967295u32;
Expand Down Expand Up @@ -179,7 +184,7 @@ pub fn get_user(logon_id: u64) -> Result<(String, Vec<String>)> {
Ok((user_name, user_groups))
}

fn from_unicode_string(unicode_string: &UNICODE_STRING) -> String {
fn from_unicode_string(unicode_string: &LSA_UNICODE_STRING) -> String {
let mut v = vec![0u16; unicode_string.Length as usize];
unsafe {
std::ptr::copy_nonoverlapping(
Expand Down
2 changes: 1 addition & 1 deletion proxy_agent_shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ windows-service = "0.7.0" # windows NT service
winreg = "0.11.0" # windows reg read/write

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.42.0"
version = "0.52.0"
features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
Expand Down
10 changes: 5 additions & 5 deletions proxy_agent_shared/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ pub fn get_processor_arch() -> String {
.Anonymous
.wProcessorArchitecture
{
windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_INTEL => "x86", // 0
windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_ARM => "ARM", // 5
windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_IA64 => "IA64", // 6
windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_AMD64 => "AMD64", // 9
12 => "ARM64", // 12 - ARM64 is missed here
windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_INTEL => "x86", // 0
windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_ARM => "ARM", // 5
windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_IA64 => "IA64", // 6
windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_AMD64 => "AMD64", // 9
windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_ARM64 => "ARM64", // 12
_ => "unknown",
}
.to_owned()
Expand Down
Loading