Solution du challenge SSTIC 2015

Solution du challenge SSTIC 2015

Guillaume Kania 25 avril 2015

1

Table des mati?res

1 Introduction

3

2 Stage 1

3

2.1 Analyse de la carte microSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 Ducky decode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.3 Extraction du PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Stage 2

6

3.1 Recherche de la cl? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3.2 D?chiffrement du stage3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 Stage 3

7

4.1 Analyse de la capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4.2 D?chiffrement Serpent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5 Stage 4

11

5.1 D?sobfuscation du code javascript . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.2 Brute force du User-Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

6 Stage 5

15

6.1 Analyse de l'assembleur ST20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

6.2 Recherche de la cl? de chiffrement . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

7 Stage 6

24

7.1 congratulations.jpg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

7.2 congratulations.png . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

7.3 congratulations.tiff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

7.4 congratulations.gif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

8 Conclusion

26

2

1 Introduction

Comme tous les ans depuis 2009, la conf?rence SSTIC organise un challenge de s?curit? informatique. L'objectif est toujours le m?me, d?couvrir une adresse e-mail de la forme ....@challenge. en analysant un fichier fourni. Le pr?sent document a pour objectif de d?crire une des d?marches possibles afin de r?soudre les diff?rentes ?preuves composant le challenge et parvenir, in fine, a r?cup?rer l'adresse e-mail cach?e.

2 Stage 1

2.1 Analyse de la carte microSD

Tout commence par la r?cup?ration du fichier :

$ wget http :// s t a t i c . s s t i c . org/ challenge2015 / challenge . zip

L'?nonc? indique que le d?fi consiste ? analyser la carte microSD qui ?tait ins?r?e dans une cl? USB ?trange. Apr?s la v?rification du sha256 et la d?compression du fichier, un file nous indique effectivement que le fichier correspond au format attendu.

$ sha256sum challenge . zip bd0df75a1d6591e01212e6e28848aec94b514e17e4ac26155696a9a76ab2ea31

. zip $ unzip challenge . zip Archive : challenge . zip

i n f l a t i n g : sdcard . img $ f i l e sdcard . img sdcard . img : x86 boot s e c t o r

challenge

Un passage de l'outil fls de sleuthkit sur l'image de la carte identifie deux fichiers : inject.bin et build.sh. Le dernier semble avoir ?t? effac? du syst?me de fichier.

$ f l s sdcard . img

r/r 4:

build . sh

r/r 6: inject . bin

v/v 3 9 9 2 1 7 9 : $MBR

v/v 3 9 9 2 1 8 0 : $FAT1

v/v 3 9 9 2 1 8 1 : $FAT2

d/d 3992182:

$OrphanFiles

Le fichier inject.bin peut ?tre r?cup?r? en montant l'image. Cependant, ayant besoin de restaurer un fichier effac?, l'utilisation de icat sur les deux inodes est rapide et efficace.

$ i c a t sdcard . img 4 > build . sh $ cat build . sh j a v a -j a r e n c o d e r . j a r -i /tmp/ d u c k y s c r i p t . t x t $ i c a t sdcard . img 4 > build . sh $ i c a t sdcard . img 6 > i n j e c t . bin

2.2 Ducky decode

Le fichier texte inject.bin ne semble pas poss?der un format en particulier. L'int?ret se porte alors sur le fichier build.sh. Apr?s quelques recherches sur internet de la chaine duckyscript, il devient ?vident que le fichier binaire est un script ducky compil? pour une cl? USB Rubber Ducky. Rapidement, un script ducky-decode.pl 1 permettant de d?coder le fichier est trouv?.

$ ducky-decode . p l -f i n j e c t . b i n > ducky-decoded . t x t

1. https ://midnitesnake/USB-Rubber-Ducky

3

Une fois d?cod?, le script ducky correspond ? un nombre important de chunks de code powershell encod?s en base64.

00 f f 007d GUI R

DELAY 500

ENTER

DELAY 1000 cmd

ENTER

DELAY 50 powe r s h e l l

SPACE -e n c

SPACE Z g B 1 AG 4 AYwB 0 AG k A b wB u ACAA d wB y AG k A d AB l AF

8 AZ g B p AGwAZQB f AG I A e QB 0 AGUA c wB 7 AHAAYQ B y AGEA b QA o AF s AQ g B 5 AHQAZQB b AF 0 AXQA g AC Q A Z g B p A G w A Z Q B f A G I A e Q B 0 A G U A c w A s A C A AWw B z A H . . . f Q A = 00a0

ENTER powe r s h e l l

SPACE -e n c

SPACE

2.3 Extraction du PowerShell

L'?criture d'un petit script python permet d'extraire rapidement le code powershell et de d?coder le base64.

1 import sys

2 import re

3 from base64 import b64decode

4

5 data = open(sys.argv[1]).read()

