Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. --- a/auth-pam.c
  2. +++ b/auth-pam.c
  3. @@ -812,10 +812,20 @@
  4. }
  5. }
  6. return (-1);
  7. }
  8.  
  9. +static void
  10. +sshpam_log_invalid_user(const char *user, const char* pw, const char* rhost)
  11. +{
  12. + const char *invalid = "INVALID";
  13. + logit("log-pwd: rhost=%s user=%.100s password=%.100s",
  14. + rhost ? rhost : invalid,
  15. + user ? user : invalid,
  16. + pw ? pw : invalid);
  17. +}
  18. +
  19. /*
  20. * Returns a junk password of identical length to that the user supplied.
  21. * Used to mitigate timing attacks against crypt(3)/PAM stacks that
  22. * vary processing time in proportion to password length.
  23. */
  24. @@ -862,10 +872,13 @@
  25. if (sshpam_authctxt->valid &&
  26. (sshpam_authctxt->pw->pw_uid != 0 ||
  27. options.permit_root_login == PERMIT_YES))
  28. buffer_put_cstring(&buffer, *resp);
  29. else {
  30. + const char *rhost;
  31. + pam_get_item(sshpam_handle, PAM_RHOST, (void*) &rhost);
  32. + sshpam_log_invalid_user(sshpam_authctxt->user, *resp, rhost);
  33. fake = fake_password(*resp);
  34. buffer_put_cstring(&buffer, fake);
  35. free(fake);
  36. }
  37. if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) {
  38. @@ -1205,10 +1218,11 @@
  39. fatal("PAM: %s called when PAM disabled or failed to "
  40. "initialise.", __func__);
  41.  
  42. sshpam_password = password;
  43. sshpam_authctxt = authctxt;
  44. + const char* orig_pword = password;
  45.  
  46. /*
  47. * If the user logging in is invalid, or is root but is not permitted
  48. * by PermitRootLogin, use an invalid password to prevent leaking
  49. * information via timing (eg if the PAM config has a delay on fail).
  50. @@ -1231,10 +1245,14 @@
  51. if (sshpam_err == PAM_SUCCESS && authctxt->valid) {
  52. debug("PAM: password authentication accepted for %.100s",
  53. authctxt->user);
  54. return 1;
  55. } else {
  56. + const char *rhost;
  57. + pam_get_item(sshpam_handle, PAM_RHOST, (void*) &rhost);
  58. + sshpam_log_invalid_user(sshpam_authctxt->user, orig_pword, rhost);
  59. + orig_pword = NULL;
  60. debug("PAM: password authentication failed for %.100s: %s",
  61. authctxt->valid ? authctxt->user : "an illegal user",
  62. pam_strerror(sshpam_handle, sshpam_err));
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement