Js_ Seven types of JavaScript encryption/decryption methods

Source: Internet
Author: User
Tags decrypt

This article introduces a total of seven JavaScript encryption methods.

One: The simplest encryption and decryption

Second: The magical character of escaping characters

Three: Encode with Microsoft-produced Scripting Encoder Script encoder (self-creating simple decoding)

Four: Arbitrarily add nul null character (hex 00H) (self-created)

Five: Useless content confusion and newline space tab DAFA

Six: Self-write decryption function method

Seven: The use of the wrong

In the Web page (in fact, it is a Trojan horse), the most annoying is their hard-working to write out the client IE JavaScript code is often easily copied by others, really let their hearts a little taste, to know that they write something is also very tired ... ^*^

But we should also clearly realize that because the JavaScript code is interpreted in IE, to absolute secrecy is impossible, we have to do as much as possible to increase the copy of the difficulty of copying, let him quit (I hope ~!~), the following I combined with their years of practice, and personal research experience, Let's discuss the encryption and decryption techniques of JavaScript code in the Web page.

For example, encrypt the following JavaScript code:
<script language= "JavaScript" >
Alert ("Hacker line of Defense");

One: The simplest encryption and decryption

For JavaScript functions Escape () and unescape () must be more understanding (many Web encryption is used in them), respectively, encoding and decoding strings, such as the example code with the Escape () function is encrypted to the following format:

How is it? You know what you're looking for? Of course one of the ASCII characters "alert" is not encrypted, and if willing we can write some JavaScript code to re-encrypt it as follows:

Oh! How is it? It's completely encrypted this time!

Of course, such encrypted code is not directly run, fortunately, there is eval (codestring) available, the function is to check the JavaScript code and execute, the required option codestring parameter is a string value containing valid JavaScript code, With the above decoding unescape (), the results of the encryption are as follows:
<script language= "JavaScript" >
var code=unescape ("%61%6c%65%72%74%28%22%u9ed1%u5ba2%u9632%u7ebf%22%29%3b");
Eval (code)

Isn't it simple? Do not be happy, decryption is the same simple, decryption code is placed to others (Unescape ())! Oh

Second: The magical meaning of the escape character ""

You may not be familiar with the escape character, but there are some special characters such as for javascript: N (newline), R (carriage return), ' (single quote), etc. should you know something about it? In fact, "" can also be followed by octal or hexadecimal digits, such as the character "a" can be expressed as: "141" or "x61" (note is lowercase character "x"), as for the double-byte character such as kanji "black" can only be used in hexadecimal notation as "u9ed1" (note that the lowercase character "u") The expression is a double-byte character, and according to this principle the example code can be expressed as:

The octal escape string is as follows:
<script language= "JavaScript" >
Eval ("1411541451621645042u9ed1u5ba2u9632u7ebf425173")

The hexadecimal escape string is as follows:
<script language= "JavaScript" >
Eval ("x61x6cx65x72x74x28x22u9ed1u5ba2u9632u7ebfx22x29x3b")

This time there is no decoding function, because JavaScript executes itself, the same decoding is very simple as follows:
<script language= "JavaScript" >
Alert ("x61x6cx65x72x74x28x22u9ed1u5ba2u9632u7ebfx22x29x3b")

A popup dialog will show you the results of the decryption!

Three: Encode with Microsoft-produced Scripting Encoder Script Encoder

The use of tools is not much introduced! I am using JavaScript directly to call the control Scripting.encoder to complete the encoding! The code is as follows:
<script language= "JavaScript" >
var senc=new activexobject ("Scripting.encoder");
var code= ' <script language= "JavaScript" >rnalert ("hacker defense");rn</script> ';
var encode=senc.encodescriptfile (". htm", code,0, "");
alert (Encode);

The result of the encoding is as follows:
<script language= "Jscript.encode" >#@~^[email PROTECTED]#@&LSDD ' J Hacker line r#[email protected]#@& fgmaaa==^#[email protected]</SCRIPT>

Ugly enough, you know? But the corresponding decryption tool has already come out, and even decrypt the page has! Because of its decryption page code too much, I do not say more pull! Let me introduce my original decryption code, as follows:
<script language= "Jscript.encode" >
function decode ()
Alert (decode.tostring ());

How? Simple enough, huh? It is the principle is: After the code run IE will decode it first, if we first put the encrypted code into a custom function such as the above Decode (), and then to the custom function decode call the ToString () method, the resulting will be decoded code!

If you think that the code language attribute is Jscript.encode, it is easy to see through, then there is a nearly unknown Window object Method Execscript (), the prototype is:
Window.execscript (Sexpression, slanguage)

Sexpression: Required option. String. The code to be executed.
Slanguage: Required option. String. Specifies the language of the code to execute. Default value is Microsoft JScript

When used, the front "window" can be omitted without writing!

With it we can run the coded JavaScript code very well, as follows:
<script language= "JavaScript" >
ExecScript ("#@~^[email protected]#@&lsdd ' j Hacker line r#[email protected]#@&fgmaaa==^#[ Email protected]"," Jscript.encode ")

You can use the method two to the "" number within the string to encode, so that "Jscript.encode" and the code signature "#@~^" does not appear, the effect will be better!

Four: Add any nul null character (hex 00H)

An accidental experiment, so that I found anywhere in the HTML page to add any number of "empty character", ie will still display the contents of the normal, and normal execution of the JavaScript code, and add "empty character" when we look at the general editor, it will show the shape of a space or black block, Make the original code difficult to understand, such as using Notepad to view the "empty character" will become a "space", using this principle to encrypt the result is as follows: (where the "space" to represent "null character")
<s C RI P t L ANG U A G E = "J a V a S C r i P T" >

A l ER t ("hacker defenses");

</SC R I P t>

How is it? Does it look a mess? It's hard to think of the "empty character" (00H) inside if you don't know the method!

Five: Useless content confusion and newline space tab DAFA

In JavaScript code we can add a lot of useless strings or numbers, as well as useless code and comment content, and so on, so that the real useful code buried in it, and the useful code can be added to line, space, tab to add a large number of line breaks, spaces, tab, and can be the normal string with "" To make line breaks, which makes the code difficult to read! As I encrypt after the form as follows:
<script language= "JavaScript" >
"Xajgxsadffgds"; 1234567890
625623216;var $=0;alert//@$%%&* (& (^%^
CCTV function//

Line of defense "//ASHJGFGF
;" #@$#%@ #432hu "; 212351436

At least if I see this code is not going to have the mind to analyze it, where are you?

Six: Self-write decryption function method

This method is similar to one or two, just write a function to decrypt the code, many VBS viruses use this method to encrypt themselves, to prevent signature scanning! Here is a simple cryptographic decryption function I wrote,

The encryption code is as follows (detailed reference file "encrypt. htm"):
<script language= "JavaScript" >
function compile (code)
var c=string.fromcharcode (code.charcodeat (0) +code.length);
for (Var i=1;i<code.length;i++)
Alert (Escape (c));
Compile (' Alert ' ("Hacker Defense");

Run to get encrypted results as:

The code that is decrypted after the corresponding encryption is as follows:
<script language= "JavaScript" >
function Uncompile (code)
Code=unescape (code);
var c=string.fromcharcode (code.charcodeat (0)-code.length);
for (Var i=1;i<code.length;i++)
return C;
Eval (uncompile ("O%CD%D1%D7%E6%9CJ%U9EF3%UFA73%UF1D4%U14F1%U7EE1KD"));

Seven: The use of the wrong

The code is tested and decrypted using the Try{}catch (e) {} structure, although the idea is very good (hehe, boast yourself), because the practicality is not big, I just give an example
<script language= "JavaScript" >

var a= ' alert ("Hacker line of Defense");
var c= "";
for (Var i=0;i<a.length;i++)

alert (c);

The above is the encryption code, of course, if you really use this method, the encryption will not be written on the
Now the variable c is the encrypted code.

The following function T () First assumes that the initial password is 0, decryption is performed,
If an error is encountered, add 1 to the password and then decrypt execution until it runs correctly.

var d=c; Save the encrypted code
var b=0; Assuming an initial password of 0
T ();

function T () catch (e) {
C= "";
for (Var i=0;i<d.length;i++)
T ();
SetTimeout ("t ()", 0);

Js_ Seven types of JavaScript encryption/decryption methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.