Jump to content

Can't access a page using curl, please help


dMilesFox

Recommended Posts

I'm new on this so I will start...

 

I'm trying to access a cgi page on another server, this page has a username and password fields, I know I need to call the url on the action and not the page where the form its located. Everything its working fine but, The response I get its, invalid username or password, thats the html msg I got everything I tried to run the script. I think the problem its with a cookie cuz if I tried to access the form manually and set the username and password by hand, I can log in. I took a quick view, and the html form on that page calls a function on the "onsubmit" form tag attribute. This function creates a cookie. That's why I think my curl script its not working.

 

How can I tell the remote site to set the cookie with curl??? its there any possible way?

 

Here is the php code

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://domain.name/path/to/login.cgi');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$post_data['username']  = 'LOGINNAME';
$post_data['password']  = 'PASSWORD';
$post_data['btnSubmit'] = 'SUBMIT';

foreach ( $post_data as $key => $value) {
	$post_items[] = $key . '=' . $value;
}
$post_string = implode('&', $post_items);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); 

$data  = curl_exec($ch);

print_r(curl_multi_getcontent($ch));
curl_close($ch); 


?>

 

And here is the html form code

<html>
<head>
<meta http-equiv="Content-Language">
<meta http-equiv="Content-Type" content="text/html">
<meta name="robots" content="none">
<title>Secure Access SSL VPN</title>
<script src="/dana-na/css/ds.js"></script>
<script>
        WriteCSS();
</script>
<noscript>
<link rel="stylesheet" href="/dana-na/css/ds.css">
</noscript>
<script>
<!--
if (window.top != self) {
top.location = location;
}
if(window.name == "newpincancel" || window.name == "nexttokencancel") {
   window.close();
}
//--></script>
<script src="/dana-na/auth/lastauthserverused.js"></script>
<script>function deletepreauth() {
    document.cookie = "DSPREAUTH="+ escape("")+ ";path=/dana-na/;expires=12-Nov-1996";
}
</script>
</head><body onLoad="FinishLoad(1)" bgcolor="#FFFFFF" color="#000000" link="#3366CC" vlink="#CC6699" alink="#3366CC" leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<table border="0" width="100%" cellspacing="0" cellpadding="3">
  <tr>
    <td bgcolor="#336699"><img border="0" src="welcome.cgi?p=logo&signinId=url_default" alt="Logo"></td>
    <td bgcolor="#336699" align="right"> </td>
  </tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td bgcolor="#000000" colspan="2"><img border="0" src="/dana-na/imgs/space.gif" width="1" height="1"></td>
  </tr>
</table>
<blockquote>
  <form name="frmLogin" action="login.cgi" method="POST" autocomplete="off" onSubmit="return Login(1)">
    <input type="hidden" name="tz_offset">
    <table border="0" cellpadding="2" cellspacing="0">
      <tr>
        <td nowrap  colspan="3"><b>Welcome to the</b></td>
      </tr>
      <tr>
        <td nowrap  colspan="3"><span class="cssLarge"><b>Secure Access SSL VPN</b></span></td>
      </tr>
      <tr>
        <td colspan="3"> </td>
      </tr>
      <tr>
        <td colspan="3"><table cellpadding="1" bgcolor="#cccc99">
            <tr>
              <td><table cellpadding="2" bgcolor="#FFFFCC">
                  <tr>
                    <td>Invalid username or password. Please re-enter your user information. </td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td valign="top"><table border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td>Username</td>
              <td> </td>
              <td><input type="text" name="username" size="20"></td>
            </tr>
            <tr>
              <td>Password</td>
              <td> </td>
              <td><input type="password" name="password" size="20"></td>
            </tr>
            <tr>
              <input type="hidden" name="realm" value="Costa Rica">
            </tr>
            <tr>
              <td colspan="3"> </td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
              <td><input type="submit" value="Sign In" name="btnSubmit">
                 </td>
            </tr>
          </table></td>
        <td valign="top">      </td>
        <td valign="top">
        <table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td>Please sign in to begin your secure session.
          </tr>
          </td>
        </table>
        </td>
      </tr>
    </table>
  </form>
</blockquote>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
    <td background="/dana-na/imgs/footerbg.gif"><table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
          <td><img src="/dana-na/imgs/space.gif" width="10" height="10"></td>
          <td><img src="/dana-na/imgs/space.gif" width="1" height="2"></td>
          <td><img src="/dana-na/imgs/space.gif" width="10" height="10"></td>
        </tr>
        <tr valign="top">
          <td><img src="/dana-na/imgs/space.gif" width="10" height="1"></td>
          <td nowrap ><br>
            <br>
            <br>
            <br>
          <td align="right"><img src="/dana-na/imgs/space.gif" width="10" height="10"></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td colspan="2"><img border="0" src="/dana-na/imgs/space.gif" height="6" width="1" alt=""></td>
  </tr>
</table>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.