Jump to content

cURL POST form. Browser Spoofing!


daydreamer

Recommended Posts

I am trying to use curl to submit a form on web server using https.

 

I have a php file with the code, and an html file on my server, which is a clone of the form I am trying to post to.

 

When I manually fill out my html form, and click "Continue", it forwards all the fields I have entered to the https server page.

 

I am trying to get my php script to fill out and click continue for me so I can automatically fill out the forms.

 

MY html form, (clone of form I am posting to, which is on https://registration.co.uk/Registration/Create)

<form name="f" method="post" action="https://registration.co.uk/Registration/Create">

<input type="hidden" name="in_portalPreference" id="" value="P" size="24" maxLength="2" />
<input type="hidden" name="IAF_domainName" id="" value=" " size="24" maxLength="15" />
<input type="hidden" name="PAF_VALIDATED_ADDRESS" id="" value="false" size="24" maxLength="15" />
<input type="hidden" name="page_name" id="" value="../Registration/Create" size="24" maxLength="25" />
Forename:
<input type="text" name="in_forename" id="in_forename" value="" size="15" maxLength="15" />

Lastname:
<input type="text" name="in_lastname" id="in_lastname" value="" size="15" maxLength="15" />

//lots of other fields here (similar to the name fields)

<input type="submit" id="submit" name="submit" value="Continue" title="Done" />

 

PHP code

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile123");
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile123"); # SAME cookiefile
curl_setopt($curl, CURLOPT_URL, "localhost/register.html"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, "in_lastname=Mubs&in_forename=John&submit=Continue");
curl_exec($curl); // execute above and send it to my form

curl_setopt($curl, CURLOPT_URL, "https://registration.co.uk/Registration/Create"); // execute 'action' my html form, posting details to                                                                                                                                                 
$xxx = curl_exec($curl);                                                                                // this page.

echo $xxx;
curl_close ($curl);
?>

 

When I manually fill out my html form and click continue in my browser, it forwards the fields to https://registration.co.uk/Registration/Create with no problem.

 

When I run my php file, the server I am posting to says that an error has occurred, but does not specify why.

 

I think it is because my php code is not spoofing a browser good enough, and the server knows that is is a script so it rejects the request.

 

 

My questions are:

 

A) Is my script spoofing a browser correctly, and are the settings correct.

 

B) Are the settings correct for posting to https forms?

 

C) What else should/shouldent I be doing!?

 

 

Thanks for the help.

 

 

 

Link to comment
Share on other sites

try this:

 

<?php
if(!isset($_POST['submit'])){
// echo your form
?>
<form name="f" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="hidden" name="in_portalPreference" id="" value="P" size="24" maxLength="2" />
<input type="hidden" name="IAF_domainName" id="" value=" " size="24" maxLength="15" />
<input type="hidden" name="PAF_VALIDATED_ADDRESS" id="" value="false" size="24" maxLength="15" />
<input type="hidden" name="page_name" id="" value="../Registration/Create" size="24" maxLength="25" />
Forename:
<input type="text" name="in_forename" id="in_forename" value="" size="15" maxLength="15" />

Lastname:
<input type="text" name="in_lastname" id="in_lastname" value="" size="15" maxLength="15" />

//lots of other fields here (similar to the name fields)

<input type="submit" id="submit" name="submit" value="Continue" title="Done" />
</form>
<?php
} else{
function Post($vars,$url){
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_POST,1);
        #curl_setopt($ch,CURLOPT_UPLOAD,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
        curl_exec($ch);
        curl_close($ch);
}

$url = "https://registration.co.uk/Registration/Create"; // Where you want the results to be posted to
$vars = "";

foreach($_POST as $name => $value){
$vars .= "&" . $name . "=" . $value;

Post($vars,$url);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.