前言
最近要打CTF的线下赛,写了个脚本作为WAF拦截流量并作流量转发。正好研究一下PHP如何使用file_get_contens()去发送POST包。正好中秋节无聊得爆炸,去年执行任务在火车上过了个中秋,今年回到地方,老友们都回家了,宿舍也是空无一人,其实就算宿舍有人也是一样,兴趣爱好不一样,自己也沉迷于技术研究,不玩游戏,不看球的。
Demo
<?php
$data = array(
'username'=>'admin',
'password'=>'hplocation123*'
);
$query = http_build_query($data); //使用给出的关联(或下标)数组生成一个经过 URL-encode 的请求字符串。
$options['http'] = array(
'timeout'=>60,
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $query
);//构造一个post包
$url = "http://point.mycute.cn/login.php";
$context = stream_context_create($options);//创建并返回一个资源流上下文
$result = file_get_contents($url, false, $context);
echo htmlspecialchars($result);
?>