Quoting a jsign
bug report related How to validate authenticode for Javascript in C#.
I've played a bit with VBScript and JScript files, it looks like the hashing method is different from the PowerShell scripts. For PowerShell the content is converted to
UTF-16LE
before being hashed. For VB and JS it doesn't work, the hash generated differs from the one computed by signtool. I tried various encodings (UTF-8
,UTF-16BE
,UTF-32BE/LE
, with or without byte order marks) but it still doesn't match.
How does one create the .vbs
signature block without signtool.exe
(and without any proprietary and/or Microsoft tools?)
Edit:
So far, I've observed the following:
- By default,
signtool.exe
uses SHA-1 signatures. It can be forced to use SHA-256 signatures using/fd sha256
- By default, JSign adds some additional properties to the signature which throw off an exact signature match.
For reference, this is what the end-product signature normally looks like when using signtool.exe
.
'' SIG '' Begin signature block
'' SIG '' MIIM4AYJKoZIhvcNAQcCoIIM0TCCDM0CAQExCzAJBgUr
' ... (a bunch of bas64 data) ...
'' SIG '' cSu0HJyT7v9OctFKlKj7aCB6JHPrR0il9GFdoZrQFNuU
'' SIG '' End signature block
The purpose of this signature is to allow Windows to verify the publisher of the file. It's not a well-documented standard, but can be found in solutions like this.
Modern purposes may include running a .vbs
file as a standalone script or as part of an application. Leveraging Windows' built-in validation mechanism adds a layer of trust to the script for environments that need it.
Quoting Chapter 28 of Don Jones' "Managing Windows with VBScript and WMI."
Running Only Signed Scripts
If you don't want to mess around with software restriction policies, you can also rely on WSH's own built-in form of security policy. This policy allows you to specify that only signed scripts will be run; unsigned scripts won't be. This is probably the easiest and most effective way to prevent most unauthorized scripts.
Digital signatures are common enough so that we shouldn't be limited by closed source utilities like signtool.exe
.