ID to pluginname Perl gizmo
Michel Arboi <[email protected]>
| Newsgroups | gmane.comp.security.nessus.general |
|---|---|
| Organization | nessus.org |
| Message-ID | <20080513222756.36bbd0c6@fr-75-02-06-037> |
It is sometimes useful to check the source of a plugin when you are browsing a report, but the reports only contain script IDs, not file names. You can have all this on www.nessus.org, but 1) I have personal scripts that are not in the CVS repository, 2) I am not always connected to Internet. fgrep -r "script_id(XXX);" /opt/nessus/lib/nessus/plugins/ works but is slow. Here is a small Perl script. You may have to edit it to change some paths. When it is executed the first time, it fills a DB file with the script IDs & names. Usage is simple. For example: $ nessusid.pl 11030 12042 11030 apache_chunked_encoding.nasl 12042 reviewpost_sql.nasl $ -- Michel Arboi GPG Key ID: 0x4A44A08307436AAC SOGETI IS / ESEC / 6-8 rue Duret / 75784 Paris Cedex 16 / France http://esec.fr.sogeti.com/ _______________________________________________ Nessus mailing list [email protected] http://mail.nessus.org/mailman/listinfo/nessus
nessusid.pl
(application/x-perl, 1.3 KB)
#!/usr/bin/perl -w
my $nessusid_db_dir = $ENV{HOME} . "/.nessusid";
my $nessus_plugins_dir;
foreach $d ("/opt/nessus/lib/nessus/plugins",
$ENV{HOME} . "/NESSUS/nessus-plugins/scripts")
{
if (-d $d and -f $d . "/find_service1.nasl") {
$nessus_plugins_dir = $d;
last;
}
}
die "Could not find plugin directory" if ! $nessus_plugins_dir;
die "$nessusid_db_dir is not a directory or does not exist"
if ! -d $nessusid_db_dir;
use DB_File;
my %id;
$id_dbf = $nessusid_db_dir . "/id2fname.db";
$db_mtime = &get_mtime($id_dbf);
$db_mtime = 1 if (! $db_mtime);
tie %id, 'DB_File', $id_dbf, O_RDWR|O_CREAT, 0644
or die "$id_dbf: $!";
foreach $file (glob("$nessus_plugins_dir/*.nasl")) {
my $mt = &get_mtime($file);
my $name = $file;
$name = $1 if ($file =~ m,.*/([^/]+\.nasl)$,);
if ($mt >= $db_mtime) {
open NASL, "<$file" or die "$file: $!";
while (<NASL>) {
if (m/script_id *\( *([0-9]+) *\) *;/) {
$id{$1} = $name;
# print STDERR ">> $1\t$name\n";
last;
}
}
close NASL;
}
}
foreach $id (@ARGV) {
print "$id\t$id{$id}\n" if exists $id{$id};
}
untie %id;
sub get_mtime {
my $filename = $_[0];
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat($filename)
or warn "$filename: $!";
return $mtime;
}