Wednesday, March 24, 2010

Anyone bored? Help me with another quick HCI survey: https://byu.qualtrics.com/SE?SID=SV_82Oria7UclodIaw&SVID=Prod

Monday, March 01, 2010

Perl Administration

I'm not sure if this works, so let me know:

#!/usr/bin/perl -w

# Brady Redfearn, IT-344, Security Scan
# Code courtesy of Googling the Internet

# include mailer program
use Mail::Mailer;

# Variables
@array = (`ls -l`);
# email default string:
sub sendEmail{
# email fields
($to, $from, $subject, $body) = @_;$mailer = new Mail::Mailer->new();$mailer -> open({From => $from,To => $to,Subject => $subject,});print $mailer $body;$mailer -> close() or die "Couldn't send the message $!\n";}

# loop
foreach(@array){
$file = $_;
# Parses through the string and the portions within the parameters are saved
if($file =~ /(.)(...)(...)(...)\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)/){
$group = $3;
$anyone = $4;
$group_per = $5;
$owner_name = $6;
$file = $7;
$user = $ENV{"USER"};

# File has been found
if(($group =~ m/(x|r|w)/)&&$anyone =~ m/(x|r|w)/){
$output = "A security issue has been detected:
File $file owned by $owner_name has $group permissions available to the group $group_per and has $anyone world permissions\n";
sendEmail("$user\@localhost","security\@localhost","Security problems detected",$output);
} # if ends

# another file
elsif($group =~ m/(x|r|w)/){
$output = "A security issue has been detected:
File $file owned by $owner_name has $group permissions available to the group $group_per and has $anyone world permissions\n";
sendEmail("$user\@localhost","security\@localhost","Security problems detected",$output);
} # else-if ends

# another file
elsif($anyone =~ m/(x|r|w)/){
$output = "A security issue has been detected:
File $file owned by $owner_name has $group permissions available to the group $group_per and has $anyone world permissions\n";
sendEmail("$user\@localhost","security\@localhost","Security problems detected",$output);
} # else-if ends

} # if statement
} # foreach loop