Click here to Skip to main content
Click here to Skip to main content

RECEME - Remote Command Execution through eMail Exchange

By , 14 Apr 2013
 

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:

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 :)

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_ICommandDll_ToBeDeployed>"
$CMD command=process,options="<ProcessNameStartPattern>"
$CMD command=screenshot,options=<DONT_CARE>
$CMD command=ping,options="ipaddress"
$CMD command=runprocess,options="ping -n 10 blrk86cd"
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 :)

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)

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionClient machine Requisitesmemberkiquenet.com18 Apr '13 - 22:19 
A question, client machine requires install this?:

Exchange Web Services Managed API 1.2 ?

Office SDK ??
kiquenet.com

GeneralMy vote of 5memberPrasad Khandekar16 Apr '13 - 9:29 
Very Interesting.
GeneralRe: My vote of 5membertumbledDown2earth16 Apr '13 - 18:49 
thanks ... please recommend to people requiring similar communications
 
... and let me know if any support is required
GeneralMy vote of 4memberkiquenet.com15 Apr '13 - 20:36 
Required updates for Twitter and more. Interesting. It would better in future if will be updates.
QuestionTwitter communication? [modified]memberkiquenet.com15 Apr '13 - 3:59 
Great idea, similar like Ifttt.com
 
I would like execute like Service or like Console App for debugging issues.
 
It would be interesting "delay" for commands (execute command with delay).
 
Any updates about SocialNetworkingClients like Twitter (and in future FAcebook , Linkedin, etc ??)
 
Where is the assemblies:
 
Yedda.Twitter
http://devblog.yedda.com/index.php/2007/05/16/twitter-c-library/
 
Microsoft.Exchange.WebServices
http://www.microsoft.com/en-us/download/details.aspx?id=28952
 
Interop.Microsoft.Office.Core (Office SDK)
 

Which is the prerrequisites? Windows 7, VS 2012, ...etc... ?
 

Any updates soon, please?
kiquenet.com


modified 16 Apr '13 - 2:36.

AnswerRe: Twitter communication?membertumbledDown2earth15 Apr '13 - 20:55 
You can find the assemblies here:
http://devblog.yedda.com/index.php/2007/05/16/twitter-c-library/
http://www.microsoft.com/en-us/download/details.aspx?id=28952
Office SDK
 
Prereq:
Windows XP
VS 2010
GeneralRe: Twitter communication? [modified]memberkiquenet.com15 Apr '13 - 22:19 
Thanks, it would great that you update your article with this information about dependencies assemblies and prerrequisites.
 

Prereq:
XP
VS 2010
 

Thanks
kiquenet.com


modified 19 Apr '13 - 3:45.

QuestionHave you thought of.....memberMember 405342414 Apr '13 - 12:18 
Using XMPP as the communication medium?
 
I have built some simple clients using this method, and it also allows for easy implementation of bi-directional communication, plus you can use the jabber server for authentication and authorisation levels.
 
But I look forward to delving in to your implementation.
AnswerRe: Have you thought of.....memberkiquenet.com15 Apr '13 - 3:55 
any full source code sample about it?
kiquenet.com

QuestionAPP Crashingmemberilyhel4 Apr '13 - 6:40 
I run the application with win7 PRO 32 bits its seems there are a probleme with .NET Version;
REMEMEAPP crash after few seconds, i need the requirments to run app. thx
AnswerRe: APP CrashingmembertumbledDown2earth7 Apr '13 - 16:55 
Hey. Thanks for your post.
 
