Skip to main content

Exploiting and Securing GitLab: Lessons from a TryHackMe Lab

Perimeter security isn’t enough—because sometimes the threat is already inside.

In this blog post, I’m sharing what I learned from a hands-on TryHackMe lab on GitLab security. It revealed how a simple internal misconfiguration—like open registration or overly permissive repo access—can lead to major data exposure inside an organization. I’ll walk you through the red team perspective on exploiting a misconfigured GitLab instance, and then flip the script to explain how you can secure your own internal build systems.

Scenario: Inside the Walls of a Large Organization

Think of a large organization—like a bank—with thousands of employees and multiple teams handling development, IT operations, and security. To keep intellectual property (IP) secure, these organizations often host self-managed GitLab instances on their internal network.

But here’s where things can go wrong:

  • GitLab is hosted internally
  • Allows anyone on the internal network to register
  • Has some projects set to public visibility

At first glance, this doesn’t sound too dangerous. But imagine:

  • 10,000 employees on the internal network
  • 2,000 developers needing GitLab access
  • If any one of those users is compromised, the attacker can register a GitLab account and view exposed projects

Suddenly, your attack surface grows exponentially—and your private codebase is at risk.

Exploiting a Vulnerable GitLab Instance

As a red teamer in this simulated environment, the first step was registering a GitLab account on the internal server (http://gitlab.tryhackme.loc/). Once logged in, I had visibility into all public repositories.

Instead of browsing them manually, I used a Python script that leverages the GitLab API to automatically enumerate and download every accessible repo.

Here’s the key part of the script:

  • Connects to the GitLab API using a personal access token
  • Lists all visible projects
  • Tries to download each project archive
  • Saves them locally with a unique ID

This script is not stealthy—it attempts to pull everything it can, making it obvious in logs. But in a red team or CTF context, it’s great for proof of concept.

GitLab API Token Setup

To use the script, I generated a GitLab Personal Access Token with read_repository scope:

  1. Go to your GitLab profile → Preferences
  2. Navigate to Access Tokens
  3. Set a name, expiry, and select scopes (e.g., read_repository)
  4. Generate and copy the token (it won’t be shown again)

Security Misconfigurations Exploited

  1. Open User Registration
    Anyone on the internal network could create a GitLab account. No restriction = expanded attack surface.
  2. Public Repositories Within the Internal Network
    Developers assumed “internal” meant “safe to share publicly.” Public visibility on GitLab meant any valid user could view the code.

Final Flag

How to Secure Your GitLab Environment

Group-Based Access Control

Organize projects into GitLab groups and set permissions at the group level. This simplifies permission management across multiple repositories and ensures consistent security policies.

Access Levels

GitLab roles include:

  • Guest – View limited info
  • Reporter – Read-only access to code and CI logs
  • Developer – Push code and trigger pipelines
  • Maintainer – Merge changes and manage pipelines
  • Owner – Full administrative access

Always follow the principle of least privilege.

Sensitive Information Protection

  • .gitignore: Prevent sensitive files like .env or config.yml from being tracked in version control.
  • Environment Variables: Store secrets like API keys securely during CI/CD runs without exposing them in source code.
  • Branch Protection: Lock down critical branches (like main) so that changes must pass code review and automated testing.

Additional Best Practices

  • Enable 2FA for all GitLab users.
  • Review access permissions regularly, especially when users change roles or leave.
  • Monitor audit logs to detect unauthorized access or suspicious activity.
  • Use secret scanning tools to detect accidental commits of credentials or API keys.

Comments

Popular posts from this blog

How to Pass CompTIA Security+ SY0-701 in 2 Months (839 Score Breakdown + Resources)

How I Scored 839/900 on CompTIA Security+ SY0-701 — 2-Month Prep Strategy That Actually Worked Score: 839/900  |  Exam: CompTIA Security+ SY0-701  |  Prep Time: 2 Months  |  Total Questions: 76 (including 3 PBQs) I'm not going to sugarcoat it — CompTIA Security+ is not easy, but it is very passable with the right strategy. I cleared it with an 839 out of 900, and in this post I'll share exactly how I did it, domain by domain, so you can replicate the approach without wasting time. My 2-Month Study Plan Month 1 — Domain-by-domain study: Read, take notes, and build comparison tables and mnemonics for tricky concepts. Month 2 — Heavy practice testing: Full focus on practice tests and PBQ simulations. Time management drills every session. The biggest mistake people make is spending 90% of their time reading and only 10% practicing. I flipped that in month 2 — and it made all the difference. Domain 1 — General Security Concepts What to focu...

ઓટીપી, ડેબિટ કાર્ડ, ક્રેડિટ કાર્ડ દ્વારા થતા બેન્ક ફ્રોડ પ્રત્યે જાગૃતિ અને અગત્ય સૂચના : સાવચેત રહો

Awareness is necessity જ્યારે પણ તમે ઇન્ટરનેટ પર વ્યક્તિગત વિગતો શેર કરતા હોય ત્યારે સાવચેત રહો. " "જ્યારે પણ તમે તમારા મોબાઇલમાં એપ્લિકશન ઇન્સ્ટોલેશન દરમિયાન 'allow' પરવાનગી આપો છો ત્યારે સાવચેત રહો." સાયબર સ્વયંસેવક તરીકે, મેં આ પ્રકારની છેતરપિંડીઓના કેટલાક કેસ નું અધ્યયન કર્યું છે. ચાલો હું તમારી સાથે એક કેસ સ્ટડી શેર કરું !! એક વ્યક્તિ OTP(વન ટાઇમ પાસવર્ડ) ને લઈને તેના મોબાઇલમાં સતત મેસેજીસ મેળવતો હતો. આ OTP તેના મોબાઇલ પર ઇન્સ્ટોલ કરેલા એક તૃતીય-પક્ષ એપ્લિકેશન દ્વારા આપમેળે કોઈ બીજા સાથે શેર થઈ રહ્યા હતા અને અચાનક, તેના ખાતામાંથી પૈસા ડેબિટ થયા, અને 7-8 ટ્રાન્ઝેક્શન સંદેશાઓ પછી, તેનું એકાઉન્ટ સ્ટેટમેન્ટ ખાલી હતું. પીડિત દ્વારા પ્રાપ્ત કેટલાક સંદેશાઓ અહીં છે. The secret OTP for online purchase is 222343 on card ending XXXX. Valid till HH:MM:SS. Do not share OTP for security reason. Rs. 9999 is Debited to A/c...XXXX on dd-mm-yy HH:MM:SS( Avlbl Bal Rs XXXXX) At POST TID-XXXXXXXXXX,ref-XXXXXXXXXXXX. TollFree XXXX...

Job Scams / Telegram Scams in India

Awareness is necessity Job scams and telegram scams have become a rampant issue in India, with many unsuspecting individuals falling victim to these fraudulent activities. These scams not only cause financial loss but also result in emotional distress and a loss of trust in online platforms. In this blog, we will discuss the ongoing job scam and telegram scam in India, and provide some tips on how to identify and avoid falling prey to these scams. The job scam in India has been on the rise, with scammers posing as recruiters or employers offering lucrative job opportunities. These scammers often target job seekers who are desperate for employment and are willing to take any opportunity that comes their way. They use fake job postings, promising high salaries and attractive benefits to lure in their victims. Once the victim is hooked, they are asked to pay a fee for processing their application or for other reasons. In reality, there is no job, and the victim en...

Bank fraud Awareness : Be careful about ATM card fraud , Debit card fraud , Credit card fraud

Awareness is necessity " Be careful whenever you are sharing personal details on the Internet." "Be careful whenever you are giving permission 'Allow' to applications during installation in your mobile." As a Cyber volunteer, I have analyzed some case studies of these kinds of frauds. Let me share one case study with you !! One person was getting messages continuously in his mobile regarding OTP ( One Time Password). These OTPs automatically shared with someone else by any third-party application installed on his mobile. That someone else can be considered as cybercriminal in this case. And suddenly, money gets debited from his account, and after 7-8 transaction messages, his account statement was empty. Here are some messages received by the victim. The secret OTP for online purchase is 222343 on card ending XXXX. Valid till HH:MM:SS. Do not share OTP for security reason. Rs. 9999 is Debited to A/c...XXXX on d...

How to Protect ourselves from Online Banking frauds: Tips & Ticks

Awareness is necessity Nowadays, Online banking frauds are increasing day by day, and awareness about Internet use, Internet Security and cyber crime can be helpful in mitigating cyber crime. So here I am sharing some security guidelines you should follow during bank transactions as given by Delhi Police. Safe Bank Transaction Tips: Always do banking transactions on self-computer and mobile devices, installed with original operating system. Use the latest Antivirus software in order to detect and stay protected from most of the threats and vulnerabilities in the applications installed on computers. Never disclose ATM PIN codes and OTP “One Time Password” sent by the bank through SMS or on Email with anyone, even if he is an employee at the bank, as bank never ask you about the codes of your account or any credit card details. Avoid using public computers for making banking transactions. Avoid electronic banking transactions if you are connected to the Internet via...