> For the complete documentation index, see [llms.txt](https://book.onosh.ovh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.onosh.ovh/ctf/breizhctf2022/des-deux-cotes-1-2.md).

# Des deux côtés 1/2

### Contexte

**Catégorie** : Forensic

**Points** : 500

**Auteur** : <https://twitter.com/_worty>

Voir les deux côtés de quelque chose, c'est toujours bon non?

Vous êtes une APT et un de vos collègues a volé une machine chez une entreprise du CAC40, malheureusement, celle-ci ne veut plus démarrer.. Votre collègue étant un hacker en herbe, il a pensé à faire un dump mémoire avant que la machine rende l'âme !

Retrouvez le fichier qui contient des données confidentielles dans ce dump mémoire !

### Début de l'analyse

* On a un dump mémoire "memory.dmp" de 1.1Go (=volatility)
* On cherche un fichier avec des données confidentielles
* La machine volée est une Windows et plus précisément une Win7SP1x86\_23418 :&#x20;

```
file memory.dmp
memory.dmp: MS Windows 32bit crash dump, PAE, full dump, 262144 pages

python volatility/vol.py -f memory.dmp imageinfo
Volatility Foundation Volatility Framework 2.6.1
INFO    : volatility.debug    : Determining profile based on KDBG search...
Suggested Profile(s) : Win7SP1x86_23418, Win7SP0x86, Win7SP1x86_24000, Win7SP1x86 (Instantiated with WinXPSP2x86)
 AS Layer1 : IA32PagedMemoryPae (Kernel AS)
 AS Layer2 : WindowsCrashDumpSpace32 (Unnamed AS)
 AS Layer3 : FileAddressSpace (/mnt/v/BZHCTF/FOFO/memory.dmp)
 PAE type : PAE
 DTB : 0x185000L
 KUSER_SHARED_DATA : 0xffdf0000L
 Image date and time : 2022-02-23 19:29:05 UTC+0000
 Image local date and time : 2022-02-23 11:29:05 -0800
```

### Recherche du fichier secret

Maintenant que nous avons notre profil volatility, nous pouvons pousser nos recherches et lister l'ensemble des fichiers connus de la mémoire via le plugin filescan.

```
python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 filescan |tee filescan.txt
```

Je pars de l'hypothèse que le fichier confidentiel en question se trouve dans l'espace perso de la victime, et effectivement, on en trouve 2 :&#x20;

* Employe Secret.txt
* Resultat Entretien 2021.txt

```
cat filescan.txt |grep Users
...
0x000000003ea68308      8      0 R--rw- \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential\Employe Secret.txt
0x000000003f17b1e8      1      1 R--rw- \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential
0x000000003f1a3f80      1      1 R--rw- \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential
0x000000003fd0af80      8      0 R--rw- \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential\Resultat Entretien 2021.txt
...
```

### Extraction des fichiers

Après avoir trouvé les fichiers, on imagine qu'il ne reste plus qu'a les extraire... mais malheureusement, le contenu des fichiers n'est pas récupérable.

```
python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 dumpfiles -Q 0x000000003ea68308 --name 'Employe Secret.txt' -D output/
DataSectionObject 0x3ea68308   None   \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential\Employe Secret.txt

python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 dumpfiles -Q 0x000000003fd0af80 --name 'Resultat Entretien 2021.txt' -D output/
DataSectionObject 0x3fd0af80   None   \Device\HarddiskVolume1\Users\Daniel\Documents\RH-Documents\Confidential\Resultat Entretien 2021.txt

ls output/
```

### Recherche d'un processus

Seul moyen pour retrouver le contenu des fichiers, chercher un processus qui les utilisent. Le plugin pslist nous aide à identifier les différents processus en fonctionnement sur le système.

notepad.exe semble être intéressant à vérifier car il est souvent utilisé pour ouvrir les fichiers .txt

* PID 3232
* PID 3732   &#x20;

```
python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 pslist
Volatility Foundation Volatility Framework 2.6.1
Offset(V)  Name                    PID   PPID   Thds     Hnds   Sess  Wow64 Start                          Exit
---------- -------------------- ------ ------ ------ -------- ------ ------ ------------------------------ ------------------------------
0x84133270 System                    4      0     77      511 ------      0 2022-02-23 18:09:02 UTC+0000
0x854f4020 smss.exe                224      4      2       29 ------      0 2022-02-23 18:09:02 UTC+0000
0x85748030 csrss.exe               304    296      9      338      0      0 2022-02-23 18:09:03 UTC+0000
0x85b9bd40 wininit.exe             340    296      3       75      0      0 2022-02-23 18:09:03 UTC+0000
0x85b9c578 csrss.exe               352    332      9      209      1      0 2022-02-23 18:09:03 UTC+0000
0x85c23d40 winlogon.exe            392    332      5      130      1      0 2022-02-23 18:09:04 UTC+0000
0x85cac030 services.exe            444    340      7      196      0      0 2022-02-23 18:09:04 UTC+0000
0x85cba2d8 lsass.exe               452    340      6      558      0      0 2022-02-23 18:09:04 UTC+0000
0x85cbc620 lsm.exe                 468    340      9      141      0      0 2022-02-23 18:09:04 UTC+0000
0x85f2bc08 svchost.exe             576    444      9      353      0      0 2022-02-23 18:09:04 UTC+0000
0x85f3d030 svchost.exe             636    444      7      250      0      0 2022-02-23 18:09:05 UTC+0000
0x854f3668 sppsvc.exe              860    444      4      147      0      0 2022-02-24 03:09:07 UTC+0000
0x84c07030 svchost.exe             900    444     14      314      0      0 2022-02-24 03:09:08 UTC+0000
0x84c08800 svchost.exe             924    444     40     1256      0      0 2022-02-24 03:09:08 UTC+0000
0x84c8d030 svchost.exe             972    444     19      450      0      0 2022-02-24 03:09:08 UTC+0000
0x84cc6030 audiodg.exe            1004    972      4      121      0      0 2022-02-24 03:09:08 UTC+0000
0x85aa6810 svchost.exe            1044    444     10      265      0      0 2022-02-24 03:09:09 UTC+0000
0x84cd8410 svchost.exe            1068    444     19      490      0      0 2022-02-24 03:09:09 UTC+0000
0x84d04d40 TrustedInstall         1180    444      6      261      0      0 2022-02-24 03:09:10 UTC+0000
0x85f9b030 spoolsv.exe            1340    444     12      293      0      0 2022-02-24 03:09:10 UTC+0000
0x85fe0030 svchost.exe            1380    444     19      315      0      0 2022-02-24 03:09:10 UTC+0000
0x85550718 svchost.exe            1692    444      6       94      0      0 2022-02-24 03:09:11 UTC+0000
0x84e3e4d0 taskhost.exe            772    444      8      208      1      0 2022-02-24 03:09:17 UTC+0000
0x84c7ac88 dwm.exe                 848    900      3       71      1      0 2022-02-24 03:09:17 UTC+0000
0x84c7f9d8 explorer.exe            880    756     32      881      1      0 2022-02-24 03:09:17 UTC+0000
0x84e79508 regsvr32.exe           1864    880      0 --------      1      0 2022-02-24 03:10:06 UTC+0000   2022-02-24 03:10:07 UTC+0000
0x85fc0030 svchost.exe            1868    444     11      144      0      0 2022-02-24 03:11:11 UTC+0000
0x84dde0b0 svchost.exe            1724    444      9      311      0      0 2022-02-24 03:11:11 UTC+0000
0x8430dc38 msiexec.exe            3820    444      6      305      0      0 2022-02-23 19:18:52 UTC+0000
0x8545d368 armsvc.exe             2660    444      6      244      0      0 2022-02-23 19:19:17 UTC+0000
0x842a3168 SearchIndexer.         3268    444     11      522      0      0 2022-02-23 19:19:24 UTC+0000
0x84356ca8 AdobeARMHelper         2484   2660      0 --------      0      0 2022-02-23 19:20:53 UTC+0000   2022-02-23 19:20:54 UTC+0000
0x85ee3d40 firefox.exe            2360    816      0 --------      1      0 2022-02-23 19:24:17 UTC+0000   2022-02-23 19:24:39 UTC+0000
0x84e17570 RH-Appli-Conne         3936    880      1       36      1      0 2022-02-23 19:24:45 UTC+0000
0x843485b0 RH-Appli-Conne         1668    880      3       94      1      0 2022-02-23 19:25:07 UTC+0000
0x84273030 cmd.exe                1472   1668      0 --------      1      0 2022-02-23 19:25:24 UTC+0000   2022-02-23 19:25:27 UTC+0000
0x8549b108 WMIADAP.exe            1152    924      5       86      0      0 2022-02-23 19:27:21 UTC+0000
0x84283830 WmiPrvSE.exe           3072    576      8      115      0      0 2022-02-23 19:27:21 UTC+0000
0x84f7e630 notepad.exe            3232    880      1       63      1      0 2022-02-23 19:27:43 UTC+0000
0x86081218 notepad.exe            3732    880      1       63      1      0 2022-02-23 19:27:46 UTC+0000
0x84f3cd40 RH-Appli-Conne         3540    880      1       20      1      0 2022-02-23 19:27:54 UTC+0000
0x842ef7e0 RH-Appli-Conne         3504    880      5       99      1      0 2022-02-23 19:28:06 UTC+0000
0x84da8938 cmd.exe                2404   3504      0 --------      1      0 2022-02-23 19:28:10 UTC+0000   2022-02-23 19:28:12 UTC+0000
```

Le plugin cmdline permet de confirmer cette hypothèse :&#x20;

```
python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 cmdline |grep -A1 -B1 notepad
************************************************************************
notepad.exe pid:   3232
Command line : "C:\Windows\system32\NOTEPAD.EXE" C:\Users\Daniel\Documents\RH-Documents\Confidential\Resultat Entretien 2021.txt
************************************************************************
notepad.exe pid:   3732
Command line : "C:\Windows\system32\NOTEPAD.EXE" C:\Users\Daniel\Documents\RH-Documents\Confidential\Employe Secret.txt
```

### Dump des processus

Je dump le premier process (pid=3232) associé à notepad.exe :&#x20;

{% hint style="info" %}

```
Le vidage mémoire (plugin memdump) d'un processus extraira tout de l'état actuel du processus. Le plugin procdump ne fera qu'extraire le code.
```

{% endhint %}

```
python volatility/vol.py -f memory.dmp --profile=Win7SP1x86_23418 memdump -p 3232 -D output/
************************************************************************
Writing notepad.exe [  3232] to 3232.dmp

file output/3232.dmp
output/3232.dmp: DOS executable (COM, 0x8C-variant)

du -h output/3232.dmp
157M    output/3232.dmp
```

### Flag !

Après un gros strings/grep sur 'BZHCTF', on ne récupère rien... j'essaye BZHCTF en base64 soit : *QlpIQ1RG*

On récupère un message indiquant l'arrivée d'un employé ainsi que sa signature, qui est en réalité notre flag : **BZHCTF{fr33\_cr3d3nti4ls}**

```
strings output/3232.dmp |grep -i -A10 -B10 'QlpIQ1RG'
f\,)
f\,)
f\,)
f\,)
Le nouvel employ
, Matthieu Delkique va nous rejoindre (ouf !)
Ses identifiants de connexion seront :
m.delkique@vulncorp.fr/MatthieuVulnCorp123!
Attenion
 bien lui fournir sa signature :
QlpIQ1RGe2ZyMzNfY3IzZDNudGk0bHN9Cg==
FILE0
FILE0
FILE0
FILE0
FILE0
FILE0
FILE0
FILE0
FILE0
FILE0
```

### Bonus :race\_car:

Il était possible de flag juste via strings/grep :&#x20;

```
strings -el memory.dmp |grep -A5 -B5 'QlpIQ1RG'

, Matthieu Delkique va nous rejoindre (ouf !)
Ses identifiants de connexion seront :
m.delkique@vulncorp.fr/MatthieuVulnCorp123!
Attenion
 bien lui fournir sa signature :
QlpIQ1RGe2ZyMzNfY3IzZDNudGk0bHN9Cg==
 oye Secret.txt
.txt
Fran
ais (France)
\Win
^C
```

### &#x20;
