mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-03-18 15:14:10 +01:00
Land #382, fix wildcard handling in Java meterpreter
This commit is contained in:
commit
a27f7c0388
java/meterpreter/stdapi/src/main/java/com/metasploit/meterpreter/stdapi
@ -1,6 +1,7 @@
|
||||
package com.metasploit.meterpreter.stdapi;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.metasploit.meterpreter.Meterpreter;
|
||||
import com.metasploit.meterpreter.TLVPacket;
|
||||
@ -8,9 +9,30 @@ import com.metasploit.meterpreter.TLVType;
|
||||
import com.metasploit.meterpreter.command.Command;
|
||||
|
||||
public class stdapi_fs_ls implements Command {
|
||||
|
||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||
stdapi_fs_stat statCommand = (stdapi_fs_stat) meterpreter.getCommandManager().getCommand("stdapi_fs_stat");
|
||||
File path = Loader.expand(request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH));
|
||||
String pathString = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
||||
File path = Loader.expand(pathString);
|
||||
if (pathString.contains("*")) {
|
||||
String root = path.getParent();
|
||||
String match = path.getName();
|
||||
List entries = stdapi_fs_search.findFiles(root, match, false);
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String entry = entries.get(i).toString();
|
||||
if (entry.equals(".") || entry.equals(".."))
|
||||
continue;
|
||||
File f = new File(entry);
|
||||
String pathEntry = entry;
|
||||
if (pathEntry.startsWith(root)) {
|
||||
pathEntry = pathEntry.substring(root.length() + 1);
|
||||
}
|
||||
response.addOverflow(TLVType.TLV_TYPE_FILE_NAME, f.getName());
|
||||
response.addOverflow(TLVType.TLV_TYPE_FILE_PATH, pathEntry);
|
||||
response.addOverflow(TLVType.TLV_TYPE_STAT_BUF, statCommand.stat(f));
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
String[] entries = path.list();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].equals(".") || entries[i].equals(".."))
|
||||
|
@ -52,7 +52,7 @@ public class stdapi_fs_search implements Command {
|
||||
}
|
||||
}
|
||||
|
||||
private List findFiles(String path, String mask, boolean recurse) {
|
||||
public static List findFiles(String path, String mask, boolean recurse) {
|
||||
try {
|
||||
File pathfile = Loader.expand(path);
|
||||
if (!pathfile.exists() || !pathfile.isDirectory()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user