ClickOnce certificate-trust bootstrap
A Windows PE extracts its own embedded Authenticode signature and installs the publisher certificate into the
TrustedPublisherstore before usingdfshim.dll!ShOpenVerbApplicationWto silently launch a remote ClickOnce.applicationmanifest.
What the technique does
ClickOnce is a Microsoft application-deployment technology that allows applications to be published to a web server and then installed/launched via a URL ending in .application. By default, ClickOnce warns users if the publisher is unknown. This technique pre-emptively trusts the publisher by extracting the signer's certificate from the PE's own signature and adding it to the TrustedPublisher certificate store, then immediately invoking dfshim to fetch the payload. The result: zero user prompts, zero SmartScreen blocks, and a fully signed malware deployment chain.
Detection / fingerprint
- Imports
CRYPT32.dlland callsCertOpenSystemStoreAwith string"TrustedPublisher"or"ROOT" - Calls
CryptQueryObjecton the running module file (obtained viaGetModuleFileNameW) - Calls
CertAddCertificateContextToStoreorCertAddEncodedCertificateToStore - Loads
dfshim.dlland resolvesShOpenVerbApplicationW - Command-line or URL contains
.application?h=orScreenConnect.Client.application - No direct WinINet/WinHTTP/CURL imports; all HTTP traffic is generated by
dfshim.dllchild processes
Implementation patterns observed
Sample: connectwise 81adbf9a — MSVC C++ PE32, 305 KB, valid Authenticode by ConnectWise, LLC.
- Self-path resolution:
GetModuleFileNameW(NULL, buf, MAX_PATH)^[raw/analyses/81adbf9a/report.md] - Store open:
CertOpenSystemStoreA(0, "TrustedPublisher")^[raw/analyses/81adbf9a/report.md] - Signature parse:
CryptQueryObject(CERT_QUERY_OBJECT_FILE, selfPath, ...)to obtainHCRYPTMSG^[raw/analyses/81adbf9a/report.md] - Cert iteration: Loop over signers, call
CryptMsgGetParam(hMsg, CMSG_CERT_PARAM, index, ...)to get encoded cert blob ^[raw/analyses/81adbf9a/report.md] - Trust injection:
CertCreateCertificateContext(X509_ASN_ENCODING, blob, len)→CertAddCertificateContextToStore(hStore, pContext, CERT_STORE_ADD_ALWAYS, NULL)^[raw/analyses/81adbf9a/report.md] - ClickOnce launch:
LoadLibraryA("dfshim")→GetProcAddress("ShOpenVerbApplicationW")→ invoke with URL to remote.applicationmanifest ^[raw/analyses/81adbf9a/report.md]
Reproduce on your own VMs
Goal: Build a minimal PoC that adds a self-signed cert to TrustedPublisher and launches a remote ClickOnce app.
Prerequisites:
- Windows 10/11 research VM with Visual Studio Community
- A self-signed code-signing certificate (see
New-SelfSignedCertificate -Type CodeSigningCertin PowerShell) - A trivial ClickOnce
.applicationmanifest published to\\VM-IP\share\or a local web server
Steps:
- Create a new C++ Win32 project in VS 2022.
- Add
#include <wincrypt.h>and linkcrypt32.lib. - Implement the six-step flow above.
- Sign the resulting EXE with your self-signed cert (
signtool sign /f mycert.pfx /p password app.exe). - Publish a trivial ClickOnce app (e.g., a WinForms "Hello World") to a local IIS folder.
- Run the signed bootstrapper. On the VM, open
certmgr.msc→Trusted Publishers— your self-signed cert should appear. - The ClickOnce app should install without an "Unknown Publisher" warning.
What you'll learn: How to detect this at the API-telemetry layer: focus on CryptQueryObject → CertAddCertificateContextToStore → LoadLibrary("dfshim.dll") chains, rather than network indicators.
Defensive countermeasures
- EDR / API telemetry: Alert on
CertAddCertificateContextToStoretargetingTrustedPublisherorROOTfrom a non-installer process. - WMI / Sysmon Event ID 7: Detect
dfshim.dllloaded by non-standard callers (e.g., a random.exein%TEMP%). - Application Control (AppLocker / WDAC): Block
dfshim.dllexecution from unusual paths or parent processes. - Network: Monitor outbound HTTP(S) requests for
.applicationmanifests fromdfsvc.exe(the ClickOnce service) to unknown IPs. - Certificate pinning: If your org uses ConnectWise ScreenConnect legitimately, pin the expected publisher hash and alert on deviations.
Cross-references
- Observed in: connectwise family
- Related concepts: legitimate-remote-access-tool-abuse
- ATT&CK mapping: T1553.004 — Install Root Certificate (publisher variant)