Spoofed HTTP Requests
HTTP 请求欺骗
A more powerful, although less convenient approach is to spoof an HTTP
request. In the example form just discussed, where the user chooses a color, the
resulting HTTP request looks like the following (assuming a choice of red):
HTTP 请求欺骗非常的强大,而且还很方便。在上面讨论到的那个让用户选择颜色示例中,
结果生成的 HTTP 请求看起来是这个样子的(假设用户选择了红色):
POST /process.php HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 9
color=red
The telnet utility can be used to perform some ad hoc testing. The following
example makes a simple GET request for http://www.php.net/:
telnet 工具能够用来执行这个用途的测试。
下面的例子执行了一个对 http://www.php.net/ 的简单的 GET 请求:
$telnet www.php.net 80
Trying 64.246.30.37...
Connected to rs1.php.net.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.php.net
HTTP/1.1 200 OK
Date: Wed,
21 May
2004 12:
34:
56 GMT
Server: Apache/1.3.26 (Unix) mod_gzip/1.3.26.1a
PHP/4.3.3-dev
X-Powered-By: PHP/4.3.3-dev
Last-Modified: Wed, 21 May 2004 12:34:56 GMT
Content-language: en
Set-Cookie: COUNTRY=USA%2C12.34.56.78; expires=Wed,
28-May-04 12:34:56 GMT; path=/; domain=.php.net
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1
2083
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
...
Of course, you can write your own client instead of manually entering requests
with telnet. The following example shows how to perform the same request
using PHP:
当然了,你也可以写一个你自己的客户端来替代在 telnet 里手动的输入那些请求指令。
下面的例子给你展示了如何用 PHP 完成相同的请求:
<?php
$http_response = '';
fputs($fp,
"GET / HTTP/1.1\r\n");
fputs($fp,
"Host: www.php.net\r\n\r\n");
{
$http_response .=
fgets($fp,
128);
}
?>
Sending your own HTTP requests gives you complete flexibility, and this
demonstrates why server-side data filtering is so essential. Without it, you have
no assurances about any data that originates from any foreign source.
发送你自己的 HTTP 请求可以给你最大的适应性。
这也证明了为什么服务器端的数据过滤这么的重要。
如果不进行服务器端数据过滤,所有的从外部过来的数据都是不保险的。