Skip to content

Commit f8442cc

Browse files
committed
Python: Adjust PAM Auth bypass test slightly
1 parent fef0667 commit f8442cc

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
edges
2-
| pam_test.py:0:0:0:0 | ModuleVariableNode for pam_test.request | pam_test.py:70:16:70:22 | ControlFlowNode for request |
2+
| pam_test.py:0:0:0:0 | ModuleVariableNode for pam_test.request | pam_test.py:71:16:71:22 | ControlFlowNode for request |
33
| pam_test.py:4:26:4:32 | ControlFlowNode for ImportMember | pam_test.py:4:26:4:32 | GSSA Variable request |
44
| pam_test.py:4:26:4:32 | GSSA Variable request | pam_test.py:0:0:0:0 | ModuleVariableNode for pam_test.request |
5-
| pam_test.py:70:16:70:22 | ControlFlowNode for request | pam_test.py:70:16:70:27 | ControlFlowNode for Attribute |
6-
| pam_test.py:70:16:70:27 | ControlFlowNode for Attribute | pam_test.py:75:14:75:40 | ControlFlowNode for pam_authenticate() |
5+
| pam_test.py:71:16:71:22 | ControlFlowNode for request | pam_test.py:71:16:71:27 | ControlFlowNode for Attribute |
6+
| pam_test.py:71:16:71:27 | ControlFlowNode for Attribute | pam_test.py:76:14:76:40 | ControlFlowNode for pam_authenticate() |
77
nodes
88
| pam_test.py:0:0:0:0 | ModuleVariableNode for pam_test.request | semmle.label | ModuleVariableNode for pam_test.request |
99
| pam_test.py:4:26:4:32 | ControlFlowNode for ImportMember | semmle.label | ControlFlowNode for ImportMember |
1010
| pam_test.py:4:26:4:32 | GSSA Variable request | semmle.label | GSSA Variable request |
11-
| pam_test.py:70:16:70:22 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
12-
| pam_test.py:70:16:70:27 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
13-
| pam_test.py:75:14:75:40 | ControlFlowNode for pam_authenticate() | semmle.label | ControlFlowNode for pam_authenticate() |
11+
| pam_test.py:71:16:71:22 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
12+
| pam_test.py:71:16:71:27 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
13+
| pam_test.py:76:14:76:40 | ControlFlowNode for pam_authenticate() | semmle.label | ControlFlowNode for pam_authenticate() |
1414
subpaths
1515
#select
16-
| pam_test.py:75:14:75:40 | ControlFlowNode for pam_authenticate() | pam_test.py:4:26:4:32 | ControlFlowNode for ImportMember | pam_test.py:75:14:75:40 | ControlFlowNode for pam_authenticate() | This PAM authentication call may lead to an authorization bypass, since `pam_acct_mgmt` is not called afterwards. |
16+
| pam_test.py:76:14:76:40 | ControlFlowNode for pam_authenticate() | pam_test.py:4:26:4:32 | ControlFlowNode for ImportMember | pam_test.py:76:14:76:40 | ControlFlowNode for pam_authenticate() | This PAM authentication call may lead to an authorization bypass, since `pam_acct_mgmt` is not called afterwards. |

python/ql/test/query-tests/Security/CWE-285-PamAuthorization/pam_test.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,30 @@ class PamConv(Structure):
3939
pam_acct_mgmt.argtypes = [PamHandle, c_int]
4040

4141

42-
class pam():
42+
def authenticate_bad_but_no_alert(self, username, service='login'):
43+
# This is not OK, but since we don't have flow from a remote-flow-source, we
44+
# don't give an alert.
45+
handle = PamHandle()
46+
conv = PamConv(None, 0)
47+
retval = pam_start(service, username, byref(conv), byref(handle))
48+
retval = pam_authenticate(handle, 0)
49+
# NOT OK: no call to `pam_acct_mgmt`
50+
auth_success = retval == 0
4351

44-
def authenticate_bad_but_good(self, username, service='login'):
45-
handle = PamHandle()
46-
conv = PamConv(None, 0)
47-
retval = pam_start(service, username, byref(conv), byref(handle))
48-
# This is not fine but we don't alert here as there is a possibility that the function is not actually used
49-
retval = pam_authenticate(handle, 0)
50-
auth_success = retval == 0
52+
return auth_success
5153

52-
return auth_success
5354

54-
def authenticate_good(self, username, service='login'):
55-
handle = PamHandle()
56-
conv = PamConv(None, 0)
57-
retval = pam_start(service, username, byref(conv), byref(handle))
55+
def authenticate_good(self, username, service='login'):
56+
handle = PamHandle()
57+
conv = PamConv(None, 0)
58+
retval = pam_start(service, username, byref(conv), byref(handle))
5859

59-
retval = pam_authenticate(handle, 0)
60-
if retval == 0:
61-
retval = pam_acct_mgmt(handle, 0)
62-
auth_success = retval == 0
60+
retval = pam_authenticate(handle, 0)
61+
if retval == 0:
62+
retval = pam_acct_mgmt(handle, 0)
63+
auth_success = retval == 0
6364

64-
return auth_success
65+
return auth_success
6566

6667

6768
app = Flask(__name__)
@@ -73,10 +74,12 @@ def bad():
7374
retval = pam_start(service, username, byref(conv), byref(handle))
7475

7576
retval = pam_authenticate(handle, 0)
77+
# NOT OK: no call to `pam_acct_mgmt`
7678
auth_success = retval == 0
7779

7880
return auth_success
7981

82+
8083
@app.route('/good')
8184
def good():
8285
username = request.args.get('username', '')
@@ -89,4 +92,4 @@ def good():
8992
retval = pam_acct_mgmt(handle, 0)
9093
auth_success = retval == 0
9194

92-
return auth_success
95+
return auth_success

0 commit comments

Comments
 (0)