Add sha512 support (#2517)

dev
James Turner 2022-08-31 03:06:02 -04:00 committed by GitHub
parent d517861e43
commit 42a0732d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 59 deletions

View File

@ -30,61 +30,63 @@ requests:
18: {{hex_encode("aa")}}
19: {{hmac("sha1", "test", "scrt")}}
20: {{hmac("sha256", "test", "scrt")}}
21: {{html_escape("<body>test</body>")}}
22: {{html_unescape("&lt;body&gt;test&lt;/body&gt;")}}
23: {{join("_", "hello", "world")}}
24: {{len("Hello")}}
25: {{len(5555)}}
26: {{md5("Hello")}}
27: {{md5(1234)}}
28: {{mmh3("Hello")}}
29: {{print_debug(1+2, "Hello")}}
30: {{rand_base(5, "abc")}}
31: {{rand_base(5, "")}}
32: {{rand_base(5)}}
33: {{rand_char("abc")}}
34: {{rand_char("")}}
35: {{rand_char()}}
36: {{rand_int(1, 10)}}
37: {{rand_int(10)}}
38: {{rand_int()}}
39: {{rand_ip("192.168.0.0/24")}}
40: {{rand_ip("2002:c0a8::/24")}}
41: {{rand_ip("192.168.0.0/24","10.0.100.0/24")}}
42: {{rand_text_alpha(10, "abc")}}
43: {{rand_text_alpha(10, "")}}
44: {{rand_text_alpha(10)}}
45: {{rand_text_alphanumeric(10, "ab12")}}
46: {{rand_text_alphanumeric(10)}}
47: {{rand_text_numeric(10, 123)}}
48: {{rand_text_numeric(10)}}
49: {{regex("H([a-z]+)o", "Hello")}}
50: {{remove_bad_chars("abcd", "bc")}}
51: {{repeat("a", 5)}}
52: {{replace("Hello", "He", "Ha")}}
53: {{replace_regex("He123llo", "(\\d+)", "")}}
54: {{reverse("abc")}}
55: {{sha1("Hello")}}
56: {{sha256("Hello")}}
57: {{to_lower("HELLO")}}
58: {{to_upper("hello")}}
59: {{trim("aaaHelloddd", "ad")}}
60: {{trim_left("aaaHelloddd", "ad")}}
61: {{trim_prefix("aaHelloaa", "aa")}}
62: {{trim_right("aaaHelloddd", "ad")}}
63: {{trim_space(" Hello ")}}
64: {{trim_suffix("aaHelloaa", "aa")}}
65: {{unix_time(10)}}
66: {{url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")}}
67: {{url_encode("https://projectdiscovery.io/test?a=1")}}
68: {{wait_for(1)}}
69: {{zlib("Hello")}}
70: {{zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))}}
71: {{hex_encode(aes_gcm("AES256Key-32Characters1234567890", "exampleplaintext"))}}
72: {{starts_with("Hello", "He")}}
73: {{ends_with("Hello", "lo")}}
74: {{line_starts_with("Hi\nHello", "He")}}
75: {{line_ends_with("Hello\nHi", "lo")}}
21: {{hmac("sha512", "test", "scrt")}}
22: {{html_escape("<body>test</body>")}}
23: {{html_unescape("&lt;body&gt;test&lt;/body&gt;")}}
24: {{join("_", "hello", "world")}}
25: {{len("Hello")}}
26: {{len(5555)}}
27: {{md5("Hello")}}
28: {{md5(1234)}}
29: {{mmh3("Hello")}}
30: {{print_debug(1+2, "Hello")}}
31: {{rand_base(5, "abc")}}
32: {{rand_base(5, "")}}
33: {{rand_base(5)}}
34: {{rand_char("abc")}}
35: {{rand_char("")}}
36: {{rand_char()}}
37: {{rand_int(1, 10)}}
38: {{rand_int(10)}}
39: {{rand_int()}}
40: {{rand_ip("192.168.0.0/24")}}
41: {{rand_ip("2002:c0a8::/24")}}
42: {{rand_ip("192.168.0.0/24","10.0.100.0/24")}}
43: {{rand_text_alpha(10, "abc")}}
44: {{rand_text_alpha(10, "")}}
45: {{rand_text_alpha(10)}}
46: {{rand_text_alphanumeric(10, "ab12")}}
47: {{rand_text_alphanumeric(10)}}
48: {{rand_text_numeric(10, 123)}}
49: {{rand_text_numeric(10)}}
50: {{regex("H([a-z]+)o", "Hello")}}
51: {{remove_bad_chars("abcd", "bc")}}
52: {{repeat("a", 5)}}
53: {{replace("Hello", "He", "Ha")}}
54: {{replace_regex("He123llo", "(\\d+)", "")}}
55: {{reverse("abc")}}
56: {{sha1("Hello")}}
57: {{sha256("Hello")}}
58: {{sha512("Hello")}}
59: {{to_lower("HELLO")}}
60: {{to_upper("hello")}}
61: {{trim("aaaHelloddd", "ad")}}
62: {{trim_left("aaaHelloddd", "ad")}}
63: {{trim_prefix("aaHelloaa", "aa")}}
64: {{trim_right("aaaHelloddd", "ad")}}
65: {{trim_space(" Hello ")}}
66: {{trim_suffix("aaHelloaa", "aa")}}
67: {{unix_time(10)}}
68: {{url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")}}
69: {{url_encode("https://projectdiscovery.io/test?a=1")}}
70: {{wait_for(1)}}
71: {{zlib("Hello")}}
72: {{zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))}}
73: {{hex_encode(aes_gcm("AES256Key-32Characters1234567890", "exampleplaintext"))}}
74: {{starts_with("Hello", "He")}}
75: {{ends_with("Hello", "lo")}}
76: {{line_starts_with("Hi\nHello", "He")}}
77: {{line_ends_with("Hello\nHi", "lo")}}
extractors:
- type: regex

View File

@ -258,7 +258,7 @@ func (h *httpDSLFunctions) Execute(filePath string) error {
}
totalExtracted := strings.Split(submatch[1], ",")
numberOfDslFunctions := 75
numberOfDslFunctions := 77
if len(totalExtracted) != numberOfDslFunctions {
return errors.New("incorrect number of results")
}

View File

@ -11,6 +11,7 @@ import (
crand "crypto/rand"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"fmt"
@ -222,6 +223,8 @@ func init() {
hashFunction = sha1.New
case "sha256", "sha-256":
hashFunction = sha256.New
case "sha512", "sha-512":
hashFunction = sha512.New
default:
return nil, fmt.Errorf("unsupported hash algorithm: '%s'", hashAlgorithm)
}
@ -239,6 +242,9 @@ func init() {
"md5": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
return toHexEncodedHash(md5.New(), types.ToString(args[0]))
}),
"sha512": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
return toHexEncodedHash(sha512.New(), types.ToString(args[0]))
}),
"sha256": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
return toHexEncodedHash(sha256.New(), types.ToString(args[0]))
}),

