munk.me.uk forum
May 21, 2012, 05:02:06 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Perl books for system administration  (Read 3777 times)
kBd
Guest


Email
« on: October 15, 2004, 06:56:46 am »

Im looking for some Perl books, firstly one I could learn basic Perl from and secondly one for examples of Perl with system admin jobs.

I want to do a project in Perl that will be like a glue holding several binaries together to accomplish a goal

Im trying to automate gateway administration




P.S. Hi2u jez

Off topic: Hellz is alive and well, he was around "thatplacewebothknow" some months ago and I just saw Enstyne tonight.  Smiley  
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #1 on: October 15, 2004, 10:32:36 am »

The perl book I learnt from was the SAMS Teach Yourself Perl in 24 hours.  Some people don't like those 24hr books, I just had it to hand though and found the perl 24hr book fine for learning perl. You should be able to find it online to download - it's in ebook (html) format widely as well as available in hard copy - I have a copy if you can't find it.

Another great place to look is the O Reilly site for perl - just browse through the books there.  The books I used in the past are Learning Perl (good for learning perl surprisingly!) and 'the camel book' otherwise known as Programming Perl (that was one of the first official' guide books to perl by the Perl head honchos Larry Wall and Larry Christianson).

The camel book is pretty damn fine, quite an easy going laid back writing style and almost makes it fun to read about a programming language!  At the same time though it's very heavy with technical info on Perl and how to best use it, with a stack of example usage in there which I still use a lot even a few years after I first bought the book.  I read through it a few years ago and some examples kind of lodged themselves in my brain in a way that I can't exactly remember verbotem the code, but if I need to use it I just pick up the book and copy the code I need.  Very good book to say the least and worth having in hard copy.

Foir the sysadmin side, I was thinking about purchasing Perl for System Administration a while ago, although never got around to it or had the need that badly.  Might be very useful though.

On the way finding out about the books for this post I also found this site which looks worth checking out:

http://learn.perl.org/

Hope hellz is well - say hello to him when you speak to him next!  Hope everything is ok with you as well.
Logged

~ Jez
kBd
Guest


Email
« Reply #2 on: October 16, 2004, 10:12:00 am »

thanks man

Im currently learning Lisp also, I just have to learn Perl right now so I can hammer some code out and let someone else do the rest.

Im redoing the spec for that gateway and authenticication stuff for FireBSD. I have to rewrite the spec first... Asmodai is leaving us with ipf(I was expecting PF) for the moment, so in order to make this package portable and interesting/useful for other ppl I have to write in support for other firewalls, starting with ipf Smiley
This way when you install this you just choose the firewall you use, keeps it simple on the admins.

Man... Lisp is so cool...  between the possibility of infinite uptime(even while applying code patches to running programs!)... the ability to interact with any API or libs I want to... and the inherit qualities which make it good for artificial intelligence projects... I can hardly get enough of it

Since Unreal Tournament broke on this machine I spend all my free time looking up Lisp stuff lol

On my List to learn:
Lisp
Perl
ADA
ASM(I figure I'll be doing some low level drivers for wearable computing projects some day)
and ofcourse the old faithful C

Anyways, thanks again for the book list


I thought you might want to see this:  http://cpan.org/authors/id/J/JS/JSTENZEL/rsc

I was thinking it would make a good platform for a distributed computing project

L8r
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #3 on: October 17, 2004, 08:30:31 pm »

Interestingly I started writing a perl script to help automate adding new rules to ipf.  It started with the need to easily add new blocking rules to IP addresses, either manually via the commandline or (potentially more dangerously) dynamically from other systems (for example from mod_security the apache security module or snort).

Unfortunately I didn't get too far with it, but you're welcome to look at what I did.  I'll post the code here... it's probably too embarrassing to post but still who knows you might find it interesting!

Code:
#!/usr/bin/perl
# Script for controlling ipfilter rules
use strict;
use Getopt::Std;

my $progname = $0;
$progname =~ s,.*/,,;  # use basename only
$progname =~ s/\.\w*$//; # strip extension, if any
if ($< != 0) {
    print STDERR "${progname}: Error: you must be root to use $progname\n";
    exit(1);
}

my $div="#"x72;
my %opt=();
my @rules=();
my ($err, $verbose);
my ($rule_dir, $order_file);
my ($rule_file, $rule);

my $default_order_file = "order.ipf";
my $default_rule_dir="/usr/local/etc/ipf";

my $ipf = "/sbin/ipf";

my $tmp_file="/tmp/$progname.$$";

# find out what options we're passed:
&getopts('lod:hv', \%opt);

$verbose=1 if $opt{v};

if($opt{d}){
$rule_dir=$opt{d};
}else{
$rule_dir=$default_rule_dir;
}

$order_file="$rule_dir/$default_order_file";

# check order file readable:
if( ! -r $order_file ){
&usage("Cannot read $order_file");
}

# display usage if bad opts:
if($opt{h} || !%opt){
&usage();
}

# get the ruleset based on $order_file:
&ruleset_build($order_file);

if($opt{o}){
foreach (@rules) { print "$_\n" };
}

if($opt{l}){
&load_rules();
}

sub load_rules{
# Write the rules to a temp file:
open(FP, ">>$tmp_file");
foreach (@rules){ print FP "$_\n"; }
close FP;

# Read the rules into the inactive list:
exec("$ipf -I -v -Fa -f $tmp_file");
}

# Build the ruleset from the order file in $rule_dir:
sub ruleset_build {
$order_file = shift;

print "Order File $order_file contains:\n" if($verbose);
open(FD, $order_file);
while($rule_file=<FD>){
  chomp $rule_file;

  print "$div\n$rule_file:\n" if($verbose);

  # skip comments and empty lines:
  next if $rule_file=~/^#|^$/;
  
  # if this rule_file is regular file, read the rules:
  $rule_file="$rule_dir/$rule_file";
  if( -f $rule_file){
   &read_rules_file();
  }
  elsif( -d $rule_file){
   my $child_rule_dir = "$rule_file";

   if($verbose){
    print "Reading rules from directory: $child_rule_dir\n";
   }

   opendir(DP, $child_rule_dir);
   while($rule_file=readdir(DP)){
    chomp($rule_file);
    
    next if($rule_file=~/\./);

    $rule_file="$child_rule_dir/$rule_file";
    print "$div\n$rule_file:\n" if($verbose);
    &read_rules_file();
   }
  }
}
close FD;
}

sub read_rules_file{
open(FR, "$rule_file");
while($rule=<FR>){
  chomp $rule;
  print("$rule\n") if($verbose);
  next if $rule=~/^$/;
  push(@rules, $rule);
}
close FR;
}

sub usage{
$err=shift;
$err && (print $err);
die<<"~USAGE~";
Usage: $progname [-d <directory>] [-h] [-o] [-D]
       -h                     Display this help.

       -v                     Be verbose.

       -l                     Load the rules that are found in the rule
                              directory.

       -d <directory>         Specify the directory that contains rules
                              to be used.  This directory should contain
                              the files containing the rules and a file
                              called 'order.ipf' which specifies the
                              order in which those rules should be
                              added.
                              Defaults to $default_rule_dir

       -o                     Output the list of rules that would be
                              loaded by -l.
~USAGE~
}

In a real mess, didn't really get anywhere with it Sad

Probably needs some explanation - I was thinking about creating a system that would allow you to dynamically add blocking rules for a given IP address.  Moreover I was just trying to tidy up my firewalling system on the FreeBSD machine.  I was getting more and more entries in my main ipf rule file, and starting to build up a set of different 'categories' of rule (for example rules for blocking brute force attacks, spammers, web exploiters/abusers, etc).

I wanted to try and tidy this all up such that when I wanted to add a spammer to my rule set, I'd just have to add that spammer's IP address to a single file.  Then when ipf was restarted, that ip address would automatically be added to the block list.  Same for the other blocking categories.

Unfortunately I never got to finishing it - it turned out to be a little more complicated than I'd bargained on and not really worth the hassle for what I needed.  I've still just got a single file containing all the rules which is fine for me.

Some ideas for you anyway, do you have anything done yet?

 
Logged

~ Jez
kBd
Guest


Email
« Reply #4 on: October 18, 2004, 05:19:35 am »

I believe they call this "deny all"

haha, but seriously...

I realised the need for automation to help users authenticicate themselves to a gateway in a wifi service environment after noticing no one has really made any dynamic or smart auth tools for firewall or routers. So basically all this thing will do is let the users sign on securely without creating a headache for admins... software MUST do this in the future, hopefully programmers with "real" jobs will catch on Tongue

As soon as I finish the spec for this little diddy I'll post a link to it here, you're more than welcome to try implementing some pieces yourself. I think, if I ever do finish the spec, alot of other ppl will see the need for something similar; I hope people take my little thought on it and expand on it. Perl scripts for this kind of stuff are valuable and are greatly needed... do people really play with them and put in feedback on stuff like this? I like the fact that you can script an entirely new feature into a piece of software without adding considerable bloat in the form of messy C or etc.

Thanks for the peek, I have a template to see how to do a few things now, I think it's going to help me learn a little faster in respect to this project

P.S. Im a Lisp whore, it's official. Random fact: The special effects in the movie "The Last Starfighter" were made using a Lisp machine with a bitmap display (mucho $$$$) and a film printer. These machines easily exceeded retail costs of $70,000 USD. Jak & Daxter on the Playstation(2?) was made with Lisp and a game language created inside of Lisp... cool eh?

Be well.
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #5 on: October 18, 2004, 02:02:00 pm »

I've just added another 3 ip addresses to a list of banned IPs and it would have been a lot easier with a simple command line rather than having to yank/paste the 'block in quick on ...' text and then insert the IPs by hand.  I don't even know if it's worth doing this at all, they were brute force SSH attacks that have been so frequent recently all over the place, what ticks me off is the dozens of attempts on the root account, when the root account isn't accessible directly via SSH.  Suppose I should just sit back and be happy in that knowledge Tongue

Crazy lisp facts - how are you learning it?  Got any links?
Logged

~ Jez
kBd
Guest


Email
« Reply #6 on: October 18, 2004, 10:12:55 pm »

If it's that big of a problem you should install PF from ports & packages and then use pfctl   B)

pfctl is very simple and easy to use IMO, it's the sort of command line functionality you talk about

infact, I THOUGHT we were going to use PF ported to NetBSD which was going to make my program easy to write, but if Im going to add support for other firewalls then I guess now's a good time to learn how to do it Tongue

one thing I like about Perl so far is the fact programs are usually short


off topic: Lisp == teh own(results may vary depending on your dialect)  Cheesy  
Logged
munk
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 368


View Profile WWW
« Reply #7 on: October 19, 2004, 08:39:56 pm »

Cool I might investigate pf then.  Good luck!!
Logged

~ Jez
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!