110
110
my ($Process , $hmatch , $bmatch , $sid_msg_version , $skip_verify ,
111
111
$proxy_workaround );
112
112
my $Sostubs = 1;
113
+ my $Snortv3 = 0;
113
114
114
115
# verbose and quiet control print()
115
116
# default values if not set otherwise in getopt
@@ -279,7 +280,7 @@ sub temp_cleanup {
279
280
# subroutine to extract the files to a temp path so that we can do what we need to do..
280
281
sub rule_extract {
281
282
my ($rule_file , $temp_path , $Distro , $arch , $Snort ,
282
- $Sorules , $ignore , $prefix )
283
+ $Sorules , $ignore , $prefix , $Snortv3 )
283
284
= @_ ;
284
285
285
286
# special case to bypass file operations when -nPT are specified
@@ -324,6 +325,14 @@ sub rule_extract {
324
325
$tar -> remove(" so_rules/precompiled/$Distro /$arch /$Snort /$_ " );
325
326
}
326
327
}
328
+ my $sofile_pat_base = " ^so_rules\/ precompiled\/ " ;
329
+ if ($Snortv3 == 0) {
330
+ $sofile_pat_base = $sofile_pat_base . " ($Distro )\/ ($arch )\/ ($Snort )\/ " ;
331
+ }
332
+ else {
333
+ $sofile_pat_base = $sofile_pat_base . " ($Distro )-($arch )\/ " ;
334
+ }
335
+ my $sofile_pat = $sofile_pat_base . " .*\. so" ;
327
336
my @files = $tar -> get_files();
328
337
foreach (@files ) {
329
338
my $filename = $_ -> name;
@@ -344,12 +353,12 @@ sub rule_extract {
344
353
}
345
354
elsif ($Sorules
346
355
&& $filename
347
- =~ / ^so_rules \/ precompiled \/ ( $Distro ) \/ ( $arch ) \/ ( $Snort ) \/ .* \. so /
356
+ =~ m / $sofile_pat /
348
357
&& -d $Sorules
349
358
&& !$Textonly )
350
359
{
351
360
$singlefile
352
- =~ s /^so_rules \/ precompiled \/ ($Distro) \/ ($arch) \/ ($Snort) \/ // ;
361
+ =~ s /$sofile_pat_base // ;
353
362
$tar -> extract_file($filename , $Sorules . $singlefile );
354
363
print " \t Extracted: $Sorules$singlefile \n "
355
364
if ($Verbose && !$Quiet );
@@ -813,20 +822,29 @@ sub read_rules {
813
822
814
823
# # sub to generate stub files using the snort --dump-dynamic-rules option
815
824
sub gen_stubs {
816
- my ($Snort_path , $Snort_config , $Sostubs ) = @_ ;
825
+ my ($Snort_path , $Snort_config , $Sostubs , $Snortv3 , $Sorules ) = @_ ;
817
826
print " Generating Stub Rules....\n " if !$Quiet ;
818
827
unless (-B $Snort_path ) {
819
828
Help(" $Snort_path is not a valid binary file" );
820
829
}
821
830
if (-d $Sostubs && -B $Snort_path && -f $Snort_config ) {
831
+ my $cmd = " " ;
832
+ if ($Snortv3 ) {
833
+ $cmd = " $Snort_path -c $Snort_config --plugin-path $Sorules --dump-dynamic-rules > $Sostubs /allso.rules" ;
834
+ }
835
+ else {
836
+ $cmd = " $Snort_path -c $Snort_config --dump-dynamic-rules=$Sostubs "
837
+ }
822
838
if ($Verbose && !$Quiet ) {
823
839
print (
824
- " \t Generating shared object stubs via:$Snort_path -c $Snort_config --dump-dynamic-rules= $Sostubs \n "
840
+ " \t Generating shared object stubs via: $cmd \n "
825
841
);
826
842
}
827
- open (FH,
828
- " $Snort_path -c $Snort_config --dump-dynamic-rules=$Sostubs 2>&1|"
829
- );
843
+ if (!$Snortv3 ) {
844
+ open (FH, " $cmd 2>&1|" );
845
+ } else {
846
+ open (FH, " |-" , " $cmd " );
847
+ }
830
848
while (<FH>) {
831
849
print " \t $_ " if $_ =~ / Dumping/i && ($Verbose && !$Quiet );
832
850
next unless $_ =~ / (err|warn|fail)/i ;
@@ -1902,6 +1920,12 @@ sub check_file_dir {
1902
1920
$Textonly = 1 unless $Snort ;
1903
1921
}
1904
1922
1923
+ # Check if version begins with 3
1924
+ if (ord ($Snort ) == 51) {
1925
+ $Snortv3 = 1;
1926
+ if ($arch ) {$arch =~ s / x86-64/ x64/ ;}
1927
+ }
1928
+
1905
1929
if (!$local_rules && ($Config_info {' local_rules' })) {
1906
1930
$local_rules = ($Config_info {' local_rules' });
1907
1931
}
@@ -1965,6 +1989,7 @@ sub check_file_dir {
1965
1989
}
1966
1990
if ($SigName ) { print " \t Sending signal Flag is Set: $SigName \n " ; }
1967
1991
if ($Snort ) { print " \t Snort Version is: $Snort \n " ; }
1992
+ if ($Snortv3 ) { print " \t Snort V3 detected & processing enabled\n " ; }
1968
1993
if ($Snort_config ) { print " \t Snort Config File: $Snort_config \n " ; }
1969
1994
if ($Snort_path ) { print " \t Snort Path is: $Snort_path \n " ; }
1970
1995
if ($Sorules ) { print " \t SO Output Path is: $Sorules \n " ; }
@@ -2212,6 +2237,7 @@ BEGIN
2212
2237
' Distro' => $Distro ,
2213
2238
' arch' => $arch ,
2214
2239
' Snort' => $Snort ,
2240
+ ' Snortv3' => $Snortv3 ,
2215
2241
' Sorules' => $Sorules ,
2216
2242
' ignore_files' => $ignore_files ,
2217
2243
' prefix' => $prefix ,
@@ -2243,7 +2269,8 @@ BEGIN
2243
2269
$filelist -> {$_ }{Snort },
2244
2270
$filelist -> {$_ }{Sorules },
2245
2271
$filelist -> {$_ }{ignore_files },
2246
- $filelist -> {$_ }{prefix }
2272
+ $filelist -> {$_ }{prefix },
2273
+ $filelist -> {$_ }{Snortv3 }
2247
2274
);
2248
2275
}
2249
2276
}
@@ -2276,7 +2303,7 @@ BEGIN
2276
2303
$prefix = " Snort-Community-"
2277
2304
if $base_url =~ / snort\. org.+community/ ;
2278
2305
rule_extract($rule_file , $temp_path , $Distro ,
2279
- $arch , $Snort , $Sorules , $ignore_files , $prefix )
2306
+ $arch , $Snort , $Sorules , $ignore_files , $prefix , $Snortv3 )
2280
2307
if !$grabonly ;
2281
2308
}
2282
2309
}
@@ -2306,7 +2333,7 @@ BEGIN
2306
2333
&& $Process )
2307
2334
{
2308
2335
gen_stubs($Snort_path , $Snort_config ,
2309
- " $temp_path " . " tha_rules/so_rules/" );
2336
+ " $temp_path " . " tha_rules/so_rules/" , $Snortv3 , $Sorules );
2310
2337
read_rules(\%rules_hash , " $temp_path " . " tha_rules/so_rules/" ,
2311
2338
$local_rules );
2312
2339
}
0 commit comments