rex-java 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +9 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +5 -0
  7. data/CODE_OF_CONDUCT.md +52 -0
  8. data/Gemfile +4 -0
  9. data/README.md +36 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/rex/java.rb +10 -0
  14. data/lib/rex/java/serialization.rb +57 -0
  15. data/lib/rex/java/serialization/builder.rb +94 -0
  16. data/lib/rex/java/serialization/decode_error.rb +11 -0
  17. data/lib/rex/java/serialization/encode_error.rb +11 -0
  18. data/lib/rex/java/serialization/model.rb +33 -0
  19. data/lib/rex/java/serialization/model/annotation.rb +69 -0
  20. data/lib/rex/java/serialization/model/block_data.rb +70 -0
  21. data/lib/rex/java/serialization/model/block_data_long.rb +72 -0
  22. data/lib/rex/java/serialization/model/class_desc.rb +64 -0
  23. data/lib/rex/java/serialization/model/contents.rb +163 -0
  24. data/lib/rex/java/serialization/model/element.rb +44 -0
  25. data/lib/rex/java/serialization/model/end_block_data.rb +12 -0
  26. data/lib/rex/java/serialization/model/field.rb +173 -0
  27. data/lib/rex/java/serialization/model/long_utf.rb +48 -0
  28. data/lib/rex/java/serialization/model/new_array.rb +229 -0
  29. data/lib/rex/java/serialization/model/new_class.rb +57 -0
  30. data/lib/rex/java/serialization/model/new_class_desc.rb +154 -0
  31. data/lib/rex/java/serialization/model/new_enum.rb +79 -0
  32. data/lib/rex/java/serialization/model/new_object.rb +235 -0
  33. data/lib/rex/java/serialization/model/null_reference.rb +12 -0
  34. data/lib/rex/java/serialization/model/proxy_class_desc.rb +109 -0
  35. data/lib/rex/java/serialization/model/reference.rb +61 -0
  36. data/lib/rex/java/serialization/model/reset.rb +12 -0
  37. data/lib/rex/java/serialization/model/stream.rb +123 -0
  38. data/lib/rex/java/serialization/model/utf.rb +69 -0
  39. data/lib/rex/java/version.rb +5 -0
  40. data/rex-java.gemspec +24 -0
  41. metadata +199 -0
  42. metadata.gz.sig +1 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1cc8296c437588d34502bf7ce4eb44011c8ebda
