The package contains various helpers libraries
projectdiscovery / utils Goto Github PK
View Code? Open in Web Editor NEWHelper Libraries
License: MIT License
Helper Libraries
License: MIT License
url.URL
wrapper that handles all parsing issues and most of the edgecasesA new release should not be created if there are no changes since the previous one (ref: https://github.com/projectdiscovery/team-backlogs/issues/228)
%d
is considered as url encoded characters and accepted by most decoders . According to RFC it should be %0D
i.e two digit hex and capital chars only .Create a new map helper capable of adding the following functionalities to an existing map:
List of potential supported methods
Put(key,value)
Get(key,value)
Interate( func(key,value) )
Setup a similar action to https://github.com/projectdiscovery/wappalyzergo/blob/master/.github/workflows/release-tag.yml with bi-weekly timing
Add in utils/file/file.go
a new helper function to count the number of lines in a file:
func CountLine(filename string) (uint64,error)
func CountLineWithSeparator(separator, filename string) (uint64,error)
Optionally, the following behavior could be supported
I know it's not easy to work with them in go as once you go over v1 you need to change paths all the time, but please use semantic versioning for this project. This project is used in other projects from projectdiscovery and builds fail all the time because go update
updates the minor versions automatically but there are often breaking changes instead and so builds depending on the other libraries tend to fail very often.
Examples:
projectdiscovery/retryablehttp-go#47
projectdiscovery/retryabledns#67
GetUpdateCallback
not using http timeoututils/file/file.go
a new helper function to count the number of matches in a file where the separator is a regular expressionfunc CountLineWithRegex(re regexp.Regexp, filename string) (uint64,error)
https://scanme.sh/%usdf%0D%0A
is a invalid url since %u
is not a valid encoding character
url.URL
returns error if above url is givenutils/url/URL
was designed to allow such caseshttps://scanme.sh/https://scanme.sh/%usd%0D%0A
Add case insensitive version of strinsgutil.ContainsAny
:
func ContainsAnyI(s string, ss ...string) bool
func FirstNonZero[T comparable](inputs []T) (T, bool)
We need to verify that the slices we return have elements that are not zero.
// EscapedString returns a string that can be used as filename (i.e stripped of / and params etc)
func (u *URL) EscapedString() string {}
// UpdateRelPath updates relative path with new path (existing params are not removed)
func (u *URL) UpdateRelPath(newrelpath string, unsafe bool) {}
// TrimPort if any
func (u *URL) TrimPort() {}
These helper function are used in httpx
Support for the following syscalls should be added:
cap_enter
cap_getmode
While reviewing projectdiscovery/proxify#205 the following functions were found to be potentially useful:
sliceutil.Merge(slices []any)
sliceutil.MergeItems(items ...any)
From projectdiscovery/nuclei#2698
- In Nuclei all parameters are stored in
url.Values
and added to URL usingquery.Encode()
method which url encodes parameters by default. thus all parameters passed viainput
and all fuzzing payloads are url encoded which is basically double url encoding
url.values
should be implemented which doesnot encode any characters (except space
).burpsuite intruder
should be implemented where only given characters are url encodedgiven an input url, returns the output hostname
Add as helpers from naabu:
// Global consts (useful for switch constructs)
type OsType uint8
const (
Darwin OsType = iota
....
)
var OS OsType
func init () {
OS = ...
}
// Global Helpers
func IsOSX() bool {
return runtime.GOOS == "darwin"
}
func IsLinux() bool {
return runtime.GOOS == "linux"
}
func IsWindows() bool {
return runtime.GOOS == "windows"
}
Notes:
A few tests fails randomly because the map values are compared with random order. These tests should be modified to make comparison order agnostic (or eg. using require.ElementsMatch
).
Ref: https://github.com/projectdiscovery/utils/actions/runs/3383736473/jobs/5619918170#step:4:96
The executils
package should attempt to identify the proper CLI engine avaliable to invoke for piped commands (cmd.exe, sh, powershell, etc). Actually it runs sh on linux and osx.
func EqualsAny[T comparable](base T,all ...T)
func EqualsAll[T comparable](base T,all ...T)
This can be used in various places for comparing multiple values , errors etc
Implement tests for the following functions:
Check if these functions are aligned with nuclei implementation, otherwise update them and implement tests:
On many occasions (e.g., to map from Type to string and vice versa), it's necessary to hold in memory a key=>value and value=>key maps. Implementing a generic mechanism to abstract the two-way search through helper functions over existing map types would be helpful. The new method' signatures might look like this:
func (m Map[K, V]) GetKeyWithValue(value V) (K,bool)
Implement a reader that can be reused multiple times
The following function:
contextutils.WithValues(ctx context.Context, name1, value1, name2, value2, ...)
could replace:
ctx := context.WithValue(context.Background(), name1, value1)
ctx = context.WithValue(ctx, name2, value2])
...
IsPrintable(string)
checks if the string is composed only of printable charactersIsCTRLC
checks if the input string is CTRL+CRef: https://github.com/projectdiscovery/utils/actions/workflows/release-tag.yml but last release is release v0.0.3
(Nov 13 2022)
Use case at: projectdiscovery/nuclei#3165 (comment)
TBD, but it should be possible to:
Many projects (nuclei, httpx, etc.) support http/https/socks5 proxies, and the logic is repeated redundantly. It would be useful to move the logic into a shared proxyutils package. The list is not complete, but it seems like the necessary methods should look like the following ones:
Often, an error must be defined with a static signature and accept later arguments. It would be super useful the possibility to declare a generic error with a signature and populate it later with runtime values:
var ErrGeneric := errorutil.NewWithFmt("error in %s with %s")
...
return ErrGeneric.Msgf("location", "error type") // binds arguments defined with NewWithFmt
GetUnexportedField(struct pointer, fieldname)
SetUnexportedField(struct pointer, field, value)
url.Parse
conflicts with Params
which causes inconsistencies in parameter encoding/decoding . Implement ParseURL
to resolve this projectdiscovery/nuclei#3167JoinPaths
that joins two relative paths and their parameters without normalising relative paths projectdiscovery/nuclei#3175abcabcabc
=> abc
mapsutil.Merge
)Helper functions:
errorsutil.IsAny(err, openssl.ErrNotAvailable, ...)
checks if err matches anyone of given errorserrorutil.WrapfWithNil(err,format string,args ...any)
unlike errors.Wrapf
this only wraps another error if given error is not nilerrorutil.WrapWithNil(err,newerrors ...error)
. wrap one or more errors if given err is not nilbased on reference projectdiscovery/tlsx#144
Proposed Enriched error Type (struct implementing the error interface):
type Error struct {
func Error() string // from standard error interface
func Equal(errs ...Error) bool // allows error comparison error1.Equal(error2)
StackTrace string // captures runtime.PrintStack()
Tag string // should work like a prefix eg; "openssl" error description or to compare errors group
Level ErrorLevel // enum of Panic/Fatal/Runtime/Etc - not sure if that might be helpful
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.