>  기사  >  웹 프론트엔드  >  의심스러운 유지관리자가 npm 공급망 공격 스레드 공개

의심스러운 유지관리자가 npm 공급망 공격 스레드 공개

WBOY
WBOY원래의
2024-07-18 15:06:49365검색

이 이야기는 React 기반 오픈 소스 문서 프로젝트인 Docusaurus의 관리자인 Sébastien Lorber가 패키지 매니페스트에 대한 Pull Request 변경 사항을 발견하면서 시작됩니다. 인기 있는 cliui npm 패키지에 제안된 변경 사항은 다음과 같습니다.

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
특히, 익숙하지 않은 구문을 사용하는 npm 종속성 변경에 주목합니다.

  "dependencies": {
    "string-width": "^5.1.2",
    "string-width-cjs": "npm:string-width@^4.2.0",
    "strip-ansi": "^7.0.1",
    "strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
    "wrap-ansi": "^8.1.0",
    "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"

대부분의 개발자는 패키지 값이나 Git 또는 파일 기반 URL에서 semver 버전 범위를 볼 수 있을 것으로 기대합니다. 하지만 이 경우 특별한 npm: 접두사 구문이 있습니다. 무슨 뜻인가요?

따라서 이 풀 요청에서 제안된 변경의 경우 string-width-cjs 패키지는 ^4.2.0 버전의 string-width 패키지로 해석됩니다. 이는 string-width-cjs에 대한 node_modules 디렉터리 항목이 있지만 string-width@^4.2.0의 내용과 잠금 파일(package-lock.json)의 유사한 동작을 포함한다는 의미입니다.

패키지 별칭 지정은 npm 패키지 관리자 기능이며 여기에 힌트된 경우(ESM 및 CJS 지원에 도움이 되도록) 합법적으로 사용할 수 있습니다.

그렇다면 패키지 앨리어싱은 남용될 수 있습니다. 2021년으로 거슬러 올라가는 기사 및 보안 공개에서 Snyk 홍보대사인 Nishant Jain은 어떻게 공식 npmjs 레지스트리를 속여 종속성 혼란 및 공급망 보안 문제의 일환으로 패키지 별칭을 기반으로 종속성 정보를 잘못 알릴 수 있는지 보여주었습니다.

이 풀 요청은 실제로 무해하며 공급망 공격의 위험이 없습니다. 그런데 세바스티앙은 이런 패키지 이름이 의심스러웠고 더 걱정할 부분이 있다는 걸 알게 됐다.

악성 모듈과 관련된 npm 잠금 파일에서 의심스러운 동작 발견

Sébastien은 끌어오기 요청을 조사할 때 lockfile-lint라는 도구를 실행했습니다. 이 도구는 package-lock.json 또는 Yarn.lock과 같은 잠금 파일을 검증하여 변조되지 않았는지 확인하고 대신 악성 패키지를 삽입하는 데 도움이 됩니다. 원본 npm 패키지.

도구를 실행하면 다음 경고가 표시됩니다.

npx lockfile-lint --path package-lock.json --allowed-hosts yarn npm --validate-https --validate-package-names

detected resolved URL for package with a different name: string-width-cjs
    expected: string-width-cjs
    actual: string-width

detected resolved URL for package with a different name: strip-ansi-cjs
    expected: strip-ansi-cjs
    actual: strip-ansi

detected resolved URL for package with a different name: wrap-ansi-cjs
    expected: wrap-ansi-cjs
    actual: wrap-ansi

 ✖ Error: security issues detected!

면책조항: lockfile-lint는 잠금 파일의 보안 문제를 공개한 출판물에 이어 2019년에 개발한 도구입니다. 왜 npm 잠금 파일이 악성 모듈 삽입의 보안 맹점이 될 수 있는지.

높은 경고: npm에서 유사하게 보이는 인기 패키지

위의 lockfile-lint 결과를 바탕으로 Sébastien은 npm에서 이러한 패키지 이름을 검색한 후 놀랍게도 이러한 패키지 이름이 공개 npm 레지스트리에 존재한다는 사실을 발견했습니다.

  • https://www.npmjs.com/package/string-width-cjs
  • https://www.npmjs.com/package/strip-ansi-cjs
  • https://www.npmjs.com/package/wrap-ansi-cjs

Sébastien은 이러한 패키지 이름이 npm에 존재할 뿐만 아니라 우려를 불러일으키는 지표도 있다고 언급했습니다.

  • 이 패키지는 공개 소스 코드 저장소와 연결되어 있지 않습니다
  • 내용물을 검사해 보면 이 패키지에는 실제 코드가 전혀 없습니다.
  • 이 패키지를 게시한 작성자의 신원은 익명으로 처리되며 개인 정보나 식별 가능한 정보와 연결되지 않습니다.

npm 패키지 Strip-ansi-cjs를 보면 패키지와 관련된 README와 소스 코드 저장소가 없지만 동일한 동작을 인용하는 합법적이고 인기 있는 패키지가 많이 있습니다.

실제로 이 특정 패키지에는 많은 종속 항목(이 패키지에 의존하는 다른 패키지) 형태로 인기 신호가 있습니다. 정확히 529개의 종속 항목이 있고, 매주 다운로드 횟수도 점점 늘어나서 총 7,274개에 달합니다. 글을 쓰는 시간.

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
Strip-ansi-cjs의 코드를 보면 이 패키지에는 패키지 매니페스트 package.json 파일이 하나만 있다는 것을 알 수 있습니다.

그렇다면 아무 것도 하지 않는 패키지가 그렇게 많은 다운로드를 받는 이유는 무엇이며, 왜 그렇게 많은 패키지가 이에 의존합니까?

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack

이 npm 패키지의 작성자를 계속 조사해 보겠습니다.

세 가지 패키지는 모두 Himanshutester002의 소유이며 해당 패키지는 모두 작년에 프로그래밍 버전 번호와 함께 게시되었습니다. 흥미로운 내용 중 일부는 다음과 같습니다.

  • isaacs-cliui npm package - potentially a typosquatting attempt on Isaac’s own fork of the cliui project and the legitimate npm package under their namespace: @isaacs/cliui.
  • azure-sdk-for-net npm package - potentially an attempt at dependency confusion campaign to attack private packages of the same name.
  • link-deep npm package - squatting on a popular capability related to utility packages such as lodash and others

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
You can also note that the user himanshutester002 has no identifiable information on this user profile page on npmjs.

We previously noted that the strip-ansi-cjs npm package has over 500 other packages that use it, therefore, potentially a positive indicator for popularity. Let’s look at them:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
If you give it a glance, this might transfer some sort of legitimacy with this list, but is it?
For example, names like clazz-transformer or react-native-multiply or maybe gh-monoproject-cli seem legitimate, but are they?

Here is the react-native-multiply npm package page:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
This package has virtually no downloads and its author is also an anonymous npm user with no identifiable information. The source URL repository this package redirects to is https://github[.]com/hasandader/react-native-multiply which doesn’t exist and the GitHub user profile looks very suspicious and lacks practical activity.

The npm package contents might seem like there’s some actual source code in there, but in reality, it looks like a generated code sample for a “hello world” application prototype.

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
You also have to wonder, if this package is just a multiplication library, then why does it need 776 dependencies to do the following:

import { multiply } from 'react-native-multiply';
const result = await multiply(3, 7);

While some may mock JavaScript for its abuse of dependencies, contributing to an astronomical tree of nested packages, it doesn’t make any sense for a project to declare 776 direct (top-level) dependencies.

Among all of these dependencies, are the 3 suspicious npm packages that our story began with: string-width-cjs, strip-ansi-cjs, and wrap-ansi-cjs:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
We mentioned that one of the strip-ansi-cjs dependencies was named clazz-transformer. Let’s look at it:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
Let’s explain what is happening here:

  • The npm package name is clazz-transformer, yet the package has a title of class-transformer at the top of the README’s package page here which was purposely done.
  • Similarly, the source code repository is https://github[.]com/typestack/class-transformer which might be a legitimate repository or a fake one, but it is not associating itself at all with the wording “clazz”.

The associated repository’s typstack/class-transformer on GitHub has the package.json file as  follows:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
Looking at the package.json file on GitHub shows no declaration of dependencies, yet if we inspect the source code of the actual package on npmjs we see the 437 dependencies that this clazz-transformer is packaged with. Again, very conveniently bundling the 3 suspicious *-cjs packages:

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack

Further thoughts on suspicious npm package findings

Before we draw further conclusions, it is important to mention a few of the traits of the npm packages we observed above:

  • React Native 패키지는 새 프로젝트를 위해 생성된 스톡 소스 코드의 일부로 기본 곱하기 함수 예제도 제공하는 create-react-native-library 스캐폴드 도구에서 파생된 것으로 보입니다.
  • 패키지는 npx create-next-app@14로 생성된 것과 같이 Next.js 14 시작 상용구에서 파생될 수 있는 디렉터리 및 파일 구조와 종속성을 갖습니다.

Sonatype의 동료들은 이전에 오픈 소스 레지스트리에 패키지가 넘쳐나는 유사한 사례를 확인했습니다. 이 경우 궁극적인 목표는 개발자가 오픈 소스 소프트웨어로 수익을 창출하기 위한 Web3 플랫폼인 Tea 토큰으로 스스로에게 보상하는 것이었습니다.

언급된 패키지에서 일부 tea.yaml 파일을 찾는 것은 이 캠페인의 목적 중 일부가 Tea의 오용을 통해 Tea 토큰을 채굴하는 것이라는 주장을 더욱 뒷받침합니다.

올해 초인 2024년 4월 14일, 차 포럼 사용자는 차 남용에 대한 우려를 더욱 뒷받침하는 댓글을 게시했습니다.

Suspicious Maintainer Unveils Threads of npm Supply Chain Attack
결론을 내리기 전에 신중한 유지 관리 사고방식과 잠재적인 npm 공급망 공격 스레드를 공개하는 데 도움을 준 Sébastien Lorber에게 진심으로 감사의 말씀을 전하고 싶습니다.

string-width-cjs에 무슨 일이 일어나고 있나요?

이 시점에서 나는 string-width-cjs에 의존하는 것으로 추정되는 나머지 패키지에 계속해서 구멍을 뚫어 진짜 적법성에 대한 매우 모호한 지표를 찾을 수 있다는 높은 확신을 갖고 있습니다.

이러한 모든 종속 패키지와 다운로드 부스트가 3개의 *-cjs 패키지에 대한 잘못된 합법성을 생성하려는 유일한 목적으로 이어지고 있어 적절한 피해자가 등장하면 이러한 가짜 패키지가 설치한 다음 새로운 악성 버전을 따르세요.

오픈 소스 소프트웨어로 작업하는 동안 보안을 유지하려면 보안 관행을 채택하고 특히 다음과 같은 후속 교육 리소스를 채택하는 것이 좋습니다.

  • npm 잠금 파일이 악성 모듈 주입의 보안 사각지대가 될 수 있는 이유
  • 10 npm 보안 모범 사례
  • NPM 보안: 공급망 공격 방지

저희가 그들의 반칙 행위 중에 공급망 보안 캠페인을 포착했나요? 아니면 이 모든 것이 자금 추적에 관한 것이며 따라서 Tea 토큰을 채굴하기 위해 npm 및 GitHub와 같은 공공 레지스트리를 스팸 및 남용했기 때문일 수 있습니까?

그러나 이런 일이 발생하더라도 주의를 기울이십시오.

위 내용은 의심스러운 유지관리자가 npm 공급망 공격 스레드 공개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.