Created
October 23, 2021 17:39
-
-
Save mdanshin/676a080c343477f6d6cbe8770043a674 to your computer and use it in GitHub Desktop.
Translate LDAP objectSID from base64 fromat (AQUAAAAAAAUVAAAA6We7mNa317+CBR5sKAYAAA==) to SSDL (S-1-5-21-2562418665-3218585558-1813906818-1576)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sidToString(base64) { | |
const buffer = Buffer.from(base64, 'base64') | |
const array = buffer.toString('hex') | |
const G = array.toString().match(/.{1,2}/g) | |
const BESA2=`${G[8]}${G[9]}${G[10]}${G[11]}` | |
const BESA3=`${G[12]}${G[13]}${G[14]}${G[15]}` | |
const BESA4=`${G[16]}${G[17]}${G[18]}${G[19]}` | |
const BESA5=`${G[20]}${G[21]}${G[22]}${G[23]}` | |
const BERID=`${G[24]}${G[25]}${G[26]}${G[27]}` | |
const LESA1=`${G[2]}${G[3]}${G[4]}${G[5]}${G[6]}${G[7]}` | |
const LESA2=`${BESA2.substr(6,2)}${BESA2.substr(4,2)}${BESA2.substr(2,2)}${BESA2.substr(0,2)}` | |
const LESA3=`${BESA3.substr(6,2)}${BESA3.substr(4,2)}${BESA3.substr(2,2)}${BESA3.substr(0,2)}` | |
const LESA4=`${BESA4.substr(6,2)}${BESA4.substr(4,2)}${BESA4.substr(2,2)}${BESA4.substr(0,2)}` | |
const LESA5=`${BESA5.substr(6,2)}${BESA5.substr(4,2)}${BESA5.substr(2,2)}${BESA5.substr(0,2)}` | |
const LERID=`${BERID.substr(6,2)}${BERID.substr(4,2)}${BERID.substr(2,2)}${BERID.substr(0,2)}` | |
const LE_SID_HEX=`${LESA1}-${LESA2}-${LESA3}-${LESA4}-${LESA5}-${LERID}` | |
const ADDR=LE_SID_HEX.split('-') | |
return "S-1-" + ADDR.map(x => parseInt(x, 16)).join('-') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment