From 3e213bd8fd6a919a384a51c3857546c52b77057e Mon Sep 17 00:00:00 2001 From: Willian Wang Date: Sat, 22 Apr 2023 14:16:46 -0300 Subject: [PATCH] Handle 302 redirects of GitHub release URLs --- metasploit/peass.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/metasploit/peass.rb b/metasploit/peass.rb index 7034199..b8a5167 100644 --- a/metasploit/peass.rb +++ b/metasploit/peass.rb @@ -220,6 +220,20 @@ class MetasploitModule < Msf::Post print_good("PEASS script sent") end + def fetch(uri_str, limit = 10) + raise 'Invalid URL, too many HTTP redirects' if limit == 0 + response = Net::HTTP.get_response(URI(uri_str)) + case response + when Net::HTTPSuccess then + response + when Net::HTTPRedirection then + location = response['location'] + fetch(location, limit - 1) + else + response.value + end + end + def load_peass # Load the PEASS script from a local file or from Internet peass_script = "" @@ -230,7 +244,7 @@ class MetasploitModule < Msf::Post raise 'Invalid URL' unless target.scheme =~ /https?/ raise 'Invalid URL' if target.host.to_s.eql? '' - res = Net::HTTP.get_response(target) + res = fetch(target) peass_script = res.body raise "Something failed downloading PEASS script from #{url_peass}" if peass_script.length < 500