@@ -9,51 +9,22 @@ class DummyClass
9
9
subject ( :dummy_object ) { DummyClass . new }
10
10
11
11
it { should respond_to :generate_uri_checksum }
12
- it { should respond_to :generate_uri_checksum_with_length }
13
12
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 }
43
14
44
15
describe '#process_uri_resource' do
45
16
context 'when passed a value for INITW' do
46
17
let ( :uri ) { "/7E37v" }
47
18
48
19
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
50
21
end
51
22
52
23
context 'with junk appended at the end' do
53
24
let ( :uri ) { "/7E37v_foobar" }
54
25
55
26
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
57
28
end
58
29
end
59
30
end
@@ -62,14 +33,14 @@ class DummyClass
62
33
let ( :uri ) { "/a6BF9" }
63
34
64
35
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
66
37
end
67
38
68
39
context 'with junk appended at the end' do
69
40
let ( :uri ) { "/a6BF9_foobar" }
70
41
71
42
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
73
44
end
74
45
end
75
46
end
@@ -78,14 +49,14 @@ class DummyClass
78
49
let ( :uri ) { "/39ab3" }
79
50
80
51
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
82
53
end
83
54
84
55
context 'with junk appended at the end' do
85
56
let ( :uri ) { "/39ab3_foobar" }
86
57
87
58
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
89
60
end
90
61
end
91
62
end
@@ -94,9 +65,54 @@ class DummyClass
94
65
let ( :uri ) { "/lolz" }
95
66
96
67
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
98
92
end
99
93
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
+
100
116
end
101
117
102
118
end
0 commit comments