Skip to content

Commit eae2808

Browse files
Integrate authorized WordPress requests with isolated PHP2Shell worker
1 parent 27a251d commit eae2808

31 files changed

Lines changed: 5224 additions & 0 deletions

‎.dockerignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*
2+
!wordpress_check.py
3+
!LICENSE
4+
!LICENSING.md
5+
!integrations/
6+
!integrations/__init__.py
7+
!integrations/worker/
8+
!integrations/worker/*.py
9+
!deployment/
10+
!deployment/Dockerfile

‎.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.md text eol=lf
44
*.yml text eol=lf
55
*.txt text eol=lf
6+
# Unified patch context includes a leading space before source indentation.
7+
deployment/*.patch -whitespace

‎.github/workflows/tests.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,40 @@ jobs:
3131
run: python -m unittest -v
3232
- name: Check CLI help
3333
run: python wordpress_check.py --help
34+
35+
wordpress:
36+
name: WordPress queue and authorization
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 10
39+
steps:
40+
- name: Check out repository
41+
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
42+
with:
43+
persist-credentials: false
44+
- name: Start isolated WordPress fixture
45+
run: docker compose -p php2shell-ci -f deployment/compose.test.yaml up -d --wait
46+
- name: Install disposable WordPress
47+
run: docker compose -p php2shell-ci -f deployment/compose.test.yaml exec -T wordpress php /work/deployment/test-bootstrap.php
48+
- name: Test queue, confirmation and receipts
49+
run: docker compose -p php2shell-ci -f deployment/compose.test.yaml exec -T wordpress php /work/integrations/wordpress/tests/integration.php
50+
- name: Test Python to WordPress over HTTP with synthetic scan responses
51+
run: |
52+
fixture=$(docker compose -p php2shell-ci -f deployment/compose.test.yaml exec -T wordpress php /work/deployment/test-http-fixture.php setup)
53+
token=$(printf '%s' "$fixture" | jq -r .token)
54+
docker run --rm --network php2shell-ci_fixture -v "$PWD:/app:ro" -w /app -e PYTHONDONTWRITEBYTECODE=1 -e PYTHONPATH=/app -e CT_FIXTURE_TOKEN="$token" python:3.12-slim-bookworm@sha256:6a0e06f5ba0b373d051aabd3fffb9b873f27f9a2a3a14bcbe37dee6f0e3bbc70 python deployment/test-http-worker.py
55+
docker compose -p php2shell-ci -f deployment/compose.test.yaml exec -T wordpress php /work/deployment/test-http-fixture.php cleanup
56+
- name: Test worker under Linux container privileges
57+
run: >-
58+
docker run --rm --network none --read-only --cap-drop ALL --cap-add SETUID --cap-add SETGID --cap-add KILL
59+
--security-opt no-new-privileges --pids-limit 32 --memory 384m
60+
--tmpfs /tmp:rw,noexec,nosuid,size=32m,mode=1777
61+
-v "$PWD:/app:ro" -w /app -e PYTHONDONTWRITEBYTECODE=1
62+
python:3.12-slim-bookworm@sha256:6a0e06f5ba0b373d051aabd3fffb9b873f27f9a2a3a14bcbe37dee6f0e3bbc70
63+
python -m unittest -v test_scan_worker
64+
- name: Build and check packaged isolation
65+
run: |
66+
docker build --build-arg CHECKER_REVISION="$GITHUB_SHA" -f deployment/Dockerfile -t ct-worker-fixture .
67+
docker run --rm --network none --read-only --cap-drop ALL --cap-add SETUID --cap-add SETGID --cap-add KILL --security-opt no-new-privileges --tmpfs /tmp:rw,noexec,nosuid,size=16m,mode=1777 -v "$PWD/deployment/test-runtime-image.py:/smoke.py:ro" -e PYTHONPATH=/app --entrypoint python ct-worker-fixture /smoke.py
68+
- name: Stop disposable fixture
69+
if: always()
70+
run: docker compose -p php2shell-ci -f deployment/compose.test.yaml down --volumes

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ results*.json
1212
websites.txt
1313
.DS_Store
1414
Thumbs.db
15+
.work/
16+
artifacts/
17+
deployment/private/

‎AGENTS.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Read [README.md](README.md) for setup and usage,
1414
- `skills/php2shell-check/SKILL.md`: reusable instructions for agents using the
1515
checker; `agents/openai.yaml` inside that skill provides discovery metadata.
1616
- `CLAUDE.md`: points Claude to these shared instructions; keep policy here.
17+
- `integrations/worker/`: restricted network adapter and authenticated queue
18+
controller; the public CLI remains independent of this integration.
19+
- `integrations/wordpress/`: WordPress MU plugin and database integration tests.
20+
- `deployment/`: isolated worker container, disposable WordPress fixture, and
21+
reviewed CompleteTech site patch. Read `docs/WORDPRESS.md` before deployment.
1722

1823
## Implementation constraints
1924

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ shared development instructions; [CLAUDE.md](CLAUDE.md) points Claude to them.
105105

106106
- [Full reference](docs/REFERENCE.md): every CLI option, output field, and request rule
107107
- [Assessment methodology](docs/PHP2SHELL.md): how each version is classified
108+
- [WordPress free-scan integration](docs/WORDPRESS.md): signed requests, confirmation,
109+
private job queue, restricted worker, deployment and recovery
108110
- [Contributing](CONTRIBUTING.md) · [Security policy](SECURITY.md)
109111

110112
```sh

‎deployment/Dockerfile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.12-slim-bookworm@sha256:6a0e06f5ba0b373d051aabd3fffb9b873f27f9a2a3a14bcbe37dee6f0e3bbc70
2+
WORKDIR /app
3+
COPY wordpress_check.py LICENSE LICENSING.md /app/
4+
COPY integrations/__init__.py /app/integrations/__init__.py
5+
COPY integrations/worker /app/integrations/worker
6+
ARG CHECKER_REVISION
7+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 CT_SCAN_REVISION=${CHECKER_REVISION}
8+
RUN test -n "$CHECKER_REVISION" && mkdir -p /var/lib/ct-scan /run/ct-scan && chmod 700 /var/lib/ct-scan /run/ct-scan
9+
# The controller reads the root-only API key; scanner children drop to 65534.
10+
USER 0:0
11+
ENTRYPOINT ["python", "-m", "integrations.worker.service"]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"theme/spintech-child/functions.php": {
3+
"before_normalized_sha256": "911f1612ff0292d4bfce13c52b8b7fe0c27e630498c13b32352f8010d91b629a",
4+
"after_sha256": "aaec0b66a94a89a3ed85475bab9a22325e52162213e58a2b2d3238f2e842f751"
5+
},
6+
"mu-plugins/ct-promo-terms.php": {
7+
"before_normalized_sha256": "9f5df66eb176e61263e76ea1a3d24ac191350885cc60b2ad7e17dd53530927c3",
8+
"after_sha256": "a1e2e25202a1857399b3d358382c7e31a4b209777dd0b25031001dc2674debfb"
9+
},
10+
"theme/spintech-child/templates/template-service-brief.php": {
11+
"before_normalized_sha256": "ad4eec2bd5e973b54f0f2a06155c96d0f4432d0c4dfd829a3145e3b8ca11073f",
12+
"after_sha256": "9ce71eadaed23d34e547539df3cb46d920e00caa0313e5a32ed1f58b0bf3f7ea"
13+
},
14+
"content/php2shell-scan-terms.html": {
15+
"before_normalized_sha256": "20ea5d6c61f65a79bba0bc18b248fc1ecef78a1c7572f4da3328e1a5083c3dce",
16+
"after_sha256": "4def089ebb32c318a3ccab18d8eb432f0cb8e28cd309554efee907f183653ee3"
17+
}
18+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
--- a/theme/spintech-child/functions.php
2+
+++ b/theme/spintech-child/functions.php
3+
@@ -509,6 +509,16 @@
4+
exit;
5+
}
6+
7+
+ // Canonical scope is signed and persisted before asynchronous work.
8+
+ if ( function_exists( 'ct_scan_normalize_target' ) ) {
9+
+ $target = ct_scan_normalize_target( wp_unslash( $_POST['ct_website'] ?? '' ) );
10+
+ if ( is_wp_error( $target ) ) {
11+
+ wp_safe_redirect( $fail );
12+
+ exit;
13+
+ }
14+
+ $website = $target;
15+
+ }
16+
+
17+
$body = "Promotion: {$promo['id']}\n"
18+
. "Referred by: {$referred_by}\n"
19+
. "Name: {$name}\n"
20+
@@ -528,6 +538,21 @@
21+
}
22+
update_post_meta( $request_id, '_ct_ref', $referred_by );
23+
24+
+ if ( function_exists( 'ct_scan_on_request_ready' ) ) {
25+
+ $fields = array( 'target' => $website, 'email' => $email, 'name' => $name, 'referrer' => $referred_by );
26+
+ $saved = true;
27+
+ foreach ( array( 'target', 'email', 'name' ) as $field ) {
28+
+ $key = '_ct_scan_' . $field;
29+
+ update_post_meta( $request_id, $key, wp_slash( $fields[ $field ] ) );
30+
+ $saved = $saved && get_post_meta( $request_id, $key, true ) === $fields[ $field ];
31+
+ }
32+
+ if ( $saved && get_post_meta( $request_id, '_ct_ref', true ) === $referred_by ) {
33+
+ do_action( 'ct_promo_request_ready', $request_id, $fields );
34+
+ } else {
35+
+ update_post_meta( $request_id, '_ct_scan_enqueue_error', 'request_metadata_not_saved' );
36+
+ }
37+
+ }
38+
+
39+
ct_promo_send_notification(
40+
$request_id,
41+
get_option( 'admin_email' ),
42+
--- a/mu-plugins/ct-promo-terms.php
43+
+++ b/mu-plugins/ct-promo-terms.php
44+
@@ -2,7 +2,7 @@
45+
/**
46+
* Plugin Name: CompleteTech Promo Terms
47+
* Description: Requires acceptance of the PHP2Shell scan terms on the promo form, records the acceptance, and attaches a filled-in copy of the terms to each request and its notification email.
48+
- * Version: 1.0.0
49+
+ * Version: 1.1.0
50+
*/
51+
52+
defined( 'ABSPATH' ) || exit;
53+
@@ -11,7 +11,7 @@
54+
function ct_promo_terms() {
55+
return array(
56+
'page_id' => 658,
57+
- 'version' => '2026-10-21',
58+
+ 'version' => '2026-10-21-r2',
59+
'title' => 'Free PHP2Shell Scan: Authorization and Promotion Terms',
60+
'path' => '/services/website-security/php2shell-scan-terms/',
61+
);
62+
@@ -119,11 +119,19 @@
63+
return;
64+
}
65+
foreach ( array( 'version', 'url', 'sha256', 'accepted_at', 'ip', 'remote_addr', 'user_agent' ) as $key ) {
66+
- update_post_meta( $post_id, '_ct_terms_' . $key, $acceptance[ $key ] );
67+
+ update_post_meta( $post_id, '_ct_terms_' . $key, wp_slash( $acceptance[ $key ] ) );
68+
}
69+
$contract = ct_promo_terms_contract( $post_id, $post->post_content, $acceptance );
70+
$GLOBALS['ct_promo_acceptance']['contract'] = $contract;
71+
update_post_meta( $post_id, '_ct_terms_contract', wp_slash( $contract ) );
72+
+ // Queue eligibility requires a complete, durably saved acceptance record.
73+
+ $terms_saved = get_post_meta( $post_id, '_ct_terms_contract', true ) === $contract;
74+
+ foreach ( array( 'version', 'url', 'sha256', 'accepted_at', 'ip', 'remote_addr', 'user_agent' ) as $key ) {
75+
+ $terms_saved = $terms_saved && get_post_meta( $post_id, '_ct_terms_' . $key, true ) === $acceptance[ $key ];
76+
+ }
77+
+ if ( $terms_saved ) {
78+
+ update_post_meta( $post_id, '_ct_terms_saved', '1' );
79+
+ }
80+
wp_update_post( wp_slash( array(
81+
'ID' => $post_id,
82+
'post_content' => $post->post_content . "\n\n" . $contract,
83+
--- a/theme/spintech-child/templates/template-service-brief.php
84+
+++ b/theme/spintech-child/templates/template-service-brief.php
85+
@@ -161,10 +161,10 @@
86+
<span class="eyebrow service-brief-offer-head">Limited offer &middot; through Nov 20, 2026</span>
87+
<h2>Request your free PHP2Shell scan</h2>
88+
<?php if ( 'sent' === $promo_state ) : ?>
89+
- <p class="service-brief-form-note" role="status">Thanks &mdash; your request is in. We&rsquo;ll be in touch within one business day.</p>
90+
+ <p class="service-brief-form-note" role="status">Thanks &mdash; your request is saved. Watch for a separate email to confirm authorization before scanning starts. We&rsquo;ll be in touch within one business day.</p>
91+
<?php else : ?>
92+
<?php if ( 'error' === $promo_state ) : ?>
93+
- <p class="service-brief-form-note is-error" role="alert">Please fill in your name, a valid email, and your website, then try again.</p>
94+
+ <p class="service-brief-form-note is-error" role="alert">Please enter your name, a valid email, and your website homepage (for example, https://example.com/), then try again.</p>
95+
<?php elseif ( 'terms' === $promo_state ) : ?>
96+
<p class="service-brief-form-note is-error" role="alert">Please read and agree to the scan terms, then try again.</p>
97+
<?php endif; ?>
98+
@@ -174,7 +174,7 @@
99+
<?php wp_nonce_field( 'ct_promo_request', 'ct_promo_nonce' ); ?>
100+
<label>Name <input type="text" name="ct_name" autocomplete="name" required></label>
101+
<label>Email <input type="email" name="ct_email" autocomplete="email" required></label>
102+
- <label>Website <input type="url" name="ct_website" placeholder="https://" autocomplete="url" required></label>
103+
+ <label>Website <input type="url" name="ct_website" placeholder="https://example.com/" autocomplete="url" required></label>
104+
<label>Phone (optional) <input type="tel" name="ct_phone" autocomplete="tel"></label>
105+
<label class="service-brief-form-hp" aria-hidden="true">Leave blank <input type="text" name="ct_hp" tabindex="-1" autocomplete="off"></label>
106+
<?php if ( function_exists( 'ct_promo_terms' ) ) : $ct_terms = ct_promo_terms(); ?>
107+
--- a/content/php2shell-scan-terms.html
108+
+++ b/content/php2shell-scan-terms.html
109+
@@ -1,5 +1,5 @@
110+
<!-- wp:paragraph -->
111+
-<p><strong>Version 2026-10-21</strong> &middot; Effective October 21, 2026 &middot; Offer ends November 20, 2026</p>
112+
+<p><strong>Version 2026-10-21-r2</strong> &middot; Effective October 21, 2026 &middot; Offer ends November 20, 2026</p>
113+
<!-- /wp:paragraph -->
114+
115+
<!-- wp:paragraph -->
116+
@@ -12,6 +12,10 @@
117+
118+
<!-- wp:paragraph -->
119+
<p>You confirm that you own the website you entered (the "Website") or are authorized by its owner to request security testing of it, and that you are at least 18 years old. Do not submit the form for a website you do not control, and do not let anyone else submit it for you. If your website is hosted by a third party, you are responsible for any notice or permission your hosting contract requires before external testing. If any of these confirmations is untrue, you agree to cover the reasonable costs and claims that result.</p>
120+
+<!-- /wp:paragraph -->
121+
+
122+
+<!-- wp:paragraph -->
123+
+<p>Before testing starts, we send a confirmation link to the email address you entered. Open the link and press the confirmation button to confirm your authority and the website scope. Merely opening the email or link does not start a scan. Callers may send you the request link, but must not sign or confirm on your behalf. Confirmation establishes control of the email address; it does not independently prove website ownership. The signed scope is the website hostname shown on the confirmation page. Other hostnames, including a www variant, require separate authorization.</p>
124+
<!-- /wp:paragraph -->
125+
126+
<!-- wp:heading {"level":3} -->
127+
@@ -38,6 +42,10 @@
128+
129+
<!-- wp:paragraph -->
130+
<p>Checks run at a low request rate from identified Complete Tech systems and are designed not to affect your site's availability.</p>
131+
+<!-- /wp:paragraph -->
132+
+
133+
+<!-- wp:paragraph -->
134+
+<p>After confirmation, the automated PHP2Shell portion checks the PHP version advertised in public response headers. A potentially affected version is not proof of exploitability, and an advertised fixed version is not proof that the website is safe. Hidden, conflicting or vendor-modified versions may be inconclusive. The other checks listed above remain part of our separate review before the full report is complete.</p>
135+
<!-- /wp:paragraph -->
136+
137+
<!-- wp:heading {"level":3} -->

‎deployment/compose.test.yaml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
services:
2+
db:
3+
image: mariadb:11.4
4+
environment:
5+
MARIADB_DATABASE: wordpress
6+
MARIADB_USER: wordpress
7+
MARIADB_PASSWORD: fixture-only
8+
MARIADB_ROOT_PASSWORD: fixture-root-only
9+
tmpfs:
10+
- /var/lib/mysql
11+
healthcheck:
12+
test: [CMD, healthcheck.sh, --connect, --innodb_initialized]
13+
interval: 2s
14+
timeout: 2s
15+
retries: 30
16+
networks: [fixture]
17+
wordpress:
18+
image: wordpress:php8.3-apache
19+
depends_on:
20+
db:
21+
condition: service_healthy
22+
environment:
23+
WORDPRESS_DB_HOST: db
24+
WORDPRESS_DB_USER: wordpress
25+
WORDPRESS_DB_PASSWORD: fixture-only
26+
WORDPRESS_DB_NAME: wordpress
27+
WORDPRESS_CONFIG_EXTRA: "define('DISABLE_WP_CRON', true);"
28+
healthcheck:
29+
test: [CMD, php, -r, "exit(@fsockopen('127.0.0.1', 80) ? 0 : 1);"]
30+
interval: 2s
31+
timeout: 2s
32+
retries: 30
33+
volumes:
34+
- wp:/var/www/html
35+
- ../integrations/wordpress:/var/www/html/wp-content/mu-plugins:ro
36+
- ..:/work:ro
37+
networks: [fixture]
38+
volumes:
39+
wp:
40+
networks:
41+
fixture:
42+
internal: true
43+
ipam:
44+
config:
45+
- subnet: ${CT_TEST_SUBNET:-10.254.96.0/28}

0 commit comments

Comments
 (0)