require 'spec_helper' require 'ronin/exploits/mixins/remote_tcp' require 'ronin/exploits/exploit' describe Ronin::Exploits::Mixins::RemoteTCP do module TestMixinsRemoteTCP class TestExploit < Ronin::Exploits::Exploit include Ronin::Exploits::Mixins::RemoteTCP end end let(:test_class) { TestMixinsRemoteTCP::TestExploit } describe ".included" do subject { test_class } it "must include Ronin::Support::Network::TCP::Mixin" do expect(subject).to include(Ronin::Support::Network::TCP::Mixin) end it "must include Ronin::Exploits::Params::Host" do expect(subject).to include(Ronin::Exploits::Params::Host) end it "must include Ronin::Exploits::Params::Port" do expect(subject).to include(Ronin::Exploits::Params::Port) end it "must include Ronin::Exploits::Params::BindHost" do expect(subject).to include(Ronin::Exploits::Params::BindHost) end it "must include Ronin::Exploits::Params::BindPort" do expect(subject).to include(Ronin::Exploits::Params::BindPort) end end let(:host) { 'example.com' } let(:port) { 1337 } let(:bind_host) { 'localhost' } let(:bind_port) { 9000 } subject do test_class.new( params: { host: host, port: port, bind_host: bind_host, bind_port: bind_port } ) end describe "#tcp_open?" do context "when given no arguments" do it "must call Ronin::Support::Network::TCP.open? with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::TCP).to receive(:open?).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.tcp_open? end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::TCP).to receive(:open?).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Testing if #{subject.host}:#{subject.port} is open ..." ) subject.tcp_open? end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#tcp_connect" do context "when given no arguments" do it "must call Ronin::Support::Network::TCP.connect with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::TCP).to receive(:connect).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.tcp_connect end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::TCP).to receive(:connect).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Connecting to #{subject.host}:#{subject.port} ..." ) subject.tcp_connect end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#tcp_connect_and_send" do context "when given one argument" do let(:data) { 'foo' } it "must call Ronin::Support::Network::TCP.connect_and_send with data, #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::TCP).to receive(:connect_and_send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.tcp_connect_and_send(data) end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::TCP).to receive(:connect_and_send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Connecting to #{subject.host}:#{subject.port} and sending #{data.inspect} ..." ) subject.tcp_connect_and_send(data) end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#tcp_banner" do context "when given no arguments" do it "must call Ronin::Support::Network::TCP.banner with #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::TCP).to receive(:banner).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.tcp_banner end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::TCP).to receive(:banner).with( subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Fetching the banner for #{subject.host}:#{subject.port} ..." ) subject.tcp_banner end after { Ronin::Support::CLI::Printing.debug = false } end end end describe "#tcp_send" do context "when given one argument" do let(:data) { 'foo' } it "must call Ronin::Support::Network::TCP.send with data, #host, #port, bind_host: #bind_host, bind_port: #bind_port" do expect(Ronin::Support::Network::TCP).to receive(:send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) subject.tcp_send(data) end context "when debug messages are enabled" do before { Ronin::Support::CLI::Printing.debug = true } it "must print a debugging message" do allow(Ronin::Support::Network::TCP).to receive(:send).with( data, subject.host, subject.port, bind_host: subject.bind_host, bind_port: subject.bind_port ) expect(subject).to receive(:print_debug).with( "Sending #{data.inspect} to #{subject.host}:#{subject.port} ..." ) subject.tcp_send(data) end after { Ronin::Support::CLI::Printing.debug = false } end end end end