packetfu 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/.gitignore +3 -0
  5. data/.travis.yml +8 -0
  6. data/CONTRIBUTING.md +47 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.rdoc +35 -30
  10. data/Rakefile +4 -4
  11. data/bench/octets.rb +9 -9
  12. data/examples/100kpackets.rb +12 -12
  13. data/examples/ackscan.rb +16 -16
  14. data/examples/arp.rb +35 -35
  15. data/examples/arphood.rb +36 -36
  16. data/examples/dissect_thinger.rb +6 -6
  17. data/examples/new-simple-stats.rb +23 -23
  18. data/examples/packetfu-shell.rb +25 -25
  19. data/examples/simple-sniffer.rb +9 -9
  20. data/examples/simple-stats.rb +23 -23
  21. data/examples/slammer.rb +3 -3
  22. data/gem-public_cert.pem +21 -0
  23. data/lib/packetfu.rb +149 -127
  24. data/lib/packetfu/capture.rb +169 -169
  25. data/lib/packetfu/config.rb +52 -52
  26. data/lib/packetfu/inject.rb +56 -56
  27. data/lib/packetfu/packet.rb +531 -528
  28. data/lib/packetfu/pcap.rb +579 -579
  29. data/lib/packetfu/protos/arp.rb +90 -90
  30. data/lib/packetfu/protos/arp/header.rb +158 -158
  31. data/lib/packetfu/protos/arp/mixin.rb +36 -36
  32. data/lib/packetfu/protos/eth.rb +44 -44
  33. data/lib/packetfu/protos/eth/header.rb +243 -243
  34. data/lib/packetfu/protos/eth/mixin.rb +3 -3
  35. data/lib/packetfu/protos/hsrp.rb +69 -69
  36. data/lib/packetfu/protos/hsrp/header.rb +107 -107
  37. data/lib/packetfu/protos/hsrp/mixin.rb +29 -29
  38. data/lib/packetfu/protos/icmp.rb +71 -71
  39. data/lib/packetfu/protos/icmp/header.rb +82 -82
  40. data/lib/packetfu/protos/icmp/mixin.rb +14 -14
  41. data/lib/packetfu/protos/invalid.rb +49 -49
  42. data/lib/packetfu/protos/ip.rb +69 -69
  43. data/lib/packetfu/protos/ip/header.rb +291 -291
  44. data/lib/packetfu/protos/ip/mixin.rb +40 -40
  45. data/lib/packetfu/protos/ipv6.rb +50 -50
  46. data/lib/packetfu/protos/ipv6/header.rb +188 -188
  47. data/lib/packetfu/protos/ipv6/mixin.rb +29 -29
  48. data/lib/packetfu/protos/tcp.rb +176 -176
  49. data/lib/packetfu/protos/tcp/ecn.rb +35 -35
  50. data/lib/packetfu/protos/tcp/flags.rb +74 -74
  51. data/lib/packetfu/protos/tcp/header.rb +268 -268
  52. data/lib/packetfu/protos/tcp/hlen.rb +32 -32
  53. data/lib/packetfu/protos/tcp/mixin.rb +46 -46
  54. data/lib/packetfu/protos/tcp/option.rb +321 -321
  55. data/lib/packetfu/protos/tcp/options.rb +95 -95
  56. data/lib/packetfu/protos/tcp/reserved.rb +35 -35
  57. data/lib/packetfu/protos/udp.rb +159 -123
  58. data/lib/packetfu/protos/udp/header.rb +91 -91
  59. data/lib/packetfu/protos/udp/mixin.rb +3 -3
  60. data/lib/packetfu/structfu.rb +280 -280
  61. data/lib/packetfu/utils.rb +292 -225
  62. data/lib/packetfu/version.rb +41 -41
  63. data/packetfu.gemspec +14 -3
  64. data/spec/arp_spec.rb +191 -0
  65. data/spec/eth_spec.rb +148 -0
  66. data/spec/icmp_spec.rb +97 -0
  67. data/spec/ip_spec.rb +78 -0
  68. data/spec/ipv6_spec.rb +81 -0
  69. data/spec/packet_spec.rb +61 -59
  70. data/spec/packet_subclasses_spec.rb +9 -10
  71. data/spec/packetfu_spec.rb +55 -62
  72. data/spec/sample3.pcap +0 -0
  73. data/spec/spec_helper.rb +44 -0
  74. data/spec/structfu_spec.rb +270 -271
  75. data/spec/tcp_spec.rb +76 -77
  76. data/spec/udp_spec.rb +32 -0
  77. data/spec/utils_spec.rb +95 -0
  78. data/test/all_tests.rb +14 -17
  79. data/test/func_lldp.rb +3 -3
  80. data/test/ptest.rb +2 -2
  81. data/test/test_capture.rb +45 -45
  82. data/test/test_eth.rb +70 -68
  83. data/test/test_hsrp.rb +9 -9
  84. data/test/test_inject.rb +18 -18
  85. data/test/test_invalid.rb +16 -16
  86. data/test/test_octets.rb +23 -21
  87. data/test/test_packet.rb +156 -154
  88. data/test/test_pcap.rb +172 -170
  89. data/test/test_structfu.rb +99 -97
  90. data/test/test_tcp.rb +322 -320
  91. data/test/test_udp.rb +78 -76
  92. metadata +108 -44
  93. metadata.gz.sig +2 -0
  94. data/spec/ethpacket_spec.rb +0 -74
  95. data/test/test_arp.rb +0 -135
  96. data/test/test_icmp.rb +0 -62
  97. data/test/test_ip.rb +0 -50
  98. data/test/test_ip6.rb +0 -68
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45346a86ccf70ceeb48ded267817e9395bb796d8
4
+ data.tar.gz: 92a9e7485b2d2089b9f4e4d0ee5ccdd00bea34a0
5
+ SHA512:
6
+ metadata.gz: 013e4765cf60749f3d12431446e7b8b82a63889cb60abbb5d6d2abc69b6dbc2812ffd768fd0ad5341b73d729ee3ae1a8620f6aa521c9579dc17be197767100a2
7
+ data.tar.gz: 7a0e1442c308792c79a00065852b13e91be050a68b981b02bc78f12db9d12955eb00b6f56be576228cbf4a8719f51e55e3f424916b7939b1ddb1f5eb47737351
Binary file
@@ -0,0 +1,2 @@
1
+ �zt����N@l
2
+ <����)��;Q����4O9_цy�
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
  doc/
