utilities

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 28 Imported by: 0

README

Utilities

A comprehensive Go utilities package providing various helper functions for common tasks including captcha solving, HTTP requests, hashing, parsing, and more.

Features

  • Captcha Solving: Support for various captcha types (reCAPTCHA v2/v3, hCaptcha, Turnstile, FunCaptcha, Image captcha)
  • HTTP Utilities: TLS client management, request handling, and user agent generation
  • Hashing Functions: SHA256, SHA1, MD5, HMAC, PBKDF2, and more
  • Parsing Utilities: JSON parsing, regex parsing, string manipulation
  • Random Generation: Secure random string generation, PKCE pair generation
  • Encoding/Decoding: Base64, URL encoding, and more

Installation

go get github.com/Gambitious/Utilities

Usage

Captcha Solving
package main

import (
    "fmt"
    "github.com/Gambitious/Utilities"
)

func main() {
    // Solve reCAPTCHA v2
    solution, err := utilities.SolveRecaptchaV2(
        "site-key",
        "https://example.com",
        false, // isInvisible
        false, // isEnterprise
        "user-agent",
        "captcha-api-key",
        "", // proxy (empty for proxyless)
        true, // proxyless
    )
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    
    fmt.Printf("Solution: %s\n", solution)
}
HTTP Utilities
package main

import (
    "github.com/Gambitious/Utilities"
    "github.com/bogdanfinn/tls-client/profiles"
)

func main() {
    // Initialize TLS client
    client := utilities.InitTLS(
        "", // proxy
        30, // timeout
        profiles.Chrome_120,
    )
    
    // Generate random user agent
    userAgent := utilities.RandomUserAgent()
    fmt.Printf("User Agent: %s\n", userAgent)
}
Hashing Functions
package main

import (
    "crypto/sha256"
    "github.com/Gambitious/Utilities"
)

func main() {
    // SHA256 hash
    hash := utilities.SHA256("hello world")
    fmt.Printf("SHA256: %s\n", hash)
    
    // HMAC
    hmac := utilities.HMAC("key", "message", crypto.SHA256, false)
    fmt.Printf("HMAC: %s\n", hmac)
}
Parsing Utilities
package main

import (
    "github.com/Gambitious/Utilities"
)

func main() {
    jsonStr := `{"user": {"name": "John", "age": 30}}`
    
    // Extract value from JSON
    name := utilities.GetValuesByKey(jsonStr, "user.name")
    fmt.Printf("Name: %s\n", name[0])
    
    // Parse with regex
    results, err := utilities.RegexParse(
        "Hello World 123",
        `(\w+) (\w+) (\d+)`,
        "[1] [2] [3]",
        false,
    )
    if err == nil {
        fmt.Printf("Parsed: %v\n", results)
    }
}

API Reference

Captcha Functions
  • SolveImageCaptcha(imageData, capKey string) (string, error)
  • SolveHCaptcha(siteKey, siteUrl string, isInvisible bool, userAgent, capKey string) (string, error)
  • SolveTurnstile(siteKey, siteUrl, capKey string) (string, error)
  • SolveFunCaptcha(siteUrl, siteKey, subdomainHost, capKey string) (string, error)
  • SolveRecaptchaV2(siteKey, siteUrl string, isInvisible, isEnterprise bool, userAgent, capKey, proxy string, proxyless bool) (string, error)
  • SolveRecaptchaV3(siteKey, siteUrl, siteAction string, isInvisible, isEnterprise bool, userAgent, capKey, proxy string, proxyless bool) (string, error)
HTTP Functions
  • InitTLS(proxy string, timeout int, profile profiles.ClientProfile) tls_client.HttpClient
  • InitTLSProxyless(timeout int, profile profiles.ClientProfile) tls_client.HttpClient
  • RandomUserAgent() string
  • GetRandomProfile() (string, profiles.ClientProfile)
  • MakeRequest(TLS tls_client.HttpClient, uri, content, method string, headers http.Header) (*http.Response, error)
Hashing Functions
  • SHA256(input string) string
  • SHA1(input string) string
  • HMAC(key, input string, hashType crypto.Hash, b64 bool) string
  • PBKDF2(password, salt []byte, algorithm string, iterations int) []byte
