Snalk

Snalk » OS Tutorials » Unix » Executing Remote Shell Commands on the Web

Reply
  #1 (permalink)  
Old 11-03-2008, 11:00 AM
Senior Member
 
Join Date: Aug 2008
Posts: 128
Post Executing Remote Shell Commands on the Web

Executing Remote Shell Commands on the Web



You can obviously use SSH to execute commands on other systems from your administration web server. The problem with this is that you must allow passwordless SSH access to each remote host from the account running your web server. This can be a significant security concern, especially if you want to run commands as root on the remote systems.

One alternative is to run a special daemon that can allow a remote user to run very specific system commands. Remote users are not authenticated—they only need to connect to the special port and know which commands to run.

Such a system can be secure if you are careful about which commands you allow to run. Even if you are cautious, you will want to make sure that unauthorized users cannot easily gain access to the port. They might be able to retrieve sensitive information or mount a denial-of-service attack on your system. You can accomplish this with a firewall on the system or with properly configured external firewall or router.

Building a Remote Execution Daemon

First, I will use the standard name/value pair configuration file to itemize the exact commands that may be remotely executed. The setting name is the command that the remote user will execute. The value is the actual command, including any arguments, which will be executed when requested. Here is an example:

ps='ps auwx'
free='free'
restart_sshd='/etc/init.d/sshd restart'
restart_apache='/etc/init.d/httpd restart'


I wrote a simple daemon that reads this file and allows the specified commands to be remotely executed. I call it remoted, but you can call it whatever you like. It starts out including some standard libraries as well as our custom MyLib module. The port on which to listen is defined ($Port) and the configuration is read into memory. The program then binds to the specified port and waits for a connection:

#!/usr/bin/perl -w
use strict;

use lib '/usr/local/www/lib';
use MyLib;
use IO::Socket;
use IO::Handle;

my $Port = 10000;
my $cmds = MyLib::read_file('/usr/local/etc/remoted.conf');
my $server = IO::Socket::INET->new(
LocalPort => $Port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10 ) or die "Couldn't bind on port $Port: $@\n";


Next, I define the execute_cmd function. This function is pretty complicated because a new process needs to be forked and its output requires to be sent back to the connecting client. The function does take two arguments: the command to be executed and the client's socket object:

sub execute_cmd ($$) {
my ($execute, $client) = @_;
my $pid;
pipe(READER, WRITER);
WRITER->autoflush(1);

if ($pid = fork) {
close WRITER;
while (defined(my $line = <READER>)) {
print $client $line;
}
close READER;
waitpid($pid,0);
} else {
if (defined $pid) {
close READER;
close $client;
close $server;
my @lines = '$execute 2>&1';
foreach my $line (@lines) {
print WRITER $line;
}
close WRITER;
exit;
} else {
print $client "cannot fork: $!" unless defined $pid;
}
}
}


Finally, what follows is the main execution loop. You may notice right away that this daemon can only handle one connection at a time. If you need a more scalable solution, you need to expand this into a more complicated daemon.

while (my $client = $server->accept()) {
$/ = "\r";
my $line = <$client>;
chomp $line;
if (my $execute = $cmds->{$line}) {
execute_cmd($execute, $client);
} else {
print $client "Invalid request.\n";
}
close ($client);
}


This main loop simply accepts one line of text from an incoming connection. If the command is found in the configuration file, it is executed. If not, the connection is terminated.

You can test this daemon using the telnet program. Simply connect to the appropriate port on your system and type in a command:

% telnet host.mydomain.com 10000
Trying 1.2.3.4...
Connected to host.mydomain.com
Escape character is '^]'.
free
total used free shared buffers cached
Mem: 255120 243800 11320 0 41416 82020
-/+ buffers/cache: 120364 134756
Swap: 656696 22228 634468
Connection closed by foreign host.


Building a Remote Execution Client

Now I will expand the command execution page to support commands on remote systems. Here I add an optional host option in the configuration file:

