Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/payloads/meterpreter/uri_checksum_spec.rb
Views: 11789
require 'spec_helper'12RSpec.describe Rex::Payloads::Meterpreter::UriChecksum do3class DummyClass4include Rex::Payloads::Meterpreter::UriChecksum5end67subject(:dummy_object) { DummyClass.new }89it { is_expected.to respond_to :generate_uri_checksum}10it { is_expected.to respond_to :process_uri_resource}11it { is_expected.to respond_to :uri_checksum_lookup}1213describe '#process_uri_resource' do14context 'when passed a value for INITW' do15let(:uri) { "/7E37v"}1617it 'returns a static value of /INITM' do18expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_native19end2021context 'with junk appended at the end' do22let(:uri) { "/7E37v_foobar"}2324it 'returns a static value of /INITM' do25expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil26end27end28end2930context 'when passed a value for INITJ' do31let(:uri) { "/a6BF9"}3233it 'returns a static value of /INITJM' do34expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :init_java35end3637context 'with junk appended at the end' do38let(:uri) { "/a6BF9_foobar"}3940it 'returns a static value of /INITJM' do41expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil42end43end44end4546context 'when passed a value for CONN' do47let(:uri) { "/39ab3"}4849it 'returns /CONN plus random junk' do50expect(dummy_object.process_uri_resource(uri)[:mode]).to eq :connect51end5253context 'with junk appended at the end' do54let(:uri) { "/39ab3_foobar"}5556it 'returns /CONN plus the junk' do57expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil58end59end60end6162context 'when passed a junk value' do63let(:uri) { "/lolz"}6465it 'returns the original uri string' do66expect(dummy_object.process_uri_resource(uri)[:mode]).to eq nil67end68end69end7071describe '#generate_uri_checksum' do72[0, 80, 88, 90, 92, 98, 255, 127].each do |checksum_value|73[5,30,50,100,127].each do |uri_length|74["", "/boom", "/___AAAAAAAAAAAAA"].each do |prefix|75it "generates a #{uri_length} byte string that checksums back to the original value (#{checksum_value}) with prefix #{prefix}" do76uri_string = dummy_object.generate_uri_checksum(checksum_value, uri_length + prefix.to_s.length, prefix)77expect(Rex::Text.checksum8(uri_string)).to eq checksum_value78end79end80end81end82end8384describe '#uri_checksum_lookup' do8586context 'when passed a value for :connect' do87let(:mode) { :connect }88it 'returns a URI_CHECKSUM_CONN' do89expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_CONN90end91end9293context 'when passed a value for :init_native' do94let(:mode) { :init_native }95it 'returns a URI_CHECKSUM_INITN' do96expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITN97end98end99100context 'when passed a value for :init_java' do101let(:mode) { :init_java }102it 'returns a URI_CHECKSUM_INITJ' do103expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ104end105end106107context 'when passed a value for :init_python' do108let(:mode) { :init_python }109it 'returns a URI_CHECKSUM_INITP' do110expect(dummy_object.uri_checksum_lookup(mode)).to eq Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITP111end112end113114end115116end117118119