# Java 101
## IDE + env
### Requirements
- IntelliJ IDE
- VM
- Java Debug Wire Protocol -> enable remote debug
1) quick tutorial about remote debug, create proj, add lib, enable remote debug
2) tips, tricks when debugging
=> Target: Chuẩn bị môi trường cần thiết
## 1. Java
OOP
Java Bean
Java Invocation (quan trọng)
Java Proxy
Java Reflection API (quan trọng)
Javascript Engine in JAVA (giúp ích viết exploit)
Java Classloading (giúp ích viết exploit)
=> Target: hiểu cơ bản Java, Java Reflection API, ...
## 2. Java Webapp
### 2.1 Architecture
- base on JSP (MVC 1)
- base on Servlet (MVC 2)
### 2.2 JSP + Servlet
### 2.3 Filter
### 2.4 Dispatcher
=> Target: audit 1 target + practice debugging
## 3. Deserialize Vulns
### 3.1 Java Deserialize
- Analysis JDK API to understand Java Deserialize vuln
- JEP 290 mitigation
- analysis some chains in ysoserial
=> Target:
- wutfaces (mates ctf 2018) -> analysis 1day, writting PoC
- Advanced: whitehat final 2018 -> write custom gadget chain
=> resource + env về 2 bài này tìm lại là thấy, không thì ib mình để tìm giúp cho
### 3.2 RMI deserialize analysis, how RMI work, case by case
- Deserialize vulns
- exploit case by case
- bypass
- How to collect remote classpath when pentesing RMI service ?
Ex: https://tradahacking.vn/rmi-study-note-and-some-study-case-72bfd47275d9
=> Target: hoàn thành PoC cho từng chain, viết JDK API bằng socket để tiện exploit
### 3.3 JMX
- deserialize vulns (tại sao lại exploit đc deserialize ?)
- jmx unauthenticated + Mbean write permission exploit -> create Mlet to load remote class (tại sao? )
- Tomcat RCE exploit study case via AccessLogValve mbean (case study)
- Advanced: Tomcat RCE exploit with jmx authen enabled (blackhat 2019 US - https://i.blackhat.com/eu-19/Wednesday/eu-19-An-Far-Sides-Of-Java-Remote-Protocols.pdf)
=> Target: hoàn thành 1 bài lab/ctf
### 3.4 JNDI injection (RMI, LDAP)
- analysis JDK API code (root cause)
- fix (fix từ ver nào của java ?)
- bypass -> turning JNDI injection to Java native deserialize (có cách nào bypass cái đã fix ko ?)
- ứng dụng của bug này?
- JSON, jackson, fastjson, ... deserialize
=> Target: hoàn thành 1 bài lab/ctf
### 3.5 Other Deserialize vulns: JSON Deserialize
- liferay CVE-2020-7961 analysis
- JSON Deserialize call arbitrary setter
- JSON Deserialize to native java deserialize
=> target 3.4 + 3.5: viết PoC CVE-2020-7961 cho 2 case mục 3.5
### 3.6 Some notes
- some fail cases
- custom ysoserial and improvement when pentesting (những case nào sẽ fail ? tại sao ? overcome ?)
- khi server không có out bound connection ?
- PoC response cmd output qua http -> cải thiện liferay PoC
- ý tưởng tương tự cho rmi deserialize bug (response cmd output qua socket của rmi)
- how to backdoor with fileless webshell
=> Target:
- cải thiện liferay PoC + hiểu những vấn đề hay stuck khi làm PoC, khắc phục, cải thiện
## 4. EL injection vulns
- netflix titus plane CVE-2020-9297: write PoC + bypass restriction
- CVE-2018-12532 -> advanced of wutfaces
- Ref: https://web.archive.org/web/20190501081357/https://tint0.com/when-el-injection-meets-java-deserialization/
=> Target: hoàn thành PoC
## 5. Template injection vulns
- Velocity template injection -> Confluence CVE-2019-3396
- PoC in case server has no out bound connection (làm thêm cho biết cũng được)
=> Target: hoàn thành PoC
## 6. Java Server Faces Framework
- path traversal bug -> leak viewstate enc key -> deserialize
- analysis bug + write PoC
=> target Java Server Faces: làm 1 bài ctf về chain trên
https://github.com/javaserverfaces/mojarra/issues/4364
https://www.alphabot.com/security/blog/2017/java/Misconfigured-JSF-ViewStates-can-lead-to-severe-RCE-vulnerabilities.html
https://www.synopsys.com/blogs/software-security/path-traversal-defects-oracles-jsf2-implementation/
=> target là gì? từ 1 issue chưa có PoC trên github, hiểu application, reproduce PoC, nghĩ thêm về các chain mới, như chain này leak viewstate key => deserialize
## 7. XXE Vulns
- Một số protocol trong Java (hiểu từ cách java handle từng scheme)
- case by case khi exploit xxe
- file://, netdoc://, jar://, ftp://, http://
- read data via ftp, fix in 8u121 (tại sao, fix chỗ nào?)
- error base to read data? (làm sao đọc data bằng error base, context app ntn ?)
## 8. Struts series
- những bug về struts, OGNL injection
## 9. Bypass nginx proxy
- nginx + tomcat => https://i.blackhat.com/us-18/Wed-August-8/us-18-Orange-Tsai-Breaking-Parser-Logic-Take-Your-Path-Normalization-Off-And-Pop-0days-Out-2.pdf
## 10. Other Deserialize vulns (tham khảo thêm)
- những format khác: xml, json, ...
Ref: https://github.com/mbechler/marshalsec
- RMI over IIOP (advanced)
- weblogic, websphere RCE
## Một số hướng phát triển
1) codeql
2) gadget inspector -> tìm gadget (deserialize surface)
3) audit framework tìm bug