Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions scripts/multi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,30 @@ sub go {

} elsif (not $daddy) {

my(@args);
my($zcat);
my($ngrep_status);

$SIG{INT} = 'IGNORE';
sigprocmask(SIG_UNBLOCK, $old_sig_set);

system("zcat $rule{'file'} | " .
"ngrep -qtI - $rule{'regex'} $rule{'filter'} 2>&1 > " .
"ngrepped.$rule_name");

exit;
# Rule fields are untrusted. Keep them out of a shell command.
$zcat = open(ZCAT, "-|");
if (not defined $zcat) {
warn "[$rule_name] zcat fork() error: $!\n";
exit 1;
} elsif (not $zcat) {
exec "zcat", "--", $rule{'file'};
warn "[$rule_name] zcat exec() error: $!\n";
exit 1;
}

open(STDIN, "<&ZCAT") || die "[$rule_name] couldn't read zcat output: $!\n";
open(STDOUT, ">ngrepped.$rule_name") || die "[$rule_name] couldn't open output: $!\n";
$ngrep_status = system("ngrep", "-qtI", "-", $rule{'regex'}, $rule{'filter'});
close(ZCAT);
waitpid($zcat, 0);

exit($ngrep_status == -1 ? 1 : $ngrep_status >> 8);

} else {

Expand Down Expand Up @@ -105,10 +119,18 @@ sub go {
die "Rules file $rules_file empty, exiting.\n";
}

%rules = map { chomp(local(@fields) = split / /, $_);
$fields[0] => { "file" => $fields[1],
"regex" => $fields[2],
"filter" => $fields[3] }; } @lines;
foreach (@lines) {
chomp;
my(@fields) = split /\s+/, $_, 4;

die "Malformed rule: $_\n" unless scalar(@fields) == 4;
die "Invalid rule name: $fields[0]\n"
unless $fields[0] =~ /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;

$rules{$fields[0]} = { "file" => $fields[1],
"regex" => $fields[2],
"filter" => $fields[3] };
}
@rules = keys %rules;

print "Hi, I'm ngrepper, and here we go.\n";
Expand All @@ -126,4 +148,3 @@ sub go {

exit;