use pwfile instead of pw for puttyng

This commit is contained in:
Robert Rostek
2023-10-03 10:52:41 +02:00
parent ac99115424
commit 54544dd2aa

View File

@@ -13,6 +13,9 @@ using mRemoteNG.Properties;
using mRemoteNG.Resources.Language;
using System.IO;
using System.Runtime.Versioning;
using System.IO.Pipes;
using Google.Protobuf.WellKnownTypes;
using System.Linq;
// ReSharper disable ArrangeAccessorOwnerBody
@@ -57,6 +60,19 @@ namespace mRemoteNG.Connection.Protocol
return !PuttyProcess.HasExited;
}
public void CreatePipe(object oData)
{
string data = (string)oData;
string random = data[..8];
string password = data[8..];
var server = new NamedPipeServerStream($"mRemoteNGSecretPipe{random}");
server.WaitForConnection();
StreamWriter writer = new(server);
writer.Write(password);
writer.Flush();
server.Dispose();
}
public override bool Connect()
{
string optionalTemporaryPrivateKeyPath = ""; // path to ppk file instead of password. only temporary (extracted from credential vault).
@@ -74,7 +90,7 @@ namespace mRemoteNG.Connection.Protocol
}
};
var arguments = new CommandLineArguments {EscapeForShell = false};
var arguments = new CommandLineArguments { EscapeForShell = false };
arguments.Add("-load", InterfaceControl.Info.PuttySession);
@@ -140,7 +156,7 @@ namespace mRemoteNG.Connection.Protocol
break;
}
}
if (string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(optionalTemporaryPrivateKeyPath))
{
@@ -162,7 +178,13 @@ namespace mRemoteNG.Connection.Protocol
if (!string.IsNullOrEmpty(password))
{
arguments.Add("-pw", password);
string random = string.Join("", Guid.NewGuid().ToString("n").Take(8).Select(o => o));
// write data to pipe
var thread = new Thread(new ParameterizedThreadStart(CreatePipe));
thread.Start($"{random}{password}");
// start putty with piped password
arguments.Add("-pwfile", $"\\\\.\\PIPE\\mRemoteNGSecretPipe{random}");
//arguments.Add("-pw", password);
}
}