Skip to content

Commit 9145b6d

Browse files
author
HD Moore
committed
Fix specs for uri_checksum
1 parent 78c73cc commit 9145b6d

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

spec/lib/rex/payloads/meterpreter/uri_checksum_spec.rb

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,22 @@ class DummyClass
99
subject(:dummy_object) { DummyClass.new }
1010

1111
it { should respond_to :generate_uri_checksum}
12-
it { should respond_to :generate_uri_checksum_with_length}
1312
it { should respond_to :process_uri_resource}
14-
15-
describe '#generate_uri_checksum' do
16-
let(:checksum_value) { 92 }
17-
18-
it 'generates a string that checksums back to the original value' do
19-
uri_string = dummy_object.generate_uri_checksum(checksum_value)
20-
expect(Rex::Text.checksum8(uri_string)).to eq checksum_value
21-
end
22-
23-
context 'when it fails to generate a random URI' do
24-
it 'should use the pre-calculated checksum string' do
25-
Rex::Text.stub(:checksum8) { false }
26-
expect(dummy_object.generate_uri_checksum(checksum_value)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_PRECALC[checksum_value]
27-
end
28-
29-
end
30-
end
31-
32-
describe '#generate_uri_checksum_with_length' do
33-
[0, 80, 88, 90, 92, 98, 255, 127].each do |checksum_value|
34-
[5,30,50,100,127].each do |uri_length|
35-
it "generates a #{uri_length} byte string that checksums back to the original value (#{checksum_value})" do
36-
uri_string = dummy_object.generate_uri_checksum_with_length(checksum_value, uri_length)
37-
expect(Rex::Text.checksum8(uri_string)).to eq checksum_value
38-
end
39-
end
40-
end
41-
42-
end
13+
it { should respond_to :uri_checksum_lookup}
4314

4415
describe '#process_uri_resource' do
4516
context 'when passed a value for INITW' do
4617
let(:uri) { "/7E37v"}
4718

4819
it 'returns a static value of /INITM' do
49-
expect(dummy_object.process_uri_resource(uri)).to eq '/INITM'
20+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_native
5021
end
5122

5223
context 'with junk appended at the end' do
5324
let(:uri) { "/7E37v_foobar"}
5425

5526
it 'returns a static value of /INITM' do
56-
expect(dummy_object.process_uri_resource(uri)).to eq '/INITM'
27+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
5728
end
5829
end
5930
end
@@ -62,14 +33,14 @@ class DummyClass
6233
let(:uri) { "/a6BF9"}
6334

6435
it 'returns a static value of /INITJM' do
65-
expect(dummy_object.process_uri_resource(uri)).to eq '/INITJM'
36+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_java
6637
end
6738

6839
context 'with junk appended at the end' do
6940
let(:uri) { "/a6BF9_foobar"}
7041

7142
it 'returns a static value of /INITJM' do
72-
expect(dummy_object.process_uri_resource(uri)).to eq '/INITJM'
43+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
7344
end
7445
end
7546
end
@@ -78,14 +49,14 @@ class DummyClass
7849
let(:uri) { "/39ab3"}
7950

8051
it 'returns /CONN plus random junk' do
81-
expect(dummy_object.process_uri_resource(uri)).to match(/\/CONN_(\w){16}/)
52+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :connect
8253
end
8354

8455
context 'with junk appended at the end' do
8556
let(:uri) { "/39ab3_foobar"}
8657

8758
it 'returns /CONN plus the junk' do
88-
expect(dummy_object.process_uri_resource(uri)).to eq '/CONN_foobar'
59+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
8960
end
9061
end
9162
end
@@ -94,9 +65,54 @@ class DummyClass
9465
let(:uri) { "/lolz"}
9566

9667
it 'returns the original uri string' do
97-
expect(dummy_object.process_uri_resource(uri)).to eq '/lolz'
68+
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
69+
end
70+
end
71+
end
72+
73+
describe '#generate_uri_checksum' do
74+
[0, 80, 88, 90, 92, 98, 255, 127].each do |checksum_value|
75+
[5,30,50,100,127].each do |uri_length|
76+
["", "/boom", "/___AAAAAAAAAAAAA"].each do |prefix|
77+
it "generates a #{uri_length} byte string that checksums back to the original value (#{checksum_value}) with prefix #{prefix}" do
78+
uri_string = dummy_object.generate_uri_checksum(checksum_value, uri_length + prefix.to_s.length, prefix)
79+
expect(Rex::Text.checksum8(uri_string)).to eq checksum_value
80+
end
81+
end
82+
end
83+
end
84+
end
85+
86+
describe '#uri_checksum_lookup' do
87+
88+
context 'when passed a value for :connect' do
89+
let(:mode) { :connect }
90+
it 'returns a URI_CHECKSUM_CONN' do
91+
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN
9892
end
9993
end
94+
95+
context 'when passed a value for :init_native' do
96+
let(:mode) { :init_native }
97+
it 'returns a URI_CHECKSUM_INITN' do
98+
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN
99+
end
100+
end
101+
102+
context 'when passed a value for :init_java' do
103+
let(:mode) { :init_java }
104+
it 'returns a URI_CHECKSUM_INITJ' do
105+
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ
106+
end
107+
end
108+
109+
context 'when passed a value for :init_python' do
110+
let(:mode) { :init_python }
111+
it 'returns a URI_CHECKSUM_INITP' do
112+
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP
113+
end
114+
end
115+
100116
end
101117

102118
end

0 commit comments

Comments
 (0)