-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Promote py/pam-auth-bypass
#9108
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
Changes from 7 commits
0c53444
c84f693
7e87e18
f68b281
c890f9c
0956d50
044829c
b54de13
6611e5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
/** | ||
* @name Authorization bypass due to incorrect usage of PAM | ||
* @description Using only the `pam_authenticate` call to check the validity of a login can lead to a authorization bypass. | ||
* @name PAM authorization bypass due to incorrect usage | ||
* @description Not using `pam_acct_mgmt` after `pam_authenticate` to check the validity of a login can lead to authorization bypass. | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 8.1 | ||
* @precision high | ||
* @id py/pam-auth-bypass | ||
* @tags security | ||
|
@@ -33,4 +34,5 @@ where | |
acctMgmtCall = libPam().getMember("pam_acct_mgmt").getACall() and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not allowed to add a comment in the appropriate place, but there's a use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, that probably what the merge conflict is also about 👍 |
||
DataFlow::localFlow(handle, acctMgmtCall.getArg(0)) | ||
) | ||
select authenticateCall, "This PAM authentication call may be lead to an authorization bypass." | ||
select authenticateCall, | ||
"This PAM authentication call may be lead to an authorization bypass, since 'pam_acct_mgmt' is not called afterwards." | ||
RasmusWL marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
libpam = CDLL(find_library("pam")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's... Quite the formatting. 😮 |
||
|
||
pam_authenticate = libpam.pam_authenticate | ||
pam_authenticate.restype = c_int | ||
pam_authenticate.argtypes = [PamHandle, c_int] | ||
|
||
def authenticate(username, password, service='login'): | ||
def my_conv(n_messages, messages, p_response, app_data): | ||
""" | ||
Simple conversation function that responds to any prompt where the echo is off with the supplied password | ||
""" | ||
... | ||
|
||
handle = PamHandle() | ||
conv = PamConv(my_conv, 0) | ||
retval = pam_start(service, username, byref(conv), byref(handle)) | ||
|
||
retval = pam_authenticate(handle, 0) | ||
return retval == 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
libpam = CDLL(find_library("pam")) | ||
|
||
pam_authenticate = libpam.pam_authenticate | ||
pam_authenticate.restype = c_int | ||
pam_authenticate.argtypes = [PamHandle, c_int] | ||
|
||
pam_acct_mgmt = libpam.pam_acct_mgmt | ||
pam_acct_mgmt.restype = c_int | ||
pam_acct_mgmt.argtypes = [PamHandle, c_int] | ||
|
||
def authenticate(username, password, service='login'): | ||
def my_conv(n_messages, messages, p_response, app_data): | ||
""" | ||
Simple conversation function that responds to any prompt where the echo is off with the supplied password | ||
""" | ||
... | ||
|
||
handle = PamHandle() | ||
conv = PamConv(my_conv, 0) | ||
retval = pam_start(service, username, byref(conv), byref(handle)) | ||
|
||
retval = pam_authenticate(handle, 0) | ||
if retval == 0: | ||
retval = pam_acct_mgmt(handle, 0) | ||
return retval == 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: newQuery | ||
--- | ||
* The query "PAM authorization bypass due to incorrect usage" (`py/pam-auth-bypass`) has been promoted from experimental to the main query pack. Its results will now appear by default. This query was originally [submitted as an experimental query by @porcupineyhairs](https://github.com/github/codeql/pull/8595). |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
| pam_test.py:48:18:48:44 | ControlFlowNode for pam_authenticate() | This PAM authentication call may be lead to an authorization bypass. | | ||
| pam_test.py:48:18:48:44 | ControlFlowNode for pam_authenticate() | This PAM authentication call may be lead to an authorization bypass, since 'pam_acct_mgmt' is not called afterwards. | | ||
RasmusWL marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Security/CWE-285/PamAuthorization.ql |
Uh oh!
There was an error while loading. Please reload this page.