Skip to content

Commit 9246f7a

Browse files
committed
Strip the NULL that PHP no longer strips
As of PHP 5.5.0, unpack("a", ...) no longer strips the NULL byte from the end of the string. A new format specifier, Z, was introduced to perform the old behavior, but we don't have a good way to test for its existence. Instead, just remove it with str_replace
1 parent 2efa3d6 commit 9246f7a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

data/meterpreter/meterpreter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ function tlv_unpack($raw_tlv) {
686686
my_print("len: {$tlv['len']}, type: {$tlv['type']}");
687687
if (($type & TLV_META_TYPE_STRING) == TLV_META_TYPE_STRING) {
688688
$tlv = unpack("Nlen/Ntype/a*value", substr($raw_tlv, 0, $tlv['len']));
689+
# PHP 5.5.0 modifed the 'a' unpack format to stop removing the trailing
690+
# NULL, so catch that here
691+
$tlv['value'] = str_replace("\0", "", $tlv['value']);
689692
}
690693
elseif (($type & TLV_META_TYPE_UINT) == TLV_META_TYPE_UINT) {
691694
$tlv = unpack("Nlen/Ntype/Nvalue", substr($raw_tlv, 0, $tlv['len']));
@@ -911,7 +914,8 @@ function read($resource, $len=null) {
911914
$r = Array($resource);
912915
my_print("Calling select to see if there's data on $resource");
913916
while (true) {
914-
$cnt = stream_select($r, $w=NULL, $e=NULL, 0);
917+
$w=NULL;$e=NULL;$t=0;
918+
$cnt = stream_select($r, $w, $e, $t);
915919

916920
# Stream is not ready to read, have to live with what we've gotten
917921
# so far
@@ -1147,7 +1151,8 @@ function remove_reader($resource) {
11471151
# Main dispatch loop
11481152
#
11491153
$r=$GLOBALS['readers'];
1150-
while (false !== ($cnt = select($r, $w=null, $e=null, 1))) {
1154+
$w=NULL;$e=NULL;$t=1;
1155+
while (false !== ($cnt = select($r, $w, $e, $t))) {
11511156
#my_print(sprintf("Returned from select with %s readers", count($r)));
11521157
$read_failed = false;
11531158
for ($i = 0; $i < $cnt; $i++) {

0 commit comments

Comments
 (0)