1
2
3
4
5
6
7
8
9
10
11 package com.jsql.model.injection.strategy;
12
13 import com.jsql.model.InjectionModel;
14 import com.jsql.model.bean.util.Interaction;
15 import com.jsql.model.bean.util.Request;
16 import com.jsql.model.exception.StoppedByUserSlidingException;
17 import com.jsql.model.injection.strategy.blind.AbstractInjectionBinary.BinaryMode;
18 import com.jsql.model.injection.strategy.blind.InjectionBlind;
19 import com.jsql.model.injection.vendor.model.VendorYaml;
20 import com.jsql.model.suspendable.AbstractSuspendable;
21 import com.jsql.util.I18nUtil;
22 import com.jsql.util.LogLevelUtil;
23 import com.jsql.util.StringUtil;
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27
28 public class StrategyInjectionBlind extends AbstractStrategy {
29
30
31
32
33 private static final Logger LOGGER = LogManager.getRootLogger();
34
35 private InjectionBlind injectionBlind;
36
37 public StrategyInjectionBlind(InjectionModel injectionModel) {
38 super(injectionModel);
39 }
40
41 @Override
42 public void checkApplicability() throws StoppedByUserSlidingException {
43 if (this.injectionModel.getMediatorUtils().getPreferencesUtil().isStrategyBlindDisabled()) {
44 LOGGER.log(LogLevelUtil.CONSOLE_INFORM, AbstractStrategy.FORMAT_SKIP_STRATEGY_DISABLED, this.getName());
45 return;
46 } else if (StringUtils.isEmpty(this.injectionModel.getMediatorVendor().getVendor().instance().sqlBinaryBlind())) {
47 LOGGER.log(
48 LogLevelUtil.CONSOLE_ERROR,
49 AbstractStrategy.FORMAT_STRATEGY_NOT_IMPLEMENTED,
50 this.getName(),
51 this.injectionModel.getMediatorVendor().getVendor()
52 );
53 return;
54 }
55
56 this.checkInjection(BinaryMode.OR);
57 this.checkInjection(BinaryMode.AND);
58 this.checkInjection(BinaryMode.STACK);
59 this.checkInjection(BinaryMode.NO_MODE);
60
61 if (this.isApplicable) {
62 this.allow();
63
64 var requestMessageBinary = new Request();
65 requestMessageBinary.setMessage(Interaction.MESSAGE_BINARY);
66 requestMessageBinary.setParameters(this.injectionBlind.getInfoMessage());
67 this.injectionModel.sendToViews(requestMessageBinary);
68 } else {
69 this.unallow();
70 }
71 }
72
73 private void checkInjection(BinaryMode binaryMode) throws StoppedByUserSlidingException {
74 if (this.isApplicable) {
75 return;
76 }
77
78 LOGGER.log(
79 LogLevelUtil.CONSOLE_DEFAULT,
80 "{} [{}] with [{}]...",
81 () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_CHECKING_STRATEGY),
82 this::getName,
83 () -> binaryMode
84 );
85 this.injectionBlind = new InjectionBlind(this.injectionModel, binaryMode);
86 this.isApplicable = this.injectionBlind.isInjectable();
87
88 if (this.isApplicable) {
89 LOGGER.log(
90 LogLevelUtil.CONSOLE_SUCCESS,
91 "{} [{}] injection with [{}]",
92 () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_VULNERABLE),
93 this::getName,
94 () -> binaryMode
95 );
96 }
97 }
98
99 @Override
100 public void allow(int... i) {
101 this.injectionModel.appendAnalysisReport(
102 StringUtil.formatReport(LogLevelUtil.COLOR_BLU, "### Strategy: " + this.getName())
103 + this.injectionModel.getReportWithoutIndex(
104 this.injectionModel.getMediatorVendor().getVendor().instance().sqlTestBlind(
105 this.injectionModel.getMediatorVendor().getVendor().instance().sqlBlind(
106 StringUtil.formatReport(LogLevelUtil.COLOR_GREEN, "<query>"),
107 "0",
108 true
109 ),
110 this.injectionBlind.getBooleanMode()
111 ),
112 "metadataInjectionProcess",
113 null
114 )
115 );
116 this.markVulnerability(Interaction.MARK_BLIND_VULNERABLE);
117 }
118
119 @Override
120 public void unallow(int... i) {
121 this.markVulnerability(Interaction.MARK_BLIND_INVULNERABLE);
122 }
123
124 @Override
125 public String inject(String sqlQuery, String startPosition, AbstractSuspendable stoppable, String metadataInjectionProcess) throws StoppedByUserSlidingException {
126 return this.injectionBlind.inject(
127 this.injectionModel.getMediatorVendor().getVendor().instance().sqlBlind(sqlQuery, startPosition, false),
128 stoppable
129 );
130 }
131
132 @Override
133 public void activateWhenApplicable() {
134 if (this.injectionModel.getMediatorStrategy().getStrategy() == null && this.isApplicable()) {
135 LOGGER.log(
136 LogLevelUtil.CONSOLE_INFORM,
137 "{} [{}] with [{}]",
138 () -> I18nUtil.valueByKey("LOG_USING_STRATEGY"),
139 this::getName,
140 () -> this.injectionBlind.getBooleanMode().name()
141 );
142 this.injectionModel.getMediatorStrategy().setStrategy(this.injectionModel.getMediatorStrategy().getBlind());
143
144 var requestMarkBlindStrategy = new Request();
145 requestMarkBlindStrategy.setMessage(Interaction.MARK_BLIND_STRATEGY);
146 this.injectionModel.sendToViews(requestMarkBlindStrategy);
147 }
148 }
149
150 @Override
151 public String getPerformanceLength() {
152 return VendorYaml.DEFAULT_CAPACITY;
153 }
154
155 @Override
156 public String getName() {
157 return "Blind";
158 }
159 }