racket 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/README +76 -0
  2. data/examples/arp-send +24 -0
  3. data/examples/arp-send2 +30 -0
  4. data/examples/cdp +39 -0
  5. data/examples/cdp-spew +52 -0
  6. data/examples/dhcp +42 -0
  7. data/examples/dhcp-spew +48 -0
  8. data/examples/dns +38 -0
  9. data/examples/egp +30 -0
  10. data/examples/hsrp +43 -0
  11. data/examples/hsrp_takeover +69 -0
  12. data/examples/icmp-recv +34 -0
  13. data/examples/icmp-spew +50 -0
  14. data/examples/icmpv6 +84 -0
  15. data/examples/icmpv6-spew +50 -0
  16. data/examples/igmpv1 +27 -0
  17. data/examples/igmpv2 +27 -0
  18. data/examples/igrp-send +25 -0
  19. data/examples/ipv6 +35 -0
  20. data/examples/ntp +38 -0
  21. data/examples/ntp2 +42 -0
  22. data/examples/sctp +32 -0
  23. data/examples/stp-send +21 -0
  24. data/examples/synflood +147 -0
  25. data/examples/tcp +43 -0
  26. data/examples/tcp2udp +65 -0
  27. data/examples/udp +46 -0
  28. data/examples/vrrp +34 -0
  29. data/examples/vtp +28 -0
  30. data/lib/racket.rb +4 -0
  31. data/lib/racket/l2.rb +30 -0
  32. data/lib/racket/l2/eightotwodotthree.rb +48 -0
  33. data/lib/racket/l2/ethernet.rb +62 -0
  34. data/lib/racket/l2/llc.rb +50 -0
  35. data/lib/racket/l2/misc.rb +67 -0
  36. data/lib/racket/l2/snap.rb +40 -0
  37. data/lib/racket/l2/vlan.rb +61 -0
  38. data/lib/racket/l2/vtp.rb +124 -0
  39. data/lib/racket/l3.rb +30 -0
  40. data/lib/racket/l3/arp.rb +63 -0
  41. data/lib/racket/l3/cdp.rb +85 -0
  42. data/lib/racket/l3/egp.rb +53 -0
  43. data/lib/racket/l3/ipv4.rb +132 -0
  44. data/lib/racket/l3/ipv6.rb +66 -0
  45. data/lib/racket/l3/misc.rb +165 -0
  46. data/lib/racket/l3/stp.rb +81 -0
  47. data/lib/racket/l4.rb +30 -0
  48. data/lib/racket/l4/gre.rb +65 -0
  49. data/lib/racket/l4/icmp.rb +295 -0
  50. data/lib/racket/l4/icmpv6.rb +446 -0
  51. data/lib/racket/l4/igmpv1.rb +79 -0
  52. data/lib/racket/l4/igmpv2.rb +76 -0
  53. data/lib/racket/l4/igrp.rb +138 -0
  54. data/lib/racket/l4/misc.rb +35 -0
  55. data/lib/racket/l4/sctp.rb +163 -0
  56. data/lib/racket/l4/tcp.rb +152 -0
  57. data/lib/racket/l4/udp.rb +81 -0
  58. data/lib/racket/l4/vrrp.rb +95 -0
  59. data/lib/racket/l5.rb +30 -0
  60. data/lib/racket/l5/bootp.rb +106 -0
  61. data/lib/racket/l5/dns.rb +110 -0
  62. data/lib/racket/l5/hsrp.rb +73 -0
  63. data/lib/racket/l5/misc.rb +35 -0
  64. data/lib/racket/l5/ntp.rb +59 -0
  65. data/lib/racket/misc.rb +30 -0
  66. data/lib/racket/misc/lv.rb +108 -0
  67. data/lib/racket/misc/misc.rb +61 -0
  68. data/lib/racket/misc/orderedhash.rb +63 -0
  69. data/lib/racket/misc/raw.rb +35 -0
  70. data/lib/racket/misc/tlv.rb +103 -0
  71. data/lib/racket/misc/vt.rb +114 -0
  72. data/lib/racket/racket.rb +164 -0
  73. data/lib/racket/racketpart.rb +66 -0
  74. data/test/l2/ts_ethernet.rb +22 -0
  75. data/test/l2/ts_misc.rb +23 -0
  76. data/test/l2/ts_vlan.rb +15 -0
  77. data/test/l3/ts_ipv4.rb +44 -0
  78. data/test/l3/ts_ipv6.rb +26 -0
  79. data/test/l3/ts_misc.rb +31 -0
  80. data/test/l4/ts_icmp.rb +38 -0
  81. data/test/l4/ts_tcp.rb +55 -0
  82. data/test/l4/ts_udp.rb +40 -0
  83. data/test/misc/ts_lv.rb +59 -0
  84. data/test/misc/ts_orderedhash.rb +33 -0
  85. data/test/misc/ts_tlv.rb +47 -0
  86. data/test/misc/ts_vt.rb +56 -0
  87. data/test/ts_all.rb +14 -0
  88. metadata +182 -0
