Fixes 416. Adds the rm/del commands to meterpreter, fixes build problems triggered by the POSIX code merge

git-svn-id: file:///home/svn/framework3/trunk@7291 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2009-10-27 02:31:07 +00:00
parent 276a3f8052
commit 5234fe8ff8
13 changed files with 84 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
#include "../precomp.h"
#include "precomp.h"
#include <sys/stat.h>
#ifndef _WIN32

View File

@ -1,4 +1,4 @@
#include "../precomp.h"
#include "precomp.h"
#include <sys/stat.h>
/***************************
@ -265,6 +265,37 @@ DWORD request_fs_stat(Remote *remote, Packet *packet)
return ERROR_SUCCESS;
}
/*
* Removes the supplied file from disk
*
* TLVs:
*
* req: TLV_TYPE_FILE_PATH - The file that is to be removed.
*/
DWORD request_fs_delete_file(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCSTR path;
DWORD result = ERROR_SUCCESS;
path = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);
if (!path)
result = ERROR_INVALID_PARAMETER;
#ifdef __WIN32__
else if (!DeleteFile(path))
#else
else if (!unlink(path))
#endif
result = GetLastError();
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
}
/*
* Expands a file path and returns the expanded path to the requestor
*

View File

@ -11,6 +11,7 @@ DWORD request_fs_getwd(Remote *remote, Packet *packet);
DWORD request_fs_chdir(Remote *remote, Packet *packet);
DWORD request_fs_mkdir(Remote *remote, Packet *packet);
DWORD request_fs_delete_dir(Remote *remote, Packet *packet);
DWORD request_fs_delete_file(Remote *remote, Packet *packet);
DWORD request_fs_stat(Remote *remote, Packet *packet);
DWORD request_fs_file_expand_path(Remote *remote, Packet *packet);

View File

@ -4,18 +4,18 @@
#ifdef _WIN32
// sf: Compatability fix for a broken sdk? We get errors in Iphlpapi.h using the latest Windows SDK if we dont do this.
#define _WIN32_WINNT _WIN32_WINNT_WIN2K
#include <Tlhelp32.h>
#include "../stdapi.h"
#include <tlhelp32.h>
#include <iphlpapi.h>
#include "resource/resource.h"
#else
#include "../stdapi.h"
#include <sys/socket.h>
#include <sys/stat.h>
#include <netdb.h>
#endif
#include "../stdapi.h"
#include "fs/fs.h"
#include "sys/sys.h"
#include "net/net.h"

View File

@ -47,6 +47,10 @@ Command customCommands[] =
{ request_fs_delete_dir, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },
},
{ "stdapi_fs_delete_file",
{ request_fs_delete_file, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },
},
{ "stdapi_fs_stat",
{ request_fs_stat, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },

View File

@ -66,6 +66,26 @@ Separator = "\\"
return client.fs.filestat.new(name)
end
#
# Performs a delete on the specified file.
#
def File.rm(name)
request = Packet.create_request('stdapi_fs_delete_file')
request.add_tlv(TLV_TYPE_FILE_PATH,name)
response = client.send_request(request)
return response
end
#
# Performs a delete on the specified file.
#
def File.unlink(name)
return File.rm(name)
end
#
# Upload one or more files to the remote computer the remote
# directory supplied in destination.

View File

@ -45,7 +45,9 @@ class Console::CommandDispatcher::Stdapi::Fs
"upload" => "Upload a file or directory",
"lcd" => "Change local working directory",
"getlwd" => "Print local working directory",
"lpwd" => "Print local working directory"
"lpwd" => "Print local working directory",
"rm" => "Delete the specified file",
"del" => "Delete the specified file"
}
end
@ -104,6 +106,22 @@ class Console::CommandDispatcher::Stdapi::Fs
return true
end
#
# Delete the specified file.
#
def cmd_rm(*args)
if (args.length == 0)
print_line("Usage: rm file")
return true
end
client.fs.file.rm(args[0])
return true
end
alias :cmd_del :cmd_rm
#
# Downloads a file or directory from the remote machine to the local
# machine.