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

Every SOC Analyst Must Know These Windows Event IDs — Here's Why

Imagine you are the security guard of a massive office building. Every time someone enters, leaves, opens a cabinet, or tries to break in — it gets recorded in a logbook. Now imagine if that logbook could automatically tell you when something suspicious happened. That is exactly what Windows Event Logs are — the logbook of your Windows system, and for a SOC analyst, it is the single most important source of truth. In this blog, we will break down Windows Event Logs from scratch — what they are, how to read them, how to query them like a pro using PowerShell, and most importantly, which Event IDs you must memorize for your SOC analyst interview. Let's dive in. 1. What Are Windows Event Logs? Windows Event Logs are records that Windows automatically creates whenever something significant happens on the system — a user logs in, a service crashes, a file is accessed, an audit policy changes, a script runs. Think...

Splunk in Plain English — A Practical SOC Guide

Imagine you are a detective, and every device on your network — servers, laptops, firewalls, cloud systems — is leaving footprints everywhere. The problem is there are millions of footprints every single day, scattered across thousands of different files. Your job is to find the one set of footprints that does not belong. That is exactly the problem Splunk solves. It is the platform that collects every footprint from every device, puts them in one place, and gives you the tools to find the suspicious ones — fast. In this blog, I will take you through Splunk from absolute scratch — what it is, how it works under the hood, how to write SPL queries like a pro, how to build dashboards and alerts, how to set up a SOC lab, and most importantly, the interview questions you will definitely face if you are going for a SOC analyst role. I have completed the TryHackMe Advanced Splunk rooms including SPL exploration, SOC lab setup, dashboards and reports, data manipula...

પ્રાઇઝ સ્કેમ: જો તમારે ઇનામ મેળવવા માટે ચૂકવણી કરવી પડતી હોય તો તે ઇનામ નથી

Awareness is necessity શું તમને ક્યારેય કોઈ કોલ્સ આવ્યા છે કે જેમાં તમે કોઈ પણ ઓનલાઇન શોપિંગ વેબસાઇટમાંથી ઇનામ અથવા લોટરી જીતી લીધી હોય તેવું કહે છે? શક્યતા છે કે આ કોલ્સ ફ્રોડ છે. સાયબર સ્વયંસેવક તરીકે, મેં આ પ્રકારની છેતરપિંડીઓના કેટલાક કેસ નું અધ્યયન કર્યું છે. ચાલો સમજીએ કે આ પ્રકારની છેતરપિંડી કેવી રીતે થાય છે? !! છેતરપિંડી કરનાર તમને કોઈપણ વિશ્વસનીય ઓનલાઇન શોપિંગ સાઇટમાંથી કર્મચારી હોવાનુ કહે છે.તેઓ તમને સાઇટ પરથી તમારી છેલ્લી ખરીદી વિશેની વિગતો, ઉત્પાદન અને ઓર્ડર ની વિગતો સાથે તમને મનાવવાનો પ્રયાસ કરે છે. જ્યારે કોઈ વ્યક્તિ માને છે કે છેતરપિંડી કરનાર ઓનલાઇન સાઇટનો કર્મચારી છે, ત્યારે તેઓ તમને વિવિધ ઇનામો જેવા કે લેપટોપ, ટીવી, મોબાઇલ ફોન વિશે આકર્ષક યોજનાઓ આપે છે અને તમારી પાસેથી એક ઇનામ પસંદ કરવાનો વિકલ્પ આપે છે.જ્યારે તમે થોડી રુચિ બતાવો અને ઇનામ પસંદ કરો ત્યારે ઉલ્લેખિત ઇનામમાંથી, તેઓ તમને SMS તરીકે એક લિંક મોકલે છે.મોકલેલી લિંક એ છેતરપિંડીની લિંક છે જે તમારી વિગતો જેવી કે બેંક વિગતો તેમજ વ્યક્તિગત માહિતી માટે પૂછે છે.નોંધણી કરતી વખતે, તે તમને તમારા સ્થા...

Do you know, by blindly following trends and using hashtags you can be the victim of cyber crime? : #couplechallenge

Awareness is necessity "Nohashtag challenges" Nowadays, #couplechallenge, #smilechallenge, #chirichchallenge trending on social media platforms. But do you know the history of hashtags? Lets see, how hashtag was invented. Chris Messina a product designer who has been working in Silicon Valley created the idea of hashtag. He and his small group of colleagues were thinking that twitter needs some kind of frame work. He got the idea of hashtag from internet chat room that had pound symbol in front of them. His main idea to create hashtag was for the internet and wanted that anybody writing text on internet be able to participate in global conversation. In 2007, he asked one of his friends to use #sandiego for his tweets and this way the use of hashtag started. In 2009, Twitter added the option of hashtag to its search bar. And this way hashtag became a trend. This trend then being followed by other apps like tumbler, Facebook, instag...

Protecting Yourself from Vishing & Smishing frauds in India

Awareness is necessity Vishing & Smishing fraud is a type of scam that involves the use of text messages and Voice calls to trick individuals into revealing sensitive personal information such as bank account details, passwords, and credit card numbers. This type of fraud has become increasingly common in India, with many people falling victim to these scams every year. In this blog, we will discuss what Vishing & Smishing frauds are, how it works, and what steps you can take to prevent falling victim to these scams. What is Vishing & Smishing Fraud? Vishing & Smishing fraud is a type of social engineering scam that involves the use of text messages and Voice calls to trick individuals into revealing sensitive personal information. The term "vishing" is a combination of "voice" and "phishing," which refers to the use of voice calls to trick individuals into revealing personal information. In "Smishing" fraud, scammers use t...