Exploding Git Repositories

ReZero lol

Origin fork: git exploding repo Tree, blob 可参考 git clone https://github.com/Katee/git-bomb.git 值得一试上面的命令。(最好不要用自己的工作物理机) 如果你没有足够大的 RAM 和 storage, 那么通常来说你的 git 会被kill, 然后就是爆内存到逼你重启。

The secret is that git de-duplicates “blobs” (which are used to store files) to make repositories smaller and allow using the same blob when a file remains unchanged between commits.

blobs 指的是 类似 文件内容或inodes, tree 指的是 类似目录一样的东西 文章开头的那个项目 git-bomb 妄想造 a billion files, 然而它实际上只有10 tree 和 10个指向文件blob指针。 实际上这种攻击类似于 笑傲江湖 (XML bomb) , 因此叫 git bomb。

Structure

Bottom

blobs 最底下的有个blob文件有一个laugh。

$ git show 5faa3895522087022ba6fc9e64b02653bd7c4283
one laugh

而有一个树对象指向这个blob对象10次

$ git ls-tree 6961ae061a9b89b91162c00d55425b39a19c9f90
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283    f0
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283    f1
# … snipped
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283    f9

Middle

然后 9 层树对象 指向 它们身后的这个树对象 (这是顶部树对象):

$ git ls-tree 106d3b1c00034193bbe91194eb8a90fc45006377
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6    d0
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6    d1
# … snipped
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6    d9

Top

master ref 指向最高树对象。

$ git log --pretty=format:"%s | tree: %T"
Create a git bomb | tree: 106d3b1c00034193bbe91194eb8a90fc45006377

可以用多种能跑tree的方法 (git status, git checkout) 来测试这个repo, 都会因git在写文件进磁盘前在内存中建树而使内存 奔溃。 这也意味着你的进程会被killed 而不是填充满你的磁盘。

Other Git Bombs

Here is a slightly different version of the same idea. This repo has 15,000 nested tree objects. On my laptop this ends up blowing up the stack and causing a segfault. $ git clone https://github.com/Katee/git-bomb-segfault.git If you’d like to make your own git bombs read the next post Making Your Own Git Bombs.

  • Post title:Exploding Git Repositories
  • Post author:ReZero
  • Create time:2017-10-13 15:46:47
  • Post link:https://rezeros.github.io/2017/10/13/exploding-git-repositories/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments