File operating_system_normalization.rb
has 457 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'recog'
#
# Rules for operating system fingerprinting in Metasploit
#
Method apply_match_to_host
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def apply_match_to_host(match)
host = self
# These values in a match always override the current value unless
# the host attribute has been explicitly locked by the user
- 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 normalize_nexpose_fingerprint
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def normalize_nexpose_fingerprint(data)
ret = {}
# :family=>"Windows" :certainty=>"0.85" :vendor=>"Microsoft" :product=>"Windows 7 Ultimate Edition"
# :family=>"Windows" :certainty=>"0.67" :vendor=>"Microsoft" :arch=>"x86" :product=>'Windows 7' :version=>'SP1'
# :family=>"Linux" :certainty=>"0.64" :vendor=>"Linux" :product=>"Linux"
- 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 recog_matches_for_note
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def recog_matches_for_note(note)
# Skip notes that are missing the correct structure or have been blacklisted
return [] if not validate_fingerprint_data(note)
#
- 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 apply_match_to_host
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def apply_match_to_host(match)
host = self
# These values in a match always override the current value unless
# the host attribute has been explicitly locked by the user
Method normalize_match
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def normalize_match(m)
# Normalize os.version strings containing 'Service Pack X' to just 'SPX'
if m['os.version'] and m['os.version'].index('Service Pack ') == 0
m['os.version'] = m['os.version'].gsub(/Service Pack /, 'SP')
end
- 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 parse_windows_os_str
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_windows_os_str(str)
ret = {}
# Set some reasonable defaults for Windows
ret['os.vendor'] = 'Microsoft'
Method normalize_nexpose_fingerprint
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def normalize_nexpose_fingerprint(data)
ret = {}
# :family=>"Windows" :certainty=>"0.85" :vendor=>"Microsoft" :product=>"Windows 7 Ultimate Edition"
# :family=>"Windows" :certainty=>"0.67" :vendor=>"Microsoft" :arch=>"x86" :product=>'Windows 7' :version=>'SP1'
# :family=>"Linux" :certainty=>"0.64" :vendor=>"Linux" :product=>"Linux"
Method recog_matches_for_note
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def recog_matches_for_note(note)
# Skip notes that are missing the correct structure or have been blacklisted
return [] if not validate_fingerprint_data(note)
#
Method normalize_nessus_fingerprint
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def normalize_nessus_fingerprint(data)
ret = {}
# :os=>"Microsoft Windows 2000 Advanced Server (English)"
# :os=>"Microsoft Windows 2000\nMicrosoft Windows XP"
# :os=>"Linux Kernel 2.6"
Method guess_purpose_from_match
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def guess_purpose_from_match(match)
# some data that is sent to this is numeric; we do not want that
pstr = ""
# Go through each character of each value and make sure it is all
# UTF-8
Method normalize_os
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def normalize_os
host = self
matches = []
# Note that we're already restricting the query to this host by using
- 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 normalize_qualys_fingerprint
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def normalize_qualys_fingerprint(data)
ret = {}
# :os=>"Microsoft Windows 2000"
# :os=>"Windows 2003"
# :os=>"Microsoft Windows XP Professional SP3"
- 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 normalize_nmap_fingerprint
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def normalize_nmap_fingerprint(data)
ret = {}
# :os_vendor=>"Microsoft" :os_family=>"Windows" :os_version=>"2000" :os_accuracy=>"94"
ret['os.certainty'] = ( data[:os_accuracy].to_f / 100.0 ).to_s if data[:os_accuracy]
- 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 guess_purpose_from_match
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def guess_purpose_from_match(match)
# some data that is sent to this is numeric; we do not want that
pstr = ""
# Go through each character of each value and make sure it is all
# UTF-8
- 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 normalize_mbsa_fingerprint
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def normalize_mbsa_fingerprint(data)
ret = {}
# :os_match=>"Microsoft Windows Vista SP0 or SP1, Server 2008, or Windows 7 Ultimate (build 7000)"
# :os_vendor=>"Microsoft" :os_family=>"Windows" :os_version=>"7" :os_accuracy=>"100"
ret['os.certainty'] = ( data[:os_accuracy].to_f / 100.0 ).to_s if data[:os_accuracy]
- 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 recog_matches_for_service
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def recog_matches_for_service(s)
#
# We assume that the service.info field contains certain types of probe
# replies and associate these with one or more Recog databases. The mapping
# of service.name to a specific database only fits into so many places and
- 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 normalize_scanner_fp
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def normalize_scanner_fp(fp)
hits = []
return hits if not validate_fingerprint_data(fp)
- 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 parse_windows_os_str
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_windows_os_str(str)
ret = {}
# Set some reasonable defaults for Windows
ret['os.vendor'] = 'Microsoft'
- 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 normalize_nessus_fingerprint
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def normalize_nessus_fingerprint(data)
ret = {}
# :os=>"Microsoft Windows 2000 Advanced Server (English)"
# :os=>"Microsoft Windows 2000\nMicrosoft Windows XP"
# :os=>"Linux Kernel 2.6"
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ! host.attribute_locked?(:os_name)
# Try to fill this value from os.product first if it exists
if match.has_key?('os.product')
host.os_name = sanitize(match['os.product'])
else
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ! host.attribute_locked?(:os_sp)
if match['os.version']
host.os_sp = sanitize(match['os.version'])
else
if match['linux.kernel.version']
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 25.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76