Home > Net >  How do I log into this website using perl (and JS?)?
How do I log into this website using perl (and JS?)?

Time:09-17

I am currently trying to automatically log in to the website below using perl. I have tried using mechanize but I believe it would require JS functionality. Ive looked into the JavaScricpt Mech Plugin but the documentation is not very understandable for me. Im not sure how to further approach this since I cant see the md5() function so Im not able to reconstruct it in the perl code...

The relevant bits are:

HTML:

<form method="POST" name="logonForm" onsubmit="encode();document.submitForm.submit();return false;">
<tr class="Element">
    <td class="text" id="ID_Text4"><nobr>User name:</nobr></td>
    <td  class="text" align="left">
        <select name="username"  style="width:125">
            <option value="user" id="ID_Text5">user&nbsp; </option>
            <option selected value="admin" id="ID_Text6">admin&nbsp;</option>
        </select>
    </td>
</tr>
<tr class="Element">
    <td class="text" id="ID_Text7"><nobr>Password:</nobr></td>
    <td  class="text">
        <input type="password" size="10" name="password" style="width:125">
    </td>
</tr>
<form method="POST" name="submitForm">
   <input type="hidden" name="encoded">
   <input type="hidden" name="nonceA" value="">
   <input type="button" name="goto" value="Log On" onClick="encode();submit();" style="width:125" ID="ID_Button1">
   <input type="hidden" name="URL" value="/">

JS:

function encode() 
{   
    // sets the hidden field value to whatever md5 returns.
    document.submitForm.encoded.value = document.logonForm.username.value   ":"   md5(document.logonForm.username.value   ":"   document.logonForm.password.value   ":"   document.submitForm.nonceA.value);
    /* Dont used */
    document.submitForm.URL.disabled = true;
}

CodePudding user response:

Have you tried md5 function from Digest::MD5?

use Digest::MD5 qw(md5)
use WWW::Mechanize;

my $encoded = $username . ':' . md5($username . ':' . $password . ':' . $nonce);
$mech->post(
    $url,
    Content => {
        'encoded' => $encoded,
        'nonceA' => $nonce,
        ....
    },
);

CodePudding user response:

I noticed that the "nonceA" value is never set so I copied the html and js dependencies and ran the html locally. I used window.prompt(document.submitForm.encoded.value); in the html to see what is being sent. I then copied this value to my perl script and set the "encoded" value acordingly:

my $form = $mech->form_name('submitForm');
$form->value('encoded', '<copied here>');

Afterwards I submitted using:

$mech->submit_form();

This did the trick for me.

  • Related