ruleset_v2 integration test working

This commit is contained in:
Kevin Pham
2023-12-05 15:02:18 -06:00
parent e6e8b0edff
commit 52d12dd1ac
8 changed files with 271 additions and 285 deletions

View File

@@ -9,7 +9,6 @@ import (
"ladder/handlers" "ladder/handlers"
"ladder/internal/cli" "ladder/internal/cli"
"ladder/proxychain/requestmodifiers/bot"
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@@ -43,15 +42,17 @@ func main() {
Help: "Adds verbose logging", Help: "Adds verbose logging",
}) })
randomGoogleBot := parser.Flag("", "random-googlebot", &argparse.Options{ /*
Required: false, randomGoogleBot := parser.Flag("", "random-googlebot", &argparse.Options{
Help: "Update the list of trusted Googlebot IPs, and use a random one for each masqueraded request", Required: false,
}) Help: "Update the list of trusted Googlebot IPs, and use a random one for each masqueraded request",
})
randomBingBot := parser.Flag("", "random-bingbot", &argparse.Options{ randomBingBot := parser.Flag("", "random-bingbot", &argparse.Options{
Required: false, Required: false,
Help: "Update the list of trusted Bingbot IPs, and use a random one for each masqueraded request", Help: "Update the list of trusted Bingbot IPs, and use a random one for each masqueraded request",
}) })
*/
// TODO: add version flag that reads from handers/VERSION // TODO: add version flag that reads from handers/VERSION
@@ -65,14 +66,9 @@ func main() {
Help: "Compiles a directory of yaml files into a single ruleset.yaml. Requires --ruleset arg.", Help: "Compiles a directory of yaml files into a single ruleset.yaml. Requires --ruleset arg.",
}) })
mergeRulesetsGzip := parser.Flag("", "merge-rulesets-gzip", &argparse.Options{
Required: false,
Help: "Compiles a directory of yaml files into a single ruleset.gz Requires --ruleset arg.",
})
mergeRulesetsOutput := parser.String("", "merge-rulesets-output", &argparse.Options{ mergeRulesetsOutput := parser.String("", "merge-rulesets-output", &argparse.Options{
Required: false, Required: false,
Help: "Specify output file for --merge-rulesets and --merge-rulesets-gzip. Requires --ruleset and --merge-rulesets args.", Help: "Specify output file for --merge-rulesets. Requires --ruleset and --merge-rulesets args.",
}) })
err := parser.Parse(os.Args) err := parser.Parse(os.Args)
@@ -80,24 +76,26 @@ func main() {
fmt.Print(parser.Usage(err)) fmt.Print(parser.Usage(err))
} }
if *randomGoogleBot { /*
err := bot.GoogleBot.UpdatePool("https://developers.google.com/static/search/apis/ipranges/googlebot.json") if *randomGoogleBot {
if err != nil { err := bot.GoogleBot.UpdatePool("https://developers.google.com/static/search/apis/ipranges/googlebot.json")
fmt.Println("error while retrieving list of Googlebot IPs: " + err.Error()) if err != nil {
fmt.Println("defaulting to known trusted Googlebot identity") fmt.Println("error while retrieving list of Googlebot IPs: " + err.Error())
fmt.Println("defaulting to known trusted Googlebot identity")
}
} }
}
if *randomBingBot { if *randomBingBot {
err := bot.BingBot.UpdatePool("https://www.bing.com/toolbox/bingbot.json") err := bot.BingBot.UpdatePool("https://www.bing.com/toolbox/bingbot.json")
if err != nil { if err != nil {
fmt.Println("error while retrieving list of Bingbot IPs: " + err.Error()) fmt.Println("error while retrieving list of Bingbot IPs: " + err.Error())
fmt.Println("defaulting to known trusted Bingbot identity") fmt.Println("defaulting to known trusted Bingbot identity")
}
} }
} */
// utility cli flag to compile ruleset directory into single ruleset.yaml // utility cli flag to compile ruleset directory into single ruleset.yaml
if *mergeRulesets || *mergeRulesetsGzip { if *mergeRulesets {
output := os.Stdout output := os.Stdout
if *mergeRulesetsOutput != "" { if *mergeRulesetsOutput != "" {
@@ -109,7 +107,7 @@ func main() {
} }
} }
err = cli.HandleRulesetMerge(*ruleset, *mergeRulesets, *mergeRulesetsGzip, output) err = cli.HandleRulesetMerge(*ruleset, *mergeRulesets, output)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

View File

@@ -1,9 +1,11 @@
package handlers package handlers
import ( import (
"fmt"
"ladder/proxychain" "ladder/proxychain"
rx "ladder/proxychain/requestmodifiers" rx "ladder/proxychain/requestmodifiers"
tx "ladder/proxychain/responsemodifiers" tx "ladder/proxychain/responsemodifiers"
"ladder/proxychain/ruleset"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@@ -24,6 +26,10 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
rs = r rs = r
} }
*/ */
rs, err := ruleset_v2.NewRuleset("ruleset_v2.yaml")
if err != nil {
panic(err)
}
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
proxychain := proxychain. proxychain := proxychain.
@@ -51,9 +57,20 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
tx.PatchDynamicResourceURLs(), tx.PatchDynamicResourceURLs(),
tx.BlockElementRemoval(".article-content"), tx.BlockElementRemoval(".article-content"),
// tx.SetContentSecurityPolicy("default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"), // tx.SetContentSecurityPolicy("default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"),
). )
Execute()
return proxychain // load ruleset
rule, exists := rs.GetRule(proxychain.Request.URL)
fmt.Println("============")
fmt.Println(proxychain.Request.URL)
fmt.Println(rs)
fmt.Println("============")
if exists {
fmt.Println("===========EXISTS=")
proxychain.AddOnceRequestModifications(rule.RequestModifications...)
proxychain.AddOnceResponseModifications(rule.ResponseModifications...)
}
return proxychain.Execute()
} }
} }

