Path: blob/master/spec/modules/auxiliary/scanner/teamcity/teamcity_login_spec.rb
27932 views
require 'rspec'1require 'metasploit/framework/login_scanner/teamcity'23RSpec.describe Metasploit::Framework::LoginScanner::TeamCity do45it_behaves_like 'Metasploit::Framework::LoginScanner::Base', has_realm_key: false, has_default_realm: false6it_behaves_like 'Metasploit::Framework::LoginScanner::RexSocket'7it_behaves_like 'Metasploit::Framework::LoginScanner::HTTP'89let(:subject) { described_class.new }1011# Sample public key taken from a running instance of TeamCity12let(:teamcity_public_key) { 123745099044379560034534292817206769690406658656179033915532150868201038268331364602421054634661908195221281696003927960251442559477403753250293468778385622756011022439279250077496033565623853604577886813851441780820332383679913126402116420846511593354558582754642561605875011841424796003363034584971880190853 }1314describe '#two_byte_chars?' do15[16{ input: 'abc', expected: false },17{ input: '', expected: false },18{ input: 'ççç', expected: false }, # has2byteChars('ç') -> false19# I love metasploit20{ input: 'メタスプライトが大好きです', expected: true } # has2byteChars('メタスプライトが大好きです') -> true21].each do |scenario|22it 'returns the correct value' do23expect(subject.two_byte_chars?(scenario[:input])).to eq(scenario[:expected])24end25end2627[28{ input: nil },29{ input: true },30{ input: 123 },31{ input: [] }32].each do |scenario|33it 'raises an error on incorrect type' do34expect { subject.two_byte_chars?(scenario[:input]) }.to raise_error(ArgumentError)35end36end37end3839describe '#max_data_size' do40[41{ input: 'abc', expected: 116 },42{ input: '', expected: 116 },43{ input: 'ççç', expected: 116 },44{ input: 'メタスプライトが大好きです', expected: 58 } # I love metasploit45].each do |scenario|46it 'returns the correct maximum message length' do47expect(subject.max_data_size(scenario[:input])).to eq(scenario[:expected])48end49end5051[52{ input: nil },53{ input: true },54{ input: 123 },55{ input: [] }56].each do |scenario|57it 'raises an error on incorrect type' do58expect { subject.max_data_size(scenario[:input]) }.to raise_error(ArgumentError)59end60end61end6263describe '#pkcs1pad2' do64[65{ input: 'abc', expected: /0061626303$/ },66{ input: '', expected: /0000$/ },67{ input: 'ççç', expected: /00e7e7e703$/ }, # 3 chars, E7 codepoint68{ input: 'メタスプライトが大好きです', expected: /0030e130bf30b930d730e930a430c8304c5927597d304d306730590d$/ } # I love metasploit69].each do |scenario|70it 'correctly pads text' do71n = (teamcity_public_key.bit_length + 7) >> 372padded_as_big_int = subject.pkcs1pad2(scenario[:input], n)73padded_hex = padded_as_big_int.to_s(16)74expect(padded_hex).to match(scenario[:expected])75end76end7778[79{ input: nil, n: nil },80{ input: '', n: nil },81{ input: nil, n: 128 },82{ input: true, n: true },83].each do |scenario|84it 'raises an error on incorrect type' do85expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)86end87end8889[90{ input: 'a', n: 11 },91{ input: 'very_long_message_that_consists_of_many_characters', n: 40 }92].each do |scenario|93it 'raises an error when message is too long' do94expect { subject.pkcs1pad2(scenario[:input], scenario[:n]) }.to raise_error(ArgumentError)95end96end97end98end99100101