The plot thickens…

Did it set myself up or am I clairvoyant? Not only was my daughter up at 4 AM this morning but my dog seemed to have eaten some sort of paper product, peas, corn and some other stuff that was partially digested and could not be identified. The dog was pacing all night long with intermittent pauses to purge his system (there is nothing like the sound of a dog purging to inhibit REM sleep). Obviously the dog mess needed to be cleaned up but it gets worse, when I looked out into the back yard I noticed that approximately ten thousand gallons of water was missing from my pool. The only good answer here is that my neighbors house burnt down in the middle of the night and the fire department needed to pump from my pool to fight the fire, unfortunately for me this was not the case. Rather when setting up the pool last night I managed to shut off all of the returns which caused a pipe on the filter to blow out, so instead of cleaning my pool last night I pumped ten thousand gallons of water into my back yard. I wonder how this day is going to turn out?

-RJB

Secure rexec… Why did I not go to bed 2 hours ago?

It is 1 AM on July 6th, 2006 and I think that I may have reached the pinnacle of techie stupidity. I am sure you are asking why? Well the answer is that I should have gone to bed hours ago because my 1 year old daughter is going to get me up in 3 or if I am lucky 4 hours from now. The reality is by the time I am done writing this post it will probably be more like 2 hours.

Anyway, I was sitting at the computer tonight and out of pure boredom decided to finish up some code I started a while ago at a techie conference session (I was probably suffering from an even more sever case of boredom then). This was a perl script that would function in the same way as rexec but utilizing the more secure ssh protocol. Again you may ask why? I often find myself asking the same question. No, really the concept was to include this in a much larger project that is still on the drawing board and may or may not actually happen depending on if I can find the cycles.

I have decided to post to code to my blog for anyone else who would like to improve, modify or use the code. I also have a windows binary version compiled for users who may want to use it but do not know how to install ActivePerl or the required perl modules, if you leave a comment I will provide the ftp site where you can grab it from.

Right now the connection speed is a bit slow and I am not sure why, I think there may be a problem with the Net::SSH::W32Perl module and password authentication but I can not verify.

You will also need to create a hosts.txt file in the same directory where the srexec.pl script is.? This file should contain the host(s) you would like the passed command to be run on.

The same code will work on UNIX/Linux just use the Net::SSH perl module as opposed to the NET::SSH::W32Perl module. Both modules can be acquired from CPAN (http://www.cpan.org).

Enjoy!

-RJB

#————begin————

#!/usr/local/bin/perl
### srexec.exe - Secure Remote Execution
### Rich Bocchinfuso
### Revision History
### 06-06-2006 - rev 0.02a

### 04-25-2006 - rev 0.01a

use strict;
use Net::SSH::W32Perl;

my $f=’hosts.txt’;

if ($ARGV[0] eq “-e”) {
&execute;
}
elsif ($ARGV[0] eq “-h”) {
&error;
}
elsif ($ARGV[0] eq “-about”) {
&about;
}

sub execute {
( my $command = $ARGV[1] || &error);
#chop $command;
( my $user = $ARGV[2] || &error);
#chop $user;
( my $pass = $ARGV[3] || &error);
#chop $pass;

my ($ssh, $out, $err, $exit);

my %args;
$args{debug} = 1;
$args{protocol} = 2;

open F, “< $f" or die "Can't open $f : $!";

while () {
chop $_;
$ssh = new Net::SSH::W32Perl($_, %args);
$ssh->login($user, $pass);
($out, $err, $exit) = $ssh->cmd($command,”\n”);
}
close (F);
exit;
}

sub error {
print “\nsrexec.exe\n\nUsage: srexec.exe [option] [command string] [username] [password]\n”;
print “i.e. - srexec.exe -e \”ps -ef | grep getty > test.out\” user password\n”;
print “srexec.exe -h => This Help\n”;
print “srexec.exe -about => Detailed srexec info\n”;
exit;
}

sub about {
print “\nSecure Remote Execution\n”;
print “Rev 0.1a build date: 04-25-2006 \n”;
print “Author: Rich Bocchinfuso \n”;
print “Licence: GPL\n”;
exit;
}

#————end————

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 45 items have been purified.