packetfu 1.1.11 → 1.1.12.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rspec +2 -0
  4. data/.travis.yml +2 -3
  5. data/README.md +127 -0
  6. data/examples/100kpackets.rb +11 -10
  7. data/examples/ackscan.rb +4 -1
  8. data/examples/arp.rb +4 -5
  9. data/examples/arphood.rb +5 -4
  10. data/examples/dissect_thinger.rb +10 -7
  11. data/examples/ethernet.rb +8 -3
  12. data/examples/ids.rb +22 -4
  13. data/examples/idsv2.rb +25 -6
  14. data/examples/ifconfig.rb +6 -3
  15. data/examples/new-simple-stats.rb +5 -6
  16. data/examples/packetfu-shell.rb +11 -48
  17. data/examples/pcap2pcapng.rb +32 -0
  18. data/examples/simple-sniffer.rb +9 -4
  19. data/examples/simple-stats.rb +7 -8
  20. data/examples/slammer.rb +2 -2
  21. data/examples/uniqpcap.rb +17 -7
  22. data/lib/packetfu.rb +10 -175
  23. data/lib/packetfu/capture.rb +2 -2
  24. data/lib/packetfu/common.rb +142 -0
  25. data/lib/packetfu/config.rb +8 -8
  26. data/lib/packetfu/inject.rb +3 -3
  27. data/lib/packetfu/packet.rb +22 -18
  28. data/lib/packetfu/pcap.rb +2 -1
  29. data/lib/packetfu/pcapng.rb +37 -0
  30. data/lib/packetfu/pcapng/block.rb +25 -0
  31. data/lib/packetfu/pcapng/epb.rb +112 -0
  32. data/lib/packetfu/pcapng/file.rb +316 -0
  33. data/lib/packetfu/pcapng/idb.rb +125 -0
  34. data/lib/packetfu/pcapng/shb.rb +146 -0
  35. data/lib/packetfu/pcapng/spb.rb +83 -0
  36. data/lib/packetfu/pcapng/unknown_block.rb +60 -0
  37. data/lib/packetfu/protos.rb +3 -0
  38. data/lib/packetfu/protos/arp.rb +10 -10
  39. data/lib/packetfu/protos/icmpv6.rb +131 -0
  40. data/lib/packetfu/protos/icmpv6/header.rb +69 -0
  41. data/lib/packetfu/protos/icmpv6/mixin.rb +14 -0
  42. data/lib/packetfu/protos/ip.rb +4 -5
  43. data/lib/packetfu/protos/ipv6/header.rb +2 -0
  44. data/lib/packetfu/protos/udp.rb +24 -12
  45. data/lib/packetfu/structfu.rb +27 -0
  46. data/lib/packetfu/utils.rb +55 -9
  47. data/lib/packetfu/version.rb +1 -1
  48. data/packetfu.gemspec +13 -7
  49. data/spec/arp_spec.rb +11 -5
  50. data/spec/eth_spec.rb +20 -11
  51. data/spec/fake_packets.rb +28 -0
  52. data/spec/hsrp_spec.rb +15 -0
  53. data/spec/icmp_spec.rb +12 -5
  54. data/spec/icmpv6_spec.rb +98 -0
  55. data/spec/invalid_spec.rb +28 -0
  56. data/spec/ip_spec.rb +10 -5
  57. data/spec/ipv4_icmp.pcap +0 -0
  58. data/spec/ipv4_udp.pcap +0 -0
  59. data/spec/ipv6_icmp.pcap +0 -0
  60. data/spec/ipv6_spec.rb +4 -0
  61. data/spec/ipv6_udp.pcap +0 -0
  62. data/spec/lldp_spec.rb +36 -0
  63. data/spec/octets_spec.rb +43 -0
  64. data/spec/packet_spec.rb +24 -0
  65. data/spec/packetfu_spec.rb +6 -1
  66. data/spec/pcap_spec.rb +286 -0
  67. data/spec/pcapng/epb_spec.rb +81 -0
  68. data/spec/pcapng/file_spec.rb +295 -0
  69. data/spec/pcapng/file_spec_helper.rb +45 -0
  70. data/spec/pcapng/idb_spec.rb +53 -0
  71. data/spec/pcapng/shb_spec.rb +42 -0
  72. data/spec/pcapng/spb_spec.rb +43 -0
  73. data/spec/pcapng/unknown_block_spec.rb +36 -0
  74. data/spec/spec_helper.rb +3 -31
  75. data/spec/tcp_spec.rb +4 -1
  76. data/spec/udp_spec.rb +149 -1
  77. data/spec/utils_spec.rb +98 -15
  78. data/test/pcapng-test/output_be/advanced/test100.pcapng +0 -0
  79. data/test/pcapng-test/output_be/advanced/test100.txt +11 -0
  80. data/test/pcapng-test/output_be/advanced/test101.pcapng +0 -0
  81. data/test/pcapng-test/output_be/advanced/test101.txt +11 -0
  82. data/test/pcapng-test/output_be/advanced/test102.pcapng +0 -0
  83. data/test/pcapng-test/output_be/advanced/test102.txt +14 -0
  84. data/test/pcapng-test/output_be/basic/test001.pcapng +0 -0
  85. data/test/pcapng-test/output_be/basic/test001.txt +9 -0
  86. data/test/pcapng-test/output_be/basic/test002.pcapng +0 -0
  87. data/test/pcapng-test/output_be/basic/test002.txt +7 -0
  88. data/test/pcapng-test/output_be/basic/test003.pcapng +0 -0
  89. data/test/pcapng-test/output_be/basic/test003.txt +8 -0
  90. data/test/pcapng-test/output_be/basic/test004.pcapng +0 -0
  91. data/test/pcapng-test/output_be/basic/test004.txt +9 -0
  92. data/test/pcapng-test/output_be/basic/test005.pcapng +0 -0
  93. data/test/pcapng-test/output_be/basic/test005.txt +9 -0
  94. data/test/pcapng-test/output_be/basic/test006.pcapng +0 -0
  95. data/test/pcapng-test/output_be/basic/test006.txt +9 -0
  96. data/test/pcapng-test/output_be/basic/test007.pcapng +0 -0
  97. data/test/pcapng-test/output_be/basic/test007.txt +9 -0
  98. data/test/pcapng-test/output_be/basic/test008.pcapng +0 -0
  99. data/test/pcapng-test/output_be/basic/test008.txt +9 -0
  100. data/test/pcapng-test/output_be/basic/test009.pcapng +0 -0
  101. data/test/pcapng-test/output_be/basic/test009.txt +9 -0
  102. data/test/pcapng-test/output_be/basic/test010.pcapng +0 -0
  103. data/test/pcapng-test/output_be/basic/test010.txt +9 -0
  104. data/test/pcapng-test/output_be/basic/test011.pcapng +0 -0
  105. data/test/pcapng-test/output_be/basic/test011.txt +10 -0
  106. data/test/pcapng-test/output_be/basic/test012.pcapng +0 -0
  107. data/test/pcapng-test/output_be/basic/test012.txt +10 -0
  108. data/test/pcapng-test/output_be/basic/test013.pcapng +0 -0
  109. data/test/pcapng-test/output_be/basic/test013.txt +9 -0
  110. data/test/pcapng-test/output_be/basic/test014.pcapng +0 -0
  111. data/test/pcapng-test/output_be/basic/test014.txt +9 -0
  112. data/test/pcapng-test/output_be/basic/test015.pcapng +0 -0
  113. data/test/pcapng-test/output_be/basic/test015.txt +9 -0
  114. data/test/pcapng-test/output_be/basic/test016.pcapng +0 -0
  115. data/test/pcapng-test/output_be/basic/test016.txt +11 -0
  116. data/test/pcapng-test/output_be/basic/test017.pcapng +0 -0
  117. data/test/pcapng-test/output_be/basic/test017.txt +9 -0
  118. data/test/pcapng-test/output_be/basic/test018.pcapng +0 -0
  119. data/test/pcapng-test/output_be/basic/test018.txt +12 -0
  120. data/test/pcapng-test/output_be/difficult/test200.pcapng +0 -0
  121. data/test/pcapng-test/output_be/difficult/test200.txt +8 -0
  122. data/test/pcapng-test/output_be/difficult/test201.pcapng +0 -0
  123. data/test/pcapng-test/output_be/difficult/test201.txt +11 -0
  124. data/test/pcapng-test/output_be/difficult/test202.pcapng +0 -0
  125. data/test/pcapng-test/output_be/difficult/test202.txt +14 -0
  126. data/test/pcapng-test/output_le/advanced/test100.pcapng +0 -0
  127. data/test/pcapng-test/output_le/advanced/test100.txt +11 -0
  128. data/test/pcapng-test/output_le/advanced/test101.pcapng +0 -0
  129. data/test/pcapng-test/output_le/advanced/test101.txt +11 -0
  130. data/test/pcapng-test/output_le/advanced/test102.pcapng +0 -0
  131. data/test/pcapng-test/output_le/advanced/test102.txt +14 -0
  132. data/test/pcapng-test/output_le/basic/test001.pcapng +0 -0
  133. data/test/pcapng-test/output_le/basic/test001.txt +9 -0
  134. data/test/pcapng-test/output_le/basic/test002.pcapng +0 -0
  135. data/test/pcapng-test/output_le/basic/test002.txt +7 -0
  136. data/test/pcapng-test/output_le/basic/test003.pcapng +0 -0
  137. data/test/pcapng-test/output_le/basic/test003.txt +8 -0
  138. data/test/pcapng-test/output_le/basic/test004.pcapng +0 -0
  139. data/test/pcapng-test/output_le/basic/test004.txt +9 -0
  140. data/test/pcapng-test/output_le/basic/test005.pcapng +0 -0
  141. data/test/pcapng-test/output_le/basic/test005.txt +9 -0
  142. data/test/pcapng-test/output_le/basic/test006.pcapng +0 -0
  143. data/test/pcapng-test/output_le/basic/test006.txt +9 -0
  144. data/test/pcapng-test/output_le/basic/test007.pcapng +0 -0
  145. data/test/pcapng-test/output_le/basic/test007.txt +9 -0
  146. data/test/pcapng-test/output_le/basic/test008.pcapng +0 -0
  147. data/test/pcapng-test/output_le/basic/test008.txt +9 -0
  148. data/test/pcapng-test/output_le/basic/test009.pcapng +0 -0
  149. data/test/pcapng-test/output_le/basic/test009.txt +9 -0
  150. data/test/pcapng-test/output_le/basic/test010.pcapng +0 -0
  151. data/test/pcapng-test/output_le/basic/test010.txt +9 -0
  152. data/test/pcapng-test/output_le/basic/test011.pcapng +0 -0
  153. data/test/pcapng-test/output_le/basic/test011.txt +10 -0
  154. data/test/pcapng-test/output_le/basic/test012.pcapng +0 -0
  155. data/test/pcapng-test/output_le/basic/test012.txt +10 -0
  156. data/test/pcapng-test/output_le/basic/test013.pcapng +0 -0
  157. data/test/pcapng-test/output_le/basic/test013.txt +9 -0
  158. data/test/pcapng-test/output_le/basic/test014.pcapng +0 -0
  159. data/test/pcapng-test/output_le/basic/test014.txt +9 -0
  160. data/test/pcapng-test/output_le/basic/test015.pcapng +0 -0
  161. data/test/pcapng-test/output_le/basic/test015.txt +9 -0
  162. data/test/pcapng-test/output_le/basic/test016.pcapng +0 -0
  163. data/test/pcapng-test/output_le/basic/test016.txt +11 -0
  164. data/test/pcapng-test/output_le/basic/test017.pcapng +0 -0
  165. data/test/pcapng-test/output_le/basic/test017.txt +9 -0
  166. data/test/pcapng-test/output_le/basic/test018.pcapng +0 -0
  167. data/test/pcapng-test/output_le/basic/test018.txt +12 -0
  168. data/test/pcapng-test/output_le/difficult/test200.pcapng +0 -0
  169. data/test/pcapng-test/output_le/difficult/test200.txt +8 -0
  170. data/test/pcapng-test/output_le/difficult/test201.pcapng +0 -0
  171. data/test/pcapng-test/output_le/difficult/test201.txt +11 -0
  172. data/test/pcapng-test/output_le/difficult/test202.pcapng +0 -0
  173. data/test/pcapng-test/output_le/difficult/test202.txt +14 -0
  174. data/test/sample-ipv6.pcapng +0 -0
  175. data/test/sample-spb.pcapng +0 -0
  176. data/test/sample.pcapng +0 -0
  177. data/test/sample2.pcapng +0 -0
  178. metadata +190 -68
  179. checksums.yaml.gz.sig +0 -0
  180. data.tar.gz.sig +0 -2
  181. data/INSTALL.rdoc +0 -40
  182. data/README.rdoc +0 -64
  183. data/examples/examples.rb +0 -4
  184. data/setup.rb +0 -1586
  185. data/test/func_lldp.rb +0 -25
  186. data/test/ptest.rb +0 -16
  187. data/test/test_eth.rb +0 -93
  188. data/test/test_hsrp.rb +0 -20
  189. data/test/test_invalid.rb +0 -28
  190. data/test/test_octets.rb +0 -36
  191. data/test/test_pcap.rb +0 -211
  192. data/test/test_udp.rb +0 -100
  193. metadata.gz.sig +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45346a86ccf70ceeb48ded267817e9395bb796d8
