{"id":213,"date":"2022-08-14T15:34:11","date_gmt":"2022-08-14T15:34:11","guid":{"rendered":"https:\/\/codecrypt76.com\/?p=213"},"modified":"2022-11-25T16:51:11","modified_gmt":"2022-11-25T16:51:11","slug":"pip-install-malware","status":"publish","type":"post","link":"https:\/\/codecrypt76.com\/index.php\/2022\/08\/14\/pip-install-malware\/","title":{"rendered":"PIP Install  Malware?!"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"581\" src=\"http:\/\/codecrypt76.com\/wp-content\/uploads\/2022\/08\/pip_security_alert-1024x581.png\" alt=\"PIP Install Malware\" class=\"wp-image-276\" srcset=\"https:\/\/codecrypt76.com\/wp-content\/uploads\/2022\/08\/pip_security_alert-1024x581.png 1024w, https:\/\/codecrypt76.com\/wp-content\/uploads\/2022\/08\/pip_security_alert-300x170.png 300w, https:\/\/codecrypt76.com\/wp-content\/uploads\/2022\/08\/pip_security_alert-768x436.png 768w, https:\/\/codecrypt76.com\/wp-content\/uploads\/2022\/08\/pip_security_alert.png 1130w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>Introduction<\/h2>\n\n\n\n<p>If you are a Python developer then you are aware of <a href=\"https:\/\/pypi.org\/project\/pip\/\">pip<\/a>. However, were you aware of the potential <a href=\"https:\/\/www.darkreading.com\/threat-intelligence\/school-kid-uploads-ransomware-scripts-to-pypi-repository-as-fun-research-project\">malware<\/a> threat associated with Python\u2019s recommended package-management system? This article will discuss the security threats associated with pip and what you can do to protect yourself against them.<\/p>\n\n\n\n<h2>What is PIP?<\/h2>\n\n\n\n<p><em>Package Installer for Python<\/em> or (pip) is the de facto and recommended package-management system written in Python and is used to install and manage software packages. It connects to an online repository of public packages, called the Python Package Index(<code>PyPI<\/code>). For example, let\u2019s say you want to install the <code>request<\/code> module. You would use the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install request<\/code><\/pre>\n\n\n\n<p>This command will download the source code of the <code>request<\/code> package and install it into your local Python environment, allowing you to utilize its functionality.<\/p>\n\n\n\n<h2>PIP\u2019s Vulnerabilities<\/h2>\n\n\n\n<p>In general practice, Python developers will usually upload secure and ethical code to the PyPI repository. However, you would be surprised to know, there are no third-party checks on the code that is uploaded to PyPI. The only restriction is that once a package name exists, only the maintainer(s) can upload packages with that name. Meaning you can\u2019t submit a package using an already established name.<\/p>\n\n\n\n<p>Unfortunately, this security feature can be exploited. In 2016, <a href=\"https:\/\/incolumitas.com\/2016\/06\/08\/typosquatting-package-managers\/\">research<\/a> proved that PyPI could be exploited through <a href=\"https:\/\/en.wikipedia.org\/wiki\/Typosquatting\">typosquatting<\/a>. The researcher uploaded some harmless \u201csimulation malware\u201d to PyPI under names that were misspelled versions of popular package names, in order to collect data on how often these misspelled packages were installed. If a script kiddie or black-hat hacker was doing this then they could have used a much more malicious script.<\/p>\n\n\n\n<h2>Malware on PyPI<\/h2>\n\n\n\n<p>On July 28, 2022 <a href=\"https:\/\/blog.sonatype.com\/ransomware-in-a-pypi-sonatype-spots-requests-typosquat\">researchers at Sonatype<\/a> discovered malicious code on PyPI. The packages were named <code>\"requesys,\"<\/code> <code>\"requesrs,\"<\/code> and <code>\"requesr,\"<\/code> which are all common typosquats of <code>\"requests\"<\/code> \u2014 a legitimate and widely used HTTP library for Python. Sonatype immediately reported this incident to PyPI\u2019s administrators, and two of the packages have since been removed.<\/p>\n\n\n\n<p>According to the researchers at Sonatype, the packages (<code>requesys<\/code>) was downloaded about 258 times, presumably by developers who made typographical errors when attempting to download the real <code>\"requests\"<\/code> package. One version of the <code>requesys<\/code> package contained the encryption and decryption code in plaintext Python. But a subsequent version contained a Base64-obfuscated executable that made analysis a little harder, according to Sonatype.<\/p>\n\n\n\n<h3>Nothing harmful found<\/h3>\n\n\n\n<p>According to Sonatype, developers who ended up with their system encrypted received a pop-up message instructing them to contact the author of the package for the decryption key. Victims were able to obtain the decryption key without having to make a payment for it. Which according to Sonatype, <em>\u201cmakes this case more of a gray area rather than outright malicious activity.\u201d<\/em><\/p>\n\n\n\n<p>Information on the hacker\u2019s Discord channel shows that at least 15 victims had installed and run the package.<\/p>\n\n\n\n<h2>A Growing Threat<\/h2>\n\n\n\n<p>This event is one of an increasing number of recent occurrences where hackers have hidden harmful code in commonly used software repositories in an effort to lure developers into downloading and installing it in their environments. For instance, Sonatype discovered in May that 300 developers had mistakenly downloaded <code>\"Pymafka,\"<\/code> a malicious program for disseminating Cobalt Strike, from the PyPI registry thinking it was the popular and trustworthy Kafka client <code>\"PyKafka.\"<\/code><\/p>\n\n\n\n<p>In July, researchers at Kaspersky discovered <a href=\"https:\/\/www.darkreading.com\/risk\/malicious-npm-packages-discord-tokens-credit-card\">four information-stealing packages in the Node Package Manager<\/a> (npm) repository.<\/p>\n\n\n\n<h2>Conclusion<\/h2>\n\n\n\n<p>Hopefully after reading this article, you now realize why it is important to pay close attention to what you download from public code repositories such as PyPI. Security researchers state that organizations must pay closer attention to their software supply chains \u2014 especially when it comes to using open source software from public repositories such as PyPI. Remember, as a Python developers, it is always your responsibility to ensure your packages are secure. Be very careful when typing out the names of popular libraries, as <code>typosquatting<\/code> is one of the most common methods for this exploitation.<\/p>\n\n\n\n<p>Additionally, it behooves you to take preemptive measure to protect your files in your day-to-day operations. Use a trusted antivirus and malware protection software, use secure &amp; strong passwords, always use secure internet connections, and always, always, always \u2014 <em>backup your data!<\/em><\/p>\n\n\n\n<p>If you found this article helpful or have any questions please leave a comment.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p> Learn about the potential security threats associated with pip and what you can do to protect yourself against them.<\/p>\n","protected":false},"author":1,"featured_media":279,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,49,4],"tags":[38,40,11],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/posts\/213"}],"collection":[{"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":14,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions\/295"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/media\/279"}],"wp:attachment":[{"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codecrypt76.com\/index.php\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}