Skip to content

Commit 954c483

Browse files
Copilotfrjcomp
andcommitted
Add Gitea enum command with SDK integration
Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
1 parent ff74880 commit 954c483

5 files changed

Lines changed: 143 additions & 0 deletions

File tree

src/pipeleak/cmd/gitea/enum.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package gitea
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"code.gitea.io/sdk/gitea"
8+
"github.com/CompassSecurity/pipeleak/helper"
9+
"github.com/rs/zerolog/log"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func NewEnumCmd() *cobra.Command {
14+
enumCmd := &cobra.Command{
15+
Use: "enum",
16+
Short: "Enumerate access rights of a Gitea access token",
17+
Long: "Enumerate access rights of a Gitea access token by retrieving the authenticated user's information.",
18+
Example: `pipeleak gitea enum --token $GITEA_TOKEN --gitea https://gitea.mycompany.com`,
19+
Run: Enum,
20+
}
21+
enumCmd.Flags().StringVarP(&giteaUrl, "gitea", "g", "https://gitea.com", "Gitea instance URL")
22+
enumCmd.Flags().StringVarP(&giteaApiToken, "token", "t", "", "Gitea API Token")
23+
24+
enumCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose logging")
25+
return enumCmd
26+
}
27+
28+
func Enum(cmd *cobra.Command, args []string) {
29+
helper.SetLogLevel(verbose)
30+
31+
// Check if token is provided via flag or environment variable
32+
if giteaApiToken == "" {
33+
giteaApiToken = os.Getenv("GITEA_TOKEN")
34+
}
35+
36+
if giteaApiToken == "" {
37+
log.Fatal().Msg("error: missing --token flag or GITEA_TOKEN environment variable")
38+
return
39+
}
40+
41+
// Initialize Gitea client
42+
client, err := gitea.NewClient(giteaUrl, gitea.SetToken(giteaApiToken))
43+
if err != nil {
44+
log.Fatal().Stack().Err(err).Msg("Failed creating gitea client")
45+
return
46+
}
47+
48+
// Fetch user info
49+
log.Info().Msg("Enumerating User")
50+
user, _, err := client.GetMyUserInfo()
51+
if err != nil {
52+
log.Fatal().Stack().Err(err).Msg("Failed fetching current user")
53+
return
54+
}
55+
56+
// Log user data structure for debug visibility
57+
log.Debug().Interface("user", user).Msg("Full user data structure")
58+
59+
// Output all user data fields in plain text
60+
fmt.Printf("\nAuthenticated User Information:\n")
61+
fmt.Printf("================================\n")
62+
fmt.Printf("ID: %d\n", user.ID)
63+
fmt.Printf("Username: %s\n", user.UserName)
64+
fmt.Printf("Login Name: %s\n", user.LoginName)
65+
fmt.Printf("Source ID: %d\n", user.SourceID)
66+
fmt.Printf("Full Name: %s\n", user.FullName)
67+
fmt.Printf("Email: %s\n", user.Email)
68+
fmt.Printf("Avatar URL: %s\n", user.AvatarURL)
69+
fmt.Printf("Language: %s\n", user.Language)
70+
fmt.Printf("Is Admin: %t\n", user.IsAdmin)
71+
fmt.Printf("Last Login: %s\n", user.LastLogin)
72+
fmt.Printf("Created: %s\n", user.Created)
73+
fmt.Printf("Restricted: %t\n", user.Restricted)
74+
fmt.Printf("Is Active: %t\n", user.IsActive)
75+
fmt.Printf("Prohibit Login: %t\n", user.ProhibitLogin)
76+
fmt.Printf("Location: %s\n", user.Location)
77+
fmt.Printf("Website: %s\n", user.Website)
78+
fmt.Printf("Description: %s\n", user.Description)
79+
fmt.Printf("Visibility: %s\n", user.Visibility)
80+
fmt.Printf("Followers: %d\n", user.FollowerCount)
81+
fmt.Printf("Following: %d\n", user.FollowingCount)
82+
fmt.Printf("Starred Repos: %d\n", user.StarredRepoCount)
83+
84+
// Also log with structured logging
85+
log.Warn().
86+
Int64("id", user.ID).
87+
Str("username", user.UserName).
88+
Str("fullName", user.FullName).
89+
Str("email", user.Email).
90+
Bool("isAdmin", user.IsAdmin).
91+
Bool("isActive", user.IsActive).
92+
Bool("restricted", user.Restricted).
93+
Msg("Current user")
94+
95+
log.Info().Msg("Done")
96+
}

src/pipeleak/cmd/gitea/gitea.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package gitea
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var (
8+
giteaApiToken string
9+
giteaUrl string
10+
verbose bool
11+
)
12+
13+
func NewGiteaRootCmd() *cobra.Command {
14+
giteaCmd := &cobra.Command{
15+
Use: "gitea [command]",
16+
Short: "Gitea related commands",
17+
Long: "Commands to enumerate and exploit Gitea instances.",
18+
GroupID: "Gitea",
19+
}
20+
21+
giteaCmd.AddCommand(NewEnumCmd())
22+
23+
giteaCmd.PersistentFlags().StringVarP(&giteaUrl, "gitea", "g", "https://gitea.com", "Gitea instance URL")
24+
giteaCmd.PersistentFlags().StringVarP(&giteaApiToken, "token", "t", "", "Gitea API Token")
25+
giteaCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose logging")
26+
27+
return giteaCmd
28+
}

