Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filesystem support for exclude and include filters #881

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
b8be0a6
Use pointer to type. (#926)
ahrav Nov 16, 2022
eb4ff43
Use pointer to type. (#926)
ahrav Nov 16, 2022
b3d3f53
Return an error from ReadToMax when it panics (#925)
mcastorina Nov 16, 2022
87e7aa3
Add warning about using trufflehog as a library (#928)
mcastorina Nov 18, 2022
b18edef
Enable skipping of particular key IDs (#930)
dustin-decker Nov 18, 2022
ae4b387
add LDAP detector (#896)
dustin-decker Nov 19, 2022
9757c33
Fix error message (#933)
thiagola92 Nov 20, 2022
b45369c
Skip some FTP FPs (#929)
dustin-decker Nov 21, 2022
6e25664
add rambbitmq detector (#936)
jesslam948 Nov 21, 2022
054e98d
Update slack webhook detector string check (#932)
ahrav Nov 21, 2022
4409210
Add custom detectors configuration parsing (#927)
mcastorina Nov 21, 2022
28dd25b
S3 scanner improvements (#938)
dustin-decker Nov 22, 2022
79cae3b
Add newlines when file is split (#937)
bill-rich Nov 22, 2022
45ebaff
fix: small errors (#917)
0xflotus Nov 22, 2022
f1ec9e7
Close files to clean up tmp files (#940)
bill-rich Nov 22, 2022
c26142d
Use new diskbufferreader version (#941)
bill-rich Nov 28, 2022
3b055ce
Add logger to context (#947)
bill-rich Nov 30, 2022
5a339b0
Add test for configuring custom regex with webhook verification (#946)
mcastorina Dec 2, 2022
2a2bcd9
Add CustomRegex validation (#939)
mcastorina Dec 2, 2022
c3e596e
Update README.md (#952)
dxa4481 Dec 2, 2022
9f99ee4
Integration test fixes (#956)
bill-rich Dec 6, 2022
1a1c2e2
Change chunker test source (#959)
bill-rich Dec 6, 2022
33d32d2
Don't scan the --since-commit target (#960)
bill-rich Dec 6, 2022
4e2ce4f
Pre-commit not GH action PR (#961)
bill-rich Dec 6, 2022
335ce85
Export line number code (#962)
bill-rich Dec 6, 2022
d96b7f8
Update Adding_Detectors_external.md (#957)
pulkitanz Dec 6, 2022
6ee3000
Bump github.com/go-sql-driver/mysql from 1.6.0 to 1.7.0 (#954)
dependabot[bot] Dec 6, 2022
f008d4b
Bump go.uber.org/zap from 1.23.0 to 1.24.0 (#955)
dependabot[bot] Dec 6, 2022
a72b9fe
Only scan org with --org flag. (#931)
ahrav Dec 7, 2022
7de9bdd
Support globbing with ignore repos (#967)
dustin-decker Dec 9, 2022
544359e
Bump github.com/xanzy/go-gitlab from 0.74.0 to 0.76.0 (#934)
dependabot[bot] Dec 9, 2022
f324900
Bump github.com/bill-rich/disk-buffer-reader from v0.1.6 to v0.1.7 (#…
bill-rich Dec 9, 2022
aada296
Bump go.mongodb.org/mongo-driver from 1.11.0 to 1.11.1 (#971)
dependabot[bot] Dec 12, 2022
4020c40
Bump github.com/getsentry/sentry-go from 0.15.0 to 0.16.0 (#973)
dependabot[bot] Dec 12, 2022
26befdd
[bug] - Handle error when scanning s3 bucket. (#969)
ahrav Dec 12, 2022
a0b8edd
Bump github.com/go-git/go-git/v5 from 5.4.2 to 5.5.1 (#972)
dependabot[bot] Dec 12, 2022
6dd0441
Bump github.com/envoyproxy/protoc-gen-validate from 0.6.13 to 0.9.1 (…
dependabot[bot] Dec 13, 2022
7ac7fda
Add more logging for git sources (#974)
mcastorina Dec 13, 2022
36ca260
Add s3 object count to trace logs (#975)
bill-rich Dec 14, 2022
861ad05
Implement CustomRegex detector (#950)
mcastorina Dec 14, 2022
e091fab
Use Todoist's REST API v2 (#978)
goncalossilva Dec 15, 2022
936a139
Allow using a glob for include list. (#977)
ahrav Dec 16, 2022
e3b6de0
Bump github.com/xanzy/go-gitlab from 0.76.0 to 0.77.0 (#981)
dependabot[bot] Dec 19, 2022
cc6bd31
Bump golang.org/x/crypto from 0.3.0 to 0.4.0 (#982)
dependabot[bot] Dec 19, 2022
f5b83ee
Add configuration parsing and custom detectors to engine (#968)
mcastorina Dec 20, 2022
130d5ae
Add custom regex detector docs (#983)
mcastorina Dec 21, 2022
8859771
Remove custom log leveler (#985)
mcastorina Dec 21, 2022
009756d
add proto that was missing. (#986)
ahrav Dec 23, 2022
330a6f7
Removing Debug version Println to logrus debug (#993)
yilmi Jan 3, 2023
3fadec9
Make GA action default base an empty string. (#996)
ahrav Jan 6, 2023
5f6143f
Add Circle CI source (#997)
dustin-decker Jan 6, 2023
ee6817a
Allow for default value to be used. (#999)
ahrav Jan 7, 2023
fc6fd29
Fix GitUrl Return (#987)
pulkitanz Jan 9, 2023
705c01e
Bump goreleaser/goreleaser-action from 3 to 4 (#980)
dependabot[bot] Jan 9, 2023
d720c0c
Switch to retryableHttpClient for GitHub AuthN API Client + More Logs…
yilmi Jan 9, 2023
d72c31b
Bump cloud.google.com/go/secretmanager from 1.9.0 to 1.10.0 (#1006)
dependabot[bot] Jan 9, 2023
0e24d40
Bump github.com/go-git/go-git/v5 from 5.5.1 to 5.5.2 (#1007)
dependabot[bot] Jan 9, 2023
6d384ce
Bump github.com/hashicorp/go-retryablehttp from 0.7.1 to 0.7.2 (#1008)
dependabot[bot] Jan 9, 2023
7de0178
Bump golang.org/x/crypto from 0.4.0 to 0.5.0 (#1009)
dependabot[bot] Jan 9, 2023
09d4422
Handle invalid regex for custom detector. (#1005)
ahrav Jan 9, 2023
74831f6
Capture callstack of canceled contexts (#979)
mcastorina Jan 9, 2023
e5ede17
Validate custom regular expressions on detector initialization (#1010)
mcastorina Jan 9, 2023
864cf00
Revert "Allow for default value to be used. (#999)" (#1004)
clarkedb Jan 10, 2023
8b2e1d3
Copy metadata for line number aware sources (#1011)
bill-rich Jan 10, 2023
430d5c7
Rename and export isGitSource (#1016)
bill-rich Jan 10, 2023
477e2a1
Update entrypoint (#1013)
ahrav Jan 12, 2023
0aa8e1c
Use access-token endpoint for validity check (#991)
clonsdale-canva Jan 12, 2023
45b02f4
Record timestamp when a context was cancelled (#1018)
mcastorina Jan 13, 2023
bc27fef
remove logger from retryable client, it is not respecting loglevels (…
dustin-decker Jan 13, 2023
319ae64
[chore] - Small cleanup of CircleCi source (#1028)
ahrav Jan 17, 2023
1621403
Add concurrency to CircleCi source (#1029)
ahrav Jan 17, 2023
8acd9fd
Bump github.com/getsentry/sentry-go from 0.16.0 to 0.17.0 (#1022)
dependabot[bot] Jan 17, 2023
c62eb18
Bump github.com/xanzy/go-gitlab from 0.77.0 to 0.78.0 (#1024)
dependabot[bot] Jan 17, 2023
86f80fc
Bump github.com/sergi/go-diff from 1.2.0 to 1.3.1 (#1023)
dependabot[bot] Jan 17, 2023
2060ae1
Updated stdout to print results in alphabetical order for consistent …
0x1 Jan 19, 2023
06dc01e
fix filter issue - empty lines should be ignored
mac2000 Oct 30, 2022
bbdd44c
filesystem support for filter exclude
mac2000 Oct 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
go-version: '1.18'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o trufflehog .

FROM alpine:3.15
RUN apk add --no-cache git ca-certificates \
RUN apk add --no-cache bash git ca-certificates \
&& rm -rf /var/cache/apk/* && \
update-ca-certificates
COPY --from=builder /build/trufflehog /usr/bin/trufflehog
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.15

RUN apk add --no-cache git ca-certificates \
RUN apk add --no-cache bash git ca-certificates \
&& rm -rf /var/cache/apk/* && \
update-ca-certificates
WORKDIR /usr/bin/
Expand Down
136 changes: 117 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ trufflehog s3 --bucket=<bucket name> --only-verified
+ All I see is `🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷` and the program exits, what gives?
+ That means no secrets were detected
+ Why is the scan is taking a long time when I scan a GitHub org
+ Unathenticated GitHub scans have rate limits. To improve your rate limits, include the `--token` flag with a personal access token
+ Unauthenticated GitHub scans have rate limits. To improve your rate limits, include the `--token` flag with a personal access token
+ It says a private key was verified, what does that mean?
+ Check out our Driftwood blog post to learn how to do this, in short we've confirmed the key can be used live for SSH or SSL [Blog post](https://trufflesecurity.com/blog/driftwood-know-if-private-keys-are-sensitive/)

Expand All @@ -96,7 +96,7 @@ trufflehog s3 --bucket=<bucket name> --only-verified
TruffleHog v3 is a complete rewrite in Go with many new powerful features.

- We've **added over 700 credential detectors that support active verification against their respective APIs**.
- We've also added native **support for scanning GitHub, GitLab, filesystems, and S3**.
- We've also added native **support for scanning GitHub, GitLab, filesystems, S3, and Circle CI**.
- **Instantly verify private keys** against millions of github users and **billions** of TLS certificates using our [Driftwood](https://trufflesecurity.com/blog/driftwood) technology.


Expand Down Expand Up @@ -130,7 +130,7 @@ docker run -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo ht
#### **Apple M1 users**

The `linux/arm64` image is better to run on the M1 than the amd64 image.
Even better is running the native darwin binary avilable, but there is not container image for that.
Even better is running the native darwin binary available, but there is no container image for that.

```bash
docker run --platform linux/arm64 -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
Expand Down Expand Up @@ -160,6 +160,7 @@ TruffleHog has a sub-command for each source of data that you may want to scan:
- S3
- filesystem
- syslog
- circleci
- file and stdin (coming soon)

Each subcommand can have options that you can see with the `--help` flag provided to the sub command:
Expand All @@ -172,27 +173,19 @@ Find credentials in git repositories.

Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--debug Run in debug mode
--version Prints trufflehog version.
--debug Run in debug mode.
--trace Run in trace mode.
-j, --json Output in JSON format.
--json-legacy Use the pre-v3.0 JSON format. Only works with git, gitlab, and github sources.
--concurrency=1 Number of concurrent workers.
--concurrency=10 Number of concurrent workers.
--no-verification Don't verify the results.
--only-verified Only output verified results.
--filter-unverified Only output first unverified result per chunk per detector if there are more than one results.
--config=CONFIG Path to configuration file.
--print-avg-detector-time Print the average time spent on each detector.
--no-update Don't check for updates.
-i, --include-paths=INCLUDE-PATHS
Path to file with newline separated regexes for files to include in scan.
-x, --exclude-paths=EXCLUDE-PATHS
Path to file with newline separated regexes for files to exclude in scan.
--since-commit=SINCE-COMMIT
Commit to start scan from.
--branch=BRANCH Branch to scan.
--max-depth=MAX-DEPTH Maximum depth of commits to scan.
--allow No-op flag for backwards compat.
--entropy No-op flag for backwards compat.
--regex No-op flag for backwards compat.
--fail Exit with code 183 if results are found.
--version Show application version.

Args:
<uri> Git repository URL. https://, file://, or ssh:// schema expected.
Expand Down Expand Up @@ -269,13 +262,111 @@ repos:
- id: trufflehog
name: TruffleHog
description: Detect secrets in your data.
entry: bash -c 'trufflehog git file://. --only-verified --fail'
entry: bash -c 'trufflehog git file://. --since-commit HEAD --only-verified --fail'
# For running trufflehog in docker, use the following entry instead:
# entry: bash -c 'docker run -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --only-verified --fail'
# entry: bash -c 'docker run -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --since-commit HEAD --only-verified --fail'
language: system
stages: ["commit", "push"]
```

## Regex Detector (alpha)

Trufflehog supports detection and verification of custom regular expressions.
For detection, at least one **regular expression** and **keyword** is required.
A **keyword** is a fixed literal string identifier that appears in or around
the regex to be detected. To allow maximum flexibility for verification, a
webhook is used containing the regular expression matches.

Trufflehog will send a JSON POST request containing the regex matches to a
configured webhook endpoint. If the endpoint responds with a `200 OK` response
status code, the secret is considered verified.

**NB:** This feature is alpha and subject to change.

### Regex Detector Example

```yaml
# config.yaml
detectors:
- name: hog detector
keywords:
- hog
regex:
adjective: hogs are (\S+)
verify:
- endpoint: http://localhost:8000/
# unsafe must be set if the endpoint is HTTP
unsafe: true
headers:
- 'Authorization: super secret authorization header'
```

```
» trufflehog filesystem --directory /tmp --config config.yaml --only-verified
🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷

Found verified result 🐷🔑
Detector Type: CustomRegex
Decoder Type: PLAIN
Raw result: hogs are cool
File: /tmp/hog-facts.txt
```

#### Verification Server Example (Python)

Unless you run a verification server, secrets found by the custom regex
detector will be unverified. Here is an example Python implementation of a
verification server for the above `config.yaml` file.

```python
import json
from http.server import BaseHTTPRequestHandler, HTTPServer

AUTH_HEADER = 'super secret authorization header'


class Verifier(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(405)
self.end_headers()

def do_POST(self):
try:
if self.headers['Authorization'] != AUTH_HEADER:
self.send_response(401)
self.end_headers()
return

# read the body
length = int(self.headers['Content-Length'])
request = json.loads(self.rfile.read(length))
self.log_message("%s", request)

# check the match
if request['hog detector']['adjective'][-1] == 'cool':
self.send_response(200)
self.end_headers()
else:
# any other response besides 200
self.send_response(406)
self.end_headers()
except Exception:
self.send_response(400)
self.end_headers()


with HTTPServer(('', 8000), Verifier) as server:
try:
server.serve_forever()
except KeyboardInterrupt:
pass
```

## Use as a library

Currently, trufflehog is in heavy development and no guarantees can be made on
the stability of the public APIs at this time.

## Contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
Expand All @@ -299,3 +390,10 @@ We have published some [documentation and tooling to get started on adding new s
## License Change

Since v3.0, TruffleHog is released under a AGPL 3 license, included in [`LICENSE`](LICENSE). TruffleHog v3.0 uses none of the previous codebase, but care was taken to preserve backwards compatibility on the command line interface. The work previous to this release is still available licensed under GPL 2.0 in the history of this repository and the previous package releases and tags. A completed CLA is required for us to accept contributions going forward.


## Enterprise product

Are you interested in continously monitoring your Git, Jira, Slack, Confluence, etc.. for credentials? We have an enterprise product that can help. Reach out here to learn more https://trufflesecurity.com/contact/

We take the revenue from the enterprise product to fund more awesome open source projects that the whole community can benefit from.
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ inputs:
required: true
base:
description: Start scanning from here (usually main branch).
required: true
required: false
default: ''
head:
description: Scan commits until here (usually dev branch).
required: false
Expand Down
9 changes: 5 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ash
#!/usr/bin/env bash

# `$*` expands the `args` supplied in an `array` individually
# or splits `args` in a string separated by whitespace.
/usr/bin/trufflehog $*
# Parse the last argument into an array of extra_args.
mapfile -t extra_args < <(bash -c "for arg in ${*: -1}; do echo \$arg; done")

/usr/bin/trufflehog "${@: 1: $#-1}" "${extra_args[@]}"