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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rspec +2 -0
- data/.travis.yml +2 -3
- data/README.md +127 -0
- data/examples/100kpackets.rb +11 -10
- data/examples/ackscan.rb +4 -1
- data/examples/arp.rb +4 -5
- data/examples/arphood.rb +5 -4
- data/examples/dissect_thinger.rb +10 -7
- data/examples/ethernet.rb +8 -3
- data/examples/ids.rb +22 -4
- data/examples/idsv2.rb +25 -6
- data/examples/ifconfig.rb +6 -3
- data/examples/new-simple-stats.rb +5 -6
- data/examples/packetfu-shell.rb +11 -48
- data/examples/pcap2pcapng.rb +32 -0
- data/examples/simple-sniffer.rb +9 -4
- data/examples/simple-stats.rb +7 -8
- data/examples/slammer.rb +2 -2
- data/examples/uniqpcap.rb +17 -7
- data/lib/packetfu.rb +10 -175
- data/lib/packetfu/capture.rb +2 -2
- data/lib/packetfu/common.rb +142 -0
- data/lib/packetfu/config.rb +8 -8
- data/lib/packetfu/inject.rb +3 -3
- data/lib/packetfu/packet.rb +22 -18
- data/lib/packetfu/pcap.rb +2 -1
- data/lib/packetfu/pcapng.rb +37 -0
- data/lib/packetfu/pcapng/block.rb +25 -0
- data/lib/packetfu/pcapng/epb.rb +112 -0
- data/lib/packetfu/pcapng/file.rb +316 -0
- data/lib/packetfu/pcapng/idb.rb +125 -0
- data/lib/packetfu/pcapng/shb.rb +146 -0
- data/lib/packetfu/pcapng/spb.rb +83 -0
- data/lib/packetfu/pcapng/unknown_block.rb +60 -0
- data/lib/packetfu/protos.rb +3 -0
- data/lib/packetfu/protos/arp.rb +10 -10
- data/lib/packetfu/protos/icmpv6.rb +131 -0
- data/lib/packetfu/protos/icmpv6/header.rb +69 -0
- data/lib/packetfu/protos/icmpv6/mixin.rb +14 -0
- data/lib/packetfu/protos/ip.rb +4 -5
- data/lib/packetfu/protos/ipv6/header.rb +2 -0
- data/lib/packetfu/protos/udp.rb +24 -12
- data/lib/packetfu/structfu.rb +27 -0
- data/lib/packetfu/utils.rb +55 -9
- data/lib/packetfu/version.rb +1 -1
- data/packetfu.gemspec +13 -7
- data/spec/arp_spec.rb +11 -5
- data/spec/eth_spec.rb +20 -11
- data/spec/fake_packets.rb +28 -0
- data/spec/hsrp_spec.rb +15 -0
- data/spec/icmp_spec.rb +12 -5
- data/spec/icmpv6_spec.rb +98 -0
- data/spec/invalid_spec.rb +28 -0
- data/spec/ip_spec.rb +10 -5
- data/spec/ipv4_icmp.pcap +0 -0
- data/spec/ipv4_udp.pcap +0 -0
- data/spec/ipv6_icmp.pcap +0 -0
- data/spec/ipv6_spec.rb +4 -0
- data/spec/ipv6_udp.pcap +0 -0
- data/spec/lldp_spec.rb +36 -0
- data/spec/octets_spec.rb +43 -0
- data/spec/packet_spec.rb +24 -0
- data/spec/packetfu_spec.rb +6 -1
- data/spec/pcap_spec.rb +286 -0
- data/spec/pcapng/epb_spec.rb +81 -0
- data/spec/pcapng/file_spec.rb +295 -0
- data/spec/pcapng/file_spec_helper.rb +45 -0
- data/spec/pcapng/idb_spec.rb +53 -0
- data/spec/pcapng/shb_spec.rb +42 -0
- data/spec/pcapng/spb_spec.rb +43 -0
- data/spec/pcapng/unknown_block_spec.rb +36 -0
- data/spec/spec_helper.rb +3 -31
- data/spec/tcp_spec.rb +4 -1
- data/spec/udp_spec.rb +149 -1
- data/spec/utils_spec.rb +98 -15
- data/test/pcapng-test/output_be/advanced/test100.pcapng +0 -0
- data/test/pcapng-test/output_be/advanced/test100.txt +11 -0
- data/test/pcapng-test/output_be/advanced/test101.pcapng +0 -0
- data/test/pcapng-test/output_be/advanced/test101.txt +11 -0
- data/test/pcapng-test/output_be/advanced/test102.pcapng +0 -0
- data/test/pcapng-test/output_be/advanced/test102.txt +14 -0
- data/test/pcapng-test/output_be/basic/test001.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test001.txt +9 -0
- data/test/pcapng-test/output_be/basic/test002.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test002.txt +7 -0
- data/test/pcapng-test/output_be/basic/test003.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test003.txt +8 -0
- data/test/pcapng-test/output_be/basic/test004.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test004.txt +9 -0
- data/test/pcapng-test/output_be/basic/test005.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test005.txt +9 -0
- data/test/pcapng-test/output_be/basic/test006.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test006.txt +9 -0
- data/test/pcapng-test/output_be/basic/test007.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test007.txt +9 -0
- data/test/pcapng-test/output_be/basic/test008.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test008.txt +9 -0
- data/test/pcapng-test/output_be/basic/test009.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test009.txt +9 -0
- data/test/pcapng-test/output_be/basic/test010.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test010.txt +9 -0
- data/test/pcapng-test/output_be/basic/test011.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test011.txt +10 -0
- data/test/pcapng-test/output_be/basic/test012.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test012.txt +10 -0
- data/test/pcapng-test/output_be/basic/test013.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test013.txt +9 -0
- data/test/pcapng-test/output_be/basic/test014.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test014.txt +9 -0
- data/test/pcapng-test/output_be/basic/test015.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test015.txt +9 -0
- data/test/pcapng-test/output_be/basic/test016.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test016.txt +11 -0
- data/test/pcapng-test/output_be/basic/test017.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test017.txt +9 -0
- data/test/pcapng-test/output_be/basic/test018.pcapng +0 -0
- data/test/pcapng-test/output_be/basic/test018.txt +12 -0
- data/test/pcapng-test/output_be/difficult/test200.pcapng +0 -0
- data/test/pcapng-test/output_be/difficult/test200.txt +8 -0
- data/test/pcapng-test/output_be/difficult/test201.pcapng +0 -0
- data/test/pcapng-test/output_be/difficult/test201.txt +11 -0
- data/test/pcapng-test/output_be/difficult/test202.pcapng +0 -0
- data/test/pcapng-test/output_be/difficult/test202.txt +14 -0
- data/test/pcapng-test/output_le/advanced/test100.pcapng +0 -0
- data/test/pcapng-test/output_le/advanced/test100.txt +11 -0
- data/test/pcapng-test/output_le/advanced/test101.pcapng +0 -0
- data/test/pcapng-test/output_le/advanced/test101.txt +11 -0
- data/test/pcapng-test/output_le/advanced/test102.pcapng +0 -0
- data/test/pcapng-test/output_le/advanced/test102.txt +14 -0
- data/test/pcapng-test/output_le/basic/test001.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test001.txt +9 -0
- data/test/pcapng-test/output_le/basic/test002.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test002.txt +7 -0
- data/test/pcapng-test/output_le/basic/test003.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test003.txt +8 -0
- data/test/pcapng-test/output_le/basic/test004.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test004.txt +9 -0
- data/test/pcapng-test/output_le/basic/test005.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test005.txt +9 -0
- data/test/pcapng-test/output_le/basic/test006.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test006.txt +9 -0
- data/test/pcapng-test/output_le/basic/test007.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test007.txt +9 -0
- data/test/pcapng-test/output_le/basic/test008.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test008.txt +9 -0
- data/test/pcapng-test/output_le/basic/test009.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test009.txt +9 -0
- data/test/pcapng-test/output_le/basic/test010.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test010.txt +9 -0
- data/test/pcapng-test/output_le/basic/test011.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test011.txt +10 -0
- data/test/pcapng-test/output_le/basic/test012.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test012.txt +10 -0
- data/test/pcapng-test/output_le/basic/test013.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test013.txt +9 -0
- data/test/pcapng-test/output_le/basic/test014.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test014.txt +9 -0
- data/test/pcapng-test/output_le/basic/test015.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test015.txt +9 -0
- data/test/pcapng-test/output_le/basic/test016.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test016.txt +11 -0
- data/test/pcapng-test/output_le/basic/test017.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test017.txt +9 -0
- data/test/pcapng-test/output_le/basic/test018.pcapng +0 -0
- data/test/pcapng-test/output_le/basic/test018.txt +12 -0
- data/test/pcapng-test/output_le/difficult/test200.pcapng +0 -0
- data/test/pcapng-test/output_le/difficult/test200.txt +8 -0
- data/test/pcapng-test/output_le/difficult/test201.pcapng +0 -0
- data/test/pcapng-test/output_le/difficult/test201.txt +11 -0
- data/test/pcapng-test/output_le/difficult/test202.pcapng +0 -0
- data/test/pcapng-test/output_le/difficult/test202.txt +14 -0
- data/test/sample-ipv6.pcapng +0 -0
- data/test/sample-spb.pcapng +0 -0
- data/test/sample.pcapng +0 -0
- data/test/sample2.pcapng +0 -0
- metadata +190 -68
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -2
- data/INSTALL.rdoc +0 -40
- data/README.rdoc +0 -64
- data/examples/examples.rb +0 -4
- data/setup.rb +0 -1586
- data/test/func_lldp.rb +0 -25
- data/test/ptest.rb +0 -16
- data/test/test_eth.rb +0 -93
- data/test/test_hsrp.rb +0 -20
- data/test/test_invalid.rb +0 -28
- data/test/test_octets.rb +0 -36
- data/test/test_pcap.rb +0 -211
- data/test/test_udp.rb +0 -100
- metadata.gz.sig +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27fdb60e2d8cf9c2abe63361c024c6b6b4077c45
|
4
|
+
data.tar.gz: ddb6a367565f97de59c730d6e5141e85165407f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d063030465de3423c0b59295bd5ebd02d568d1832f7770965cb6825d29d645cfd6bc6ab43e40cb5871fb7b187507d3ba2a1415bc3d63b7b017287b39adfd5481
|
7
|
+
data.tar.gz: 445f37e0c272b179382396bd2307fa24e6214fd0ae8cdb34d65cbcdef3fd05562a927239bea0f4aeaf6d79d34386827d4c2489604b9261b35422eb376ba6937b
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/README.md
ADDED
@@ -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.
|
data/examples/100kpackets.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
data/examples/ackscan.rb
CHANGED
@@ -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
|
-
|
data/examples/arp.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
data/examples/arphood.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
# -*- coding: binary -*-
|
3
3
|
|
4
4
|
# A simple local network fingerprinter. Uses the OUI list.
|
5
|
-
# Usage:
|
5
|
+
# Usage:
|
6
|
+
# rvmsudo examples/arphood.rb [iface] [network] <oui.txt>
|
6
7
|
|
7
|
-
|
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
|
-
|
data/examples/dissect_thinger.rb
CHANGED
@@ -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
|
-
|
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
|
data/examples/ethernet.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
# -*- coding: binary -*-
|
2
2
|
|
3
|
-
|
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
|
-
|
11
|
-
|
14
|
+
eth_pkt.recalc
|
15
|
+
puts eth_pkt.inspect
|
16
|
+
puts eth_pkt.to_f('/tmp/ethernet.pcap').inspect
|
data/examples/ids.rb
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
data/examples/idsv2.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
data/examples/ifconfig.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# -*- coding: binary -*-
|
2
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
data/examples/packetfu-shell.rb
CHANGED
@@ -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
|
-
|
48
|
-
|
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
|