| 1 | #!/usr/local/bin/perl | ||
| 2 | # | ||
| 3 | # $Id: sinfp3-plugin-add-signature.pl 19 2012-09-11 12:40:54Z gomor $ | ||
| 4 | # | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Getopt::Std; | ||
| 9 | my %opts; | ||
| 10 | getopts('s:6f:tnhvl:p', \%opts); | ||
| 11 | |||
| 12 | if ($opts{h} || !$opts{f} && !$opts{n}) { | ||
| 13 | print "\n -- SinFP3 plugin add signature --\n". | ||
| 14 | "\n". | ||
| 15 | "Usage: $0 [-f pcapFile | -n] [-s signatureFile] [-p] [-6] [-t] [-h] [-v]\n". | ||
| 16 | "\n". | ||
| 17 | " -h this help\n". | ||
| 18 | " -p passive signature i/o active\n". | ||
| 19 | " -v be verbose\n". | ||
| 20 | " -l N verbose level\n". | ||
| 21 | " -f file pcap file to read\n". | ||
| 22 | " -n signature in Nessus format\n". | ||
| 23 | " -s db signature file to use\n". | ||
| 24 | " -6 this is an IPv6 signature\n". | ||
| 25 | " -t flag to indicate this is a trusted signature source\n". | ||
| 26 | ""; | ||
| 27 | exit(0); | ||
| 28 | } | ||
| 29 | |||
| 30 | use Net::SinFP3; | ||
| 31 | use Net::SinFP3::Global; | ||
| 32 | use Net::SinFP3::DB::SinFP3; | ||
| 33 | #use Net::SinFP3::Input::Nessus; | ||
| 34 | use Net::SinFP3::Input::Pcap; | ||
| 35 | use Net::SinFP3::Mode::Active; | ||
| 36 | use Net::SinFP3::Mode::Passive; | ||
| 37 | use Net::SinFP3::Mode::Null; | ||
| 38 | use Net::SinFP3::Search::Active; | ||
| 39 | use Net::SinFP3::Search::Passive; | ||
| 40 | use Net::SinFP3::Output::AddSignature; | ||
| 41 | use Net::SinFP3::Output::AddSignatureP; | ||
| 42 | use Net::SinFP3::Log::Console; | ||
| 43 | |||
| 44 | $opts{6} ||= 0; | ||
| 45 | |||
| 46 | my $log = Net::SinFP3::Log::Console->new( | ||
| 47 | level => $opts{v} ? ($opts{l} || 1) : 0, | ||
| 48 | ); | ||
| 49 | |||
| 50 | my $global = Net::SinFP3::Global->new( | ||
| 51 | log => $log, | ||
| 52 | ipv6 => $opts{6}, | ||
| 53 | ); | ||
| 54 | |||
| 55 | # Load database | ||
| 56 | my $db = Net::SinFP3::DB::SinFP3->new( | ||
| 57 | global => $global, | ||
| 58 | file => $opts{s} || 'bin/sinfp3.db', | ||
| 59 | ); | ||
| 60 | |||
| 61 | my $output; | ||
| 62 | my $search; | ||
| 63 | if ($opts{p}) { | ||
| 64 | $output = Net::SinFP3::Output::AddSignatureP->new( | ||
| 65 | global => $global, | ||
| 66 | trusted => $opts{t} ? 1 : 0, | ||
| 67 | ); | ||
| 68 | $search = Net::SinFP3::Search::Passive->new( | ||
| 69 | global => $global, | ||
| 70 | ); | ||
| 71 | } | ||
| 72 | else { | ||
| 73 | $output = Net::SinFP3::Output::AddSignature->new( | ||
| 74 | global => $global, | ||
| 75 | trusted => $opts{t} ? 1 : 0, | ||
| 76 | ); | ||
| 77 | $search = Net::SinFP3::Search::Active->new( | ||
| 78 | global => $global, | ||
| 79 | ); | ||
| 80 | } | ||
| 81 | |||
| 82 | my $input; | ||
| 83 | my $mode; | ||
| 84 | if ($opts{n}) { | ||
| 85 | $input = Net::SinFP3::Input::Nessus->new( | ||
| 86 | global => $global, | ||
| 87 | ); | ||
| 88 | $mode = Net::SinFP3::Mode::Null->new( | ||
| 89 | global => $global, | ||
| 90 | ); | ||
| 91 | } | ||
| 92 | elsif ($opts{f}) { | ||
| 93 | if ($opts{p}) { | ||
| 94 | $input = Net::SinFP3::Input::Pcap->new( | ||
| 95 | global => $global, | ||
| 96 | file => $opts{f}, | ||
| 97 | ); | ||
| 98 | } | ||
| 99 | else { | ||
| 100 | $input = Net::SinFP3::Input::Pcap->new( | ||
| 101 | global => $global, | ||
| 102 | file => $opts{f}, | ||
| 103 | count => 10, | ||
| 104 | ); | ||
| 105 | } | ||
| 106 | if ($opts{p}) { | ||
| 107 | $mode = Net::SinFP3::Mode::Passive->new( | ||
| 108 | global => $global, | ||
| 109 | ); | ||
| 110 | } | ||
| 111 | else { | ||
| 112 | $mode = Net::SinFP3::Mode::Active->new( | ||
| 113 | global => $global, | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | my $sinfp = Net::SinFP3->new( | ||
| 119 | global => $global, | ||
| 120 | db => [ $db ], | ||
| 121 | input => [ $input ], | ||
| 122 | search => [ $search ], | ||
| 123 | output => [ $output ], | ||
| 124 | mode => [ $mode ], | ||
| 125 | ); | ||
| 126 | |||
| 127 | # Ready to go | ||
| 128 | $sinfp->run; | ||
| 129 | $log->post; | ||
| 130 | |||
| 131 | exit(0); |