Mimicking a login form...

903 Views Asked by At

We have an internal application that requires the same username/password across the board.

However, if the login fails too many times, then the account is locked for that username.

We can't change the lockout because that will affect the public facing site as well.

I have been asked to come up with a way to essentially, click a button and auto-login.

Initial research has brought me to this script... (Credit)

<!doctype html>
    <!-- saved from url=(0014)about:internet -->

    <html>
    <title>Auto Login</title>
    </head>
    <body>
    <form id="loginForm" name="loginForm" method="post"    action="http://mail.google.com">
    <select name="uni_url" id="logServer" class="validate[required]">
    <option  class=""  value="" fbUrl=""  cookieName=""  >
            Test_en
    </option>
    </select>
    <input id="loginName" name="name" type="text" value="Username" class="" />
    <input id="loginPassword" name="password" type="password" value="ExamplePassword" class="" />
    <input type="hidden" id="loginKid" name="kid" value=""/>
                        </form>
  <script>document.loginForm.submit();</script>       
  </body></html>

...but I can't seem to get it to work for me.

So, I found another option where I can create a small html file (form) with a submit button, that does - onload="form1.submit();", and this could basically log me into this website without having to key in any login information.

Not sure where to start with mimicking a login form like this and need a good direction to get started in.

Thoughts?

1

There are 1 best solutions below

6
On

Let's assume your existing login form looks like this:

<form action="/login.php" method="post" id="loginform">
    <input type="text"     name="username" />
    <input type="password" name="password" />
    <input type="submit" />
</form>

On your "auto-login" (which is really an auto-submit) page you want to mimic the same structure as before but:

  • Add in values to be submitted (static username and password?)
  • Optionally remove the submit button (if you know your users have JS enabled then you can get rid).
  • Add some JS that automagically submits the form for you.

That might give us something like this:

<form action="/login.php" method="post" id="loginform">
    <input type="text"     name="username" value="gvee" />
    <input type="password" name="password" value="hunter2" />
</form>
<script type="text/javascript">document.forms[0].submit()</script>

The javascript will essentially look for the first form on the page (forms[0]) and submit that.


Update

Upon further inspection your existing login form is a bit of a funny onion. Instead of submitting the form directly, it's calling a function called doLogin() that sets certain hidden properties.

Therefore, instead of submitting the form, we should mimic the same behaviour (i.e. call doLogin() instead of .submit()).

One key thing here is that you'll want to only call the function after it has been declared. Simplest solution is to put our added bit of script at the very bottom of the HTML.

<script type="text/javascript">doSubmit();</script>