Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails if registry editing tools are disabled on windows #27

Open
eohland opened this issue Oct 6, 2017 · 16 comments
Open

Fails if registry editing tools are disabled on windows #27

eohland opened this issue Oct 6, 2017 · 16 comments

Comments

@eohland
Copy link

eohland commented Oct 6, 2017

Hi,
If you are on a restricted environment where local group policy prevent access to registry editing tools, the "REG QUERY" command fails.
A workaround for me was to write a native tool (attached below), it work either on native and mixed environment.

get-machine-guid.c.zip

@joneian
Copy link

joneian commented Nov 22, 2017

I'm seeing this issue too...

@SirNeural
Copy link

Also seeing this issue as well, would it be possible to implement a fallback to the native tool or another nodejs way of accessing the registry if the REG QUERY command is detected as failed?

@yawar-ali
Copy link

@eohland @joneian @SirNeural Any luck with this issue ?

@yawar-ali
Copy link

@automation-stack You got any chance to look into this issue ?

@eohland
Copy link
Author

eohland commented Mar 7, 2018

No @SweetEvil, I still use my cpp workaround like that:

function getMachineIdSync() {
  if (process.platform === 'win32') {
    let guid = execSync('get-machine-guid.exe').toString()
    guid = guid.replace(/\r+|\n+|\s+/ig, '').toLowerCase()
    return createHash('sha256').update(guid).digest('hex')
  }
  else {
    return machineIdSync()
  }

A proper fix could be to implement it as a native module.

@yawar-ali
Copy link

@eohland What is this get-machine-guid.exe ? You created exe file on your own or it is available online ?

@eohland
Copy link
Author

eohland commented Mar 7, 2018

I created my own, It is the compiled version of get-machine-guid.c included in my first post.

@yawar-ali
Copy link

@eohland Does it return same machine Id in each case with machineIdSync & your workaround ?

@eohland
Copy link
Author

eohland commented Mar 7, 2018

@SweetEvil Yes, the only difference is the way to retrieve the MachineGuid registry key

@yawar-ali
Copy link

@eohland It didn't compile for me, I am getting some errors.

@eohland
Copy link
Author

eohland commented Mar 8, 2018

@SweetEvil I just tried again and it compile without errors using the VS2015 Developer Command Prompt like this:

cl get-machine-guid.c

Here is the compiled executable : get-machine-guid.exe.zip

@yawar-ali
Copy link

@eohland Your executable just flickers and returns nothing. I am getting undeclared KEY_WOW64_64KEY error while compiling script.

@yawar-ali
Copy link

@eohland Nevermind, I got it working, just that I am having issues with returning char* buffer back from dll export method to the app. I am using node-ffi for dll comms.

@ScubaDrew
Copy link

Does this occur only is GP specifically "prevent access to registry editing tools" or is it if the user is not a local admin?

@DeverStyle
Copy link

Late to the party but you can also use PowerShell:

const {spawnSync} = require('child_process');
const {createHash} = require('crypto');

const getSync = (original = false) => {
  const psProc = 'powershell.exe';
  const psArgs = ['-NoLogo', '-Command', '-NonInteractive', '(New-Object -ComObject WScript.Shell).RegRead("HKLM\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid")'];
  const output = spawnSync(`${psProc}`, psArgs);
  const string = output.stdout.toString().split('\r\n')[0];

  return original ? string : hash(string);
};

function hash(guid) {
  return createHash('sha256').update(guid).digest('hex');
}

module.exports = {
  getSync,
};

@Antheso
Copy link

Antheso commented Dec 6, 2019

@DeverStyle '-NonInteractive' should be before '-Command'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants