0

I'd like to make a JavaScript script that'd generate numbers from 0000 to 9999, not randomly but that would try every number one by one, like 0000, 0001, 0002... and would press the submit button right after, the script should remain running after page refreshes.

Input box: <input id="form_Number" name="form[Number]" required="required" class="form-control" value="" type="text" pattern="[0-9]*" data-kpxc-id="form_Number">

Submit button: <button type="submit" id="form_submit" name="form[submit]" class="btn-primary btn">Submit</button>

It's for one primitive website that uses codes to login, it doesn't have a captcha too. Either way, it's supposed to try out every combination until it successfully logs in, like the script puts in these combinations and presses the button immediately, then if fails, page refreshes and script should remain running and put those combinations over and over. It's more for fun than for serious purposes. Also I have to be logged in on the site with actual user to access this input box.

Tomurisk
  • 17
  • 5
  • 5
    I think it would help if you explain *why* you want this, because as is, it's a bit of a unlogical idea :) – Martijn Apr 02 '20 at 12:16
  • 1
    "would press the submit button right after" Who/what presses the submit button and right after what? – D. Pardal Apr 02 '20 at 12:16
  • If you are trying to get *unique* values this will not work very well. 1. A script cannot continue running after refresh. You *could* save the last value and after refresh restore it but you run into another problem 2. I you have more than one person looking at the page, you cannot synchronise them. Not reliably enough, at least. However, you can just [create a GUID](https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript) and that would be unique between browsers and page refreshes. – VLAZ Apr 02 '20 at 12:18
  • 2
    @Martijn Unless we have a Mr. Hacker here who is trying to brute-force a PIN :) – Yury Tarabanko Apr 02 '20 at 12:19
  • It's for one primitive website that uses codes to login, it doesn't have a captcha too. Either way, it's supposed to try out every combination until it successfully logs in, like the script puts in these combinations and presses the button immediately, then if fails, page refreshes and script should remain running and put those combinations over and over. It's more for fun than for serious purposes. – Tomurisk Apr 02 '20 at 12:22
  • @Tomsonas Do not use UI. Just write a bash script that sends requests to the form action until it gets success response. – Yury Tarabanko Apr 02 '20 at 12:25
  • Please [edit] your question to include the explanation. Most people don't read the comments. – Heretic Monkey Apr 02 '20 at 12:26

1 Answers1

0

If I understand correct, you wish to bruteforce something. I'm writing this answer with the assumption you're not going to use this for bad stuff.


You might be looking for an ajax request. I'm going to write this in jQuery because it makes the example less obfuscated, you might need to rewrite it to your needs.

This will fire 10 (so that this example remains an example) requests and will return the result into a div. You might want something else, just edit the content of the .then() function.

function probeForResult(iNumber){
    var $target = $(`<div id="result${iNumber}" />`);
    $target.html(`Waiting for result (${iNumber})...`);

    $('#wrapper').append($target);

    $.post('/some/url', {form: {number: iNumber}})
    .then(response=>{
     $target.html(response);
        // Reponse is likely not some string. You might want to check header,
        // or something else that is it returning
        console.log(response);
    })
    .catch(()=>{
        $target.html('Whoops, error. Does the url exist?'); // the url in this example doesnt exists
    });
}

$('#wrapper').html('');
for( let i=0; i<=10; i++){
    probeForResult(i);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="wrapper">
    Did nothing so far
</div>

Disclaimer: Setting this to 10.000 iterattions might fry your browser :)

Martijn
  • 15,791
  • 4
  • 36
  • 68
  • "*Setting this to 10.000 iterattions might fry your PC*" I sincirely doubt it. I'd expect the browser to rate limit the requests. Might even just abort them directly. – VLAZ Apr 02 '20 at 12:58
  • Rephrazed it to browser. Dont know if they're going to abort them, you can add an interval, or do batches or whatever you like. This is just the core of a solution :) – Martijn Apr 02 '20 at 20:27