Skip to content

Commit

Permalink
check for console before setting encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Christensen committed Feb 1, 2024
1 parent b303d1c commit 0e1e63e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Rubeus/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private static void MainExecute(string commandName, Dictionary<string,string> pa

try
{
// print unicode char properly
Console.OutputEncoding = Encoding.UTF8;
// print unicode char properly if there's a console
if(IsConsolePresent()) Console.OutputEncoding = Encoding.UTF8;

var commandFound = new CommandCollection().ExecuteCommand(commandName, parsedArgs);

Expand Down Expand Up @@ -99,6 +99,11 @@ public static string MainString(string command)
return output;
}

private static bool IsConsolePresent()
{
return Interop.GetConsoleWindow() != IntPtr.Zero;
}

public static void Main(string[] args)
{
// try to parse the command line arguments, show usage on failure and then bail
Expand Down
4 changes: 4 additions & 0 deletions Rubeus/lib/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ public static extern int DsGetDcName(
[DllImport("kernel32.dll")]
public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();


// LSA functions

[DllImport("secur32.dll", SetLastError = false)]
Expand Down

0 comments on commit 0e1e63e

Please sign in to comment.