Skip to content

Commit 0b39c2e

Browse files
author
Tod Beardsley
committed
Land rapid7#4084, prep for Ruby 2.1
2 parents 4f0fbaa + d86d8e9 commit 0b39c2e

File tree

16 files changed

+121
-9382
lines changed

16 files changed

+121
-9382
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ before_script:
2323
script: "bundle exec rake $RAKE_TASK"
2424

2525
rvm:
26-
#- '1.8.7'
2726
- '1.9.3'
27+
- '2.0'
28+
- '2.1'
2829

2930
notifications:
3031
irc: "irc.freenode.org#msfnotify"

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
33
# spec.add_runtime_dependency '<name>', [<version requirements>]
44
gemspec
55

6+
gem 'rb-readline', require: false
7+
68
group :db do
79
# Needed for Msf::DbManager
810
gem 'activerecord', '>= 3.0.0', '< 4.0.0'

Gemfile.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PATH
1414
nokogiri
1515
packetfu (= 1.1.9)
1616
railties
17+
rb-readline
1718
recog (~> 1.0)
1819
robots
1920
rubyzip (~> 1.1)
@@ -57,7 +58,7 @@ GEM
5758
childprocess (>= 0.3.6)
5859
cucumber (>= 1.1.1)
5960
rspec-expectations (>= 2.7.0)
60-
bcrypt (3.1.7)
61+
bcrypt (3.1.9)
6162
builder (3.0.4)
6263
capybara (2.4.1)
6364
mime-types (>= 1.16)
@@ -161,6 +162,7 @@ GEM
161162
rdoc (~> 3.4)
162163
thor (>= 0.14.6, < 2.0)
163164
rake (10.3.2)
165+
rb-readline (0.5.1)
164166
rdoc (3.12.2)
165167
json (~> 1.4)
166168
recog (1.0.0)
@@ -230,6 +232,7 @@ DEPENDENCIES
230232
pg (>= 0.11)
231233
pry
232234
rake (>= 10.0.0)
235+
rb-readline
233236
redcarpet
234237
rspec (>= 2.12, < 3.0.0)
235238
rspec-rails (>= 2.12, < 3.0.0)

features/commands/help.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Feature: Help command
2-
2+
33
Background:
44
Given I run `msfconsole` interactively
55
And I wait for stdout to contain "Free Metasploit Pro trial: http://r-7.co/trymsp"
6-
6+
77
Scenario: The 'help' command's output
88
When I type "help"
99
And I type "exit"
@@ -75,4 +75,4 @@ Feature: Help command
7575
vulns List all vulnerabilities in the database
7676
workspace Switch between database workspaces
7777
"""
78-
78+

features/modules/exploit/smb/ms08_067_netapi.feature

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: MS08-067 netapi
77
And a mocked home directory
88
Given I run `msfconsole` interactively
99
And I wait for stdout to contain "Free Metasploit Pro trial: http://r-7.co/trymsp"
10-
10+
1111
Scenario: The MS08-067 Module should have the following options
1212
When I type "use exploit/windows/smb/ms08_067_netapi"
1313
And I type "show options"
@@ -28,7 +28,7 @@ Feature: MS08-067 netapi
2828
Id Name
2929
-- ----
3030
0 Automatic Targeting
31-
31+
3232
"""
3333

