|
50 | 50 | 0xf6b6898d8bf28643
|
51 | 51 | end
|
52 | 52 |
|
| 53 | + let(:empty) { '' } |
| 54 | + let(:empty_io) { StringIO.new(empty) } |
| 55 | + let(:string) { "\x00\x04\x41\x42\x43\x44" } |
| 56 | + let(:string_io) { StringIO.new(string) } |
| 57 | + let(:int) { "\x00\x00\x00\x04" } |
| 58 | + let(:int_io) { StringIO.new(int) } |
| 59 | + |
| 60 | + let(:contents_unicast_ref) do |
| 61 | + "\x00\x0a\x55\x6e\x69\x63\x61\x73\x74\x52\x65\x66\x00\x0e\x31\x37" + |
| 62 | + "\x32\x2e\x31\x36\x2e\x31\x35\x38\x2e\x31\x33\x31\x00\x00\x0b\xf1" + |
| 63 | + "\x54\x74\xc4\x27\xb7\xa3\x4e\x9b\x51\xb5\x25\xf9\x00\x00\x01\x4a" + |
| 64 | + "\xdf\xd4\x57\x7e\x80\x01\x01" |
| 65 | + end |
| 66 | + |
| 67 | + let(:unicast_ref_io) do |
| 68 | + StringIO.new(Rex::Java::Serialization::Model::BlockData.new(nil, contents_unicast_ref).contents) |
| 69 | + end |
| 70 | + |
| 71 | + let(:ref_address) { '172.16.158.131' } |
| 72 | + let(:ref_port) { 3057 } |
| 73 | + let(:ref_object_number) { 6085704671348084379 } |
| 74 | + |
| 75 | + let(:unicast_ref) do |
| 76 | + { |
| 77 | + :address => '172.16.158.131', |
| 78 | + :object_number => 6085704671348084379, |
| 79 | + :port => 3057 |
| 80 | + } |
| 81 | + end |
| 82 | + |
53 | 83 | describe "#calculate_interface_hash" do
|
54 | 84 | context "when an example interface is provided" do
|
55 | 85 | it "generates a correct interface hash" do
|
|
69 | 99 | expect(mod.calculate_method_hash(method_signature)).to eq(method_hash)
|
70 | 100 | end
|
71 | 101 | end
|
| 102 | + |
| 103 | + describe "#extract_string" do |
| 104 | + context "when io contains a valid string" do |
| 105 | + it "returns the string" do |
| 106 | + expect(mod.extract_string(string_io)).to eq('ABCD') |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + context "when io doesn't contain a valid string" do |
| 111 | + it "returns nil" do |
| 112 | + expect(mod.extract_string(empty_io)).to be_nil |
| 113 | + end |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + describe "#extract_int" do |
| 118 | + context "when io contains a valid int" do |
| 119 | + it "returns the string" do |
| 120 | + expect(mod.extract_int(int_io)).to eq(4) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + context "when io doesn't contain a valid int" do |
| 125 | + it "returns nil" do |
| 126 | + expect(mod.extract_int(empty_io)).to be_nil |
| 127 | + end |
| 128 | + end |
| 129 | + end |
| 130 | + |
| 131 | + describe "#extract_reference" do |
| 132 | + context "when empty io" do |
| 133 | + it "returns nil" do |
| 134 | + expect(mod.extract_reference(empty_io)). to be_nil |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context "when valid io" do |
| 139 | + it "returns a hash" do |
| 140 | + expect(mod.extract_reference(unicast_ref_io)).to be_a(Hash) |
| 141 | + end |
| 142 | + |
| 143 | + it "returns a hash containing the address where the remote interface listens" do |
| 144 | + expect(mod.extract_reference(unicast_ref_io)[:address]).to eq(ref_address) |
| 145 | + end |
| 146 | + |
| 147 | + it "returns a hash containing the port where the remote interface listens" do |
| 148 | + expect(mod.extract_reference(unicast_ref_io)[:port]).to eq(ref_port) |
| 149 | + end |
| 150 | + |
| 151 | + it "returns a hash containing the object number of the remote interface" do |
| 152 | + expect(mod.extract_reference(unicast_ref_io)[:object_number]).to eq(ref_object_number) |
| 153 | + end |
| 154 | + |
| 155 | + it "returns a hash containing the extracted unique identifier" do |
| 156 | + expect(mod.extract_reference(unicast_ref_io)[:uid]).to be_a(Rex::Proto::Rmi::Model::UniqueIdentifier) |
| 157 | + end |
| 158 | + end |
| 159 | + end |
| 160 | + |
72 | 161 | end
|
73 | 162 |
|
0 commit comments