Privilege escalation occurs when a malicious user exploits a bug, design flaw, or configuration error in an application or operating system to gain elevated access to the system. Elevated privileges can be used to delete files, view private information, or install unwanted programs or backdoors.
1def set_user_noncompliant():
2 import os
3 root = 0
4 # Noncompliant: the process user is set to root.
5 os.setuid(root)
1def set_user_compliant():
2 import os
3 root = 4
4 # Compliant: the process user is set to userid 4.
5 os.setuid(root)