3
3
  pkg/
4
4
  test/*test.pcap
5
+ Gemfile.lock
6
+ .ruby-gemset*
7
+ .ruby-version*
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - sudo apt-get install libpcap-dev -qq
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.6
8
+ - 2.2.2
@@ -0,0 +1,47 @@
1
+ # Contributing to PacketFu
2
+
3
+ Thanks for your interest in contributing to PacketFu.
4
+
5
+ If you could follow the following guidelines, you will make it much easier for
6
+ us to give feedback, help you find whatever problem you have and fix it.
7
+
8
+ ## Issues
9
+
10
+ If you have questions of any kind, or are unsure of how something works, please
11
+ [create an issue](https://github.com/packetfu/packetfu/issues/new).
12
+
13
+ Please try to answer the following questions in your issue:
14
+
15
+ - What did you do?
16
+ - What did you expect to happen?
17
+ - What happened instead?
18
+
19
+ If you have identified a bug, it would be very helpful if you could include a
20
+ way to replicate the bug. Ideally a failing test would be perfect, but even a
21
+ simple script demonstrating the error would suffice.
22
+
23
+ Feature requests are great and if submitted they will be considered for
24
+ inclusion, but sending a pull request is much more awesome.
25
+
26
+ ## Pull Requests
27
+
28
+ If you want your pull requests to be accepted, please follow the following guidelines:
29
+
30
+ - [**Add tests!**](http://rspec.info/) Your patch won't be accepted (or will be delayed) if it doesn't have tests.
31
+
32
+ - [**Document any change in behaviour**](http://yardoc.org/) Make sure the README and any other
33
+ relevant documentation are kept up-to-date.
34
+
35
+ - [**Create topic branches**](https://github.com/dchelimsky/rspec/wiki/Topic-Branches) Don't ask us to pull from your master branch.
36
+
37
+ - [**One pull request per feature**](https://help.github.com/articles/using-pull-requests) If you want to do more than one thing, send
38
+ multiple pull requests.
39
+
40
+ - [**Send coherent history**](http://stackoverflow.com/questions/6934752/git-combining-multiple-commits-before-pushing) Make sure each individual commit in your pull
41
+ request is meaningful. If you had to make multiple intermediate commits while
42
+ developing, please squash them before sending them to us.
43
+
44
+ - [**Follow coding conventions**](https://github.com/styleguide/ruby) The standard Ruby stuff, two spaces indent,
45
+ don't omit parens unless you have a good reason.
46
+
47
+ Thank you so much for contributing!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in packetfu.gemspec
4
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2012, Tod Beardsley
1
+ Copyright (c) 2008-2014, Tod Beardsley
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
@@ -1,59 +1,64 @@
1
1
  = PacketFu
2
2
 
3
- A library for reading and writing packets to an interface or to a libpcap-formatted file.
3
+ {<img src="https://travis-ci.org/packetfu/packetfu.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/packetfu/packetfu]
4
+ {<img src="https://codeclimate.com/github/packetfu/packetfu.png" />}[https://codeclimate.com/github/packetfu/packetfu]
4
5
 
5
- It is maintained at http://code.google.com/p/packetfu and https://github.com/todb/packetfu (which repository will win?)
6
+ A library for reading and writing packets to an interface or to a
7
+ libpcap-formatted file.
8
+
9
+ It is maintained at https://github.com/packetfu/packetfu .
6
10
 
7
11
  == Documentation
8
12
 
9
- PacketFu is rdoc-compatible, which means it's sdoc compatible. In the same directory as this file, run "sdoc" by itself (gem install sdoc), and then view doc/index.html with your favored browser. Once that's done, navigate at the top, and read up on how to create a Packet or Capture from an interface with show_live or whatever.
13
+ PacketFu is yard-compatible (as well as sdoc/rdoc, if you prefer). You
14
+ can generate local documentation easily with either `yard doc .` or
15
+ `sdoc`, and view doc/index.html with your favored browser. Once that's
16
+ done, navigate at the top, and read up on how to create a Packet or
17
+ Capture from an interface with show_live or whatever.
10
18
 
11
19
  == Requirements
12
20
 
13
- PcapRub:
21
+ PcapRub:
14
22
 
15
23
  $ rvm gem install pcaprub
16
24
 
17
- Marshall Beddoe's PcapRub is required only for packet reading and writing from a network interfaces (which is a pretty big only). PcapRub itself relies on libpcap 0.9.8 or later for packet injection. PcapRub also requires root privileges to access the interface directly.
25
+ Marshall Beddoe's PcapRub is required only for packet reading and
26
+ writing from a network interfaces (which is a pretty big only). PcapRub
27
+ itself relies on libpcap 0.9.8 or later for packet injection. PcapRub
28
+ also requires root privileges to access the interface directly.
18
29
 
19
30
  === Platforms
20
31
 
21
- I tend to test with the following (with bash):
22
-
23
- date > /tmp/tests.txt; for i in default 1.8.6-p420 1.8.7-p334 1.9.1-p431 1.9.2-p180 1.9.3-head
24
- do rvm use $i >> /tmp/tests.txt
25
- echo Testing with $i
26
- echo $i >> /tmp/tests.txt; echo +++++++++++++++++++++++ >> /tmp/tests.txt
27
- rvmsudo ./all_tests.rb >> /tmp/tests.txt; rspec . >> /tmp/tests.txt
28
- done
29
-
30
- ==== Problem Platforms
31
-
32
- * 1.8.6-p420 -- Has problems with pcaprub and capture/inject. Technically, these are pcaprub problems and not PacketFu problems, but PacketFu should at least fail better at them.
32
+ Given the security issues with older Rubies and the long-past [EOL for
33
+ 1.8.x](http://www.ruby-lang.org/en/news/2011/10/06/plans-for-1-8-7/),
34
+ PacketFu is rather stuck on very recent versions of 1.9.3 (as of this
35
+ moment, the version to trust is 1.9.3-p484).
33
36
 
34
- * 1.9.1-p431 -- Has problems with loading gems in general, see http://redmine.ruby-lang.org/issues/2404
37
+ ==== 1.8.x
35
38
 
36
- * 2.0.0-p0 -- Has problems with binary encoding of strings that do not manifest in 1.9.x See https://github.com/todb/packetfu/issues/28
39
+ EOL, no longer supported in any sense. PacketFu may or may not work.
37
40
 
41
+ ==== 1.9.x
38
42
 
43
+ 1.9.3-p484.
39
44
 
40
- ==== Passing Platforms
41
-
42
- * 1.9.1-p378
43
- * 1.8.7-p334
44
- * 1.9.2-p180 (suggested version)
45
- * 1.9.3-head
46
-
47
-
45
+ ==== 2.x
48
46
 
47
+ Not yet vetted. I don't believe there's anything exciting in these
48
+ platforms, but there has been no attempt yet to perform formal testing.
49
+ I know, I'm behind the times.
49
50
 
50
51
  == Examples
51
52
 
52
- PacketFu ships with dozens and dozens of tests, built on Test::Unit. These should give good pointers on how you're expected to use it. See the /tests directory. Furthermore, PacketFu also ships with packetfu-shell.rb, which should be run via IRB (as root, if you intend to use your interfaces).
53
+ PacketFu ships with dozens and dozens of tests, built on Test::Unit.
54
+ These should give good pointers on how you're expected to use it. See
55
+ the /tests directory. Furthermore, PacketFu also ships with
56
+ packetfu-shell.rb, which should be run via IRB (as root, if you intend
57
+ to use your interfaces).
53
58
 
54
59
  == Author
55
60
 
56
- PacketFu is maintained primarily by Tod Beardsley todb@planb-security.net, with help from Open Source Land.
61
+ PacketFu is maintained primarily by Tod Beardsley todb@packetfu.com and
62
+ Jonathan Claudius claudijd@yahoo.com, with help from Open Source Land.
57
63
 
58
64
  See LICENSE for licensing details.
59
-
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
 
2
2
  begin
3
- require 'rspec/core/rake_task'
3
+ require 'rspec/core/rake_task'
4
4
  rescue LoadError
5
- $stderr.puts "rspec not available, so can't set up spec tasks."
5
+ $stderr.puts "rspec not available, so can't set up spec tasks."
6
6
  else
7
- RSpec::Core::RakeTask.new
7
+ RSpec::Core::RakeTask.new
8
8
 
9
- task :default => :spec
9
+ task :default => :spec
10
10
  end
11
11
 
@@ -8,15 +8,15 @@ IPV4_STR = "1.2.3.4"
8
8
 
9
9
  iters = 50_000
10
10
  Benchmark.bm do |bm|
11
- bm.report("Octets.new.read(...) ") {iters.times {PacketFu::Octets.new.read(IPV4_RAW)}}
12
- bm.report("Octets.new.read_quad(...) ") {iters.times {PacketFu::Octets.new.read_quad(IPV4_STR)}}
11
+ bm.report("Octets.new.read(...) ") {iters.times {PacketFu::Octets.new.read(IPV4_RAW)}}
12
+ bm.report("Octets.new.read_quad(...) ") {iters.times {PacketFu::Octets.new.read_quad(IPV4_STR)}}
13
13
 
14
- octets = PacketFu::Octets.new
15
- bm.report("octets#read(...) ") {iters.times {octets.read(IPV4_RAW)}}
16
- bm.report("octets#read_quad(...) ") {iters.times {octets.read_quad(IPV4_STR)}}
14
+ octets = PacketFu::Octets.new
15
+ bm.report("octets#read(...) ") {iters.times {octets.read(IPV4_RAW)}}
16
+ bm.report("octets#read_quad(...) ") {iters.times {octets.read_quad(IPV4_STR)}}
17
17
 
18
- octets.read(IPV4_RAW)
19
- bm.report("octets#to_x() ") {iters.times {octets.to_x}}
20
- bm.report("octets#to_i() ") {iters.times {octets.to_i}}
21
- bm.report("octets#to_s() ") {iters.times {octets.to_s}}
18
+ octets.read(IPV4_RAW)
19
+ bm.report("octets#to_x() ") {iters.times {octets.to_x}}
20
+ bm.report("octets#to_i() ") {iters.times {octets.to_i}}
21
+ bm.report("octets#to_s() ") {iters.times {octets.to_s}}
22
22
  end
@@ -14,18 +14,18 @@ start_time = Time.now.utc
14
14
  count = 0
15
15
 
16
16
  100.times do
17
- @pcaps = []
18
- 1000.times do
19
- u = UDPPacket.new
20
- u.ip_src = [rand(2**32-1)].pack("N")
21
- u.ip_dst = [rand(2**32-1)].pack("N")
22
- u.recalc
23
- @pcaps << u
24
- end
25
- pfile = PcapFile.new
26
- res = pfile.array_to_file(:filename => "/tmp/out.pcap", :array => @pcaps, :append => true)
27
- count += res.last
28
- puts "Wrote #{count} packets in #{Time.now.utc - start_time} seconds"
17
+ @pcaps = []
18
+ 1000.times do
19
+ u = UDPPacket.new
20
+ u.ip_src = [rand(2**32-1)].pack("N")
21
+ u.ip_dst = [rand(2**32-1)].pack("N")
22
+ u.recalc
23
+ @pcaps << u
24
+ end
25
+ pfile = PcapFile.new
26
+ res = pfile.array_to_file(:filename => "/tmp/out.pcap", :array => @pcaps, :append => true)
27
+ count += res.last
28
+ puts "Wrote #{count} packets in #{Time.now.utc - start_time} seconds"
29
29
  end
30
30
 
31
31
  read_bytes_start = Time.now.utc
@@ -10,25 +10,25 @@ require 'packetfu'
10
10
  #cap = Capture.new(:iface=>'wlan0') # or whatever your interface is
11
11
  # Run this on the third
12
12
  def do_scan
13
- puts "Generating packets..."
14
- pkt_array = gen_packets.sort_by {rand}
15
- puts "Dumping them on the wire..."
16
- inj = PacketFu::Inject.new(:iface => ARGV[0])
17
- inj.array_to_wire(:array=>pkt_array)
18
- puts "Done!"
13
+ puts "Generating packets..."
14
+ pkt_array = gen_packets.sort_by {rand}
15
+ puts "Dumping them on the wire..."
16
+ inj = PacketFu::Inject.new(:iface => ARGV[0])
17
+ inj.array_to_wire(:array=>pkt_array)
18
+ puts "Done!"
19
19
  end
20
20
 
21
21
  def gen_packets
22
- config = PacketFu::Utils.whoami?(:iface=>ARGV[0])
23
- pkt = PacketFu::TCPPacket.new(:config=>config, :flavor=>"Windows")
24
- pkt.payload ="all I wanna do is ACK ACK ACK and a RST and take your money"
25
- pkt.ip_daddr="209.85.165.0" # One of Google's networks
26
- pkt.tcp_flags.ack=1
27
- pkt.tcp_dst=81
28
- pkt_array = []
29
- 256.times do |i|
30
- pkt.ip_dst.o4=i
31
- pkt.tcp_src = rand(5000 - 1025) + 1025
22
+ config = PacketFu::Utils.whoami?(:iface=>ARGV[0])
23
+ pkt = PacketFu::TCPPacket.new(:config=>config, :flavor=>"Windows")
24
+ pkt.payload ="all I wanna do is ACK ACK ACK and a RST and take your money"
25
+ pkt.ip_daddr="209.85.165.0" # One of Google's networks
26
+ pkt.tcp_flags.ack=1
27
+ pkt.tcp_dst=81
28
+ pkt_array = []
29
+ 256.times do |i|
30
+ pkt.ip_dst.o4=i
31
+ pkt.tcp_src = rand(5000 - 1025) + 1025
32
32
  pkt.recalc
33
33
  pkt_array << pkt.to_s
34
34
  end
@@ -9,11 +9,11 @@ require './examples' # For path setting slight-of-hand
9
9
  require 'packetfu'
10
10
 
11
11
  def usage
12
- if ARGV[0].nil?
13
- raise ArgumentError, "You need an IP address to start with."
14
- elsif !Process.euid.zero?
15
- raise SecurityError, "You need to be root to run this."
16
- end
12
+ if ARGV[0].nil?
13
+ raise ArgumentError, "You need an IP address to start with."
14
+ elsif !Process.euid.zero?
15
+ raise SecurityError, "You need to be root to run this."
16
+ end
17
17
  end
18
18
 
19
19
  usage unless target_ip = ARGV[0] # Need a target IP.
@@ -24,36 +24,36 @@ $packetfu_default = PacketFu::Config.new(PacketFu::Utils.whoami?).config
24
24
 
25
25
  def arp(target_ip)
26
26
 
27
- arp_pkt = PacketFu::ARPPacket.new(:flavor => "Windows")
28
- arp_pkt.eth_saddr = arp_pkt.arp_saddr_mac = $packetfu_default[:eth_saddr]
29
- arp_pkt.eth_daddr = "ff:ff:ff:ff:ff:ff"
30
- arp_pkt.arp_daddr_mac = "00:00:00:00:00:00"
31
-
32
- arp_pkt.arp_saddr_ip = $packetfu_default[:ip_saddr]
33
- arp_pkt.arp_daddr_ip = target_ip
34
-
35
- # Stick the Capture object in its own thread.
36
-
37
- cap_thread = Thread.new do
38
- cap = PacketFu::Capture.new(:start => true,
39
- :filter => "arp src #{target_ip} and ether dst #{arp_pkt.eth_saddr}")
40
- arp_pkt.to_w # Shorthand for sending single packets to the default interface.
41
- target_mac = nil
42
- while target_mac.nil?
43
- if cap.save > 0
44
- arp_response = PacketFu::Packet.parse(cap.array[0])
45
- target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip = target_ip
46
- end
47
- sleep 0.1 # Check for a response ten times per second.
48
- end
49
- puts "#{target_ip} is-at #{target_mac}"
50
- # That's all we need.
51
- exit 0
52
- end
53
-
54
- # Timeout for cap_thread
55
- sleep 3; puts "Oh noes! Couldn't get an arp out of #{target_ip}. Maybe it's not here."
56
- exit 1
27
+ arp_pkt = PacketFu::ARPPacket.new(:flavor => "Windows")
28
+ arp_pkt.eth_saddr = arp_pkt.arp_saddr_mac = $packetfu_default[:eth_saddr]
29
+ arp_pkt.eth_daddr = "ff:ff:ff:ff:ff:ff"
30
+ arp_pkt.arp_daddr_mac = "00:00:00:00:00:00"
31
+
32
+ arp_pkt.arp_saddr_ip = $packetfu_default[:ip_saddr]
33
+ arp_pkt.arp_daddr_ip = target_ip
34
+
35
+ # Stick the Capture object in its own thread.
36
+
37
+ cap_thread = Thread.new do
38
+ cap = PacketFu::Capture.new(:start => true,
39
+ :filter => "arp src #{target_ip} and ether dst #{arp_pkt.eth_saddr}")
40
+ arp_pkt.to_w # Shorthand for sending single packets to the default interface.
41
+ target_mac = nil
42
+ while target_mac.nil?
43
+ if cap.save > 0
44
+ arp_response = PacketFu::Packet.parse(cap.array[0])
45
+ target_mac = arp_response.arp_saddr_mac if arp_response.arp_saddr_ip = target_ip
46
+ end
47
+ sleep 0.1 # Check for a response ten times per second.
48
+ end
49
+ puts "#{target_ip} is-at #{target_mac}"
50
+ # That's all we need.
51
+ exit 0
52
+ end
53
+
54
+ # Timeout for cap_thread
55
+ sleep 3; puts "Oh noes! Couldn't get an arp out of #{target_ip}. Maybe it's not here."
56
+ exit 1
57
57
  end
58
58
 
59
59
  arp(target_ip)
@@ -11,20 +11,20 @@ require 'open-uri'
11
11
  $oui_prefixes = {}
12
12
  $arp_results = []
13
13
  def build_oui_list
14
- if ARGV[2].nil?
15
- puts "Fetching the oui.txt from IEEE, it'll be a second. Avoid this with #{$0} [iface] [network] <filename>."
16
- oui_file = open("http://standards.ieee.org/regauth/oui/oui.txt")
17
- else
18
- oui_file = File.open(ARGV[2], "rb")
19
- end
20
- oui_file.each do |oui_line|
21
- maybe_oui = oui_line.scan(/^[0-9a-f]{2}\-[0-9a-f]{2}\-[0-9a-f]{2}/i)[0]
22
- unless maybe_oui.nil?
23
- oui_value = maybe_oui
24
- oui_vendor = oui_line.split(/\(hex\)\s*/n)[1] || "PRIVATE"
25
- $oui_prefixes[oui_value] = oui_vendor.chomp
26
- end
27
- end
14
+ if ARGV[2].nil?
15
+ puts "Fetching the oui.txt from IEEE, it'll be a second. Avoid this with #{$0} [iface] [network] <filename>."
16
+ oui_file = open("http://standards.ieee.org/regauth/oui/oui.txt")
17
+ else
18
+ oui_file = File.open(ARGV[2], "rb")
19
+ end
20
+ oui_file.each do |oui_line|
21
+ maybe_oui = oui_line.scan(/^[0-9a-f]{2}\-[0-9a-f]{2}\-[0-9a-f]{2}/i)[0]
22
+ unless maybe_oui.nil?
23
+ oui_value = maybe_oui
24
+ oui_vendor = oui_line.split(/\(hex\)\s*/n)[1] || "PRIVATE"
25
+ $oui_prefixes[oui_value] = oui_vendor.chomp
26
+ end
27
+ end
28
28
  end
