LoginSignup
9
9

More than 5 years have passed since last update.

glibc CVE-2015-7547 dnsmasqで何とかできるか?

Posted at

参考

Googleの記事
https://googleonlinesecurity.blogspot.jp/2016/02/cve-2015-7547-glibc-getaddrinfo-stack.html

PoC
https://github.com/fjserna/CVE-2015-7547

iptableで
http://qiita.com/kawaz/items/1b07429b28851f997dba

Google has found some mitigations that may help prevent exploitation if you are not able to immediately patch your instance of glibc. The vulnerability relies on an oversized (2048+ bytes) UDP or TCP response, which is followed by another response that will overwrite the stack. Our suggested mitigation is to limit the response (i.e., via DNSMasq or similar programs) sizes accepted by the DNS resolver locally as well as to ensure that DNS queries are sent only to DNS servers which limit the response size for UDP responses with the truncation bit set.

dnsmasqでどうやんのか?

dnsmasqに2048byte以上のレスポンスを叩き切る機能は多分ない(俺の調べが足らんかも)。じゃあどうやってやんのか、試してみたら ただ単にdnsmasqをかましてやればそれだけでOK ポイことが分かった。たぶん

検証方法

  1. 上記のPoCを git clone そんで make
  2. そのまんまの状態で、サーバサイド(.py) と クライアントサイドを動かして、セグメンテーションフォールト出るのを確認 (詳細は他の人の見て!)
  3. dnsmasqをインストールして設定追加
  4. サーバサイドが port:53 決め打ちなので、 1053とかにずらす
  5. dnsmasq経由で突っついて試してみる

dnsmasqの設定

dnsmasq.conf
server=/google.com/127.0.0.1#1053

どっかにぶち込む

CVE-2015-7547-poc.py 変更

ポートを 53->1053へ置換

CVE-2015-7547-client.c 変更

int
main(void)
{
        struct addrinfo hints, *res;
        int r;

        memset(&hints, 0, sizeof(hints));
        hints.ai_socktype = SOCK_STREAM;

        if ((r = getaddrinfo("google.com", "80",
            &hints, &res)) != 0)
                errx(1, "getaddrinfo: %s", gai_strerror(r));

        return 0;
}

結果

とりあえず digで叩く。ちなみにdigは getaddrinfo()はコールしてない、ちゃんとソース読んだ、マジ俺真面目。 nslookup も host も同じ、ぜんぶ bind-utilsのお仲間

# dig google.com
[UDP] Total Data len recv 39
00 00 0d 00 04 44 44 44 44 c0 0c 00 01 00 01 00          .....DDDD.......
00 00 0d 00 04 44 44 44 44 c0 0c 00 01 00 01 00          .....DDDD.......
00 00 0d 00 04 44 44 44 44 c0 0c 00 01 00 01 00          .....DDDD.......
00 00 0d 00 04 44 44 44 44                               .....DDDD

セグフォは出ないが、バイナリがまんま出る。これ見る限り、2048以下にカットしてるわけではなさ気。

つづいて、クライアントアプリで叩く

# ./CVE-2015-7547-client
[UDP] Total Data len recv 28
[UDP] Total Data len recv 28
Connected with 127.0.0.1:40195
[TCP] Total Data len recv 30
[TCP] Request1 len recv 28
... 待たされる

セグフォは出ない!が、待たされる。これはどうなんだろうか。まあ、クラックされるよりはいいかと。

なぜダイジョブなのかは正直わからない

パケットキャプチャ、だれかやって。

9
9
1

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
9
9