Cleaned up Windows server and added more docs

This commit is contained in:
Andrew Rioux
2024-01-25 16:53:05 -05:00
parent 28dd9f5138
commit 7390a2e3bf
11 changed files with 242 additions and 44 deletions

View File

@@ -13,14 +13,16 @@ pub fn print_capabilities(capabilities: &Capabilities, ip: &IpAddr) {
OperatingSystem::Windows => "Windows",
}
);
println!(
"\tInside a container: \t{}",
if capabilities.docker_container {
"yes"
} else {
"no"
}
);
if matches!(&capabilities.operating_system, OperatingSystem::Linux) {
println!(
"\tInside a container: \t{}",
if capabilities.docker_container {
"yes"
} else {
"no"
}
);
}
if capabilities.docker_container {
println!(
"\tContainer breakout: \t{}",

View File

@@ -18,6 +18,12 @@ pub const SPARSE_WINDOWS_SERVER_BINARY: &'static [u8] =
#[cfg(not(debug_assertions))]
pub const SPARSE_WINDOWS_SERVER_BINARY: &'static [u8] =
include_bytes!(std::env!("SPARSE_WINDOWS_SERVER"));
#[cfg(debug_assertions)]
pub const SPARSE_WINDOWS_SERVICE_BINARY: &'static [u8] =
include_bytes!("../../../../target/x86_64-pc-windows-gnu/debug/sparse-05-server.exe");
#[cfg(not(debug_assertions))]
pub const SPARSE_WINDOWS_SERVICE_BINARY: &'static [u8] =
include_bytes!(std::env!("SPARSE_WINDOWS_SERVICE"));
pub async fn generate(mut name: PathBuf, port: u16, target: TargetOs) -> anyhow::Result<()> {
let mut csprng = rand::thread_rng();
@@ -31,7 +37,7 @@ pub async fn generate(mut name: PathBuf, port: u16, target: TargetOs) -> anyhow:
let old_file_part = name.file_name().unwrap().to_owned();
if matches!(target, TargetOs::Windows) {
if matches!(target, TargetOs::Windows) || matches!(target, TargetOs::WindowsService) {
let mut file_part = name.file_name().unwrap().to_owned();
file_part.push(OsString::from(".exe"));
name.pop();
@@ -40,14 +46,15 @@ pub async fn generate(mut name: PathBuf, port: u16, target: TargetOs) -> anyhow:
let mut file = file.open(&name).await?;
if matches!(target, TargetOs::Windows) {
if matches!(target, TargetOs::Windows) || matches!(target, TargetOs::WindowsService) {
name.pop();
name.push(old_file_part);
}
file.write_all(match target {
TargetOs::Windows => SPARSE_WINDOWS_SERVER_BINARY,
TargetOs::Linux => SPARSE_LINUX_SERVER_BINARY,
TargetOs::Windows => SPARSE_WINDOWS_SERVER_BINARY,
TargetOs::WindowsService => SPARSE_WINDOWS_SERVICE_BINARY
})
.await?;
file.write_all(CONFIG_SEPARATOR).await?;

View File

@@ -17,6 +17,7 @@ fn to_socket_addr(src: &str) -> Result<SocketAddr, std::io::Error> {
pub enum TargetOs {
Linux,
Windows,
WindowsService,
}
impl std::str::FromStr for TargetOs {
@@ -25,6 +26,7 @@ impl std::str::FromStr for TargetOs {
match input {
"linux" => Ok(Self::Linux),
"windows" => Ok(Self::Windows),
"windows-service" => Ok(Self::WindowsService),
_ => Err("could not parse target operating system"),
}
}