4
- data.tar.gz: 92a9e7485b2d2089b9f4e4d0ee5ccdd00bea34a0
3
+ metadata.gz: 27fdb60e2d8cf9c2abe63361c024c6b6b4077c45
4
+ data.tar.gz: ddb6a367565f97de59c730d6e5141e85165407f4
5
5
  SHA512:
6
- metadata.gz: 013e4765cf60749f3d12431446e7b8b82a63889cb60abbb5d6d2abc69b6dbc2812ffd768fd0ad5341b73d729ee3ae1a8620f6aa521c9579dc17be197767100a2
7
- data.tar.gz: 7a0e1442c308792c79a00065852b13e91be050a68b981b02bc78f12db9d12955eb00b6f56be576228cbf4a8719f51e55e3f424916b7939b1ddb1f5eb47737351
6
+ metadata.gz: d063030465de3423c0b59295bd5ebd02d568d1832f7770965cb6825d29d645cfd6bc6ab43e40cb5871fb7b187507d3ba2a1415bc3d63b7b017287b39adfd5481
7
+ data.tar.gz: 445f37e0c272b179382396bd2307fa24e6214fd0ae8cdb34d65cbcdef3fd05562a927239bea0f4aeaf6d79d34386827d4c2489604b9261b35422eb376ba6937b
data/.gitignore CHANGED
@@ -1,7 +1,9 @@
1
1
  *.gem
