Squashed commit of the following:

commit b590de2de14923e4cb35dd19845e12833a4ccbfa
Author: Xavier Stevens <xstevens@users.noreply.github.com>
Date:   Wed Mar 23 08:29:37 2022 -0700

    Updated rand_ip to use variadic args

commit ea883be8c0aa56174a1301252129289334659f3f
Author: Xavier Stevens <xstevens@users.noreply.github.com>
Date:   Tue Mar 22 16:59:19 2022 -0700

    Updated rand_ip function to handle multiple CIDRs
dev
Xavier Stevens 2022-03-23 08:37:05 -07:00
parent 6213454cb3
commit 4a65097194
3 changed files with 46 additions and 32 deletions

View File

@ -39,33 +39,34 @@ requests:
27: {{rand_int()}}
28: {{rand_ip("192.168.0.0/24")}}
29: {{rand_ip("2002:c0a8::/24")}}
30: {{rand_text_alpha(10, "abc")}}
31: {{rand_text_alpha(10, "")}}
32: {{rand_text_alpha(10)}}
33: {{rand_text_alphanumeric(10, "ab12")}}
34: {{rand_text_alphanumeric(10)}}
35: {{rand_text_numeric(10, 123)}}
36: {{rand_text_numeric(10)}}
37: {{regex("H([a-z]+)o", "Hello")}}
38: {{remove_bad_chars("abcd", "bc")}}
39: {{repeat("a", 5)}}
40: {{replace("Hello", "He", "Ha")}}
41: {{replace_regex("He123llo", "(\\d+)", "")}}
42: {{reverse("abc")}}
43: {{sha1("Hello")}}
44: {{sha256("Hello")}}
45: {{to_lower("HELLO")}}
46: {{to_upper("hello")}}
47: {{trim("aaaHelloddd", "ad")}}
48: {{trim_left("aaaHelloddd", "ad")}}
49: {{trim_prefix("aaHelloaa", "aa")}}
50: {{trim_right("aaaHelloddd", "ad")}}
51: {{trim_space(" Hello ")}}
52: {{trim_suffix("aaHelloaa", "aa")}}
53: {{unix_time(10)}}
54: {{url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")}}
55: {{url_encode("https://projectdiscovery.io/test?a=1")}}
56: {{wait_for(1)}}
30: {{rand_ip("192.168.0.0/24","10.0.100.0/24")}}
31: {{rand_text_alpha(10, "abc")}}
32: {{rand_text_alpha(10, "")}}
33: {{rand_text_alpha(10)}}
34: {{rand_text_alphanumeric(10, "ab12")}}
35: {{rand_text_alphanumeric(10)}}
36: {{rand_text_numeric(10, 123)}}
37: {{rand_text_numeric(10)}}
38: {{regex("H([a-z]+)o", "Hello")}}
39: {{remove_bad_chars("abcd", "bc")}}
40: {{repeat("a", 5)}}
41: {{replace("Hello", "He", "Ha")}}
42: {{replace_regex("He123llo", "(\\d+)", "")}}
43: {{reverse("abc")}}
44: {{sha1("Hello")}}
45: {{sha256("Hello")}}
46: {{to_lower("HELLO")}}
47: {{to_upper("hello")}}
48: {{trim("aaaHelloddd", "ad")}}
49: {{trim_left("aaaHelloddd", "ad")}}
50: {{trim_prefix("aaHelloaa", "aa")}}
51: {{trim_right("aaaHelloddd", "ad")}}
52: {{trim_space(" Hello ")}}
53: {{trim_suffix("aaHelloaa", "aa")}}
54: {{unix_time(10)}}
55: {{url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")}}
56: {{url_encode("https://projectdiscovery.io/test?a=1")}}
57: {{wait_for(1)}}
extractors:
- type: regex

View File

@ -401,10 +401,18 @@ func init() {
return rand.Intn(max-min) + min, nil
},
),
"rand_ip": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
cidr := args[0].(string)
return randomip.GetRandomIPWithCidr(cidr)
}),
"rand_ip": makeDslWithOptionalArgsFunction(
"(cidr ...string) string",
func(args ...interface{}) (interface{}, error) {
if len(args) == 0 {
return nil, invalidDslFunctionError
}
var cidrs []string
for _, arg := range args {
cidrs = append(cidrs, arg.(string))
}
return randomip.GetRandomIPWithCidr(cidrs...)
}),
"generate_java_gadget": makeDslFunction(3, func(args ...interface{}) (interface{}, error) {
gadget := args[0].(string)
cmd := args[1].(string)

View File

@ -12,7 +12,12 @@ const (
maxIterations = 255
)
func GetRandomIPWithCidr(cidr string) (net.IP, error) {
func GetRandomIPWithCidr(cidrs ...string) (net.IP, error) {
if len(cidrs) == 0 {
return nil, errors.Errorf("must specify at least one cidr")
}
cidr := cidrs[rand.Intn(len(cidrs))]
if !iputil.IsCIDR(cidr) {
return nil, errors.Errorf("%s is not a valid cidr", cidr)
}