Changeset 271


Ignore:
Timestamp:
01/26/2010 05:25:08 AM (3 years ago)
Author:
sullo
Message:

More database syntax checks. Ticket #111.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/nikto_core.plugin

    r270 r271  
    10441044sub dbcheck 
    10451045{ 
    1046  my @dbs=qw/db_404_strings  db_outdated  db_realms  db_tests  db_variables/; 
     1046 my @dbs=qw/db_headers db_httpoptions db_multiple_index db_server_msgs db_subdomains db_favicon db_embedded db_404_strings  db_outdated  db_realms  db_tests  db_variables/; 
    10471047 my $prefix = $_[0]; 
    1048  
    10491048 if ($prefix eq ""  )  { nprint "\n-->\tNikto Databases\n"; } 
    10501049 if ($prefix eq "u"  ) { nprint "\n-->\tUser Databases\n"; } 
     
    10551054   if (!-r $filename) { next; } 
    10561055   open(IN,"<$filename") || die nprint("+ ERROR: Can't open \"$filename\":$!\n"); 
    1057     
    10581056   nprint "Syntax Check: $filename\n"; 
    10591057    
    10601058   if ($file eq 'db_outdated')  
    10611059     { 
    1062        foreach $line (<IN>) 
    1063          { 
     1060       foreach $line (<IN>) { 
    10641061           $line =~ s/^\s+//; 
    10651062           if ($line =~ /^\#/) { next; } 
     
    10671064           if ($line eq "") { next; } 
    10681065           my @L=parse_csv($line); 
    1069            if ($line !~ /^\".*\"\,\".*\"\,\".*\"$/) { print STDERR "\t+ ERROR: Invalid syntax ($#L): $line\n"; next; } 
    10701066           if ($#L ne 3) { print STDERR "\t+ ERROR: Invalid syntax ($#L): $line\n"; next; } 
    10711067           $ENTRIES{"$L[0]"}++; 
    10721068         } 
    1073  
    10741069          foreach $entry (keys %ENTRIES) { if ($ENTRIES{$entry} > 1) { print STDERR "\t+ ERROR: Duplicate ($ENTRIES{$entry}): $entry\n"; } } 
    10751070          nprint "\t" . keys(%ENTRIES) . " entries\n"; 
     
    10781073     { 
    10791074       my %ENTRIES; 
    1080        foreach my $line (<IN>) 
    1081          { 
     1075       foreach my $line (<IN>) { 
    10821076           if ($line !~ /^\"/)  { next; } 
    10831077           my @L=parse_csv($line); 
     
    10881082           if (($L[3] =~ /^\@CG/) && ($L[3] !~ /^\@CGIDIRS/)) { print STDERR "\t+ ERROR: Possible \@CGIDIRS misspelling: $line"; } 
    10891083           $ENTRIES{"$L[3],$L[4],$L[5],$L[6],$L[7],$L[8],$L[9],$L[11],$L[12]"}++; 
    1090         } 
    1091  
     1084           if ((count_fields($line, 1) ne 12) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line\n"; } 
     1085         } 
    10921086       foreach $entry (keys %ENTRIES) { if ($ENTRIES{$entry} > 1) { print STDERR "\t+ ERROR: Duplicate ($ENTRIES{$entry}): $entry\n"; } } 
    10931087       nprint "\t" . keys(%ENTRIES) . " entries\n"; 
     
    10961090     { 
    10971091       my $ctr=0; 
    1098        foreach $line (<IN>) 
    1099          { 
     1092       foreach $line (<IN>) { 
    11001093           if ($line !~ /^\@/)  { next; } 
    11011094           if ($line !~ /^\@.+\=.+$/i ) { print STDERR "\t+ ERROR: Invalid syntax: $line\n"; } 
     
    11071100     { 
    11081101       my $ctr=0; 
    1109        foreach $line (<IN>) 
    1110          { 
    1111            if ($line !~ /^\"/)  { next; } 
    1112            chomp($line); 
    1113            my @L=parse_csv($line); 
    1114            if ($#L ne 4) { print STDERR "\t+ ERROR: Invalid syntax: $line\n"; } 
     1102       foreach $line (<IN>) { 
     1103           if ((count_fields($line, 1) ne 4) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
    11151104           $ctr++; 
    11161105         } 
     
    11201109     { 
    11211110       my $ctr=0; 
    1122        foreach $line (<IN>) 
    1123          { 
     1111       foreach $line (<IN>) { 
    11241112           # not really any syntax to check 
    11251113           $ctr++; 
     
    11271115        nprint "\t$ctr entries\n"; 
    11281116     } 
     1117   elsif ($file eq 'db_embedded')  
     1118     { 
     1119       my $ctr=0; 
     1120       foreach $line (<IN>) { 
     1121           if ((count_fields($line, 1) ne 4) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1122           $ctr++; 
     1123         } 
     1124        nprint "\t$ctr entries\n"; 
     1125     } 
     1126   elsif ($file eq 'db_favicon')  
     1127     { 
     1128       my $ctr=0; 
     1129       foreach $line (<IN>) { 
     1130           if ((count_fields($line, 1) ne 2) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1131           $ctr++; 
     1132         } 
     1133        nprint "\t$ctr entries\n"; 
     1134     } 
     1135   elsif ($file eq 'db_headers') 
     1136     { 
     1137       my $ctr=0; 
     1138       foreach $line (<IN>) { 
     1139           if ((count_fields($line) ne 0) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1140           $ctr++; 
     1141         } 
     1142        nprint "\t$ctr entries\n"; 
     1143     } 
     1144   elsif ($file eq 'db_httpoptions') 
     1145     { 
     1146       my $ctr=0; 
     1147       foreach $line (<IN>) { 
     1148           if ((count_fields($line, 1) ne 3) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1149           $ctr++; 
     1150         } 
     1151        nprint "\t$ctr entries\n"; 
     1152     } 
     1153   elsif ($file eq 'db_multiple_index') 
     1154     { 
     1155       my $ctr=0; 
     1156       foreach $line (<IN>) { 
     1157           if ((count_fields($line) ne 0) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1158           $ctr++; 
     1159         } 
     1160        nprint "\t$ctr entries\n"; 
     1161     } 
     1162   elsif ($file eq 'db_server_msgs') 
     1163     { 
     1164       my $ctr=0; 
     1165       foreach $line (<IN>) { 
     1166           if ((count_fields($line, 1) ne 2) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1167           $ctr++; 
     1168         } 
     1169        nprint "\t$ctr entries\n"; 
     1170     } 
     1171   elsif ($file eq 'db_subdomains') 
     1172     { 
     1173       my $ctr=0; 
     1174       foreach $line (<IN>) { 
     1175           if ((count_fields($line, 1) ne 1) && (count_fields($line) ne '')) { print STDERR "\t+ ERROR: Invalid syntax: $line"; } 
     1176           $ctr++; 
     1177         } 
     1178        nprint "\t$ctr entries\n"; 
     1179     } 
    11291180 
    11301181   close(IN);   
     
    11351186 nprint "\n"; 
    11361187 exit; 
     1188} 
     1189############################################################################### 
     1190sub count_fields 
     1191{ 
     1192 my $line =$_[0] || return; 
     1193 my $checkid=$_[1] || 0; 
     1194 if ($line !~ /^\"/) { return; } 
     1195 chomp($line); 
     1196 $line =~ s/\s+$//; 
     1197 if ($line eq '') { return; } 
     1198 my @L=parse_csv($line); 
     1199 if ($checkid && ($L[0] ne 'nikto_id') && (($L[0] =~ /[^0-9]/) || ($L[0] eq ''))) { return -1; } 
     1200 return $#L; 
    11371201} 
    11381202############################################################################### 
Note: See TracChangeset for help on using the changeset viewer.