Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

GetUsers

by Jerry (Scribe)
on Aug 30, 2001 at 23:15 UTC ( [id://109182]=sourcecode: print w/replies, xml ) Need Help??
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);
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://109182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-19 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found