Reading PuTTY output with c# - c#

What i want: I want to read the Output of the PuttY Window with C#
What I've got: Our company has several hundreds of servers with at least 2-3 technical users (which are running applications). We got a database of all the users and passwords. So it's basically search, copy and paste to login.
What i want to do: Write a piece of software that does this automatically.
How far i am: Wrote a tool, that reads the logfile of a single PuTTY instance and looks for the password prompt. Determinates target user and server (based on current server and su - [username]). Retrieves the password and sends it via PostMessage to a selected PuTTY.
The Problem or what i want to change:
I want to be able to read the PuTTY output directly from the PuTTY window, because the logfile is kind of unreliable (TAB, ESCAPE, etc which scrambles the output).
I have used UISpy and other tools to get a control, but no luck.
I don't want to use a keylogger mechanism or something like that.
Maybe a hook or something, but have never done that before.
Additonal Info:
Connection is made over a JumpServer, only ssh connections from there to the target servers are allowed.
Direct login with the tech. user is disabled.
The PuTTY window is already opened and used to work on the server.
Writing a whole new Connection Manager is no option. Coworkers are familar with PuTTY and this solution should be some sort of standalone background worker.
Additonal Info 2:
The goal is to write a strict 3rd party software. Not to use other SSH libs, modify PuTTY source or other approaches. The question is: how to read text from the PuTTY window, beside the logfiles.

I don't know why this hasn't been suggested yet, but plink (which is part of the PuTTY suite) is the command-line version of PuTTY, you'll just need to redirect stdin and stdout to get a relatively powerful (as in features, you'll still need to interpret telnet stuff yourself) SSH client.

Have you considered using OCR?
Sketch of solution would be:
1 - Agent runs waiting to notice a Putty Window (either register a callback with OS for new processes or periodically check the list of running processes)
2 - When a putty is noticed, agent takes screenshot and extracts portion of screen occupied by putty. You would need to extract window location, but can be done via OS calls assuming you have a handle from step 1
3 - Pump this image data into tesseract or something, and get text output back. check to see if the password prompt is there
4 - If prompt is there, it sounds like you had the rest done after this (send info needed via PostMessage)

