Simple Web 0x15.5(Pickle)
tags: NTUSTWS CTF Web
Background - Pickle
Python magic method: __reduce__ which is used to define what needs to be done when deserializing.
Source code
1 | |
1 | |
Output & Analyze
In Linux

GLOBAL 'posix system': importposix system(which is a library in linux)BINPUT 0: put the top stack to position 0 at Memo structure(array)BINUNICODE: push string ‘pwd’ to stack topTUPLE1: let the element of top stack be a tuple typeREDUCE:1
2
3
4args = stack.top() # which is 'pwd' in tuple type func = stack.top() # which is 'posix system' stack.push(func(args)) # then it'll execute os.system('pwd') and push the output to stack
In Windows
Much similar with the outcome on linux environment. 但兩者 pickle.dump 下來的hex不一樣,所以如果要debug要注意平台
How to RCE?
1 | |
How did it do?
- First,
exploit.pywill serialize the exploit function and turned it tobyte.hexthen send itserver_app.py - Then
server_app.pywill deserialize it and during the process, it’ll execute magic method__reduce__, suddenly, it’ll executeos.system('pwd')at the same time → RCE