1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-01-02 11:36:22 +01:00

add support for absolute paths, fixes #4874

git-svn-id: file:///home/svn/framework3/trunk@13108 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
James Lee 2011-07-06 21:35:51 +00:00
parent 0d1a29354e
commit ea2bc29a8e
8 changed files with 16 additions and 19 deletions

View File

@ -13,6 +13,13 @@ import com.metasploit.meterpreter.ExtensionLoader;
public class Loader implements ExtensionLoader {
public static File cwd;
public static File expand(String path) {
File result = new File(path);
if (!result.isAbsolute())
result = new File(cwd, path);
return result;
}
public void load(CommandManager mgr) throws Exception {
cwd = new File(".").getCanonicalFile();

View File

@ -1,7 +1,6 @@
package com.metasploit.meterpreter.stdapi;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -26,11 +25,11 @@ public class channel_create_stdapi_fs_file implements Command {
channel = new Channel(meterpreter, new ByteArrayInputStream(data), null);
}
if (channel == null)
channel = new Channel(meterpreter, new FileInputStream(new File(Loader.cwd, fpath)), null);
channel = new Channel(meterpreter, new FileInputStream(Loader.expand(fpath)), null);
} else if (mode.equals("r") || mode.equals("wb") || mode.equals("wbb")) {
channel = new Channel(meterpreter, new ByteArrayInputStream(new byte[0]), new FileOutputStream(new File(Loader.cwd, fpath).getPath(), false));
channel = new Channel(meterpreter, new ByteArrayInputStream(new byte[0]), new FileOutputStream(Loader.expand(fpath).getPath(), false));
} else if (mode.equals("a") || mode.equals("ab") || mode.equals("abb")) {
channel = new Channel(meterpreter, new ByteArrayInputStream(new byte[0]), new FileOutputStream(new File(Loader.cwd, fpath).getPath(), true));
channel = new Channel(meterpreter, new ByteArrayInputStream(new byte[0]), new FileOutputStream(Loader.expand(fpath).getPath(), true));
} else {
NotYetImplementedCommand.INSTANCE.execute(meterpreter, request, response);
throw new IllegalArgumentException("Unsupported file mode: " + mode);

View File

@ -12,12 +12,9 @@ public class stdapi_fs_chdir implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
File f = new File(Loader.cwd, path);
File f = Loader.expand(path);
if (!f.exists() || !f.isDirectory()) {
f = new File(path);
if (!f.exists() || !f.isDirectory()) {
throw new IOException("Path not found: " + path);
}
}
Loader.cwd = f.getCanonicalFile();
return ERROR_SUCCESS;

View File

@ -12,9 +12,7 @@ public class stdapi_fs_delete_dir implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
File file = new File(Loader.cwd, path);
if (!file.exists())
file = new File(path);
File file = Loader.expand(path);
if (!file.exists() || !file.isDirectory()) {
throw new IOException("Directory not found: " + path);
}

View File

@ -12,9 +12,7 @@ public class stdapi_fs_delete_file implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
File file = new File(Loader.cwd, path);
if (!file.exists())
file = new File(path);
File file = Loader.expand(path);
if (!file.exists() || !file.isFile()) {
throw new IOException("File not found: " + path);
}

View File

@ -12,9 +12,7 @@ public class stdapi_fs_mkdir implements Command {
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
File file = new File(Loader.cwd, path);
if (!file.getParentFile().exists())
file = new File(path);
File file = Loader.expand(path);
if (!file.getParentFile().exists() || !file.getParentFile().isDirectory()) {
throw new IOException("Parent directory not found: " + path);
}

View File

@ -54,7 +54,7 @@ public class stdapi_fs_search implements Command {
private List findFiles(String path, String mask, boolean recurse) {
try {
File pathfile = new File(Loader.cwd, path);
File pathfile = Loader.expand(path);
if (!pathfile.exists() || !pathfile.isDirectory()) {
pathfile = new File(path);
if (!pathfile.exists() || !pathfile.isDirectory()) {

View File

@ -16,7 +16,7 @@ public class stdapi_fs_stat implements Command {
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
File file = new File(path);
if (!file.exists())
file = new File(Loader.cwd, path);
file = Loader.expand(path);
if (!file.exists())
throw new IOException("File/directory does not exist: " + path);
response.add(TLVType.TLV_TYPE_STAT_BUF, stat(file));