data/examples/stp-send ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: stp-send 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ n = Racket::Racket.new
11
+ n.iface = "eth0"
12
+
13
+ n.layers[2] = L2::EightOTwoDotThree.new
14
+ n.layers[3] = L2::LLC.new()
15
+ n.layers[4] = L2::SNAP.new()
16
+ n.layers[4].pid = 0x010b
17
+
18
+ n.layers[5] = L3::STP.new()
19
+ n.layers[5].version = 2
20
+
21
+ n.sendpacket
data/examples/synflood ADDED
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/ruby
2
+ # $Id: synflood 174 2010-08-21 22:26:52Z jhart $
3
+ # Simple SYN flooder with randomness built in, using Racket
4
+ # Use at your own risk
5
+ #
6
+ # Jon Hart <jhart@spoofed.org>
7
+
8
+ require 'rubygems'
9
+ require 'racket'
10
+ require 'monitor'
11
+ require 'optparse'
12
+ require 'ostruct'
13
+
14
+ include Racket
15
+
16
+ class Options
17
+ def self.parse(name, args)
18
+ options = OpenStruct.new
19
+ options.verbose = false
20
+ options.srcport = nil
21
+ options.dstport = nil
22
+ options.srcip = nil
23
+ options.dstip = nil
24
+ options.packets = nil
25
+ options.threads = 1
26
+
27
+ opts = OptionParser.new do |opts|
28
+ opts.banner = "#{File.basename(name)}"
29
+ opts.banner += "Usage: #{name} [options]"
30
+
31
+ opts.on("--srcip SOURCEIP", "Source IP address (default: random)") do |o|
32
+ options.srcip = o
33
+ end
34
+
35
+ opts.on("--dstip DESTIP", "Destination IP address (required)") do |o|
36
+ options.dstip = o
37
+ end
38
+
39
+ opts.on("--srcport SRCPORT", "Source port (default: random)") do |o|
40
+ options.srcport = o.to_i
41
+ end
42
+
43
+ opts.on("--dstport DSTPORT", "Destination port (default: random)") do |o|
44
+ options.dstport = o.to_i
45
+ end
46
+
47
+ opts.on("--threads NUMTHREADS", "Number of writing threads (default: 1)") do |o|
48
+ options.threads = o.to_i
49
+ end
50
+
51
+ opts.on("--packets NUMPACKETS", "Number of packets to send (default: infinite)") do |o|
52
+ options.packets = o.to_i
53
+ end
54
+ opts.on_tail("-h", "--help", "Show this help message.") { puts opts; exit }
55
+ end
56
+
57
+
58
+ begin
59
+ opts.parse!(args)
60
+ rescue OptionParser::ParseError => e
61
+ puts "#{e}\n\n#{opts}"
62
+ exit(1)
63
+ end
64
+ options.help = opts
65
+ options
66
+ end
67
+ end
68
+
69
+ @options = Options.parse($0, ARGV)
70
+
71
+ if (@options.dstip.nil?)
72
+ puts "Destination IP required"
73
+ puts @options.help
74
+ exit(1)
75
+ end
76
+
77
+
78
+ @p = Racket::Racket.new
79
+ @p.iface = "eth0"
80
+
81
+ @p.l3 = L3::IPv4.new
82
+ @p.l3.src_ip = @options.srcip.nil? ? "0.0.0.0" : @options.srcip
83
+ @p.l3.dst_ip = @options.dstip.nil? ? "0.0.0.0" : @options.dstip
84
+ @p.l3.protocol = 6
85
+
86
+ @p.l4 = L4::TCP.new
87
+ @p.l4.dst_port = @options.dstport.nil? ? 0 : @options.dstport
88
+ @p.l4.src_port = @options.srcport.nil? ? 0 : @options.srcport
89
+ @p.l4.flag_syn = 1
90
+
91
+ t1 = Time.new
92
+ i = 0
93
+
94
+ class Flood < Monitor
95
+ attr_reader :count
96
+ def initialize
97
+ @count = 0
98
+ super
99
+ end
100
+
101
+ def flood(packet, options)
102
+ @packet = packet
103
+ @options = options
104
+ begin
105
+ if ( (! @options.packets.nil?) && @options.packets < @count)
106
+ break
107
+ end
108
+
109
+ if (@options.srcip.nil?)
110
+ @packet.l3.src_ip = L3::Misc.long2ipv4(rand(2**32))
111
+ end
112
+
113
+ if (@options.srcport.nil?)
114
+ @packet.l4.src_port = 1024 + rand(65535-1024)
115
+ end
116
+
117
+ if (@options.dstport.nil?)
118
+ @packet.l4.dst_port = 1024 + rand(65535-1024)
119
+ end
120
+
121
+ @packet.l4.fix!(@packet.l3.src_ip, @packet.l3.dst_ip, "")
122
+
123
+ synchronize do
124
+ @count += 1
125
+ @packet.sendpacket
126
+ end
127
+ end while (true)
128
+ end
129
+ end
130
+
131
+
132
+ t1 = Time.new
133
+ f = Flood.new
134
+ threads = []
135
+ (1.upto(@options.threads)).each do |t|
136
+ threads << Thread.new { f.flood(@p, @options) }
137
+ end
138
+
139
+ threads.each do |t|
140
+ t.join
141
+ end
142
+ t2 = Time.new
143
+
144
+ time = t2 - t1
145
+
146
+ puts "Sent #{f.count} packets in #{time} seconds (#{"%.0f" % (f.count/time).to_f} pps)"
147
+
data/examples/tcp ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: tcp 172 2010-03-16 07:07:04Z jhart $
4
+ #
5
+ # Send a DNS request
6
+
7
+ require 'rubygems'
8
+ require 'racket'
9
+
10
+ include Racket
11
+ unless (ARGV.size == 3)
12
+ puts "Usage: #{$0} <srcip> <dstip> <domain>"
13
+ exit
14
+ end
15
+
16
+ n = Racket::Racket.new
17
+ n.iface = "eth0"
18
+
19
+ n.l3 = Racket::L3::IPv4.new
20
+ n.l3.src_ip = ARGV[0]
21
+ n.l3.dst_ip = ARGV[1]
22
+ n.l3.protocol = 0x6
23
+
24
+ n.l4 = Racket::L4::TCP.new
25
+ n.l4.src_port = 48484
26
+ n.l4.seq = 0xabcdef
27
+ n.l4.ack = 0xfedcba
28
+ n.l4.flag_ack = 1
29
+ n.l4.flag_psh = 1
30
+ n.l4.dst_port = 53
31
+ n.l4.window = 4445
32
+
33
+ n.l5 = Racket::L5::DNS.new
34
+ n.l5.tx_id = 1234
35
+ #n.l5.add_question(ARGV[2], 1, 1)
36
+ n.l4.add_option(2, "\xff\xee")
37
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip, n.l5)
38
+
39
+ f = n.sendpacket
40
+ n.layers.compact.each do |l|
41
+ puts l.pretty
42
+ end
43
+ puts "Sent #{f}"
data/examples/tcp2udp ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: tcp2udp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ #
6
+ # Spew TCP packets back at the source but in UDP form. Gross.
7
+ # Pointless.
8
+
9
+
10
+ require 'rubygems'
11
+ require 'pcaprub'
12
+ require 'racket'
13
+
14
+ include Racket
15
+
16
+
17
+ if (ARGV.size < 1)
18
+ puts "Usage: #{$0} <iface> [filter]"
19
+ exit
20
+ end
21
+
22
+ begin
23
+ p = Pcap::open_live(ARGV[0], 1500, true, 1000)
24
+ unless (ARGV[1].nil?)
25
+ p.setfilter(ARGV[1])
26
+ end
27
+ rescue Exception => e
28
+ puts "Pcap: Cannot open device #{ARGV[0]}: #{e}"
29
+ exit
30
+ end
31
+
32
+ p.each do |pkt|
33
+ if (p.datalink == Pcap::DLT_EN10MB)
34
+ eth = L2::Ethernet.new(pkt)
35
+ case eth.ethertype
36
+ when 0x0800:
37
+ orig_ipv4 = L3::IPv4.new(eth.payload)
38
+ if (orig_ipv4.protocol == 6)
39
+ n = Racket::Racket.new
40
+ orig_tcp = L4::TCP.new(orig_ipv4.payload)
41
+
42
+ if (!orig_tcp.payload.nil?)
43
+ n.l3 = L3::IPv4.new
44
+ n.l4 = L4::UDP.new
45
+ n.l4.src_port = orig_tcp.dst_port
46
+ n.l4.dst_port = orig_tcp.src_port
47
+ n.l3.src_ip = orig_ipv4.dst_ip
48
+ n.l3.dst_ip = orig_ipv4.src_ip
49
+ n.l3.protocol = 17
50
+
51
+ n.l4.payload = orig_tcp.payload
52
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
53
+
54
+ f = n.sendpacket
55
+ puts "Sent #{f}"
56
+ n.layers.compact.each do |l|
57
+ puts l.pretty
58
+ end
59
+ exit
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ # vim: set ts=2 et sw=2:
data/examples/udp ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: udp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send random garbage to a UDP port
6
+
7
+ require 'rubygems'
8
+ require 'racket'
9
+
10
+ include Racket
11
+ unless (ARGV.size == 4)
12
+ puts "Usage: #{$0} <srcip> <dstip> <dst_port> <size>"
13
+ exit
14
+ end
15
+
16
+ # create a new Racket object and pick an interface
17
+ n = Racket::Racket.new
18
+ n.iface = "eth0"
19
+
20
+ # skip right to layer3, layer2 will be done automatically
21
+ # build a new IPv4 layer, and assign src and dst ip from the command line
22
+ n.l3 = L3::IPv4.new
23
+ n.l3.src_ip = ARGV[0]
24
+ n.l3.dst_ip = ARGV[1]
25
+ n.l3.protocol = 0x11
26
+
27
+ # tack on UDP
28
+ n.l4 = L4::UDP.new
29
+ # randomize source port
30
+ n.l4.src_port = 1024 + rand(65535-1024)
31
+ # take destination port from the commandline
32
+ n.l4.dst_port = ARGV[2].to_i
33
+ # build a random amount of garbage for the payload
34
+ n.l4.payload = Misc.randstring(ARGV[3].to_i)
35
+
36
+ # fix 'er up (checksum, length) prior to sending
37
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
38
+
39
+ # off you go
40
+ f = n.sendpacket
41
+
42
+ # print out what we built
43
+ n.layers.compact.each do |l|
44
+ puts l.pretty
45
+ end
46
+ puts "Sent #{f}"
data/examples/vrrp ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: vrrp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ unless (ARGV.size == 3)
11
+ puts "Usage: #{$0} <srcip> <dstip> <type>"
12
+ exit
13
+ end
14
+
15
+ n = Racket::Racket.new
16
+ n.iface = "eth0"
17
+
18
+ n.l3 = L3::IPv4.new
19
+ n.l3.src_ip = ARGV[0]
20
+ n.l3.dst_ip = ARGV[1]
21
+ n.l3.protocol = 112
22
+
23
+ n.l4 = L4::VRRP.new
24
+ n.l4.type = ARGV[2].to_i
25
+ n.l4.auth_type = 1
26
+ n.l4.add_ip("1.2.3.4")
27
+ n.l4.add_auth("haha")
28
+ #n.l4.payload = [ L3::Misc.ipv42long("1.2.3.4") ].pack("N")
29
+
30
+ f = n.sendpacket
31
+ n.layers.compact.each do |l|
32
+ puts l.pretty
33
+ end
34
+ puts "Sent #{f}"
data/examples/vtp ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: vtp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send amusing CDP packets
6
+ require 'rubygems'
7
+ require '../lib/racket'
8
+
9
+ include Racket
10
+ n = Racket::Racket.new
11
+ n.iface = "eth0"
12
+
13
+ n.layers[2] = L2::EightOTwoDotThree.new(Misc.randstring(14))
14
+ n.layers[2].dst_mac = "01:00:0c:cc:cc:cc"
15
+ n.layers[3] = L2::LLC.new()
16
+ n.layers[4] = L2::SNAP.new()
17
+ n.layers[4].pid = 0x2003
18
+
19
+ n.layers[5] = L2::VTPSubsetAdvertisement.new
20
+ n.layers[5].version = 1
21
+ n.layers[5].revision = 12345
22
+ n.layers[5].add_vlan_info(0xFF, 3, 5, 6, 7, "blafadfadsfasdf")
23
+
24
+ n.layers.compact.each do |l|
25
+ puts l.pretty
26
+ end
27
+
28
+ n.sendpacket
data/lib/racket.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Racket
2
+ end
3
+
4
+ require 'racket/racket'
data/lib/racket/l2.rb ADDED
@@ -0,0 +1,30 @@
1
+ # $Id: l2.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ Dir.glob(File.join(File.dirname(__FILE__), 'l2/*.rb')).each { |f| require f }
29
+
30
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,48 @@
1
+ # $Id: eightotwodotthree.rb 14 2008-03-02 05:42:30Z warchild $
2
+ #
3
+ # Copyright (c) 2008, Jon Hart
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of the <organization> nor the
14
+ # names of its contributors may be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY Jon Hart ``AS IS'' AND ANY
18
+ # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL Jon Hart BE LIABLE FOR ANY
21
+ # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ module Racket
29
+ module L2
30
+ # 802.3 Ethernet. Should always be followed by an LLC header
31
+ class EightOTwoDotThree < RacketPart
32
+ # Destination MAC address
33
+ hex_octets :dst_mac, 48
34
+ # Source MAC address
35
+ hex_octets :src_mac, 48
36
+ # Length of the payload
37
+ unsigned :length, 16
38
+ # Payload
39
+ rest :payload
40
+
41
+ # Fix this layer up prior to sending. For 802.3, just adjusts +length+
42
+ def fix!
43
+ self.length = self.payload.length
44
+ end
45
+ end
46
+ end
47
+ end
48
+ # vim: set ts=2 et sw=2: