Category: Utility Scripts
Author/Contact Info Jerry Fowler
jerry@digilliance.net
Description: Client app for my GiveUsers server. Currently set up to get the password and shadow files (gpg encrypted before crossing the network!!), and changing all shells to /bin/false (except the first 20 lines). Be sure to create GPG keys and import them to the other box (as the user which will be running the GetUsers and GiveUsers scripts)
#!/usr/bin/perl

use IO::Socket;
use File::Copy;
$sock=new IO::Socket::INET      (LocalHost => '222.22.222.22',
                                LocalPort => '60009',
                                Proto => 'tcp',
                                Listen => 2,
                                Reuse => 1
                                );
die "Socket could not be created! Reason: $!" unless $sock;
while ($new_sock = $sock->accept()) {
        copy("/etc/passwd","/tmp/giveusers/passwd");
        copy("/etc/shadow","/tmp/giveusers/shadow");
        system('gpg -e -r jerry2 -a /tmp/giveusers/passwd');
        system('gpg -e -r jerry2 -a /tmp/giveusers/shadow');
        unlink '/tmp/giveusers/passwd';
        unlink '/tmp/giveusers/shadow';

        $hersockaddr    = getpeername($new_sock);
        ($port, $iaddr) = unpack_sockaddr_in($hersockaddr);
        $herhostname    = gethostbyaddr($iaddr, AF_INET);
        $herstraddr     = inet_ntoa($iaddr);
        $date=`date`;
        open(LOG, ">>" . "/var/adm/getusers");
        print LOG "Connection from: $herhostname [$herstraddr] at $dat
+e\n";
        close(LOG);
        if (($herstraddr eq '22.22.22.22') || ($herstraddr eq '22.22.2
+2.21')) {
                open(PASSWD, "<" . "/tmp/giveusers/passwd.asc");
                while (<PASSWD>) {
                        chomp;
#                        @line=split(/:/);
#                        $cleaned="$line[0]:x:$line[2]:$line[3]::/tmp:
+/bin/false";
#                        print $new_sock "$cleaned\n";
                        print $new_sock "$_\n";
                }
                close(PASSWD);
                print $new_sock "---DELIMITER---\n";
                open(SHADOW, "<" . "/tmp/giveusers/shadow.asc");
                while (<SHADOW>) {
                        chomp;
                        print $new_sock "$_\n";
                }
                close(SHADOW);
                unlink '/tmp/giveusers/passwd.asc';
                unlink '/tmp/giveusers/shadow.asc';
        } else {
                print $new_sock "Unauthorized access from $herstraddr 
+LOGGED!!\n";
                die "$herstraddr";
        }
        close($new_sock);
}