Giter Club home page Giter Club logo

gf's Introduction

gf

A wrapper around grep to avoid typing common patterns.

What? Why?

I use grep a lot. When auditing code bases, looking at the output of meg, or just generally dealing with large amounts of data. I often end up using fairly complex patterns like this one:

▶ grep -HnrE '(\$_(POST|GET|COOKIE|REQUEST|SERVER|FILES)|php://(input|stdin))' *

It's really easy to mess up when typing all of that, and it can be hard to know if you haven't got any results because there are non to find, or because you screwed up writing the pattern or chose the wrong flags.

I wrote gf to give names to the pattern and flag combinations I use all the time. So the above command becomes simply:

▶ gf php-sources

Pattern Files

The pattern definitions are stored in ~/.gf as little JSON files that can be kept under version control:

▶ cat ~/.gf/php-sources.json
{
    "flags": "-HnrE",
    "pattern": "(\\$_(POST|GET|COOKIE|REQUEST|SERVER|FILES)|php://(input|stdin))"
}

To help reduce pattern length and complexity a little, you can specify a list of multiple patterns too:

▶ cat ~/.gf/php-sources-multiple.json
{
    "flags": "-HnrE",
    "patterns": [
        "\\$_(POST|GET|COOKIE|REQUEST|SERVER|FILES)",
        "php://(input|stdin)"
    ]
}

There are some more example pattern files in the examples directory.

You can use the -save flag to create pattern files from the command line:

▶ gf -save php-serialized -HnrE '(a:[0-9]+:{|O:[0-9]+:"|s:[0-9]+:")'

Auto Complete

There's an auto-complete script included, so you can hit 'tab' to show you what your options are:

▶ gf <tab>
base64       debug-pages  fw           php-curl     php-errors   php-sinks    php-sources  sec          takeovers    urls

Bash

To get auto-complete working you need to source the gf-completion.bash file in your .bashrc or similar:

source ~/path/to/gf-completion.bash

Zsh

To get auto-complete working you need to enable autocomplete (not needed if you have oh-my-zsh) using autoload -U compaudit && compinit or by putting it into .zshrc

Then source the gf-completion.zsh file in your .zshrc or similar:

source ~/path/to/gf-completion.zsh

Note: if you're using oh-my-zsh or similar you may find that gf is an alias for git fetch. You can either alias the gf binary to something else, or unalias gf to remove the git fetch alias.

Using custom engines

There are some amazing code searching engines out there that can be a better replacement for grep. A good example is the silver searcher. It's faster (like way faster) and presents the results in a more visually digestible manner. In order to utilize a different engine, add engine: <other tool> to the relevant pattern file:

# Using the silver searcher instead of grep for the aws-keys pattern:
# 1. Adding "ag" engine
# 2. Removing the E flag which is irrelevant for ag
{
  "engine": "ag",
  "flags": "-Hanr",
  "pattern": "([^A-Z0-9]|^)(AKIA|A3T|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{12,}"
}
  • Note: Different engines use different flags, so in the example above, the flag E has to be removed from the aws-keys.json file in order for ag to successfully run.

Install

If you've got Go installed and configured you can install gf with:

▶ go get -u github.com/tomnomnom/gf

If you've installed using go get, you can enable auto-completion to your .bashrc like this:

▶ echo 'source $GOPATH/src/github.com/tomnomnom/gf/gf-completion.bash' >> ~/.bashrc

Note that you'll have to restart your terminal, or run source ~/.bashrc for the changes to take effect.

To get started quickly, you can copy the example pattern files to ~/.gf like this:

▶ cp -r $GOPATH/src/github.com/tomnomnom/gf/examples ~/.gf

My personal patterns that I've included as examples might not be very useful to you, but hopefully they're still a reasonable point of reference.

Contributing

I'd actually be most interested in new pattern files! If you've got something you regularly grep for then feel free to issue a PR to add new pattern files to the examples directory.

Bug fixes are also welcome as always :)

gf's People

Contributors

