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
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: icmp-recv 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ #
6
+ # Simple re-implementation of tcpdump using Racket
7
+ require 'pcaplet'
8
+ include Pcap
9
+ require 'rubygems'
10
+ require 'racket'
11
+ #require 'racket-all'
12
+
13
+ include Racket
14
+ pcaplet = Pcaplet.new("-s 65535" + ARGV.join)
15
+ pcaplet.each_packet { |pkt|
16
+ if (pkt.datalink == DLT_EN10MB)
17
+ l2 = L2::Ethernet.new(pkt.raw_data)
18
+ puts l2.pretty
19
+ if (l2.ethertype == 0x0800)
20
+ l3 = L3::IPv4.new(l2.payload)
21
+ puts l3.pretty
22
+ case l3.protocol
23
+ when 1
24
+ l4 = L4::ICMP.new(l3.payload)
25
+ puts l4.pretty
26
+ else
27
+ next
28
+ end
29
+ end
30
+ else
31
+ puts "Skipping unknown datalink #{pkt.datalink}"
32
+ end
33
+ }
34
+ # vim: set ts=2 et sw=2:
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: icmp-spew 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Given a source and destination IP address
6
+ # and a data size, spew all 65536 possible ICMP
7
+
8
+ require 'rubygems'
9
+ require 'racket'
10
+
11
+ include Racket
12
+ if (ARGV.size != 3)
13
+ puts "Usage #{$0} <src_ip> <dst_ip> <icmp data size>"
14
+ exit!
15
+ end
16
+
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 rand_icmp(n)
26
+ n.l3 = L3::IPv4.new
27
+ n.l3.src_ip= ARGV[0]
28
+ n.l3.dst_ip = ARGV[1]
29
+ n.l3.version = 0x4
30
+ n.l3.hlen = 0x5
31
+ n.l3.protocol = 0x1
32
+ n.l3.flags = 0x0
33
+ n.l3.foffset = 0x0
34
+ n.l4 = L4::ICMP.new(Misc.randstring(20))
35
+ n.sendpacket
36
+ tick
37
+ end
38
+
39
+ @it = 0
40
+ @ticks = %w( / - \\ | )
41
+
42
+ n = Racket::Racket.new
43
+ n.iface = "eth0"
44
+
45
+ puts "Spewing..."
46
+ while (true)
47
+ rand_icmp(n)
48
+ end
49
+
50
+ # vim: set ts=2 et sw=2:
data/examples/icmpv6 ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: icmpv6 175 2010-08-21 22:27:11Z jhart $
4
+
5
+ require 'rubygems'
6
+ require 'racket'
7
+
8
+ include Racket
9
+ unless (ARGV.size == 3)
10
+ puts "Usage: #{$0} <interface> <srcip> <dstip>"
11
+ exit
12
+ end
13
+
14
+ n = Racket::Racket.new
15
+ n.iface = ARGV[0]
16
+
17
+ #n.l2 = L2::Ethernet.new(Misc.randstring(14))
18
+ n.l2 = L2::Ethernet.new
19
+ n.l2.src_mac = L2::Misc.randommac
20
+ n.l2.dst_mac = L2::Misc.randommac
21
+ n.l2.ethertype = 0x86DD
22
+
23
+ n.l3 = L3::IPv6.new
24
+ n.l3.src_ip = L3::Misc.ipv62long(ARGV[1])
25
+ n.l3.dst_ip = L3::Misc.ipv62long(ARGV[2])
26
+ n.l3.nhead = 58
27
+
28
+ def build(i)
29
+ i.l4.fix!(i.l3.src_ip, i.l3.dst_ip)
30
+ f = i.sendpacket
31
+ puts "Sent #{f}"
32
+ end
33
+
34
+ n.l4 = L4::ICMPv6DestinationUnreachable.new
35
+ n.l4.payload = L3::IPv6.new(Misc.randstring(40))
36
+ build(n)
37
+ n.l4 = L4::ICMPv6TimeExceeded.new
38
+ n.l4.payload = L3::IPv6.new(Misc.randstring(40))
39
+ build(n)
40
+ n.l4 = L4::ICMPv6EchoRequest.new
41
+ build(n)
42
+ n.l4 = L4::ICMPv6EchoReply.new
43
+ build(n)
44
+ n.l4 = L4::ICMPv6PacketTooBig.new
45
+ n.l4.mtu = rand(65535)
46
+ n.l4.payload = L3::IPv6.new(Misc.randstring(40))
47
+ build(n)
48
+ n.l4 = L4::ICMPv6ParameterProblem.new
49
+ payload = L3::IPv6.new(Misc.randstring(40))
50
+ n.l4.payload = payload
51
+ n.l4.pointer = 0x20
52
+ build(n)
53
+ n.l4 = L4::ICMPv6MulticastListenerQuery.new
54
+ build(n)
55
+ n.l4 = L4::ICMPv6MulticastListenerReport.new
56
+ build(n)
57
+ n.l4 = L4::ICMPv6MulticastListenerDone.new
58
+ build(n)
59
+ n.l4 = L4::ICMPv6RouterSolicitation.new
60
+ build(n)
61
+ n.l4 = L4::ICMPv6RouterAdvertisement.new
62
+ build(n)
63
+ n.l4 = L4::ICMPv6NeighborSolicitation.new
64
+ build(n)
65
+ n.l4 = L4::ICMPv6NeighborAdvertisement.new
66
+ n.l4.solicited = 1
67
+ n.l4.slla = "01:02:03:04:aa:bb"
68
+ build(n)
69
+ n.l4 = L4::ICMPv6Redirect.new
70
+ n.l4.slla = "01:02:03:04:aa:bb"
71
+ n.l4.src_ip = L3::Misc.ipv62long(ARGV[2])
72
+ n.l4.dst_ip = L3::Misc.ipv62long(ARGV[1])
73
+ build(n)
74
+
75
+ n.l4 = L4::ICMPv6NodeInformationRequest.new
76
+ n.l4.payload = Misc.randstring(rand(32))
77
+ n.l4.code = 2
78
+ n.l4.payload = [L3::Misc.ipv42long("192.168.1.10")].pack("N")
79
+ n.l4.qtype = 2
80
+ build(n)
81
+
82
+ n.l4 = L4::ICMPv6NodeInformationReply.new
83
+ n.l4.payload = Misc.randstring(rand(32))
84
+ build(n)
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: icmpv6-spew 152 2009-12-13 06:21:32Z jhart $
4
+ #
5
+ # Given a source and destination IP address
6
+ # and a data size, spew all 65536 possible ICMPv6
7
+
8
+ require 'rubygems'
9
+ require 'racket'
10
+
11
+ include Racket
12
+ if (ARGV.size != 4)
13
+ puts "Usage #{$0} <interface> <src_ip> <dst_ip> <icmp data size>"
14
+ exit!
15
+ end
16
+
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 rand_icmp6(n)
26
+ n.l4 = L4::ICMPv6.new(Misc.randstring(40))
27
+ n.l4.payload = Misc.randstring(ARGV[3].to_i)
28
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
29
+ n.sendpacket
30
+ tick
31
+ end
32
+
33
+ @it = 0
34
+ @ticks = %w( / - \\ | )
35
+
36
+ n = Racket::Racket.new
37
+ n.iface = ARGV[0]
38
+ n.l2 = L2::Ethernet.new(Misc.randstring(14))
39
+ n.l2.ethertype = 0x86DD
40
+ n.l3 = L3::IPv6.new
41
+ n.l3.src_ip= L3::Misc.ipv62long(ARGV[1])
42
+ n.l3.dst_ip= L3::Misc.ipv62long(ARGV[2])
43
+ n.l3.nhead = 58
44
+
45
+ puts "Spewing..."
46
+ while (true)
47
+ rand_icmp6(n)
48
+ end
49
+
50
+ # vim: set ts=2 et sw=2:
data/examples/igmpv1 ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: igmpv1 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ if (ARGV.size != 4)
11
+ puts "Usage #{$0} <src_ip> <dst_ip> <igmp code> <gaddr>"
12
+ exit!
13
+ end
14
+
15
+ n = Racket::Racket.new
16
+ n.l3 = L3::IPv4.new
17
+
18
+ n.l3.src_ip = ARGV[0]
19
+ n.l3.dst_ip = ARGV[1]
20
+ n.l3.protocol = 2
21
+
22
+ n.l4 = L4::IGMPv1.new
23
+ n.l4.type = ARGV[2].to_i
24
+ n.l4.gaddr = ARGV[3]
25
+
26
+ f = n.sendpacket
27
+ puts "Sent #{f} bytes"
data/examples/igmpv2 ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: igmpv2 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ if (ARGV.size != 4)
11
+ puts "Usage #{$0} <src_ip> <dst_ip> <igmp code> <gaddr>"
12
+ exit!
13
+ end
14
+
15
+ n = Racket::Racket.new
16
+ n.l3 = L3::IPv4.new
17
+
18
+ n.l3.src_ip = ARGV[0]
19
+ n.l3.dst_ip = ARGV[1]
20
+ n.l3.protocol = 2
21
+
22
+ n.l4 = L4::IGMPv1.new
23
+ n.l4.type = ARGV[2].to_i
24
+ n.l4.gaddr = ARGV[3]
25
+
26
+ f = n.sendpacket
27
+ puts "Sent #{f} bytes"
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: igrp-send 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send IGRP packets. Needs work... obviously.
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ n = Racket::Racket.new
11
+ n.iface = "eth0"
12
+
13
+ n.l2 = L2::Ethernet.new(Misc.randstring(14))
14
+ n.l2.ethertype = 0x800
15
+
16
+ n.l3 = L3::IPv4.new
17
+ n.l3.protocol = 9
18
+
19
+ n.l4 = L4::IGRP.new()
20
+ n.l4.version = 1
21
+ n.l4.opcode = 1
22
+ n.l4.add_system(0xFFFFFF, 1, 2, 3, 4, 5, 6)
23
+ n.l4.add_exterior(0x12345, 6, 7, 8, 9, 0xa, 0xb)
24
+ n.l4.add_interior(0x67890, 6, 7, 8, 9, 0xa, 0xb)
25
+ n.sendpacket
data/examples/ipv6 ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: ipv6 172 2010-03-16 07:07:04Z jhart $
4
+ #
5
+
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.l2 = L2::Ethernet.new(Misc.randstring(14))
19
+ n.l2.ethertype = 0x86DD
20
+
21
+ n.l3 = L3::IPv6.new
22
+ n.l3.src_ip = L3::Misc.ipv62long(ARGV[0])
23
+ n.l3.dst_ip = L3::Misc.ipv62long(ARGV[1])
24
+ n.l3.nhead = 17
25
+
26
+ n.l4 = L4::UDP.new
27
+ n.l4.src_port = 12345
28
+ n.l4.dst_port = 123
29
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
30
+
31
+ f = n.sendpacket
32
+ n.layers.compact.each do |l|
33
+ puts l.pretty
34
+ end
35
+ #puts "Sent #{f}"
data/examples/ntp ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: ntp 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send lolcat NTP packets
6
+
7
+ require 'rubygems'
8
+ require 'racket'
9
+
10
+ include Racket
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.l3 = 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 = L4::UDP.new
25
+ n.l4.src_port = 12345
26
+ n.l4.dst_port = 123
27
+
28
+ n.l5 = L5::NTP.new("I'm in your ntp, stealin ur time")
29
+
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/ntp2 ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: ntp2 174 2010-08-21 22:26:52Z jhart $
4
+ #
5
+ # Send lolcat NTP packets
6
+
7
+ require 'rubygems'
8
+ require 'racket'
9
+
10
+ include Racket
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.l3 = L3::IPv4.new
20
+ n.l3.src_ip = ARGV[0]
21
+ n.l3.dst_ip = ARGV[1]
22
+ n.l3.protocol = 0x11
23
+ n.l3.add_option(4, "wt")
24
+ n.l3.add_option(136, "aa")
25
+ n.l3.add_option(130, "123456789")
26
+ n.l3.add_option(148, "yz")
27
+
28
+ n.l4 = L4::UDP.new
29
+ n.l4.src_port = 12345
30
+ n.l4.dst_port = 123
31
+
32
+ n.l5 = L5::NTP.new("I'm in your ntp, stealin ur time")
33
+
34
+ n.l4.payload = n.l5
35
+ n.l4.fix!(n.l3.src_ip, n.l3.dst_ip)
36
+ n.l4.payload = ""
37
+
38
+ f = n.sendpacket
39
+ n.layers.compact.each do |l|
40
+ puts l.pretty
41
+ end
42
+ puts "Sent #{f}"
data/examples/sctp ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # $Id: sctp 172 2010-03-16 07:07:04Z jhart $
4
+ #
5
+
6
+ require 'rubygems'
7
+ require 'racket'
8
+
9
+ include Racket
10
+ unless (ARGV.size == 4)
11
+ puts "Usage: #{$0} <srcip> <srcport> <dstip> <dstport>"
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[2]
21
+ n.l3.protocol = 132
22
+
23
+ n.l4 = L4::SCTP.new
24
+ n.l4.src_port = ARGV[1].to_i
25
+ n.l4.dst_port = ARGV[3].to_i
26
+ #n.l4.add_chunk(1, 2, 8, "blah")
27
+
28
+ f = n.sendpacket
29
+ n.layers.compact.each do |l|
30
+ puts l.pretty
31
+ end
32
+ puts "Sent #{f}"