Code deobfuscation is an important skill to learn if we want to be skilled in code analysis and reverse engineering. Obfuscation is a technique used to make a script more difficult to read by humans but allows it to function the same from a technical point of view, though performance may be slower. This article will explain what code deobfuscation is, the reasons for using it, and its potential advantages and disadvantages.
This is usually achieved automatically by using an obfuscation tool, which takes code as input, and attempts to re-write the code in a way that is much more difficult to read, depending on its design For example, consider the following two snippets of code and their output:
Snippet 1:
console.log("Hello by Dhanush")
Output of Snippet 1:
Hello by Dhanush
Snippet 2:
eval(
(function (p, a, c, k, e, d) {
e = function (c) {
return c;
};
if (!"".replace(/^/, String)) {
while (c--) {
d[c] = k[c] || c;
}
k = [
function (e) {
return d[e];
},
];
e = function () {
return "\\w+";
};
c = 1;
}
while (c--) {
if (k[c]) {
p = p.replace(new RegExp("\\b" + e(c) + "\\b", "g"), k[c]);
}
}
return p;
})('0.1("2 3 4")', 5, 5, "console|log|Hello|by|Dhanush".split("|"), 0, {}),
);
Output of Snippet 2:
Hello by Dhanush
Snippet 1 contains a simple JavaScript script. It logs the string "Hello by Dhanush" to the console using the console.log() function. In JavaScript, this is a typical method of message output. A more advanced piece of code, found in Snippet 2, uses the eval() function to run a JavaScript function that is generated dynamically. Here is a summary of what is occurring:
The practice of reverse engineering or deciphering code that has been purposefully obfuscated or made more challenging to understand is known as deobfuscation. Deobfuscation would entail converting the obfuscated code in the second code snippet back into its original, more readable form. In the second snippet, to make it difficult to understand at first glance, the code has been purposefully obfuscated.
Here, the obfuscation strategy entails swapping out meaningful variable names and codes for obscure ones and convoluted reasoning. This type of obfuscation is known as "packing", which is usually recognizable from the six function arguments used in the initial function "function(p,a,c,k,e,d)". There are many online tools also available to obfuscate javascript code like
and many more.
Obfuscation of code should be employed sparingly and in conjunction with other security safeguards like encryption, access controls, and routine security audits. It is most frequently employed in situations when securing information or preserving intellectual property are major priorities.
Thanks for reading, share this article on social media if you found it useful
Connect 👉