Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / C#

RECEME - Remote Command Execution through eMail Exchange

Rate me:
Please Sign up or sign in to vote.
4.87/5 (62 votes)
6 Jun 2013CPOL7 min read 121.5K   2.6K   68   67
A service concept is implemented here for seamless and connectionless computation from anywhere to anywhere.

1. Introduction

REmote Command Execution through eMail Exchange, or RECEME, successfully attempts to solve the problem of remote code execution. The proposed solution executes any .NET runnable code on a computer (where the service application is up and running) in the form of an 'ICommand'.

The commands can be fired from any other location by sending an email/twit/(or any other mode in principle, e.g., SMS/phone/etc.) to the connected communication client (email-box in the current implementation).

2. Background

There are several pains in automation areas in traditional communication systems. VPN etc., are not everybody's cup of tea. Also, connection oriented communication services are not accessible from behind certain firewall settings.

Let's discuss a practical problem:

Problem: Our team mate had to be in office till 12 every night to start a process and check its execution and results (build completion) and then go home. The problem was he would only have to start the build when a certain management decision triggered him to do so. Generally, he gets a mail just before 12AM from some other country where it is still daylight to start a build. And this does not happen everyday so he cannot start an automated scheduled build every day at 12 midnight. The mails are conversation like and have no specific format so that he could not set an Outlook rule for it. And even if he did, he had no response being sent to his home. Even if that happened and something failed, he would have no way to start the build again.

Sad story: His peace of mind was off, he was late for office every morning.

Answer: He can now peacefully use "RECEME" and control the huge build servers from the comfort of his home, may be while he is half awake.

I list here a few pre-requisites to understand the basic concepts behind this service, and to develop custom commands for your usage scenarios:

  1. C# .NET (may be 2.0; ideally 3.0)
  2. Basic concept of interface and abstraction
  3. Some idea on Reflection
  4. Knowledge of C#, Web Services, Reflection, and connectivity to public free-email services like GMail/Twitter/Hotmail/Outlook/Exchange/etc.

3. How does RECEME work

receme/image1.gif

The RECEME service application can be started on a system and connected to a desired CommunicationClient. Presently, the supported communication clients are:

  1. Emails - GMail / Hotmail / Outlook / Exchange (for corporate emails)
  2. Social Networking - Twitter
  3. Future - SMS / BluFi / Phone / Basically any communication medium

Once the service is running, you can communicate with your system (where RECEME is running) just by sending an email/twit/SMS from any medium. The communication mode is through the RECEME application running on systemXYZ. The basic architecture of how it works is explained in the image above. The communication works in a simple request-response way. For example, you send a request email and the RECEME service sends you back a response email.

The RECEME service and you can be connected to separate communication clients and still work successfully.

Also, there is an advantage of deploying custom commands while still being on a remote location. In this case, you can create a command in a DLL and send the DLL with the "deploy" command. RECEME installs this new command, and then you can send this new command to get serviced.

The built-in commands and how you can create custom commands are explained below. In principle, it is possible to run any code on the same computer. Also, any communication client can be used by implementing AbstractCommunicationClient.

A more generalized scenario supported by RECEME is:

receme/image2.gif

4. Using the code

Things to do to make it work:

4.1. Developing custom Commands using the ICommand interface

Implement the ICommand Interface:

C#
public interface ICommand 
{
    string Run(string options);
}

An implemented ICommand interface class built into a DLL can be dropped in the <Environment.CurrentDirectory>\Commands directory.

Important point to note: Sample implementations are available in the attached zip file. Also, in the same folder, you will find Command.Core.dll, which contains the ICommand interface. You need to add this DLL as a reference to your project before starting to develop any custom command (ICommand) for your use. In case of any issues, please do not hesitate to bug me (contact information at the end of this article).

Once this is done, start RECEMEapp.exe. The RECEME service is thus started and connected to the email service.

After this, send an email from anywhere in the world to the connected email box and get response in a few minutes from the RECEME service. It is also connected to Twitter, and it is also logically possible to extend this concept to be connected to SMS/VoiceTelephony, etc.

