-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
TACACS: Don't send sshd's bad password to AAA #9310
Merged
renukamanavalan
merged 1 commit into
sonic-net:202012
from
renukamanavalan:pam_passwd_202012
Nov 20, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
src/tacacs/pam/0007-handle-bad-password-set-by-sshd.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
From f2687e7a442c83e19190695021fb9a60fe07ba60 Mon Sep 17 00:00:00 2001 | ||
From: Renuka Manavalan <[email protected]> | ||
Date: Wed, 17 Nov 2021 02:31:45 +0000 | ||
Subject: [PATCH] handle bad password set by sshd | ||
|
||
--- | ||
pam_tacplus.c | 11 +++++++++-- | ||
support.c | 37 +++++++++++++++++++++++++++++++++++++ | ||
support.h | 1 + | ||
tacc.c | 4 ++-- | ||
4 files changed, 49 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/pam_tacplus.c b/pam_tacplus.c | ||
index ec8ea27..014421b 100644 | ||
--- a/pam_tacplus.c | ||
+++ b/pam_tacplus.c | ||
@@ -251,6 +251,13 @@ int pam_sm_authenticate (pam_handle_t * pamh, int flags, | ||
return PAM_CRED_INSUFFICIENT; | ||
} | ||
|
||
+ if (validate_not_sshd_bad_pass(pass) != PAM_SUCCESS) { | ||
+ syslog(LOG_ERR, "auth fail: Password incorrect"); | ||
+ memset(pass, 0, strlen (pass)); | ||
+ free(pass); | ||
+ return PAM_AUTH_ERR; | ||
+ } | ||
+ | ||
retval = pam_set_item (pamh, PAM_AUTHTOK, pass); | ||
if (retval != PAM_SUCCESS) { | ||
_pam_log(LOG_ERR, "unable to set password"); | ||
@@ -483,7 +490,7 @@ int pam_sm_authenticate (pam_handle_t * pamh, int flags, | ||
syslog(LOG_DEBUG, "%s: exit with pam status: %d", __FUNCTION__, status); | ||
|
||
if (NULL != pass) { | ||
- bzero(pass, strlen (pass)); | ||
+ memset(pass, 0, strlen (pass)); | ||
free(pass); | ||
pass = NULL; | ||
} | ||
@@ -979,7 +986,7 @@ finish: | ||
syslog(LOG_DEBUG, "%s: exit with pam status: %d", __FUNCTION__, status); | ||
|
||
if (NULL != pass) { | ||
- bzero(pass, strlen(pass)); | ||
+ memset(pass, 0, strlen (pass)); | ||
free(pass); | ||
pass = NULL; | ||
} | ||
diff --git a/support.c b/support.c | ||
index 3e55e2f..09d09bf 100644 | ||
--- a/support.c | ||
+++ b/support.c | ||
@@ -108,6 +108,43 @@ int converse(pam_handle_t * pamh, int nargs, const struct pam_message *message, | ||
return retval; | ||
} | ||
|
||
+/* | ||
+ * Ref: From <https://groups.google.com/g/mailing.unix.openssh-dev/c/ViHvtciKYh0> | ||
+ * For future archive searchers: | ||
+ * > Why does OpenSSH replaces the password entered by the user with the | ||
+ * > bad password - "\b\n\r\177INCORRECT | ||
+ * | ||
+ * There are some situations where sshd determines a user can't log in. | ||
+ * Typical samples of that are DenyUsers or PermitRootLogin. | ||
+ * In those cases sshd *still* calls PAM, so that delays set by it are | ||
+ * still performed to the user (without leaking info about accounts | ||
+ * existing, disabled, etc.). But in order to ensure it can't succeed, | ||
+ * replaces the password with that impossible one. | ||
+ * | ||
+ */ | ||
+int validate_not_sshd_bad_pass(const char *pass) | ||
+{ | ||
+ const char *SSHD_BAD_PASS = "\010\012\015\177INCORRECT"; | ||
+ const int SSHD_BAD_PASS_LEN = strlen(SSHD_BAD_PASS); | ||
+ | ||
+ int len = strlen(pass); | ||
+ const char *p = pass; | ||
+ | ||
+ if (len == 0) | ||
+ return PAM_SUCCESS; | ||
+ | ||
+ while (len > 0) { | ||
+ int l = len < SSHD_BAD_PASS_LEN ? len : SSHD_BAD_PASS_LEN; | ||
+ | ||
+ if (strncmp(p, SSHD_BAD_PASS, l) != 0) | ||
+ return PAM_SUCCESS; | ||
+ | ||
+ len -= l; | ||
+ p += l; | ||
+ } | ||
+ return PAM_AUTH_ERR; | ||
+} | ||
+ | ||
/* stolen from pam_stress */ | ||
int tacacs_get_password (pam_handle_t * pamh, int flags | ||
,int ctrl, char **password) { | ||
diff --git a/support.h b/support.h | ||
index 09b8a85..cb04a4f 100644 | ||
--- a/support.h | ||
+++ b/support.h | ||
@@ -42,6 +42,7 @@ extern struct addrinfo *tac_source_addr; | ||
int _pam_parse (int, const char **); | ||
unsigned long _resolve_name (char *); | ||
unsigned long _getserveraddr (char *serv); | ||
+int validate_not_sshd_bad_pass(const char *pass); | ||
int tacacs_get_password (pam_handle_t *, int, int, char **); | ||
int converse (pam_handle_t *, int, const struct pam_message *, struct pam_response **); | ||
void _pam_log (int, const char *, ...); | ||
diff --git a/tacc.c b/tacc.c | ||
index fcc7d8c..bf0f2a3 100644 | ||
--- a/tacc.c | ||
+++ b/tacc.c | ||
@@ -181,7 +181,7 @@ int main(int argc, char **argv) { | ||
break; | ||
case 'L': | ||
// tac_login is a global variable initialized in libtac | ||
- bzero(tac_login, sizeof(tac_login)); | ||
+ memset(tac_login, 0, sizeof(tac_login)); | ||
strncpy(tac_login, optarg, sizeof(tac_login) - 1); | ||
break; | ||
case 'p': | ||
@@ -312,7 +312,7 @@ int main(int argc, char **argv) { | ||
} | ||
|
||
/* we no longer need the password in our address space */ | ||
- bzero(pass, strlen(pass)); | ||
+ memset(pass, 0, strlen(pass)); | ||
pass = NULL; | ||
|
||
if (do_account) { | ||
-- | ||
2.17.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep it as 0010 as the master commit? Then later if we decide to backport more patches, others will be easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. As master has diverged well with 3 patches, this patch had to be manually re-created. The contents of 0010 & 0007 are different but for the same purpose. Similarly, in future, if we would need any patch from master it has to be re-created manually. The title of the patch would indicate the patch purpose, which is same in both master & here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for misleading. Is it possible to keep original file name
../0010-handle-bad-password-set-by-sshd.patch
? I am okay if the file content changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got your point.
The number is just meant for sequence of application. So here, this patch has to be applied after 0006, hence 0007.