c0rv4x avatar jab2870 avatar omerxx avatar shaddy avatar tomnomnom avatar vschwaberow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gf's Issues

Not showing the OUTPUT

I think I have installed this correctly as it isn't giving any error but after running it doesn't give any output.
So would like to know what can be the issue.
Screenshot 2020-07-20 at 6 12 34 PM

Backends other than grep

I am thinking that I might create a pull request that would allow use of backends such as ripgrep as a backend rather than grep.

Is this something you would be interested in?

Obviously, some of the flags are different when using a different tool. I propose changing the json files from this:

{
	"flags": "-oriahE",
	"pattern": "https?://[^\"\\'> ]+"
}

to something more like this:

{	"rg": {
		"flags": "-olIN --binary",
		"pattern": "https?://[^'\"]+"
	},
	"grep": {
		"flags": "-oriahE",
		"pattern": "https?://[^\"\\'> ]+"
	}
}

Note, I haven't tested the rg command above but it should give you an idea of how it could work.

For each json file, it would do the first that it could. The key for each section would be the command to run. In this case, it would try to use rg, if that wasn't available it would try grep.

This way, if someone wanted to use silver surfer or something else, they could.

I am not sure when I will get around to implementing this although it probably won't be for a couple of weeks.

Do you have any requests or suggestions? I am mostly looking for feedback on the proposed json format change.

gf autocomplete doesn't work

Im using Oh-my-zsh shell. Installed gf. But autocomplete is not working
Commands i used,
go get -u github.com/tomnomnom/gf

Added these lines in .zshrc,

export GOPATH="/Users/gopikrishna/go"
alias gf="$GOPATH/bin/gf"
source $GOPATH/src/github.com/tomnomnom/gf/gf-completion.zsh

when i hit tab after gf command it shows _gf:1: command not found: gf

Screenshot 2020-03-15 at 5 09 28 PM

Any help is appreciated!

Binary releases

In resource-constrained environments we sometimes cannot afford to install full-blown Go + build packages with it: good practice is to have pre-packaged binary releases for each platform like https://github.com/projectdiscovery/httpx/releases.

See https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04#step-4-building-executables-for-different-architectures for the process of creating binary releases.

You can include this in a GitHub action workflow, by leveraging something like the https://github.com/marketplace/actions/go-release-binaries action which automates the process.

This is not getting installed

In the installation manual it said that we would have a directory like go/src/github.com...... but even after installing it with go get I don't have this directory created, I cannot install this tool can u help?

Add color mode

I think there's a mode were missed and very useful, which is "--color" mode.

Bug "no such pattern" no matter what

@tomnomnom
I have the last version installed with go install github.com/tomnomnom/gf@latest , found the example and the zsh script folder and added just like before (i am installing in a new eviromment), but even with the sources in my .zshrc and everything like it was before it still not working the gf -list it's blank and when trying to run something it returns : no such pattern

Any help?

name

why it's called gf I know g is for grep but what about the f

bash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory

root@kali:~# source ~/.bashrc
bash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory
bash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory
bash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory
bash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory

Feature request: support for -A and -B grep flags

I am by no means a go developer or I would submit a pull request / prototype for this request.

It would be nice to have a way to pass -A# or -B# in the gf binary and/or encoding a field in the .json object.

Main use case is making the search more visibly identifiable, i.e. adjacent headers or other multi-line entries that might be relevant or helpful in recon.

Binary file (standard input) matches

After gf runs for a period of time, it will treat the input file as a binary file, and grep can usually be solved by using the -a option. But how can gf avoid this problem
image

grep base64 output is wrong

Below is the content in my file.
there is a JWT token which is base64 encoded.