Once the service is up, expect to communicate with the started service from anywhere in the world at anytime.

If all is fine, you get replies to your local mail box from the RECEME service every time you request it, with a command Smile | :)

receme/screenshot.GIF

4.2. What could be achieved...

Technically, the proposed solution (also the attached implementation) successfully attempts to solve the problem of remote code execution:

  1. Without the need to establish direct/indirect connection between two systems
  2. Physically and network-wise independent, but still controls a remote process
  3. 2-way communication (send a command and get back a response)
  4. Immensely attractive and easy
  5. Needs no additional overhead of cost, time, resource, effort
  6. Just one line of configuration to manage (actually, four basic words)

More practically, let us assume a scenario, when I am at office and I want to check what's going on in my home computer. What do I do?

I just send an email to my GMail/Hotmail/etc. from any mail client I currently have access to, from anywhere in the world... and within a matter of a couple of minutes (may be less), I get a response back to my mail showing me the current screenshot of my home desktop or the current processes running and how much process or memory they consume, or are they hung (may be I also want to kill the hung process).

Now, let's re-visit the points above:

  1. I did not have to establish any connection with my home computer
  2. Both my current computer and home computer were still independent of each other
  3. I sent a command and got back a response
  4. Was easy
  5. At no additional cost
  6. The one line configured service was already running on my home computer

Some part of the above problems can be solved with a lot of intermixing of existing technologies and plug and play development components.

More details can be found in the document available for download (use link at the beginning of the article).

4.3. Sample commands already available

Binaries and sample commands (with source code of how to implement commands) are also available for download (use link at the beginning of the article).

In principle, anything possible in the world of programming is possible to be made into a command, just by implementing the ICommand interface. Some basic commands are available with the following explanations.

User commands
$CMD command=notepad,options="<FilePathToOpen>"
$CMD command=iexplore,options="<LinkToOpen>"
$CMD command=deploy,options="<WebLink_Of_ICommandDll_ToBeDownloadedAndDeployed>"
$CMD command=process,options="notepad.exe"
$CMD command=screenshot,options=<DONT_CARE>
$CMD command=ping,options="192.168.1.2"
$CMD command=runprocess,options="ping -n 10 mymachineOrIP"
Admin commands
$CMD command=lock,options="<lockoptions>",key"<SecretKey>" 
$CMD command=unlock,options="<unlockoptions>",key="<Secretkey>"
Sample response

receme/IMG_0272.JPG

5. Points to note

For currently implemented communication clients, please write the commands in the subject line of your email. The body of the email is not read, so it does not matter what you write there.

Please use " and not “ for specifying commands.

SendMail of GMail client is known to fail from behind some firewalls or if GMail is blocked by other sources (like filthy corporate policies :P). So please see the logs to understand the issue.

SendMail from all communication clients may throw WebException sporadically. Thus, a retry mechanism was built in to retry to send response from RECEME, for three times. Please check if any firewall is blocking sending mails.

TwitterClient is known not to work since Twitter changed it authorization to 3-legged XAuth. I am working on it...

------------ Thanks to Caludio Tortorelli (in the discussion section of this article) for clarifying these points and helping me find some bugs Smile | :)

6. Applicability

  1. Automation (Public/Personal)
  2. Multisite code execution (something like connectionless-secure grid computing)
  3. Work from remote location
  4. Domestic appliances [working on a USB-switch to start/stop my TV at home while in office]
  5. Need to create a communication client for "bluefi"

7. What's next?

  1. A scheduler module is planned between command identification and execution for deferred command execution.
  2. A pluggable codec module for more security.

Contact

8. History

Past a few months of head banging :P

  • September 23, 2010: A few bugs fixed and certain points clarified.
  • September 17, 2010: Approved by CodeProject community.
  • September 12, 2010: Posted on Codeproject.com
  • March 14, 2010: Discussed and demonstrated in public for the first time.
  • December 2009: Thinking started...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
is a poor software developer and thinker. Presently working on a theory of "complementary perception". It's a work in progress.

