-
Notifications
You must be signed in to change notification settings - Fork 0
/
reboot.php
51 lines (39 loc) · 1.5 KB
/
reboot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Script that reboots TP Link Archer C7
*
* Based on reverse engineering of TP Link admin web interface
*/
$username = 'username';
$password = 'password';
/** IP address of the router */
$baseUrl = '192.168.0.1';
/** URL of login endpoint */
$loginUrl = 'userRpm/LoginRpm.htm?Save=Save';
/** URL of reboot endpoint */
$rebootUrl = 'userRpm/SysRebootRpm.htm';
/** Options needed for reboot endpoint to perform reboot */
$rebootOpt = 'Reboot=Reboot';
/** Router uses Basic authentication, generate a cookie for that */
$auth = "Basic " . base64_encode($username . ':' . md5($password));
$cookie = "Authorization=" . rawurlencode($auth) . ";path=/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://' . $baseUrl . '/' . $loginUrl);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
//curl_setopt($ch, CURLOPT_FAILONERROR, true);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/** This is important, without correct referer this will not work */
curl_setopt($ch, CURLOPT_REFERER, $baseUrl);
$session = curl_exec($ch);
/**
* The request will return some HTML with JavaScript in it. We need to extract sessionID from that
* HTML code using regex
*/
preg_match('/http:\/\/' . $baseUrl . '\/([a-zA-Z0-9]+)\//', $session, $matches);
/** Construct actual URL to reboot and set new referer */
$url = $baseUrl . '/' . $matches[1] . '/' . $rebootUrl;
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_URL, $url . '/' . $rebootOpt);
/** That should be it */
curl_exec($ch);
curl_close($ch);