A group of researchers from the University of Turku (Finland) published the results of an analysis of packages in the PyPI repository for the use of potentially hazardous constructs that could lead to vulnerabilities. During the analysis of 197 thousand packages, 749 thousand potential security issues were identified. In 46% of the packages, at least one such issue was present. Among the most frequently encountered problems are shortcomings related to exception handling and the use of capabilities that allow code injection.
Of the identified 749 thousand issues, 442 thousand (41%) are marked as minor, 227 thousand (30%) as moderate, and 80 thousand (11%) as serious. Some packages stand out and contain thousands of issues: for example, the PyGGI package revealed 2589 problems, primarily related to the use of the 'try-except-pass' construct, while the appengine-sdk package found 2356 issues. A large number of problems are also present in the genie.libs.ops, pbcore, and genie.libs.parser packages.
It should be noted that the results were obtained based on automated static analysis, which does not take into account the context of the use of certain constructs. The developer of the bandit tool, which was used for code scanning, expressed the opinion that due to the relatively high number of false positives, the results of the check cannot be directly considered vulnerabilities without further manual review of each issue.
For example, the analyzer considers the use of unreliable random number generators and hashing algorithms such as MD5 to be a security problem, while in the code such algorithms may be used for purposes that do not impact security. The analyzer also considers any handling of external data in unsafe functions, such as pickle, yaml.load, subprocess, and eval, to be a problem, but this usage is not necessarily associated with the emergence of vulnerabilities, and in practice, the use of these functions can be implemented without security threats.
Among the checks used in the study:
- The use of potentially unsafe functions like exec, mktemp, eval, mark_safe, etc.
- Insecure file access permissions.
- Binding a network socket to all network interfaces.
- Using hardcoded passwords and keys.
- Using a predefined temporary directory.
- Using pass and continue in catch-all-style exception handlers.
- Running web applications based on the Flask web framework with debug mode enabled.
- Using unsafe data deserialization methods.
- Using MD2, MD4, MD5, and SHA1 hash functions.
- Using unsafe ciphers including DES and encryption modes.
- Using an unsafe implementation of HTTPSConnection in some versions of Python.
- Specifying the file:// scheme in urlopen.
- Using pseudo-random number generators for cryptographic tasks.
- Using the Telnet protocol.
- Using unsafe XML parsers.
Additionally, it is worth noting the discovery of 8 malicious packages in the PyPI directory. Prior to their removal, these problematic packages had been downloaded over 30,000 times. To conceal malicious activity and bypass warnings from simple static analyzers, the packages employed base64 encoding of code blocks and organized execution after decoding via eval calls.
In the packages noblesse, genesisbot, are, suffer, noblesse2, and noblessev2, code was found to intercept credit card numbers and passwords saved in Chrome and Edge browsers, as well as to transmit account tokens from the Discord application and send system data, including screenshots of the screen content. The packages pytagora and pytagora2 had the capability to download and execute third-party executable code.
Source: opennet.ru
