mirror of
https://github.com/rapid7/metasploit-payloads
synced 2024-12-27 08:33:43 +01:00
Land #32, switch FILE_HASH to use RAW, strings to use UTF-8
This commit is contained in:
commit
3ba13e719a
@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A packet consisting of multiple TLV values. Having the same type more than once is an error.
|
* A packet consisting of multiple TLV values. Having the same type more than once is an error.
|
||||||
*
|
*
|
||||||
* @author mihi
|
* @author mihi
|
||||||
*/
|
*/
|
||||||
public class TLVPacket {
|
public class TLVPacket {
|
||||||
@ -62,7 +62,7 @@ public class TLVPacket {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a TLV packet from an input stream.
|
* Read a TLV packet from an input stream.
|
||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* Input stream to read from
|
* Input stream to read from
|
||||||
* @param remaining
|
* @param remaining
|
||||||
@ -84,7 +84,7 @@ public class TLVPacket {
|
|||||||
value = data;
|
value = data;
|
||||||
} else if ((type & TLV_META_TYPE_STRING) != 0) {
|
} else if ((type & TLV_META_TYPE_STRING) != 0) {
|
||||||
in.readFully(data);
|
in.readFully(data);
|
||||||
String string = new String(data, "ISO-8859-1"); // better safe than sorry
|
String string = new String(data, "UTF-8");
|
||||||
if (!string.endsWith("\0"))
|
if (!string.endsWith("\0"))
|
||||||
throw new IOException("C string is not 0 terminated: " + string);
|
throw new IOException("C string is not 0 terminated: " + string);
|
||||||
string = string.substring(0, string.length() - 1);
|
string = string.substring(0, string.length() - 1);
|
||||||
@ -281,7 +281,7 @@ public class TLVPacket {
|
|||||||
private static void write(DataOutputStream out, int type, Object value) throws IOException {
|
private static void write(DataOutputStream out, int type, Object value) throws IOException {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
if ((type & TLV_META_TYPE_STRING) != 0) {
|
if ((type & TLV_META_TYPE_STRING) != 0) {
|
||||||
data = ((String) value + "\0").getBytes("ISO-8859-1");
|
data = ((String) value + "\0").getBytes("UTF-8");
|
||||||
} else if ((type & TLV_META_TYPE_QWORD) != 0) {
|
} else if ((type & TLV_META_TYPE_QWORD) != 0) {
|
||||||
out.writeInt(16);
|
out.writeInt(16);
|
||||||
out.writeInt(type);
|
out.writeInt(type);
|
||||||
|
@ -57,6 +57,7 @@ public interface TLVType {
|
|||||||
public static final int TLV_TYPE_FILE_NAME = TLVPacket.TLV_META_TYPE_STRING | 1201;
|
public static final int TLV_TYPE_FILE_NAME = TLVPacket.TLV_META_TYPE_STRING | 1201;
|
||||||
public static final int TLV_TYPE_FILE_PATH = TLVPacket.TLV_META_TYPE_STRING | 1202;
|
public static final int TLV_TYPE_FILE_PATH = TLVPacket.TLV_META_TYPE_STRING | 1202;
|
||||||
public static final int TLV_TYPE_FILE_MODE = TLVPacket.TLV_META_TYPE_STRING | 1203;
|
public static final int TLV_TYPE_FILE_MODE = TLVPacket.TLV_META_TYPE_STRING | 1203;
|
||||||
|
public static final int TLV_TYPE_FILE_HASH = TLVPacket.TLV_META_TYPE_RAW | 1206;
|
||||||
public static final int TLV_TYPE_STAT_BUF = TLVPacket.TLV_META_TYPE_COMPLEX | 1220;
|
public static final int TLV_TYPE_STAT_BUF = TLVPacket.TLV_META_TYPE_COMPLEX | 1220;
|
||||||
|
|
||||||
// Net
|
// Net
|
||||||
|
@ -20,7 +20,7 @@ public abstract class HashCommand implements Command {
|
|||||||
while ((len = in.read(buf)) != -1) {
|
while ((len = in.read(buf)) != -1) {
|
||||||
md.update(buf, 0, len);
|
md.update(buf, 0, len);
|
||||||
}
|
}
|
||||||
response.add(TLVType.TLV_TYPE_FILE_NAME, new String(md.digest(), "ISO-8859-1"));
|
response.add(TLVType.TLV_TYPE_FILE_HASH, md.digest());
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user