Send authentication log to the syslog#29
Conversation
if you want, I've added a method to send logs (Public IP and username) during authentication.
|
Hello @j1pe, Thank you for the PR, it's a good idea ! Plus, in your code added, I think you need to:
Available to discuss it, I think it's a good feature. If you can adjust your pull request, I would integrate and merge it with the project. Thank you ! |
| echo "<script type='text/javascript'>document.location='./';</script>"; | ||
| #sending a log to the syslog when authentication is correct | ||
| $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
| $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})"; |
There was a problem hiding this comment.
I think this message isn't the right one. It's not a failure in this case, but a success, no ? :)
| $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
| $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})"; | ||
| $len = strlen($msg); | ||
| socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514); |
There was a problem hiding this comment.
If the Syslog server isn't reachable, PHP-error can be triggered. Several control need to be added I think.
| echo "<span class='error'>" . AUTHENTICATION_ERROR_CREDENTIAL . "</span>"; | ||
| #sending a log to the syslog when authentication is incorrect | ||
| $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
| $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})"; |
There was a problem hiding this comment.
The $_SERVER['HTTP_X_FORWARDED_FOR'] and $_POST['user'] are defined client(attacker)-side, so it's necessary to add more control / check / sanitization over these variables to prevent log injection attack.
| $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
| $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})"; | ||
| $len = strlen($msg); | ||
| socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514); |
There was a problem hiding this comment.
Syslog server and port can be defined in the config.php file as constant.
| sleep(2); | ||
| if(!checkAuthentication(trim(strval($_POST['user'])), trim(strval($_POST['pass'])))){ | ||
| echo "<span class='error'>" . AUTHENTICATION_ERROR_CREDENTIAL . "</span>"; | ||
| #sending a log to the syslog when authentication is incorrect |
There was a problem hiding this comment.
A dedicated function to factorize code can be defined I think.
|
Hello, |
|
Hi, So, I created a function allowing to send log to the Syslog server with verification of the values to have no injection. I updated the index.php by only using the function |
if you want, I've added a method to send logs (Public IP and username) during authentication to a syslog with udp socket.