Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send authentication log to the syslog #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dedicated function to factorize code can be defined I think.

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Syslog server isn't reachable, PHP-error can be triggered. Several control need to be added I think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syslog server and port can be defined in the config.php file as constant.

socket_close($sock);
exit;
} else {
echo "<span class='success'>" . AUTHENTICATION_SUCCESS_REDIRECT . "&nbsp;&nbsp;&nbsp;</span><img src='./images/loading-login.gif' />";
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']})";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message isn't the right one. It's not a failure in this case, but a success, no ? :)

$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
socket_close($sock);
exit;
exit;
}
}
Expand Down