package CBE;
use warnings;
use strict;
my $pop3 = 'pop3.server';
my $login = 'email@adress';
my $pass = 'password';
my $number = 'phone_number';
sub check {
my $last;
if( -e 'num' ){
open(NUM, "num");
$last = int();
} else {
open(NUM, ">>num");
$last = '0';
}
close NUM;
my $pop = Net::POP3->new($pop3) || die("Can't connect");
my $now = $pop->login($login, $pass) || die("Can't connect");
if ($last < $now){
my $msg = $pop->get($now);
my $auth;
for my $line (@$msg){
if( $line =~ /(<$number@(.*)>)$/ ){
$auth = '1';
}
}
while( my $line = shift @$msg ) {
last while $line =~ /^Status:/;
}
chomp(@$msg);
my $string = @$msg[1];
if(@$msg[1] =~ /=(.*)=/){
my @arr=split(/=(.*)=/,$1);
if (system(`$arr[0]`)){
&log_save($arr[0],'yes');
} else {
&log_save($arr[0],'no');
}
}
}
open(WRI, ">num");
print WRI $now;
close WRI;
$pop->quit;
sleep 5;
}
sub log_save {
my $log = shift;
my $status = shift;
open(LOG, '>>log.txt');
print LOG "Command: $log\n";
print LOG "Date: ".localtime()."\n";
print LOG "Success: $status\n";
print LOG "-----------\n";
close LOG;
}
cbe.pl
#!/usr/bin/perl
use warnings;
use strict;
use Net::POP3;
use CBE;
while(1){
CBE::check();
}
That's horribly insecure and allows anyone who finds out (or guesses) the recipient address and a valid phone number to run any command they like on your machine.
To do this at least somewhat securely you should encrypt your command with a private key unique to the sender and only execute if it can be decrypted with the public key stored on the recipient machine. Personally I'd still not use that and rather set up a system that performs specific actions only (instead of blindly executing any command it receives), but that's just me.
That's still no good. Email is cleartext and, unless you're using the SMTP server on the same host as the POP server, has to pass through multiple hosts over which you probably have no control. Anyone can read the cleartext password on the way, you need to use some form of encryption if you want to have a mechanism that's even borderline secure.
perlmonks.org content © perlmonks.org and salva, tirwhan, w3b
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03