forked from ambionics/phpggc
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathGadgetChain.php
83 lines (70 loc) · 2.01 KB
/
GadgetChain.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
<?php
namespace PHPGGC;
abstract class GadgetChain
{
public $name;
public static $type;
public $version = '?';
# Vector to start the chain: __destruct, __toString, offsetGet, etc.
public $vector = '';
public $author = '';
public $parameters = [];
public $informations;
# Types
const TYPE_RCE = 'rce';
const TYPE_FI = 'file_include';
const TYPE_FR = 'file_read';
const TYPE_FW = 'file_write';
const TYPE_FD = 'file_delete';
const TYPE_SQLI = 'sql_injection';
public function __toString()
{
$infos = [
'Name' => $this->get_name(),
'Version' => $this->version,
'Type' => self::$type,
'Vector' => $this->vector
];
$strings = [];
if($this->informations)
{
$informations = trim($this->informations);
$informations = preg_replace("#\n\s+#", "\n", $informations);
$infos['Informations'] = "\n" . $informations;
}
foreach($infos as $k => $v)
{
$strings[] = str_pad($k, 15) . ': ' . $v;
}
return implode("\n", $strings);
}
public function get_name()
{
$class = get_class($this);
$class = substr($class, strpos($class, '\\') + 1);
$class = str_replace('\\', '/', $class);
return $class;
}
public function load_gadgets()
{
$file = dirname((new \ReflectionClass($this))->getFileName());
require $file . '/gadgets.php';
}
/**
* Modifies given parameters if required.
*/
public function pre_process(array $parameters)
{
return $parameters;
}
abstract public function generate(array $parameters);
/**
* Changes some values in the unserialize payload.
* For instance, if a class is meant to be named A\B\C but has been named
* A_B_C in the gadget for convenience, it can be str_replace()d here.
*/
public function post_process($payload)
{
return $payload;
}
}