Cache-Control: max-age=0
< Set-Cookie: _ua={"session_id":"b24a5ce4-bd5a-4375-99a5-c5eb78c524c9","session_time_ms":1585593146162}; path=/; httponly
< Set-Cookie: jwt-session=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImNzcmYtc2VjcmV0Ijoi77-9Tlxu77-9VSrvv71cdTAwMTNcdTAwMDfvv71T77-977-977-977-9XHUwMDEx77-9XHUwMDEx77-9Rlx1MDAxMu-_ve-_vSDvv70877-977-9McmiMSJ9LCJpYXQiOjE1ODU1OTMxNDYsImV4cCI6MTU4NTY3OTU0Nn0.Wkn8UFPcVJIk0pV1jQI8YqeI2FJstbpXq2UMa7B0tDU; path=/; expires=Tue, 31 Mar 2020 18:32:26 GMT; httponly
< X-Content-Type-Options: nosniff

image

when I use gf, it shows only half of the base64 encoded output. that is if there is any ' - ' in base64 format then gf regex stops there and outputs until that.

Is that a bug or expected result?
Any help is appreciated!

gf: command not found

I have reached this error whenever i tried tab to auto complete
touch test.txt|gf gf: command not found touch |gf gf: command not found

I am pretty sure that i have copy the gf list to ~/.gf
also add source of auto complete to ~/.zshrc file

#Auto complete for gf source ~/go/pkg/mod/github.com/tomnomnom/[email protected]/gf-completion.zsh

Able to install but dont know why its not showing and hence unable to run

Greetings ,
I am able to install with the command of go get, but after installing it neither gives any error nor shows the file. And on terminal it says gf is not a directory neither a file. Why is it so? How can I fix it. I fixed this issue in some other tools by downloading its binary but since this tool doesn't have binary uploaded. So, what should I do, btw I did all the steps from installing to editing and till refreshing .bashrc ...Yet nothing worked.

no pattern match

Hello

Whenever I include gf in any one liner , I always get no pattern match error.
I have given two one liners below where I am getting this error.
gau $1 | gf lfi | qsreplace "/etc/passwd" | xargs -I % -P 25 sh -c 'curl -s "%" 2>&1 | grep -q "root:x" && echo "VULN! %"'
export LHOST="http://localhost"; gau $1 | gf redirect | qsreplace "$LHOST" | xargs -I % -P 25 sh -c 'curl -Is "%" 2>&1 | grep -q "Location: $LHOST" && echo "VULN! %"'

Could you please tell me why it is happening ?

Best Regards,

Ashish

Bug when using in bash script

When running some script like

find /var/www/jsrecon/links/  -maxdepth 3 -name "waybackurl*"  -print0 | while IFS= read -r -d '' file; do gf potential $file  ; done 

you will find instead of using the input file as target , the current direcotry when running the script will be considered as target .

I think it is because of

	files := flag.Arg(1)
	if files == "" {
		files = "."
	}

in main.go

This bug wasted me more than 4 hours, hope it can get fixed

GO command updated

Use the latest version command if you face the error:

go install github.com/tomnomnom/gf@latest

gf xss not working

fatal: 'xss' does not appear to be a git repository
fatal: Could not read from remote repository.

Unable to install

root@kali:~# go get -u github.com/tomnomnom/gf
package encoding/json: unrecognized import path "encoding/json" (import path does not begin with hostname)
package errors: unrecognized import path "errors" (import path does not begin with hostname)
package flag: unrecognized import path "flag" (import path does not begin with hostname)
package fmt: unrecognized import path "fmt" (import path does not begin with hostname)
package os: unrecognized import path "os" (import path does not begin with hostname)
package os/exec: unrecognized import path "os/exec" (import path does not begin with hostname)
package os/user: unrecognized import path "os/user" (import path does not begin with hostname)
package path/filepath: unrecognized import path "path/filepath" (import path does not begin with hostname)
package strings: unrecognized import path "strings" (import path does not begin with hostname)

_PLease Help __

Suggestion: Add JavaScript `debugger` flag to debug-pages

If one wants to use this tool to debug a code base, it would be helpful to find the debugger flag in a JavaScript/NodeJs framework.

I know I can fork and add whatever patterns I like but I want to know if this pattern is actually useful or if it could just make the program run slower overall.

What do you think, @tomnomnom?

Unable to install gf in kali

