# Dependency Confusion

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

* 您在**网络安全公司**工作吗？ 想要看到您的**公司在HackTricks中做广告**？ 或者想要访问**PEASS的最新版本或下载HackTricks的PDF**？ 请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获取[**官方PEASS和HackTricks商品**](https://peass.creator-spring.com)
* **加入** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上**关注**我 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks)**和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud)**提交PR来分享您的黑客技巧**。

</details>

<figure><img src="/files/YM7uBW8YtIhrJWT3a6lG" alt=""><figcaption></figcaption></figure>

{% embed url="<https://websec.nl/>" %}

## 基本信息

简而言之，依赖混淆漏洞发生在项目使用具有**拼写错误**、**不存在**或**未指定版本**的库，并且所使用的依赖库允许从**公共**存储库中**获取更新版本**时。

* **拼写错误**：导入\*\*`reqests`\*\*而不是`requests`
* **不存在**：导入`company-logging`，一个**不再存在**的内部库
* **未指定版本**：导入一个**内部**的**存在的**`company-requests`库，但存储库检查**公共存储库**以查看是否有**更高版本**。

## 利用

{% hint style="warning" %}
在所有情况下，攻击者只需发布一个带有受害公司使用的库名称的**恶意软件包**。
{% endhint %}

### 拼写错误和不存在

如果您的公司试图**导入一个不存在的库**，很可能库的存储库会在**公共存储库**中搜索它。 如果攻击者已经创建了它，您的代码和运行的机器很可能会受到威胁。

### 未指定版本

开发人员很常见**不指定库的任何版本**，或者只指定一个**主要版本**。 然后，解释器将尝试下载符合这些要求的**最新版本**。\
如果库是一个**已知的外部库**（如python `requests`），**攻击者无法做太多事情**，因为他将无法创建一个名为`requests`的库（除非他是原始作者）。\
但是，如果库是**内部**的，就像在这个示例中的`requests-company`，如果**库存储库**允许**在外部也检查新版本**，它将搜索公开可用的更新版本。\
因此，如果**攻击者知道**公司正在使用`requests-company`库**版本1.0.1**（允许次要更新）。 他可以**发布**库`requests-company`**版本1.0.2**，公司将**使用该库**而不是内部库。

## AWS修复

这个漏洞在AWS的**CodeArtifact**中发现（阅读这篇[**博客文章中的详细信息**](https://zego.engineering/dependency-confusion-in-aws-codeartifact-86b9ff68963d)）。\
AWS通过允许指定库是内部还是外部来修复了这个问题，以避免从外部存储库下载内部依赖项。

## 查找易受攻击的库

在关于**依赖混淆**的[**原始帖子中**](https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610)，作者搜索了数千个包含JavaScript项目依赖项的package.json文件。

## 参考

* <https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610>
* <https://zego.engineering/dependency-confusion-in-aws-codeartifact-86b9ff68963d>

<figure><img src="/files/YM7uBW8YtIhrJWT3a6lG" alt=""><figcaption></figcaption></figure>

{% embed url="<https://websec.nl/>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

* 您在**网络安全公司**工作吗？ 想要看到您的**公司在HackTricks中做广告**？ 或者想要访问**PEASS的最新版本或下载HackTricks的PDF**？ 请查看[**订阅计划**](https://github.com/sponsors/carlospolop)！
* 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获取[**官方PEASS和HackTricks商品**](https://peass.creator-spring.com)
* **加入** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上**关注**我 🐦[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks)**和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud)**提交PR来分享您的黑客技巧**。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/pentesting-web/dependency-confusion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