View File

@@ -5,9 +5,7 @@ import (
"io" "io"
"os" "os"
"ladder/pkg/ruleset" "ladder/proxychain/ruleset"
"golang.org/x/term"
) )
// HandleRulesetMerge merges a set of ruleset files, specified by the rulesetPath or RULESET env variable, into either YAML or Gzip format. // HandleRulesetMerge merges a set of ruleset files, specified by the rulesetPath or RULESET env variable, into either YAML or Gzip format.
@@ -21,7 +19,7 @@ import (
// //
// Returns: // Returns:
// - An error if the ruleset loading or merging process fails, otherwise nil. // - An error if the ruleset loading or merging process fails, otherwise nil.
func HandleRulesetMerge(rulesetPath string, mergeRulesets bool, useGzip bool, output *os.File) error { func HandleRulesetMerge(rulesetPath string, mergeRulesets bool, output *os.File) error {
if !mergeRulesets { if !mergeRulesets {
return nil return nil
} }
@@ -35,55 +33,15 @@ func HandleRulesetMerge(rulesetPath string, mergeRulesets bool, useGzip bool, ou
os.Exit(1) os.Exit(1)
} }
rs, err := ruleset.NewRuleset(rulesetPath) rs, err := ruleset_v2.NewRuleset(rulesetPath)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
if useGzip {
return gzipMerge(rs, output)
}
return yamlMerge(rs, output) return yamlMerge(rs, output)
} }
// gzipMerge takes a RuleSet and an optional output file path pointer. It compresses the RuleSet into Gzip format.
// If the output file path is provided, the compressed data is written to this file. Otherwise, it prints a warning
// and outputs the binary data to stdout
//
// Parameters:
// - rs: The ruleset.RuleSet to be compressed.
// - output: The output for the gzip data. If nil, stdout will be used.
//
// Returns:
// - An error if compression or file writing fails, otherwise nil.
func gzipMerge(rs ruleset.RuleSet, output io.Writer) error {
gzip, err := rs.GzipYaml()
if err != nil {
return err
}
if output != nil {
_, err = io.Copy(output, gzip)
if err != nil {
return err
}
}
if term.IsTerminal(int(os.Stdout.Fd())) {
println("warning: binary output can mess up your terminal. Use '--merge-rulesets-output <ruleset.gz>' or pipe it to a file.")
os.Exit(1)
}
_, err = io.Copy(os.Stdout, gzip)
if err != nil {
return err
}
return nil
}
// yamlMerge takes a RuleSet and an optional output file path pointer. It converts the RuleSet into YAML format. // yamlMerge takes a RuleSet and an optional output file path pointer. It converts the RuleSet into YAML format.
// If the output file path is provided, the YAML data is written to this file. If not, the YAML data is printed to stdout. // If the output file path is provided, the YAML data is written to this file. If not, the YAML data is printed to stdout.
// //
@@ -93,7 +51,7 @@ func gzipMerge(rs ruleset.RuleSet, output io.Writer) error {
// //
// Returns: // Returns:
// - An error if YAML conversion or file writing fails, otherwise nil. // - An error if YAML conversion or file writing fails, otherwise nil.
func yamlMerge(rs ruleset.RuleSet, output io.Writer) error { func yamlMerge(rs ruleset_v2.Ruleset, output io.Writer) error {
yaml, err := rs.Yaml() yaml, err := rs.Yaml()
if err != nil { if err != nil {
return err return err

View File

@@ -3,23 +3,13 @@ package proxychain
import ( import (
"errors" "errors"
"fmt" "fmt"
http "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client"
"io" "io"
"log" "log"
"net/url" "net/url"
"strings" "strings"
//"time"
//"net/http"
//"github.com/Danny-Dasilva/CycleTLS/cycletls"
//http "github.com/Danny-Dasilva/fhttp"
http "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client"
//"github.com/bogdanfinn/tls-client/profiles"
"ladder/pkg/ruleset"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@@ -100,7 +90,6 @@ type ProxyChain struct {
onceRequestModifications []RequestModification onceRequestModifications []RequestModification
onceResponseModifications []ResponseModification onceResponseModifications []ResponseModification
responseModifications []ResponseModification responseModifications []ResponseModification
Ruleset *ruleset.RuleSet
debugMode bool debugMode bool
abortErr error abortErr error
APIPrefix string APIPrefix string
@@ -177,13 +166,6 @@ func (chain *ProxyChain) WithAPIPath(path string) *ProxyChain {
return chain return chain
} }
// Adds a ruleset to ProxyChain
func (chain *ProxyChain) AddRuleset(rs *ruleset.RuleSet) *ProxyChain {
chain.Ruleset = rs
// TODO: add _applyRuleset method
return chain
}
func (chain *ProxyChain) _initializeRequest() (*http.Request, error) { func (chain *ProxyChain) _initializeRequest() (*http.Request, error) {
if chain.Context == nil { if chain.Context == nil {
chain.abortErr = chain.abort(errors.New("no context set")) chain.abortErr = chain.abort(errors.New("no context set"))

View File

@@ -1,5 +1,5 @@
package ruleset_v2
package ruleset_v2
// DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go // DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go
// The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable // The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable
// for use in proxychains. // for use in proxychains.
@@ -16,167 +16,168 @@ var rqmModMap map[string]RequestModifierFactory
func init() { func init() {
rqmModMap = make(map[string]RequestModifierFactory) rqmModMap = make(map[string]RequestModifierFactory)
rqmModMap["ForwardRequestHeaders"] = func(_ ...string) proxychain.RequestModification { rqmModMap["ForwardRequestHeaders"] = func(_ ...string) proxychain.RequestModification {
return rx.ForwardRequestHeaders() return rx.ForwardRequestHeaders()
} }
rqmModMap["MasqueradeAsGoogleBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsGoogleBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsGoogleBot() return rx.MasqueradeAsGoogleBot()
} }
rqmModMap["MasqueradeAsBingBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsBingBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsBingBot() return rx.MasqueradeAsBingBot()
} }
rqmModMap["MasqueradeAsWaybackMachineBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsWaybackMachineBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsWaybackMachineBot() return rx.MasqueradeAsWaybackMachineBot()
} }
rqmModMap["MasqueradeAsFacebookBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsFacebookBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsFacebookBot() return rx.MasqueradeAsFacebookBot()
} }
rqmModMap["MasqueradeAsYandexBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsYandexBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsYandexBot() return rx.MasqueradeAsYandexBot()
} }
rqmModMap["MasqueradeAsBaiduBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsBaiduBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsBaiduBot() return rx.MasqueradeAsBaiduBot()
} }
rqmModMap["MasqueradeAsDuckDuckBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsDuckDuckBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsDuckDuckBot() return rx.MasqueradeAsDuckDuckBot()
} }
rqmModMap["MasqueradeAsYahooBot"] = func(_ ...string) proxychain.RequestModification { rqmModMap["MasqueradeAsYahooBot"] = func(_ ...string) proxychain.RequestModification {
return rx.MasqueradeAsYahooBot() return rx.MasqueradeAsYahooBot()
} }
rqmModMap["ModifyDomainWithRegex"] = func(params ...string) proxychain.RequestModification { rqmModMap["ModifyDomainWithRegex"] = func(params ...string) proxychain.RequestModification {
return rx.ModifyDomainWithRegex(params[0], params[1]) return rx.ModifyDomainWithRegex(params[0], params[1])
} }
rqmModMap["SetOutgoingCookie"] = func(params ...string) proxychain.RequestModification { rqmModMap["SetOutgoingCookie"] = func(params ...string) proxychain.RequestModification {
return rx.SetOutgoingCookie(params[0], params[1]) return rx.SetOutgoingCookie(params[0], params[1])
} }
rqmModMap["SetOutgoingCookies"] = func(params ...string) proxychain.RequestModification { rqmModMap["SetOutgoingCookies"] = func(params ...string) proxychain.RequestModification {
return rx.SetOutgoingCookies(params[0]) return rx.SetOutgoingCookies(params[0])
} }
rqmModMap["DeleteOutgoingCookie"] = func(params ...string) proxychain.RequestModification { rqmModMap["DeleteOutgoingCookie"] = func(params ...string) proxychain.RequestModification {
return rx.DeleteOutgoingCookie(params[0]) return rx.DeleteOutgoingCookie(params[0])
} }
rqmModMap["DeleteOutgoingCookies"] = func(_ ...string) proxychain.RequestModification { rqmModMap["DeleteOutgoingCookies"] = func(_ ...string) proxychain.RequestModification {
return rx.DeleteOutgoingCookies() return rx.DeleteOutgoingCookies()
} }
rqmModMap["DeleteOutgoingCookiesExcept"] = func(params ...string) proxychain.RequestModification { rqmModMap["DeleteOutgoingCookiesExcept"] = func(params ...string) proxychain.RequestModification {
return rx.DeleteOutgoingCookiesExcept(params[0]) return rx.DeleteOutgoingCookiesExcept(params[0])
} }
rqmModMap["ModifyPathWithRegex"] = func(params ...string) proxychain.RequestModification { rqmModMap["ModifyPathWithRegex"] = func(params ...string) proxychain.RequestModification {
return rx.ModifyPathWithRegex(params[0], params[1]) return rx.ModifyPathWithRegex(params[0], params[1])
} }
rqmModMap["ModifyQueryParams"] = func(params ...string) proxychain.RequestModification { rqmModMap["ModifyQueryParams"] = func(params ...string) proxychain.RequestModification {
return rx.ModifyQueryParams(params[0], params[1]) return rx.ModifyQueryParams(params[0], params[1])
} }
rqmModMap["SetRequestHeader"] = func(params ...string) proxychain.RequestModification { rqmModMap["SetRequestHeader"] = func(params ...string) proxychain.RequestModification {
return rx.SetRequestHeader(params[0], params[1]) return rx.SetRequestHeader(params[0], params[1])
} }
rqmModMap["DeleteRequestHeader"] = func(params ...string) proxychain.RequestModification { rqmModMap["DeleteRequestHeader"] = func(params ...string) proxychain.RequestModification {
return rx.DeleteRequestHeader(params[0]) return rx.DeleteRequestHeader(params[0])
} }
rqmModMap["RequestArchiveIs"] = func(_ ...string) proxychain.RequestModification { rqmModMap["RequestArchiveIs"] = func(_ ...string) proxychain.RequestModification {
return rx.RequestArchiveIs() return rx.RequestArchiveIs()
} }
rqmModMap["RequestGoogleCache"] = func(_ ...string) proxychain.RequestModification { rqmModMap["RequestGoogleCache"] = func(_ ...string) proxychain.RequestModification {
return rx.RequestGoogleCache() return rx.RequestGoogleCache()
} }
rqmModMap["RequestWaybackMachine"] = func(_ ...string) proxychain.RequestModification { rqmModMap["RequestWaybackMachine"] = func(_ ...string) proxychain.RequestModification {
return rx.RequestWaybackMachine() return rx.RequestWaybackMachine()
} }
rqmModMap["ResolveWithGoogleDoH"] = func(_ ...string) proxychain.RequestModification { rqmModMap["ResolveWithGoogleDoH"] = func(_ ...string) proxychain.RequestModification {
return rx.ResolveWithGoogleDoH() return rx.ResolveWithGoogleDoH()
} }
rqmModMap["SpoofOrigin"] = func(params ...string) proxychain.RequestModification { rqmModMap["SpoofOrigin"] = func(params ...string) proxychain.RequestModification {
return rx.SpoofOrigin(params[0]) return rx.SpoofOrigin(params[0])
} }
rqmModMap["HideOrigin"] = func(_ ...string) proxychain.RequestModification { rqmModMap["HideOrigin"] = func(_ ...string) proxychain.RequestModification {
return rx.HideOrigin() return rx.HideOrigin()
} }
rqmModMap["SpoofReferrer"] = func(params ...string) proxychain.RequestModification { rqmModMap["SpoofReferrer"] = func(params ...string) proxychain.RequestModification {
return rx.SpoofReferrer(params[0]) return rx.SpoofReferrer(params[0])
} }
rqmModMap["HideReferrer"] = func(_ ...string) proxychain.RequestModification { rqmModMap["HideReferrer"] = func(_ ...string) proxychain.RequestModification {
return rx.HideReferrer() return rx.HideReferrer()
} }
rqmModMap["SpoofReferrerFromBaiduSearch"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromBaiduSearch"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromBaiduSearch() return rx.SpoofReferrerFromBaiduSearch()
} }
rqmModMap["SpoofReferrerFromBingSearch"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromBingSearch"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromBingSearch() return rx.SpoofReferrerFromBingSearch()
} }
rqmModMap["SpoofReferrerFromGoogleSearch"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromGoogleSearch"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromGoogleSearch() return rx.SpoofReferrerFromGoogleSearch()
} }
rqmModMap["SpoofReferrerFromLinkedInPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromLinkedInPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromLinkedInPost() return rx.SpoofReferrerFromLinkedInPost()
} }
rqmModMap["SpoofReferrerFromNaverSearch"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromNaverSearch"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromNaverSearch() return rx.SpoofReferrerFromNaverSearch()
} }
rqmModMap["SpoofReferrerFromPinterestPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromPinterestPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromPinterestPost() return rx.SpoofReferrerFromPinterestPost()
} }
rqmModMap["SpoofReferrerFromQQPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromQQPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromQQPost() return rx.SpoofReferrerFromQQPost()
} }
rqmModMap["SpoofReferrerFromRedditPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromRedditPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromRedditPost() return rx.SpoofReferrerFromRedditPost()
} }
rqmModMap["SpoofReferrerFromTumblrPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromTumblrPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromTumblrPost() return rx.SpoofReferrerFromTumblrPost()
} }
rqmModMap["SpoofReferrerFromTwitterPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromTwitterPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromTwitterPost() return rx.SpoofReferrerFromTwitterPost()
} }
rqmModMap["SpoofReferrerFromVkontaktePost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromVkontaktePost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromVkontaktePost() return rx.SpoofReferrerFromVkontaktePost()
} }
rqmModMap["SpoofReferrerFromWeiboPost"] = func(_ ...string) proxychain.RequestModification { rqmModMap["SpoofReferrerFromWeiboPost"] = func(_ ...string) proxychain.RequestModification {
return rx.SpoofReferrerFromWeiboPost() return rx.SpoofReferrerFromWeiboPost()
} }
rqmModMap["SpoofUserAgent"] = func(params ...string) proxychain.RequestModification { rqmModMap["SpoofUserAgent"] = func(params ...string) proxychain.RequestModification {
return rx.SpoofUserAgent(params[0]) return rx.SpoofUserAgent(params[0])
} }
rqmModMap["SpoofXForwardedFor"] = func(params ...string) proxychain.RequestModification { rqmModMap["SpoofXForwardedFor"] = func(params ...string) proxychain.RequestModification {
return rx.SpoofXForwardedFor(params[0]) return rx.SpoofXForwardedFor(params[0])
} }
}
}

