OWASP Thailand Meeting May 2020 (Free Event)
犖犖迦 OWASP 犖犖犖萎犖橿犖犖劇賢犖犖犖む県犖犖迦犖
犖о険犖犖犖朽 28 犖.犖. 2563 犢犖о献犖 18.00-19.30 犖.
犖犖園硯犖犢犖 Web Hacking with Object Deserialization
Event: https://www.facebook.com/events/294577638200535/
Video: https://www.facebook.com/groups/owaspthailand/permalink/10157939551293127/
1 of 91
Downloaded 54 times
More Related Content
Web Hacking with Object Deserialization
1. Web Hacking with
Object Deserialization
Made for
Responsible: Pichaya Morimoto
Version (Date): 1.0 (2020-05-28)
Confidentiality class: Public
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
1
OWASP Thailand Chapter
2. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
$ whoami
2
Mr. Pichaya (LongCat) Morimoto
Founder | Lead Penetration Tester
Siam Thanat Hack Company Limited
2
Past Events:
OWASP Thailand Meeting 2/2017
OWASP Thailand Meeting 7/2016
OWASP Thailand Meeting 5/2015
OWASP Thailand Meeting 3/2014
3. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
3
- ...
- Ragnarok Mobile in Security, Red Pill 2019
- Mysterious Crypto in Android Biometrics,
2600 Thailand Meetup 2019/10
- Docker Security Plugin in DevSecOps,
OWASP Day 2020: DevSecOps in Actions
俗_()_/俗
19. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
19
犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権
1. 犖犖迦犖犖犢犖犖犖o犖犖迦検犖迦牽犖犖犖伍検犖犖 serialized data 犢犖
犢犖犖犢犖犖犖o犖犖迦犢犖犖ム元犢犖∇犖犖 object 犖犖園犖犢犖犖劇犖犖犢犖迦犖犖犖巌犖犖犖朽犢犖¥犖犖о牽犖犢犖迦犖
HP = 1234
MP = 0
Gold = 129340
binary serialization is
not easily modifiable
for the common user
20. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
20
犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
Session Data as
PHP Serialized Object
犖犖迦検犖 field 犢犖 session data 犢犖犖 user role 犖犖犖劇賢 id
犢犖犖迦肩犖迦検犖迦牽犖犢犖 user 犖犖犖犖÷犖迦犖犖 admin 犢犖犢犖犖?
21. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
21
犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
Session Data as
PHP Serialized Object
Singing Signature = MD5(session + secret key) 犖÷険犖犖犖劇賢 MAC (Message
Authentication Code)
22. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
22
犖犖迦牽犖犢犖 Signing Signature 犖犖犖犖犖園犖犖迦牽犢犖犢犖犖犖
Web Server
Web Browser
(User) Set-Cookie: session=
O:4:"User":3:{s:4:"name";s:7:"pichay
a";s:4:"role";s:4:"user";s:3:"age";i:28;}
Web Server
Web Browser
(User)
Cookie: session=
O:4:"User":3:{s:4:"name";s:3:"
sth";s:4:"role";s:5:"admin";s:3:
"age";i:999;}
1. Server 犖犖犖犖 Serialized Data 犢犖犖犖犢犖犢犖о犖犖犖ム険犖犖ム犖犖犖犖巌
user=pichaya&password=P@ssw0rd
2. 犢犖犖犢犖犖犖o犖犖謹犢犖犢犖犖犖 Serialized Data 犖犖園硯犢犖犖犢犖犢犖犖犖犖犖犖劇犖犢犖
23. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
23
犖犖迦牽犖犢犖 Signing Signature 犖犖犖犖犖園犖犖迦牽犢犖犢犖犖犖
Web Server
Web Browser
(User) Set-Cookie: session=
O:4:"User":3:{s:4:"name";s:7:"pichaya";s:4:
"role";s:4:"user";s:3:"age";i:28;}:deadbeef
Web Server
Web Browser
(User)
Cookie: session=
O:4:"User":3:{s:4:"name";s:3:"
sth";s:4:"role";s:5:"admin";s:3:
"age";i:999;}:deadbeef
1. Server 犖犖犖犖 Serialized Data 犢犖犖犖犢犖犢犖о犖犖犖ム険犖犖ム犖犖犖犖巌
犖犖o犖犖÷犖 signing signature 犖犖朽犖犖o犖迦犖犖迦 md5(msg + key)
user=pichaya&password=P@ssw0rd
secret_key=longcat
signature=md5(O4:...i
:28;}+secret_key)
犖犖÷検犖伍犖巌犖 deadbeef
2. 犢犖犖犢犖犖犖o犖犖萎犖犢犖犖犖 Serialized Data 犖犖園硯犢犖犖犢犖犢犖犖э犖
犖犖萎犖¥犖犖迦検犖迦牽犖犢犖犢犖犖犖 signing signature 犢犖犖犖犖迦犖朽犖犖項犢犖
犢犖犖犖迦鍵犖犖迦犖朽犖犖o犖迦犖犖迦 secret key 犖犖朽犖÷元犢犖 server 犖犖朽犖犖刻
Rejected
* 犖犖園硯犖犖犖迦犢犖犖犢犖犖迦犖犖犖迦権 犢犖犖 犢 犖犖犖犖犖犖巌犖犖о牽
犢犖 HMAC 犖犖園 secret key 犖犖朽犖犖ム賢犖犖犖園権
74. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
74
Insecure Deserialization (.NET)
Many types built into .NET framework have code that will run just because they are
instantiated.
The example of .NET magic methods:
- Constructors
- OnDeserialize Handlers
- Setters / Getters
- Destructors
75. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
75
.NET Serialization Gadget
Start with an easy gadget: TempFileCollection
Read this by yourself if you dare:
https://github.com/microsoft/referencesource/blob/master/System/compmod/system/codedom/compiler/TempFiles.cs#L34
76. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
76
.NET Serialization Gadget
Start with an easy gadget: TempFileCollection
Controllable Object Attributes
This gadget cannot RCE
Delete Temp Directory in
Destructor Method
77. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
77
.NET Serialization Gadget
Make it harder: TypeConfuseDelegate
This is too hard. Read it yourself please:
https://googleprojectzero.blogspot.com/2017/04/exploiting-net-managed-dcom.html
犢犖犢犖犖∇険犖 .NET Framework
犢犖о賢犖o犖犖園犖犖ワ犖迦肩犖伍
78. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
78
.NET Serialization Gadget
Make it harder: TypeConfuseDelegate
We have 3 friends as follows:
- ComparisonComparer
- MulticastDelegate
- SortedSet
1
2
3 4
79. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
79
.NET Serialization Gadget
Make it harder: TypeConfuseDelegate
ComparisonComparer class SortedSet class
Process::Start(Executable, Args)
??
1
2
犢犖犖迦犖萎犖犖朽権犖...
4
3
犖犖犖 犢 犢犖¥犢犖犢犖犖犖迦鍵犖犖犖 Comparison Type
80. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
80
.NET Serialization Gadget
Make it harder: TypeConfuseDelegate
MulticastDelegate
Fields:
- _invocationList
- _invocationCount
- ...
ComparisonA(A, B)
ComparisonB(A, B)
ComparisonC(A, B) Replace this delegate with
Process::Start(Executable, Args)
1
2
3
81. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
81
.NET Serialization Gadget
Let test TypeConfuseDelegate gadget
Demo Video: demo3_typeconfusedelegate.flv
82. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
ViewState
82
_VIEWSTATE value will be deserialized with
ObjectStateFormatter to be ViewState object.
85. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖犖о犖犖犖 ViewState 犖犖о権 Burp Suite
85
ViewState MAC is Disabled
ViewState MAC is Enabled
ViewState MAC is Encrypted
86. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
86
犖ム賢犖犢犖犖 ViewState 犖犖о権
Insecure Deserialization
Let hack Insecure ViewState Serialization with TypeConfuseDelegate Gadget
Demo Video: demo4_viewstate.flv
87. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
87
Key Takeaways
#1 Do NOT Deserialize Untrusted Data
#2 Logging and Monitoring