justsexxx
04-06-2002, 03:24 PM
Hi,<br /><br />Got this in my hotmail from an asianaddress or so<br /></font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: fixed;">#!/usr/local/bin/perl <br />$ttsgpath="/local/wwwcust/karupspc/lcgi-bin/ttsgremoteccbill.pl"; <br />$ttsgserver2 = "bserver.karupspc.com"; <br />chop($date = &ctime(time)); <br /><br />if ($ARGV[0] eq ''){ <br />&Get_Post; <br />$passstring=$date."!".join("|",@data); <br /># `$ttsgpath -h $ttsgserver2 -p \"$passstring\"`; <br />print "Content-type: text/html\n\n"; <br />} <br />### The Directory secure is designed to be chmod 700 <br />### To keep people out since there is stuff in there <br />### Which hackers should never see. <br /><br />$pwd = '/local/wwwcust/karupspc/ccbill'; <br />$securedir = 'secure'; <br /><br />### Disk Full Hack <br /><br />if($ARGV[0] eq ''){ <br />open(FULL,">$pwd/$securedir/disk.$$"); <br />print FULL time(); <br />close FULL; <br />open(FULL,"$pwd/$securedir/disk.$$"); <br />$test = <FULL>; <br />close FULL; <br />unlink("$pwd/$securedir/disk.$$"); <br />if (time()-$test >30){ <br />print "DSK-000"; <br />exit; <br />} <br />} <br /><br />$dmr = 1; <br />$second = 0; <br />$dbm = 1; <br /><br />$second_file = "$pwd/secure/second.txt"; <br /><br />##&Setup; <br /><br />$_ = $ENV{'SERVER_SOFTWARE'}; <br /><br />$nt = 1; <br />if (!/microsoft/i){ <br />$nt = 0; <br />$prog_name = 'ccbill-local.cgi'; <br />} else { <br />$nt_user = $pwd.'/'.$securedir.'/nt_user'; <br />open(NT,$nt_user); <br />$nt_user = ; <br />$nt_user =~ s/\n//g; <br />$nt_user = ', '.$nt_user; <br />$prog_name = 'ccbill-local.pl'; <br />} <br /><br />## Set standard values for locking <br />&lock_values; <br /><br />## Password file with all the members in it. <br />$password_file = "/local/wwwcust/karupspc/dmr/htpasswd"; <br /><br /><br />## Referer file <br />$ref_file = "/var/www/virtual/mesohorny/partners/referer.log"; <br /><br />## Log file of everything that happens <br />$log_file = "$pwd/$securedir/ccbill.log"; <br /><br />## List of current users who are active in the system <br />$current_file = "$pwd/$securedir/current.log"; <br /><br />## Users get move here after they are expired. Reference File <br />$expired_file = "$pwd/$securedir/expired.log"; <br /><br />## Trigger File used for scheduling cleanups <br />$purge_file = "$pwd/$securedir/purge"; <br /><br />## Keyfile contains their assigned system password encrypted <br />## This must match the one on the mysql server <br /><br />$key_file = "$pwd/$securedir/private_key"; <br /><br />## History of additions and deletes <br />$history_file = ">>$pwd/$securedir/history.dat"; <br /><br />## Commissions File <br />$commission = ">>$pwd/$securedir/commission.dat"; <br /><br />$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin'; <br /><br /><br /><br />if ($cmd eq 'Y2K'){ <br />&SQL_Date; <br />} <br /><br /><br />@post_values = split(/:/,$post_values); <br /><br /><br /><br /><br />if ($cmd eq 'CLEANUP'){ <br />&Cleanup; <br />print "CLN-111"; <br />if ($dmr & !$nt){ <br />system("chmod 666 $password_file"); <br />} <br /><br />exit; <br />} <br /><br /><br /><br />if ($cmd ne '' ){ <br />&Verify_Key; <br />} <br /><br />if ($cmd eq 'ADD'){ <br />&Add_User; <br />&Check_Time; <br />print "ADD-111"; <br />exit; <br />} <br /><br />if ($cmd eq 'KILL'){ <br />&Kill_User; <br />&Check_Time; <br />print "KILL-111"; <br />exit; <br />} <br /><br />if ($cmd eq 'PASS'){ <br />&Check_Password; <br />print "PASS-111"; <br />exit; <br />} <br /><br />open(KEY,$key_file); <br />$key = join('',<KEY>); <br />close KEY; <br /><br />if ($key ne ''){ <br />## System probably working <br />print "111-111"; <br />exit; <br />} else { <br />## System running but not suid or keyfile gone <br />print "101-101"; <br />exit; <br />} <br /><br />exit; <br /><br />sub lock_values <br />{ <br />$LOCK_EX = 2; <br />$LOCK_UN = 8; <br />} <br /><br />sub lock <br />{ <br />local($file) = @_; <br />flock($file,$LOCK_EX); <br /># and, in case someone appended <br /># while we were waiting... <br />seek($file, 0, 2); <br />} <br /><br />sub unlock <br />{ <br />local($file) = @_; <br />flock($file,$LOCK_UN); <br />} <br /><br />sub Verify_Key <br />{ <br /><br />if (!open(KEYFILE,$key_file)){ <br />print "123-000"; <br />exit; <br />} <br /><br />$private_key = <KEYFILE>; <br />$newkey = $private_key; <br />close KEYFILE; <br /><br />$line = $cmd.':'.$verbose.':'.$post_values; <br />@array = split(/:/,$line); <br /><br />foreach $n (@array){ <br />$newkey = crypt($n,reverse($newkey)); <br />} <br /><br />if ($key ne $newkey){ <br />print "999-000"; <br />exit; <br />} <br />} <br /><br />sub Add_User <br />{ <br />### For an adduser command the post values will be of the form <br />### username:password. This means that $post_values[0] is the <br />### username and $post_values[1] is the password. <br />### No you can't add more than one user at a time. <br /><br /><br />### open password file and append <br />if($dbm){ <br />dbmopen(%password,"$password_file",0666); <br />} else { <br />if(!open(FILE,">>$password_file")){ <br />print "ADD-000 $!"; <br />exit; <br />} <br />} <br /><br />if(!$dbm){ <br />print FILE $post_values[0].':'.$post_values[1],"$nt_user\n"; <br />close FILE; <br />} else { <br />### ADD TO DBM FILE HERE <br /><br />$password{$post_values[0]} = $post_values[1]; <br />dbmclose(%password) <br />} <br /><br />### update the log file with whatever is in verbose <br />### but put a header in there for reference <br /><br />if(!open(FILE,">>$log_file")){ <br />print "ADD-000"; <br />exit; <br />} <br /><br /><br />&lock('FILE'); <br />print FILE "ADD-$post_values[0]:$post_values[1]|$verbose\n"; <br />&unlock('FILE'); <br /><br />close FILE; <br /><br />### update the current file with whatever is in verbose <br /><br />if (!open(FILE,">>$current_file")){ <br />print "ADD-000"; <br />exit; <br />} <br /><br />$_ = $verbose; <br />if (!/:Recurring$/i){ <br />&lock('FILE'); <br />print FILE "$verbose\n"; <br />&unlock('FILE'); <br />} <br /><br />close FILE; <br /><br />($username, $new_subscription_id, $start_date, $end_date, <br />$subscription, $referer, $amount ) = split(/:/,$verbose); <br /><br />if ($referer ne ''){ <br />open(REFERER,">>$ref_file"); <br />print REFERER "$referer|$amount|$new_subscription_id|$post_value s[0]|$date\n"; <br />close REFERER; <br />} <br /><br />} <br /><br />sub Kill_User <br />{ <br />### For an killuser command the post values will be of the form <br />### username:username:username This means that $post_values[0]...[x] <br />### are the usernames <br />### Multiple Users can be batched for efficiency. <br /><br /><br />if(!$dbm){ <br /><br /><br />### Make a list of who to kill in an associative array <br />@kill = split(/:/,$post_values); <br />foreach $n (@kill){ <br />if ($n ne ''){ <br />$kill{$n} = 1; <br />} <br />} <br /><br />### Open Log File <br />if(!open(LOG,">>$log_file")){ <br />print "KILL-002"; <br />exit; <br />} <br /><br />### open password file <br />if(!open(FILE,"$password_file")){ <br />print "KILL-000"; <br />exit; <br />} <br /><br />$tempfile = $password_file."$$"; <br />### open temp file to write to <br />if(!open(TEMP,">$tempfile")){ <br />print "KILL-001"; <br />exit; <br />} <br /><br />while(<FILE>){ <br />($musr, $mpwd) = split(/:/,$_); <br />if (!$kill{$musr}){ <br />print TEMP $_; <br />} else { <br />&lock('LOG'); <br />print LOG "KILL-$musr\n"; <br />&unlock('LOG'); <br />} <br />} <br /><br />close FILE; <br />close TEMP; <br />close LOG; <br /><br />rename($password_file,"$password_file-bak"); <br />rename($tempfile,$password_file); <br />if ($dmr & !$nt){ <br />system("chmod 666 $password_file"); <br />} <br /><br /><br />} else { <br /><br />### They're using a DBM file <br /><br />### Open Log File <br />if(!open(LOG,">>$log_file")){ <br />print "KILL-002"; <br />exit; <br />} <br /><br />### open password file <br /><br />if(!dbmopen(%password,$password_file,0666)){ <br />print "KILL-000"; <br />exit; <br />} <br /><br /><br />@kill = split(/:/,$post_values); <br />foreach $n (@kill){ <br />if ($n ne ''){ <br />delete($password{"$n"}); <br />} <br />} <br /><br />dbmclose(%password); <br />close LOG; <br /><br />} <br />} <br /><br />sub Cleanup <br />{ <br />### Loop through the current.log file and remove anyone <br />### who is expired. <br /><br />$today = &SQL_Date(time()); <br /><br />open(CURRENT,"$current_file"); <br />while(<CURRENT>){ <br />($username, $sub_id, $start_date, $end_date, $length) = split(/:/,$_); <br />$userdata{$username} = $_; <br />$expires{$username} = $end_date; <br />} <br />close CURRENT; <br /><br />if(!$dbm){ <br /><br />foreach $n (keys %userdata){ <br /><br />if ($expires{$n} < $today){ <br />$kill{$n} = 'YES'; <br /># User has expired. Wipe the userdata clean. <br />$userdata{$n} = ''; <br />} <br />} <br /><br />$tempfile = $current_file."$$"; <br />open(TEMP,">$tempfile"); <br />&lock('TEMP'); <br />print TEMP values(%userdata); <br />&unlock('TEMP'); <br />close TEMP; <br /><br />rename($current_file,"$current_file-bak")