6 rex = pile(r"- e n c \x0aSPACE (.*?) = 00a0 \x0aENTER",re.DOTALL)

7

8 match = rex.findall(data)

9 out = ""

10 i = 0

11 for g in match :

12

g = g.replace(" ","")

13

g = g.replace("\x0a","")

14

l = len(g)

15

if(l%4 != 0):

16

g += "="*(4-(l%4))

17

out += b64decode(g)

18 open ( sys . argv [2] , " w " ) . write ( out . decode ( " utf -16 " ) )

Execution du script :

$ python e x t r a c t -p o w e r s h e l l . py ducky-decoded . t x t e x t r a c t e d -p o w e r s h e l l . t x t $ cat extracted -powershelgl

4

func tion write_file_bytes {param ( [ Byte [ ] ] $file_bytes , [ s t r i n g ] $file_path = ".\ stage2 . zip ") ; $f = [ io . f i l e ] : : OpenWrite ( $file_path ) ; $f . Seek ( $f . Length

,0) ; $f . Write ( $file_bytes ,0 , $file_bytes . Length ) ; $f . Close () ;} function check_correct_environment{$e=[Environment ] : : CurrentDirectory . s p l i t ("\") ; $e=$e [ $e . Length -1]+[ Environment ] : : UserName ; $e -eq " c h a l l e n g e 2 0 1 5 s s t i c " ; } i f ( check_correct_environment ){write_file_bytes ([ Convert ] : : FromBase64String ( 'UEsDB . . . zWnXw==') ) ; } e l s e { w r i t e _ f i l e _ b y t e s ( [ Convert ] : : FromBase64String ( 'VAByAHkASABhAHIAZABlAHIA' ) ) ; }

func tion write_file_bytes {param ( [ Byte [ ] ] $file_bytes , [ s t r i n g ] $file_path = ".\ stage2 . zip ") ; $f = [ io . f i l e ] : : OpenWrite ( $file_path ) ; $f . Seek ( $f . Length

,0) ; $f . Write ( $file_bytes ,0 , $file_bytes . Length ) ; $f . Close () ;} function check_correct_environment{$e=[Environment ] : : CurrentDirectory . s p l i t ("\") ; $e=$e [ $e . Length -1]+[ Environment ] : : UserName ; $e -eq " c h a l l e n g e 2 0 1 5 s s t i c " ; } i f ( check_correct_environment ){write_file_bytes ([ Convert ] : : FromBase64String ( '9 Le + . . . scjw ==') ) ; } e l s e { wr i te _f il e_ b yt es ( [ Convert ] : : FromBase64String ( 'VAByAHkASABhAHIAZABlAHIA' ) ) ; }

f u n c t i o n h a s h _ f i l e {param ( [ s t r i n g ] $ f i l e p a t h ) ; $sha1 = New-Object -TypeName System . Security . Cryptography . SHA1CryptoServiceProvider ; $h = [ System . BitConverter ] : : ToString ( $sha1 . ComputeHash ( [ System . IO . F i l e ] : : ReadAllBytes ( $ f i l e p a t h ) ) ) ; $h}$h = h a s h _ f i l e ( " . \ s t a g e 2 . z i p " ) ; i f ( $h -eq "EA-9B-8A-6F-5 B-52-7E-72-65-20-19-31-3C-25-B5-6A-D2-7C-7E-C6" ) { echo "You WIN" ; } e l s e { echo "You LOSE" ; }

La logique du code est simple : si la variable d'environnement UserName est ?gale ? challenge2015sstic alors une chaine en base64 est d?cod?e puis ?crite dans le fichier stage2.zip. Dans le cas contraire, c'est une autre chaine en base64 qui est d?cod?e puis ?crite. Cette derni?re, d?cod?e, correspond en r?alit? ? la chaine TryHarder. Si le SHA1, calcul? sur le fichier stage2.zip, est ?gal ? EA9B8A6F5B527E72652019313C25B56AD27C7EC6 alors le script affiche "You WIN" sinon "You LOSE". De la m?me fa?on que pour l'extraction du script powershell, il est possible de r?cup?rer le fichier stage2.zip via un petit script python.

1 import sys

2 import re

3 from base64 import b64decode

4

5 data = open(sys.argv[1]).read()

6 rex = pile(r"if\( check_correct_environment \)\{write_file_bytes

\(\[ Convert \]\:\: FromBase64String \(\ '(.*?)\'",re.DOTALL)

7 match = rex.findall(data)

8 out = ""

9 i=0

10 for g in match :

11

out += b64decode(g)

12 open ( sys . argv [2] , " w " ) . write ( out )

$ python extract -stage2 . py extracted -powershell . txt stage2 . zip $ sha1sum stage2 . zip ea9b8a6f5b527e72652019313c25b56ad27c7ec6 stage2 . zip

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download