mirror of
https://github.com/rapid7/metasploit-payloads
synced 2024-11-26 17:41:08 +01:00
implement full globbing
This commit is contained in:
parent
0e8fe2b642
commit
29ca118b98
@ -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;
|
||||
@ -12,14 +13,26 @@ 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");
|
||||
String pathString = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
||||
if (pathString.equals("*")) {
|
||||
pathString = ".";
|
||||
} else if (pathString.contains("*")) {
|
||||
if (pathString.endsWith(File.separator + "*")) {
|
||||
pathString = pathString.substring(0, pathString.length() - 1);
|
||||
}
|
||||
}
|
||||
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, pathEntry);
|
||||
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…
Reference in New Issue
Block a user