Skip to content

Commit

Permalink
add rspec for the matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
jcran committed Jan 13, 2012
1 parent e3c327a commit 27cce89
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source :rubygems

gem 'cucumber'
gem 'rspec'
gem 'msfrpc-client'
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ GEM
librex (>= 0.0.32)
msgpack (>= 0.4.5)
msgpack (0.4.6)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
term-ansicolor (1.0.7)

PLATFORMS
Expand All @@ -25,3 +33,4 @@ PLATFORMS
DEPENDENCIES
cucumber
msfrpc-client
rspec
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$:.unshift(File.dirname(__FILE__) + 'lib')

require 'cucumber/rake/task'
require 'rspec'

Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
Expand Down
1 change: 0 additions & 1 deletion features/step_definitions/default_login_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
run_module(mod, @systems, options)
end
end


When /^I check for valid logins via (.+)$/ do |types|
types = types.split(",")
Expand Down
69 changes: 49 additions & 20 deletions features/support/metasploit_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,50 @@ def initialize
end
end

#
# This class wraps the RPC connection and handles passing the token around
class Client

attr_accessor :rpc
attr_accessor :token

def initialize
@system = "127.0.0.1"
@username = "test"
@password = "bC}W0k8$"
@port = "3790"
system = "127.0.0.1"
username = "test"
password = "test"
port = "55553"

begin
@rpc = Msf::RPC::Client.new(:host => @system, :port => @port, :user => @username, :pass => @password, :ssl => true )
# make the connection
@rpc = Msf::RPC::Client.new(:host => system, :port => port, :ssl => true, :user => "test", :pass => "test" )
#response = @rpc.call("auth.login", username, password)

# Check to make sure we successfully authenticated
#if response['result'] == "success"
# puts "DEBUG: Successfully authenticated"
# @token = response['token']
# puts "DEBUG: Token is: #{@token}"
#else
# raise "Unable to authenticate"
#end
rescue Exception => e
raise "Unable to connect"
raise "Unable to connect: #{e}"
exit
end

end

#def call(method, *args)
# return @rpc.call(method, @token, args)
#end

end

#
# Below you'll find methods that can be called directly in step
# definitions. TODO - segment this up a bit and make more OO
#

def setup
@client = Client.new
end
Expand Down Expand Up @@ -59,10 +85,8 @@ def get_valid_cred_count
else
return 0
end

end


def check_logins(type="smb",systems,usernames,passwords)
self.setup unless @client

Expand Down Expand Up @@ -102,19 +126,20 @@ def run_module(module_name, systems, options={})
# -----------------------------------------------
# Start out with an empty settings hash and pull out each of the options
options_hash = {}
options_string.split(",").each{ |setting| options_hash["#{setting.split("=").first}"] = setting.split("=").last }

# Set a default payload unless it's already been set by the user
options_hash["PAYLOAD"] = "windows/meterpreter/bind_tcp" unless options_hash["PAYLOAD"]

# Set a default target unless it's already been set by the user
options_hash["TARGET"] = 0 unless options_hash["TARGET"]

#puts
#puts "DEBUG: Module type: #{module_type}"
#puts "DEBUG: Module name: #{module_name}"
#puts "DEBUG: Options Hash: #{options_hash}"
#puts
puts
puts "DEBUG: Module type: #{module_type}"
puts "DEBUG: Module name: #{module_name}"
puts "DEBUG: Options Hash: #{options_hash}"
puts "DEBUG: Method: module.execute"
puts "DEBUG: Token: #{@client.token}"
puts

# then call execute
@client.rpc.call("module.execute", module_type, module_name, options_hash)
Expand Down Expand Up @@ -144,12 +169,14 @@ def _check_http(systems,usernames,passwords)
# Set a default target unless it's already been set by the user
options_hash["TARGET"] = 0 unless options_hash["TARGET"]

#puts
#puts "DEBUG: Module type: #{module_type}"
#puts "DEBUG: Module name: #{module_name}"
#puts "DEBUG: Options Hash: #{options_hash}"
#puts

puts
puts "DEBUG: Module type: #{module_type}"
puts "DEBUG: Module name: #{module_name}"
puts "DEBUG: Options Hash: #{options_hash}"
puts "DEBUG: Method: module.execute"
puts "DEBUG: Token: #{@client.token}"
puts

# then call execute
begin
@client.rpc.call("module.execute", module_type, module_name, options_hash)
Expand Down Expand Up @@ -185,6 +212,8 @@ def _check_smb(systems,usernames,passwords)
puts "DEBUG: Module type: #{module_type}"
puts "DEBUG: Module name: #{module_name}"
puts "DEBUG: Options Hash: #{options_hash}"
puts "DEBUG: Method: module.execute"
puts "DEBUG: Token: #{@client.token}"
puts

# then call execute
Expand Down

0 comments on commit 27cce89

Please sign in to comment.