49
Diffing Hex Packages Diffing Hex Packages

Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Diffing Hex PackagesDiffing Hex Packages

Page 2: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

JohannaJohannaLarssonLarsson@joladev

Page 3: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header
Page 4: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

AgendaAgenda

History of dependenciesDependencies todayAttacks in the wildMitigations

Takeawaysdiff.hex.pm

Page 5: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

IntroductionIntroduction

Page 6: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

DependenciesDependencies

Page 7: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

VendoringVendoring

Page 8: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

The Rise of theThe Rise of thePackage RepositoryPackage Repository

Page 9: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

The Dominance ofThe Dominance ofnpmnpm

Page 10: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

http://www.modulecounts.com/

Page 11: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

https://medium.com/hackernoon/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-

how-9a8cb347c5b5

Page 12: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Jacek Królikowski - Trust issues: trouble inpackage paradise | Code BEAM STO 19

Page 13: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

How to take over a Ruby gem / MaciejMensfeld @maciejmensfeld

Page 14: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

TransitiveTransitivedependencies anddependencies and

riskrisk

Page 15: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Small World with High Risks:

A Study of Security Threats in the npm Ecosystem

“ Installing an average npm packageintroduces an implicit trust on 79

third-party packages and 39maintainers, creating a surprisingly

large attack surface.

Page 16: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Small World with High Risks:

A Study of Security Threats in the npm Ecosystem

“ Some maintainers have an impacton hundreds of thousands of

packages. As a result, a very smallnumber of compromised maintaineraccounts suffices to inject malwareinto the majority of all packages.

Page 17: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

AttacksAttacks

 

Page 18: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

DistributingDistributingMalicious CodeMalicious Code

TyposquattingMalicious dependencyCompromised credentialsOffering to maintain package

Page 19: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Intentional orIntentional oraccidentalaccidental

Page 20: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

For profit or to harmFor profit or to harm

Page 21: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Compile timeCompile time

Run timeRun timevs

Page 22: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

eslint-scopeeslint-scope

https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes

“ On installation, the malicious packagesdownloaded and executed code from

pastebin.com which sent the contents of the user's.npmrc file to the attacker. An .npmrc file typically

contains access tokens for publishing to npm.

Page 23: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

event-streamevent-stream

https://medium.com/intrinsic/compromised-npm-package-event-stream-d47d08605502

Scanned the computer for bitcoin wallets and sentcredentials to the attacker's server.

Only ran in production mode, not testing, and only forwallets with enough bitcoin in them for it to be worth it.

Took 2 months before it was discovered.

Page 24: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

bootstrap-sassbootstrap-sass

https://snyk.io/blog/malicious-remote-code-execution-backdoor-discovered-in-the-

popular-bootstrap-sass-ruby-gem/

Uploaded new malicious version and yanked theprevious one to force updates.

Monkey patches rails to eval a special header if it's foundin a request, allowing remote code execution.

Was discovered the same day.

Page 25: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

MitigationsMitigations

Page 26: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

TyposquattingLimited republishing/unpublishing

Run by volunteers

Page 27: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

What can you do?What can you do?

Static analysisHardening infrastructureAuditing dependencies

Page 28: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

DiffingDiffing

Page 29: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Can't I just useCan't I just useGithub?Github?

Page 30: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

mix hex.package diff

Page 31: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

diff.hex.pmdiff.hex.pm

Page 32: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Brief historyBrief historyhttps://diff.jola.dev

Page 33: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header
Page 34: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header
Page 35: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

prior artprior art

RubyGems npm

Page 36: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

TechnicalTechnicalBackgroundBackground

Page 37: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

hex_core

https://github.com/hexpm/hex_core

> hex_repo:get_names(Config).{ok, {200, ..., #{packages => [ #{name => <<"package1">>}, #{name => <<"package2">>}, ... ]}}}

1234567

Page 38: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

ETS

https://erlang.org/doc/man/ets.html

def get_versions(key) do case :ets.lookup(@store_module, key) do [{_key, versions}] -> {:ok, versions} _ -> {:error, :not_found} endend def get_names() do :ets.select(@store_module, [{{:"$1", :_}, [], [:"$1"]}])end

12345678910

Page 39: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

git_diff

https://github.com/mononym/git_diff

[ %GitDiff.Patch{ chunks: [ %GitDiff.Chunk{ from_num_lines: "42", from_start_line: "42", header: "@@ -481,23 +483,24 @@ class Cursor context: "class Cursor extends Model {", #

12345678

Page 40: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

LiveView

https://github.com/phoenixframework/phoenix_live_view

LiveDemo!

Page 41: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Problems seenProblems seen

Page 42: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header
Page 43: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

GCP load balancerGCP load balancercloses connectionscloses connections

after 30safter 30s

Page 44: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

TakeawaysTakeaways

Page 45: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

                  is really                  is reallycoolcool

hex_core

Page 46: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

 Talk about how to Talk about how towork withwork with

dependencies independencies inyour workplace in ayour workplace in a

way where it doesn'tway where it doesn'thurt productivityhurt productivity

Page 47: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Improve ToolingImprove Tooling

Page 48: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Contribute back toContribute back tothe community,the community,

report vulnerabilitiesreport vulnerabilities

Page 49: Diffing Hex Packages€¦ · popular-bootstrap-sass-ruby-gem/ Uploaded new malicious version and yanked the previous one to force updates. Monkey patches rails to eval a special header

Thank you!Thank you!