Showing 173 of 310 total issues
Method _open
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _open(filename:, attributes: nil, options: nil, disposition: RubySMB::Dispositions::FILE_OPEN,
impersonation: RubySMB::ImpersonationLevels::SEC_IMPERSONATE, read: true, write: false, delete: false)
create_request = RubySMB::SMB2::Packet::CreateRequest.new
create_request = set_header_fields(create_request)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method dcerpc_request
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def dcerpc_request(stub_packet, auth_level: nil, auth_type: nil)
stub_class = stub_packet.class.name.split('::')
#opts.merge!(endpoint: stub_class[-2])
values = {
opnum: stub_packet.opnum,
Method parse
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.parse(defaults: {}, &block)
defaults = DEFAULT_OPTIONS.merge(defaults)
options = defaults.clone
OptionParser.new do |parser|
parser.on("--share-name SHARE_NAME", "The share name (default: #{defaults[:share_name]})") do |share|
Method process
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process(request_buffer=nil)
if request_buffer.nil?
# this is only NTLMSSP (as opposed to SPNEGO + NTLMSSP)
buffer = OpenSSL::ASN1::ASN1Data.new([
Gss::OID_SPNEGO,
Method decompress_chunk
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.decompress_chunk(chunk)
out = ''
until chunk.empty?
flags = chunk[0].unpack1('C')
chunk = chunk[1..-1]
Method proxy_share_io_smb2
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def proxy_share_io_smb2(request, session)
if request.smb2_header.flags.related_operations == 0
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/9a639360-87be-4d49-a1dd-4c6be0c020bd
share_processor = session.tree_connect_table[request.smb2_header.tree_id]
@smb2_related_operations_state[:tree_id] = request.smb2_header.tree_id
Method parse_smb3_capabilities
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_smb3_capabilities(response_packet)
nc = response_packet.find_negotiate_context(
RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES
)
@preauth_integrity_hash_algorithm = RubySMB::SMB2::PreauthIntegrityCapabilities::HASH_ALGORITM_MAP[nc&.data&.hash_algorithms&.first]
Method do_session_setup_andx_smb1
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_session_setup_andx_smb1(request, session)
session_id = request.smb_header.uid
if session_id == 0
session_id = rand(1..0x10000)
session = @session_table[session_id] = Server::Session.new(session_id)
Method cert_server_request
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def cert_server_request(attributes:, authority:, csr:)
cert_server_request_request = CertServerRequestRequest.new(
pwsz_authority: authority,
pctb_attribs: { pb: (attributes.map { |k,v| "#{k}:#{v}" }.join("\n").encode('UTF-16LE').force_encoding('ASCII-8BIT') + "\x00\x00".b) },
pctb_request: { pb: csr.to_der }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method initialize
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def initialize(disk, path, **kwargs)
@virtual_disk = disk
@path = path
if kwargs.fetch(:exist?, true)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method proxy_share_io_smb2
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def proxy_share_io_smb2(request, session)
if request.smb2_header.flags.related_operations == 0
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/9a639360-87be-4d49-a1dd-4c6be0c020bd
share_processor = session.tree_connect_table[request.smb2_header.tree_id]
@smb2_related_operations_state[:tree_id] = request.smb2_header.tree_id
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method handle_smb2
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def handle_smb2(raw_request, header)
session_required = !(header.command == SMB2::Commands::SESSION_SETUP && header.session_id == 0)
if header.flags.related_operations == 0
@smb2_related_operations_state.clear
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method do_tree_connect_smb2
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def do_tree_connect_smb2(request, session)
@smb2_related_operations_state.delete(:tree_id)
response = RubySMB::SMB2::Packet::TreeConnectResponse.new
response.smb2_header.credits = 1
Method add_smb3_to_negotiate_request
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_smb3_to_negotiate_request(packet, dialects = SMB3_DIALECT_DEFAULT)
dialects.each do |dialect|
raise ArgumentError, 'Must be an array of strings' unless dialect.is_a? String
packet.add_dialect(dialect.to_i(16))
end
Method _handle_smb2
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def _handle_smb2(raw_request)
begin
header = RubySMB::SMB2::SMB2Header.read(raw_request)
rescue IOError => e
logger.error("Caught a #{e.class} while reading the SMB2 header (#{e.message})")
Method bind
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def bind(options={})
@call_id ||= 1
bind_req = Bind.new(options)
bind_req.pdu_header.call_id = @call_id
auth_type = options.fetch(:auth_type) { RPC_C_AUTHN_WINNT }
Method negotiate_response
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def negotiate_response(raw_data)
response = nil
if smb1
packet = RubySMB::SMB1::Packet::NegotiateResponseExtended.read raw_data
Method drs_crack_names
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def drs_crack_names(h_drs, flags: 0, format_offered: DS_SID_OR_SID_HISTORY_NAME, format_desired: DS_UNIQUE_ID_NAME, rp_names: [])
drs_crack_names_request = DrsCrackNamesRequest.new(
h_drs: h_drs,
pmsg_in: {
switch_type: 1,
Method query_value
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def query_value(handle, value_name)
query_value_request_packet = RubySMB::Dcerpc::Winreg::QueryValueRequest.new(hkey: handle, lp_value_name: value_name)
query_value_request_packet.lp_type = 0
query_value_request_packet.lpcb_data = 0
query_value_request_packet.lpcb_len = 0
Method read
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def read(bytes: @size, offset: 0)
atomic_read_size = [bytes, @tree.client.max_buffer_size].min
remaining_bytes = bytes
data = ''