Enforce Style/RedundantBegin for new modules

This commit is contained in:
Alan Foster 2021-05-13 04:01:03 +01:00
parent 3312494a01
commit 100da2f1b1
No known key found for this signature in database
GPG Key ID: 3BD4FA3818818F04
47 changed files with 263 additions and 358 deletions

View File

@ -359,8 +359,7 @@ Layout/EmptyLinesAroundClassBody:
Description: 'these are used to increase readability'
Layout/EmptyLinesAroundMethodBody:
Enabled: false
Description: 'these are used to increase readability'
Enabled: true
Layout/ExtraSpacingWithBinDataIgnored:
Description: 'Do not use unnecessary spacing.'
@ -405,18 +404,7 @@ Style/PercentLiteralDelimiters:
VersionChanged: '0.48.1'
Style/RedundantBegin:
Exclude:
# this pattern is very common and somewhat unavoidable
# def run_host(ip)
# begin
# ...
# rescue ...
# ...
# ensure
# disconnect
# end
# end
- 'modules/**/*'
Enabled: true
Style/SafeNavigation:
Description: >-

View File

@ -146,7 +146,6 @@ class MetasploitModule < Msf::Auxiliary
end
def make_forward_request_package(method, headers, attributes)
prefix_code_int = 2
prefix_code_bytes = int2byte(prefix_code_int)
method_bytes = int2byte(method2code(method))

View File

@ -170,7 +170,6 @@ class MetasploitModule < Msf::Auxiliary
end
def run
begin
vers_string = retrieve_asa_version
print_status("Building #{action.name} payload for version #{vers_string}...")
@ -202,7 +201,6 @@ class MetasploitModule < Msf::Auxiliary
ensure
disconnect_snmp
end
end
def retrieve_asa_version
return datastore['ASAVER'] unless (datastore['ASAVER'] == 'auto')

View File

@ -26,7 +26,6 @@ class MetasploitModule < Msf::Auxiliary
Opt::RPORT(22)
]
)
end
def run

View File

@ -34,7 +34,6 @@ class MetasploitModule < Msf::Auxiliary
Opt::RPORT(22)
]
)
end
def run

View File

@ -32,7 +32,6 @@ class MetasploitModule < Msf::Auxiliary
Opt::RPORT(22)
]
)
end
def run

View File

@ -32,7 +32,6 @@ class MetasploitModule < Msf::Auxiliary
Opt::RPORT(22)
]
)
end
def i_file

View File

@ -215,7 +215,6 @@ class MetasploitModule < Msf::Auxiliary
end
def check
# Set up variables
os_release = ''
os_release_file = '/etc/os-release'
@ -294,7 +293,6 @@ class MetasploitModule < Msf::Auxiliary
end
def action_file_read
# Set up XML data for HTTP request
setup_xml_and_variables
make_post_data(@file, dos: false)
@ -349,7 +347,6 @@ class MetasploitModule < Msf::Auxiliary
end
def action_dos
# Set up XML data for HTTP request
setup_xml_and_variables
make_post_data(@file, dos: true)
@ -389,7 +386,6 @@ class MetasploitModule < Msf::Auxiliary
# Check HTTP response
fail_with(Failure::NotVulnerable, 'The target responded with a 200 OK response code. The DoS attempt was unsuccessful.') unless dos_response.code != 200
end
end

View File

@ -75,7 +75,6 @@ class MetasploitModule < Msf::Auxiliary
print_status('Opened connection')
EM::Timer.new(1) do
begin
print_status('Sending payload')
payload = Rex::Text.rand_text_alphanumeric(7000..8000)
driver.send({
@ -94,7 +93,6 @@ class MetasploitModule < Msf::Auxiliary
fail_with(Failure::Unreachable, 'Could not establish websocket connection')
end
end
end
EM::Timer.new(10) do
print_status('Checking Modem Status')

View File

@ -229,7 +229,6 @@ class MetasploitModule < Msf::Auxiliary
end
print_good("#{peer} Saved LDAP data to #{ldif_filename}")
end
def decode_pwdhistory(hash)

View File

@ -68,7 +68,6 @@ class MetasploitModule < Msf::Auxiliary
# Connect to Redis and ensure compatibility.
def redis_connect
begin
connect
# NOTE: Full INFO payload fails occasionally. Using server filter until Redis library can be fixed
if (info_data = redis_command('INFO', 'server')) && /redis_version:(?<redis_version>\S+)/ =~ info_data
@ -101,7 +100,6 @@ class MetasploitModule < Msf::Auxiliary
print_error('Unknown error trying to connect to Redis')
return
end
end
def check_host(_ip)
info_data = redis_connect

View File

@ -79,7 +79,6 @@ class MetasploitModule < Msf::Auxiliary
end
return 'unsupported'
end
def rce_check(version, real_target: false)

View File

@ -108,7 +108,6 @@ class MetasploitModule < Msf::Auxiliary
end
def do_enum(username)
begin
vprint_status("Attempting #{username}")
res = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'webman', 'forget_passwd.cgi'),
@ -150,6 +149,4 @@ class MetasploitModule < Msf::Auxiliary
rescue Timeout::Error, Errno::EPIPE
fail_with(Failure::Unreachable, 'Connection issue')
end
end
end

View File

@ -125,7 +125,7 @@ class MetasploitModule < Msf::Auxiliary
path.split('/').last
)
print_good("#{ip} - Database backup (#{res.body.bytesize} bytes) saved in: #{path}")
begin
Zip::File.open(path) do |zip_file|
# Handle entries one by one
zip_file.each do |entry|
@ -168,4 +168,3 @@ class MetasploitModule < Msf::Auxiliary
print_status("#{ip} - finished processing backup zip")
end
end
end

View File

@ -178,10 +178,8 @@ class MetasploitModule < Msf::Auxiliary
end
def cleanup
begin
disconnect
rescue StandardError
nil
end
end
end

View File

@ -59,7 +59,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def firmware
begin
res = send_request_cgi(
'method' => 'GET',
'uri' => '/brand.xml'
@ -73,7 +72,6 @@ class MetasploitModule < Msf::Exploit::Remote
@version = res_xml.at('//firmware').text
return true
end
end
def check
result = firmware

View File

@ -94,11 +94,9 @@ class MetasploitModule < Msf::Exploit::Remote
@cookie = res.get_cookies
@admin_nonce = res.get_hidden_inputs.first['admin-nonce']
end
def exploit
capture_cookie_token
@task_name = Rex::Text.rand_text_alpha_lower(5)
@ -131,7 +129,6 @@ class MetasploitModule < Msf::Exploit::Remote
if res && res.code == 200 && res.body.include?('Successfully saved')
print_good "Scheduler successfully created ! Wait up to #{wfs_delay} seconds"
end
end
def on_new_session(_session)
@ -154,7 +151,6 @@ class MetasploitModule < Msf::Exploit::Remote
if res && res.code == 200 && res.body.include?('Successfully saved')
print_good 'The scheduler config successfully cleaned up!'
end
end
end

View File

@ -132,7 +132,6 @@ class MetasploitModule < Msf::Exploit::Remote
when :php_dropper
dropper
end
end
def dropper

View File

@ -196,6 +196,5 @@ class MetasploitModule < Msf::Exploit::Remote
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end
end
end

View File

@ -194,7 +194,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def exploit
unless check == CheckCode::Vulnerable
fail_with Failure::NotVulnerable, 'Target is not vulnerable'
end

View File

@ -74,7 +74,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def exploit
begin
vprint_status('Sending exploit code')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'webGui/images/green-on.png/'),
@ -98,4 +97,3 @@ class MetasploitModule < Msf::Exploit::Remote
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end
end
end

View File

@ -134,7 +134,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
fail_with(Failure::UnexpectedReply, "Web server error! Expected a HTTP 302 response code, but got #{res.code} instead.")
end
end
def start_backup_and_trigger_payload

View File

@ -65,7 +65,6 @@ class MetasploitModule < Msf::Exploit::Local
register_advanced_options [
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
]
end
# Simplify pulling the writable directory variable

View File

@ -48,7 +48,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def on_request_uri(cli, request)
if datastore['DEBUG_EXPLOIT'] && request.uri =~ %r{/print$*}
print_status("[*] #{request.body}")
send_response(cli, '')

View File

@ -74,7 +74,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def on_request_uri(cli, request)
if datastore['DEBUG_EXPLOIT'] && request.uri =~ %r{/print$*}
print_status("[*] #{request.body}")
send_response(cli, '')

View File

@ -522,7 +522,6 @@ class MetasploitModule < Msf::Exploit::Remote
fail_with(Failure::UnexpectedReply, e.message)
ensure
[project_a, project_b].each do |project|
begin
next unless project
print_status("Attempting to delete project #{project['path']}")
@ -532,7 +531,6 @@ class MetasploitModule < Msf::Exploit::Remote
print_error("Failed to delete project #{project['path']}")
end
end
end
def exploit
secret_key_base = read_secret_key_base

View File

@ -470,7 +470,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def execute_java(opts = {})
template =
%q{
#set($_="")

View File

@ -398,7 +398,6 @@ class MetasploitModule < Msf::Exploit::Remote
# Gets human verification type (options: "Question" | "Image" | Recaptcha2 | "Disabled")
def get_hv_type
print_status("Sending request to '#{target_uri.path}/ajax/api/hv/fetchHvType' to get human verification type.")
res = send_request_cgi({
'method' => 'POST',

View File

@ -88,7 +88,6 @@ class MetasploitModule < Msf::Exploit::Remote
OptString.new('TARGETURI', [true, 'The URI of the vBulletin base path', '/']),
OptEnum.new('PHP_CMD', [true, 'Specify the PHP function in which you want to execute the payload.', 'shell_exec', ['shell_exec', 'exec']])
])
end
def cmd_payload(command)

View File

@ -258,6 +258,5 @@ class MetasploitModule < Msf::Exploit::Remote
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end
end
end

View File

@ -246,7 +246,6 @@ class MetasploitModule < Msf::Exploit::Remote
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end
end
def on_new_session(session)

View File

@ -156,6 +156,5 @@ class MetasploitModule < Msf::Exploit::Remote
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end
end
end

View File

@ -94,7 +94,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
CheckCode::Detected
end
def rhost

View File

@ -203,7 +203,6 @@ class MetasploitModule < Msf::Exploit::Remote
# Main function
# ==============
def exploit
return unless check == Exploit::CheckCode::Appears
@encrypted = datastore['ENCRYPTED']

View File

@ -71,7 +71,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
def check
begin
res = check_product_info
unless res
@ -92,14 +91,12 @@ class MetasploitModule < Msf::Exploit::Remote
rescue JSON::ParserError
fail_with(Failure::UnexpectedReply, 'The target may have been updated')
end
end
def create_payload
Msf::Util::EXE.to_exe_asp(generate_payload_exe).to_s
end
def exploit
begin
print_good('Generate Payload')
data = create_payload
@ -149,7 +146,6 @@ class MetasploitModule < Msf::Exploit::Remote
'uri' => normalize_uri(target_uri.path, '/Assets/temp/hotspot/img/logohotspot.asp'),
'method' => 'GET'
}, 5)
end
rescue StandardError => e
fail_with(Failure::UnexpectedReply, "Failed to execute the payload: #{e}")
end

View File

@ -80,7 +80,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
fail_with(Failure::NoAccess, 'Failed to authenticate to the web interface')
end
end
def prtg_create_notification(cmd)
@ -166,7 +165,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
fail_with(Failure::Unknown, 'Failed to create malicious notification')
end
end
def prtg_trigger_notification
@ -195,7 +193,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
fail_with(Failure::Unknown, 'Failed to trigger malicious notification')
end
end
def prtg_delete_notification
@ -225,7 +222,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
fail_with(Failure::Unknown, 'Failed to delete malicious notification')
end
end
def check

View File

@ -121,6 +121,5 @@ class MetasploitModule < Msf::Exploit::Remote
unless res&.code == 200
print_error('Non-200 HTTP response received while trying to execute the command')
end
end
end

View File

@ -145,7 +145,6 @@ class MetasploitModule < Msf::Exploit::Remote
end
return CheckCode::Appears("Target is ZenTao version #{@version}.")
end
def retrieve_rand_val(res)

View File

@ -169,7 +169,6 @@ class MetasploitModule < Msf::Exploit::Local
end
def launch_dll_trigger
begin
print_status('Trying to start notepad')
process = setup_process
inject_magic(process)
@ -178,7 +177,6 @@ class MetasploitModule < Msf::Exploit::Local
elog(e)
print_error(e.message)
end
end
def rastapi_privileged_filecopy(file_contents, exploit_dir, upload_payload_pathname, target_payload_pathname)
handles = [] # stores open handles to cleanup properly
@ -289,13 +287,11 @@ class MetasploitModule < Msf::Exploit::Local
end
def validate_active_host
begin
print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}")
rescue Rex::Post::Meterpreter::RequestError => e
elog(e)
raise Msf::Exploit::Failed, 'Could not connect to session'
end
end
def validate_target
unless sysinfo['Architecture'] == ARCH_X64

View File

@ -150,13 +150,11 @@ class MetasploitModule < Msf::Exploit::Local
end
def validate_active_host
begin
print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}")
rescue Rex::Post::Meterpreter::RequestError => e
elog('Could not connect to session', error: e)
raise Msf::Exploit::Failed, 'Could not connect to session'
end
end
def validate_payload
vprint_status("Target Arch = #{sysinfo['Architecture']}")

View File

