Skip to content

Commit

Permalink
(#342) Add --ignore-param flag and change func 'CheckInspectionParam'
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Feb 12, 2022
1 parent aa2035a commit e9d75b5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 23 deletions.
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var cfgFile string
var optionsStr = make(map[string]string)
var optionsBool = make(map[string]bool)
var header, p []string
var header, p, ignoreParams []string
var config, cookie, data, customPayload, userAgent, blind, output, format, foundAction, proxy, grep, cookieFromRaw string
var ignoreReturn, miningWord, method, customAlertValue, customAlertType, remotePayloads, remoteWordlists string
var timeout, concurrence, delay int
Expand Down Expand Up @@ -45,6 +45,7 @@ func init() {
// Slice
rootCmd.PersistentFlags().StringSliceVarP(&header, "header", "H", []string{}, "Add custom headers")
rootCmd.PersistentFlags().StringSliceVarP(&p, "param", "p", []string{}, "Only testing selected parameters")
rootCmd.PersistentFlags().StringSliceVar(&ignoreParams, "ignore-param", []string{}, "Ignores this parameter when scanning.\n * Example: --ignore-param api_token --ignore-param csrf_token")

//Str
rootCmd.PersistentFlags().StringVar(&config, "config", "", "Using config from file")
Expand All @@ -61,7 +62,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&foundActionShell, "found-action-shell", "bash", "Select shell application for --found-action")
rootCmd.PersistentFlags().StringVar(&proxy, "proxy", "", "Send all request to proxy server\n * Example: --proxy http://127.0.0.1:8080")
rootCmd.PersistentFlags().StringVar(&grep, "grep", "", "Using custom grepping file\n * Example: --grep ./samples/sample_grep.json")
rootCmd.PersistentFlags().StringVar(&ignoreReturn, "ignore-return", "", "Ignore scanning from return code\n * Example: --ignore-return 302,403,404")
rootCmd.PersistentFlags().StringVar(&ignoreReturn, "ignore-return", "", "Ignores scanning from return code\n * Example: --ignore-return 302,403,404")
rootCmd.PersistentFlags().StringVarP(&miningWord, "mining-dict-word", "W", "", "Custom wordlist file for param mining\n * Example: --mining-dict-word word.txt")
rootCmd.PersistentFlags().StringVarP(&method, "method", "X", "GET", "Force overriding HTTP Method\n * Example: -X PUT")
rootCmd.PersistentFlags().StringVarP(&cookieFromRaw, "cookie-from-raw", "", "", "Load cookie from burp raw http request\n * Example: --cookie-from-raw request.txt")
Expand Down Expand Up @@ -118,6 +119,7 @@ func initConfig() {
ProxyAddress: proxy,
Grep: grep,
IgnoreReturn: ignoreReturn,
IgnoreParams: ignoreParams,
Timeout: timeout,
Concurrence: concurrence,
Delay: delay,
Expand Down
6 changes: 6 additions & 0 deletions lib/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Initialize(target Target, options Options) model.Options {
ProxyAddress: "",
Grep: "",
IgnoreReturn: "",
IgnoreParams: []string{},
Timeout: 10,
TriggerMethod: "GET",
Concurrence: 100,
Expand Down Expand Up @@ -103,6 +104,11 @@ func Initialize(target Target, options Options) model.Options {
if options.IgnoreReturn != "" {
newOptions.IgnoreReturn = options.IgnoreReturn
}
if len(options.IgnoreParams) > 0 {
for _, v := range options.IgnoreParams {
newOptions.IgnoreParams = append(newOptions.IgnoreParams, v)
}
}
if options.Trigger != "" {
newOptions.Trigger = options.Trigger
}
Expand Down
2 changes: 2 additions & 0 deletions lib/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestInitialize(t *testing.T) {
ProxyAddress: "http://127.0.0.1",
Grep: "Test",
IgnoreReturn: "301",
IgnoreParams: []string{"qqq"},
OnlyDiscovery: true,
FollowRedirect: true,
Trigger: "https://google.com",
Expand Down Expand Up @@ -51,6 +52,7 @@ func TestInitialize(t *testing.T) {
assert.NotEqual(t, newOptions.ProxyAddress, "", "they should not bee equal")
assert.NotEqual(t, newOptions.Grep, "", "they should not bee equal")
assert.NotEqual(t, newOptions.IgnoreReturn, "", "they should not bee equal")
assert.NotEqual(t, newOptions.IgnoreParams, []string{""}, "they should not bee equal")
assert.NotEqual(t, newOptions.Trigger, "", "they should not bee equal")
assert.NotEqual(t, newOptions.Timeout, 10, "they should not bee equal")
assert.NotEqual(t, newOptions.Concurrence, 100, "they should not bee equal")
Expand Down
1 change: 1 addition & 0 deletions lib/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Options struct {
ProxyAddress string `json:"proxy"`
Grep string `json:"grep"`
IgnoreReturn string `json:"ignore-return"`
IgnoreParams []string `json:"ignore-params"`
Trigger string `json:"trigger"`
TriggerMethod string `json:"request-method"`
Sequence int `json:"sequence"`
Expand Down
1 change: 1 addition & 0 deletions pkg/model/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Options struct {
ProxyAddress string `json:"proxy"`
Grep string `json:"grep"`
IgnoreReturn string `json:"ignore-return"`
IgnoreParams []string `json:"ignore-params"`
Trigger string `json:"trigger"`
Timeout int `json:"timeout"`
Concurrence int `json:"worker"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/hahwul/dalfox/v2/pkg/model"
)

func CheckUniqParam(options model.Options, k string) bool {
func CheckInspectionParam(options model.Options, k string) bool {
if len(options.UniqParam) > 0 {
for _, selectedParam := range options.UniqParam {
if selectedParam == k {
Expand All @@ -13,5 +13,12 @@ func CheckUniqParam(options model.Options, k string) bool {
}
return false
}
if len(options.IgnoreParams) > 0 {
for _, ignoreParam := range options.IgnoreParams {
if ignoreParam == k {
return false
}
}
}
return true
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hahwul/dalfox/v2/pkg/model"
)

func Test_CheckUniqParam(t *testing.T) {
func Test_CheckInspectionParam(t *testing.T) {
type args struct {
options model.Options
k string
Expand Down Expand Up @@ -66,11 +66,37 @@ func Test_CheckUniqParam(t *testing.T) {
},
want: false,
},
{
name: "test - false",
args: args{
options: model.Options{
IgnoreParams: []string{
"1234",
"cat",
},
},
k: "1234",
},
want: false,
},
{
name: "test - false",
args: args{
options: model.Options{
IgnoreParams: []string{
"1234",
"cat",
},
},
k: "5555",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CheckUniqParam(tt.args.options, tt.args.k); got != tt.want {
t.Errorf("checkUniqParam() = %v, want %v", got, tt.want)
if got := CheckInspectionParam(tt.args.options, tt.args.k); got != tt.want {
t.Errorf("CheckInspectionParam() = %v, want %v", got, tt.want)
}
})
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/scanning/bav.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SSTIAnalysis(target string, options model.Options, rl *rateLimiter) {
}

for bpk := range bpd {
if optimization.CheckUniqParam(options, bpk) {
if optimization.CheckInspectionParam(options, bpk) {
for _, ssti := range getSSTIPayload() {
turl, _ := optimization.MakeRequestQuery(target, bpk, ssti, "toGrepping", "ToAppend", "Nan", options)
reqs <- turl
Expand Down Expand Up @@ -63,7 +63,7 @@ func CRLFAnalysis(target string, options model.Options, rl *rateLimiter) {
}

for bpk := range bpd {
if optimization.CheckUniqParam(options, bpk) {
if optimization.CheckInspectionParam(options, bpk) {
for _, crlfpayload := range getCRLFPayload() {
turl, _ := optimization.MakeRequestQuery(target, bpk, crlfpayload, "toGrepping", "ToAppend", "NaN", options)
reqs <- turl
Expand Down Expand Up @@ -95,7 +95,7 @@ func ESIIAnalysis(target string, options model.Options, rl *rateLimiter) {
}

for bpk := range bpd {
if optimization.CheckUniqParam(options, bpk) {
if optimization.CheckInspectionParam(options, bpk) {
for _, crlfpayload := range getESIIPayload() {
turl, _ := optimization.MakeRequestQuery(target, bpk, crlfpayload, "toGrepping", "ToAppend", "NaN", options)
reqs <- turl
Expand Down Expand Up @@ -129,7 +129,7 @@ func SqliAnalysis(target string, options model.Options, rl *rateLimiter) {
}

for bpk := range bpd {
if optimization.CheckUniqParam(options, bpk) {
if optimization.CheckInspectionParam(options, bpk) {
for _, sqlipayload := range getSQLIPayload() {
turl, _ := optimization.MakeRequestQuery(target, bpk, sqlipayload, "toGrepping", "ToAppend", "NaN", options)
reqs <- turl
Expand Down Expand Up @@ -163,7 +163,7 @@ func OpenRedirectorAnalysis(target string, options model.Options, rl *rateLimite
}

for bpk := range bpd {
if optimization.CheckUniqParam(options, bpk) {
if optimization.CheckInspectionParam(options, bpk) {
for _, openRedirectPayload := range getOpenRedirectPayload() {
turl, _ := optimization.MakeRequestQuery(target, bpk, openRedirectPayload, "toOpenRedirecting", "toReplace", "NaN", options)
reqs <- turl
Expand Down
14 changes: 10 additions & 4 deletions pkg/scanning/parameterAnlaysis.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scanning

import (
"io/ioutil"
"io"
"compress/gzip"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -204,7 +204,7 @@ func ParameterAnalysis(target string, options model.Options, rl *rateLimiter) ma
wgg.Add(1)
go func() {
for k := range paramsQue {
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
printing.DalLog("DEBUG", "Mining URL scan to "+k, options)
tempURL, _ := optimization.MakeRequestQuery(target, k, "DalFox", "PA", "toAppend", "NaN", options)
var code string
Expand Down Expand Up @@ -286,6 +286,12 @@ func ParameterAnalysis(target string, options model.Options, rl *rateLimiter) ma
paramsQue <- v
}
}
} else if len(options.IgnoreParams) > 0 {
for _, ignoreParam := range options.IgnoreParams {
if ignoreParam != v {
paramsQue <- v
}
}
} else {
paramsQue <- v
}
Expand All @@ -302,7 +308,7 @@ func ParameterAnalysis(target string, options model.Options, rl *rateLimiter) ma
go func() {
for k := range paramsDataQue {
printing.DalLog("DEBUG", "Mining FORM scan to "+k, options)
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
tempURL, _ := optimization.MakeRequestQuery(target, k, "DalFox", "PA-FORM", "toAppend", "NaN", options)
var code string
rl.Block(tempURL.Host)
Expand Down
16 changes: 8 additions & 8 deletions pkg/scanning/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
}

for v := range cp {
if optimization.CheckUniqParam(options, v) {
if optimization.CheckInspectionParam(options, v) {
cpArr = append(cpArr, v)
arc := optimization.SetPayloadValue(getCommonPayload(), options)
for _, avv := range arc {
Expand All @@ -321,7 +321,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
}

for v := range cpd {
if optimization.CheckUniqParam(options, v) {
if optimization.CheckInspectionParam(options, v) {
cpdArr = append(cpdArr, v)
arc := optimization.SetPayloadValue(getCommonPayload(), options)
for _, avv := range arc {
Expand All @@ -348,7 +348,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
}
dpayloads := optimization.SetPayloadValue(dlst, options)
for v := range cp {
if optimization.CheckUniqParam(options, v) {
if optimization.CheckInspectionParam(options, v) {
// loop payload list
if len(params[v]) == 0 {
for _, dpayload := range dpayloads {
Expand All @@ -370,7 +370,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
}
}
for v := range cpd {
if optimization.CheckUniqParam(options, v) {
if optimization.CheckInspectionParam(options, v) {
// loop payload list
if len(params[v]) == 0 {
for _, dpayload := range dpayloads {
Expand All @@ -395,7 +395,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error

// Set param base xss
for k, v := range params {
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
vStatus[k] = false
ptype := ""
chars := GetSpecialChar()
Expand Down Expand Up @@ -487,7 +487,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error

// loop parameter list
for k, v := range params {
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
ptype := ""
for _, av := range v {
if strings.Contains(av, "PTYPE:") {
Expand Down Expand Up @@ -533,7 +533,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
for _, customPayload := range payload {
if customPayload != "" {
for k, v := range params {
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
ptype := ""
for _, av := range v {
if strings.Contains(av, "PTYPE:") {
Expand Down Expand Up @@ -568,7 +568,7 @@ func Scan(target string, options model.Options, sid string) (model.Result, error
for _, customPayload := range ff {
if customPayload != "" {
for k, v := range params {
if optimization.CheckUniqParam(options, k) {
if optimization.CheckInspectionParam(options, k) {
ptype := ""
for _, av := range v {
if strings.Contains(av, "PTYPE:") {
Expand Down

0 comments on commit e9d75b5

Please sign in to comment.