Parsing Functions
  • GetValuesByKey(jsonStr, path string) []string
  • RegexParse(input, pattern, outputFormat string, multiline bool) ([]string, error)
  • LR(source, left, right string, recursion bool) []string
  • JSON(source, field string, recursion bool) []string
Utility Functions
  • RandomString(input string) string
  • GeneratePKCEPair() (codeVerifier string, codeChallenge string)
  • Base64Encode(text string) string
  • Base64Decode(text string) string
  • ReverseString(s string) string
  • Distinct(input []string) []string

Dependencies

This package uses the following external dependencies:

  • github.com/bogdanfinn/fhttp - HTTP client
  • github.com/bogdanfinn/tls-client - TLS client
  • github.com/go-resty/resty/v2 - HTTP client for captcha solving
  • github.com/golang-jwt/jwt - JWT handling
  • github.com/xdg-go/pbkdf2 - PBKDF2 implementation
  • golang.org/x/crypto - Cryptographic functions

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Disclaimer

This package includes functionality for solving captchas. Please ensure you comply with the terms of service of the websites you interact with and the captcha solving services you use.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(text string) string

func Base64Encode

func Base64Encode(text string) string

func ConvertToJsonSingleLine

func ConvertToJsonSingleLine(input string) (string, error)

func CurrentUnixTime

func CurrentUnixTime(useUtc bool) int64

func DeriveKeyFromPassword

func DeriveKeyFromPassword(password, email string, kdfConfig map[string]int) []byte

DeriveKeyFromPassword derives a master key from password and email using PBKDF2.

func Distinct

func Distinct(input []string) []string

func DoubleSha256

func DoubleSha256(data []byte) []byte

func FormatInt

func FormatInt(n int) string

func FormatInt64

func FormatInt64(n int64) string

func FromBufferToB64

func FromBufferToB64(data []byte) string

FromBufferToB64 converts a byte slice to a base64 string.

func FromUtf8ToBytes

func FromUtf8ToBytes(str string) []byte

FromUtf8ToBytes converts a UTF-8 string to a byte slice.

func GenerateOAuth2Params

func GenerateOAuth2Params(length int) (state, codeVerifier, codeChallenge string, err error)

func GeneratePKCEPair

func GeneratePKCEPair() (codeVerifier string, codeChallenge string)

Function to generate a code verifier and code challenge

func GenerateRandomHex

func GenerateRandomHex(length int) (string, error)

func GetCurrentISO8601Datetime

func GetCurrentISO8601Datetime() string

func GetRandomChromeProfile

func GetRandomChromeProfile() (string, profiles.ClientProfile)

func GetRandomDesktopProfile

func GetRandomDesktopProfile() (string, profiles.ClientProfile)

func GetRandomIOSProfile

func GetRandomIOSProfile() (string, profiles.ClientProfile)

func GetRandomProfile

func GetRandomProfile() (string, profiles.ClientProfile)

func GetValuesByKey

func GetValuesByKey(jsonStr, path string) []string

func HMAC

func HMAC(key, input string, hashType crypto.Hash, b64 bool) string

Hmac creates an HMAC with SHA256, optionally base64 encoded

func Hash

func Hash(input string, hasher hash.Hash) string

Hash hashes input using SHA256 and returns the result as a hex string

func HashMasterKey

func HashMasterKey(password string, key []byte) string

HashMasterKey hashes a master key using PBKDF2 and a specified purpose.

func InitTLS

func InitTLS(proxy string, timeout int, profile profiles.ClientProfile) tls_client.HttpClient
func InitTLS(proxy string, timeout int, profile profiles.ClientProfile) tls_client.HttpClient {
	cookieJarOptions := []tls_client.CookieJarOption{
		tls_client.WithAllowEmptyCookies(),
	}
	jar := tls_client.NewCookieJar(cookieJarOptions...)
	options := []tls_client.HttpClientOption{
		tls_client.WithTimeoutSeconds(timeout),
		// tls_client.WithNotFollowRedirects(),
		// tls_client.WithDebug(),
		tls_client.WithCookieJar(jar),
		// tls_client.WithRandomTLSExtensionOrder(),
		tls_client.WithClientProfile(profile),
		tls_client.WithProxyUrl(proxy),
	}
	client, err := tls_client.NewHttpClient(nil /*tls_client.NewDebugLogger(tls_client.NewLogger())*/, options...)
	if err != nil {
		fmt.Println("TLS Error: " + err.Error())
		return nil
	}
	return client
}

