Page 1 of 1 1
Topic Options
#52140 - 2000-11-08 10:30 AM Remote Execution Requests....
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia

ok dudes,

There have been times in the past when I have wanted to issue commands to a server or workstation, but couldn't because I was not on the network... so

Here is a system where you can email commands to a computer and it will do them:

What you need:
1: A PC running MS Outlook Express(OE)(you can prob use OutLook or other MS mail product, but I have only tested this on Express)

2: This script running on a (semi)regular basis. Use AT on NT or that scheduler program on win9x.

Setup:
1: Create a folder in OE called RER (or whatever you like, but remember it and change the KiX script to suit)

2: Create a RULE in OE that MOVEs all mail with the SUBJECT "Remote Execution Request" to the aforementioned folder. Again, you can change this, but you must change the KiX script too...


How it works:

The script goes to the registry to get the path to your OE folders. If this doesn't work for you, check your registry and get the correct path.

So far, this only works when someone is logged in, so if you want to use this scriupt for an unattended server, login and lockup...Also, OE must be running.

When a new email comes in, OE puts it in our folder and stores email in clear text (well mine does) and the KiX script uses the FIND command to search the folder for any email with the subject line as defined in the script $subject.

If KiX finds an email with the subject, it then scans that email message for a line starting with :: if this is found, the command is taken from that line and run.

So, if you email that computer a message like this:

From: chrismat@ozemail.com.au
To: chrismat@ozemail.com.au
Subject: Remote Execution Request
Body:

Hello,

Please run these commands for me on \\server
::del c:\temp\*.txt
::net send chrism "all done"

thanks, cj

when the script runs, the two commands will be executed and then the email deleted.

If you delete the OE folder file, it re-creates it when a new message comes in.

Note: You cannot run the script if you are browsing in that folder in OE... as the folder file is locked.

ok, well here is the script...

cj

P.S. any questions?

code:

cls
break on

;
; this program will search for commands from a MS Outlook Express
; mailbox and execute them
;
; The commands must be in an email with a subject line "Remote Execution Request"
; Then each command line must start with ::
;
; An example email:
;
; From: chrismat@ozemail.com.au
; To: chrismat@ozemail.com.au
; Subject: Remote Execution Request
; Body:
;
; Hello,
;
; Please run these commands for me on \\server
;
; ::del c:\temp\*.txt
; ::net send chrism "all done"
;
; thanks, cj
;

; get $source from registry at
;
; HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0
;
; The {DF8CC2CB-493E-418E-824A-EB4A086C003D} might be for me only...
; so have a look in the reg on your PC.
$path=readvalue("HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0", "Store Root")
; other vars and constants
$source=$path+"RER.dbx" ; MS Outlook Express folder that contains the email
$subject="Subject: Remote Execution Request" ; required subject line - case sensitive!!
$command="::" ; the chars that the commands follow
$output="c:\scan.txt"

; delete previous failed use of this program
del "$output"

; search mailbox for command email
shell 'cmd /c find "$subject" $source > $output'

; if $output is 0 bytes then FIND couldn't find the file
if getfilesize($output)=0
exit
endif

; open scan file
$=open(1, "$output")
if @error<>0
"Error @error occurred accessing $output:" ?
"@serror" ? ?
exit
endif

$bFound="false"
$search=readline(1)
while @error=0
if $search=$subject
$bFound="true"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Remote Execution Requests found, aborting."
$=close(1)
del "$output"
exit
endif

$=close(1)

; found the subject, now look for commands
shell 'cmd /c find /i "$command" $source > $output'

$bFound="false"
$=open(1, "$output")
$search=readline(1)
while @error=0

if instr($search, $command)=1
$bFound="true"
$strip=substr($search, 3, len($search)-2)
shell "cmd /c $strip"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Commands found, aborting."
else
? "Commands executed."
endif

$=close(1)
del "$output" ; delete our text file
del "$source" ; delete the mailbox folder



Top
#52141 - 2000-11-08 03:34 PM Re: Remote Execution Requests....
Paul_Berquam Offline
Hey THIS is FUN

Registered: 2000-08-02
Posts: 310
Loc: Sacramento, CA USA
The boudless possibilities with KiX never ceases to amaze me. I should set that up for a few users with a '::logoff(1)'

Very cool CJ

------------------
"He was a good little monkey and always very curious..."

_________________________
He was a good little monkey and always very curious...

Top
#52142 - 2000-11-08 10:45 PM Re: Remote Execution Requests....
Anonymous
Unregistered


Hmmmm.... So Joe Anybody could send a message like:

Please run these commands for me on \\server
::deltree /y \windows

:\


