<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ruwan Pradeep Geeganage</title>
    <description>The latest articles on DEV Community by Ruwan Pradeep Geeganage (@rpgeeganage).</description>
    <link>https://dev.to/rpgeeganage</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F122656%2F8d1a631c-8bd2-46b8-a22a-f6d682af9cf5.jpeg</url>
      <title>DEV Community: Ruwan Pradeep Geeganage</title>
      <link>https://dev.to/rpgeeganage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rpgeeganage"/>
    <language>en</language>
    <item>
      <title>Auditing NodeJs modules with YARA rules</title>
      <dc:creator>Ruwan Pradeep Geeganage</dc:creator>
      <pubDate>Tue, 06 Apr 2021 17:01:39 +0000</pubDate>
      <link>https://dev.to/rpgeeganage/auditing-nodejs-modules-with-yara-rules-7j0</link>
      <guid>https://dev.to/rpgeeganage/auditing-nodejs-modules-with-yara-rules-7j0</guid>
      <description>&lt;h2&gt;
  
  
  Auditing NodeJs modules with YARA rules
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara"&gt;https://github.com/rpgeeganage/audit-node-modules-with-yara&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently I thought of pursuing my secret passion in the field of information security, specifically work related to malware analysis. While I was looking into static analysis methods, I came across YARA rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is YARA?
&lt;/h3&gt;