4
+ data.tar.gz: a93efc058ae439f2588a6b28c58e5413cf2571db
5
+ SHA512:
6
+ metadata.gz: ca9cb732b9140e11c385023f75630f9d57cf7e4c35a9d56ec41aecda7126216da8600ab6b5fcbcb966c466ce8493541df17cc694a555b9f5533d715c5f5ec975
7
+ data.tar.gz: 8680ab754505669e9e775cb371a77cc1e5a1e460aca60e4a37c3cf63b568f98dae17f729b1b082c4262054699277f05565d5fbcd71ea11e9138a7ce3cf000bfc
@@ -0,0 +1,3 @@
1
+ 7)c��d��)V֍��P8A��?8�C�<Ɩ�)�XP|�
2
+ �!xZ1�g�%������)��-�A>��Ї̚�: T���$m-���C�����=F å�-+iN]�H+q���TQ���{���k1JH
3
+ ��誣|ޱ��A���P���/&Z���!}A ��^�l\�b�-P˿M
Binary file
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.5
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,52 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This Code of Conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting the project maintainers at msfdev@metasploit.com. If
39
+ the incident involves a committer, you may report directly to
40
+ egypt@metasploit.com or todb@metasploit.com.
41
+
42
+ All complaints will be reviewed and investigated and will result in a
43
+ response that is deemed necessary and appropriate to the circumstances.
44
+ Maintainers are obligated to maintain confidentiality with regard to the
45
+ reporter of an incident.
46
+
47
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
48
+ version 1.3.0, available at
49
+ [http://contributor-covenant.org/version/1/3/0/][version]
50
+
51
+ [homepage]: http://contributor-covenant.org
52
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rex-java.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # Rex::Java
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rex/java`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rex-java'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rex-java
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rapid7/rex-java. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rex/java"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ # -*- coding: binary -*-
2
+
3
+ require "rex/java/version"
4
+ require 'rex/java/serialization'
5
+
6
+ module Rex
7
+ module Java
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,57 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ # Include constants defining terminal and constant
6
+ # values expected in a stream.
7
+ module Serialization
8
+ STREAM_MAGIC = 0xaced
9
+ STREAM_VERSION = 5
10
+ TC_NULL = 0x70
11
+ TC_REFERENCE = 0x71
12
+ TC_CLASSDESC = 0x72
13
+ TC_OBJECT = 0x73
14
+ TC_STRING = 0x74
15
+ TC_ARRAY = 0x75
16
+ TC_CLASS = 0x76
17
+ TC_BLOCKDATA = 0x77
18
+ TC_ENDBLOCKDATA = 0x78
19
+ TC_RESET = 0x79
20
+ TC_BLOCKDATALONG = 0x7A
21
+ TC_EXCEPTION = 0x7B
22
+ TC_LONGSTRING = 0x7C
23
+ TC_PROXYCLASSDESC = 0x7D
24
+ TC_ENUM = 0x7E
25
+ BASE_WIRE_HANDLE = 0x7E0000
26
+
27
+ SC_WRITE_METHOD = 0x01 # if SC_SERIALIZABLE
28
+ SC_BLOCK_DATA = 0x08 # if SC_EXTERNALIZABLE
29
+ SC_SERIALIZABLE = 0x02
30
+ SC_EXTERNALIZABLE = 0x04
31
+ SC_ENUM = 0x10
32
+
33
+ PRIMITIVE_TYPE_CODES = {
34
+ 'B' => 'byte',
35
+ 'C' => 'char',
36
+ 'D' => 'double',
37
+ 'F' => 'float',
38
+ 'I' => 'int',
39
+ 'J' => 'long',
40
+ 'S' => 'short',
41
+ 'Z' => 'boolean'
42
+ }
43
+
44
+ OBJECT_TYPE_CODES = {
45
+ '[' => 'array',
46
+ 'L' => 'object'
47
+ }
48
+
49
+ TYPE_CODES = PRIMITIVE_TYPE_CODES.merge(OBJECT_TYPE_CODES)
50
+ end
51
+ end
52
+ end
53
+
54
+ require 'rex/java/serialization/decode_error'
55
+ require 'rex/java/serialization/encode_error'
56
+ require 'rex/java/serialization/model'
57
+ require 'rex/java/serialization/builder'
@@ -0,0 +1,94 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ # This class provides a builder to help in the construction of
7
+ # Java serialized contents.
8
+ class Builder
9
+
10
+ # Creates a Rex::Java::Serialization::Model::NewArray
11
+ #
12
+ # @param opts [Hash{Symbol => <Rex::Java::Serialization::Model::NewClassDesc, String, Array>}]
13
+ # @option opts [Rex::Java::Serialization::Model::NewClassDesc] :description
14
+ # @option opts [String] :values_type
15
+ # @option opts [Array] :values
16
+ # @return [Rex::Java::Serialization::Model::NewArray]
17
+ # @see #new_class
18
+ def new_array(opts = {})
19
+ class_desc = opts[:description] || new_class(opts)
20
+ type = opts[:values_type] || ''
21
+ values = opts[:values] || []
22
+
23
+ array = Rex::Java::Serialization::Model::NewArray.new
24
+ array.array_description = Rex::Java::Serialization::Model::ClassDesc.new
25
+ array.array_description.description = class_desc
26
+ array.type = type
27
+ array.values = values
28
+
29
+ array
30
+ end
31
+
32
+ # Creates a Rex::Java::Serialization::Model::NewObject
33
+ #
34
+ # @param opts [Hash{Symbol => <Rex::Java::Serialization::Model::NewClassDesc, Array>}]
35
+ # @option opts [Rex::Java::Serialization::Model::NewClassDesc] :description
36
+ # @option opts [Array] :data
37
+ # @return [Rex::Java::Serialization::Model::NewObject]
38
+ # @see #new_class
39
+ def new_object(opts = {})
40
+ class_desc = opts[:description] || new_class(opts)
41
+ data = opts[:data] || []
42
+
43
+ object = Rex::Java::Serialization::Model::NewObject.new
44
+ object.class_desc = Rex::Java::Serialization::Model::ClassDesc.new
45
+ object.class_desc.description = class_desc
46
+ object.class_data = data
47
+
48
+ object
49
+ end
50
+
51
+ # Creates a Rex::Java::Serialization::Model::NewClassDesc
52
+ #
53
+ # @param opts [Hash{Symbol => <Rex::Java::Serialization::Model::NewClassDesc, Array>}]
54
+ # @option opts [String] :name
55
+ # @option opts [Fixnum] :serial
56
+ # @option opts [Fixnum] :flags
57
+ # @option opts [Array] :fields
58
+ # @option opts [Array] :annotations
59
+ # @option opts [Rex::Java::Serialization::Model::Element] :super_class
60
+ # @return [Rex::Java::Serialization::Model::NewClassDesc]
61
+ def new_class(opts = {})
62
+ class_name = opts[:name] || ''
63
+ serial_version = opts[:serial] || 0
64
+ flags = opts[:flags] || 2
65
+ fields = opts[:fields] || []
66
+ annotations = opts[:annotations] || [Rex::Java::Serialization::Model::NullReference.new,
67
+ Rex::Java::Serialization::Model::EndBlockData.new]
68
+ super_class = opts[:super_class] || Rex::Java::Serialization::Model::NullReference.new
69
+
70
+ class_desc = Rex::Java::Serialization::Model::NewClassDesc.new
71
+ class_desc.class_name = Rex::Java::Serialization::Model::Utf.new(nil, class_name)
72
+ class_desc.serial_version = serial_version
73
+ class_desc.flags = flags
74
+ class_desc.fields = []
75
+
76
+ fields.each do |f|
77
+ field = Rex::Java::Serialization::Model::Field.new
78
+ field.type = f[0]
79
+ field.name = Rex::Java::Serialization::Model::Utf.new(nil, f[1])
80
+ field.field_type = Rex::Java::Serialization::Model::Utf.new(nil, f[2]) if f[2]
81
+ class_desc.fields << field
82
+ end
83
+
84
+ class_desc.class_annotation = Rex::Java::Serialization::Model::Annotation.new
85
+ class_desc.class_annotation.contents = annotations
86
+ class_desc.super_class = Rex::Java::Serialization::Model::ClassDesc.new
87
+ class_desc.super_class.description = super_class
88
+
89
+ class_desc
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ class DecodeError < ::RuntimeError
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ class EncodeError < ::RuntimeError
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ module Model
7
+
8
+ autoload :Annotation, 'rex/java/serialization/model/annotation'
9
+ autoload :BlockDataLong, 'rex/java/serialization/model/block_data_long'
10
+ autoload :BlockData, 'rex/java/serialization/model/block_data'
11
+ autoload :ClassDesc, 'rex/java/serialization/model/class_desc'
12
+ autoload :Contents, 'rex/java/serialization/model/contents'
13
+ autoload :Element, 'rex/java/serialization/model/element'
14
+ autoload :EndBlockData, 'rex/java/serialization/model/end_block_data'
15
+ autoload :Field, 'rex/java/serialization/model/field'
16
+ autoload :LongUtf, 'rex/java/serialization/model/long_utf'
17
+ autoload :NewArray, 'rex/java/serialization/model/new_array'
18
+ autoload :ProxyClassDesc, 'rex/java/serialization/model/proxy_class_desc'
19
+ autoload :NewClassDesc, 'rex/java/serialization/model/new_class_desc'
20
+ autoload :NewEnum, 'rex/java/serialization/model/new_enum'
21
+ autoload :NewObject, 'rex/java/serialization/model/new_object'
22
+ autoload :NewClass, 'rex/java/serialization/model/new_class'
23
+ autoload :NullReference, 'rex/java/serialization/model/null_reference'
24
+ autoload :Reference, 'rex/java/serialization/model/reference'
25
+ autoload :Reset, 'rex/java/serialization/model/reset'
26
+ autoload :Stream, 'rex/java/serialization/model/stream'
27
+ autoload :Utf, 'rex/java/serialization/model/utf'
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,69 @@
1
+ # -*- coding: binary -*-
2
+
3
+ module Rex
4
+ module Java
5
+ module Serialization
6
+ module Model
7
+ # This class provides an annotation representation. It's used for both class
8
+ # annotations (classAnnotation) and object annotations (objectAnnotation).
9
+ class Annotation < Element
10
+
11
+ include Rex::Java::Serialization::Model::Contents
12
+
13
+ # @!attribute contents
14
+ # @return [Array] The annotation contents
15
+ attr_accessor :contents
16
+
17
+ # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
18
+ def initialize(stream = nil)
19
+ super(stream)
20
+ self.contents = []
21
+ end
22
+
23
+ # Deserializes a Rex::Java::Serialization::Model::Annotation
24
+ #
25
+ # @param io [IO] the io to read from
26
+ # @return [self] if deserialization succeeds
27
+ # @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
28
+ def decode(io)
29
+ loop do
30
+ content = decode_content(io, stream)
31
+ self.contents << content
32
+ return self if content.kind_of?(EndBlockData)
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ # Serializes the Rex::Java::Serialization::Model::Annotation
39
+ #
40
+ # @return [String] if serialization suceeds
41
+ # @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
42
+ def encode
43
+ raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Annotation with empty contents' if contents.empty?
44
+
45
+ encoded = ''
46
+
47
+ contents.each do |content|
48
+ encoded << encode_content(content)
49
+ end
50
+
51
+ encoded
52
+ end
53
+
54
+ # Creates a print-friendly string representation
55
+ #
56
+ # @return [String]
57
+ def to_s
58
+ str = '[ '
59
+ contents_data = contents.collect {|content| "#{print_content(content)}"}
60
+ str << contents_data.join(', ')
61
+ str << ' ]'
62
+ str
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end