-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish removing code from old work arounds
- Loading branch information
1 parent
dd6f303
commit e492eef
Showing
6 changed files
with
14 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,7 @@ | ||
module RubySMB::NTLM | ||
module Message | ||
def deflag | ||
security_buffers.inject(head_size) do |cur, a| | ||
a[1].offset = cur | ||
cur += a[1].data_size | ||
has_flag?(:UNICODE) ? cur + cur % 2 : cur | ||
end | ||
end | ||
|
||
def serialize | ||
deflag | ||
@alist.map { |n, f| f.serialize }.join + security_buffers.map { |n, f| f.value + (has_flag?(:UNICODE) ? "\x00".b * (f.value.length % 2) : '') }.join | ||
end | ||
end | ||
|
||
class Client < Net::NTLM::Client | ||
class Session < Net::NTLM::Client::Session | ||
def authenticate! | ||
calculate_user_session_key! | ||
type3_opts = { | ||
:lm_response => is_anonymous? ? "\x00".b : lmv2_resp, | ||
:ntlm_response => is_anonymous? ? '' : ntlmv2_resp, | ||
:domain => domain, | ||
:user => username, | ||
:workstation => workstation, | ||
:flag => (challenge_message.flag & client.flags) | ||
} | ||
t3 = Net::NTLM::Message::Type3.create type3_opts | ||
t3.extend(Message) | ||
if negotiate_key_exchange? | ||
t3.enable(:session_key) | ||
rc4 = OpenSSL::Cipher.new("rc4") | ||
rc4.encrypt | ||
rc4.key = user_session_key | ||
sk = rc4.update exported_session_key | ||
sk << rc4.final | ||
t3.session_key = sk | ||
end | ||
t3 | ||
end | ||
|
||
def is_anonymous? | ||
username == '' && password == '' | ||
end | ||
|
||
private | ||
|
||
def use_oem_strings? | ||
# @see https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/99d90ff4-957f-4c8a-80e4-5bfe5a9a9832 | ||
!challenge_message.has_flag?(:UNICODE) && challenge_message.has_flag?(:OEM) | ||
end | ||
|
||
def ntlmv2_hash | ||
@ntlmv2_hash ||= RubySMB::NTLM.ntlmv2_hash(username, password, domain, {:client_challenge => client_challenge, :unicode => !use_oem_strings?}) | ||
end | ||
|
||
def calculate_user_session_key! | ||
if is_anonymous? | ||
# see MS-NLMP section 3.4 | ||
@user_session_key = "\x00".b * 16 | ||
else | ||
@user_session_key = OpenSSL::HMAC.digest(OpenSSL::Digest::MD5.new, ntlmv2_hash, nt_proof_str) | ||
end | ||
end | ||
end | ||
|
||
def init_context(resp = nil, channel_binding = nil) | ||
if resp.nil? | ||
@session = nil | ||
type1_message | ||
else | ||
@session = Client::Session.new(self, Net::NTLM::Message.decode64(resp), channel_binding) | ||
@session.authenticate! | ||
end | ||
end | ||
# There was a bunch of code in here that was necessary in versions up to and including rubyntlm version 0.6.3. | ||
# The class is kept because there are references to it that should be kept in place in case future alterations to | ||
# rubyntlm are required. | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,18 @@ require 'ruby_smb/version' | |
Gem::Specification.new do |spec| | ||
spec.name = 'ruby_smb' | ||
spec.version = RubySMB::VERSION | ||
spec.authors = ['Metasploit Hackers', 'David Maloney', 'James Lee', 'Dev Mohanty', 'Christophe De La Fuente'] | ||
spec.authors = [ | ||
'Metasploit Hackers', | ||
'David Maloney', | ||
'James Lee', | ||
'Dev Mohanty', | ||
'Christophe De La Fuente', | ||
'Spencer McIntyre' | ||
] | ||
spec.email = ['[email protected]'] | ||
spec.summary = 'A pure Ruby implementation of the SMB Protocol Family' | ||
spec.description = '' | ||
spec.homepage = 'https://github.com/rapid7/ruby_smb' | ||
spec.homepage = 'https://github.com/rapid7/ruby_smb' | ||
spec.license = 'BSD-3-clause' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
|
@@ -33,7 +40,7 @@ Gem::Specification.new do |spec| | |
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'yard' | ||
|
||
spec.add_runtime_dependency 'rubyntlm' | ||
spec.add_runtime_dependency 'rubyntlm', '>= 0.6.5' | ||
spec.add_runtime_dependency 'windows_error', '>= 0.1.4' | ||
spec.add_runtime_dependency 'bindata', '2.4.15' | ||
spec.add_runtime_dependency 'openssl-ccm' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters