Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/modules/auxiliary/scanner/teamcity/teamcity_login_spec.rb
27932 views
1
require 'rspec'
2
require 'metasploit/framework/login_scanner/teamcity'
3
4
RSpec.describe Metasploit::Framework::LoginScanner::TeamCity do
5
6
it_behaves_like 'Metasploit::Framework::LoginScanner::Base', has_realm_key: false, has_default_realm: false
7
it_behaves_like 'Metasploit::Framework::LoginScanner::RexSocket'
8
it_behaves_like 'Metasploit::Framework::LoginScanner::HTTP'
9
10
let(:subject) { described_class.new }
11
12
# Sample public key taken from a running instance of TeamCity
13
let(:teamcity_public_key) { 123745099044379560034534292817206769690406658656179033915532150868201038268331364602421054634661908195221281696003927960251442559477403753250293468778385622756011022439279250077496033565623853604577886813851441780820332383679913126402116420846511593354558582754642561605875011841424796003363034584971880190853 }
14
15
describe '#two_byte_chars?' do
16
[
17
{ input: 'abc', expected: false },
18
{ input: '', expected: false },
19
{ input: 'ççç', expected: false }, # has2byteChars('ç') -> false
20
# I love metasploit
21
{ input: 'メタスプライトが大好きです', expected: true } # has2byteChars('メタスプライトが大好きです') -> true
22
].each do |scenario|
23
it 'returns the correct value' do
24
expect(subject.two_byte_chars?(scenario[:input])).to eq(scenario[:expected])
25
end
26
end
27
28
[
29
{ input: nil },
30
{ input: true },
31
{ input: 123 },
32
{ input: [] }
33
].each do |scenario|
34
it 'raises an error on incorrect type' do
35
expect { subject.two_byte_chars?(scenario[:input]) }.to raise_error(ArgumentError)
36
end
37
end
38
end
39
40
describe '#max_data_size' do
41
[
42
{ input: 'abc', expected: 116 },
43
{ input: '', expected: 116 },
44
{ input: 'ççç', expected: 116 },
45
{ input: 'メタスプライトが大好きです', expected: 58 } # I love metasploit
46
].each do |scenario|
47
it 'returns the correct maximum message length' do
48
expect(subject.max_data_size(scenario[:input])).to eq(scenario[:expected])
49
end
50
end
51
52
[
53
{ input: nil },
54
{ input: true },
55
{ input: 123 },
56
{ input: [] }
57
].each do |scenario|
58
it 'raises an error on incorrect type' do
59
expect { subject.max_data_size(scenario[:input]) }.to raise_error(ArgumentError)
60
end
61
end
62
end
63
64
describe '#pkcs1pad2' do
65
[
66
{ input: 'abc', expected: /0061626303$/ },
67
{ input: '', expected: /0000$/ },
68
{ input: 'ççç', expected: /00e7e7e703$/ }, # 3 chars, E7 codepoint
69
{ input: 'メタスプライトが大好きです', expected: /0030e130bf30b930d730e930a430c8304c5927597d304d306730590d$/ } # I love metasploit
70
].each do |scenario|
71
it 'correctly pads text' do
72
n = (teamcity_public_key.bit_length + 7) >> 3
73
padded_as_big_int = subject.pkcs1pad2(scenario[:input], n)
74
padded_hex = padded_as_big_int.to_s(16)
75
expect(padded_hex).to match(scenario[:expected])
76
end
77
end
78
79
[
80
{ input: nil, n: nil },
81
{ input: '', n: nil },
82
{ input: nil, n: 128 },
83
{ input: true, n: true },
84
].each do |scenario|
85
it 'raises an error on incorrect type' do
86
expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)
87
end
88
end
89
90
[
91
{ input: 'a', n: 11 },
92
{ input: 'very_long_message_that_consists_of_many_characters', n: 40 }
93
].each do |scenario|
94
it 'raises an error when message is too long' do
95
expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)
96
end
97
end
98
end
99
end
100
101