3434
Scenario: The MS08-067 Module should have the following advanced options
@@ -40,19 +40,19 @@ Feature: MS08-067 netapi
4040
Module advanced options:
4141
4242
Name : CHOST
43-
Current Setting:
43+
Current Setting:
4444
Description : The local client address
4545
4646
Name : CPORT
47-
Current Setting:
47+
Current Setting:
4848
Description : The local client port
4949
5050
Name : ConnectTimeout
5151
Current Setting: 10
5252
Description : Maximum number of seconds to establish a TCP connection
5353
5454
Name : ContextInformationFile
55-
Current Setting:
55+
Current Setting:
5656
Description : The information file that contains context information
5757
5858
Name : DCERPC::ReadTimeout
@@ -69,41 +69,41 @@ Feature: MS08-067 netapi
6969
7070
Name : NTLM::SendLM
7171
Current Setting: true
72-
Description : Always send the LANMAN response (except when NTLMv2_session is
72+
Description : Always send the LANMAN response (except when NTLMv2_session is
7373
specified)
7474
7575
Name : NTLM::SendNTLM
7676
Current Setting: true
77-
Description : Activate the 'Negotiate NTLM key' flag, indicating the use of
77+
Description : Activate the 'Negotiate NTLM key' flag, indicating the use of
7878
NTLM responses
7979
8080
Name : NTLM::SendSPN
8181
Current Setting: true
82-
Description : Send an avp of type SPN in the ntlmv2 client Blob, this allow
82+
Description : Send an avp of type SPN in the ntlmv2 client Blob, this allow
8383
authentification on windows Seven/2008r2 when SPN is required
8484
8585
Name : NTLM::UseLMKey
8686
Current Setting: false
87-
Description : Activate the 'Negotiate Lan Manager Key' flag, using the LM key
87+
Description : Activate the 'Negotiate Lan Manager Key' flag, using the LM key
8888
when the LM response is sent
8989
9090
Name : NTLM::UseNTLM2_session
9191
Current Setting: true
92-
Description : Activate the 'Negotiate NTLM2 key' flag, forcing the use of a
92+
Description : Activate the 'Negotiate NTLM2 key' flag, forcing the use of a
9393
NTLMv2_session
9494
9595
Name : NTLM::UseNTLMv2
9696
Current Setting: true
97-
Description : Use NTLMv2 instead of NTLM2_session when 'Negotiate NTLM2' key
97+
Description : Use NTLMv2 instead of NTLM2_session when 'Negotiate NTLM2' key
9898
is true
9999
100100
Name : Proxies
101-
Current Setting:
101+
Current Setting:
102102
Description : Use a proxy chain
103103
104104
Name : SMB::ChunkSize
105105
Current Setting: 500
106-
Description : The chunk size for SMB segments, bigger values will increase
106+
Description : The chunk size for SMB segments, bigger values will increase
107107
speed but break NT 4.0 and SMB signing
108108
109109
Name : SMB::Native_LM
@@ -131,37 +131,37 @@ Feature: MS08-067 netapi
131131
Description : The NetBIOS hostname (required for port 139 connections)
132132
133133
Name : SMBPass
134-
Current Setting:
134+
Current Setting:
135135
Description : The password for the specified username
136136
137137
Name : SMBUser
138-
Current Setting:
138+
Current Setting:
139139
Description : The username to authenticate as
140140
141141
Name : SSL
142142
Current Setting: false
143143
Description : Negotiate SSL for outgoing connections
144144
145145
Name : SSLCipher
146-
Current Setting:
146+
Current Setting:
147147
Description : String for SSL cipher - "DHE-RSA-AES256-SHA" or "ADH"
148148
149149
Name : SSLVerifyMode
150150
Current Setting: PEER
151-
Description : SSL verification method (accepted: CLIENT_ONCE,
151+
Description : SSL verification method (accepted: CLIENT_ONCE,
152152
FAIL_IF_NO_PEER_CERT, NONE, PEER)
153153
154154
Name : SSLVersion
155155
Current Setting: SSL3
156-
Description : Specify the version of SSL that should be used (accepted: SSL2,
156+
Description : Specify the version of SSL that should be used (accepted: SSL2,
157157
SSL3, TLS1)
158158
159159
Name : VERBOSE
160160
Current Setting: false
161161
Description : Enable detailed status messages
162162
163163
Name : WORKSPACE
164-
Current Setting:
164+
Current Setting:
165165
Description : Specify the workspace for this module
166166
167167
Name : WfsDelay

features/msfconsole/database_yml.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ Feature: `msfconsole` `database.yml`
157157
And the output should not contain "user_metasploit_framework_test"
158158
And the output should not contain "project_metasploit_framework_test"
159159
And the output should contain "[*] postgresql selected, no connection"
160-
160+
161161
Scenario: Starting `msfconsole` with a valid database.yml
162162
Given I run `msfconsole` interactively
163163
And I wait for stdout to contain "Free Metasploit Pro trial: http://r-7.co/trymsp"
164164
When I type "db_status"
165165
And I type "exit"
166166
Then the output should contain "[*] postgresql connected to metasploit_framework_test"
167-
167+

lib/msf/ui/console/driver.rb

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,7 @@ class Driver < Msf::Ui::Driver
5454
# @option opts [Boolean] 'SkipDatabaseInit' (false) Whether to skip
5555
# connecting to the database and running migrations
5656
def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {})
57-
58-
# Choose a readline library before calling the parent
59-
rl = false
60-
rl_err = nil
61-
begin
62-
if(opts['RealReadline'])
63-
require 'readline'
64-
rl = true
65-
end
66-
rescue ::LoadError
67-
rl_err = $!
68-
end
69-
70-
# Default to the RbReadline wrapper
71-
require 'readline_compatible' if(not rl)
57+
choose_readline(opts)
7258

7359
histfile = opts['HistFile'] || Msf::Config.history_file
7460

@@ -112,9 +98,9 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
11298
enstack_dispatcher(CommandDispatcher::Core)
11399

114100
# Report readline error if there was one..
115-
if not rl_err.nil?
101+
if !@rl_err.nil?
116102
print_error("***")
117-
print_error("* WARNING: Unable to load readline: #{rl_err}")
103+
print_error("* WARNING: Unable to load readline: #{@rl_err}")
118104
print_error("* Falling back to RbReadLine")
119105
print_error("***")
120106
end
@@ -719,6 +705,43 @@ def handle_loglevel(val)
719705
set_log_level(Msf::LogSource, val)
720706
end
721707

708+
# Require the appropriate readline library based on the user's preference.
709+
#
710+
# @return [void]
711+
def choose_readline(opts)
712+
# Choose a readline library before calling the parent
713+
@rl_err = nil
714+
if opts['RealReadline']
715+
# Remove the gem version from load path to be sure we're getting the
716+
# stdlib readline.
717+
gem_dir = Gem::Specification.find_all_by_name('rb-readline').first.gem_dir
718+
rb_readline_path = File.join(gem_dir, "lib")
719+
index = $LOAD_PATH.index(rb_readline_path)
720+
# Bundler guarantees that the gem will be there, so it should be safe to
721+
# assume we found it in the load path, but check to be on the safe side.
722+
if index
723+
$LOAD_PATH.delete_at(index)
724+
end
725+
end
726+
727+
begin
728+
require 'readline'
729+
rescue ::LoadError => e
730+
if @rl_err.nil? && index
731+
# Then this is the first time the require failed and we have an index
732+
# for the gem version as a fallback.
733+
@rl_err = e
734+
# Put the gem back and see if that works
735+
$LOAD_PATH.insert(index, rb_readline_path)
736+
index = rb_readline_path = nil
737+
retry
738+
else
739+
# Either we didn't have the gem to fall back on, or we failed twice.
740+
# Nothing more we can do here.
741+
raise e
742+
end
743+
end
744+
end
722745
end
723746

724747
#
@@ -731,6 +754,7 @@ def to_s
731754
end
732755
end
733756

757+
734758
end
735759
end
736760
end

0 commit comments

Comments
 (0)