@ -146,13 +146,11 @@ class MetasploitModule < Msf::Exploit::Local
end
def validate_active_host
begin
print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}")
rescue Rex::Post::Meterpreter::RequestError => e
elog('Could not connect to session', error: e)
raise Msf::Exploit::Failed, 'Could not connect to session'
end
end
def validate_payload
vprint_status("Target Arch = #{sysinfo['Architecture']}")

View File

@ -64,7 +64,6 @@ class MetasploitModule < Msf::Exploit::Local
OptBool.new('STEALTH_ONLY', [false, 'Only exploit if the payload can be triggered without launching the Windows Update UI) ', false]),
OptInt.new('WAIT_FOR_TIWORKER', [false, 'No. of minutes to wait for TiWorker.exe to finish running if it is already active. ', 0])
])
end
def provided_path_dir

View File

@ -71,14 +71,12 @@ class MetasploitModule < Msf::Exploit::Remote
Opt::RPORT(48000),
]
)
end
# check: there are only two prerequisites to getting code execution. The version number
# and access to the directory_list probe. The easiest way to get this information is to
# ask nicely ;)
def check
connect
sock.put(generate_probe('get_info', ['interfaces=0']))
@ -105,7 +103,6 @@ class MetasploitModule < Msf::Exploit::Remote
else
return CheckCode::Safe
end
end
def exploit
@ -148,13 +145,11 @@ class MetasploitModule < Msf::Exploit::Remote
sock.put(exploit_packet)
disconnect
end
# generate_rsp_chain: This chain will re-align RSP / Stack, it MUST be a multiple of 16 bytes
# otherwise our call will fail. I had VP work 50% of the time when the stack was unaligned.
def generate_rsp_chain
rop_gadgets = [0x0000000140018c42] * 20 # ret
rop_gadgets += [
0x0000000140002ef6, # pop rax ; ret
@ -165,14 +160,12 @@ class MetasploitModule < Msf::Exploit::Remote
] # add esp, edi ; adc byte [rax], al ; add rsp, 0x0000000000000278 ; ret
return rop_gadgets.pack('<Q*')
end
# generate_rop_chain: This chain will craft function calls to GetModuleHandleA, GetProcAddressStub,
# and finally VirtualProtectStub. Once completed, we have bypassed DEP and can get code execution.
# Since we dynamically generate VirtualProtectStub, we needn't worry about other OS's.
def generate_rop_chain
# RAX -> HMODULE GetModuleHandleA(
# ( RCX == *module ) LPCSTR lpModuleName,
# );
@ -320,13 +313,11 @@ class MetasploitModule < Msf::Exploit::Remote
rop_gadgets += [0x0000000140018c42] * 20 # ret (do not remove)
return rop_gadgets.pack('<Q*')
end
# parse_listing: once the directory_list probe is sent we're returned a directory listing
# unfortunately it's hard to read this simply "decodes" it
def parse_listing(response, directory)
result = { 'name' => '', 'date' => '', 'size' => '', 'type' => '' }
i = 0
@ -424,7 +415,6 @@ class MetasploitModule < Msf::Exploit::Remote
# generate_probe: The nimcontroller utilizes the closed source protocol nimsoft so we need to specially
# craft probes in order for the controller to accept any input.
def generate_probe(probe, args)
client = "#{rand_text_alphanumeric(14)}\x00"
packet_args = ''
probe += "\x00"
@ -474,7 +464,6 @@ class MetasploitModule < Msf::Exploit::Remote
probe = packet_header + packet_body + packet_args
return probe
end
end

View File

@ -28,7 +28,6 @@ class MetasploitModule < Msf::Post
OptPath.new('WORDLIST', [false, 'Wordlist of possible enable passwords to try.'])
]
)
end
def run

View File

@ -48,7 +48,6 @@ class MetasploitModule < Msf::Post
end
def run
fail_with(Failure::NotVulnerable, 'AvDump.exe does not exist on target.') unless avdump
print_status('AvDump.exe exists!')
@ -65,6 +64,5 @@ class MetasploitModule < Msf::Post
print_status(result)
rm_f(dump_path)
end
end

View File

@ -48,7 +48,6 @@ class MetasploitModule < Msf::Post
OptBool.new('NoSaveCache', [false, 'Dont save the cache file to disk', true]),
OptString.new('ZipFileName', [false, 'Zip Output File Name. Blank for random', '']),
])
end
# Options removed or changed in sharphound v2 to sharphound v3

View File

@ -38,7 +38,6 @@ class MetasploitModule < Msf::Post
'Author' => ['Quentin Kaiser <kaiserquentin[at]gmail.com>']
)
)
end
# Decrypts `data` encrypted with Windows DPAPI by calling CryptUnprotectData