View File

@@ -1,5 +1,5 @@
package ruleset_v2
package ruleset_v2
// DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go // DO NOT EDIT THIS FILE. It is automatically generated by ladder/proxychain/codegen/codegen.go
// The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable // The purpose of this is serialization of rulesets from JSON or YAML into functional options suitable
// for use in proxychains. // for use in proxychains.
@@ -16,83 +16,84 @@ var rsmModMap map[string]ResponseModifierFactory
func init() { func init() {
rsmModMap = make(map[string]ResponseModifierFactory) rsmModMap = make(map[string]ResponseModifierFactory)
rsmModMap["APIContent"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["APIContent"] = func(_ ...string) proxychain.ResponseModification {
return tx.APIContent() return tx.APIContent()
} }
rsmModMap["BlockElementRemoval"] = func(params ...string) proxychain.ResponseModification { rsmModMap["BlockElementRemoval"] = func(params ...string) proxychain.ResponseModification {
return tx.BlockElementRemoval(params[0]) return tx.BlockElementRemoval(params[0])
} }
rsmModMap["BypassCORS"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["BypassCORS"] = func(_ ...string) proxychain.ResponseModification {
return tx.BypassCORS() return tx.BypassCORS()
} }
rsmModMap["BypassContentSecurityPolicy"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["BypassContentSecurityPolicy"] = func(_ ...string) proxychain.ResponseModification {
return tx.BypassContentSecurityPolicy() return tx.BypassContentSecurityPolicy()
} }
rsmModMap["SetContentSecurityPolicy"] = func(params ...string) proxychain.ResponseModification { rsmModMap["SetContentSecurityPolicy"] = func(params ...string) proxychain.ResponseModification {
return tx.SetContentSecurityPolicy(params[0]) return tx.SetContentSecurityPolicy(params[0])
} }
rsmModMap["ForwardResponseHeaders"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["ForwardResponseHeaders"] = func(_ ...string) proxychain.ResponseModification {
return tx.ForwardResponseHeaders() return tx.ForwardResponseHeaders()
} }
rsmModMap["GenerateReadableOutline"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["GenerateReadableOutline"] = func(_ ...string) proxychain.ResponseModification {
return tx.GenerateReadableOutline() return tx.GenerateReadableOutline()
} }
rsmModMap["InjectScriptBeforeDOMContentLoaded"] = func(params ...string) proxychain.ResponseModification { rsmModMap["InjectScriptBeforeDOMContentLoaded"] = func(params ...string) proxychain.ResponseModification {
return tx.InjectScriptBeforeDOMContentLoaded(params[0]) return tx.InjectScriptBeforeDOMContentLoaded(params[0])
} }
rsmModMap["InjectScriptAfterDOMContentLoaded"] = func(params ...string) proxychain.ResponseModification { rsmModMap["InjectScriptAfterDOMContentLoaded"] = func(params ...string) proxychain.ResponseModification {
return tx.InjectScriptAfterDOMContentLoaded(params[0]) return tx.InjectScriptAfterDOMContentLoaded(params[0])
} }
rsmModMap["InjectScriptAfterDOMIdle"] = func(params ...string) proxychain.ResponseModification { rsmModMap["InjectScriptAfterDOMIdle"] = func(params ...string) proxychain.ResponseModification {
return tx.InjectScriptAfterDOMIdle(params[0]) return tx.InjectScriptAfterDOMIdle(params[0])
} }
rsmModMap["DeleteIncomingCookies"] = func(params ...string) proxychain.ResponseModification { rsmModMap["DeleteIncomingCookies"] = func(params ...string) proxychain.ResponseModification {
return tx.DeleteIncomingCookies(params[0]) return tx.DeleteIncomingCookies(params[0])
} }
rsmModMap["DeleteIncomingCookiesExcept"] = func(params ...string) proxychain.ResponseModification { rsmModMap["DeleteIncomingCookiesExcept"] = func(params ...string) proxychain.ResponseModification {
return tx.DeleteIncomingCookiesExcept(params[0]) return tx.DeleteIncomingCookiesExcept(params[0])
} }
rsmModMap["SetIncomingCookies"] = func(params ...string) proxychain.ResponseModification { rsmModMap["SetIncomingCookies"] = func(params ...string) proxychain.ResponseModification {
return tx.SetIncomingCookies(params[0]) return tx.SetIncomingCookies(params[0])
} }
rsmModMap["SetIncomingCookie"] = func(params ...string) proxychain.ResponseModification { rsmModMap["SetIncomingCookie"] = func(params ...string) proxychain.ResponseModification {
return tx.SetIncomingCookie(params[0], params[1]) return tx.SetIncomingCookie(params[0], params[1])
} }
rsmModMap["SetResponseHeader"] = func(params ...string) proxychain.ResponseModification { rsmModMap["SetResponseHeader"] = func(params ...string) proxychain.ResponseModification {
return tx.SetResponseHeader(params[0], params[1]) return tx.SetResponseHeader(params[0], params[1])
} }
rsmModMap["DeleteResponseHeader"] = func(params ...string) proxychain.ResponseModification { rsmModMap["DeleteResponseHeader"] = func(params ...string) proxychain.ResponseModification {
return tx.DeleteResponseHeader(params[0]) return tx.DeleteResponseHeader(params[0])
} }
rsmModMap["PatchDynamicResourceURLs"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["PatchDynamicResourceURLs"] = func(_ ...string) proxychain.ResponseModification {
return tx.PatchDynamicResourceURLs() return tx.PatchDynamicResourceURLs()
} }
rsmModMap["PatchGoogleAnalytics"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["PatchGoogleAnalytics"] = func(_ ...string) proxychain.ResponseModification {
return tx.PatchGoogleAnalytics() return tx.PatchGoogleAnalytics()
} }
rsmModMap["PatchTrackerScripts"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["PatchTrackerScripts"] = func(_ ...string) proxychain.ResponseModification {
return tx.PatchTrackerScripts() return tx.PatchTrackerScripts()
} }
rsmModMap["RewriteHTMLResourceURLs"] = func(_ ...string) proxychain.ResponseModification { rsmModMap["RewriteHTMLResourceURLs"] = func(_ ...string) proxychain.ResponseModification {
return tx.RewriteHTMLResourceURLs() return tx.RewriteHTMLResourceURLs()
} }
}
}

View File

@@ -163,6 +163,18 @@ func (rs *Ruleset) loadRulesFromLocalDir(path string) error {
return nil return nil
}) })
// create a map of pointers to rules loaded above based on domain string keys
// this way we don't have two copies of the rule in ruleset
for i, rule := range rs.Rules {
rulePtr := &rs.Rules[i]
for _, domain := range rule.Domains {
rs._rulemap[domain] = rulePtr
if !strings.HasPrefix(domain, "www.") {
rs._rulemap["www."+domain] = rulePtr
}
}
}
if err != nil { if err != nil {
return err return err
} }

17
ruleset_v2.yaml Normal file
View File

@@ -0,0 +1,17 @@
rules:
- domains:
- example.com
- www.example.com
responsemodifications:
- name: APIContent
params: []
- name: SetContentSecurityPolicy
params:
- foobar
- name: SetIncomingCookie
params:
- authorization-bearer
- hunter2
requestmodifications:
- name: ForwardRequestHeaders
params: []