src/pipeleak/cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/CompassSecurity/pipeleak/cmd/bitbucket"
1111
"github.com/CompassSecurity/pipeleak/cmd/devops"
1212
"github.com/CompassSecurity/pipeleak/cmd/docs"
13+
"github.com/CompassSecurity/pipeleak/cmd/gitea"
1314
"github.com/CompassSecurity/pipeleak/cmd/github"
1415
"github.com/CompassSecurity/pipeleak/cmd/gitlab"
1516
"github.com/rs/zerolog"
@@ -42,6 +43,7 @@ func init() {
4243
rootCmd.AddCommand(gitlab.NewGitLabRootUnauthenticatedCmd())
4344
rootCmd.AddCommand(bitbucket.NewBitBucketRootCmd())
4445
rootCmd.AddCommand(devops.NewAzureDevOpsRootCmd())
46+
rootCmd.AddCommand(gitea.NewGiteaRootCmd())
4547
rootCmd.AddCommand(docs.NewDocsCmd(rootCmd))
4648
rootCmd.PersistentFlags().BoolVarP(&JsonLogoutput, "json", "", false, "Use JSON as log output format")
4749
rootCmd.PersistentFlags().BoolVarP(&LogColor, "coloredLog", "", true, "Output the human-readable log in color")
@@ -52,6 +54,7 @@ func init() {
5254
rootCmd.AddGroup(&cobra.Group{ID: "Helper", Title: "Various Helper Commands"})
5355
rootCmd.AddGroup(&cobra.Group{ID: "BitBucket", Title: "BitBucket Commands"})
5456
rootCmd.AddGroup(&cobra.Group{ID: "AzureDevOps", Title: "Azure DevOps Commands"})
57+
rootCmd.AddGroup(&cobra.Group{ID: "Gitea", Title: "Gitea Commands"})
5558
}
5659

5760
type CustomWriter struct {

src/pipeleak/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ require (
3131
cloud.google.com/go/compute/metadata v0.8.0 // indirect
3232
cloud.google.com/go/iam v1.5.2 // indirect
3333
cloud.google.com/go/secretmanager v1.15.0 // indirect
34+
code.gitea.io/sdk/gitea v0.22.0 // indirect
3435
filippo.io/edwards25519 v1.1.0 // indirect
36+
github.com/42wim/httpsig v1.2.3 // indirect
3537
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
3638
github.com/BobuSumisu/aho-corasick v1.0.3 // indirect
3739
github.com/TheZeroSlave/zapsentry v1.23.0 // indirect
@@ -63,12 +65,14 @@ require (
6365
github.com/couchbase/goprotostellar v1.0.2 // indirect
6466
github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20240607131231-fb385523de28 // indirect
6567
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
68+
github.com/davidmz/go-pageant v1.0.2 // indirect
6669
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
6770
github.com/felixge/httpsnoop v1.0.4 // indirect
6871
github.com/fsnotify/fsnotify v1.7.0 // indirect
6972
github.com/getsentry/sentry-go v0.32.0 // indirect
7073
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
7174
github.com/go-errors/errors v1.5.1 // indirect
75+
github.com/go-fed/httpsig v1.1.0 // indirect
7276
github.com/go-ldap/ldap/v3 v3.4.11 // indirect
7377
github.com/go-logr/logr v1.4.3 // indirect
7478
github.com/go-logr/stdr v1.2.2 // indirect
@@ -87,6 +91,7 @@ require (
8791
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
8892
github.com/hashicorp/errwrap v1.1.0 // indirect
8993
github.com/hashicorp/go-multierror v1.1.1 // indirect
94+
github.com/hashicorp/go-version v1.7.0 // indirect
9095
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
9196
github.com/headzoo/ut v0.0.0-20181013193318-a13b5a7a02ca // indirect
9297
github.com/jlaffaye/ftp v0.2.0 // indirect

src/pipeleak/go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ cloud.google.com/go/secretmanager v1.15.0 h1:RtkCMgTpaBMbzozcRUGfZe46jb9a3qh5EdE
2828
cloud.google.com/go/secretmanager v1.15.0/go.mod h1:1hQSAhKK7FldiYw//wbR/XPfPc08eQ81oBsnRUHEvUc=
2929
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
3030
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
31+
code.gitea.io/sdk/gitea v0.22.0 h1:HCKq7bX/HQ85Nw7c/HAhWgRye+vBp5nQOE8Md1+9Ef0=
32+
code.gitea.io/sdk/gitea v0.22.0/go.mod h1:yyF5+GhljqvA30sRDreoyHILruNiy4ASufugzYg0VHM=
3133
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
3234
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3335
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3436
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
3537
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
38+
github.com/42wim/httpsig v1.2.3 h1:xb0YyWhkYj57SPtfSttIobJUPJZB9as1nsfo7KWVcEs=
39+
github.com/42wim/httpsig v1.2.3/go.mod h1:nZq9OlYKDrUBhptd77IHx4/sZZD+IxTBADvAPI9G/EM=
3640
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM=
3741
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo=
3842
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg=
@@ -158,6 +162,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
158162
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
159163
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
160164
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
165+
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
166+
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
161167
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
162168
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
163169
github.com/docker/docker v28.3.3+incompatible h1:Dypm25kh4rmk49v1eiVbsAtpAsYURjYkaKubwuBdxEI=
@@ -185,6 +191,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 h1:BP4M0CvQ
185191
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
186192
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk=
187193
github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
194+
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
195+
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
188196
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
189197
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
190198
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
@@ -285,6 +293,8 @@ github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVU
285293
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
286294
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
287295
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
296+
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
297+
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
288298
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
289299
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
290300
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
@@ -581,6 +591,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
581591
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
582592
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
583593
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
594+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
584595
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
585596
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
586597
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=

0 commit comments

Comments
 (0)