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

e-SIM fraud : All you need to know about e-SIM and SIM swapping fraud

Awareness is necessity Ever heard about the place, Jamtara? Many of you must have seen the famous series "Jamtara: Sab ka number ayega" on Netflix. It is located near Jharkhand's capital Ranchi. This place has become a hub for phishing and bank fraud. Recently, Jamtara has come in the limelight because this place's fraudsters have started a new type of crime/ fraud, i.e. e-SIM fraud. Do you know what eSIM is? e-SIM stands for the "Embedded Subscriber Identity Module." You don't need to buy a telecom operator's SIM card separately and insert it into your mobile. e-SIM is a part of your smartphone's hardware. This e-SIM chip comes pre-installed on your smartphone. Its working is the same as our standard SIM, which saves information like IMSI number, some contact details etc. e-SIM is re-writable means previous telecom operator related details can be erased and new information can be written again by a new telecom operator. This type o...

OLX fraud : Beware of this new fraud/scam of 'Army men'

Awareness is necessity Nowadays, OLX related frauds are increasing, such as share OLX password/OTP, QR code scams, Paytm link scam etc. The most occurring cases are related to Army personnel. Instead of writing all the things, it will be better to watch the video by a YouTuber, Mr. Rohit R Gaba and lets see How fraudster makes fools to people as Army personnel. Here, in the video, the fraudster talked about QR code. Let's understand what a QR code is and how fraud can be occurred by QR code. QR code ( Quick Response code ), We can store so much information within it in text form. I made one QR code that stores information such as a person's name, aadhar card number, etc. We can store any data with the QR code. Same fraudster store bank details and malicious code so that when you scan that QR code, the money will be debit from the account directly. How to protect ourselves from online OLX frauds? Always prefer face to face meetings with buyers or sellers and ...

શું તમે જાણો છો કે હેશટેગ્સ #couplechallenge નો ઉપયોગ કરીને, તમે સાયબર ક્રાઇમનો ભોગ બની શકો છો?

Awareness is necessity "Nohashtag challenges" આજકાલ, સોશિયલ મીડિયા પ્લેટફોર્મ પર #couplechallenge, #smilechalenlenge, #chirichchallenge ટ્રેંડિંગ છે. પરંતુ શું તમે હેશટેગ્સનો ઇતિહાસ જાણો છો? ચાલો પહેલા જોઈએ કે #hashtag ની શોધ કેવી રીતે થઈ. સિલિકોન વેલીમાં કામ કરતા પ્રોડકટ ડિઝાઇનર ક્રિસ મેસિના એ હેશટેગનો આઈડિયા બનાવ્યો હતો.તે અને તેના કર્મચારીઓ મિત્રો વિચારી રહ્યા હતા કે ટ્વિટરને કેટલાક માળખાની જરૂર છે.તેને સામે પાઉન્ડ સિમ્બોલ હતું તેમાંથી હેશટેગ કન્સેપ્ટ મળ્યો.હેશટેગ બનાવવાનો તેમનો મુખ્ય વિચાર ઇન્ટરનેટનો હતો, અને ઈચ્છતા હતા કે વૈશ્વિક વાર્તાલાપમાં ભાગ લેવા ઇન્ટરનેટ પર કોઈપણ લખાણ લખે. 2007 માં, તેણે તેના એક મિત્રને તેના tweet માટે #sandiego નો ઉપયોગ કરવા કહ્યું અને આ રીતે, હેશટેગનો ઉપયોગ શરૂ થયો. 2009 માં, ટ્વિટરે તેના સર્ચ બારમાં હેશટેગનો વિકલ્પ ઉમેર્યો. અને આ રીતે, હેશટેગ એક વલણ બની હતી. આ વલણ પછી અન્ય એપ્લિકેશન્સ જેવી કે ટમ્બલર, ફેસબુક, ઇન્સ્ટાગ્રામ અને અન્ય social media પ્લેટફોર્મ સુધી વિસ્તરિત થયો હતો. શરૂઆતમાં, હેશટેગ...

OLX ફ્રોડ : આર્મી ના માણસો ના નામે થતા આ નવા કોભાંડ થી સાવચેત રહો.

Awareness is necessity આજ કાલ OLX સંબંધીત ફ્રોડો વધી રહ્યા છે જેમ કે OLX password કે OTP શેર કરવો, QR Code Scan ,Paytm લિંક ને સબંધીત કોભાંડ અને સૈાથી વધુ બનતા કિસ્સાઓ આર્મી ના જવાનો ના નામ સાથે સંબંધીત છે બધી બાબતો લખવાને બદલે YouTuber , Mr. Rohit R Gaba દ્વારા શેર થયેલો વિડિયો જોવો વધુ સારો રહેશે અને ચાલો જોઈ એ કે કેવી રીતે આ ફ્રોડ કરનાર લોકો ને આર્મી ના કર્મચારી તરીકે મૂર્ખ બનાવે છે. અહીં, વિડિઓમાં ક્રિમીનલ એ QR code વિશે વાત કરી.ચાલો સમજીએ કે QR code શું છે અને QR code દ્વારા કેવી રીતે fraud થઈ શકે છે. QR code ( Quick Response code ), તેની અંદર આપણે ઘણી માહિતી લખાણ સ્ટોર કરી શકીએ છીએ. મેં એક QR code બનાવ્યો છે જે માહિતી સંગ્રહિત કરે છે જેમ કે વ્યક્તિનું નામ, આધાર કાર્ડ નંબર, વગેરે. આપણે કોઈપણ ડેટાને QR code સાથે સ્ટોર કરી શકીએ છીએ.એ જ રીતે ક્રિમીનલ બેંકની વિગતો અને malicious code સ્ટોર કરે છે જેથી જ્યારે તમે તે QR code સ્કેન કરો છો, ત્યારે પૈસા સીધા એકાઉન્ટમાંથી ડેબિટ થઈ જાય છે. OLX થી થતા ફ્રોડ થી પોતાને કેવી રીતે બચાવવા? ખરીદદાર અથવા વેચાણકર્તા ઓ સાથે ...

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...