29
29
 
30
30
  build_oui_list
@@ -32,30 +32,30 @@ build_oui_list
32
32
  $root_ok = true if Process.euid.zero?
33
33
 
34
34
  def arp_everyone
35
- my_net = PacketFu::Config.new(PacketFu::Utils.whoami?(:iface =>(ARGV[0] || 'wlan0')))
36
- threads = []
37
- network = ARGV[1] || "192.168.2"
38
- print "Arping around..."
39
- 253.times do |i|
40
- threads[i] = Thread.new do
41
- this_host = network + ".#{i+1}"
42
- print "."
43
- colon_mac = PacketFu::Utils.arp(this_host,my_net.config)
44
- unless colon_mac.nil?
45
- hyphen_mac = colon_mac.tr(':','-').upcase[0,8]
46
- else
47
- hyphen_mac = colon_mac = "NOTHERE"
48
- end
49
- $arp_results << "%s : %s / %s" % [this_host,colon_mac,$oui_prefixes[hyphen_mac]]
50
- end
51
- end
52
- threads.each {|thr| thr.join}
35
+ my_net = PacketFu::Config.new(PacketFu::Utils.whoami?(:iface =>(ARGV[0] || 'wlan0')))
36
+ threads = []
37
+ network = ARGV[1] || "192.168.2"
38
+ print "Arping around..."
39
+ 253.times do |i|
40
+ threads[i] = Thread.new do
41
+ this_host = network + ".#{i+1}"
42
+ print "."
43
+ colon_mac = PacketFu::Utils.arp(this_host,my_net.config)
44
+ unless colon_mac.nil?
45
+ hyphen_mac = colon_mac.tr(':','-').upcase[0,8]
46
+ else
47
+ hyphen_mac = colon_mac = "NOTHERE"
48
+ end
49
+ $arp_results << "%s : %s / %s" % [this_host,colon_mac,$oui_prefixes[hyphen_mac]]
50
+ end
51
+ end
52
+ threads.each {|thr| thr.join}
53
53
  end
54
54
 
55
55
  if $root_ok
56
- arp_everyone
57
- puts "\n"
58
- sleep 3
59
- $arp_results.sort.each {|a| puts a unless a =~ /NOTHERE/}
56
+ arp_everyone
57
+ puts "\n"
58
+ sleep 3
59
+ $arp_results.sort.each {|a| puts a unless a =~ /NOTHERE/}
60
60
  end
61
61