マルウェア
仮想通貨を発掘する不正なDockerコンテナを確認、Shodanを利用して露出したAPIを検索
トレンドマイクロは、コンテナを狙う不正活動を監視するための取り組みの一環として、APIを露出させたDockerホストを実行するPCをハニーポットとして設置しました。Dockerは、コンテナベースの脅威によって最もよく狙われるシステムのひとつです。このハニーポットを設置して監視した目的は、攻撃者がこのDockerホストを発見し、ユーザが望まないコンテナを展開するために利用することを検出するためでした。
トレンドマイクロは、コンテナを狙う不正活動を監視するための取り組みの一環として、APIを露出させたDockerホストを実行するPCをハニーポットとして設置しました。Dockerは、コンテナベースの脅威によって最もよく狙われるシステムのひとつです。このハニーポットを設置して監視した目的は、攻撃者がこのDockerホストを発見し、ユーザが望まないコンテナを展開するために利用することを検出するためでした。最近、ハニーポットの状態を確認したところ、1つのイメージ(コンテナのスナップショット)が既にこの環境に展開されていたことが分かりました。 ハニーポットとの間で送受信されるトラフィックデータとログの解析から、弊社はこのコンテナが、リポジトリホスティングサービス「Docker Hub」のリポジトリ「zoolu2」から取得されたことを確認しました。このリポジトリは、公開されているため誰にでもアクセス可能となっています。このリポジトリの内容を確認したところ、カスタムメイドのシェル、Pythonスクリプト、設定ファイル、「Shodan」を利用して検索するスクリプト、そして仮想通貨マイニングソフトウェアのバイナリが含まれていたことが判明しました。「Shodan」はインターネットに接続されたデバイスを対象とする検索サービスです。Dockerはこのリポジトリを独自に捕捉し、本記事執筆時点(2019年5月30日)でアクセスできないようにしていました。 リポジトリ「zoolu2」内で確認されたすべてのイメージには、仮想通貨「Monero(XMR)」を発掘する仮想通貨発掘ツール(コインマイナー)のバイナリが含まれていました。この発見に関して、弊社がコインマイナーとしてデプロイされていたコンテナを確認したことがあることを考慮すると、これはとても興味深い事例です。加えて、このリポジトリにおいて確認されたイメージの中には、Shodanを利用して露出したAPIを持つDockerホストを列挙するスクリプトが含まれているものもありました。このスクリプトは、今後不正なコンテナを展開するのに適した標的を定めるために利用されていたと考えられます。
図1.:「Docker Hub」のリポジトリ「zoolu2」
■コンテナの展開とその動作について解説
図2:感染の流れ
トレンドマイクロは、この脅威についてさらに理解するために、リポジトリに含まれていた9つのイメージを解析することにしました。まず、これらのイメージはスクリプトを利用してデプロイされることがわかりました。このスクリプト「ubu.sh」(「PUA.Linux.XMRMiner.AA.component」として検出)は露出したAPIを利用してホストを確認します。その後、Dockerコマンド「POST /container/create)を利用して不正なコンテナを遠隔で作成します。また、このスクリプトは遠隔から通信するためにコンテナ内でSSHデーモンを起動します。 その後、このスクリプトはMoneroを発掘するバイナリ「darwin」(「PUA.Linux.XMRMiner.AA」として検出)を呼び出してバックグラウンドで実行します。すべてのコインマイナーと同様に、所有者の知らないうちにホストシステムのリソースを利用して仮想通貨(今回の事例の場合はMonero)を発掘します。この攻撃において興味深い点は、既存のコインマイナーではなく、ゼロから開発したコインマイナーを利用していることです。 以下の図では、コインマイナーのバイナリ「darwin」を呼び出した後、不適切な設定の他のDockerホストを見つけるためのスクリプト「rip」を呼び出す様子が示されています。
図3: Dockerイメージのエントリ
図4:コインマイナーのバイナリの詳細
また、このバイナリにはShodan APIを利用するシェルスクリプトも含まれています。このシェルスクリプトは、「port:2375 + product:Docker」を主なクエリとして利用し、露出したAPIを持つ他のDockerホストを検索します。トレンドマイクロは、感染のための新しいホストに関する情報を集める手段として、このシェルスクリプトを利用したのではないかと推測しています。
図5: 「Shodan」にログインし、デフォルトポートが開いたDockerホストを検索するために使用された関数のコード
図6:「Shodan」で見つかったオープンポートへの辞書攻撃に使用されるユーザ名とパスワード
IPアドレスのリストの用途に関して、弊社が推測した通りのことが起きていました。露出したDockerホストが見つかると、このホストのIPアドレスがリスト(「iplist.txt」ファイル)に追加されます。さらに、このリストは固有のIPアドレスを利用するために並べ替えられます。また、標的としたホストにおいて仮想通貨を発掘するコンテナが既に実行されているかどうかを確認します。見つかった場合、この既存のコンテナは削除されます。 このホストはそれからIPアドレスのリストに基づき、他の露出されたホストに追加のコンテナを展開するためにC&Cサーバとの通信を試みます。その後、新しいホストに対して前述の動作へと戻ります。
図7:イメージをコンテナとして遠隔から展開するコード
以下の図8、9、および10は、スクリプトのバックアップとShodan検索の履歴を含むコマンド&アンドコントロール(C&C)サーバを示しています。
図8:C&Cサーバにホストされたスクリプトのバックアップ
図9:Shodan検索の履歴
図10:国コードを含むShodan検索文字列
注(図8、9、および10):一部のパラメータには特定の地域と特定のサービスが含まれていますが、Docker APIポートと製品タグの検索は一定となっています。 リポジトリ「zoolu2」のイメージのメタデータは、このコンポーネントが2019年5月に追加されたことを示しています。ただし、このイメージは常にアップデートされているため、この情報は正確ではない、もしくは最新のものではない可能性があります。このアップデートの動きは、イメージを作成した攻撃者が動作や機能をさらに追加していることを示していると考えられます。
図11:遠隔からの通信のためにコンテナ内に残ったSSHキーに対する「Deep Discovery™ Smart Check」からの警告
■被害に遭わないためには
コンテナの普及に伴い、この技術を標的とする脅威も増加しました。このような脅威は、コンテナソフトウェアの欠陥や脆弱性を利用するだけでなく、不適切な設定を突いて攻撃を実行することもあります。これは、企業にとって常に課題とみなされている問題です。今回の事例の場合、露出したAPIを持ったホストは、仮想通貨の発掘によるリソース盗用の被害を受けるだけでなく、感染したコンテナの配布に加担させられてしまいます。 望まない仮想通貨発掘活動は、標的となった利用者に追加のリソース消費を強いることになります。今回の事例では、Dockerホストが内部インフラストラクチャ上で実行されている場合、他のホストもこの影響を受ける可能性があります。一方、Dockerホストがクラウドサービスプロバイダを利用している場合、より高いリソース使用量のために、法人に対して追加料金が発生してしまう可能性があります。 コンテナおよびホストを狙う攻撃を許して開発環境に影響を与えるのを防ぐために、以下のベストプラクティスを講じることを推奨します。
- セキュリティの隙を突く攻撃を最小限に抑えるために、コンテナとAPIは常に適切に設定すること。この設定には、内部ネットワークまたは信頼できるソースからのみアクセスを許すことも含まれます。さらに、ユーザがセキュリティを強化する方法に関して、Dockerは具体的なガイドラインを提供しています
- 信頼できるコンテンツのみが利用者の環境で実行されるように、Dockerは常に公式または公認のイメージを使用することを推奨しています
- 実行中のコンテナをroot権限で実行しないこと。代わりに、アプリケーションユーザとしてのみ、これらのコンテナを利用するようにしましょう
■トレンドマイクロの対策
企業は、ソフトウェアを安全かつ迅速にビルドおよび展開し実行するために包括的なセキュリティソフトウェアを利用することが可能です。トレンドマイクロの総合サーバセキュリティ製品「Trend Micro Deep Security™」およびコンテナイメージを保護する「Deep Security Smart Check」により、デプロイおよび実行時にコンテナイメージをスキャンすることが可能です。
■侵入の痕跡(Indicators of Compromise、IoCs)
侵入の痕跡はこちらを参照してください。 参考記事:
- 「Infected Cryptocurrency-Mining Containers Target Docker Hosts With Exposed APIs, Use Shodan to Find Additional Victims」 by Alfredo Oliveira
翻訳: 下舘 紗耶加(Core Technology Marketing, Trend Micro™ Research)