From a11f2ef1e01cfd26b8c8515c1f348e2cfb791d97 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 6 Jul 2024 11:59:47 +0200 Subject: Refactoring, make function to save credentials. --- src/process-request.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/process-request.php b/src/process-request.php index fd290ce..bbc1e4b 100644 --- a/src/process-request.php +++ b/src/process-request.php @@ -7,6 +7,13 @@ use VolseNet\Webtrap\XmlRpcMethod; +function save_credentials(string $user, string $pass): void +{ + $file_name = dirname(__DIR__) . '/payloads/credentials.txt'; + $file = new SplFileObject($file_name, 'a'); + $file->fwrite("{$user}: {$pass}\n"); +} + $data = [ 'SERVER_NAME' => $_SERVER['SERVER_NAME'], 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], @@ -24,10 +31,8 @@ $data = [ if (preg_match('/xmlrpc\.php/i', $data['REQUEST_URI']) && $data['REQUEST_METHOD'] === 'POST') { $method = XmlRpcMethod::parse($data['BODY']); if ($method->name === 'wp.getUsersBlogs') { - $file_name = dirname(__DIR__) . '/payloads/credentials.txt'; - $file = new SplFileObject($file_name, 'a'); - $file->fwrite("{$method->params[0]}: {$method->params[1]}\n"); - error_log("Trapped XML-RPC request, saving credentials to {$file_name}"); + save_credentials($method->params[0], $method->params[1]); + error_log("Trapped XML-RPC request: saved credentials"); header("HTTP/1.1 404 Not Found"); die(); -- cgit v1.2.3