# CyberDay CTF : Forensic - Volatile memory (300 points)
###### tags: `Forensics` `CyberDay CTF 2020` `Volatility`
*Par Maestran - Membre de Hacktimel*
On nous donne un fichier "memoire_volatile.raw"
L'énoncé nous indique que l'on cherche :
- Le pid du processus Desktop Windows Manager
- Le nom d'un processus malveillant
- Le sha256 de ce processus qui commence par "f03df7a..."
Le flag est de la forme EFREI{PID_NOM_HASH}
J'ai utilisé l'outil Volatility afin de résoudre ce challenge, grand classique de ce type d'épreuve de forensic : https://github.com/volatilityfoundation/volatility
## 1ère étape : Recherche du profil
Afin de pouvoir chercher mes différentes informations dans ce dump de mémoire, j'ai besoin de determiner un profile volatility afin de pouvoir étudier ce dump.
J'utilise la commande *imageinfo* de volatility qui me suggère une liste de profil :
```
python vol.py -f memoire_volatile.raw imageinfo
INFO : volatility.debug : Determining profile based on KDBG search...
Suggested Profile(s) : Win7SP1x64, Win7SP0x64, Win2008R2SP0x64, Win2008R2SP1x64_24000, Win2008R2SP1x64_23418, Win2008R2SP1x64, Win7SP1x64_24000, Win7SP1x64_23418
AS Layer1 : WindowsAMD64PagedMemory (Kernel AS)
AS Layer2 : FileAddressSpace (/home/tristan/Bureau/Volatility/volatility/memoire_volatile.raw)
PAE type : No PAE
DTB : 0x187000L
KDBG : 0xf80002c420a0L
Number of Processors : 1
Image Type (Service Pack) : 1
KPCR for CPU 0 : 0xfffff80002c43d00L
KUSER_SHARED_DATA : 0xfffff78000000000L
Image date and time : 2020-06-02 20:02:03 UTC+0000
Image local date and time : 2020-06-02 16:02:03 -0400
```
Je prends le 1er profil sugéré, *Win7SP1x64*, qui est le plus récent et le plus commun.
Maintenant, à chaque fois que je vais taper une commande sous volatility, je vais utiliser l'argument *---profile=Win7SP1x64* pour préciser que j'analyse le dump avec ce profil.
## 2ème étape : Trouver le PID de Desktop Windows Manager
Une recherche google m'apprends que Desktop Windows Manager peut aussi se nommer dwm.exe (Logique), donc je vais utiliser la commande *pslist* pour me lister tous les processus en cours d'éxécution sur la machine lors du dump :
```
python vol.py -f memoire_volatile.raw --profile=Win7SP1x64 pslist
Offset(V) Name PID PPID Thds Hnds Sess Wow64 Start Exit
------------------ -------------------- ------ ------ ------ -------- ------ ------ ------------------------------ ------------------------------
0xfffffa8000b07b30 System 4 0 90 498 ------ 0 2020-06-02 19:40:18 UTC+0000
0xfffffa8002387b30 smss.exe 268 4 2 29 ------ 0 2020-06-02 19:40:18 UTC+0000
0xfffffa800249f550 csrss.exe 360 352 9 488 0 0 2020-06-02 19:40:24 UTC+0000
0xfffffa80024c8910 wininit.exe 416 352 3 74 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa80024fdb30 csrss.exe 428 408 10 291 1 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002bbab30 winlogon.exe 484 408 3 111 1 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002beead0 services.exe 520 416 9 210 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002c00b30 lsass.exe 528 416 6 575 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002c04b30 lsm.exe 536 416 11 152 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002cbcb30 svchost.exe 648 520 11 360 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002cf6b30 svchost.exe 712 520 8 309 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002d299e0 svchost.exe 764 520 25 515 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002f1f560 svchost.exe 856 520 15 312 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002f26b30 svchost.exe 884 520 46 1056 0 0 2020-06-02 19:40:26 UTC+0000
0xfffffa8002fd5b30 audiodg.exe 984 764 8 144 0 0 2020-06-02 19:40:29 UTC+0000
0xfffffa8002fee3a0 svchost.exe 304 520 12 536 0 0 2020-06-02 19:40:29 UTC+0000
0xfffffa800302a740 svchost.exe 408 520 20 396 0 0 2020-06-02 19:40:29 UTC+0000
0xfffffa8003083360 spoolsv.exe 1036 520 16 274 0 0 2020-06-02 19:40:30 UTC+0000
0xfffffa80030a0890 svchost.exe 1068 520 19 317 0 0 2020-06-02 19:40:30 UTC+0000
0xfffffa80031a8370 VGAuthService. 1236 520 3 84 0 0 2020-06-02 19:40:31 UTC+0000
0xfffffa80031cdab0 vmtoolsd.exe 1268 520 11 279 0 0 2020-06-02 19:40:31 UTC+0000
0xfffffa80032adb30 svchost.exe 1516 520 7 95 0 0 2020-06-02 19:40:34 UTC+0000
0xfffffa80033beb30 WmiPrvSE.exe 1720 648 10 268 0 0 2020-06-02 19:40:40 UTC+0000
0xfffffa8002d48340 dllhost.exe 1776 520 15 196 0 0 2020-06-02 19:40:40 UTC+0000
0xfffffa8002cab060 msdtc.exe 1864 520 14 153 0 0 2020-06-02 19:40:41 UTC+0000
0xfffffa8001875320 taskhost.exe 676 520 8 150 1 0 2020-06-02 19:40:51 UTC+0000
0xfffffa8003c5a060 sppsvc.exe 1920 520 4 149 0 0 2020-06-02 19:40:51 UTC+0000
0xfffffa8002107060 GoogleCrashHan 2180 2156 5 97 0 1 2020-06-02 19:40:52 UTC+0000
0xfffffa8003cdf060 GoogleCrashHan 2188 2156 5 90 0 0 2020-06-02 19:40:52 UTC+0000
0xfffffa80033a5060 WmiPrvSE.exe 2252 648 11 293 0 0 2020-06-02 19:41:00 UTC+0000
0xfffffa8003cb7190 dwm.exe 2512 856 3 70 1 0 2020-06-02 19:41:51 UTC+0000
0xfffffa8003c48060 explorer.exe 2536 2500 42 1049 1 0 2020-06-02 19:41:51 UTC+0000
0xfffffa8001bfcb30 vm3dservice.ex 2620 2536 2 44 1 0 2020-06-02 19:41:51 UTC+0000
0xfffffa8003cf4b30 vmtoolsd.exe 2636 2536 8 154 1 0 2020-06-02 19:41:51 UTC+0000
0xfffffa8003cf4060 sidebar.exe 2644 2536 10 244 1 0 2020-06-02 19:41:51 UTC+0000
0xfffffa8000cd4b30 SearchIndexer. 2892 520 13 694 0 0 2020-06-02 19:41:57 UTC+0000
0xfffffa8002a73060 svchost.exe 1392 520 16 250 0 0 2020-06-02 19:42:33 UTC+0000
0xfffffa8000db0270 svchost.exe 920 520 14 337 0 0 2020-06-02 19:42:33 UTC+0000
0xfffffa80033e9b30 WmiApSrv.exe 1656 520 6 113 0 0 2020-06-02 19:43:04 UTC+0000
0xfffffa8000ce0060 notepad.exe 1472 2536 6 236 1 0 2020-06-02 19:43:32 UTC+0000
0xfffffa8000b68520 spkl.exe 1800 2536 6 249 1 1 2020-06-02 19:45:37 UTC+0000
0xfffffa8000de6060 dllhost.exe 1512 648 9 211 1 0 2020-06-02 19:45:42 UTC+0000
0xfffffa8000e9c380 spmm.exe 2940 1800 1 90 1 1 2020-06-02 19:45:44 UTC+0000
0xfffffa8000e0eb30 wmplayer.exe 2312 648 21 555 1 1 2020-06-02 19:45:47 UTC+0000
0xfffffa8000fa7060 Sonic Visualis 3032 2536 11 218 1 0 2020-06-02 19:45:50 UTC+0000
0xfffffa8000fef060 cmd.exe 1396 2536 1 19 1 0 2020-06-02 19:46:10 UTC+0000
0xfffffa8000f3b060 conhost.exe 2588 428 2 50 1 0 2020-06-02 19:46:10 UTC+0000
0xfffffa8000ff5580 taskmgr.exe 2296 2536 6 118 1 0 2020-06-02 19:46:20 UTC+0000
0xfffffa8000dce060 SearchProtocol 928 2892 8 318 0 0 2020-06-02 19:56:39 UTC+0000
0xfffffa8000fd7060 SearchFilterHo 748 2892 5 98 0 0 2020-06-02 19:56:40 UTC+0000
0xfffffa8002fe4060 cmd.exe 3004 1268 0 -------- 0 0 2020-06-02 20:02:03 UTC+0000 2020-06-02 20:02:03 UTC+0000
0xfffffa800306d760 conhost.exe 2680 360 0 -------- 0 0 2020-06-02 20:02:03 UTC+0000 2020-06-02 20:02:03 UTC+0000
0xfffffa80010bc9e0 ipconfig.exe 2556 3004 0 -------- 0 0 2020-06-02 20:02:03 UTC+0000 2020-06-02 20:02:03 UTC+0000
```
Un petit grep me donne la ligne que je cherche :
```
0xfffffa8003cb7190 dwm.exe 2512 856 3 70 1 0 2020-06-02 19:41:51 UTC+0000
```
Le PID du processus est donc 2512
## 3ème étape : Trouver le processus malveillant :
Je pourrais rester regarder les processus avec *pslist*, cependant, je préfère utiliser *pstree*, qui donne un arbre montrant les relations père/fils entre chaque processus :
```
python vol.py -f memoire_volatile.raw --profile=Win7SP1x64 pstree
Name Pid PPid Thds Hnds Time
-------------------------------------------------- ------ ------ ------ ------ ----
0xfffffa80024c8910:wininit.exe 416 352 3 74 2020-06-02 19:40:26 UTC+0000
. 0xfffffa8002c00b30:lsass.exe 528 416 6 575 2020-06-02 19:40:26 UTC+0000
. 0xfffffa8002beead0:services.exe 520 416 9 210 2020-06-02 19:40:26 UTC+0000
.. 0xfffffa8003c5a060:sppsvc.exe 1920 520 4 149 2020-06-02 19:40:51 UTC+0000
.. 0xfffffa8002cbcb30:svchost.exe 648 520 11 360 2020-06-02 19:40:26 UTC+0000
... 0xfffffa80033beb30:WmiPrvSE.exe 1720 648 10 268 2020-06-02 19:40:40 UTC+0000
... 0xfffffa8000e0eb30:wmplayer.exe 2312 648 21 555 2020-06-02 19:45:47 UTC+0000
... 0xfffffa80033a5060:WmiPrvSE.exe 2252 648 11 293 2020-06-02 19:41:00 UTC+0000
... 0xfffffa8000de6060:dllhost.exe 1512 648 9 211 2020-06-02 19:45:42 UTC+0000
.. 0xfffffa80030a0890:svchost.exe 1068 520 19 317 2020-06-02 19:40:30 UTC+0000
.. 0xfffffa8002f1f560:svchost.exe 856 520 15 312 2020-06-02 19:40:26 UTC+0000
... 0xfffffa8003cb7190:dwm.exe 2512 856 3 70 2020-06-02 19:41:51 UTC+0000
.. 0xfffffa800302a740:svchost.exe 408 520 20 396 2020-06-02 19:40:29 UTC+0000
... 0xfffffa80024fdb30:csrss.exe 428 408 10 291 2020-06-02 19:40:26 UTC+0000
.... 0xfffffa8000f3b060:conhost.exe 2588 428 2 50 2020-06-02 19:46:10 UTC+0000
... 0xfffffa8002bbab30:winlogon.exe 484 408 3 111 2020-06-02 19:40:26 UTC+0000
.. 0xfffffa8002a73060:svchost.exe 1392 520 16 250 2020-06-02 19:42:33 UTC+0000
.. 0xfffffa8001875320:taskhost.exe 676 520 8 150 2020-06-02 19:40:51 UTC+0000
.. 0xfffffa8002fee3a0:svchost.exe 304 520 12 536 2020-06-02 19:40:29 UTC+0000
.. 0xfffffa80031cdab0:vmtoolsd.exe 1268 520 11 279 2020-06-02 19:40:31 UTC+0000
... 0xfffffa8002fe4060:cmd.exe 3004 1268 0 ------ 2020-06-02 20:02:03 UTC+0000
.... 0xfffffa80010bc9e0:ipconfig.exe 2556 3004 0 ------ 2020-06-02 20:02:03 UTC+0000
.. 0xfffffa8000db0270:svchost.exe 920 520 14 337 2020-06-02 19:42:33 UTC+0000
.. 0xfffffa8002cf6b30:svchost.exe 712 520 8 309 2020-06-02 19:40:26 UTC+0000
.. 0xfffffa8003083360:spoolsv.exe 1036 520 16 274 2020-06-02 19:40:30 UTC+0000
.. 0xfffffa80031a8370:VGAuthService. 1236 520 3 84 2020-06-02 19:40:31 UTC+0000
.. 0xfffffa8000cd4b30:SearchIndexer. 2892 520 13 694 2020-06-02 19:41:57 UTC+0000
... 0xfffffa8000dce060:SearchProtocol 928 2892 8 318 2020-06-02 19:56:39 UTC+0000
... 0xfffffa8000fd7060:SearchFilterHo 748 2892 5 98 2020-06-02 19:56:40 UTC+0000
.. 0xfffffa80032adb30:svchost.exe 1516 520 7 95 2020-06-02 19:40:34 UTC+0000
.. 0xfffffa8002d48340:dllhost.exe 1776 520 15 196 2020-06-02 19:40:40 UTC+0000
.. 0xfffffa8002cab060:msdtc.exe 1864 520 14 153 2020-06-02 19:40:41 UTC+0000
.. 0xfffffa8002f26b30:svchost.exe 884 520 46 1056 2020-06-02 19:40:26 UTC+0000
.. 0xfffffa80033e9b30:WmiApSrv.exe 1656 520 6 113 2020-06-02 19:43:04 UTC+0000
.. 0xfffffa8002d299e0:svchost.exe 764 520 25 515 2020-06-02 19:40:26 UTC+0000
... 0xfffffa8002fd5b30:audiodg.exe 984 764 8 144 2020-06-02 19:40:29 UTC+0000
. 0xfffffa8002c04b30:lsm.exe 536 416 11 152 2020-06-02 19:40:26 UTC+0000
0xfffffa800249f550:csrss.exe 360 352 9 488 2020-06-02 19:40:24 UTC+0000
. 0xfffffa800306d760:conhost.exe 2680 360 0 ------ 2020-06-02 20:02:03 UTC+0000
0xfffffa8003c48060:explorer.exe 2536 2500 42 1049 2020-06-02 19:41:51 UTC+0000
. 0xfffffa8000ce0060:notepad.exe 1472 2536 6 236 2020-06-02 19:43:32 UTC+0000
. 0xfffffa8000b68520:spkl.exe 1800 2536 6 249 2020-06-02 19:45:37 UTC+0000
.. 0xfffffa8000e9c380:spmm.exe 2940 1800 1 90 2020-06-02 19:45:44 UTC+0000
. 0xfffffa8000fa7060:Sonic Visualis 3032 2536 11 218 2020-06-02 19:45:50 UTC+0000
. 0xfffffa8001bfcb30:vm3dservice.ex 2620 2536 2 44 2020-06-02 19:41:51 UTC+0000
. 0xfffffa8003cf4b30:vmtoolsd.exe 2636 2536 8 154 2020-06-02 19:41:51 UTC+0000
. 0xfffffa8000ff5580:taskmgr.exe 2296 2536 6 118 2020-06-02 19:46:20 UTC+0000
. 0xfffffa8000fef060:cmd.exe 1396 2536 1 19 2020-06-02 19:46:10 UTC+0000
. 0xfffffa8003cf4060:sidebar.exe 2644 2536 10 244 2020-06-02 19:41:51 UTC+0000
0xfffffa8000b07b30:System 4 0 90 498 2020-06-02 19:40:18 UTC+0000
. 0xfffffa8002387b30:smss.exe 268 4 2 29 2020-06-02 19:40:18 UTC+0000
0xfffffa8002107060:GoogleCrashHan 2180 2156 5 97 2020-06-02 19:40:52 UTC+0000
0xfffffa8003cdf060:GoogleCrashHan 2188 2156 5 90 2020-06-02 19:40:52 UTC+0000
```
Je n'ai pas spécialement de bonne méthode pour trouver un processus malveillant hormis ces deux la :
- Chercher tous les processus qui ont lancé un conhost.exe / cmd.exe (Une ligne de commande, très suspect)
- Chercher un processus avec un nom chelou en partant de la fin en regardant chaque processus sur google.
Rapidement, je tombe sur **spkl.exe** et **spmm.exe** qui m'interpellent, spmm me faisant penser à spam, je me dis que j'ai peut-être une piste ici.
Je tape spmm.exe sur mon moteur de recherche favori, et je vois dès mes 1ers résultats des liens vers des sites comme virustotal.com ou threatinfo.net, je me dis que je dois être sur le bon chemin.
De toute manière, je sais que l'étape suivant confirmera mes doutes.
## 4ème étape : Extraire ce processus et obtenir son hash
Je crée d'abord un dossier pour extraire mon éxecutable :
```
mkdir output
```
Puis, j'extraie l'éxecutable de ce processus avec *procdump* en utilisant le PID de spmm.exe (2940) :
```
python vol.py -f memoire_volatile.raw --profile=Win7SP1x64 procdump -p 2940 -D output/
Process(V) ImageBase Name Result
------------------ ------------------ -------------------- ------
0xfffffa8000e9c380 0x0000000000400000 spmm.exe OK: executable.2940.exe
```
Puis, je calcule le sha256 :
```
sha256sum output/executable.2940.exe
f03df7a5c6ea31ecfac016c84ade902587024a473ceac0c8070cef3eb900a2d5 output/executable.2940.exe
```
Le sha256 est bien correct avec ce qui est demandé dans l'ennoncé ! J'avais raison de suspecter ce fichier.
## Reconstitution du flag :
Étape 1 : 2512
Étape 2 : spmm.exe
Étape 3 : f03df7a5c6ea31ecfac016c84ade902587024a473ceac0c8070cef3eb900a2d5
Le flag est donc:
EFREI{2512_spmm.exe_f03df7a5c6ea31ecfac016c84ade902587024a473ceac0c8070cef3eb900a2d5}
Merci à SQUAD et Efrei Paris pour ce CTF