Created
June 18, 2015 12:57
-
-
Save claudijd/3763faa17b83b614cb00 to your computer and use it in GitHub Desktop.
I way to manually update RubyGems without susceptibility to CVE-2015-3900
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
require 'digest' | |
require 'net/http' | |
gem_file = 'rubygems-update-2.4.8.gem' | |
# Reference: https://rubygems.org/gems/rubygems-update/versions/2.4.8 | |
sha256hash = "dbed858db605923d9cc77080de1a5f1ce6ac3c68924877c78665e0d85d7b3e73" | |
################################################## | |
# Download the Gem from RubyGems.org (over HTTPS) | |
################################################## | |
puts "Downloading #{gem_file}" | |
if File.exists?(gem_file) | |
File.unlink(gem_file) | |
end | |
puts `wget https://rubygems.org/downloads/#{gem_file}` | |
if File.exists?(gem_file) | |
puts "Successfully Downloaded #{gem_file}" | |
else | |
puts "Failed to Download #{gem_file}" | |
puts "Aborting..." | |
exit | |
end | |
################################################## | |
# Verify the Gem against the SHA265 Hash from RubyGems.org | |
################################################## | |
puts "Verifying File against SHA256 hash" | |
if Digest::SHA256.hexdigest(File.read(gem_file)) == sha256hash | |
puts "#{gem_file} is Verified" | |
else | |
puts "#{gem_file} is Not Verified" | |
puts "Aborting..." | |
exit | |
end | |
################################################## | |
# Install the gem manually from downloaded file | |
################################################## | |
puts `gem install #{gem_file}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stupiding it up with bash