Jenkins Arbitrary File Read to RCE via "Remember Me"
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
In this blog post is possible to find a great way to transform a Local File Inclusion vulnerability in Jenkins into RCE: https://blog.securelayer7.net/spring-cloud-skipper-vulnerability/
This is an AI created summary of the part of the post were the creaft of an arbitrary cookie is abused to get RCE abusing a local file read until I have time to create a summary on my own:
Attack Prerequisites
Feature Requirement: "Remember me" must be enabled (default setting).
Access Levels: Attacker needs Overall/Read permissions.
Secret Access: Ability to read both binary and textual content from key files.
Detailed Exploitation Process
Step 1: Data Collection
User Information Retrieval
Access user configuration and secrets from
$JENKINS_HOME/users/*.xml
for each user to gather:Username
User seed
Timestamp
Password hash
Secret Key Extraction
Extract cryptographic keys used for signing the cookie:
Secret Key:
$JENKINS_HOME/secret.key
Master Key:
$JENKINS_HOME/secrets/master.key
MAC Key File:
$JENKINS_HOME/secrets/org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices.mac
Step 2: Cookie Forging
Token Preparation
Calculate Token Expiry Time:
Concatenate Data for Token:
MAC Key Decryption
Decrypt MAC Key File:
Signature Computation
Compute HMAC SHA256:
Cookie Encoding
Generate Final Cookie:
Step 3: Code Execution
Session Authentication
Fetch CSRF and Session Tokens:
Make a request to
/crumbIssuer/api/json
to obtainJenkins-Crumb
.Capture
JSESSIONID
from the response, which will be used in conjunction with the remember-me cookie.
Command Execution Request
Send a POST Request with Groovy Script:
Groovy script can be used to execute system-level commands or other operations within the Jenkins environment.
The example curl command provided demonstrates how to make a request to Jenkins with the necessary headers and cookies to execute arbitrary code securely.
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Last updated