2
2
  doc/
3
+ .yardoc/
3
4
  pkg/
4
5
  test/*test.pcap
5
6
  Gemfile.lock
6
7
  .ruby-gemset*
7
- .ruby-version*
8
+ .ruby-version*
9
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
@@ -2,7 +2,6 @@ language: ruby
2
2
  before_install:
3
3
  - sudo apt-get install libpcap-dev -qq
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
5
  - 2.1.6
8
- - 2.2.2
6
+ - 2.2.3
7
+ - 2.3.0
@@ -0,0 +1,127 @@
1
+ # PacketFu
2
+
3
+ [![Build Status](https://secure.travis-ci.org/packetfu/packetfu.png)](http://travis-ci.org/packetfu/packetfu)
4
+ [![Code Climate](https://codeclimate.com/github/packetfu/packetfu.png)](https://codeclimate.com/github/packetfu/packetfu)
5
+ [![Coverage Status](https://coveralls.io/repos/github/packetfu/packetfu/badge.svg?branch=master)](https://coveralls.io/github/packetfu/packetfu?branch=master)
6
+
7
+ A library for reading and writing packets to an interface or to a
8
+ libpcap-formatted file.
9
+
10
+ It is maintained [here](https://github.com/packetfu/packetfu).
11
+
12
+ ## Setup
13
+
14
+ To install the gem, type
15
+
16
+ ```bash
17
+ gem install packetfu
18
+ ```
19
+
20
+ To install from source, type
21
+
22
+ ```bash
23
+ gem install bundler
24
+ git clone https://github.com/packetfu/packetfu.git
25
+ cd packetfu
26
+ bundle install
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ The best way to test your installation is by using [packetfu-shell](https://github.com/packetfu/packetfu/blob/master/examples/packetfu-shell.rb), like so
32
+
33
+ ```bash
34
+ $ rvmsudo ruby examples/packetfu-shell.rb
35
+ _______ _______ _______ _ _______ _________ _______
36
+ ( ____ )( ___ )( ____ \| \ /\( ____ \\__ __/( ____ \|\ /|
37
+ | ( )|| ( ) || ( \/| \ / /| ( \/ ) ( | ( \/| ) ( |
38
+ | (____)|| (___) || | | (_/ / | (__ | | | (__ | | | |
39
+ | _____)| ___ || | | _ ( | __) | | | __) | | | |
40
+ | ( | ( ) || | | ( \ \ | ( | | | ( | | | |
41
+ | ) | ) ( || (____/\| / \ \| (____/\ | | | ) | (___) |
42
+ |/ |/ \|(_______/|_/ \/(_______/ )_( |/ (_______)
43
+ ____________________________ ____________________________
44
+ ( ) ( )
45
+ | 01000001 00101101 01001000 )( )( )( )( )( 00101101 01000001 00100001 |
46
+ | )( )( )( )( )( |
47
+ (____________________________) (____________________________)
48
+ PacketFu
49
+ a mid-level packet manipulation library for ruby
50
+
51
+ >>> PacketFu Shell 1.1.12.
52
+ >>> Use $packetfu_default.config for salient networking details.
53
+ IP: 192.168.0.100 Mac: ac:bc:32:85:47:3f Gateway: ec:08:6b:62:bc:d2
54
+ Net: 192.168.0.0 Iface: en0
55
+ >>> Packet capturing/injecting enabled.
56
+ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
57
+ 2.3.0 :001 >
58
+ ```
59
+
60
+ Once you're a this point, you're in an IRB (aka: [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)) interface when you can start creating and injection packets with PacketFu.
61
+
62
+ Here's an example of creating a TCPPacket and sending it out on the wire:
63
+
64
+ ```
65
+ 2.3.0 :002 > packet = TCPPacket.new(:config => Utils.whoami?)
66
+ => --EthHeader-------------------------------------------
67
+ eth_dst ec:08:6b:62:bc:d2 PacketFu::EthMac
68
+ eth_src ac:bc:32:85:47:3f PacketFu::EthMac
69
+ eth_proto 0x0800 StructFu::Int16
70
+ --IPHeader--------------------------------------------
71
+ ip_v 4 Fixnum
72
+ ip_hl 5 Fixnum
73
+ ip_tos 0 StructFu::Int8
74
+ ip_len 20 StructFu::Int16
75
+ ip_id 0x77e4 StructFu::Int16
76
+ ip_frag 0 StructFu::Int16
77
+ ip_ttl 32 StructFu::Int8
78
+ ip_proto 6 StructFu::Int8
79
+ ip_sum 0xffff StructFu::Int16
80
+ ip_src 192.168.0.100 PacketFu::Octets
81
+ ip_dst 0.0.0.0 PacketFu::Octets
82
+ --TCPHeader-------------------------------------------
83
+ tcp_src 42653 StructFu::Int16
84
+ tcp_dst 0 StructFu::Int16
85
+ tcp_seq 0x8d65fbbf StructFu::Int32
86
+ tcp_ack 0x00000000 StructFu::Int32
87
+ tcp_hlen 5 PacketFu::TcpHlen
88
+ tcp_reserved 0 PacketFu::TcpReserved
89
+ tcp_ecn 0 PacketFu::TcpEcn
90
+ tcp_flags ...... PacketFu::TcpFlags
91
+ tcp_win 16384 StructFu::Int16
92
+ tcp_sum 0x7f29 StructFu::Int16
93
+ tcp_urg 0 StructFu::Int16
94
+ tcp_opts PacketFu::TcpOptions
95
+
96
+ 2.3.0 :003 > packet.ip_dst = "8.8.8.8"
97
+ => "8.8.8.8"
98
+ 2.3.0 :004 > packet.tcp_dst = 53
99
+ => 53
100
+ 2.3.0 :005 > packet.to_w
101
+ => [1, 1, 54]
102
+ ```
103
+
104
+ ## Documentation
105
+
106
+ PacketFu is yard-compatible (as well as sdoc/rdoc, if you prefer). You
107
+ can generate local documentation easily with either `yard doc .` or
108
+ `sdoc`, and view doc/index.html with your favored browser. Once that's
109
+ done, navigate at the top, and read up on how to create a Packet or
110
+ Capture from an interface with show_live or whatever.
111
+
112
+ ## Supported Rubies
113
+
114
+ This project is integrated with travis-ci and is regularly tested to work with the following rubies:
115
+
116
+ - 2.1.6
117
+ - 2.2.3
118
+ - 2.3.0
119
+
120
+ To checkout the current build status for these rubies, click [here](https://travis-ci.org/packetfu/packetfu).
121
+
122
+ ## Author
123
+
124
+ PacketFu is maintained primarily by Tod Beardsley todb@packetfu.com and
125
+ Jonathan Claudius claudijd@yahoo.com, with help from Open Source Land.
126
+
127
+ See [LICENSE](https://github.com/packetfu/packetfu/blob/master/LICENSE.txt) for licensing details.
@@ -3,10 +3,14 @@
3
3
 
4
4
  # Used mainly to test for memory leaks and to demo the preferred ways of
5
5
  # reading and writing packets to and from pcap files.
6
- require './examples' # For path setting slight-of-hand
6
+
7
+ # Usage:
8
+ # ruby examples/100kpackets.rb
9
+
10
+ # Path setting slight of hand:
11
+ $: << File.expand_path("../../lib", __FILE__)
7
12
  require 'packetfu'
8
13
 
9
- include PacketFu
10
14
  puts "Generating packets... (#{Time.now.utc})"
11
15
 
12
16
  File.unlink("/tmp/out.pcap") if File.exists? "/tmp/out.pcap"
@@ -15,14 +19,14 @@ count = 0
15
19
 
16
20
  100.times do
17
21
  @pcaps = []
18
- 1000.times do
19
- u = UDPPacket.new
22
+ 1000.times do
23
+ u = PacketFu::UDPPacket.new
20
24
  u.ip_src = [rand(2**32-1)].pack("N")
21
25
  u.ip_dst = [rand(2**32-1)].pack("N")
22
26
  u.recalc
23
27
  @pcaps << u
24
28
  end
25
- pfile = PcapFile.new
29
+ pfile = PacketFu::PcapFile.new
26
30
  res = pfile.array_to_file(:filename => "/tmp/out.pcap", :array => @pcaps, :append => true)
27
31
  count += res.last
28
32
  puts "Wrote #{count} packets in #{Time.now.utc - start_time} seconds"
@@ -30,13 +34,10 @@ end
30
34
 
31
35
  read_bytes_start = Time.now.utc
32
36
  puts "Reading packet bytes..."
33
- packet_bytes = PcapFile.read_packet_bytes "/tmp/out.pcap"
37
+ packet_bytes = PacketFu::PcapFile.read_packet_bytes "/tmp/out.pcap"
34
38
  puts "Read #{packet_bytes.size} packet byte blobs in #{Time.now.utc - read_bytes_start} seconds."
35
39
 
36
40
  read_packets_start = Time.now.utc
37
41
  puts "Reading packets..."
38
- packet_bytes = PcapFile.read_packets "/tmp/out.pcap"
42
+ packet_bytes = PacketFu::PcapFile.read_packets "/tmp/out.pcap"
39
43
  puts "Read #{packet_bytes.size} parsed packets in #{Time.now.utc - read_packets_start} seconds."
40
-
41
-
42
-
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: binary -*-
3
+
4
+ # Path setting slight of hand:
5
+ $: << File.expand_path("../../lib", __FILE__)
3
6
  require 'packetfu'
7
+
4
8
  # Portscanning!
5
9
  # Run this on one machine
6
10
  #cap = Capture.new(:iface=>'wlan0') # or whatever your interface is
@@ -36,4 +40,3 @@ def gen_packets
36
40
  end
37
41
 
38
42
  do_scan
39
-
@@ -5,7 +5,8 @@
5
5
  # (and a wee bit cleaner) is already available as Packet::Utils::arp, since knowing the
6
6
  # MAC address of a target IP turns out to be pretty useful day-to-day.
7
7
 
8
- require './examples' # For path setting slight-of-hand
8
+ # Path setting slight of hand:
9
+ $: << File.expand_path("../../lib", __FILE__)
9
10
  require 'packetfu'
10
11
 
11
12
  def usage
@@ -30,12 +31,12 @@ def arp(target_ip)
30
31
  arp_pkt.arp_daddr_mac = "00:00:00:00:00:00"
31
32
 
32
33
  arp_pkt.arp_saddr_ip = $packetfu_default[:ip_saddr]
33
- arp_pkt.arp_daddr_ip = target_ip
34
+ arp_pkt.arp_daddr_ip = target_ip
34
35
 
35
36
  # Stick the Capture object in its own thread.
36
37
 
37
38
  cap_thread = Thread.new do
38
- cap = PacketFu::Capture.new(:start => true,
39
+ cap = PacketFu::Capture.new(:start => true,
39
40
  :filter => "arp src #{target_ip} and ether dst #{arp_pkt.eth_saddr}")
40
41
  arp_pkt.to_w # Shorthand for sending single packets to the default interface.
41
42
  target_mac = nil
@@ -57,5 +58,3 @@ def arp(target_ip)
57
58
  end
58
59
 
59
60
  arp(target_ip)
60
-
61
-
@@ -2,9 +2,11 @@
2
2
  # -*- coding: binary -*-
3
3
 
4
4
  # A simple local network fingerprinter. Uses the OUI list.
5
- # Usage: rvmsudo ./arphood.rb [iface] [network] <oui.txt>
5
+ # Usage:
6
+ # rvmsudo examples/arphood.rb [iface] [network] <oui.txt>
6
7
 
7
- require './examples'
8
+ # Path setting slight of hand:
9
+ $: << File.expand_path("../../lib", __FILE__)
8
10
  require 'packetfu'
9
11
  require 'open-uri'
10
12
 
@@ -39,7 +41,7 @@ def arp_everyone
39
41
  253.times do |i|
40
42
  threads[i] = Thread.new do
41
43
  this_host = network + ".#{i+1}"
42
- print "."
44
+ print "."
43
45
  colon_mac = PacketFu::Utils.arp(this_host,my_net.config)
44
46
  unless colon_mac.nil?
45
47
  hyphen_mac = colon_mac.tr(':','-').upcase[0,8]
@@ -58,4 +60,3 @@ if $root_ok
58
60
  sleep 3
59
61
  $arp_results.sort.each {|a| puts a unless a =~ /NOTHERE/}
60
62
  end
61
-
@@ -1,18 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: binary -*-
3
3
  # This just allows you to eyeball the dissection stuff to make sure it's all right.
4
- # Some day, there will be a proper test for it.
5
4
 
6
- fname = ARGV[0] || "../test/sample.pcap"
5
+ # Usage:
6
+ # ruby examples/ethernet.rb
7
+
8
+ # Path setting slight of hand:
9
+ $: << File.expand_path("../../lib", __FILE__)
10
+ require 'packetfu'
11
+ include PacketFu
12
+
13
+ fname = ARGV[0] || "test/sample.pcap"
7
14
  sleep_interval = ARGV[1] || 1
8
15
 
9
- require File.join("..","lib","packetfu")
10
16
  puts "Loaded: PacketFu v#{PacketFu.version}"
11
- # $: << File.join(File.expand_path(File.dirname(__FILE__)),"..","lib")
12
-
13
- include PacketFu
14
17
 
15
- packets = PcapFile.file_to_array fname
18
+ packets = PacketFu::PcapFile.file_to_array fname
16
19
  packets.each do |packet|
17
20
  puts "_" * 75
18
21
  puts packet.inspect
@@ -1,11 +1,16 @@
1
1
  # -*- coding: binary -*-
2
2
 
3
- require './examples' # For path setting slight-of-hand
3
+ # Usage:
4
+ # ruby examples/ethernet.rb
5
+
6
+ # Path setting slight of hand:
7
+ $: << File.expand_path("../../lib", __FILE__)
4
8
  require 'packetfu'
5
9
 
6
10
  eth_pkt = PacketFu::EthPacket.new
7
11
  eth_pkt.eth_saddr="01:02:03:04:05:06"
8
12
  eth_pkt.eth_daddr="0a:0b:0c:0d:0e:0f"
9
13
  eth_pkt.payload="I'm a lonely little eth packet with no real protocol information to speak of."
10
- puts eth_pkt.to_f('/tmp/e.pcap').inspect
11
-
14
+ eth_pkt.recalc
15
+ puts eth_pkt.inspect
16
+ puts eth_pkt.to_f('/tmp/ethernet.pcap').inspect
@@ -1,4 +1,22 @@
1
- require 'packetfu' # Line 1, require PacketFu.
2
- cap = PacketFu::Capture.new(:iface => ARGV[0], :start => true, :filter => "ip") # Line 2, set up the capture object.
3
- loop {cap.stream.each {|pkt| packet = PacketFu::Packet.parse(pkt) # Line 3, loop the capture forever, parsing packets.
4
- p "#{Time.now}: %s slammed %s" % [packet.ip_saddr, packet.ip_daddr] if packet.payload =~ /^\x04\x01{50}/ }} # Line 4, profit! I mean, alert!
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: binary -*-
3
+
4
+ # Usage:
5
+ # rvmsudo ruby examples/idsv2.rb
6
+
7
+ # Path setting slight of hand:
8
+ $: << File.expand_path("../../lib", __FILE__)
9
+ require 'packetfu'
10
+
11
+ iface = ARGV[0] || PacketFu::Utils.default_int
12
+
13
+ cap = PacketFu::Capture.new(:iface => iface, :start => true, :filter => "ip")
14
+
15
+ loop do
16
+ cap.stream.each do |pkt|
17
+ packet = PacketFu::Packet.parse(pkt)
18
+ if packet.payload =~ /^\x04\x01{50}/
19
+ p "#{Time.now}: %s slammed %s" % [packet.ip_saddr, packet.ip_daddr]
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,25 @@
1
- require 'packetfu' # Line 0, require PacketFu for an IDS in 6 lines or less!
2
- cap = PacketFu::Capture.new(:iface => ARGV[0], :start => true, :filter => "ip") # Line 1, set up the capture object.
3
- attack_patterns = ["^gotcha", "owned!*$", "^\x04[^\x00]{50}"] # Line 2, define your attack patterns.
4
- loop {cap.stream.each {|pkt| packet = PacketFu::Packet.parse(pkt) # Line 3, loop the capture forever, parsing packets.
5
- attack_patterns.each {|sig| hit = packet.payload.scan(/#{sig}/i) || nil # Line 4, test the packet for a match against one of the attacks.
6
- puts "#{Time.now}: %s attacked %s [%s]" % [packet.ip_saddr, packet.ip_daddr, sig.inspect] unless hit.size.zero? }}} # Line 5, profit! I mean, alert!
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: binary -*-
3
+
4
+ # Usage:
5
+ # rvmsudo ruby examples/idsv2.rb
6
+
7
+ # Path setting slight of hand:
8
+ $: << File.expand_path("../../lib", __FILE__)
9
+ require 'packetfu'
10
+
11
+ iface = ARGV[0] || PacketFu::Utils.default_int
12
+
13
+ cap = PacketFu::Capture.new(:iface => iface, :start => true, :filter => "ip")
14
+
15
+ attack_patterns = ["^gotcha", "owned!*$", "^\x04[^\x00]{50}"]
16
+
17
+ loop do
18
+ cap.stream.each do |pkt|
19
+ packet = PacketFu::Packet.parse(pkt)
20
+ attack_patterns.each do |sig|
21
+ hit = packet.payload.scan(/#{sig}/i) || nil
22
+ puts "#{Time.now}: %s attacked %s [%s]" % [packet.ip_saddr, packet.ip_daddr, sig.inspect] unless hit.size.zero?
23
+ end
24
+ end
25
+ end
@@ -1,9 +1,12 @@
1
1
  # -*- coding: binary -*-
2
- $:.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib/"))
2
+ # Usage:
3
+ # ruby examples/ifconfig.rb
4
+
5
+ # Path setting slight of hand:
6
+ $: << File.expand_path("../../lib", __FILE__)
3
7
  require 'packetfu'
4
8
 
5
- # ifconfig for Darwin
6
- iface = ARGV[0] || 'en1'
9
+ iface = ARGV[0] || PacketFu::Utils.default_int
7
10
  config = PacketFu::Utils.ifconfig(iface)
8
11
  print "#{RUBY_PLATFORM} => "
9
12
  p config
@@ -9,7 +9,11 @@
9
9
  # every 11 seconds (my own benchmark) for this script, at least
10
10
  # it doesn't hog up all your memory.
11
11
 
12
- require './examples' # For path setting slight-of-hand
12
+ # Usage:
13
+ # ruby examples/new-simple-stats.rb test/sample.pcap
14
+
15
+ # Path setting slight of hand:
16
+ $: << File.expand_path("../../lib", __FILE__)
13
17
  require 'packetfu'
14
18
 
15
19
  def print_results(stats)
@@ -46,8 +50,3 @@ if File.readable?(infile = (ARGV[0] || 'in.pcap'))
46
50
  else
47
51
  raise RuntimeError, "Need an infile, like so: #{$0} in.pcap"
48
52
  end
49
-
50
-
51
-
52
-
53
-
@@ -1,52 +1,13 @@
1
1
  # -*- coding: binary -*-
2
- # == Synopsis
3
- #
4
- # packetfu-shell.rb is intended for IRB consumption, and providing an
5
- # interactive interface for PacketFu experimentation.
6
- #
7
- # == Usage
8
- #
9
- # irb -r packetfu-shell.rb
10
- # or
11
- # sudo irb -r packetfu-shell.rb
12
- #
13
- # If run as root, packet capturing/injecting is available, which includes
14
- # access to Utils.whoami?
15
- #
16
- # Once loaded, the PacketFu module is mixed in, and Utils commands are
17
- # aliased to the PacketFu module proper. Sessions look something like
18
- # this:
19
- #
20
- # == Example
21
- #
22
- # irb(main):001:0> pkt = TCPPacket.new
23
- # => 00 1a c5 00 00 00 00 1a c5 00 00 00 08 00 45 00 ..............E.
24
- # 00 28 62 9d 00 00 ff 06 59 33 00 00 00 00 00 00 .(b.....Y3......
25
- # 00 00 d4 fb 00 00 18 c6 32 86 00 00 00 00 50 00 ........2.....P.
26
- # 40 00 4f 9d 00 00 @.O...
27
- # irb(main):002:0> pkt.payload="I am totally up in your stack, twiddling your bits."
28
- # => "I am totally up in your stack, twiddling your bits."
29
- # irb(main):003:0> pkt.ip_saddr="1.2.3.4"
30
- # => "1.2.3.4"
31
- # irb(main):004:0> pkt.tcp_sport=13013
32
- # => 13013
33
- # irb(main):005:0> pkt.tcp_dport=808
34
- # => 808
35
- # irb(main):006:0> pkt.recalc
36
- # => {"eth_src"=>{"oui"=>{"local"=>0, "oui"=>6853, "b0"=>0, "b1"=>0, "b2"=>0, "multicast"=>0, "b3"=>0, "b4"=>0, "b5"=>0}, "nic"=>{"n1"=>0, "n2"=>0, "n3"=>0}}, "body"=>{"ip_tos"=>0, "ip_src"=>{"o1"=>1, "o2"=>2, "o3"=>3, "o4"=>4}, "body"=>{"tcp_ecn"=>{"c"=>0, "n"=>0, "e"=>0}, "tcp_dst"=>808, "tcp_win"=>16384, "body"=>"I am totally up in your stack, twiddling your bits.", "tcp_flags"=>{"fin"=>0, "psh"=>0, "syn"=>0, "rst"=>0, "ack"=>0, "urg"=>0}, "tcp_hlen"=>5, "tcp_ack"=>0, "tcp_urg"=>0, "tcp_seq"=>415642246, "tcp_sum"=>51184, "tcp_reserved"=>0, "tcp_opts"=>"", "tcp_src"=>13013}, "ip_dst"=>{"o1"=>0, "o2"=>0, "o3"=>0, "o4"=>0}, "ip_frag"=>0, "ip_proto"=>6, "ip_hl"=>5, "ip_len"=>91, "ip_sum"=>21754, "ip_id"=>25245, "ip_v"=>4, "ip_ttl"=>255}, "eth_proto"=>2048, "eth_dst"=>{"oui"=>{"local"=>0, "oui"=>6853, "b0"=>0, "b1"=>0, "b2"=>0, "multicast"=>0, "b3"=>0, "b4"=>0, "b5"=>0}, "nic"=>{"n1"=>0, "n2"=>0, "n3"=>0}}}
37
- # irb(main):007:0> pkt.to_f('/tmp/tcp-example.pcap')
38
- # => ["/tmp/tcp-example.pcap", 145, 1, 1220048597, 1]
39
- # irb(main):008:0> puts pkt.inspect_hex(2)
40
- # 32 d5 03 28 7c 50 1f 01 00 00 00 00 50 00 40 00 2..(|P......P.@.
41
- # 77 eb 00 00 49 20 61 6d 20 74 6f 74 61 6c 6c 79 w...I am totally
42
- # 20 75 70 20 69 6e 20 79 6f 75 72 20 73 74 61 63 up in your stac
43
- # 6b 2c 20 74 77 69 64 64 6c 69 6e 67 20 79 6f 75 k, twiddling you
44
- # 72 20 62 69 74 73 2e r bits.
45
- # => nil
46
2
 
47
- $: << File.expand_path(File.dirname(__FILE__) + "/../lib/")
48
- require './examples'
3
+ # Usage:
4
+ # rvmsudo ruby examples/packetfu-shell.rb
5
+
6
+ # Path setting slight of hand:
7
+ $: << File.expand_path("../../lib", __FILE__)
8
+
49
9
  require 'packetfu'
10
+ require 'irb'
50
11
 
51
12
  module PacketFu
52
13
  def whoami?(args={})
@@ -65,7 +26,7 @@ include PacketFu
65
26
  #
66
27
  def packetfu_ascii_art
67
28
  puts <<EOM
68
- _______ _______ _______ _ _______ _________ _______
29
+ _______ _______ _______ _ _______ _________ _______
69
30
  ( ____ )( ___ )( ____ \\| \\ /\\( ____ \\\\__ __/( ____ \\|\\ /|
70
31
  | ( )|| ( ) || ( \\/| \\ / /| ( \\/ ) ( | ( \\/| ) ( |
71
32
  | (____)|| (___) || | | (_/ / | (__ | | | (__ | | | |
@@ -94,7 +55,7 @@ def banner
94
55
  print "IP: %-15s Mac: %s" % [$packetfu_default.ip_saddr, $packetfu_default.eth_saddr]
95
56
  puts " Gateway: %s" % $packetfu_default.eth_daddr
96
57
  print "Net: %-15s" % [Pcap.lookupnet($packetfu_default.iface)][0]
97
- print " " * 13
58
+ print " " * 13
98
59
  puts "Iface: %s" % [($packetfu_default.iface)]
99
60
  puts ">>> Packet capturing/injecting enabled."
100
61
  else
@@ -112,3 +73,5 @@ rescue RuntimeError
112
73
  end
113
74
 
114
75
  banner
76
+
77
+ IRB.start