如何发送获取表单并接收数据

时间:2017-01-24 11:32:42

标签: javascript php jquery html curl

好吧,我实际上是作为一家公司的测试人员,我发现网站上有一个错误,他们生成csrf令牌,因为我们收到了对此页面localhost/csrf-token的请求并发出了csrf令牌在未加密的文本中 要获得正确的csrf令牌,需要随请求一起发送用户的cookie 我尝试在我的POC中使用curl来获取作为令牌的请求的结果 但是cookie并没有随请求一起发送 我发现请求可能被发送的唯一方法是使用普通表单,但我无法获得结果 卷曲代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://localhost/csrf-token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Requested-With: XMLHttpRequest'
));
$output = curl_exec ($ch);
curl_close ($ch);
echo $output;

我想要使用的正常get请求是

<form action="localhost/csrf-token" method="get">
<input type="submit" name="submit" value="send">
</form>

我的问题是如何获取第二个代码段的结果

1 个答案:

答案 0 :(得分:0)

curl_setopt($ch, CURLOPT_POSTFIELDS, 'parametsr');

使用它来添加参数。

由于您的表单只能发送一个参数。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://localhost/csrf-token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

 curl_setopt($ch, CURLOPT_POSTFIELDS, 'submit=send');

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Requested-With: XMLHttpRequest'
));
$output = curl_exec ($ch);
curl_close ($ch);
echo $output;

将是表格请求。 或者只是更改URL,因为您的请求是GET

https://localhost/csrf-token?submit=send

但是,我认为该请求还需要cookie来生成令牌。