openvas-plugins-dfsg (1:20100705-1) 25_scripts_update.dpatch

Summary

 extra/describe-openvas-plugin |  145 +++++++++++++++++++++++++++++++++---------
 1 file changed, 115 insertions(+), 30 deletions(-)

    
download this patch

Patch contents

#! /bin/sh /usr/share/dpatch/dpatch-run
## 25_scripts_update.dpatch by  <jfs@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Update tools based on latest content available

@DPATCH@
--- openvas-plugins-dfsg-1.0.7.orig/extra/describe-openvas-plugin
+++ openvas-plugins-dfsg-1.0.7/extra/describe-openvas-plugin
@@ -5,12 +5,12 @@
 #
 # Written by George A. Theall, theall@tifaware.com
 #
-# Copyright (c) 2003 - 2005, George A. Theall. All rights reserved.
+# Copyright (c) 2003-2009, George A. Theall. All rights reserved.
 #
 # This module is free software; you can redistribute it and/or modify
 # it under the same terms as Perl itself.
 #
-# $Id: describe-openvas-plugin 112 2006-05-13 21:10:10Z labanm $
+# $Id: describe-openvas-plugin 31 2009-06-27 13:48:34Z theall $
 # ---------------------------------------------------------------------
 
 
@@ -22,23 +22,19 @@
 =head1 SYNOPSIS
 
   # Describe assorted NASL plugins related to MS SQL.
-  describe-openvas-plugin /usr/local/lib/openvas/plugins/mssql*.nasl
-
-  # Describe assorted NASL plugins related to Zope using 
-  #   French strings whenever possible.
-  describe-openvas-plugin -l francais /usr/local/lib/openvas/plugins/zope*.nasl
+  describe-openvas-plugin /usr/local/lib/nessus/plugins/mssql*.nasl
 
   # Show how the script parses the specified NASL plugin.
   describe-openvas-plugin -d wip.nasl
 
   # Report CVE ID(s) for all Oracle-related plugins.
-  describe-openvas-plugin -f cve_id /usr/local/lib/openvas/plugins/oracle*.nasl
+  describe-openvas-plugin -f cve_id /usr/local/lib/nessus/plugins/oracle*.nasl
 
   # Same as above but avoid line-wrap.
-  describe-openvas-plugin -f cve_id -w 999 /usr/local/lib/openvas/plugins/oracle*.nasl
+  describe-openvas-plugin -f cve_id -w 999 /usr/local/lib/nessus/plugins/oracle*.nasl
 
   # Report all information except the description for all Apache-related plugins.
-  describe-openvas-plugin -f _all_ -f '!description' /usr/local/lib/openvas/plugins/apache*.nasl
+  describe-openvas-plugin -f _all_ -f '!description' /usr/local/lib/nessus/plugins/apache*.nasl
 
 
 =head1 DESCRIPTION
@@ -49,7 +45,7 @@
 of interest from the various C<script_*> functions in the its
 description block.  As such, it only works with plugins written in NASL
 (C<*.nasl>), not NASL include files (C<*.inc>) or plugins written in C
-(C<*.nes>).  It does not require access to a openvas server but does
+(C<*.nes>).  It does not require access to a OpenVAS server but does
 require read access to the plugin. 
 
 The decision about what information to report can be controlled either
@@ -61,13 +57,6 @@
 controlled by setting C<@func_order> in this script; there is no way to
 change it via the commandline. 
 
-Some of the descriptive information is available in languages other than
-English -- typically French, but occasionally German and Portuguese. 
-You can control the language used by adjusting the variable C<$lang> in
-the source or with the option C<--language>; if information in the
-desired language is not available, this script defaults to English, like
-the NASL interpreter. 
-
 B<describe-openvas-plugin> is written in Perl.  It should work on any
 system with Perl 5.005 or better.  It also requires the following Perl
 modules:
@@ -121,7 +110,7 @@
 
 =head1 SEE ALSO
 
-L<http://cgi.nessus.org/plugins/>,
+L<http://www.nessus.org/plugins/index.php?view=all>,
 L<http://www.nessus.org/doc/nasl2_reference.pdf>,
 L<http://www.tifaware.com/perl/describe-nessus-plugin/>. 
 
