0

I have a web application that contains a command to start an EXE

Process.Start("MyApp.exe")

This app will then run putty.exe and will SendKeys to emulate keystrokes to the application.

The app works fine if I start under my username, or even if I run using runas /user:anyother_user.

The problem is, when MyApp.exe starts putty.exe (which is what should happen when someone opens a certain web page), I can see that the app is started, and a process is created for both MyApp.EXE and putty.exe. However, nothing seems to be visible to me or any user. Mainly because the application is started under NT AUTHORITY\NETWORK SERVICE. I can tell that none of the keystrokes that MyApp is sending, are reaching putty.

I suspect that it is due to putty launching a dialog box for the first time it runs under a user (prompting to establish secure connection, etc..).

My questions are:

  1. Can I somehow tell putty to avoid these dialog boxes?
  2. Can I tell ntauthority\networkservice to dismiss the dialogbox raised by putty?
  3. Can I view the putty window launched by network service? so that I may dismiss it myself and then it will no longer appear again?
  4. Can I run putty as any other user (without having to store any passwords, for security reasons)?

Any answer to these questions will help me achieve my goal.

Slipeer
  • 3,295
  • 2
  • 21
  • 33
Ahmad Al-Mutawa
  • 127
  • 1
  • 2
  • 11
  • 2
    Can I ask what your use-case is? This sounds like something that would be better served by e.g. https://github.com/sshnet/SSH.NET rather than trying to pupetteer putty – frymaster Feb 06 '17 at 11:34
  • @frymaster I am trying to send a sequence of commands to a remote server to stop and start a certain service. Putty is used because it supports SSH. Is there a .NET library reference I can add to my project so that I can do the commands from within the web application? – Ahmad Al-Mutawa Feb 06 '17 at 11:43
  • @frymaster I looked at the link you proposed, I don't know how can I make use of any of the files up there. I was expecting to find a COM library or a class file that will allow me to create SSH connections. I am a newbie. – Ahmad Al-Mutawa Feb 06 '17 at 11:44

1 Answers1

1

The box dialog seems to be the acceptation of the hostkey of the remote server. Putty asks to confirm the hostkey to store this key in the registry of the user who wants to connect to him. If you want to bypass this dialog, you can force the use of a specified hostkey with the -hostkey option.

Moreover, you can explain to putty to use a serie of commands stored in a text file with the -m option.

All these options are explained here : putty

Sorcha
  • 1,325
  • 8
  • 11
  • Thanks for the tip about `-m` I will read more about it. But I could not find information about `-hostfile`. Are you sure about that? – Ahmad Al-Mutawa Feb 07 '17 at 05:33
  • -hostkey not hosfile :`3.8.3.20 -hostkey: manually specify an expected host key This option overrides PuTTY's normal SSH host key caching policy by telling it exactly what host key to expect, which can be useful if the normal automatic host key store in the Registry is unavailable. The argument to this option should be either a host key fingerprint, or an SSH-2 public key blob. See section 4.19.3 for more information. You can specify this option more than once if you want to configure more than one key to be accepted. ` – Sorcha Feb 07 '17 at 06:54
  • I tried running `putty -hostkey` but got a message: `Unknown option -hostkey` – Ahmad Al-Mutawa Feb 07 '17 at 07:16
  • You must use the 0.67 version. This option is not in the 0.62 version for example. – Sorcha Feb 07 '17 at 08:56