hello guys , hope someone here will help to resolve this issue :
i use kali linux and i unable to install gf with :

  • go install github.com/tomnomnom/gf@latest && cp ~/go/bin/gf /usr/local/bin/ && gf -h && mkdir ~/.gf && git clone https://github.com/Sherlock297/gf_patterns.git && cd gf_patterns/ && cp *.json ~/.gf && gf -list
    cp: cannot stat '/root/go/bin/gf': No such file or directory

  • go install github.com/tomnomnom/gf@latest
    ( gf is not installed )

then i try :

  • go get -u github.com/tomnomnom/gf
    ( the some issue i got )

the issue

There is no gf-completion.bash

Actually go get -u is no longer supported, so I tried to install the package using go install github.com/tomnomnom/gf@latest. But after installing the package, there is no directory src/github.com/tomnomnom/gf/examples in $GOPATH.
So I can't complete installation and now can't use gf.

Feature Request: Allow for folders in ~/.gf/

Hello @tomnomnom

awesome lib! Super useful and applicable to so many things!

I was wondering what you think about the idea to allow for folders in ~/.gf/ - this way one could organize the files better. If I would know golang, I would give it a try, but I'm too new in the game.

Peter

gf is incompatible with oh-my-zsh git plugin

Just ran the regular installation process (go build && mv gf /usr/bin/ && cat zsh-completion.zsh >> ~/.zshrc && source ~/.zshrc) just fo find out gf wasn't working due to an alias I did not set up.

If you have oh-my-zsh and the git plugin activated (which I believe actually comes activated by default), then this plugin has an alias for gf command, for git fetch.

Console output:

$ gf -list
error: unknown switch `l'
usage: git fetch [<options>] [<repository> [<refspec>...]]
   or: git fetch [<options>] <group>
   or: git fetch --multiple [<options>] [(<repository> | <group>)...]
   or: git fetch --all [<options>] 
... ... ... 

GF also prints lines with similar patterns.

Multiple Flags

Would you be interested in a PR that allowed multiple flags? For example, it might be useful to specify include or exclude flags which don't have the short hand arguments.

Having flags like

{
    "flags": "-HnroE --include={whatever}"
    ....
}

This doesn't work as it is given to the grep command as a single argument.

I am not sure what the best way to do this is. We could spit the flags key by the space character and pass each to grep, or we could make the flags json property an array like 'patterns'.

Missing + to regexp s3-buckets

Current rules:

{
    "flags": "-hrioaE",
    "patterns": [
        "[a-z0-9.-]+\\.s3\\.amazonaws\\.com",
        "[a-z0-9.-]+\\.s3-[a-z0-9-]\\.amazonaws\\.com",
        "[a-z0-9.-]+\\.s3-website[.-](eu|ap|us|ca|sa|cn)",
        "//s3\\.amazonaws\\.com/[a-z0-9._-]+",
        "//s3-[a-z0-9-]+\\.amazonaws\\.com/[a-z0-9._-]+"
    ]
}

If I have a text file that contains:

S3 bucket: bucketname1.s3.amazonaws.com/xxxxx
S3 bucket: https://s3.amazonaws.com/bucketname2/xxxxx
S3 bucket: http://s3-us-east-2.amazonaws.com/bucketname3/xxxxx
S3 bucket: http://bucketname4.s3-ca-central-1.amazonaws.com/xxxxx

The current rule returns 3 buckets:

$ gf s3-buckets dummy.txt 
bucketname1.s3.amazonaws.com
//s3.amazonaws.com/bucketname2
//s3-us-east-2.amazonaws.com/bucketname3

By adding a single + to the second rule:

"[a-z0-9.-]+\\.s3-[a-z0-9-]+\\.amazonaws\\.com",

I get all of them:

$ gf s3-buckets dummy.txt 
bucketname1.s3.amazonaws.com
//s3.amazonaws.com/bucketname2
//s3-us-east-2.amazonaws.com/bucketname3
bucketname4.s3-ca-central-1.amazonaws.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.