Those of you who are interested, here is the updated version of the .pl
script (I inadvertantly dropped a hash key/value when I edited this
yesterday). It now works as expected. If anyone would like a copy of the
full distro, I can post it to an ftp server if anyone has one.
without further wait....
#!/usr/bin/perl
#---------------------------------------------------------------------------
---#
# script name: patches.pl
# version history
# -----------------------------
# version 0.0.2
# Bugfix to get actual report output pretty. Put parse back
together so
# that it splits all of the fields correctly.
# -----------------------------
# version 0.0.1
# date: May 9, 2002
# author: Joshua R. Sidwell
# [EMAIL PROTECTED]
# comments: This script is designed to leverage HFNetChk.exe from
# www.shavlik.com by creating a completely automated compliance
# check for Servers and Workstations running Microsoft Windows
2000.
# There are no command line options required for running this
script,
# you do however need to ensure that you have the appropriate
# directory structure in place as well as all of the required
files.
# Some of these files are a part of Jason Scott Gessners
# hfnetchk_to_html.pl script. See his site for the most current
# version of his script. In the future, the command line and it's
# options may change, so you need to review his documentation and
# verify that it is setup appropriately. Currently, you need to
# maintain a folder named images in the Results directory to use
his
# images. The directory structure is as follows:
#
# C:\AutoSec
# hfnetchk.exe
# patches.pl
# servers.txt
# t_results.csv
# C:\AutoSec\Results (This folder is populated by the patches.pl
# script at runtime. It will have one file
per
# IP Address that you scan, a results.csv
# file, and a results.html file [generated by
# hfnetchk_to_html.pl by Jason Scott Gessner])
# C:\AutoSec\Results\images
# alert.gif
# Curve_Aid.gif
# exclamation.gif
# info.gif
# LeftCurve_Top.gif
# RightCurve_Top.gif
# C:\AutoSec\html
# html_CSV.pl (renamed hfnetchk_to_html.pl script)
# style-msie.css
#
# If you have any questions/comments regarding the patches.pl
script
# please contact the author at the e-mail address provided above.
#
# In the future, I will be trying to reduce the number of files,
and
# provide this in a small executable file.
#
# --------------------------------CORP
SECTION-------------------------------- #
use Tie::IxHash;
# presize %hash to $num
keys(%hash) = 256;
# Create hash and preserve the order in which it is initialized
tie (%hash, Tie::IxHash);
%hash=(
# heading => 'This script has been created by: ',
buffer1 => '',
buffer2 => '',
co1 => ' _
____ ____',
co2 => ' / \
/ ___|/ ___|',
co3 => ' / _ \
| | \___ \\',
co4 => ' / ___
\| |___ ___) |',
co5 => ' /_/
\_\\\\____||____/',
co6 => ' ____ _
_',
co7 => ' / ___| |
|_ __ _ | |_ ___',
co8 => ' \___ \ |
__|/ _` || __|/ _ \\',
co9 => ' ___) ||
|_| (_| || |_| __/',
co10 => ' |____/ \__|\__,_|
\__|\___|',
co11 => ' ___',
co12 => ' ( _ )',
co13 => ' / _
\/\\',
co14 => ' | (_>
<',
co15 => ' _ \___/\/
_',
co16 => ' | | ___ ___
__ _ | |',
co17 => ' | | / _ \ /
__|/ _` || |',
co18 => ' | |___| (_) ||
(__| (_| || |',
co19 => ' |_____|\___/
\___|\__,_||_|',
co20 => ' ____ _ _ _
___ _ _ ____',
co21 => ' / ___| ___ | | _ _ | |_ (_) ___ _
__ ___ |_ _|| \ | | / ___|',
co22 => ' \___ \ / _ \ | || | | || __|| | / _ \ |
\'_ \ / __| | | | \| || \|',
co23 => ' ___) || (_) || || |_| || |_ | || (_) || |
| |\__ \ _ | | | |\ || |___ _',
co24 => ' |____/ \___/ |_| \__,_| \__||_| \___/ |_|
|_||___/( ) |___||_| \_| \____|(_)',
co25 => '
|/',
buffer3 => '',
buffer4 => '',
borderT => '
******************************************************',
version => ' * version = 0.0.1 created @
10:22:53 on 05.09.2002 *',
program => ' * Files = hfnetchk.exe
*',
reqfile1 => ' * t_reults.csv
*',
reqfile2 => ' * patches.pl
*',
reqfile3 => ' * servers.txt
*',
reqfile4 => ' *
$root\\html\\html_CVS.pl *',
reqfile5 => ' *
$root\\html\\style-msie.css *',
reqdir1 => ' * Dirs = $root
*',
reqdir2 => ' *
$root\\Results *',
reqdir3 => ' * $root\\HTML
*',
borderB => '
******************************************************',
buffer5 => '',
buffer6 => '',
name => ' Joshua R.
Sidwell',
title => ' Network
Engineer, CISSP',
company => ' ACS State & Local
Solutions, Inc.',
phone => ' (714)
796-8383',
email => '
[EMAIL PROTECTED]',
buffer7 => '',
buffer8 => '',
borderT2 => '
******************************************************',
addinfo => ' * Additional work has been
performed by: *',
addinfoN => ' * author: jason
scott gessner *',
addinfoE => ' *
[EMAIL PROTECTED] *',
addinfoPS => ' * script name:
hfnetchk_to_html.pl *',
addinfoLNK => '
*http://www.multiply.org/software/hfnetchk/index.html*',
borderB2 => '
******************************************************',
);
# Print creation information
print "\n\n";
while (($k, $v) = each %hash) {print "$v \n"};
print "\n\n";
# --------------------------------CORP
SECTION-------------------------------- #
# --------------------------------PROG
SECTION-------------------------------- #
# Create an anonymous hash to hold the values from the
C:\AutoSec\servers.txt
# file. This file has the following format:
#
# IPAddress,Domain\UserName,Password
# --OR--
# IPAddress,UserName,Password (for servers that are not part of a Domain)
%hash = (
IP => "",
UN => "",
PW => ""
);
# Here we setup all of the files that we will be using throughout this
script.
# Each one is relative to the $root folder, so it should be trivial to
change
# the location where you place this. The subdirectories, and files on the
# other hand are "hardcoded" relative to the root directory, so you will
need
# to follow the layout given above, or alter the script to suit your fancy.
$root = "c:\\AutoSec";
$html = "$root\\html";
$folder = "$root\\Results";
$output = "$folder\\results.csv";
$sourcefile = "$root\\t_results.csv";
$style = "$html\\style-msie.css";
$outstyle = "$folder\\style-msie.css";
# Here we are copying the t_results.csv and the style-msie.css
# files to the results subdirectory to make sure that they are present.
# The advantage of this is that you can delete the entire contents of the
# results directory when you are done running your report, and simply move
the
# results.html file to your prefered location.
# Thanks to [EMAIL PROTECTED] for the following code snippet. It did
the
# trick and solved one of my frustrations.
# print "Path is $root\nSource is $sourcefile\nDestination is $output\n"; #
Debug Info
if (-e $sourcefile) {
`copy $sourcefile $output`;
}
if (! -e $output) { die "file copy failed\n"; }
if (-e $style) {
`copy $style $outstyle`;
}
if (! -e $outstyle) { die "file copy failed\n";}
# Now we are getting to the meat of the program. Here we are opening the
# servers.txt file that we use to determine what hosts we are going to
check.
open(SERVERS, "<c:\\AutoSec\\servers.txt");
# While we have a line in the servers.txt file, we will execute the
following
# block of code....
while (<SERVERS>) {
# Basic housekeeping, move the current line into the $line variable.
$line = $_;
# Here we are populating the hash that we created earlier with the
IPAddress,
# UserName, and Password.
($hash->{IP},$hash->{UN},$hash->{PW}) = split(/,/, $line) or die
"Could not split the imput line from servers.txt";
# Basic housekeeping, copy the IPAddress from the hash to the $ip variable.
$ip = $hash->{IP};
# Create the variable $imput, and give it the following value (this file is
# used for the individual scans, and can be used individually with the
# original version of hfnetchk_to_html.pl from Jason Scott Gessner.
$imput = "$folder\\$ip.txt";
# Here we are calling the external hfnetchk.exe program with the
information
# from the servers.txt file that we pulled into the hash. You may wish to
# change some of these settings to fit your environment. See the relevant
# documentation on the Microsoft site or by typing hfnetchk.exe /?
# `hfnetchk.exe -i $hash->{IP} -z -v -t 128 -o tab -b -f $imput -u
$hash->{UN} -p $hash->{PW}`;
`hfnetchk.exe -i $hash->{IP} -z -v -t 128 -o tab -f $imput -u
$hash->{UN} -p $hash->{PW}`;
# `hfnetchk.exe -i $hash->{IP} -v -t 128 -o tab -f $imput -u
$hash->{UN} -p $hash->{PW}`;
# We now use the output file $ip.txt that we just created as our imput file
# for another hash. This one is designed to convert the standard tab
delimited
# output of hfnetchk.exe to a comma seperated file (*.csv)
open(SOURCE,"<$imput");
# The hash receives the split information representing the
MachineName,Product,
# Bulletin,Q Number, and Reason
my %info = (
MN => "",
P => "",
B => "",
QN => "",
R => "",
S => ""
);
# While we have a line of text to process from our output file, we take
each
# line and place it into the $text variable to do something with it.
while (<SOURCE>) {
$text = $_;
# If the line begins with "Machine Name," we want to skip it since it is
# redundant.
if (m/Machine Name/g) {
next;
} else {
# If it does not match with "Machine Name" we want to split the line into
its
# different parts. So, to capture this, we open the $output filehandle and
# print the hash with commas seperating the now split fields.
open(OUTPUT,">>$output");
($info->{MN},$info->{P},$info->{B},$info->{QN},$info->{R},$info->{S}) =
split(/ /, $text);
printf OUTPUT "$info->{MN}" . "," . "$info->{P}" . "," .
"$info->{B}" . "," . "$info->{QN}" . "," . "$info->{R}" . "," .
"$info->{S}";
close(OUTPUT);
}
}
close SOURCE;
}
close SERVERS;
# --------------------------------PROG
SECTION-------------------------------- #
# --------------------------------HTML
FORMAT-------------------------------- #
# This is a call to an external perl script that parses the results.csv
file
# and outputs it to a formatted HTML file with all the relevant links to
the
# Microsoft.com site. Thanks to Jason Scott Gessner for writing this
script.
`$html\\html_CSV.pl $folder\\results.csv $folder\\results.html cvs
yes`;
# --------------------------------HTML
FORMAT-------------------------------- #
Joshua Sidwell
Network Engineer, CISSP
1400 S. Grand Ave
Santa Ana, CA 92705
(714) 796-8383
[EMAIL PROTECTED]
--------- Email Confidentiality Notice -------
The information in this email may be confidential, proprietary and/or
sensitive and is intended only for use by the entity or individual to whom
it is addressed. If you, the reader of this email and/or its attachments,
are not the intended recipient, you are hereby notified that any
dissemination, distribution, publishing, modification, storage or copying of
this email or any of its attachments is strictly prohibited. If you have
received this communication in error, please immediately notify the
[EMAIL PROTECTED] and destroy all copies of this message along with any
attachments.
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs