Send login & password to PuTTY

Advertisement

Limo
Guest

Send login & password to PuTTY

I think it could be very useful to login in a PuTTY session without typing the username in the PuTTY login window.

The password is already sent through the provided WinSCP option.

Reply with quote

Advertisement

Limo
Guest

The username is correctly sent if you save it in the options of the server you want to connect to.

If you have a server stored without access data, WinSCP asks for username and password and, once connected, if you open a PuTTY session, it (PuTTY) will ask for the username.

Is it possible to send username and password to the PuTTY session without storing them in the server options?

Reply with quote

WhiteTiger
Guest

Just change the way PuTTY integration works.
The current Integration isn't compatible with KiTTY in portable mode just because all informations are stored to the registry. (or any other portable PuTTY, except all who uses the registry as a fall back)
Just allow patterns for external applications so we can use something like this:
putty -pw "!P" !U@!@
kitty -pw "!P" -cmd "cd !/" !U@!@
kitty -pass "!P" -cmd "cd !/" !U@!@
(but i don't like the pattern style... what ever :D)
Why using the registry anyway?

Of course, don't get the session informations from stored session files^^

Reply with quote

Advertisement

Guest

martin wrote:

Not all session options can be passed via command-line.
...can they be passed with ini files? Do those "portable" versions use ini files?

Reply with quote

Advertisement

Josef
Joined:
Posts:
3
Location:
Austria

I also only use KiTTY and WinSCP in portable mode.
Most of the time I just start KiTTY first and then WinSCP using Shift+F3, but it would be cool if it would work the other way around too.

Reply with quote

scottyman2k
Guest

KiTTY in place of PuTTY

Hi guys
I'd rather use KiTTY than PuTTY, but want to manage all the connections from inside WinSCP

Reply with quote

Loreto
Guest

KiTTY in place of PuTTY

I agree with scottyman2k.
Pmimarly I use Kitty.
I use putty only for the fact that winscp does not allow to pass parameters to an external application. I noticed that winscp passes the following parameters:
-pw password -load "WinSCP temporary session"
but nothing else.
For example it doesn't pass the userID.
If userID could be passed it would be enough to throw kitty.
For example:
-l userID -pass password -load "WinSCP temporary session"
So it's great if winscp could start other external applications over putty.

Reply with quote

WhiteTiger
Joined:
Posts:
7
Location:
Germany

Re: KiTTY in place of PuTTY

Well... to be fair, I've wrote a wrapper application that starts KiTTY (and even sends the current remote path to it)
I've wrote it as I've posted my first post... actually I wanted to "upgrade" WinSCP but it's code is a mess xD And I'm only using real C/C++ so no Borland crap (which is the main reason I'm not able to do it directly for WinSCP, besides the code of course xD)

I can give you the wrapper... I wanted to post it anyway but it's not user friendly at all :P Works for me but no one else xD

Reply with quote

Advertisement

WhiteTiger
Joined:
Posts:
7
Location:
Germany

well... my wrapper will be still of some use.. it gives KiTTY all informations it needs by command line, but it censors the command line once KiTTY is fully running (replaces the entire command line with *, so using taskmgr will show something like KiTTY.exe ****************************)
As we are talking about portable versions anyway, such security additions might be helpful. (not that I'm using my portable version outside my Computer/Home)

P.S. the code to "delete" the command line is actually based on code to retrieve the command line of other processes, but it does not only read it as it also overwrites it.

Reply with quote

Simba
Donor
Joined:
Posts:
21

Support for PuTTY should be dropped. It's dead.

Please change it to KiTTY or provide us way to use KiTTY.

Thanks, Martin. Simon.

Reply with quote

Advertisement

Simba
Donor
Joined:
Posts:
21

Hello Martin,

Please, it is time to make a move to KiTTY. PuTTY is outdated.

I have tried creating custom command within WinSCP to call KiTTY, but I cannot find a way to pass the port, so i always get Network connection refused.

As discussed in this post: Fast-open of PuTTY in current directory

Otherwise login info passed via parameters seems to work fine.

Thanks!

Reply with quote

WhiteTiger
Joined:
Posts:
7
Location:
Germany

Well.. Simba you might try my PuTTY wrapper for now... it's still not finished (and I'm not really developing it further as it works for me) but should work...

You'll have to setup WinSCP the way I require it though...
  • Options > Preferences... > Environment > Window > Show full path (checked)
  • extract PuTTY-Wrapper where your KiTTY.exe is
  • setup WinSCP to use PuTTY-Wrapper instead of PuTTY/KiTTY
    Options > Preferences... > Integration/Applications > PuTTY path
also, it deletes the registry entries for PuTTY / all SimonTatham products... that means your PuTTY settings if you're not using KiTTY in a portable way.
HKEY_CURRENT_USER\Software\SimonTatham
so use it only with KiTTY or portable PuTTY (portable PuTTY not tested.. as I pass KiTTY specific params) and don't use the registry to store PuTTY/KiTTY settings.

It's done in AutoIt and actually OpenSource... so I'll handle it out on request (and it's ugly as there's a lot of comments, unused crap and that like... As I said, not finished)
Last edited by WhiteTiger on 2013-05-12 13:34; edited 1 time in total

Reply with quote

Simba
Donor
Joined:
Posts:
21

Thanks for your response.
First time i got it working, but after it always:
Network error: connection refused.
Maybe Martin could help us?

Reply with quote

WhiteTiger
Joined:
Posts:
7
Location:
Germany

and you used my wrapper? (and it worked^^ wasn't that sure about that :P)
Well... my wrapper passes the port to kitty... you could check the command line it passes.
For that: open taskmgr, set refresh rate to "high" and start KiTTY through WinSCP . You might be able to "capture" the command line that way before the wrapper deletes it.

Reply with quote

Advertisement

Simba
Donor
Joined:
Posts:
21

Actually I found very easy way.

On <invalid hyperlink removed by admin>:
The problem was that KiTTY is using a different key in the Windows registry to store its settings.

For PuTTY you have:
[HKCU\Software\SimonTatham\PuTTY\*]
For KiTTY it's
[HKCU\Software\9bis.com\KiTTY\*]
So in order to launch a KiTTY session straight from WinSCP (portable) you need to edit WinSCP.ini

Just browse for the line:
PuttyRegistryStorageKey=Software%5CSimonTatham%5CPuTTY
and replace it with:
PuttyRegistryStorageKey=Software%5C9bis.com%5CKiTTY
Just make sure you are using NOT portable KiTTY version.
After changing WinSCP registry key, change path to Kitty.exe and it will work.

Reply with quote

Advertisement

Simba
Donor
Joined:
Posts:
21

Tested and it's working perfectly.

Next step would be to rename PuTTY instances to "SSH client" (I believe in future there might arise new, even better alternatives).

Include dropdown – PuTTY or KiTTY

Display Note "Portable Kitty version not supported".

And we are good to go.

Thanks!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Simba wrote:

Next step would be to rename PuTTY instances to "SSH client" (i believe in future there might arise new , even better alternatives).
It's still not generic enough to support any SSH client fully. It relies on registry keys format of PuTTY and its clones. But you can at least pass username, password and hostname to any SSH client that is able to accept them on command line (patterns !U, !P and !@).

Display Note "Portable Kitty version not supported".
That contradicts your suggestion above, doesn't it? Anyway, even portably KiTTY is partially supported, when you use !U@!@ pattern to pass username and hostname.

Reply with quote

Simba
Donor
Joined:
Posts:
21

Hi, Martin,

Well i doubt somebody will start from scratch. If somebody will decide to build another version, they probably would use putty sources. Same as Mozilla, bunch of Firefox spin-offs.

Problem with passing parameters, there does not seem to be a way to pass custom PORT, keeping in mind that first step securing your server is to change SSH port, makes this method useless.

Of course, it would be the best, if we could pass host, login info, PORT and even directory.

Reply with quote

WhiteTiger
Joined:
Posts:
7
Location:
Germany

What's wrong with my wrapper :P
It does all that... passes "port", "directory" etc^^ Well... passing the directory is a bit hacky as WinSCP has no support for that one.
And even though I'm using my wrapper and I'm kind of happy with it, a native solution within WinSCP is preferred... (and faster/better directory change on KiTTY's part)
The worst thing about my wrapper is (besides the fact I haven't completed it) that it still has to read from registry and clean it afterwards... it leaves no tracks but still shouldn't be considered "portable"

Reply with quote

Advertisement

madburg
Joined:
Posts:
1

WhiteTiger wrote:

It's done in AutoIt and actually OpenSource... so I'll handle it out on request (and it's ugly as there's a lot of comments, unused crap and that like... As I said, not finished)
@WhiteTiger, would you be so kind and share the AutoIT code block(s) that re-write the process commandline, so no one can view the original process commandline (which contains the USR/PWD) in taskmgr.

Much appreciated.

Reply with quote

WhiteTiger
Joined:
Posts:
7
Location:
Germany

This is no cleaned up version... as it's the code I've used and tested with
It's part of my local __ProcessX.au3 I use for different kind of things...

;~    https://www.autoitscript.com/forum/topic/88214-_winapi_getcommandlinefrompid-from-any-process/
;~ Func _WinAPI_GetCommandLineFromPID($iPID)
;~ If $iDELETE = replace CommandLine with "*" so no one can read it again (ProgramPath isn't replaced)
;~ If $iDELETE > 1 = even replace the ProgramPath
Func _ProcessGetCommandLine($iPID = @AutoItPID, $iDELETE = 0)
   Local $dwDesiredAccess = 0x0410; 0x0410 = PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)         0x0438 = && PROCESS_VM_OPERATION (0x0008) | PROCESS_VM_WRITE (0x0020)
   If $iDELETE Then
      $iDELETE = Int($iDELETE + 0);
      $dwDesiredAccess += 0x0028;
   EndIf
   Local $aCall = DllCall('Kernel32.dll', 'HANDLE', 'OpenProcess', _
         'DWORD', $dwDesiredAccess, _
         'BOOL', 0, _
         'DWORD', $iPID)
   If @error Or Not $aCall[0] Then
      Return SetError(1, 0, '')
   EndIf
   Local $hProcess = $aCall[0]
   Local $tPROCESS_BASIC_INFORMATION = DllStructCreate('dword_ptr ExitStatus;' & _
         'ptr PebBaseAddress;' & _
         'dword_ptr AffinityMask;' & _
         'dword_ptr BasePriority;' & _
         'dword_ptr UniqueProcessId;' & _
         'dword_ptr InheritedFromUniqueProcessId')
   $aCall = DllCall('ntdll.dll', 'int', 'NtQueryInformationProcess', _
         'handle', $hProcess, _
         'dword', 0, _ ; ProcessBasicInformation
         'ptr', DllStructGetPtr($tPROCESS_BASIC_INFORMATION), _
         'dword', DllStructGetSize($tPROCESS_BASIC_INFORMATION), _
         'dword*', 0)
   If @error Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(2, 0, '')
   EndIf
   Local $tPEB = DllStructCreate('byte InheritedAddressSpace;' & _
         'byte ReadImageFileExecOptions;' & _
         'byte BeingDebugged;' & _
         'byte Spare;' & _
         'ptr Mutant;' & _
         'ptr ImageBaseAddress;' & _
         'ptr LoaderData;' & _
         'ptr ProcessParameters;' & _
         'ptr SubSystemData;' & _
         'ptr ProcessHeap;' & _
         'ptr FastPebLock;' & _
         'ptr FastPebLockRoutine;' & _
         'ptr FastPebUnlockRoutine;' & _
         'dword EnvironmentUpdateCount;' & _
         'ptr KernelCallbackTable;' & _
         'ptr EventLogSection;' & _
         'ptr EventLog;' & _
         'ptr FreeList;' & _
         'dword TlsExpansionCounter;' & _
         'ptr TlsBitmap;' & _
         'dword TlsBitmapBits[2];' & _
         'ptr ReadOnlySharedMemoryBase;' & _
         'ptr ReadOnlySharedMemoryHeap;' & _
         'ptr ReadOnlyStaticServerData;' & _
         'ptr AnsiCodePageData;' & _
         'ptr OemCodePageData;' & _
         'ptr UnicodeCaseTableData;' & _
         'dword NumberOfProcessors;' & _
         'dword NtGlobalFlag;' & _
         'ubyte Spare2[4];' & _
         'int64 CriticalSectionTimeout;' & _
         'dword HeapSegmentReserve;' & _
         'dword HeapSegmentCommit;' & _
         'dword HeapDeCommitTotalFreeThreshold;' & _
         'dword HeapDeCommitFreeBlockThreshold;' & _
         'dword NumberOfHeaps;' & _
         'dword MaximumNumberOfHeaps;' & _
         'ptr ProcessHeaps;' & _
         'ptr GdiSharedHandleTable;' & _
         'ptr ProcessStarterHelper;' & _
         'ptr GdiDCAttributeList;' & _
         'ptr LoaderLock;' & _
         'dword OSMajorVersion;' & _
         'dword OSMinorVersion;' & _
         'dword OSBuildNumber;' & _
         'dword OSPlatformId;' & _
         'dword ImageSubSystem;' & _
         'dword ImageSubSystemMajorVersion;' & _
         'dword ImageSubSystemMinorVersion;' & _
         'dword GdiHandleBuffer[34];' & _
         'dword PostProcessInitRoutine;' & _
         'dword TlsExpansionBitmap;' & _
         'byte TlsExpansionBitmapBits[128];' & _
         'dword SessionId')
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPROCESS_BASIC_INFORMATION, 'PebBaseAddress'), _
         'ptr', DllStructGetPtr($tPEB), _
         'dword', DllStructGetSize($tPEB), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(3, 0, '')
   EndIf
   Local $tPROCESS_PARAMETERS = DllStructCreate('dword AllocationSize;' & _
         'dword ActualSize;' & _
         'dword Flags;' & _
         'dword Unknown1;' & _
         'word LengthUnknown2;' & _
         'word MaxLengthUnknown2;' & _
         'ptr Unknown2;' & _
         'handle InputHandle;' & _
         'handle OutputHandle;' & _
         'handle ErrorHandle;' & _
         'word LengthCurrentDirectory;' & _
         'word MaxLengthCurrentDirectory;' & _
         'ptr CurrentDirectory;' & _
         'handle CurrentDirectoryHandle;' & _
         'word LengthSearchPaths;' & _
         'word MaxLengthSearchPaths;' & _
         'ptr SearchPaths;' & _
         'word LengthApplicationName;' & _
         'word MaxLengthApplicationName;' & _
         'ptr ApplicationName;' & _
         'word LengthCommandLine;' & _
         'word MaxLengthCommandLine;' & _
         'ptr CommandLine;' & _
         'ptr EnvironmentBlock;' & _
         'dword Unknown[9];' & _
         'word LengthUnknown3;' & _
         'word MaxLengthUnknown3;' & _
         'ptr Unknown3;' & _
         'word LengthUnknown4;' & _
         'word MaxLengthUnknown4;' & _
         'ptr Unknown4;' & _
         'word LengthUnknown5;' & _
         'word MaxLengthUnknown5;' & _
         'ptr Unknown5;')
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPEB, 'ProcessParameters'), _
         'ptr', DllStructGetPtr($tPROCESS_PARAMETERS), _
         'dword', DllStructGetSize($tPROCESS_PARAMETERS), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(4, 0, '')
   EndIf
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPROCESS_PARAMETERS, 'CommandLine'), _
         'wstr', '', _
         'dword', DllStructGetData($tPROCESS_PARAMETERS, 'MaxLengthCommandLine'), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(5, 0, '')
   EndIf
   If $iDELETE Then
      Local $tmp = '';
      Local $tmp_len = DllStructGetData($tPROCESS_PARAMETERS, 'LengthCommandLine');
      Local $tmp_slen = ($tmp_len / 2)
      Local $tmp_nlen = 0;
      Local $pos = 0;
      If $iDELETE == 1 Then
         $pos = StringInStr($aCall[3], ' ');
         If $pos <> 0 Then
            Local $pos2 = StringInStr($aCall[3], '"');
            If $pos2 == 0 Or $pos < $pos2 Then
               $tmp = StringLeft($aCall[3], $pos);
            Else
               $pos2 = StringInStr($aCall[3], '"', 0, 2);
               $pos = StringInStr($aCall[3], ' ', 0, 1, $pos2);
               If $pos <> 0 Then
                  $tmp = StringLeft($aCall[3], $pos);
               Else
                  $pos = $tmp_slen;
               EndIf
            EndIf
         Else
            $pos = $tmp_slen;
         EndIf
      EndIf
;~       $tmp &= '/TUStart /pid:532';
      For $i = $pos To $tmp_slen
         $tmp &= '*';
      Next
      _WinAPI_WriteProcessMemory($hProcess, DllStructGetData($tPROCESS_PARAMETERS, 'CommandLine'), $tmp, $tmp_len, $tmp_nlen, 'wstr');
      If $tmp_nlen <> $tmp_len Then
;~          ConsoleWrite('WriteError!' & @LF);
         DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
         Return SetError(0, 6, $aCall[3])
      EndIf
   EndIf
   DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
   Return $aCall[3]
EndFunc   ;==>_ProcessGetCommandLine

Reply with quote

Advertisement

You can post new topics in this forum