HackTheBox頑張る その26 ~特権昇格について1
過去のWriteUp確認で、ある方が特権昇格についてまとめていたので、
内容を見ていって学ぶことにします。
参考:
linux privilege escalation basics :: xorond's blog for security stuff
システム情報
hostname # hostname whoami # current user ip a # show ip address ifconfig -a # show ip address cat /etc/*issue # linux distribution cat /etc/*release # linux distribution uname -a # hostname, kernel version, cpu architecture (32-bit vs. 64-bit) dmesg | head -n1 # hostname,kernel version, cpu arch (if uname doesn't exist) cat /etc/resolv.conf # dns information ip r # route information cat /etc/network/interfaces # show network config cat /etc/sysconfig/network # show network config iptables -xvL # show firewall rules netstat -antpl # show current network connections and opened ports on the machine ss -antpl # if 'netstat' doesn't exist
ネットワーク系が多い。実際のペネトレでは重要な情報か。
ユーザ情報
whoami # who am i? id # groups last # last logins w # who's logged in? who -a # who's logged in? cat /etc/passwd # take a look here for any hashes or interesting users cat /etc/passwd | cut -d':' -f1 # list all users cat /etc/passwd | grep -vE "(nologin|false)" # only print out users with shell access umask -S && umask # current umask values echo $HOME # home directory ls -alR $HOME # what's inside our $HOME? cat ~/.bash_history # bash history cat ~/.zhistory # zsh history cat ~/.nano_history # nano history cat ~/.mysql_history # mysql history cat /etc/shadow # unlikely but worth a shot ls -al /etc/passwd # check if we can write there
umaskについて知らなかったのですが、以下のようです
umaskコマンドについて詳しくまとめました 【Linuxコマンド集】
ファイルを新規作成するときに、権限を変更することができるマスク
特権アクセス
cat /etc/sudoers # can we read? which users have sudo privileges? sudo -l # can we use sudo? do we need a password? ls -al /root # can we read /root? ls -alR /home # check permissions for /home directories
sudo -lしてPW聞かれなければ、特権昇格できるとして、
前回も書いたGTFObinsの紹介がなされていた、次回はこのツールを確認したい
GTFOBins
環境変数
echo $PATH # current value of PATH env # display environment information
環境変数にキーやパスワードがあったり、隠れたbinファイルをPATHで見つけたり。
cronやtask
|
crontab -l # cron jobs for this user
ls -alR /etc/cron* # show all cronjob files
cat /etc/crontab # read main crontab file
実行したいスクリプトを、root権限で実行したりできるかも? * 実行中プロセス・サービス確認 >|| netstat -antp # which ports are services exposing? ps aux # list all processes ps aux | grep root # list all processes running as root top # show processes
バージョン情報確認
dpkg -l # (Debian/Ubuntu variants) show installed packages and versions rpm -qa # (CentOS/RHEL) show installed packages and versions pacman -Q # (Archlinux) show installed packages and versions sudo -V # sudo version
etc配下のconfファイルにあるpassword文字列列挙
grep -Ri password $(find /etc -name '*.conf' 2>/dev/null) # search conf files in /etc for passwords さらに次のフォルダも確認 /home /var/log /opt /var/www 拡張子 php cfg inc log txt ini 確認文字列 pass: username passphrase
これらに加え、grepの前後を-C 2とかでとると、PW文字列っぽいものをひっかけたりできるかも。
また、例えば上記で取得できたPWがmysqlだったら
mysql -uroot -pPASSWORD # check if you can login to mysql with PASSWORD
として試してみる
SUID/GUIDに関する情報
find / -writable -type d 2>/dev/null # show writable folders find / -writable -type f 2>/dev/null # show writable files find / -perm -4000 -type f 2>/dev/null # search system for suid files find / -perm -u=s -type f 2>/dev/null # search system for suid files getcap -r / # get capabilities of binaries
正直SUID/GUIDの部分について理解が浅いので、別記事でお勉強したいところです・・・
記事はもう少し続くので、また次回!