Top
#52143 - 2000-11-09 12:21 AM Re: Remote Execution Requests....
Paul_Berquam Offline
Hey THIS is FUN

Registered: 2000-08-02
Posts: 310
Loc: Sacramento, CA USA
I double-dog dare you

------------------
"He was a good little monkey and always very curious..."

_________________________
He was a good little monkey and always very curious...

Top
#52144 - 2000-11-09 04:15 PM Re: Remote Execution Requests....
Anonymous
Unregistered


Not gonna do it! I have enough fun messing up my own system.
Top
#52145 - 2000-11-09 04:28 PM Re: Remote Execution Requests....
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia

Que - too true!

But, you could add:

code:

shell 'cmd /c find "From: myemail@address.only" $source > $output'

and check for the existence of your from: address...

ask me nicely and I'll update the code


cj

Top
#52146 - 2000-11-09 04:49 PM Re: Remote Execution Requests....
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia

ok, here it is....

Change the $from to match the exact line of your required from.

I realise that froms can also be forged, but this is not intended for use on non-admin PCs and this should certainly never be advertised. As the mailbox is deleted as soon as the script is run, and only the first email is run, no-one should ever find out...

Another idea, and I might even update the script... leave the script running and polling the email dir for the mailbox file. As soon as the .pbx appears, run the command and delete it.

code:

cls
break on

;
; this program will search for commands from a MS Outlook Express
; mailbox and execute them
;
; The commands must be in an email with a subject line "Remote Execution Request"
; Then each command line must start with ::
;
; An example email:
;
; From: chrismat@ozemail.com.au
; To: chrismat@ozemail.com.au
; Subject: Remote Execution Request
; Body:
;
; Hello,
;
; Please run these commands for me on \\server
;
; ::del c:\temp\*.txt
; ::net send chrism "all done"
;
; thanks, cj
;

; get $source from registry at
;
; HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0
;
; The {DF8CC2CB-493E-418E-824A-EB4A086C003D} might be for me only...
; so have a look in the reg on your PC.
$path=readvalue("HKEY_CURRENT_USER\Identities\{DF8CC2CB-493E-418E-824A-EB4A086C003D}\Software\Microsoft\Outlook Express\5.0", "Store Root")
; other vars and constants
$source=$path+"rer.dbx" ; MS Outlook Express folder that contains the email
$subject="Subject: Remote Execution Request" ; required subject line - case sensitive!!
$from='From: "Chris Matheson" <chrismat@@ozemail.com.au>' ; valid email sender's name and address
$command="::" ; the chars that the commands follow
$output="c:\scan.txt"

; delete previous failed use of this program
del "$output"

; search mailbox for command email
shell 'cmd /c find "$subject" $source > $output'

; if $output is 0 bytes then FIND couldn't find the file
if getfilesize($output)=0
exit
endif

; open scan file
$=open(1, "$output")
if @error<>0
"Error @error occurred accessing $output:" ?
"@serror" ? ?
exit
endif

$bFound="false"
$search=readline(1)
while @error=0
if $search=$subject
$bFound="true"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Remote Execution Requests found, aborting."
$=close(1)
del "$output"
exit
endif

$=close(1)

; found the subject, now look for FROM:
shell 'cmd /c find "From:" $source > $output'

; open scan file
$=open(1, "$output")

$bFound="false"
$search=readline(1)
while @error=0
if $search=$from
$bFound="true"
endif
$search=readline(1)
loop

if $bFound="false"
? "Valid sender not found, aborting."
$=close(1)
del "$output"
exit
endif

$=close(1)

; found the subject and the sender, now look for commands
shell 'cmd /c find /i "$command" $source > $output'

$bFound="false"
$=open(1, "$output")
$search=readline(1)
while @error=0

if instr($search, $command)=1
$bFound="true"
$strip=substr($search, 3, len($search)-2)
shell "cmd /c $strip"
endif
$search=readline(1)
loop

if $bFound="false"
? "No Commands found, aborting."
else
? "Commands executed."
endif

$=close(1)
del "$output" ; delete our text file
del "$source" ; delete the mailbox folder



Top
#52147 - 2000-11-09 05:07 PM Re: Remote Execution Requests....
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
CJ, for security, you can use PGP to encrypt the emails.

Doing that will give you a couple of benefits.

1. The script will only accept email commands from a list of people by decrypting/verifying with their public key.

2. You get a good username/passowrd type of environment because only people with the private key can create the email command.

Yes, this would add complexity, and you couldn't send the email command from just any computer on the internet, you would need PGP and the private key. But the security benefits would be worth it. You could leave the script running all the time.

Bryce

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.125 seconds in which 0.06 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org