mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-01-20 20:37:27 +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:
parent
0d1a29354e
commit
ea2bc29a8e
@ -13,6 +13,13 @@ import com.metasploit.meterpreter.ExtensionLoader;
|
|||||||
public class Loader implements ExtensionLoader {
|
public class Loader implements ExtensionLoader {
|
||||||
|
|
||||||
public static File cwd;
|
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 {
|
public void load(CommandManager mgr) throws Exception {
|
||||||
cwd = new File(".").getCanonicalFile();
|
cwd = new File(".").getCanonicalFile();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.metasploit.meterpreter.stdapi;
|
package com.metasploit.meterpreter.stdapi;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
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);
|
channel = new Channel(meterpreter, new ByteArrayInputStream(data), null);
|
||||||
}
|
}
|
||||||
if (channel == 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")) {
|
} 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")) {
|
} 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 {
|
} else {
|
||||||
NotYetImplementedCommand.INSTANCE.execute(meterpreter, request, response);
|
NotYetImplementedCommand.INSTANCE.execute(meterpreter, request, response);
|
||||||
throw new IllegalArgumentException("Unsupported file mode: " + mode);
|
throw new IllegalArgumentException("Unsupported file mode: " + mode);
|
||||||
|
@ -12,12 +12,9 @@ public class stdapi_fs_chdir implements Command {
|
|||||||
|
|
||||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||||
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
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()) {
|
if (!f.exists() || !f.isDirectory()) {
|
||||||
f = new File(path);
|
|
||||||
if (!f.exists() || !f.isDirectory()) {
|
|
||||||
throw new IOException("Path not found: " + path);
|
throw new IOException("Path not found: " + path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loader.cwd = f.getCanonicalFile();
|
Loader.cwd = f.getCanonicalFile();
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
|
@ -12,9 +12,7 @@ public class stdapi_fs_delete_dir implements Command {
|
|||||||
|
|
||||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||||
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
||||||
File file = new File(Loader.cwd, path);
|
File file = Loader.expand(path);
|
||||||
if (!file.exists())
|
|
||||||
file = new File(path);
|
|
||||||
if (!file.exists() || !file.isDirectory()) {
|
if (!file.exists() || !file.isDirectory()) {
|
||||||
throw new IOException("Directory not found: " + path);
|
throw new IOException("Directory not found: " + path);
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,7 @@ public class stdapi_fs_delete_file implements Command {
|
|||||||
|
|
||||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||||
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
|
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
|
||||||
File file = new File(Loader.cwd, path);
|
File file = Loader.expand(path);
|
||||||
if (!file.exists())
|
|
||||||
file = new File(path);
|
|
||||||
if (!file.exists() || !file.isFile()) {
|
if (!file.exists() || !file.isFile()) {
|
||||||
throw new IOException("File not found: " + path);
|
throw new IOException("File not found: " + path);
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,7 @@ public class stdapi_fs_mkdir implements Command {
|
|||||||
|
|
||||||
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
public int execute(Meterpreter meterpreter, TLVPacket request, TLVPacket response) throws Exception {
|
||||||
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
String path = request.getStringValue(TLVType.TLV_TYPE_DIRECTORY_PATH);
|
||||||
File file = new File(Loader.cwd, path);
|
File file = Loader.expand(path);
|
||||||
if (!file.getParentFile().exists())
|
|
||||||
file = new File(path);
|
|
||||||
if (!file.getParentFile().exists() || !file.getParentFile().isDirectory()) {
|
if (!file.getParentFile().exists() || !file.getParentFile().isDirectory()) {
|
||||||
throw new IOException("Parent directory not found: " + path);
|
throw new IOException("Parent directory not found: " + path);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class stdapi_fs_search implements Command {
|
|||||||
|
|
||||||
private List findFiles(String path, String mask, boolean recurse) {
|
private List findFiles(String path, String mask, boolean recurse) {
|
||||||
try {
|
try {
|
||||||
File pathfile = new File(Loader.cwd, path);
|
File pathfile = Loader.expand(path);
|
||||||
if (!pathfile.exists() || !pathfile.isDirectory()) {
|
if (!pathfile.exists() || !pathfile.isDirectory()) {
|
||||||
pathfile = new File(path);
|
pathfile = new File(path);
|
||||||
if (!pathfile.exists() || !pathfile.isDirectory()) {
|
if (!pathfile.exists() || !pathfile.isDirectory()) {
|
||||||
|
@ -16,7 +16,7 @@ public class stdapi_fs_stat implements Command {
|
|||||||
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
|
String path = request.getStringValue(TLVType.TLV_TYPE_FILE_PATH);
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
file = new File(Loader.cwd, path);
|
file = Loader.expand(path);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
throw new IOException("File/directory does not exist: " + path);
|
throw new IOException("File/directory does not exist: " + path);
|
||||||
response.add(TLVType.TLV_TYPE_STAT_BUF, stat(file));
|
response.add(TLVType.TLV_TYPE_STAT_BUF, stat(file));
|
||||||
|
Loading…
Reference in New Issue
Block a user