Coder Social home page Coder Social logo

utils's Introduction

utils

The package contains various helpers libraries

utils's People

Contributors

actions-user avatar alefossa avatar dependabot[bot] avatar dogancanbakir avatar dutra-malga avatar edoardottt avatar ehsandeep avatar iamargus95 avatar iamleot avatar ice3man543 avatar khiemdoan avatar luitelsamikshya avatar lz-censys avatar mzack9999 avatar ramanareddy0m avatar shubhamrasal avatar sullo avatar tarunkoyalwar avatar xm1k3 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

Watchers

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

utils's Issues

use standard format for url encoding

Proposed Changes

  • while %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 .
  • Go Stdlib also follows RFC and has above format

Add generic syncmap with locks

Create a new map helper capable of adding the following functionalities to an existing map:

  • Supports concurrent R/W
  • Can be Locked/Unlocked (Read-Only mode)

List of potential supported methods

Put(key,value)
Get(key,value)
Interate( func(key,value) )

Add helper function to count lines in files

Description

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

  • By default (if not differently provided), the new line character should be considered as a separator
  • The separator could be a regular expression
  • Skip Empty Lines
  • Additional Helper function to process multiple files and return a struct with filename e number of lines/words in the file.

Please use semantic versioning

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

update utils improvements

Proposed Changes

  • fix GetUpdateCallback not using http timeout
  • Disable proxying upgrade traffic (i.e github get latest release , download binary etc)

Additional Count Lines helpers

Description

  • Add in utils/file/file.go a new helper function to count the number of matches in a file where the separator is a regular expression
func CountLineWithRegex(re regexp.Regexp, filename string) (uint64,error)
  • Add support to skip empty lines

urlutil returns corrupted url if url contains invalid chars in path

Description

  • 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 given
    • utils/url/URL was designed to allow such cases
  • However it returns a corrupted url instead of valid one for this case i.e
https://scanme.sh/https://scanme.sh/%usd%0D%0A

Add FirstNonZero helper function

Proposed Changes

  • func FirstNonZero[T comparable](inputs []T) (T, bool)

We need to verify that the slices we return have elements that are not zero.

Add helper methods to url utils

Proposed Changes

// 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() {}

Anything else

These helper function are used in httpx

Add URL Encoding Utils

Description

From projectdiscovery/nuclei#2698

  • In Nuclei all parameters are stored in url.Values and added to URL using query.Encode() method which url encodes parameters by default. thus all parameters passed via input and all fuzzing payloads are url encoded which is basically double url encoding
  • URL Encoded similar to url.values should be implemented which doesnot encode any characters (except space).
  • A Method Similar to burpsuite intruder should be implemented where only given characters are url encoded
  • And any other methods depending on security perspective of URL encoding

Add helpers to detect OS type and Arch as boolean

Description

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"
}

Implement tests for helper functions - mapsutil

Description

Implement tests for the following functions:

  • Flatten
  • Walk

Check if these functions are aligned with nuclei implementation, otherwise update them and implement tests:

  • HTTPToMap
  • DNSToMap
  • HTTPRequesToMap
  • HTTPResponseToMap

Add support for search by key/value in generic map

Description

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)

Add contextutils

Description

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])
...

Add more string helpers

  • IsPrintable(string) checks if the string is composed only of printable characters
  • IsCTRLC checks if the input string is CTRL+C

Add proxyutils package

Description

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:

  • GetProxy(proxies ...string) ProxyFunc // Validate and get a valid proxy from a list
  • IsBurpProxy(url string) bool // checks if the proxy is burp (e.g. requesting http://burpsuite - which requires tls max version to 1.2 for https targets)

Add error type with default format

Description

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

Update mapsutil

  • Merge instead of MergeMaps (mapsutil.Merge)
  • HTTPRequestToMap test
  • HTTPResponseToMap test
  • Add Clear function
  • Add SliceToMap function & test
  • Fix test using ElementsMatch (#12)
  • Add IsEmpty function

Add error utils

Proposed Changes

Helper functions:

  • errorsutil.IsAny(err, openssl.ErrNotAvailable, ...) checks if err matches anyone of given errors
  • errorutil.WrapfWithNil(err,format string,args ...any) unlike errors.Wrapf this only wraps another error if given error is not nil
  • errorutil.WrapWithNil(err,newerrors ...error) . wrap one or more errors if given err is not nil

based 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
}

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.