Skip to content

Commit e21f6f6

Browse files
frjcompfrjcomp
and
frjcomp
authored
Disable TLS checks and Bugfix Shodan (#25)
* article update * do not verify tls * bugfix shodan scanner --------- Co-authored-by: frjcomp <frj1@securelogon.ch>
1 parent 689d4dc commit e21f6f6

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

docs/article.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Sweet now you have access to the GitLab instance with an account.
1919
The first thing to look out for: What projects do I have access to? Is it more than unauthenticated?
2020
Some companies grant their developers `developer` access to each repository, this might become interesting.
2121

22+
The main question: Is the access concept based on the least privilege principle?
23+
2224
# Misconfigurations And Mishandling
2325

2426
## Secret Detection in Source Code

src/pipeleak/cmd/scan.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func NewScanCmd() *cobra.Command {
2828
log.Fatal().Stack().Err(err).Msg("Unable to require gitlab flag")
2929
}
3030

31-
//@todo test null vs empty string when no account
3231
scanCmd.Flags().StringVarP(&options.GitlabApiToken, "token", "t", "", "GitLab API Token")
3332
err = scanCmd.MarkFlagRequired("token")
3433
if err != nil {

src/pipeleak/cmd/shodan.go

+9-16
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ package cmd
33
import (
44
"bytes"
55
"context"
6-
"crypto/tls"
76
"encoding/json"
87
"io"
9-
"net/http"
108
"net/url"
119
"os"
1210
"path"
1311
"strconv"
1412
"strings"
15-
"time"
1613

14+
"github.com/CompassSecurity/pipeleak/helper"
1715
"github.com/perimeterx/marshmallow"
1816
"github.com/rs/zerolog/log"
1917
"github.com/spf13/cobra"
@@ -32,7 +30,7 @@ type result struct {
3230
Hostnames []string `json:"hostnames"`
3331
Port int `json:"port"`
3432
IPString string `json:"ip_str"`
35-
Shodan shodan `json:"shodan"`
33+
Shodan shodan `json:"_shodan"`
3634
}
3735

3836
func NewShodanCmd() *cobra.Command {
@@ -63,7 +61,7 @@ func Shodan(cmd *cobra.Command, args []string) {
6361

6462
data, _ := io.ReadAll(jsonFile)
6563
ctx := context.Background()
66-
group := parallel.Unlimited(ctx)
64+
group := parallel.Limited(ctx, 4)
6765
ctr := 0
6866

6967
for _, line := range bytes.Split(data, []byte{'\n'}) {
@@ -74,9 +72,9 @@ func Shodan(cmd *cobra.Command, args []string) {
7472
log.Error().Stack().Err(err).Msg("failed unmarshalling jsonl line")
7573
} else {
7674

77-
isHttps := true
78-
if strings.EqualFold("http", d.Shodan.Module) {
79-
isHttps = false
75+
isHttps := false
76+
if strings.EqualFold("https", d.Shodan.Module) {
77+
isHttps = true
8078
}
8179

8280
if len(d.Hostnames) == 0 {
@@ -126,10 +124,7 @@ func isRegistrationEnabled(base string) (bool, error) {
126124
u.Path = path.Join(u.Path, "/users/somenotexistigusr/exists")
127125
s := u.String()
128126

129-
tr := &http.Transport{
130-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
131-
}
132-
client := &http.Client{Transport: tr, Timeout: 15 * time.Second}
127+
client := helper.GetNonVerifyingHTTPClient()
133128
res, err := client.Get(s)
134129

135130
if err != nil {
@@ -160,10 +155,8 @@ func checkNrPublicRepos(base string) (int, error) {
160155
if err != nil {
161156
return 0, err
162157
}
163-
tr := &http.Transport{
164-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
165-
}
166-
client := &http.Client{Transport: tr, Timeout: 15 * time.Second}
158+
159+
client := helper.GetNonVerifyingHTTPClient()
167160
u.Path = "/api/v4/projects"
168161
s := u.String()
169162
res, err := client.Get(s + "?per_page=100")

src/pipeleak/gitlab/runner.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitlab
33
import (
44
"strings"
55

6+
"github.com/CompassSecurity/pipeleak/helper"
67
"github.com/rs/zerolog/log"
78
"github.com/xanzy/go-gitlab"
89
)
@@ -14,7 +15,7 @@ type runnerResult struct {
1415
}
1516

1617
func ListAllAvailableRunners(gitlabUrl string, apiToken string) {
17-
git, err := gitlab.NewClient(apiToken, gitlab.WithBaseURL(gitlabUrl))
18+
git, err := helper.GetGitlabClient(apiToken, gitlabUrl)
1819
if err != nil {
1920
log.Fatal().Stack().Err(err).Msg("failed creating gitlab client")
2021
}

src/pipeleak/helper/helper.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func CookieSessionValid(gitlabUrl string, cookieVal string) {
5353
return
5454
}
5555
req.AddCookie(&http.Cookie{Name: "_gitlab_session", Value: cookieVal})
56-
client := &http.Client{}
56+
client := GetNonVerifyingHTTPClient()
5757
resp, err := client.Do(req)
5858
if err != nil {
5959
log.Fatal().Stack().Err(err).Msg("Failed GitLab session test")
@@ -71,7 +71,7 @@ func CookieSessionValid(gitlabUrl string, cookieVal string) {
7171

7272
func DetermineVersion(gitlabUrl string, apiToken string) *gitlab.Version {
7373
if len(apiToken) > 0 {
74-
git, err := gitlab.NewClient(apiToken, gitlab.WithBaseURL(gitlabUrl))
74+
git, err := GetGitlabClient(apiToken, gitlabUrl)
7575
if err != nil {
7676
return &gitlab.Version{Version: "none", Revision: "none"}
7777
}
@@ -88,10 +88,7 @@ func DetermineVersion(gitlabUrl string, apiToken string) *gitlab.Version {
8888
}
8989
u.Path = path.Join(u.Path, "/help")
9090

91-
tr := &http.Transport{
92-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
93-
}
94-
client := &http.Client{Transport: tr, Timeout: 15 * time.Second}
91+
client := GetNonVerifyingHTTPClient()
9592
response, err := client.Get(u.String())
9693

9794
if err != nil {
@@ -190,3 +187,15 @@ func RegisterGracefulShutdownHandler(handler ShutdownHandler) {
190187
}()
191188

192189
}
190+
191+
func GetNonVerifyingHTTPClient() *http.Client {
192+
tr := &http.Transport{
193+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
194+
}
195+
return &http.Client{Transport: tr, Timeout: 15 * time.Second}
196+
}
197+
198+
func GetGitlabClient(token string, url string) (*gitlab.Client, error) {
199+
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(url), gitlab.WithHTTPClient(GetNonVerifyingHTTPClient()))
200+
return client, err
201+
}

src/pipeleak/scanner/pipeline.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func cleanUp() {
131131
func fetchProjects(options *ScanOptions) {
132132
log.Info().Msg("Fetching projects")
133133

134-
git, err := gitlab.NewClient(options.GitlabApiToken, gitlab.WithBaseURL(options.GitlabUrl))
134+
git, err := helper.GetGitlabClient(options.GitlabApiToken, options.GitlabUrl)
135135
if err != nil {
136136
log.Fatal().Stack().Err(err).Msg("failed creating gitlab client")
137137
}
@@ -294,7 +294,7 @@ func DownloadEnvArtifact(cookieVal string, gitlabUrl string, prjectPath string,
294294

295295
req.AddCookie(&http.Cookie{Name: "_gitlab_session", Value: cookieVal})
296296

297-
client := &http.Client{}
297+
client := helper.GetNonVerifyingHTTPClient()
298298
resp, err := client.Do(req)
299299
if err != nil {
300300
log.Debug().Stack().Err(err).Msg("Failed requesting dotenv artifact")

0 commit comments

Comments
 (0)