Ive tried and it does not crash for me ... Can you please share the staktrace ... Also please use the latest source code
GeneralMy vote of 5memberGregoryW27 Jan '13 - 19:38 
Great idea, i don't have time to check this code out, but i will keep this concept in my mind Wink | ;)
GeneralRe: My vote of 5membertumbledDown2earth7 Apr '13 - 16:53 
Thanks for your comments. Yeah .. the concept works for me even today in varied situations. I am glad many find it useful too
GeneralSource Code Uploadedmemberarnab_pal7 Apr '11 - 5:29 
Here[^]
GeneralCould you possible provide the source code for RECEME.exe pleasememberAmir_Hasan5 Apr '11 - 5:12 
your zip file does not contain the source code for RECEME.exe. Please provide
GeneralRe: Could you possible provide the source code for RECEME.exe pleasememberarnab_pal7 Apr '11 - 5:28 
Source code is provided as-is:
https://sites.google.com/site/tumbleddowntoearth/home/downloads/RECEME_app.zip[^]
GeneralExchangememberMichal Rafaj7 Feb '11 - 19:27 
How does conenction to exchange work? Not working for me..
Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException was unhandled
GeneralRe: Exchangememberarnab_pal15 Feb '11 - 18:32 
You have to have a folder called "RECEME" in your "inbox" under "Personal Folders" .... sorry it is hardcoded as of now... would be taken care in the next version :P sometime in future... also sorry for the late reply (keep busy lately) -A
GeneralRECEME finds a review @ elifemagz.commemberarnab_pal15 Nov '10 - 18:56 
http://www.elifemagz.com/application-software/programming/receme-remote-command-execution-through-email-exchange/[^]
NewsGood news for RECEME Usersmemberarnab_pal15 Nov '10 - 18:31 
Source: http://www.bbc.co.uk/news/technology-11760050[^]
"Email remains one of the most popular means of communication". RECEME integrates smoothly with emails and there is a chance a lot can be achived by using email... My sole intension to use emails as basci communication clients in the beginning, was to use its implicity features, like security....
GeneralMy vote of 5memberhs_10026 Oct '10 - 19:47 
excellent concept.
you should also develop a template for creating commands and sending off an email without using the email client
GeneralMy vote of 5memberjoye-jol30 Sep '10 - 6:17 
nice neu toy
GeneralMy vote of 5memberSrikanth 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 5memberarnab_pal29 Sep '10 - 17:28 
Thanks for your vote Srikanth.
 
Let me tell you that from behind the firewall (like in corporate scenario), please use the outlook client. The corporate firewalls painfully make us aware, that we are in the age of "security" Smile | :)
 
So, from the service computer you have to connect to a communication-client which is accessable.
 
For example you start RECEME from your office computer on the OutlookClient.
Then you go home and send a command from your home (say from gmail) to your office email.
This gets delivered to your outlook and the command gets processed.
 
Thus, you could get services from office computer (behind some proxy - without actually talking to the proxy or without even connecting to your office computer).
 
Hope it is clear to you now Smile | :)
GeneralMy vote of 5memberSrikanth Nellore29 Sep '10 - 17:13 
Nice work Arnab
GeneralMy vote of 5memberAgnit29 Sep '10 - 1:46 
A real nice new concept. No firewall hassles
GeneralMy vote of 5memberKun Yu28 Sep '10 - 20:33 
nice concept
GeneralVery very cool.memberBritto28 Sep '10 - 17:27 
Nice article and it works very well.
Britto Raj

GeneralMy vote of 5memberRichard Osafo28 Sep '10 - 0:21 
Working on a similar idea. Nice to see it in action.
GeneralMy vote of 5memberomraviprakash27 Sep '10 - 22:35 
Good concept. Keep the application richness increase.
GeneralMy vote of 5memberjulio-thomas25 Sep '10 - 21:10 
cool. we need your scheduler asap. and a client for connectionless clusters
GeneralMy vote of 5memberasp_goal25 Sep '10 - 1:03 
worx f9. do more
GeneralMy vote of 5memberjose_jean25 Sep '10 - 0:05 
works as expected with gmail/outlook. Great Smile | :)
GeneralMy vote of 5memberMember 235878223 Sep '10 - 22:47 
Super idea
QuestionI got an exception in AbstractMailClient.ProcessCommand()memberbull7823 Sep '10 - 21:50 
I think your project is really interesting!
I'm a c++ developer but I'm a newbie in C# world. Probably I do something wrong but I started your app, I inserted my gmail account data (or Twitter, the same) and then Receme crashes.
 
If I check the logs I found following messages