func InitTLSOF

func InitTLSOF(proxy string, timeout int, profile profiles.ClientProfile) tls_client.HttpClient

func InitTLSProxyless

func InitTLSProxyless(timeout int, profile profiles.ClientProfile) tls_client.HttpClient

func InitTLSSkipVerify

func InitTLSSkipVerify(proxy string, timeout int, profile profiles.ClientProfile) tls_client.HttpClient

func JSON

func JSON(source, field string, recursion bool) []string

func JToken

func JToken(JSON, jToken string, recursive bool) []string

func JsonParserGetValuesByKey

func JsonParserGetValuesByKey(data interface{}, keys []string) []string

JsonParserGetValuesByKey function in Go

func LR

func LR(source, left, right string, recursion bool) []string

func MakeMasterKey

func MakeMasterKey(password, email string, kdfConfig map[string]int) []byte

MakeMasterKey creates a master key using password and email.

func MakePreloginKey

func MakePreloginKey(masterPassword, email string, iterations int) []byte

MakePreloginKey makes a pre-login key using the user's master password and email.

func MakeRequest

func MakeRequest(TLS tls_client.HttpClient, uri, content, method string, headers http.Header) (*http.Response, error)

func MakeRequestCookies

func MakeRequestCookies(TLS tls_client.HttpClient, url, content, method string, headers http.Header, cookies []http.Cookie) (http.Response, error)

}

func PBKDF2

func PBKDF2(password, salt []byte, algorithm string, iterations int) []byte

PBKDF2 derives a key using PBKDF2 with specified parameters.

func PBKDF2Hash

func PBKDF2Hash(credentials map[string]string, iterations int) string

LogIn performs login by deriving and hashing keys based on user credentials.

func ParseProxyFasthttp

func ParseProxyFasthttp(proxy string) string

func ParseProxyTLS

func ParseProxyTLS(proxy string) string

func QueryJsonToken

func QueryJsonToken(jsonStr, jToken, prefix, suffix string, urlEncodeOutput bool) string

func RSAEncrypt

func RSAEncrypt(data, modulus, exponent string) (string, error)

func RandomAndroidUserAgent

func RandomAndroidUserAgent() string

func RandomString

func RandomString(input string) string

RandomString generates a random string given a mask

func RandomUserAgent

func RandomUserAgent() string

func RegexParse

func RegexParse(input, pattern, outputFormat string, multiline bool) ([]string, error)

func RemoveCookieByName

func RemoveCookieByName(cookies []*http.Cookie, namesToRemove ...string) []*http.Cookie

func RemoveElement

func RemoveElement(s []string, r string) []string

func ReverseString

func ReverseString(s string) string

func SHA1

func SHA1(input string) string

func SHA256

func SHA256(input string) string

func SolveFunCaptcha

func SolveFunCaptcha(siteUrl, siteKey, subdomainHost, capKey string) (string, error)

func SolveHCaptcha

func SolveHCaptcha(siteKey, siteUrl string, isInvisible bool, userAgent, capKey string) (string, error)

func SolveImageCaptcha

func SolveImageCaptcha(imageData, capKey string) (string, error)

func SolveRecaptchaV2

func SolveRecaptchaV2(siteKey, siteUrl string, isInvisible, isEnterprise bool, userAgent, capKey, proxy string, proxyless bool) (string, error)

func SolveRecaptchaV2EnterpriseNextCaptcha

func SolveRecaptchaV2EnterpriseNextCaptcha(siteKey, siteUrl string, isInvisible bool, title, websiteInfo, apiDomain, action, capKey string) (string, error)

func SolveRecaptchaV3

func SolveRecaptchaV3(siteKey, siteUrl, siteAction string, isInvisible, isEnterprise bool, userAgent, capKey, proxy string, proxyless bool) (string, error)

func SolveTurnstile

func SolveTurnstile(siteKey, siteUrl, capKey string) (string, error)

func UnixTimeToDate

func UnixTimeToDate(timestamp int64, format string) string

func Zip

func Zip(a, b []string, format string) ([]string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL