This blog post examines the research of Finnish computer scientist Vladimir Smitka on the dangers of open version control system Git files. We discuss his results, how prevalent it is, why the structure of Git makes it so convenient for hackers, how you can check if your Git folder is open and how to protect your folders.
Finnish computer scientist, Linus Torvalds, changed the world twice in his lifetime. The first time was roughly 25 years ago when he wrote the Linux kernel; the second was when he developed the revolutionary Git – the open source, distributed version control system (VCS).Git is a great system. However, if you mistakenly deploy the version control system files of your web application in a mode that makes them publicly available, along with your entire website, that could mean game over! In this imaginary scenario, your website’s source code, API tokens, database access passwords would be retrieved by attackers before you take them down.Vladimir Smitka is a Czech security researcher who released his research notes in open Git version control system files. His goal was to identify how common it is to find easily retrievable websites' open Git repositories. In this article, we will take a look at the security risks posed by version control system files, and the solutions in light of Smitka’s research.
Let’s begin by analyzing the statistics in Smitka’s research notes:
Smitka then enlarged his scope:
Smitka further enhanced his research by categorizing the results by the technology they used. He reported that vulnerable websites mostly used PHP and Apache servers – not surprising, given the prevalence of these technologies.
Let's now look at the structure of Git directories and folders.
This is an xkcd comic, supplied on their website under a Creative Commons license.When you generate a Git repository (repo) using the git init command, a hidden directory with the name '.git' is created in the Git folder. Similarly when you clone a repo, you’ll see that a '.git' directory is also cloned in the repo folder. The .git directory should not be changed if you're not familiar with Git. It’s a sensitive directory that has all the necessary information and files for Git to work, such as the commit history and previous and current versions of the files.This is a sample .git directory.├── HEAD├── branches├── config├── description├── hooks│ ├── pre-commit.sample│ ├── pre-push.sample│ └── ...├── info│ └── exclude├── objects│ ├── info│ └── pack└── refs├── heads└── tags
In this example, the attacker would have access to all the source code for the website if they could reach the Git repository – including the current and previous versions of the code. Simply put, the .git folder should never be deployed, and if it is, it should never be open to public access.
There are several ways to find out whether the .git folder is accessible to the public.
Since information on the folder structure of Git is widely available, the attacker won’t have any difficulty in finding the code once he’s in the directory. There are also many automated tools to help the attacker.Once the existence of the Git folder is confirmed and directory listing is enabled, it is simply a matter of downloading it using wget in recursive mode:wget -r http://www.example.com/.git/
If directory listing is disabled you can use one of the readily available tools that allow you to download the folder.
Nginx:location ~ /\.(?!well-known\/) {deny all;} Apache:<Directory ~ "/\.(?!well-known\/)">Order deny,allowDeny from all</Directory>
Caddy Server:status 403 /blockdotrewrite {r /\.(?!well-known\/)to /blockdot}
In light of Smitka's research, it appears that open Git folders remain a glaring global web application security problem that has not yet been seriously addressed. For now, applying the proper restrictions regarding files that begin with a dot character, as suggested above, will help protect the sensitive .git directory, preventing a large scale takeover of your website. It is important to be sure that you know where your website's folders and files are and whether they can or cannot be accessed by malicious hackers.If you'd like to find out more about the research that inspired this blog post, see Global scan - exposed .git repos.