&lt;p&gt;Based on the VirusTotal website YARA is,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;YARA is a tool aimed at (but not limited to) helping malware researchers to identify and classify malware samples. With YARA you can create descriptions of malware families (or whatever you want to describe) based on textual or binary patterns. Each description, a.k.a rule, consists of a set of strings and a boolean expression which determine its logic&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  An example of a YARA rule looks like this.
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rule silent_banker : banker
{
    meta:
        description = "This is just an example"
        threat_level = 3
        in_the_wild = true
    strings:
        $a = {6A 40 68 00 30 00 00 6A 14 8D 91}
        $b = {8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9}
        $c = "UVODFRYSIHLNWPEJXQZAKCBGMT"
    condition:
        $a or $b or $c
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  You can get YARA from &lt;a href="https://yara.readthedocs.io/en/stable/"&gt;https://yara.readthedocs.io/en/stable/&lt;/a&gt;
&lt;/h5&gt;

&lt;h3&gt;
  
  
  Supply chain attacks
&lt;/h3&gt;

&lt;p&gt;As I was reading through the latest security issues in the NodeJS ecosystem, one type of attack caught my attention, which is the supply chain attack. &lt;/p&gt;

&lt;p&gt;According to Wikipedia, the supply chain attack described as follows.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A Supply chain attack is a cyber-attack that seeks to damage an organization by targeting less-secure elements in the supply chain.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In NodeJs, one of the methods is to create malicious packages and publish them to NPM. The following articles explain how to utilize malicious NPM packages to perform supplier chain attacks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://iamakulov.com/notes/npm-malicious-packages/"&gt;Malicious packages in npm. Here’s what to do&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bleepingcomputer.com/news/security/malicious-npm-packages-target-amazon-slack-with-new-dependency-attacks/"&gt;Malicious NPM packages target Amazon, Slack with new dependency attacks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://duo.com/decipher/hunting-malicious-npm-packages"&gt;Hunting malicious NPM packages&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  My project to combine auditing NodeJS modules with YARA
&lt;/h3&gt;

&lt;p&gt;To achieve this, I started setting up a small project. It is available at &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara"&gt;https://github.com/rpgeeganage/audit-node-modules-with-yara&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining YARA rules for malicious packages
&lt;/h3&gt;

&lt;p&gt;In this project, I created a couple of sample YARA rules based on article 1 mentioned above. These rules are available at &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/tree/master/yara_rules/package_json."&gt;https://github.com/rpgeeganage/audit-node-modules-with-yara/tree/master/yara_rules/package_json&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(All of these packages have currently been removed from the NPM registry.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A sample rule for &lt;code&gt;babelcli@1.0.1&lt;/code&gt; is as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rule babelcli
{
    meta:
        name = "babelcli@1.0.1"

    strings:
        $name = /"name":\s"babelcli",/
        $version = /"version":\s"1.0.1"/

    condition:
        all of them
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/blob/master/yara_rules/package_json/babelcli_1_0_1.yara"&gt;https://github.com/rpgeeganage/audit-node-modules-with-yara/blob/master/yara_rules/package_json/babelcli_1_0_1.yara&lt;/a&gt;
&lt;/h5&gt;

&lt;h3&gt;
  
  
  Creating the runtime environment for YARA Executable
&lt;/h3&gt;

&lt;p&gt;To provide a simple runtime environment for YARA, I choose the most convenient way, which is to create a &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/blob/master/docker/Dockerfile"&gt;Docker container&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Applying the YARA rules and handling the output
&lt;/h3&gt;

&lt;p&gt;In this Docker container, I install all the applications needed to run YARA as well as a small NodeJs app. The special app (I called it &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/tree/master/executor"&gt;executor&lt;/a&gt;) allows me to apply YARA rules and format the output as a JSON and store it in &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/tree/master/artifacts"&gt;artifacts/output.json&lt;/a&gt;. The executor runs the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yara --recursive --print-strings --fail-on-warnings \`find ${yaraRulesFolder} -type f -name "*.yara"\` ${folderToAudit}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the execution, results will be parsed as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
 {
  "rule": "evil_package_1",
  "string_information": [
   "0x6:$name: \"name\": \"nodecaffe\",",
   "0x1f:$version: \"version\": \"0.0.1\""
  ]
 },
 {
  "rule": "evil_package_2",
  "string_information": [
   "0x6:$name: \"name\": \"sqlserver\",",
   "0x1f:$version: \"version\": \"4.0.5\""
 } 
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Integration with the CI/CD pipeline
&lt;/h3&gt;

&lt;p&gt;I thought integration with the CI/CD pipeline was important, as this checking process can help identify malicious NPM packages that can sneak into our repository. For integration with the CI/CD pipeline, I suggested something like the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
make NODE_MODULE_FOLDER_TO_AUDIT=../restful4up/node_modules run

# You need to install "jq" library if required

suspicious_file_count=$(jq length artifacts/output.json)

exit $suspicious_file_count
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding new rules
&lt;/h3&gt;

&lt;p&gt;It is important to add new rules to detect new malicious packages or scripts. The new rules can be added to the &lt;a href="https://github.com/rpgeeganage/audit-node-modules-with-yara/tree/master/yara_rules"&gt;yara_rules folder&lt;/a&gt;. The newly added rules will be applied to the specified node module folder the next time this project is run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improvements and future work
&lt;/h3&gt;

&lt;p&gt;This is a very simple tool that can be improved with the help of the community. I myself am a noob when it comes to malware analysis and YARA rules. So, new pull requests, new rules, new suggestions are highly welcome and always appreciated. &lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>yarn</category>
      <category>infosec</category>
    </item>
    <item>
      <title>Async-Ray and alls 2 promise utility libraries are written in TypeScript</title>
      <dc:creator>Ruwan Pradeep Geeganage</dc:creator>
      <pubDate>Tue, 01 Jan 2019 22:17:58 +0000</pubDate>
      <link>https://dev.to/rpgeeganage/async-ray-and-alls-2-promise-utility-libraries-are-written-in-typescript-2676</link>
      <guid>https://dev.to/rpgeeganage/async-ray-and-alls-2-promise-utility-libraries-are-written-in-typescript-2676</guid>
      <description>&lt;p&gt;Hi EveryOne,&lt;br&gt;
I would like to introduce below 2 libraries. They are written in TypeScript with 100% test coverage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Async-Ray:
&lt;/h3&gt;

&lt;p&gt;Purpose of this package is to provide &lt;code&gt;async/await&lt;/code&gt; callbacks for &lt;code&gt;every&lt;/code&gt; , &lt;code&gt;filter&lt;/code&gt; , &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;findIndex&lt;/code&gt; , &lt;code&gt;forEach&lt;/code&gt; , &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;reduce&lt;/code&gt;, &lt;code&gt;reduceRight&lt;/code&gt; and &lt;code&gt;some&lt;/code&gt; methods in Array with easy chaining.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/rpgeeganage/async-ray"&gt;https://github.com/rpgeeganage/async-ray&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Chaining Samples: 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rpgeeganage/async-ray/blob/master/examples/chain_sample_1.ts"&gt;https://github.com/rpgeeganage/async-ray/blob/master/examples/chain_sample_1.ts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rpgeeganage/async-ray/blob/master/examples/chain_sample_2.ts"&gt;https://github.com/rpgeeganage/async-ray/blob/master/examples/chain_sample_2.ts&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  alls:
&lt;/h3&gt;

&lt;p&gt;Just another library with the sole purpose of waiting till all promises to complete Nothing more, Nothing less. Since &lt;code&gt;Promise.all()&lt;/code&gt; doesn't wait if an error.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/rpgeeganage/alls"&gt;https://github.com/rpgeeganage/alls&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Samples: &lt;a href="https://github.com/rpgeeganage/alls/blob/master/test/alls.ts"&gt;https://github.com/rpgeeganage/alls/blob/master/test/alls.ts&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>promise</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