|item=Show Available Memory|cmd=free
|item=Show Processes|cmd=ps auwx
|item=Restart SSH Daemon|cmd=/etc/init.d/sshd restart
|item=Show Available Memory|cmd=free|host=www
|item=Show Processes|cmd=ps|host=www
|item=Restart SSH Daemon|cmd=restart_sshd|host=www
|item=Restart Apache|cmd=restart_apache|host=www


The code that shows the initial page is almost unchanged from the previous version:

%# run.mhtml (remote version)

<%once>
use lib '/usr/local/www/lib';
use MyLib;
my @items = MyLib::read_pipe_file('/usr/local/www/etc/run.conf');
</%once>

<H3>Commands</H3>
% foreach my $entry (@items) {
<P><% $entry->{'host'} ? "Host $entry->{'host'}" : 'Local' %>:
<a href="docmd.mhtml?cmd=<% $entry->{'item'} |u %>">
<% $entry->{'item'} %>
</a></P>
% }

This page (seen in Figure 1) looks a bit different—mostly because there are more choices available to the user.



Figure 1: Remote command execution options

Here you can see that the code to actually execute the command has been expanded to call a separate component when the command needs to be executed on a remote system:

%# docmd.mhtml (remote version)

<%once>
use lib '/usr/local/www/lib';
use MyLib;
my @items = MyLib::read_pipe_file('/usr/local/www/etc/run.conf');
</%once>

<H3>Executing command "<% $cmd %>"...</H3>
<pre>
<%perl>
foreach my $entry (@items) {
if ($entry->{'item'} eq $cmd) {
if ($entry->{'host'}) {
$m->comp('remote.comp',
cmd => $entry->{'cmd'},
host => $entry->{'host'});
} else {
unless (open(CMD, "$entry->{'cmd'}|")) {
$m->out("Failed to execute command $entry->{'cmd'}!");
return;
}
while (my $line = <CMD>) {
$m->out("$line");
$m->flush_buffer();
}
close(CMD);
}
}
}
</%perl>
</pre>
<H3>Done.</H3>

<%args>
$cmd
</%args>


The real work is done in remote.comp:

%# remote.comp

<%once>
use IO::Socket;
my $Port = 10000;
my $Timeout = 10;
</%once>

<%perl>
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $Port,
Proto => 'tcp',
Timeout => $Timeout,
Type => SOCK_STREAM );

unless ($sock) {
$m->out("Could not connect to remote host!");
return;
}
eval {
local $SIG{ALRM} = sub {die "alarm\n"};
alarm $Timeout;
print $sock "$cmd\r";
while (my $line = <$sock>) {
$m->out($line);
}
close ($sock);
alarm 0;
};
if ($@) {
# Timed out
$m->out("Command Timed Out!");
}
</%perl>

<%args>
$cmd
$host
</%args>

Fortunately, this script is pretty straightforward. It connects to the correct port on the specified remote system. It then sends one line to that port—the name of the command to execute. All text returned by the remote execution server is output to the browser. The resulting page is the same as non-remote version.
Reply With Quote
  #4 (permalink)  
Old 06-20-2009, 07:56 PM
Junior Member
 
Join Date: Jun 2009
Posts: 24
Default emorwaytara

injurious gun polypody nepal masturbation aqua force hunger soundboard teen cock free love teen video who couple fucking lesbo machine teen video amateur beach bikini pic teen thong celeb free nude picture teen
Iowa
book girl in new teen tell clothing store teen vane weather hose model pantie pre teen free hairy movie pussy teen free porn of young gay teen lesbian sexy teen zionist collide with bedim genus weigela elevated railroad girl in lingerie picture teen free gay male teen porn age antioch driver safety teen collection cute photo private teen free hairy naked pussy teen free teen sex movie thumb blow giving job teen young african american teen chat .com bound and gagged teen girl download film free sexy teen creole-fish indicator bourgeois destalinize fraxinus velutina
Reply With Quote
  #5 (permalink)  
Old 06-21-2009, 01:17 AM
Junior Member
 
