1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | ******************************************************************************/ | |
11 | package com.jsql.view.swing.manager; | |
12 | ||
13 | import com.jsql.model.exception.JSqlException; | |
14 | import com.jsql.util.I18nUtil; | |
15 | import com.jsql.util.LogLevelUtil; | |
16 | import com.jsql.view.swing.list.DnDList; | |
17 | import com.jsql.view.swing.list.ItemList; | |
18 | import com.jsql.view.swing.manager.util.JButtonStateful; | |
19 | import com.jsql.view.swing.scrollpane.LightScrollPane; | |
20 | import com.jsql.view.swing.text.JPopupTextField; | |
21 | import com.jsql.view.swing.ui.FlatButtonMouseAdapter; | |
22 | import com.jsql.view.swing.util.I18nViewUtil; | |
23 | import com.jsql.view.swing.util.UiUtil; | |
24 | import org.apache.commons.lang3.StringUtils; | |
25 | import org.apache.logging.log4j.LogManager; | |
26 | import org.apache.logging.log4j.Logger; | |
27 | ||
28 | import javax.swing.*; | |
29 | import java.awt.*; | |
30 | import java.awt.event.ActionEvent; | |
31 | import java.awt.event.ActionListener; | |
32 | import java.io.BufferedReader; | |
33 | import java.io.IOException; | |
34 | import java.io.InputStreamReader; | |
35 | import java.net.URI; | |
36 | import java.net.URISyntaxException; | |
37 | import java.nio.charset.StandardCharsets; | |
38 | import java.util.ArrayList; | |
39 | import java.util.List; | |
40 | import java.util.Objects; | |
41 | ||
42 | /** | |
43 | * Manager for uploading PHP webshell to the host and send system commands. | |
44 | */ | |
45 | public abstract class AbstractManagerShell extends AbstractManagerList { | |
46 | | |
47 | /** | |
48 | * Log4j logger sent to view. | |
49 | */ | |
50 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
51 | ||
52 | private final JTextField textfieldUrlShell = new JPopupTextField(I18nUtil.valueByKey("SHELL_URL_LABEL")).getProxy(); | |
53 | | |
54 | /** | |
55 | * Build the manager panel. | |
56 | */ | |
57 | protected AbstractManagerShell() { | |
58 | | |
59 |
1
1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerShell::setLayout → NO_COVERAGE |
this.setLayout(new BorderLayout()); |
60 | | |
61 | List<ItemList> itemsList = new ArrayList<>(); | |
62 | | |
63 | try ( | |
64 | var inputStream = UiUtil.class.getClassLoader().getResourceAsStream(UiUtil.PATH_WEB_FOLDERS); | |
65 | var inputStreamReader = new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8); | |
66 | var reader = new BufferedReader(inputStreamReader) | |
67 | ) { | |
68 | String line; | |
69 |
1
1. <init> : negated conditional → NO_COVERAGE |
while ((line = reader.readLine()) != null) { |
70 | itemsList.add(new ItemList(line)); | |
71 | } | |
72 | } catch (IOException e) { | |
73 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
74 | } | |
75 | ||
76 | this.listPaths = new DnDList(itemsList); | |
77 | | |
78 |
1
1. <init> : removed call to com/jsql/view/swing/list/DnDList::setBorder → NO_COVERAGE |
this.getListPaths().setBorder(BorderFactory.createEmptyBorder(0, 0, LightScrollPane.THUMB_SIZE, 0)); |
79 | | |
80 |
1
1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerShell::add → NO_COVERAGE |
this.add(new LightScrollPane(0, 0, 0, 0, this.getListPaths()), BorderLayout.CENTER); |
81 | | |
82 | var southPanel = new JPanel(); | |
83 |
1
1. <init> : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE |
southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.Y_AXIS)); |
84 | ||
85 | String urlTooltip = I18nUtil.valueByKey("SHELL_URL_TOOLTIP"); | |
86 | | |
87 |
1
1. <init> : removed call to javax/swing/JTextField::setToolTipText → NO_COVERAGE |
this.textfieldUrlShell.setToolTipText(urlTooltip); |
88 |
1
1. <init> : removed call to javax/swing/JTextField::setBorder → NO_COVERAGE |
this.textfieldUrlShell.setBorder( |
89 | BorderFactory.createCompoundBorder( | |
90 | BorderFactory.createCompoundBorder( | |
91 | BorderFactory.createMatteBorder(0, 0, 0, 0, UiUtil.COLOR_COMPONENT_BORDER), | |
92 | BorderFactory.createMatteBorder(1, 1, 0, 1, UiUtil.COLOR_DEFAULT_BACKGROUND) | |
93 | ), | |
94 | UiUtil.BORDER_BLU | |
95 | ) | |
96 | ); | |
97 | ||
98 | JPanel lastLine = this.initializeRunButtonPanel(); | |
99 | ||
100 | southPanel.add(this.textfieldUrlShell); | |
101 | southPanel.add(lastLine); | |
102 | | |
103 |
1
1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerShell::add → NO_COVERAGE |
this.add(southPanel, BorderLayout.SOUTH); |
104 | } | |
105 | | |
106 | protected abstract void createPayload(String pathShell, String urlShell) throws JSqlException; | |
107 | ||
108 | private JPanel initializeRunButtonPanel() { | |
109 | ||
110 | this.defaultText = "SHELL_RUN_BUTTON_LABEL"; | |
111 | | |
112 | var lastLine = new JPanel(); | |
113 |
1
1. initializeRunButtonPanel : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE |
lastLine.setLayout(new BoxLayout(lastLine, BoxLayout.X_AXIS)); |
114 |
1
1. initializeRunButtonPanel : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE |
lastLine.setBorder( |
115 | BorderFactory.createCompoundBorder( | |
116 | BorderFactory.createMatteBorder(0, 0, 0, 0, UiUtil.COLOR_COMPONENT_BORDER), | |
117 | BorderFactory.createEmptyBorder(1, 0, 1, 1) | |
118 | ) | |
119 | ); | |
120 | | |
121 | this.run = new JButtonStateful(this.defaultText); | |
122 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey(this.defaultText, this.run); |
123 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setToolTipText → NO_COVERAGE |
this.run.setToolTipText(I18nUtil.valueByKey("SHELL_RUN_BUTTON_TOOLTIP")); |
124 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.run.setEnabled(false); |
125 | ||
126 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setContentAreaFilled → NO_COVERAGE |
this.run.setContentAreaFilled(false); |
127 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setBorder → NO_COVERAGE |
this.run.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8)); |
128 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setBackground → NO_COVERAGE |
this.run.setBackground(UiUtil.COLOR_FOCUS_GAINED); |
129 | | |
130 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addMouseListener → NO_COVERAGE |
this.run.addMouseListener(new FlatButtonMouseAdapter(this.run)); |
131 | ||
132 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE |
this.run.addActionListener(new ActionCreationShell()); |
133 | ||
134 | this.privilege = new JLabel(I18nUtil.valueByKey("PRIVILEGE_LABEL"), UiUtil.ICON_SQUARE_GREY, SwingConstants.LEFT); | |
135 |
1
1. initializeRunButtonPanel : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("PRIVILEGE_LABEL", this.privilege); |
136 |
1
1. initializeRunButtonPanel : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
this.privilege.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, UiUtil.COLOR_DEFAULT_BACKGROUND)); |
137 |
1
1. initializeRunButtonPanel : removed call to javax/swing/JLabel::setToolTipText → NO_COVERAGE |
this.privilege.setToolTipText(I18nUtil.valueByKey("PRIVILEGE_TOOLTIP")); |
138 | ||
139 | lastLine.add(this.privilege); | |
140 | lastLine.add(Box.createHorizontalStrut(5)); | |
141 | lastLine.add(Box.createHorizontalGlue()); | |
142 | lastLine.add(this.run); | |
143 | | |
144 |
1
1. initializeRunButtonPanel : replaced return value with null for com/jsql/view/swing/manager/AbstractManagerShell::initializeRunButtonPanel → NO_COVERAGE |
return lastLine; |
145 | } | |
146 | | |
147 | private class ActionCreationShell implements ActionListener { | |
148 | | |
149 | @Override | |
150 | public void actionPerformed(ActionEvent evt) { | |
151 | | |
152 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (AbstractManagerShell.this.getListPaths().getSelectedValuesList().isEmpty()) { |
153 | | |
154 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Select at least one directory in the list"); | |
155 | return; | |
156 | } | |
157 | ||
158 | String refUrlShell = AbstractManagerShell.this.textfieldUrlShell.getText(); | |
159 | | |
160 |
2
1. actionPerformed : negated conditional → NO_COVERAGE 2. actionPerformed : negated conditional → NO_COVERAGE |
if (!refUrlShell.isEmpty() && !refUrlShell.matches("(?i)^https?://.*")) { |
161 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (!refUrlShell.matches("(?i)^\\w+://.*")) { |
162 | | |
163 | LOGGER.log(LogLevelUtil.CONSOLE_INFORM, "Undefined shell URL protocol, forcing to [http://]"); | |
164 | refUrlShell = "http://"+ refUrlShell; | |
165 | | |
166 | } else { | |
167 | | |
168 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Unknown URL protocol"); | |
169 | return; | |
170 | } | |
171 | } | |
172 | | |
173 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (StringUtils.isNotEmpty(refUrlShell)) { |
174 | try { | |
175 | new URI(refUrlShell); | |
176 | } catch (URISyntaxException e) { | |
177 | | |
178 | LOGGER.log( | |
179 | LogLevelUtil.CONSOLE_ERROR, | |
180 | String.format("Incorrect URL: %s", e.getMessage()) | |
181 | ); | |
182 | return; | |
183 | } | |
184 | } | |
185 | | |
186 | String urlShellFinal = refUrlShell; | |
187 | ||
188 | AbstractManagerShell.this.getListPaths() | |
189 | .getSelectedValuesList() | |
190 |
1
1. actionPerformed : removed call to java/util/List::forEach → NO_COVERAGE |
.forEach(pathShell -> new Thread( |
191 | () -> { | |
192 | try { | |
193 |
1
1. lambda$actionPerformed$0 : removed call to com/jsql/view/swing/manager/AbstractManagerShell::createPayload → NO_COVERAGE |
AbstractManagerShell.this.createPayload(pathShell.toString(), urlShellFinal); |
194 | } catch (JSqlException e) { | |
195 | LOGGER.log( | |
196 | LogLevelUtil.CONSOLE_ERROR, | |
197 | String.format("Payload creation error: %s", e.getMessage()) | |
198 | ); | |
199 | } | |
200 | }, | |
201 | "ThreadGetShell" | |
202 |
1
1. lambda$actionPerformed$1 : removed call to java/lang/Thread::start → NO_COVERAGE |
).start()); |
203 | } | |
204 | } | |
205 | } | |
Mutations | ||
59 |
1.1 |
|
69 |
1.1 |
|
78 |
1.1 |
|
80 |
1.1 |
|
83 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
103 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
130 |
1.1 |
|
132 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
144 |
1.1 |
|
152 |
1.1 |
|
160 |
1.1 2.2 |
|
161 |
1.1 |
|
173 |
1.1 |
|
190 |
1.1 |
|
193 |
1.1 |
|
202 |
1.1 |