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.AbstractInjectionBit.BlindOperator;
18 import com.jsql.model.injection.strategy.blind.InjectionBlindBin;
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 StrategyBlindBin extends AbstractStrategy {
29
30
31
32
33 private static final Logger LOGGER = LogManager.getRootLogger();
34
35 private InjectionBlindBin injectionBlindBin;
36
37 public StrategyBlindBin(InjectionModel injectionModel) {
38 super(injectionModel);
39 }
40
41 @Override
42 public void checkApplicability() throws StoppedByUserSlidingException {
43 if (this.injectionModel.getMediatorUtils().getPreferencesUtil().isStrategyBlindBinDisabled()) {
44 LOGGER.log(LogLevelUtil.CONSOLE_INFORM, AbstractStrategy.FORMAT_SKIP_STRATEGY_DISABLED, this.getName());
45 return;
46 } else if (StringUtils.isEmpty(
47 this.injectionModel.getMediatorVendor().getVendor().instance().getModelYaml().getStrategy().getBinary().getTest().getBin()
48 )) {
49 LOGGER.log(
50 LogLevelUtil.CONSOLE_ERROR,
51 AbstractStrategy.FORMAT_STRATEGY_NOT_IMPLEMENTED,
52 this.getName(),
53 this.injectionModel.getMediatorVendor().getVendor()
54 );
55 return;
56 }
57
58 this.checkInjection(BlindOperator.OR);
59 this.checkInjection(BlindOperator.AND);
60 this.checkInjection(BlindOperator.STACK);
61 this.checkInjection(BlindOperator.NO_MODE);
62
63 if (this.isApplicable) {
64 this.allow();
65 var requestMessageBinary = new Request();
66 requestMessageBinary.setMessage(Interaction.MESSAGE_BINARY);
67 requestMessageBinary.setParameters(this.injectionBlindBin.getInfoMessage());
68 this.injectionModel.sendToViews(requestMessageBinary);
69 } else {
70 this.unallow();
71 }
72 }
73
74 private void checkInjection(BlindOperator blindOperator) throws StoppedByUserSlidingException {
75 if (this.isApplicable) {
76 return;
77 }
78 LOGGER.log(
79 LogLevelUtil.CONSOLE_DEFAULT,
80 "{} [{}] with [{}]...",
81 () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_CHECKING_STRATEGY),
82 this::getName,
83 () -> blindOperator
84 );
85 this.injectionBlindBin = new InjectionBlindBin(this.injectionModel, blindOperator);
86 this.isApplicable = this.injectionBlindBin.isInjectable();
87 if (this.isApplicable) {
88 LOGGER.log(
89 LogLevelUtil.CONSOLE_SUCCESS,
90 "{} [{}] injection with [{}]",
91 () -> I18nUtil.valueByKey(AbstractStrategy.KEY_LOG_VULNERABLE),
92 this::getName,
93 () -> blindOperator
94 );
95 }
96 }
97
98 @Override
99 public void allow(int... i) {
100 this.injectionModel.appendAnalysisReport(
101 StringUtil.formatReport(LogLevelUtil.COLOR_BLU, "### Strategy: " + this.getName())
102 + this.injectionModel.getReportWithoutIndex(
103 this.injectionModel.getMediatorVendor().getVendor().instance().sqlTestBlindWithOperator(
104 this.injectionModel.getMediatorVendor().getVendor().instance().sqlBlind(StringUtil.formatReport(LogLevelUtil.COLOR_GREEN, "<query>"), "0", true),
105 this.injectionBlindBin.getBooleanMode()
106 ),
107 "metadataInjectionProcess",
108 null
109 )
110 );
111 this.markVulnerability(Interaction.MARK_BLIND_BIN_VULNERABLE);
112 }
113
114 @Override
115 public void unallow(int... i) {
116 this.markVulnerability(Interaction.MARK_BLIND_BIN_INVULNERABLE);
117 }
118
119 @Override
120 public String inject(String sqlQuery, String startPosition, AbstractSuspendable stoppable, String metadataInjectionProcess) throws StoppedByUserSlidingException {
121 return this.injectionBlindBin.inject(
122 this.injectionModel.getMediatorVendor().getVendor().instance().sqlBlind(sqlQuery, startPosition, false),
123 stoppable
124 );
125 }
126
127 @Override
128 public void activateWhenApplicable() {
129 if (this.injectionModel.getMediatorStrategy().getStrategy() == null && this.isApplicable()) {
130 LOGGER.log(
131 LogLevelUtil.CONSOLE_INFORM,
132 "{} [{}] with [{}]",
133 () -> I18nUtil.valueByKey("LOG_USING_STRATEGY"),
134 this::getName,
135 () -> this.injectionBlindBin.getBooleanMode().name()
136 );
137 this.injectionModel.getMediatorStrategy().setStrategy(this);
138
139 var requestMarkBlindBinStrategy = new Request();
140 requestMarkBlindBinStrategy.setMessage(Interaction.MARK_BLIND_BIN_STRATEGY);
141 this.injectionModel.sendToViews(requestMarkBlindBinStrategy);
142 }
143 }
144
145 @Override
146 public String getPerformanceLength() {
147 return VendorYaml.DEFAULT_CAPACITY;
148 }
149
150 @Override
151 public String getName() {
152 return "Blind bin";
153 }
154 }