Skip to content

Commit 300f5e5

Browse files
committed
ci: patch meterpreter.php in installed gem using patch file
Apply php-meterpreter-tcp-eof.patch to the installed metasploit-payloads gem's meterpreter.php to test the TCP EOF fix without publishing a new gem.
1 parent a63e3e4 commit 300f5e5

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/php/meterpreter/meterpreter.php b/php/meterpreter/meterpreter.php
2+
--- a/php/meterpreter/meterpreter.php
3+
+++ b/php/meterpreter/meterpreter.php
4+
@@ -1972,6 +1972,17 @@ function read($resource, $len=null) {
5+
} else {
6+
$tmp = fread($resource, $len);
7+
$last_requested_len = $len;
8+
+ # An empty fread on a stream that stream_select reported as readable
9+
+ # means the peer has closed the connection (EOF). feof() may not return
10+
+ # true immediately on all stream types (e.g. SSL), so treat "" as EOF
11+
+ # for non-C2 channel sockets.
12+
+ if ($tmp === false || ($tmp === '' && $resource !== $msgsock)) {
13+
+ if (empty($buff)) {
14+
+ my_print("---- EOF ON " . get_resource_map_id($resource) . " ----");
15+
+ $buff = false;
16+
+ }
17+
+ break;
18+
+ }
19+
$buff .= $tmp;
20+
if (strlen($tmp) < $len) {
21+
break;

.github/workflows/shared_meterpreter_acceptance.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,15 @@ jobs:
348348
shell: bash
349349
run: |
350350
GEM_PATH=$(bundle show metasploit-payloads)
351-
curl -fsSL "https://raw.githubusercontent.com/rapid7/metasploit-payloads/6.5.0-prerelease-build/php/meterpreter/meterpreter.php" \
352-
-o "${GEM_PATH}/data/meterpreter/meterpreter.php"
351+
patch "${GEM_PATH}/data/meterpreter/meterpreter.php" .github/patches/php-meterpreter-tcp-eof.patch
353352
working-directory: metasploit-framework
354353

355354
- name: Patch meterpreter.php in installed gem (Windows)
356355
if: ${{ matrix.meterpreter.name == 'php' && runner.os == 'Windows' }}
357356
shell: pwsh
358357
run: |
359358
$gemPath = bundle show metasploit-payloads
360-
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/rapid7/metasploit-payloads/6.5.0-prerelease-build/php/meterpreter/meterpreter.php" `
361-
-OutFile "$gemPath\data\meterpreter\meterpreter.php"
359+
patch "$gemPath\data\meterpreter\meterpreter.php" .github\patches\php-meterpreter-tcp-eof.patch
362360
working-directory: metasploit-framework
363361

364362
- name: Acceptance

0 commit comments

Comments
 (0)