Skip to content

Commit 20cf25d

Browse files
committed
Land rapid7#3491, @jlee-r7's fix for php meterpreter on php 5.5.0
2 parents 2efa3d6 + 9246f7a commit 20cf25d

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)