root/fwknop/tags/fwknop-1.8.4-pre2/knopspoof

Revision 346, 3.3 kB (checked in by mbr, 3 years ago)

minor comment update

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl -w
2 #
3 ##############################################################################
4 #
5 # File: knopspoof
6 #
7 # Purpose:  To provide an interface for fwknop to send spoofed authentication
8 #           packets to another fwknop instance running in pcap mode.  We need
9 #           this script because normally doing "use Net::RawIP;" requires
10 #           root access, and fwknop does not normally run as root when
11 #           executed in client mode.
12 #
13 # Author: Michael Rash (mbr@cipherdyne.org)
14 #
15 # Version: 0.9.0
16 #
17 # Copyright (C) 2004 Michael Rash (mbr@cipherdyne.org)
18 #
19 # License (GNU Public License):
20 #
21 #    This program is distributed in the hope that it will be useful,
22 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
23 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 #    GNU General Public License for more details.
25 #
26 #    You should have received a copy of the GNU General Public License
27 #    along with this program; if not, write to the Free Software
28 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
29 #    USA
30 #
31 #  NOTE: This program has been depreciated in favor of fwknop using
32 #        Net::RawIP directly.
33 #
34 ##############################################################################
35 #
36 # $Id$
37 #
38
39 use lib '/usr/lib/fwknop';
40 use Net::RawIP;
41 use strict;
42
43 my $file = $ARGV[0] || die "[*] Usage: $0 <file>";
44
45 my $ip_re = '(?:\d{1,3}\.){3}\d{1,3}';
46
47 open F, "< $file" or die "[*] Could not open $file: $!";
48 my $line = <F>;
49 close F;
50
51 if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/) {
52
53     my $src   = $1;
54     my $dst   = $2;
55     my $proto = lc($3);
56     my $sp    = $4;
57     my $dp    = $5;
58     my $msg   = $6;
59
60     ### the file theat is read is constructed by fwknop
61     die "[*] proto: $proto not supported.\n"
62         unless ($proto eq 'udp' or $proto eq 'tcp' or $proto eq 'icmp');
63     die "[*] src address must be a standard IP address."
64         unless $src =~ /$ip_re/;
65     die "[*] dst address must be a standard IP address."
66         unless $dst =~ /$ip_re/;
67
68     if ($proto eq 'udp') {
69         my $rawpkt = new Net::RawIP({ip => {saddr => $src, daddr => $dst},
70             udp =>{}});
71         $rawpkt->set({ ip => { saddr  => $src,
72                 daddr  => $dst
73             },
74             udp => {
75                 source => $sp,
76                 dest   => $dp,
77                 data   => $msg,
78             }
79         });
80         $rawpkt->send();
81     } elsif ($proto eq 'icmp') {
82         my $rawpkt = new Net::RawIP({ip => {saddr => $src, daddr => $dst},
83             icmp =>{}});
84         $rawpkt->set({ ip => { saddr  => $src,
85                 daddr  => $dst
86             },
87             icmp => {
88                 type => 0,
89                 code => 0,
90                 sequence => 0,
91                 data => $msg
92             }
93         });
94         $rawpkt->send();
95     } elsif ($proto eq 'tcp') {
96         my $rawpkt = new Net::RawIP({ip => {saddr => $src, daddr => $dst},
97             tcp =>{}});
98         $rawpkt->set({ ip => { saddr => $src,
99                 daddr  => $dst
100             },
101             tcp => {
102                 ack => 1,
103                 source => $sp,
104                 dest   => $dp,
105                 data => $msg
106             }
107         });
108         $rawpkt->send();
109     }
110 } else {
111     die "[*] Line not in the correct format.\n";
112 }
113 exit 0;
Note: See TracBrowser for help on using the browser.