9/15/2010 9:43:33 AM : Message : RECEME started with client - Commander.CommunicationClient.UserAccount
9/15/2010 9:43:33 AM : Exception : Exception caught in AbstractMailClient.ProcessCommand()
System.ArgumentException: COMMAND=RUNPROCESS OPTIONS=PING;-N_10_BLRK86CD is not a valid Request
at Command.Core.Request.Parse(String message) in E:\myProjects\RECEME_app\Command.Core\Request.cs:line 58
at Command.Core.CommandManager.Inform(String message, IList`1 results) in E:\myProjects\RECEME_app\Command.Core\CommandManager.cs:line 42
at Commander.CommunicationClient.AbstractCommunicationClient.ProcessCommand(String from, String message) in E:\myProjects\RECEME_app\CommunicationClient\CommunicationClient.cs:line 79
9/15/2010 9:43:34 AM : Exception : Exception caught in AbstractMailClient.ProcessCommand()
System.ArgumentException: COMMAND=RUNPROCESS OPTIONS="PING -N 10 BLRK86CD" is not a valid Request
at Command.Core.Request.Parse(String message) in E:\myProjects\RECEME_app\Command.Core\Request.cs:line 58
at Command.Core.CommandManager.Inform(String message, IList`1 results) in E:\myProjects\RECEME_app\Command.Core\CommandManager.cs:line 42
at Commander.CommunicationClient.AbstractCommunicationClient.ProcessCommand(String from, String message) in E:\myProjects\RECEME_app\CommunicationClient\CommunicationClient.cs:line 79
9/15/2010 9:43:35 AM : Message : RECEME stopped successfully

 
where I can see 'wrong' absolute path "E:\myProjects\RECEME_app\".
Can you suggest me a solution?
Thanks
Claudio Tortorelli

AnswerRe: I got an exception in AbstractMailClient.ProcessCommand()memberarnab_pal23 Sep '10 - 22:10 
2 minor issues. I have modified the binaries now. Please check.
Thanks for pointing the error.
 
Please vote Smile | :)
GeneralRe: I got an exception in AbstractMailClient.ProcessCommand()memberbull7823 Sep '10 - 23:19 
Wow it works now! Thank you! I just rated your article with a 5.
Claudio Tortorelli

GeneralMy vote of 5memberdownload only22 Sep '10 - 19:50 
everything just as u thought
Generalnot workingmemberqumar22 Sep '10 - 6:47 
I try to run this application but I am not able to open this. I have Visual Studio.Net 2005 in my system.
Can any one help me regarding this?? or send me a new code for this application
Thankx
anis

GeneralRe: not workingmemberarnab_pal22 Sep '10 - 8:06 
It should open on VS 2008 and later.
GeneralMy vote of 5memberrob tillaart21 Sep '10 - 5:17 
in 1994 I had a very similar application based on my Unix station@work. I was a sysadmin and could work from home - start the backup etc. Smile | :)
GeneralRe: My vote of 5memberarnab_pal21 Sep '10 - 5:21 
Thanks for your vote. I can think how freaking tuf it was in 1994 for unix
GeneralMy vote of 5membersharp prospector21 Sep '10 - 2:31 
I love this application. Our computer services people however, will not be happy about this. Your work is wonderful.
GeneralRe: My vote of 5memberarnab_pal21 Sep '10 - 4:10 
Thanks Smile | :)
 
Even our comp services people was not happy. But once they understood and the security aspects were explained to them, they also accepted the facts and got extremely pleased
GeneralMy vote of 4memberUR-IT20 Sep '10 - 22:51 
Cool app - the it-security staff will love you Wink | ;)
GeneralRe: My vote of 4memberarnab_pal20 Sep '10 - 22:58 
Thanks Smile | :)
 
Just another interesting point for IT-security:
RECEME supports 'lock' and 'unlock' for the sole purpose of security. There was a big buzz and feedback from some IT-security folks I know, while RECEME was discussed locally.
Plus there are several provisions to make it more secure.
 
The sole idea, of discussing this in public is to find more areas of improvement; So please keep your comments flowing
GeneralMy vote of 5memberJudy Green18 Sep '10 - 22:38 
Loved the work... I am already using it. Please lauch a dev-blog to discuss issues and remarks Smile | :) .. Great going...
GeneralRe: My vote of 5memberarnab_pal20 Sep '10 - 23:02 
Thanks Judy Smile | :)
 
For now I think we can discuss all we want right here in code project.
If RECEME finds more users and all of us really need a different blog, I will start one (probably in blogspot)
 
Till then read my other blogs Smile | :)
GeneralMy vote of 5memberAshim Pal18 Sep '10 - 22:18 
excellent!!!
QuestionWhat's that?memberAjay Vijayvargiya12 Sep '10 - 8:11 
I fail to understand what are you trying to explain in this article? D'Oh! | :doh:
 
Cannot be accepted as well written article.

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 14 Apr 2013
Article Copyright 2010 by tumbledDown2earth
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid