Jump to content
Sign in to follow this  
hisoka

request about a script

Recommended Posts

In this website :

http://www.howtocreate.co.uk/emails/test_RC4B64_js.htm

When you clicked on the Download the script  , you get a script . I know exactly what the script does . The script decrypts and encrypts based on a password   . In the encryption process , the script asks for the password and the plaintext . From the password , a key stream will be created . Then , the created key stream will be  XORED  with the plaintext to give an RC4  cipher which , in return, is encoded to base 64 .  the decryption process is the reverse of the encryption process. Anyway . My question is the following : Based , only , on  these two information : 1) the ciphertext and  2)the script in the Download the script section is it possible to recover or hack or crack  the password if we do not know it or we forget it ?

Edited by hisoka

Share this post


Link to post
Share on other sites

No, it is not possible. If it was, then the encryption would not be doing its job since anybody can decrypt it.

Share this post


Link to post
Share on other sites

Sure, if the password that was used was weak and you have a dictionary of all probable passwords.

  • Thanks 1

Share this post


Link to post
Share on other sites

OK , lets suppose the password is a weak English word with 5 characters . So the password can be brute forced using a dictionary  attack . The problem is that I could not find a bruteforcer 

that could do the job for me and recover the password from the above script and as i am a newbie  , I cannot write my own . So what should I do ? could you please provide me with a good bruteforcer or if not possible help me write one or suggest another solution ?

Best regards

Share this post


Link to post
Share on other sites

I think this would be a good beginner's project for you.

Share this post


Link to post
Share on other sites

OK :)  could you please show me , step by step ,   how to fulfill this project ? Tell me please what to do step by step and from the beginning until the end

thanks

Share this post


Link to post
Share on other sites

I actually don't think you can easily brute force an encrypted string. Every attempt to decrypt it gives you an output message that could potentially be valid and you can't know for sure if the message you got is correct.

You could do a check on the output to see if the it only contains characters that commonly appear in text, but that code might actually miss out on a valid output that happens to have unusual characters. Another possible way to test the output is to see if it has valid English words in it, but the message might not be in English.

The other brute force attempt would test all possible inputs and all possible passwords to see if any of the input-password combinations give you the output message.

It's pointless, you cannot brute force it. Don't even try.

Share this post


Link to post
Share on other sites

Yeah, this would take a long time and generate a pretty large set of data that you would then need to go through to figure out which is the right one.

Or, if you have both the input and output, and you're just trying to get the password, then at least the script could check the output to see if it's the expected input and then you would know what the password is.  It's still going to take a while though unless it happens to test the correct password relatively early.

Here are the steps:

1. Read the list of the passwords. 

2. For each password, decrypt the text.

3. Compare the output with the original input. If they are the same, you found the password.

 

If you don't know the exact original input, then you're wasting your time.

Share this post


Link to post
Share on other sites

1. You need to have some idea what was encrypted -- and an appropriate test that will detect that output.

2. You need a list of passwords such as Popular Passwords 2017

3. You need to write a script that will attempt each password in the list and test the result.

Share this post


Link to post
Share on other sites

I know that the text is in English and I know that the password used to generate the key stream ,  is an English word with maximum 7 letters and minimum 3 letters and of course I know the ciphertext . Based on all these information , brute forcing will not take a long time ,  it  will be the  efficient  and right method . the password lists , used in brute forcing  are of course in English ,  and  not a problem to get as I can find many lists using google . My only problem is that I cannot write the program that can do the brute force . I will , if I ever know how to write it , write it in javascript as it is the only language I know LITTLE about (better than nothing) . I have , absolutely , no idea about C++ , PHP or JAVA . Therefore I will write it in JAVASCRIPT .

the algorithm can be like this I guess :

1) I need a program that decrypt . So I need to know how decryption is done

2) the program should be linked with the password list files . So it will take or accept , for example ,  60 MB passwords

3) the program should know the right output that is the plaintext . How I do not know ? I mean how can  the bruteforcer determine that it has the plaintext ?

 

Quote

You need to have some idea what was encrypted -- and an appropriate test that will detect that output.

What do you mean by " appropriate test " ?

 

 

Edited by hisoka

Share this post


Link to post
Share on other sites

You have the decryption function, it's on the page you linked to earlier. http://www.howtocreate.co.uk/emails/test_RC4B64_js.htm

The problem here is that you have two variables to find out. There are three parts of the equation, input, password and output; two of which you don't know. You have only the output and you are trying to determine the password, but in order to determine the password you also need to know the input.

If you knew the input, the brute force algorithm would look like this:

var Encryption = new Rc4B64Class();
var englishWords = [ /* ... List of all possible English words ... */];
var input = "This is the input message";
var output = "LgYkO2JSfWoA394oOvXrwO4mtuDkusLCzg==";
var password, test;
for(var i = 0; i < englishWords.length; i++) {
  password = englishWords[i];
  test = Encryption.Decrypt(output, password); 
  if(test == input) {
    alert("The password is " + password);
    break;
  }
}

You don't know the input, so this brute force algorithm is not going to work. You also don't have a full list of English words, which would be at least hundreds of thousands of items long.

If you want to build a program that reads the list from a file, you're going to have to learn a lot more Javascript, I am not going to explain that complicated process here when there are entire articles written about it all over the internet. If you have to ask how to do things like that, you still have not learned enough Javascript.

I am going to reiterate that the task you have set out to do is impossible, if encryption were that easy to break we would have some serious security problems on the internet.

Share this post


Link to post
Share on other sites

As Ingolme says, you have the decryption code and obviously Javascript is the only reasonable language choice. The problem is choosing passwords and detecting success. Now, as an example, if you know that the successful decryption will result in a phrase that contains one of the English words; "the", "and", or "is" then an "appropriate test" you might use;

test = toLowerCase(test);

if(test.indexOf('the') != -1 || test.indexOf('and') != -1 || test.indexOf('is') != -1){
    alert(test);
}

or this might be better...

var t = toLowerCase(test);
if(t.indexOf(' the ') != -1 || t.indexOf(' and ') != -1 || t.indexOf(' is ') != -1){
   alert(test);
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

brute forcing will not take a long time

How do you know that? How long does it take to do one decryption and test it?  How many do you have to do?  If you're going to test all passwords that contain uppercase letters, lowercase letters, numbers, and a few symbols, then that's 4,398,046,511,104 different passwords for a length of 7 characters.  If you're doing a million decryptions and tests per second, which seems like it would be an achievement if you're using Javascript instead of a compiled language, then that will take you around 50 days to finish.  Hopefully you don't turn your computer off, or close your browser, or whatever, or else you're going to have to start all over (assuming you're not keeping track of which passwords you've already tested, which you can do but that's going to take more time).

Share this post


Link to post
Share on other sites
Quote

If you're going to test all passwords that contain uppercase letters, lowercase letters, numbers, and a few symbols, then that's 4,398,046,511,104 different passwords for a length of 7 characters

Quote

I know that the text is in English and I know that the password used to generate the key stream ,  is an English word with maximum 7 letters and minimum 3 letters

it is a lowercase word . How I know it because I read in the mind of the challenger . 

Quote

The problem here is that you have two variables to find out. There are three parts of the equation, input, password and output; two of which you don't know. You have only the output and you are trying to determine the password, but in order to determine the password you also need to know the input.

I know the input . The input is the ciphertext which is an RC4 cipher .

var input = "This is the input message";
var output = "LgYkO2JSfWoA394oOvXrwO4mtuDkusLCzg==";

we do not know the output . Because the output is the plaintext . So is not correcter to put the variable output as undefined like this :

var output = " ";
var t = toLowerCase(test);
if(t.indexOf(' the ') != -1 || t.indexOf(' and ') != -1 || t.indexOf(' is ') != -1){
   alert(test);
}

this is very brilliant :)

 

Edited by hisoka

Share this post


Link to post
Share on other sites
Quote

If you want to build a program that reads the list from a file, you're going to have to learn a lot more Javascript, I am not going to explain that complicated process here when there are entire articles written about it all over the internet. If you have to ask how to do things like that, you still have not learned enough Javascript.

Is there a tutorial on how to do it in w3schools website ?

Share this post


Link to post
Share on other sites

Ok I found a website in which there a script on how to read from a file .

https://gist.github.com/Arahnoid/9925725

There is a piece of script :

 
var txtFile = "c:/test.txt"
var file = new File(txtFile);

file.open("r"); // open file with read access
var str = "";
while (!file.eof) {
// read each line of text
str += file.readln() + "\n";
}
file.close();

alert(str); 

It is not hard to understand . Nonetheless I have some questions :

why we use new and not just File . I mean why do not we use :

var file =  File(txtFile); 
File()
Returns a newly constructed File.
 
https://developer.mozilla.org/en-US/docs/Web/API/File
 
I cannot find readln() function in google so what is it ?
 
when I run the above script I got this error which I could not understand
 
/*
Exception: TypeError: Not enough arguments to File.
@Scratchpad/1:3:12
*/
 
I mean i understand that the function File() does not  have enough argument . but how many argument should File() has ?
How to repair the above error ?

Share this post


Link to post
Share on other sites

I know the input . The input is the ciphertext which is an RC4 cipher .

The input is the orginal cleartext.  The output is the ciphertext.  You don't know the original input, you only have the output.  The three variables are the input, the password, and the output.  You only have the output.

Is there a tutorial on how to do it in w3schools website ?

The server-side languages should be able to read files on the server, but you're not going to find a single tutorial that does exactly what you're trying to do, you need to learn the individual pieces and then put them together to build what you want.

Ok I found a website in which there a script on how to read from a file .

Make sure you read the user comments on that Github page.

It is not hard to understand . Nonetheless I have some questions :

why we use new and not just File .

Because that's one way to create an object in Javascript.

I cannot find readln() function in google so what is it ?

It's not part of that File object, I can tell that.  Maybe it's part of Node.js.

I mean i understand that the function File() does not  have enough argument . but how many argument should File() has ?


How to repair the above error ?

https://developer.mozilla.org/en-US/docs/Web/API/File/File

That's not the right way to read a file in modern browsers though, the FileReader object is.

Share this post


Link to post
Share on other sites
Quote

I am going to reiterate that the task you have set out to do is impossible, if encryption were that easy to break we would have some serious security problems on the internet.

it is possible if the password is a lowercase English word and part of the English sentence is guessable which it is . All what is needed is a brute forcer .

Quote

you need to learn the individual pieces and then put them together to build what you want.

I know javascript and I read all the tutorials in the w3schools concerning javascript all without exception and I understood them very well . I even read books about javascript and I understood what I read . So what do you suggest me ? can you tell me what should I do?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×