It all depends on the web server. When you request an address like http://webapp.thm/index.php?page=1
(I'm assuming the extra =
was a typo) your browser opens a connection to webapp.thm
port 80
, and sends a data packet like this:1
GET /index.php?page=1 HTTP/1.1
Host: webapp.thm
User-Agent: AwesomeBrowser/1.0 (like Firefox)
Accept-Language: en
... more metadata and cookies go here ...
This is the only part that's standardized. What the server does with this request, is up to the server. A very basic server would look for a page called /index.php?page=1
and give a 404 response because there isn't one. A slightly more sophisticated server would know that everything after ?
is parameters for the page and not part of the filename, so it would look for a page called /index.php
.
However, we can infer this is not a very basic server. The .php
file extension strongly indicates2 this server is using a piece of software called PHP, which is a script interpreter that generates HTML pages on-demand based on PHP scripts. There's no general way to know this - you have to have some basic familiarity with what PHP is. You could probably find it out by Googling the .php
file extension.
When a server with PHP installed gets a request for a file it recognizes as a PHP file, it does not simply send the file contents to the client, like an HTML file. Instead, it runs the script. Whatever the script outputs is then sent to the client. If it's written to do so, the script has the ability to access various information, like the current date and time, the client's IP address, the User-Agent
, Accept-Language
and other metadata, cookies, ?
parameters and so on. It runs on the server, so it can access databases and other files stored on the server.
And so you have the possibility that someone wrote a script that has a vulnerability. For example, I once wrote a simple script download.php
so that /download.php?file=foo.zip
would increment the download counter for foo.zip
and then send the contents of foo.zip
. The script looks approximately like this:
<?php
$file = $_GET["file"]; // access the ?file= parameter
// not showing how is_valid_filename is defined
if (!is_valid_filename($file) || !file_exists($file)) {
http_response_code(404);
Header("Content-Type: text/plain");
print "error";
} else {
$db = open_database();
db_query($db, "update downloads where filename=? set counter=counter+1", [$file]);
db_close($db);
Header("Content-Type: application/octet-stream");
readfile($file); // outputs the contents of the file
}
?>
If that script did not validate the filename as a valid filename to download, it would be possible that someone could request /download.php?file=/etc/passwd
and get the contents of /etc/passwd
because the script would call readfile("/etc/passwd");
which is supposed to send the contents of /etc/passwd to the client. This has nothing to do with the client, the server, or HTTP, really - it would have everything to do with a faulty script. In hindsight this script could have used an HTTP redirect instead of readfile
- that would be even safer.
1 In HTTP/1.1 this is literally the data packet. It's not a human-readable translation - the packet is human-readable by itself. HTTP/2.0 uses a non-human-readable format to make it faster, but it basically sends the same data.
2 There's no guaranteed connection between the .php
file extension and the PHP software. It's just a convention. They could choose to configure their copy of PHP so that files with .script
or .html
extensions run the PHP software, and they could choose to configure some other software to use .php
extensions. But it is a strong indication.
index.php=?...
is quite a different request fromindex.php?...
. I'd be curious if that's the actual URL provided or a typo.