How to Write Your Own Remote Access Tools in C# by Paul Chin

How to Write Your Own Remote Access Tools in C# by Paul Chin

Author:Paul Chin [Chin, Paul]
Language: eng
Format: mobi
Published: 2011-03-16T16:00:00+00:00


Take note that the CreateNoWindow is set to true so that the DOS window will not pop-up when the program runs. Also, the StandardIn, StandardOut and StandardError streams are all redirected. What this means is that, the keyboard is no longer the StandardIn stream and the monitor is no longer the StandardOutput and StandardError stream. Also, once the streams have been redirected, three pipes are created for the cmd.exe process as shown in Fig 9a in the previous chapter. The figure is reproduced here again for clarity, re-labelled as Fig 10a:

Read

| |

| | [StandardOut] | |

Read cmd.exe Write

| | Write

| | [StandardIn] | |

| | | | [StandardError]

Write | |

Read

Fig 10a - Linking three pipes to the cmd.exe process Once we have these pipes, it is trivial for any other process to read from or write to them. Hence, the name Inter Process Communication (IPC). Network streams can read from or write to them as well. This is what makes it possible for shells to talk to remote PC’s through network sockets.

The next line brings us to the main loop of the Server, the perpetual while loop. Unless there is an exception, the program control will perpetually try to read from the network stream, which was created when the Server connected to the Client. The streamReader.Readline() method reads the data (commands) sent by the Client. If the command is “terminate”, the program will call the StopServer() method to kill the Server. The streams and sockets are closed and the Server program exits. On the other hand, if the Client sends the “exit” command, the program will deliberately throw an ArgumentException() so that the catch-block will Cleanup() the streams, sockets and break out of the while loop to return control to the for(;;) loop in the Form_Shown Event Handler. On the other hand, if the Client sends commands other then “terminate” or “exit”, program flow will proceed to inject the command into the StandardIn pipe of the cmd.exe process, by using the

processCmd.Standard.WriteLine() method:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.