inno setupを使用したマルウェアの解析

inno setupとの出会い

先日Malware bazaarに転がっている検体を落としてきてDIEに読み込ませたところ、初めて見る結果が表示されました。

inno setupというインストーラーが検知されました。

 

inno setupとは公式の説明を引用すると、Windows用のフリーインストーラのようです。

Inno Setup is free installer for Windows programs by Jordan Russell and Martijn Laan. First introduced in 1997, Inno Setup today rivals and even surpasses many commercial installers in feature set and stability.

jrsoftware.org

 

 

実際にマルウェアデバッグしながら挙動を確認していたところ、特徴的な文字列が見つかりました。

 

何やらセットアップに関する文字列であることが分かったため、全文をコピーして整形した結果が以下です。

inno setupのオプションに関するものが確認できました。

The Setup program accepts optional command line parameters...
/HELP, /? - Shows this information...
/SP- - Disables the prompt at the beginning of Setup...
/SILENT, /VERYSILENT - Instructs Setup to be silent or very silent...
/SUPPRESSMSGBOXES - Instructs Setup to suppress message boxes...
/LOG - Causes Setup to create a log file in the user's TEMP directory...
/LOG="filename" - Same as /LOG, except it allows you to specify a fixed path/filename to use for the log file...
/NOCANCEL - Prevents the user from cancelling during the installation process...
/NORESTART - Prevents Setup from restarting the system following a successful installation or after a Preparing to Install failure that requests a restart...
/RESTARTEXITCODE=exit code - Specifies a custom exit code that Setup is to return when the system needs to be restarted...
/CLOSEAPPLICATIONS - Instructs Setup to close applications using files that need to be updated...
/NOCLOSEAPPLICATIONS - Prevents Setup from closing applications using files that need to be updated...
/RESTARTAPPLICATIONS - Instructs Setup to restart applications...
/NORESTARTAPPLICATIONS - Prevents Setup from restarting applications...
/LOADINF="filename" - Instructs Setup to load the settings from the specified file after having checked the command line...
/SAVEINF="filename" - Instructs Setup to save installation settings to the specified file...
/LANG=language - Specifies the internal name of the language to use...
/DIR="x:\dirname" - Overrides the default directory name...
/GROUP="folder name" - Overrides the default folder name...
/NOICONS - Instructs Setup to initially check the Don't create a Start Menu folder check box...
/TYPE=type name - Overrides the default setup type...
/COMPONENTS="comma separated list of component names" - Overrides the default component settings...
/TASKS="comma separated list of task names" - Specifies a list of tasks that should be initially selected...
/MERGETASKS="comma separated list of task names" - Like the /TASKS parameter, except the specified tasks will be merged with the set of tasks that would have otherwise been selected by default...
/PASSWORD=password - Specifies the password to use...
For more detailed information, please visit http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline...
Setup...U...V

jrsoftware.org

 

これらの情報から、この検体はinno setup本体(または格納されてる?)と判断しました。

 

とりあえず、この判断が正しいかどうか確認するために正規のinnno setupを公式からダウンロードして、DIEに読み込んだ結果が以下のとおりです。

検体のDIEの結果とほとんど同じ結果が表示されたことが分かりました。

 

また、Stringsから文字列を確認したところIDAでデバッグ中に見つかった文字列が見つかりました。

これらの2つの理由から、この検体はinno setupを使用して新たな検体をドロップして実行する機能があると思われます。

 

デバッグの話に戻ります。

検体はCreateFileA関数を呼び出して自身と同じファイル名のtmpファイルを作成します。おそらくこれがinno setupによって作成されるインストーラーです。

インストーラーがドロップされる場所は、検体が作成したTemp配下のis-<ランダムな文字列>.tmpというディレクトリの中です。

 

ドロップされた検体をDIEに読み込ませた結果です。

 

リソースに潜んでいる実行ファイル

この検体をpestudioに取り込んだ結果、リソースデータに2つの実行可能形式ファイルが見つかりました。

 

 

  • SHFOLDERDLL

 

どちらのファイルもダンプしてハッシュをVTで検索してみましたが、結果だけ見ると不審なファイルではなさそうでした。

結果的に生成されたインストーラーに自動でつくもののようですね(?)

 

インストーラーのデバッグ

話を再度戻してドロップされたnnYotQ.tmpの行方をデバッガで確認して見ると、CreateProcess関数で実行され、引数は以下の内容が指定されていました。

C:\Users\m\Local\Temp\is-<ランダムな文字列>.tmp\nnYotQ.tmp  /SL5="$405C8,140559,56832,C:\Users\m\Desktop\nnYotQ.exe"

 

IDAにnnYotQ.tmpを読み込ませデバッグ時の引数に/SL5="$405C8,140559,56832,C:\Users\m\Desktop\nnYotQ.exe"を追加して実行したところ、nnYotQ.tmpがC2サーバーと接続していることが分かりました。

 

通信部分を特定するためにデバッグを進めていったところ、CFFによって解析妨害された関数にぶち当たりました・・・

(このレベルのCFFは初めてだったので、目的の箇所を見つけるまで約2時間かかりました・・・)

 

トレースを使用して使用しない関数や分岐などを調査して、残った関数からどのタイミングでC2と接続しているか調べていったところ、以下の箇所で通信していることが分かりました。

callされている部分にintoで入ってみると、idp.dllというDLLがメモリ上に展開されていて、その中で通信処理を行なっていました。

 

inno setupのアンパック

このDLLを取り出すためにinnounp.exeを使用します。 

innounp.exeは非公式のツールですが、これを使用することでアンパックすることができるようです。

innounp.sourceforge.net

 

ちなみにFlare VMにはデフォルトで入っていたので、そのまま使用します。

(引数でxを指定してあげると抽出)

無事にアンパックでき、2つのファイルを抽出することができました。

1つは先ほどメモリ上に展開されていたidp.dll。

もう1つはinstall_script.issというファイルです。

 

install_script.issはInno Setupのインストールスクリプトファイルで、インストーラーを作成するにあたって設定や指示が書かれています。

以下はinstall_script.issvscodeで展開した結果です。

 

[Files]
Source: "{tmp}\idp.dll"; DestDir: "{tmp}"; MinVersion: 0.0,5.0; Flags: deleteafterinstall dontcopy 

この箇所でインストールに含まれるファイルを定義しており、インストーラ作成時に「{tmp}idp.dll」ファイルを含み、インストール後に削除し、他の場所にコピーしないことを指定しているようです。

 

軽くidp.dllについて調べてみましたがinno download pluginの略称のようです。

また、VTにハッシュ値を投げてみましたがこのDLL自体は正規のファイルみたいでした。

 

 

これらの結果から、インストーラー(tmp)によってC2と接続して別の検体をダウンロードしていることが分かりました。

 

終わり

今回のブログは、inno setupについてある程度分かったため、ここまでで終わりにします。

なお、インストーラーがC2からダウンロードしてきた検体は.NET製でした。

機会があれば次はこの検体を解析したみたい・・・・と思ってます(いつか)

 

最後までこの記事を見てくださってありがとうございます。

何か間違ったことを書いていれば、Twitterか何かでお叱りいただけると助かりますm(_ _)m