1 package com.jsql.view.swing.panel.preferences;
2
3 import com.jsql.util.tampering.TamperingType;
4 import com.jsql.view.swing.panel.PanelPreferences;
5 import com.jsql.view.swing.panel.preferences.listener.TamperingMouseAdapter;
6 import com.jsql.view.swing.popupmenu.JPopupMenuComponent;
7 import com.jsql.view.swing.text.SyntaxTextArea;
8 import com.jsql.view.swing.text.listener.DocumentListenerEditing;
9 import com.jsql.view.swing.util.MediatorHelper;
10 import com.jsql.view.swing.util.UiUtil;
11 import org.apache.commons.lang3.StringUtils;
12 import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
13 import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
14 import org.fife.ui.rtextarea.RTextScrollPane;
15
16 import javax.swing.*;
17 import java.util.AbstractMap.SimpleEntry;
18 import java.util.Arrays;
19 import java.util.stream.Stream;
20
21 public class PanelTampering extends JPanel {
22
23
24 private final JCheckBox checkboxIsTamperingBase64 = new JCheckBox();
25 private final JCheckBox checkboxIsTamperingVersionComment = new JCheckBox();
26 private final JCheckBox checkboxIsTamperingFunctionComment = new JCheckBox();
27 private final JCheckBox checkboxIsTamperingEqualToLike = new JCheckBox();
28 private final JCheckBox checkboxIsTamperingRandomCase = new JCheckBox();
29 private final JCheckBox checkboxIsTamperingEval = new JCheckBox();
30 private final JCheckBox checkboxIsTamperingHexToChar = new JCheckBox();
31 private final JCheckBox checkboxIsTamperingStringToChar = new JCheckBox();
32 private final JCheckBox checkboxIsTamperingQuoteToUtf8 = new JCheckBox();
33 private final JCheckBox checkboxIsTamperingCharToEncoding = new JCheckBox();
34 private final JRadioButton radioIsTamperingSpaceToMultilineComment = new JRadioButton();
35 private final JRadioButton radioIsTamperingSpaceToDashComment = new JRadioButton();
36 private final JRadioButton radioIsTamperingSpaceToSharpComment = new JRadioButton();
37
38 private static final RSyntaxTextArea TEXT_PANE_EVAL = new SyntaxTextArea("Click on a tamper to paste source and edit custom script");
39
40 public PanelTampering(PanelPreferences panelPreferences) {
41 this.checkboxIsTamperingEval.setToolTipText("Custom tamper in JavaScript and Java, e.g. sql.replace(/\\+/gm,'/**/')");
42
43 PanelTampering.TEXT_PANE_EVAL.setText(StringUtils.EMPTY);
44 PanelTampering.TEXT_PANE_EVAL.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
45 PanelTampering.TEXT_PANE_EVAL.setPopupMenu(new JPopupMenuComponent(PanelTampering.TEXT_PANE_EVAL));
46 PanelTampering.applyTheme();
47
48 var textAreaIsTamperingEval = new RTextScrollPane(PanelTampering.TEXT_PANE_EVAL, false);
49
50 PanelTampering.TEXT_PANE_EVAL.getDocument().addDocumentListener(new DocumentListenerEditing() {
51 @Override
52 public void process() {
53 MediatorHelper.model().getMediatorUtils().tamperingUtil().setCustomTamper(PanelTampering.TEXT_PANE_EVAL.getText());
54 }
55 });
56 PanelTampering.TEXT_PANE_EVAL.setText(MediatorHelper.model().getMediatorUtils().tamperingUtil().getCustomTamper());
57 this.checkboxIsTamperingEval.addActionListener(panelPreferences.getActionListenerSave());
58 this.checkboxIsTamperingEval.setText("Enable user tamper script:");
59
60 Stream.of(
61 new SimpleEntry<>(this.checkboxIsTamperingBase64, TamperingType.BASE64),
62 new SimpleEntry<>(this.checkboxIsTamperingFunctionComment, TamperingType.COMMENT_TO_METHOD_SIGNATURE),
63 new SimpleEntry<>(this.checkboxIsTamperingVersionComment, TamperingType.VERSIONED_COMMENT_TO_METHOD_SIGNATURE),
64 new SimpleEntry<>(this.checkboxIsTamperingEqualToLike, TamperingType.EQUAL_TO_LIKE),
65 new SimpleEntry<>(this.checkboxIsTamperingRandomCase, TamperingType.RANDOM_CASE),
66 new SimpleEntry<>(this.checkboxIsTamperingHexToChar, TamperingType.HEX_TO_CHAR),
67 new SimpleEntry<>(this.checkboxIsTamperingStringToChar, TamperingType.STRING_TO_CHAR),
68 new SimpleEntry<>(this.checkboxIsTamperingQuoteToUtf8, TamperingType.QUOTE_TO_UTF8),
69 new SimpleEntry<>(this.checkboxIsTamperingCharToEncoding, TamperingType.CHAR_TO_ENCODING),
70 new SimpleEntry<>(this.radioIsTamperingSpaceToMultilineComment, TamperingType.SPACE_TO_MULTILINE_COMMENT),
71 new SimpleEntry<>(this.radioIsTamperingSpaceToDashComment, TamperingType.SPACE_TO_DASH_COMMENT),
72 new SimpleEntry<>(this.radioIsTamperingSpaceToSharpComment, TamperingType.SPACE_TO_SHARP_COMMENT)
73 )
74 .forEach(entry -> {
75 entry.getKey().setText(entry.getValue().instance().getDescription());
76 entry.getKey().setToolTipText(entry.getValue().instance().getTooltip());
77 entry.getKey().addMouseListener(new TamperingMouseAdapter(entry.getValue(), PanelTampering.TEXT_PANE_EVAL));
78 entry.getKey().addActionListener(panelPreferences.getActionListenerSave());
79 });
80
81 var groupSpaceToComment = new ButtonGroup() {
82 @Override
83 public void setSelected(ButtonModel buttonModel, boolean isSelected) {
84 if (isSelected) {
85 super.setSelected(buttonModel, true);
86 } else {
87 this.clearSelection();
88 }
89 }
90 };
91 groupSpaceToComment.add(this.radioIsTamperingSpaceToDashComment);
92 groupSpaceToComment.add(this.radioIsTamperingSpaceToMultilineComment);
93 groupSpaceToComment.add(this.radioIsTamperingSpaceToSharpComment);
94
95 var labelCommonConversion = new JLabel("<html><b>Common tamper</b></html>");
96 var labelSpaceTamper = new JLabel("<html><br /><b>Space tamper (click again to uncheck)</b></html>");
97 var labelCustomConversion = new JLabel("<html><br /><b>Custom tamper (hover tamper to show implementation, click to paste)</b></html>");
98 Arrays.asList(labelCommonConversion, labelSpaceTamper, labelCustomConversion).forEach(label -> label.setBorder(PanelGeneral.MARGIN));
99
100 var groupLayout = new GroupLayout(this);
101 this.setLayout(groupLayout);
102
103 groupLayout.setHorizontalGroup(
104 groupLayout
105 .createSequentialGroup()
106 .addGroup(
107 groupLayout
108 .createParallelGroup(GroupLayout.Alignment.LEADING)
109 .addComponent(labelCommonConversion)
110 .addComponent(this.checkboxIsTamperingBase64)
111 .addComponent(this.checkboxIsTamperingFunctionComment)
112 .addComponent(this.checkboxIsTamperingVersionComment)
113 .addComponent(this.checkboxIsTamperingEqualToLike)
114 .addComponent(this.checkboxIsTamperingRandomCase)
115 .addComponent(this.checkboxIsTamperingStringToChar)
116 .addComponent(this.checkboxIsTamperingHexToChar)
117 .addComponent(this.checkboxIsTamperingQuoteToUtf8)
118 .addComponent(this.checkboxIsTamperingCharToEncoding)
119 .addComponent(labelSpaceTamper)
120 .addComponent(this.radioIsTamperingSpaceToMultilineComment)
121 .addComponent(this.radioIsTamperingSpaceToDashComment)
122 .addComponent(this.radioIsTamperingSpaceToSharpComment)
123 .addComponent(labelCustomConversion)
124 .addComponent(this.checkboxIsTamperingEval)
125 .addComponent(textAreaIsTamperingEval)
126 )
127 );
128
129 groupLayout.setVerticalGroup(
130 groupLayout
131 .createSequentialGroup()
132 .addGroup(
133 groupLayout
134 .createParallelGroup(GroupLayout.Alignment.BASELINE)
135 .addComponent(labelCommonConversion)
136 )
137 .addGroup(
138 groupLayout
139 .createParallelGroup(GroupLayout.Alignment.BASELINE)
140 .addComponent(this.checkboxIsTamperingBase64)
141 )
142 .addGroup(
143 groupLayout
144 .createParallelGroup(GroupLayout.Alignment.BASELINE)
145 .addComponent(this.checkboxIsTamperingFunctionComment)
146 )
147 .addGroup(
148 groupLayout
149 .createParallelGroup(GroupLayout.Alignment.BASELINE)
150 .addComponent(this.checkboxIsTamperingVersionComment)
151 )
152 .addGroup(
153 groupLayout
154 .createParallelGroup(GroupLayout.Alignment.BASELINE)
155 .addComponent(this.checkboxIsTamperingEqualToLike)
156 )
157 .addGroup(
158 groupLayout
159 .createParallelGroup(GroupLayout.Alignment.BASELINE)
160 .addComponent(this.checkboxIsTamperingRandomCase)
161 )
162 .addGroup(
163 groupLayout
164 .createParallelGroup(GroupLayout.Alignment.BASELINE)
165 .addComponent(this.checkboxIsTamperingStringToChar)
166 )
167 .addGroup(
168 groupLayout
169 .createParallelGroup(GroupLayout.Alignment.BASELINE)
170 .addComponent(this.checkboxIsTamperingHexToChar)
171 )
172 .addGroup(
173 groupLayout
174 .createParallelGroup(GroupLayout.Alignment.BASELINE)
175 .addComponent(this.checkboxIsTamperingQuoteToUtf8)
176 )
177 .addGroup(
178 groupLayout
179 .createParallelGroup(GroupLayout.Alignment.BASELINE)
180 .addComponent(this.checkboxIsTamperingCharToEncoding)
181 )
182 .addGroup(
183 groupLayout
184 .createParallelGroup(GroupLayout.Alignment.BASELINE)
185 .addComponent(labelSpaceTamper)
186 )
187 .addGroup(
188 groupLayout
189 .createParallelGroup(GroupLayout.Alignment.BASELINE)
190 .addComponent(this.radioIsTamperingSpaceToMultilineComment)
191 )
192 .addGroup(
193 groupLayout
194 .createParallelGroup(GroupLayout.Alignment.BASELINE)
195 .addComponent(this.radioIsTamperingSpaceToDashComment)
196 )
197 .addGroup(
198 groupLayout
199 .createParallelGroup(GroupLayout.Alignment.BASELINE)
200 .addComponent(this.radioIsTamperingSpaceToSharpComment)
201 )
202 .addGroup(
203 groupLayout
204 .createParallelGroup(GroupLayout.Alignment.BASELINE)
205 .addComponent(labelCustomConversion)
206 )
207 .addGroup(
208 groupLayout
209 .createParallelGroup(GroupLayout.Alignment.BASELINE)
210 .addComponent(this.checkboxIsTamperingEval)
211 )
212 .addGroup(
213 groupLayout
214 .createParallelGroup(GroupLayout.Alignment.BASELINE)
215 .addComponent(textAreaIsTamperingEval)
216 )
217 );
218 }
219
220 public static void applyTheme() {
221 UiUtil.applySyntaxTheme(PanelTampering.TEXT_PANE_EVAL);
222 }
223
224
225
226
227 public JCheckBox getCheckboxIsTamperingBase64() {
228 return this.checkboxIsTamperingBase64;
229 }
230
231 public JCheckBox getCheckboxIsTamperingEqualToLike() {
232 return this.checkboxIsTamperingEqualToLike;
233 }
234
235 public JCheckBox getCheckboxIsTamperingFunctionComment() {
236 return this.checkboxIsTamperingFunctionComment;
237 }
238
239 public JCheckBox getCheckboxIsTamperingVersionComment() {
240 return this.checkboxIsTamperingVersionComment;
241 }
242
243 public JCheckBox getCheckboxIsTamperingRandomCase() {
244 return this.checkboxIsTamperingRandomCase;
245 }
246
247 public JCheckBox getCheckboxIsTamperingEval() {
248 return this.checkboxIsTamperingEval;
249 }
250
251 public JRadioButton getRadioIsTamperingSpaceToDashComment() {
252 return this.radioIsTamperingSpaceToDashComment;
253 }
254
255 public JRadioButton getRadioIsTamperingSpaceToMultilineComment() {
256 return this.radioIsTamperingSpaceToMultilineComment;
257 }
258
259 public JRadioButton getRadioIsTamperingSpaceToSharpComment() {
260 return this.radioIsTamperingSpaceToSharpComment;
261 }
262
263 public JCheckBox getCheckboxIsTamperingHexToChar() {
264 return this.checkboxIsTamperingHexToChar;
265 }
266
267 public JCheckBox getCheckboxIsTamperingQuoteToUtf8() {
268 return this.checkboxIsTamperingQuoteToUtf8;
269 }
270
271 public JCheckBox getCheckboxIsTamperingCharToEncoding() {
272 return this.checkboxIsTamperingCharToEncoding;
273 }
274
275 public JCheckBox getCheckboxIsTamperingStringToChar() {
276 return this.checkboxIsTamperingStringToChar;
277 }
278 }