packetnom 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c534ecee26ff6e9863e5f7e47ee398b1753a0ff9
4
+ data.tar.gz: d0956ce605ac8c8d931cb0bb47e8f44248a8fa89
5
+ SHA512:
6
+ metadata.gz: e1694ec52b0c97d8a74fa4cee0d982acaffa5338859a9f379021ae9d77f96164a319c0f85418035c813d56dc7aabd56f0ed04a6cdb4669d8d6797490498ad6fe
7
+ data.tar.gz: 51256b048099fbc89b495b031a195a658f1d4ffd482ac7a8d0ad3f67b63131bed51a317ba85a8ac9aaf85fab245b9ef05e80957ae03f2a41be99c6b5d7e504d3
data/lib/packet/eth.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Kn0x
2
+
3
+ class Packet
4
+
5
+ class Eth
6
+
7
+ # Attributes
8
+ attr_accessor :dst
9
+ attr_accessor :src
10
+ attr_accessor :type
11
+
12
+ # Initialize the packet
13
+ def initialize( bytes )
14
+ @packet = bytes
15
+
16
+ # Layer 2
17
+ @dst = bytes[0..5].join(':')
18
+ @src = bytes[6..11].join(':')
19
+ @type = bytes[12..13].join() # http://en.wikipedia.org/wiki/EtherType
20
+
21
+ end
22
+
23
+ def type
24
+ types = {
25
+ "0800" => "ip",
26
+ }
27
+
28
+ types[ @type ]
29
+ end
30
+ alias_method :ethertype, :type
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
data/lib/packet/ip.rb ADDED
@@ -0,0 +1,78 @@
1
+ module Kn0x
2
+
3
+ class Packet
4
+
5
+ class Ip
6
+
7
+ # Attributes
8
+ attr_accessor :version
9
+ attr_accessor :ihl
10
+ attr_accessor :ds
11
+ attr_accessor :len
12
+ attr_accessor :id
13
+ attr_accessor :flags
14
+ attr_accessor :offset
15
+ attr_accessor :ttl
16
+ attr_accessor :proto
17
+ attr_accessor :sum
18
+ attr_accessor :src
19
+ attr_accessor :dst
20
+
21
+ # Initialize the packet
22
+ def initialize( bytes )
23
+ @packet = bytes
24
+
25
+ @version = bytes[14].split(//)[0]
26
+ @ihl = bytes[14].split(//)[1]
27
+ @ds = bytes[15]
28
+ @len = bytes[16..17].join().to_i(16)
29
+ @id = bytes[18..19].join()
30
+
31
+ @flags = bytes[20].split(//)[0].to_i(16) #todo
32
+ @offset = "#{bytes[20].split(//)[1]}#{bytes[21]}".to_i(16) #todo
33
+
34
+ @ttl = bytes[22].to_i(16)
35
+ @proto = bytes[23].to_i(16)
36
+ @sum = bytes[24..25].join().to_i(16)
37
+ @src = bytes[26..29].map{|octet| octet.to_i(16).to_s(10)}.join('.')
38
+ @dst = bytes[30..33].map{|octet| octet.to_i(16).to_s(10)}.join('.')
39
+
40
+ end
41
+
42
+ alias_method :length, :len
43
+ alias_method :checksum, :sum
44
+
45
+ def proto
46
+ protocol( @proto.to_i )
47
+ end
48
+ alias_method :protocol, :proto
49
+
50
+ def src
51
+ IPAddress @src
52
+ end
53
+ alias_method :source, :src
54
+ alias_method :from, :src
55
+
56
+
57
+ def dst
58
+ IPAddress @dst
59
+ end
60
+ alias_method :dest, :dst
61
+ alias_method :target, :dst
62
+
63
+ private
64
+
65
+ def protocol( proto )
66
+ protocols = {
67
+ 6 => "tcp",
68
+ 17 => "udp",
69
+ }
70
+
71
+ protocols[ proto ]
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end
data/lib/packet/tcp.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Kn0x
2
+
3
+ class Packet
4
+
5
+ class Tcp
6
+
7
+ # Attributes
8
+ attr_accessor :src_port
9
+ attr_accessor :dst_port
10
+ attr_accessor :seq
11
+ attr_accessor :ack
12
+ attr_accessor :offset
13
+ attr_accessor :reserved
14
+ attr_accessor :ecn
15
+ attr_accessor :cbits
16
+ attr_accessor :win
17
+ attr_accessor :sum
18
+ attr_accessor :uptr
19
+
20
+ # Initialize the packet
21
+ def initialize( bytes )
22
+ @packet = bytes
23
+
24
+ @src_port = bytes[34..35].join().to_i(16).to_s(10).to_i
25
+ @dst_port = bytes[36..37].join().to_i(16).to_s(10).to_i
26
+
27
+ @seq = bytes[38..41].join().to_i(16).to_s(10).to_i
28
+
29
+ @ack = bytes[42..45].join().to_i(16).to_s(10).to_i
30
+
31
+ @offset = bytes[46].split(//)[0].to_i(16).to_s(10)
32
+
33
+ @reserved = bytes[46].split(//)[1].to_i(16).to_s(10)
34
+ @ecn = bytes[47].split(//)[0].to_i(16).to_s(10)
35
+ @cbits = bytes[47].split(//)[1].to_i(16).to_s(10)
36
+
37
+ @win = bytes[48..49].join().to_i(16)
38
+ @sum = bytes[50..51].join().to_i(16)
39
+ @uptr = bytes[52..53].join().to_i(16)
40
+ end
41
+
42
+ alias_method :source_port, :src_port
43
+ alias_method :sport, :src_port
44
+
45
+ alias_method :dest_port, :dst_port
46
+ alias_method :dport, :dst_port
47
+
48
+ alias_method :window, :win
49
+ alias_method :windowsize, :win
50
+ alias_method :size, :win
51
+
52
+ alias_method :checksum, :sum
53
+ alias_method :urgent, :uptr
54
+
55
+ def cbits
56
+ @cbits
57
+ end
58
+ alias_method :controlbits, :cbits
59
+ alias_method :control, :cbits
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
data/lib/packetnom.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'packet/eth'
2
+ require 'packet/ip'
3
+
4
+ require 'packet/tcp'
5
+ #require 'packet/udp'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packetnom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Mackintosh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: PacketNom - Best way to view, consume and replay packets with ruby
14
+ email: m@zyp.io
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/packetnom.rb
20
+ - lib/packet/eth.rb
21
+ - lib/packet/ip.rb
22
+ - lib/packet/tcp.rb
23
+ homepage: http://github.com/mikemackintosh/packetnom
24
+ licenses:
25
+ - not-yet-decided
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.14
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: PacketNom, nom, nom, nom
47
+ test_files: []