Comments and Discussions

 
GeneralMy vote of 5 Pin
GregoryW27-Jan-13 19:38
GregoryW27-Jan-13 19:38 
GeneralRe: My vote of 5 Pin
tumbledDown2earth7-Apr-13 16:53
tumbledDown2earth7-Apr-13 16:53 
GeneralSource Code Uploaded Pin
tumbledDown2earth7-Apr-11 5:29
tumbledDown2earth7-Apr-11 5:29 
GeneralCould you possible provide the source code for RECEME.exe please Pin
Amir_Hasan5-Apr-11 5:12
Amir_Hasan5-Apr-11 5:12 
GeneralRe: Could you possible provide the source code for RECEME.exe please Pin
tumbledDown2earth7-Apr-11 5:28
tumbledDown2earth7-Apr-11 5:28 
GeneralExchange Pin
Michal Rafaj7-Feb-11 19:27
Michal Rafaj7-Feb-11 19:27 
GeneralRe: Exchange Pin
tumbledDown2earth15-Feb-11 18:32
tumbledDown2earth15-Feb-11 18:32 
GeneralRECEME finds a review @ elifemagz.com Pin
tumbledDown2earth15-Nov-10 18:56
tumbledDown2earth15-Nov-10 18:56 
GeneralRe: RECEME finds a review @ elifemagz.com Pin
kiquenet.com12-Jan-18 12:10
professionalkiquenet.com12-Jan-18 12:10 
NewsGood news for RECEME Users Pin
tumbledDown2earth15-Nov-10 18:31
tumbledDown2earth15-Nov-10 18:31 
GeneralMy vote of 5 Pin
hs_10026-Oct-10 19:47
hs_10026-Oct-10 19:47 
GeneralMy vote of 5 Pin
joye-jol30-Sep-10 6:17
joye-jol30-Sep-10 6:17 
GeneralMy vote of 5 Pin
Srikanth Nellore29-Sep-10 17:18
Srikanth Nellore29-Sep-10 17:18 
How will this work if I have to pass on the Proxy authentication credentials. this is the exception i ve got!Exception : Exception caught in FrontEnd while creating client object
System.Net.WebException: The remote name could not be resolved: 'mail.google.com'
at Commander.CommunicationClient.ClientCreator.GetClient(String clientType, UserAccount account, Int32 refreshDelay)
at RECEMEapp.FEWindow.button1_Click(Object sender, RoutedEventArgs e)

No doubt its definetly a great tool, if the service can include proxy authentication too, bcz most of the office boxes wil have proxy credentials!!
AnswerRe: My vote of 5 Pin
tumbledDown2earth29-Sep-10 17:28
tumbledDown2earth29-Sep-10 17:28 
GeneralMy vote of 5 Pin
Srikanth Nellore29-Sep-10 17:13
Srikanth Nellore29-Sep-10 17:13 
GeneralMy vote of 5 Pin
Agnit29-Sep-10 1:46
Agnit29-Sep-10 1:46 
GeneralMy vote of 5 Pin
Kun Yu28-Sep-10 20:33
Kun Yu28-Sep-10 20:33 
GeneralVery very cool. Pin
Britto28-Sep-10 17:27
Britto28-Sep-10 17:27 
GeneralMy vote of 5 Pin
Richard Osafo28-Sep-10 0:21
Richard Osafo28-Sep-10 0:21 
GeneralMy vote of 5 Pin
omraviprakash27-Sep-10 22:35
omraviprakash27-Sep-10 22:35 
GeneralMy vote of 5 Pin
julio-thomas25-Sep-10 21:10
julio-thomas25-Sep-10 21:10 
GeneralMy vote of 5 Pin
asp_goal25-Sep-10 1:03
asp_goal25-Sep-10 1:03 
GeneralMy vote of 5 Pin
jose_jean25-Sep-10 0:05
jose_jean25-Sep-10 0:05 
GeneralMy vote of 5 Pin
Member 235878223-Sep-10 22:47
Member 235878223-Sep-10 22:47 
QuestionI got an exception in AbstractMailClient.ProcessCommand() Pin
Claudio Tortorelli23-Sep-10 21:50
Claudio Tortorelli23-Sep-10 21:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.