From a204b550d2cc2166723c05102f1d89c0c6e7c8d7 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Tue, 3 Mar 2015 10:55:55 -0600 Subject: [PATCH] Add specs for TRANSACTION2 helper methods --- .../smb/server/share/command/trans2_spec.rb | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 spec/lib/msf/core/exploit/smb/server/share/command/trans2_spec.rb diff --git a/spec/lib/msf/core/exploit/smb/server/share/command/trans2_spec.rb b/spec/lib/msf/core/exploit/smb/server/share/command/trans2_spec.rb new file mode 100644 index 0000000000..6f58fe3af5 --- /dev/null +++ b/spec/lib/msf/core/exploit/smb/server/share/command/trans2_spec.rb @@ -0,0 +1,68 @@ +# -*- coding:binary -*- +require 'spec_helper' + +require 'msf/core' +require 'msf/core/exploit/smb/server/share' +require 'rex/proto/smb/constants' + +describe Msf::Exploit::Remote::SMB::Server::Share do + + subject(:mod) do + mod = Msf::Exploit.new + mod.extend described_class + mod.send(:initialize) + + mod + end + + let(:unicode_path) { "\x5c\x00\x74\x00\x65\x00\x73\x00\x74\x00\x2e\x00\x65\x00\x78\x00\x65\x00\x00\x00" } + let(:normalized_path) { '\\test.exe' } + let(:ascii_path) { 'test.exe' } + let(:broken_path) { 'ts.x' } + let(:wildcard_filename) { '\\*.exe' } + let(:wildcard_ext) { '\\test.*' } + let(:alternate_wildcard_filename) { '\\<.exe' } + + before(:each) do + mod.lo = 0 + mod.hi = 0 + mod.share = 'test' + mod.path_name = "\\" + mod.file_name = 'test.exe' + mod.file_contents = 'metasploit' + end + + describe "#normalize_path" do + context "when unicode path" do + it "returns the normalized path" do + expect(mod.normalize_path(unicode_path)).to eq(normalized_path) + end + end + + context "when ascii path" do + it "returns a broken path" do + expect(mod.normalize_path(ascii_path)).to eq(broken_path) + end + end + end + + describe "#smb_expand" do + context "when * wildcard" do + it "expands the filename" do + expect(mod.smb_expand(wildcard_filename)).to eq(normalized_path) + end + + it "doesn't expand the extension" do + expect(mod.smb_expand(wildcard_ext)).to eq('\\test.*') + end + end + + context "when < wildcard" do + it "expands the filename" do + expect(mod.smb_expand(alternate_wildcard_filename)).to eq(normalized_path) + end + end + end +end + +