You should take a look at This Link (Putty StdIn / StdOut. Shows how to open putty from a c# app and how to handle Standard In, Out and Error Output to communicate with your putty instance.

If you are using putty as an SSH tool, use http://www.routrek.co.jp/en/product/varaterm/granados.html C# SSH library
If you are using putty as a serial tool use the inbuilt IO classes
Telnet also has C# libraries, none that I can give any knowledgabel input into what is good.

If you can purpose a modified version of putty, you should modify putty sources and including some pipes (or socket) that communicates with your c# application. Like that, your coworker keep the same software.

Related

Send command from PC application to Jailbroken iphone

I am making an simple application on PC by C# to send command to jailbroken iphone (exp: open app, get list application installed on iphone..e.t.c..) but I do not know how to send to iphone, searching google but can not find a thing to do this. Anyone know how to send command to iphone please point me out or some documents to learn about this.
Thank you.
in my opinion the best way to go is using SSH, here's the steps
On the Jailbroken device (Skip this steps if you already have an ssh server installed and running)
Download the SSH server from Cydia
Take note of your device's IP address
Default username: root and password: alpine Remember to change that!, also i would recommend creating another user for your app
In your application
Download and install the SSH.NET library from NuGET here
Implement your appropriate methods to connect,disconnect and send commands, se those examples:
using (var client = new SshClient("phoneIp", "phoneUsername", "phonePassword")) {
client.Connect();
//Open the Facebook app and show your profile
client.RunCommand("open fb://profile");
//Alternative method using `uiopen`
client.RunCommand("uiopen fb://profile");
//Read device network info (install network-cmds first)
Console.WriteLine(client.RunCommand("ifconfig"));
//List all apps installed via Cydia
Console.WriteLine(client.RunCommand("dpkg –list"));
//List all apps that are installed from iTunes/Appstore
Console.WriteLine(client.RunCommand("cat /private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"));
client.Disconnect();
}
I haven't tested this code of course, and I have no Jailbroken iOS device, but this should put you on the right path at least!
First you have to create a daemon on your jailbroken iDevice. It will contain a TCP server, which accepts connections from your PC and translates them into your commands. After that commands will be executed by your daemon and you have to write code to process each type of command.
Another one easy solution would be to use Cycript in conjunction with SSH.
If Cycript is installed on the jailbroken phone and a SSH server is running, you could write some scripts and upload it to the phone.
By running them, it would output relevant informations to the standard output.
You would still have to do some very basic reversing stuff to know what you want to to display (i.e. asking the right SpringBoard controller to have the desired information)

c++/c# app to connect to linux server

I am planning to do an App either in c++/C# (through Visual Studio) in Windows 7.
OK what this app does is it will accept input through studio elements like text box or buttons ..then it should create an command based on input and run these command on the Linux server.
E.g : One simple example is to restart a certain process on a Linux machine
Now to proceed to my problem:
How do I connect my App to Linux machine?
I don't want to install any third party application as i am not allowed to do so.
If possible please list me the different ways i can do this
Well, you can do this. I am already familiar with this scenario. I have several application setup working this way. The only option that will allow you to do this without any 3rd party application is using SSH protocol.
The SSH protocol is the well known and most power full tool of linux sysadmins. You can execute any command over it on a linux box from any part of the world or any piece of shit which can run an SSH client. Ask me on comment if you need more info on this.
EDIT
One example, if you want to restart certain process.. You can pass the command over SSH as below.
ssh user#server_ip '/etc/init.d/httpd restart"
The above will restart the HTTPD(Apache) service.
Some libraries you can use in .NET
http://www.codeproject.com/Articles/11966/sharpSsh-A-Secure-Shell-SSH-library-for-NET
https://sshnet.codeplex.com/
I have not used above libraries in .Net, Instead I have done several things using linux box with python and bash.
if I understand correctly, to solve this you can implemente WebService.
But when you said :
I dont want to install any third party application as i am not allowed
to do so
I'm afraid you can not setup WebService on Linux server ?
Other possibility, use SSH if already install on linux server (some chance that is) and you probably could find a .Net lib to make SSH
This link will help .Net class to execute remotely on Linux over SSH?

Passing commands to a running process

After looking for a couple of hours, I decided it's time to ask for some help.
I have a local server of an online game, which has its own command line where the admin can execute different commands, like /kickuid x (which kicks the user with the useruid = x) and many other commands. Here's a screenshot of how it looks like:
I am interested in automatically executed commands, but the problem is that I have no idea of how I could pass a command to the game service through cmd.
I would be very grateful if somebody knows how to(assuming that it's possible) send commands to a running process through cmd or maybe in another way.
No, there is no generic mechanism to "send commands from outside the program".
Possible approaches to look at:
sending keystrokes is one ultimate fallback to automating programs with any UI
some programs expose COM automation interfaces (like Office/IE), or even COM remoting.
some program expose REST remote management API (usually if the rest of program uses some form of HTTP server)
some read configuration/other files
some have custom API to execute commands remotely (i.e. most DB servers)

Can I listen to a command prompt?

I want to be able to access the command prompt from a web browser. It doesn't sound like a possible thing?
So my options:
In the browser do a server request and that platform (.NET/IIS?) can
talk to a command prompt (Can it be done?)
Write an app that can listen to a command prompt and its I/O
Let me know if I'm talking crazy. If not, any info would be appreciated!
You can call Process.Start() in C# and set Redirect* to true in the ProcessStartInfo.
You can then read and write to/from the standard in/out streams of the process you create.

.Net class to execute remotely on Linux over SSH?

I'm not sure where to get started with simply executing a remote script and returning the output to a web form. In this case we have an application server that executes some 3rd party tools. We'd like to write an interface for our power users that allow them to check the status of various processes and also execute some of the 3rd party admin tools that support has available. The issue is that we only connect to this Linux (RedHat) machine via Putty over SSH. I looked into PsExec but it doesn't seem to handle SSH. I'd like to avoid any large security holes, if possible, but this is intended to be a limited number of users in a closed network.
Thanks for any assistance getting started!
There are several options to do SSH in .NET - although you need a library for that since nothing is built-in:
http://www.codeproject.com/KB/IP/sharpssh.aspx
http://www.rebex.net/ssh-shell.net/ (commercial)
https://www.eldos.com/sbb/net-ssh.php (commercial)
http://sshnet.codeplex.com/
http://granados.sourceforge.net/

Categories