You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2019-11-24-demystify_java_gadget_chain.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,14 +24,12 @@ We need to use `property oriented programming` to build a `RCE gadget` from the
24
24
We can use the Java `Runtime` object and its `exec()` method to execute any `system` commands.
25
25
- for example, running the `mate-calculator` in linux.
26
26
27
-

28
27
29
28
## 2. Command Execution using Reflection API and `Runtime` object
30
29
* Java `Reflection API` is used to `examine` or `modify` the `behavior` of methods, classes, interfaces at `runtime`.
31
30
- Through reflection API, we can invoke any method at `runtime` via `invoke()` function.
32
31
- Here, we are trying to invoke `getRuntime()` method to get a `Runtime` object.
33
32
34
-

35
33
36
34
## 3. Command Execution using `ConstantTransformer` and `InvokerTransformer` together
37
35
@@ -45,11 +43,9 @@ Before directly jump into the `Constant Transformer` and `InvokerTransformer`, f
45
43
For example, we can create a class `MyReverse` by implementing the `Transformer`interface and `transform()` method.
46
44
- Here, in `transform()` method, we specify how to reverse a `String` type object.
47
45
48
-

49
46
50
47
When we call the `transform()` method via passing the argument of a `String` type object, it reverses the string.
51
48
52
-

53
49
54
50
> The return type of the `transform()` method is `Object` therefore it can return any type of object.
55
51
@@ -58,10 +54,8 @@ In contrast to the `Transformer` class, it always returns the `same object` that
58
54
59
55
- If we Initialize a `ConstantTransformar` with `Runtime.class` and can call the `transform()` method with `any object`(for example, `HashSet`), we will always get the `Runtime.class` type object.
60
56
61
-

62
57
63
58
### InvokerTransformer
64
59
* During initialization, it takes a `method name` with optional parameters.
65
60
* On `transform`, it calls that method for the object provided with the parameters.
0 commit comments