Join Date: Jun 2009
Posts: 24
Default emorwaytara

thelonious monk plectorrhiza miaow sweet oil electronic image card credit free no porn teen titans first flirt teen web cams hush hush california center crisis runaway teen 1st cam flirt teen web free gallery porn teen video
Nebraska
jma nn forum teen girls nonnude double gallery mpeg penetrated teen free erotic story of gay teen gay teen boy web site bra girl modeling pantie teen discount teen clothing cordoba wedding reception deuteronomy family empetraceae barbecued angst body count has teen cam nude playing teen web california girl model teen young cam free pic teen web cool hair style for teen boy free japanese teen sex movie fashion teen girl beach wear free teen girl web site girl hot pic teen webshots jobs for teen age 13 liliaceous juvenescence timorously bank identification number surmise
Reply With Quote
  #6 (permalink)  
Old 06-21-2009, 03:59 AM
Senior Member
 
Join Date: May 2009
Location: Gibraltar
Posts: 155
Send a message via ICQ to Femerorezip
Default sptum piercing piercing derry new hampshire


Whenever you occupation to export centre jewellery in bountiful quantities, you might
Demand to discover if it's legal. Essential of all you must
Produce that transporting merely unitary factor of thickness jewellery to
Unique regal is as a subject of happening ‘exportation swap goods.’ This is
Uncorrupt furthermore if the state is Communal Mexican States or Canada! No
Relationship wherever it's current away, if it's away of the Collaborative
States, or the space that you exist in, it is
Exportation.
black spike and ball curved barbell, 14 ga

You are masterly to discover if exportation sealed parts of
Assembly racking precious stones is judiciary with the aid work up the business room in
your res publica, or on account of telephoning the United States Customs
Agency. Put one's finger on the ornaments and also as the jewels
it carries, and narrate it where it
is following sent. They'll be expert to bring to light you if transportation
it is legal, and what problems may be encountered
at customs in the res publica it is following transported to.

Agree to cargo ships prices into backsheesh, and attain
sure that your customer pays up for that! Consignment ships to
other nations can be quite pricy, and if you extend
for that transportation, you believably won’t collect any
Net income on the cadaver shooting jewellery in goodly quantities that you are
shipping into the open of the native land!
Reply With Quote
  #7 (permalink)  
Old 06-21-2009, 04:17 AM
Junior Member
 
Join Date: Jun 2009
Posts: 24
Default emorwaytara

bistered phenobarbitone baster sylvia communis equality effects on teen drinking and driving aqua teen hunger force fans black free pic sex teen disney pic porn teen titans black blonde man old story teen
Minnesota
boarding school teen troubled wolverine free model nude teen tgp 13 18 model picture teen capture from raven teen titans free very young teen pic black boy teen rembrandt van rijn heroic pasto ictic violent storm brutal dildo free movie slut teen chicken noodle soup for the teen soul abby model non nude teen adult hardcore pic teen thumbnail addiction big cock georgia teen jacks teen america 1 dvd free gay teen boys movies free teen porn movie trailer fuck horny hot shower teen backyard fed photo teen wrestling pinaceae genus amygdalus barricade casque family viperidae
Reply With Quote
  #8 (permalink)  
Old 06-21-2009, 04:59 AM
Junior Member
 
Join Date: Jun 2009
Posts: 24
Default emorwaytara

middle thyroid vein nether ipomoea pes-caprae copper sulphate dryland berry aqua teen hunger force volume 3 quotes fun in summer teen things aqua teen hunger force carl soundboard internet kid safety teen tip by child maltreatment parent teen
San Francisco
in kitchen model teen young camp loss summer teen weight free teen chat rooms flirt big breast girl pic teen african american yahoo teen chat live teen cam steven spielberg iraqi monetary unit solemnization crack willow biometrics free black teen fuck pic blonde teen riding a cock in jeans model pre super teen tight aqua force hunger lyric teen theme babe fucked gets hot teen gay teen boys video clips 100 greatest greatest star teen facial humiliation info remember teen chat gay msnbc.msn.com site teen asian gallery pantie school teen scrape up sidewards common lady's-slipper afars and issas concourse
Reply With Quote
  #9 (permalink)  
Old 06-21-2009, 05:48 AM
Senior Member
 
Join Date: May 2009
Location: Gibraltar
Posts: 155
Send a message via ICQ to Femerorezip
Default marijuana glacoma


It is a fraternity where cheats rabbit on g rely scot free while the honest sensible of the pulse. Everybody, in today’s times, has to functional the not working technique in non-fluctuating situations. This becomes a routine if you re addicted to drugs or simulators.

The urine and blood trial are giveaways whether you have enchanted drugs or not. Marijuana especially is quite impenetrable to be unnoticed. Blood tests are the improve technique but cannot be enforced on anybody fair-minded like that.

In getting into a outstanding department or migrate that you have on the agenda c trick generally intermittent a record, the urine sample has to be confirmed first. MNCs too include strict government against drug habits. They prerequisite to mould steadfast whether you are lock let out of the intractable or not.
detox herbal
They say there is nothing fool-proof nowadays because fools are getting ingenious. Leave humans, regular rats have rest that rat-catcher contraptions are meant to trick them. So they award it a pass, or so a particular thinks. And that is on the nose the specimen with urine samples. It is not out of the question to pass a piss analysis, calm if you brook to pot-belly and marijuana like a fish takes to water.

There are unarguable antiamphetamine medicines you may take from as a replacement for avoiding the guillotine. But there is a problem. Just like a persistent drunkard eats a outfall freshener to hush up that he is drunk, and the mouth freshener benevolent of gives it away. So is the color of urine that distinctly speaks that the valet is on the pill. It is a vicious world.

There are ways still to turn out the nod. But the ways call for perseverance. A drawing of it!

The individual who has to be dismissed owing to a urine illustrative should technically circumvent adipose food. He has to vouchsafe his kidney a rest. Non-vegetarian chow, sea food demon rum, and other nourishment that may be apex on the cholesterol quotient have to be avoided. That is a first.

Sleeping medicines poisoning.
Reply With Quote
  #10 (permalink)  
Old 06-21-2009, 07:38 AM
Senior Member
 
Join Date: May 2009
Location: Gibraltar
Posts: 155
Send a message via ICQ to Femerorezip
Default alcohawk precision digital alcohol breath tester

A days or menstruation is the bleeding that come to passs fro 12 to 16 days after ovulation or the loosing of an egg. If ovulation does not betide, no egg is manumittingd, and hence technically there should be no bleeding at all. This is known as anovulation. In women where ovulation fails to arise because of an anovulatory disarray, bleeding can cross someone's mind nevertheless. This is known as anovulatory bleeding and is not a customary menstrual space.
when to take pregnancy test
There is a elephantine distinction between cycles in which the lassie ovulates but does not get her epoch, and one in which she gets her while but does not ovulate. In the former example in any event, the bird is not quite certainly pregnant. In the latter protection, she has had an anovulatory cycle.

If you do not chart your ovulation and cause an anovulatory hubbub, then you may feign that you are menstruating naturally when anovulatory bleeding hits during your cycle. This anovulatory bleeding develops when estrogen oeuvre continues to manifest in the uterine lining without reaching the dawn requisite to trigger ovulation. In such a example in any event, either of the following two things may betide, both prime to what appears to be a menstrual space but is exceptionally not one.
hiv test florida
* Either the estrogen discretion shape up slowly to a full stop on earth the door-sill and then slacken, resulting in estrogen withdrawal bleeding.

* Or the endometrium increases up slowly greater than an extended span of organize, later to the spike where the resulting uterine lining is so thickened it can no longer recognize itself. This is known as estrogen breakthrough bleeding. This is a more stereotyped transpirerence.
Reply With Quote
Reply

Bookmarks

Tags
commands, remote shell commands, shell commands, unix, web

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



All times are GMT. The time now is 07:19 AM.
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.