Skip to content

Commit 57f7c8d

Browse files
committed
ViewState Java
1 parent 9425cec commit 57f7c8d

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Diff for: Insecure Deserialization/Java.md

+68
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Burp extensions using ysoserial](#burp-extensionsl)
1212
* [Alternative Tooling](#alternative-tooling)
1313
* [YAML Deserialization](#yaml-deserialization)
14+
* [ViewState](#viewstate)
1415
* [References](#references)
1516

1617

@@ -146,13 +147,80 @@ SnakeYAML
146147
```
147148

148149

150+
## ViewState
151+
152+
In Java, ViewState refers to the mechanism used by frameworks like JavaServer Faces (JSF) to maintain the state of UI components between HTTP requests in web applications. There are 2 major implementations:
153+
154+
* Oracle Mojarra (JSF reference implementation)
155+
* Apache MyFaces
156+
157+
**Tools**:
158+
159+
* [joaomatosf/jexboss](https://github.com/joaomatosf/jexboss) - JexBoss: Jboss (and Java Deserialization Vulnerabilities) verify and EXploitation Tool
160+
* [Synacktiv-contrib/inyourface](https://github.com/Synacktiv-contrib/inyourface) - InYourFace is a software used to patch unencrypted and unsigned JSF ViewStates.
161+
162+
163+
### Encoding
164+
165+
| Encoding | Starts with |
166+
| ------------- | ----------- |
167+
| base64 | `rO0` |
168+
| base64 + gzip | `H4sIAAA` |
169+
170+
171+
### Storage
172+
173+
The `javax.faces.STATE_SAVING_METHOD` is a configuration parameter in JavaServer Faces (JSF). It specifies how the framework should save the state of a component tree (the structure and data of UI components on a page) between HTTP requests.
174+
175+
The storage method can also be inferred from the viewstate representation in the HTML body.
176+
177+
* **Server side** storage: `value="-XXX:-XXXX"`
178+
* **Client side** storage: `base64 + gzip + Java Object`
179+
180+
181+
### Encryption
182+
183+
By default MyFaces uses DES as encryption algorithm and HMAC-SHA1 to authenticate the ViewState. It is possible and recommended to configure more recent algorithms like AES and HMAC-SHA256.
184+
185+
| Encryption Algorithm | HMAC |
186+
| -------------------- | ----------- |
187+
| DES ECB (default) | HMAC-SHA1 |
188+
189+
Supported encryption methods are BlowFish, 3DES, AES and are defined by a context parameter.
190+
The value of these parameters and their secrets can be found inside these XML clauses.
191+
192+
```xml
193+
<param-name>org.apache.myfaces.MAC_ALGORITHM</param-name>
194+
<param-name>org.apache.myfaces.SECRET</param-name>
195+
<param-name>org.apache.myfaces.MAC_SECRET</param-name>
196+
```
197+
198+
Common secrets from the [documentation](https://cwiki.apache.org/confluence/display/MYFACES2/Secure+Your+Application).
199+
200+
| Name | Value |
201+
| -------------------- | ---------------------------------- |
202+
| AES CBC/PKCS5Padding | `NzY1NDMyMTA3NjU0MzIxMA==` |
203+
| DES | `NzY1NDMyMTA=<` |
204+
| DESede | `MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz` |
205+
| Blowfish | `NzY1NDMyMTA3NjU0MzIxMA` |
206+
| AES CBC | `MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz` |
207+
| AES CBC IV | `NzY1NDMyMTA3NjU0MzIxMA==` |
208+
209+
210+
* **Encryption**: Data -> encrypt -> hmac_sha1_sign -> b64_encode -> url_encode -> ViewState
211+
* **Decryption**: ViewState -> url_decode -> b64_decode -> hmac_sha1_unsign -> decrypt -> Data
212+
149213

150214
## References
151215

152216
- [Detecting deserialization bugs with DNS exfiltration - Philippe Arteau - March 22, 2017](https://www.gosecure.net/blog/2017/03/22/detecting-deserialization-bugs-with-dns-exfiltration/)
217+
- [Hack The Box - Arkham - 0xRick - August 10, 2019](https://0xrick.github.io/hack-the-box/arkham/)
153218
- [How I found a $1500 worth Deserialization vulnerability - Ashish Kunwar - August 28, 2018](https://medium.com/@D0rkerDevil/how-i-found-a-1500-worth-deserialization-vulnerability-9ce753416e0a)
154219
- [Jackson CVE-2019-12384: anatomy of a vulnerability class - Andrea Brancaleoni - July 22, 2019](https://blog.doyensec.com/2019/07/22/jackson-gadgets.html)
220+
- [Java Deserialization in ViewState - Haboob Team - December 23, 2020](https://www.exploit-db.com/docs/48126)
155221
- [Java-Deserialization-Cheat-Sheet - Aleksei Tiurin - May 23, 2023](https://github.com/GrrrDog/Java-Deserialization-Cheat-Sheet/blob/master/README.md)
222+
- [JSF ViewState upside-down - Renaud Dubourguais, Nicolas Collignon - March 15, 2016](https://www.synacktiv.com/ressources/JSF_ViewState_InYourFace.pdf)
223+
- [Misconfigured JSF ViewStates can lead to severe RCE vulnerabilities - Peter Stöckli - August 14, 2017](https://www.alphabot.com/security/blog/2017/java/Misconfigured-JSF-ViewStates-can-lead-to-severe-RCE-vulnerabilities.html)
156224
- [Misconfigured JSF ViewStates can lead to severe RCE vulnerabilities - Peter Stöckli - August 14, 2017](https://www.alphabot.com/security/blog/2017/java/Misconfigured-JSF-ViewStates-can-lead-to-severe-RCE-vulnerabilities.html)
157225
- [On Jackson CVEs: Don’t Panic — Here is what you need to know - cowtowncoder - December 22, 2017](https://medium.com/@cowtowncoder/on-jackson-cves-dont-panic-here-is-what-you-need-to-know-54cd0d6e8062#da96)
158226
- [Pre-auth RCE in ForgeRock OpenAM (CVE-2021-35464) - Michael Stepankin (@artsploit) - June 29, 2021](https://portswigger.net/research/pre-auth-rce-in-forgerock-openam-cve-2021-35464)

0 commit comments

Comments
 (0)