@@ -142,13 +131,15 @@
 # Initialize variables.
 $| = 1;
 my $DEBUG = 0;
-my %cat_labels = (                      # see openvas-server/doc/WARNING.En and
+my %cat_labels = (                      # see nessus-core/doc/WARNING.En and
                                         #     send_plug_info() in 
-                                        #     openvas-server/openvasd/comm.c
+                                        #     nessus-core/nessusd/comm.c
     'ACT_ATTACK'                => 'attack',
     'ACT_DENIAL'                => 'denial',
     'ACT_DESTRUCTIVE_ATTACK'    => 'destructive_attack',
-    'ACT_END'                   => 'unknown',
+    'ACT_END'                   => 'end',
+    'ACT_END2'                  => 'end2',
+    'ACT_INIT'                  => 'init',
     'ACT_FLOOD'                 => 'flood',
     'ACT_GATHER_INFO'           => 'infos',
     'ACT_KILL_HOST'             => 'kill_host',
@@ -230,7 +221,6 @@
 # Process commandline arguments.
 my %options = (
     'debug'       => \$DEBUG,
-    'language'    => \$lang,
 );
 Getopt::Long::Configure('bundling');
 GetOptions(
@@ -238,7 +228,6 @@
     'debug|d!',
     'functions|f=s@',
     'help|h|?!',
-    'language|l=s',
     'width|w=i',
 ) or $options{help} = 1;
 $0 =~ s/^.+\///;
@@ -258,9 +247,6 @@
           "                               'require_udp_ports', 'risk', 'summary',\n",
           "                               'timeout', 'version', 'xref', and '_all_'.\n",
           "                             Functions prefixed with '!' are ignored.\n",
-          "  -l, --language <lang>      Use <lang> as language preference; must be one of\n",
-          "                               'deutsch', 'english', 'francais', and\n",
-          "                               'portugues'.\n",
           "  -w, --width <width>        Use <width> as the screen width (for controlling\n",
           "                               line wrap).\n";
     exit(9);
@@ -343,7 +329,7 @@
 
     # Parse description info.
     warn "debug:   parsing description info.\n" if $DEBUG;
-    my %info;
+    my (%attrs, %info);
     # nb: spurious leading characters are removed since extract_bracketed()
     #     expects string to start with '(' in order to isolate the argument.
     while ($desc =~ s/^(?s).*?script_(\w+)\s*\(/(/) {
@@ -360,7 +346,11 @@
                     # nb: name is used in outputing info about add_preference.
                     ($func eq 'name' and $_ eq 'add_preference') or
                     # nb: risk is embedded in description, not a separate function.
-                    ($func eq 'description' and $_ eq 'risk')
+                    ($func eq 'description' and $_ eq 'risk') or
+                    # nb: set_attribute is used to build the description.
+                    ($func eq 'set_attribute' and ($_ eq 'description' or $_ eq 'risk')) or
+                    # nb: and end_attribute to finish it up.
+                    $func eq 'end_attributes'
                 ), 
                 @funcs
             )
@@ -372,6 +362,23 @@
             $desc,
             '()',
         );
+
+        # Handle new compatibility API.
+        if ($func eq 'end_attributes') {
+          $func = 'description';
+          $argstr = "";
+
+          foreach my $attr ('Synopsis', 'Description', 'See also', 'Solution', 'Risk factor') {
+            $attrs{$attr} = "None" if ($attr eq 'Risk factor' and !exists($attrs{$attr}));
+
+            $argstr .= (length($argstr) ? "\n\n" : "") . 
+                       $attr . " :\n\n" . $attrs{$attr} if (exists $attrs{$attr});
+          }
+          $info{$func} = $argstr;
+          warn "debug:       arg string at end is '$argstr'.\n" if $DEBUG;
+          next;
+        }
+
         unless ($argstr and $argstr =~ s/^(?s)\(\s*(.+)\s*\)$/$1/) {
             warn "*** Can't identify arg string for '$func' in '$plugin'! ***\n";
             next;
@@ -450,6 +457,50 @@
                 next;
             }
         }
+        elsif ($func eq 'set_attribute') {
+            if (exists($named_args{attribute}) and exists($named_args{value})) {
+                my $attr = $named_args{attribute};
+                my $val = $named_args{value};
+
+                if ($attr eq 'cvss_vector') {
+                  my $score = &calc_cvss($val);
+                  if ($score)
+                  {
+                    my $risk;
+                    $risk = "Critical" if ($score == 10);
+                    $risk = "High"     if ($score >= 7.0 and $score < 10);
+                    $risk = "Medium"   if ($score >= 4.0 and $score < 7);
+                    $risk = "Low"      if ($score >= 0 and $score < 4);
+                    $risk = "None"     if ($score == 0);
+
+                    $attr = "Risk factor";
+                    $val = "$risk / CVSS Base Score : " . $score . " (" . $val . ")";
+
+                    $info{risk} = $val;
+                  }
+                }
+
+                $attr =~ s/^(.)(.+)$/\U$1\E$2/;
+                $attr =~ s/_/ /;
+                warn "debug:       attribute for set_attribute is '$attr'\n" if $DEBUG;
+
+                # Removing newlines except those separating paragraphs.
+                $val =~ s/([^\n])\n([^\n])/$1 $2/sg;
+                warn "debug:       value for set_attribute is '$val'\n" if $DEBUG;
+
+                if ($attr eq 'See also' and exists $attrs{$attr}) {
+                  $attrs{$attr} .= "\n" . $val;
+                }
+                else {
+                  $attrs{$attr} = $val;
+                }
+                next;
+            }
+            else {
+                warn "*** Can't handle arguments for 'set_attribute' in '$plugin'! ***\n";
+                next;
+            }
+        }
 
         # Regenerate $argstr.
         $argstr = join(", ", @args);
@@ -457,7 +508,7 @@
         # Fix up $argstr for a few functions.
         $argstr = $cat_labels{$argstr}
             if ($func eq 'category' and exists $cat_labels{$argstr});
-        $argstr =~ s/^\$Revision: 112 $$/$1/i if ($func eq 'version');
+        $argstr =~ s/^\$Revision: (\S+) \$$/$1/i if ($func eq 'version');
 
         # Identify risk if desired.
         #
@@ -731,3 +782,37 @@
     warn "debug eval_expr: result is '$expr'.\n" if $DEBUG;
     return $expr;
 }
+
+
+############################################################################
+# Calculate a CVSS base score.
+sub calc_cvss {
+  my($vector) = shift;
+
+  my $score = 0;
+  # CVSS v2
+  if ($vector =~ /^CVSS2#AV:(L|A|N)\/AC:(L|M|H)\/Au:(N|S|M)\/C:(N|P|C)\/I:(N|P|C)\/A:(N|P|C)$/) {
+    my($av, $ac, $au, $c, $i, $a) = ($1, $2, $3, $4, $5, $6);
+    $av = (0.395*($av eq 'L') + 0.646*($av eq 'A') + 1.0*($av eq 'N'));
+    $ac = (0.35*($ac eq 'H') + 0.61*($ac eq 'M') + 0.71*($ac eq 'L'));
+    $au = (0.450*($au eq 'M') + 0.560*($au eq 'S') + 0.704*($au eq 'N'));
+    $c = (0.275*($c eq 'P') + 0.660*($c eq 'C'));
+    $i = (0.275*($i eq 'P') + 0.660*($i eq 'C'));
+    $a = (0.275*($a eq 'P') + 0.660*($a eq 'C'));
+
+    my $fx = ($c == 0 && $i == 0 && $a == 0) ? 0 : 1.176;
+
+    $score = 
+      (
+        0.6*(10.41*(1-(1-$c)*(1-$i)*(1-$a))) +
+        0.4*(20*$ac*$au*$av) +
+        -1.5
+      ) * $fx;
+    $score = sprintf("%.1f", $score);
+
+    return $score;
+  }
+  else {
+    warn "*** '$vector' is not a valid vector for CVSS base score! ***\n";
+  }
+}