Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with escape characters #12

Open
sjdevries opened this issue Apr 11, 2023 · 1 comment
Open

Possible issue with escape characters #12

sjdevries opened this issue Apr 11, 2023 · 1 comment

Comments

@sjdevries
Copy link

I'm trying to use litcrypt to encrypt some strings and have been running into an issue using strings containing escape characters, specifically backslashes.

I'm fairly new to rust, so maybe I am doing something wrong. The main function creates the string values and sends them to the net_use function. That function uses command to call the windows net use command to map a network drive.

My cargo.toml as the following:

[dependencies]
litcrypt = "0.3"

Here is the main function:

use std::process::Command;  // Import Command, used for the net_use function
#[macro_use]
extern crate litcrypt;      // Import litcrypt and initialize the crate.
use_litcrypt!();

fn main() {
    // encrypt parameters so they are not easily visible in the final executabale.
    let drive_letter = lc!("Z:");
    let drive_label = lc!("My Share Label");
    let share_path = lc!("\\\\server\\share\\subdir");
    //let share_path = String::from("\\\\server\\share\\subdir");
    let user = lc!("my_secret_user");
    let password = lc!("my_secret_password");
    let persistent = true;
    let remove = true;
    let savecred = false;
    net_use(&drive_letter, &drive_label, &share_path, &user, &password, persistent, remove, savecred);
}

The output I get is:

Network share "\\\\server\\share\\subdir" not found.  No delete required.
Drive label "My Share Label" for drive Z: pointing to "\\\\server\\share\\subdir" added successfully.
... error info because there is no real share ...

When using a real share, it fails to find an actual share and connect, because the share_path variable has extra backslashes in it as shown in the output above. When I reverse the lines for the share_path variable I get the expected output result.

Modified lines:

    //let share_path = lc!("\\\\server\\share\\subdir");
    let share_path = String::from("\\\\server\\share\\subdir");

The output I get is:

Network share "\\server\share\subdir" not found.  No delete required.
Drive label "My Share Label" for drive Z: pointing to "\\server\share\subdir" added successfully.

The backslashes are properly escaped in the above output string. When I change the values to a real share the net_use function does find the share, delete the previous mapped drive, labels new mapped drive, and create a new mapped drive as expected.

If I try to change the line as follows, it fails to compile at all because it cannot understand the escape characters.
let share_path = lc!("\\server\share\subdir");

The following also seems to work correctly:

    let server = lc!("server");
    let share = lc!("share");
    let subdir = lc!("subdir");
    let share_path = format!("\\\\{}\\{}\\{}", server, share, subdir);

Is there any specific way escaped characters should be handled with litcrypt?
Hopefully, this is enough information to create a simple test case and confirm if it an issue.

@virtualritz
Copy link
Contributor

This is a more telling example:

use litcrypt2::*;

use_litcrypt!();

fn main() {
    assert_eq!(lc!("\"hello\""), "\"hello\"");
}
thread 'main' panicked at src/main.rs:6:5:
assertion `left == right` failed
  left: "\\\"hello\\\""
 right: "\"hello\""
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants