The blog.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

109 righe
4.9 KiB

  1. ---
  2. title: CODEpendence
  3. description: >
  4. How to surreptitiouslyinject code via submodules that use GitHub repos
  5. created: !!timestamp '2021-07-07'
  6. time: 11:16 AM
  7. tags:
  8. - security
  9. - GitHub
  10. - git
  11. ---
  12. TL;dr: If you use submodules that point to a GitHub repo, make sure
  13. that the commit id matches an offical branch or tag, especially if
  14. upgraded via a PR or submitted patch.
  15. This issue was disclosed to GitHub via the HackerOne Bug Bounty
  16. program and resolved by them in a timely manner. The
  17. [writeup](https://www.funkthat.com/~jmg/github.submodules.hash.txt) is
  18. available and is the same one that was provided to GitHub. It contains
  19. the complete steps in more detail than this blog post does.
  20. Discovery
  21. ---------
  22. Earlier this year, I was dealing with a git repo that used submodules.
  23. I've never been a fan of them due to the extra work involved in using
  24. them. But then a thought hit me, last year, when GitHub took down
  25. youtube-dl, someone was a bit sneaky and inserted a [copy of it into
  26. GitHub's DMCA repo](https://www.reddit.com/r/programming/comments/jhlhok/someone_replaced_the_github_dmca_repo_with/).
  27. They were able to do this because there is a feature/bug in GitHub's
  28. backend, that all the commits to a forked repo are accessible in the
  29. parent repo, it's just that the branches and tags are maintained
  30. separately.<label for="sn-reason" class="margin-toggle sidenote-number">
  31. </label><input type="checkbox" id="sn-reason" class="margin-toggle"/>
  32. <span class="sidenote">This makes sense to reduce storing duplicate data
  33. if a repo is large or has many forks.</span>
  34. Verification
  35. ------------
  36. The next question, would combining these into an attack even work?
  37. What would things look like? I created a few accounts to test them,
  38. creating a project to represent a code dependancy,
  39. [depproj](https://github.com/upstream123/depproj), that would be
  40. imported into another project by another user,
  41. [proj](https://github.com/comproj/proj). Then once those were created,
  42. have a malicious user create a fork of both the
  43. [deprpoj](https://github.com/maliciousrepo/depproj) and the
  44. [proj](https://github.com/maliciousrepo/proj).
  45. Once the malicious forks were created, clone them locally. With the
  46. clones, malicious [code can be
  47. inserted](https://github.com/maliciousrepo/depproj/commit/91781e4b9e1b1c944e19db740db12304755666b5)
  48. into the depproj repo. If you look at the repo, the previous commit
  49. was done as the maliciousrepo user, but while I was working on this,
  50. I remembered that w/ git, you can set the commit author to be anything
  51. (signing helps prevent that), so this commit appears to be done by the
  52. correct upstream123 user.
  53. Once the malicious code has been inserted, the malicious user can now
  54. update the submodule of the project to the commit id of the malicious
  55. code. This is done simply by doing:
  56. ```
  57. cd depproj
  58. git fetch origin <commitid>
  59. git checkout <commitid>
  60. ```
  61. Even though the depproj still points to the upstream123 repo, because
  62. fork commits appear IN the depproj repo, the above works w/o any other
  63. changes. This is also what makes it dangerous, because the repo is not
  64. changed, it can be disguised as a simple version update.
  65. A [PR](https://github.com/comproj/proj/pull/3) is then submitted to the
  66. project being attacked. I did not control the author of commits as
  67. well as I should have, but it still is effective. If you click into
  68. the proposed change, and then click on code.c, the file changed, it'll
  69. bring you to the [change compare
  70. view](https://github.com/upstream123/depproj/compare/91781e4b9e1b1c944e19db740db12304755666b5...370d35ec5df81a16bb361111faeb665ea90de026#diff-e43700a08429a0231daba9a49ff36a118566849856da2811ae074417ebb552d0).
  71. For this demo, it was a small change, but if the project is large, it's
  72. would be easy to bury a minor flaw in lots of changes. The other thing
  73. to note about this page is that the author displayed is NOT the author
  74. of the change, but it appears that it is a legitimate change by the
  75. author of the repo. [![Screenshot of github comparing changes with a popup of the author showing the author owns this repository and committed to this repository.]([[!!images/codependence-comp-author.png]])]({{ media_url('images/codependence-comp-author.png') }})
  76. Conclusion
  77. ----------
  78. This is an interesting attack in that it leverages two features in a
  79. way that has surprising results. It demonstrates that software
  80. dependancies need to be reviewed, and vetted, and that if you're using
  81. GitHub, that just because a PR says it's updating a submodule to the
  82. new version, it doesn't mean that it is safe to simply merge in the
  83. change.
  84. Timeline
  85. --------
  86. 2021-03-31 -- Reported to GitHub via HackerOne.<br>
  87. 2021-03-31 -- More info requested and provided.<br>
  88. 2021-04-01 -- Ack'd issue and started work on fix.<br>
  89. 2021-05-04 -- GitHub determined it was low risk, but did add warning when viewing commit.<br>
  90. 2021-05-05 -- Asked GitHub for disclosure timeline.<br>
  91. 2021-06-04 -- Pinged GitHub again.<br>
  92. 2021-07-07 -- Published blog post.<br>