View File

@ -233,6 +233,7 @@ func TestDslExpressions(t *testing.T) {
`reverse("abc")`: "cba",
`sha1("Hello")`: "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0",
`sha256("Hello")`: "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969",
`sha512("Hello")`: "3615f80c9d293ed7402687f94b22d58e529b8cc7916f8fac7fddf7fbd5af4cf777d3d795a7a00a16bf7e7f3fb9561ee9baae480da9fe7a18769e71886b03f315",
`to_lower("HELLO")`: "hello",
`to_upper("hello")`: "HELLO",
`trim("aaaHelloddd", "ad")`: "Hello",
@ -269,6 +270,7 @@ func TestDslExpressions(t *testing.T) {
`compare_versions('v1.0.0', '>v0.0.1', '<v1.0.1')`: true,
`hmac('sha1', 'test', 'scrt')`: "8856b111056d946d5c6c92a21b43c233596623c6",
`hmac('sha256', 'test', 'scrt')`: "1f1bff5574f18426eb376d6dd5368a754e67a798aa2074644d5e3fd4c90c7a92",
`hmac('sha512', 'test', 'scrt')`: "1d3fff1dbb7369c1615ffb494813146bea051ce07e5d44bdeca539653ea97656bf9d38db264cddbe6a83ea15139c8f861a7e73e10e43ad4865e852a9ee6de2e9",
`substr('xxtestxxx',2)`: "testxxx",
`substr('xxtestxxx',2,-2)`: "testx",
`substr('xxtestxxx',2,6)`: "test",