Category: networking
Author/Contact Info LordScinawa
Description: i think to use this on my little server to get up or shutdown all the other demon such as httpd,sshd,ftpd when i don't need it. i how that doing so i can evitate some attaks from extern :) in the two file there are the username and password and the command to execute with a little comment. :)
# # To install this program:
# # mkdir /etc/abdemon
# # cd /etc/abdemon
# # jed /user.conf
# #     write here user and pass coded in base64 :) 
# #     user:pass
# # jed /abcomand.conf
# #     write here the command to startup or shtudown the demon
# #     Demon Name:command:Description

#!/usr/bin/perl -w
use strict;
use warnings;
use IO::Socket::INET;
use MIME::Base64;

sub login{
    print"Starting LogIN\n";
    my $session = $_[0];
    print $session "LogIN: AbsoluteDemon\n\r";
    print $session "UserName:";
    my $ut=<$session>;
    print $session "Pass:";
    my $pa=<$session>;
    open DB, "<", "user.conf";
    #open DB, ">", "/etc/abdemon/user.conf";
    $a=<DB>;
    my @vagone=split( /:/, $a);
    my $user=beis($vagone[0]);
    my $pass=beis($vagone[1]);
    chomp($user, $pass);
    $ut =~ s/\r\n\z//;
    $pa =~ s/\r\n\z//;
    chomp($ut, $pa);
    if ($ut eq $user) {
        if ($pa eq $pass){
            print "LogIN Succesfull\n";                               
+         
            choose($session);}}
            else {    print $session "User can NOT log in";
            sleep 1;
                    uail(); }}

sub choose {
    my $session=$_[0];
    my @comz;
    my $ch;
    #open COM, "<", "/etc/abdemon/adcomand.conf";
    open COM, "<", "C:/abd/abcomand.conf";
    my $num=0;
    while (my $riga=<COM>) {
        $num=$num+1;
        print $session "$num, $riga\n\r";        
        $comz[$num]=$riga;                                #array che c
+ontiene i comandi pił il numero 
        }
    do  { $ch=<$session>;                                    #ricevo i
+l numero di comando
        $ch =~ s/\n\r\z//;
        my $dirty=$comz[$ch];                                #tiro fuo
+ri la riga e la chompo
        chomp($dirty);
        my @command=split( /:/, $dirty);                              
+  #tiro fuori il comando
        print $session "$command[1]\n\r";
        print "$ch\n\r"; 
        system($command[1]);
        print $session "And now?"}
        while ($ch ne "0");
    close $session;
    close COM;
    sleep 10;
    uail();
}
    
sub beis { my $a=decode_base64($_[0]);
             print "Decoding..\n";
            return $a;}    
             
sub uail {    my @time = (localtime);
            my $sock = new IO::Socket::INET(
                        LocalPort => '7350',
                        #Localaddr =>'localhost',
                        Proto => 'tcp',
                        Listen => '1') or die "Cannot Listen on sock! 
+$!\n";
            my $session = $sock->accept;
            print "Socket Created\n";
            #    open LOGZ, '>>', '/etc/abdemon/access_log';
            open LOGZ, '>>', 'logz.txt';
            my $ip=$session->peerhost;
            print (LOGZ "$ip at time: $time[2]h $time[1]m $time[0]s Da
+y: $time[3]/$time[4]($time[5]-100) ");
            close LOGZ;
            print"Logged IP\n";
            login($session);
            close $sock;}

    print"Absolute Demon 1.0 (un)stable relase\n";
    chdir "C:/abd";
    uail();
Replies are listed 'Best First'.
Re: BigDemon
by zentara (Cardinal) on Aug 21, 2006 at 12:30 UTC
    Just an observation.......

    Using SSH or Net::SSH would be more secure to run remote commands on your machine. With all the network surveillance going on nowadays, your base64encoded password is as good as sending a plain text password.

    As pointed out to me by Limbic-Region, you should also use "keys authorization" with SSH, rather than a conventional user/password login. See keys setup for a guide.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: BigDemon
by mkirank (Chaplain) on Aug 21, 2006 at 15:22 UTC
    you are not handling errors on open calls ..