CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/payloads/meterpreter/uri_checksum_spec.rb
Views: 11789
1
require 'spec_helper'
2
3
RSpec.describe Rex::Payloads::Meterpreter::UriChecksum do
4
class DummyClass
5
include Rex::Payloads::Meterpreter::UriChecksum
6
end
7
8
subject(:dummy_object) { DummyClass.new }
9
10
it { is_expected.to respond_to :generate_uri_checksum}
11
it { is_expected.to respond_to :process_uri_resource}
12
it { is_expected.to respond_to :uri_checksum_lookup}
13
14
describe '#process_uri_resource' do
15
context 'when passed a value for INITW' do
16
let(:uri) { "/7E37v"}
17
18
it 'returns a static value of /INITM' do
19
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_native
20
end
21
22
context 'with junk appended at the end' do
23
let(:uri) { "/7E37v_foobar"}
24
25
it 'returns a static value of /INITM' do
26
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
27
end
28
end
29
end
30
31
context 'when passed a value for INITJ' do
32
let(:uri) { "/a6BF9"}
33
34
it 'returns a static value of /INITJM' do
35
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_java
36
end
37
38
context 'with junk appended at the end' do
39
let(:uri) { "/a6BF9_foobar"}
40
41
it 'returns a static value of /INITJM' do
42
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
43
end
44
end
45
end
46
47
context 'when passed a value for CONN' do
48
let(:uri) { "/39ab3"}
49
50
it 'returns /CONN plus random junk' do
51
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :connect
52
end
53
54
context 'with junk appended at the end' do
55
let(:uri) { "/39ab3_foobar"}
56
57
it 'returns /CONN plus the junk' do
58
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
59
end
60
end
61
end
62
63
context 'when passed a junk value' do
64
let(:uri) { "/lolz"}
65
66
it 'returns the original uri string' do
67
expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil
68
end
69
end
70
end
71
72
describe '#generate_uri_checksum' do
73
[0, 80, 88, 90, 92, 98, 255, 127].each do |checksum_value|
74
[5,30,50,100,127].each do |uri_length|
75
["", "/boom", "/___AAAAAAAAAAAAA"].each do |prefix|
76
it "generates a #{uri_length} byte string that checksums back to the original value (#{checksum_value}) with prefix #{prefix}" do
77
uri_string = dummy_object.generate_uri_checksum(checksum_value, uri_length + prefix.to_s.length, prefix)
78
expect(Rex::Text.checksum8(uri_string)).to eq checksum_value
79
end
80
end
81
end
82
end
83
end
84
85
describe '#uri_checksum_lookup' do
86
87
context 'when passed a value for :connect' do
88
let(:mode) { :connect }
89
it 'returns a URI_CHECKSUM_CONN' do
90
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN
91
end
92
end
93
94
context 'when passed a value for :init_native' do
95
let(:mode) { :init_native }
96
it 'returns a URI_CHECKSUM_INITN' do
97
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN
98
end
99
end
100
101
context 'when passed a value for :init_java' do
102
let(:mode) { :init_java }
103
it 'returns a URI_CHECKSUM_INITJ' do
104
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ
105
end
106
end
107
108
context 'when passed a value for :init_python' do
109
let(:mode) { :init_python }
110
it 'returns a URI_CHECKSUM_INITP' do
111
expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP
112
end
113
end
114
115
end
116
117
end
118
119