Skip to content

Commit 87eadb3

Browse files
authored
Add files via upload
1 parent f83706b commit 87eadb3

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Watcher
2+
3+
Watcher tracks referrer page, IP address, date/time and user agent data before discreetly redirecting to the indended URL.
4+
5+
# Setup
6+
7+
## Hosting
8+
9+
PHP has a [built-in web server](https://www.php.net/manual/en/features.commandline.webserver.php) which can be used to spin up a server immediately for testing purposes.
10+
11+
$ git clone https://github.com/safesploit/Watcher.git
12+
$ cd Watcher
13+
$ php -S localhost:8080 index.php
14+
15+
We can now access Watcher via `http://localhost:8080`
16+
17+
## URL Formatting
18+
19+
Using the GET variable `s` we can specify the header address to redirect the user to.
20+
21+
http://localhost:8080/index.php?s=safesploit.com
22+
23+
Watcher will log information in `log.txt` and then redirect the user to `http://google.com`.
24+
25+
Alternatively the shorter form `http://localhost:8080/?s=safesploit.com` can be used.
26+
27+
# Example log
28+
29+
`Logged IP address: 127.0.0.1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36 Reffered by: Parameter: safesploit.com Date logged: Friday 29th 2022f July 2022 07:33:38 PM`
30+
31+
## Watcher v1.1.0
32+
Since v1.1.0 full URLs can be provided via the `s` parameter without significant issue
33+
34+
`Logged IP address: 127.0.0.1, User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36, Referred by: , Parameter: https://www.safesploit.com, Date logged: Saturday 30th 2022f July 2022 05:56:57 PM`
35+
36+
The supplied URL is as follows:
37+
38+
http://localhost:8080/index.php?s=https://www.safesploit.com
39+
40+
41+
## Potential Issues
42+
Because `www.safesploit.com` will redirect HTTP request to HTTPS the code logic `header( "Location: http://" . $_GET['s'], TRUE, 301 )` works fine.
43+
44+
But for web servers which only use HTTPS and do not redirect HTTP requests issues will occur.

index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
require('watcher.php');
3+
4+
watcher();
5+
?>

watcher.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
function getIPAddress()
3+
{
4+
// IP logging
5+
$register_globals = (bool) ini_get('register_gobals');
6+
if ($register_globals)
7+
$ip = getenv(REMOTE_ADDR);
8+
else
9+
$ip = $_SERVER['REMOTE_ADDR'];
10+
11+
return $ip;
12+
}
13+
14+
function redirect()
15+
{
16+
$url = parameterValidator();
17+
18+
header( "Location: " . $url, TRUE, 301 );
19+
}
20+
21+
function referred()
22+
{
23+
if(isset($_SERVER['HTTP_REFERER']))
24+
$referred = $_SERVER['HTTP_REFERER'];
25+
else
26+
$referred = "NULL";
27+
}
28+
29+
function parameter()
30+
{
31+
if (isset($_GET['s']) && $_GET['s'] != "")
32+
return $_GET['s'];
33+
else
34+
exit;
35+
}
36+
37+
function parameterValidator()
38+
{
39+
//Check if parameter() supplied is URL or URN
40+
41+
if(filter_var(parameter(), FILTER_VALIDATE_URL))
42+
$url = parameter();
43+
else
44+
{
45+
$protocol = "http://"; //assuming protocol is HTTP
46+
$url = $protocol . parameter();
47+
}
48+
49+
return $url;
50+
}
51+
52+
function userAgent()
53+
{
54+
return $_SERVER['HTTP_USER_AGENT'];
55+
}
56+
57+
58+
function watcher()
59+
{
60+
$logFilename="log.txt"; //log file
61+
$log=fopen("$logFilename", "a+");
62+
63+
$pattern = "/\btxt\b/i"; // only txt files
64+
$date=date("l dS of F Y h:i:s A");
65+
66+
$ip = getIPAddress();
67+
$userAgent = userAgent();
68+
$referred = referred();
69+
$param = parameter();
70+
71+
72+
$data =
73+
"Logged IP address: $ip, " .
74+
"User-Agent: $userAgent, " .
75+
"Referred by: $referred, " .
76+
"Parameter: $param, " .
77+
"Date logged: $date " .
78+
"\n";
79+
80+
if(preg_match($pattern, $logFilename))
81+
fputs($log, $data);
82+
83+
fclose($log); //close log
84+
85+
redirect();
86+
}
87+
?>

0 commit comments

Comments
 (0)