File: test_seedbasebuilder.py

package info (click to toggle)
wfuzz 3.1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,648 kB
  • sloc: python: 13,161; makefile: 59; sh: 4
file content (140 lines) | stat: -rw-r--r-- 4,353 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import pytest

from wfuzz.fuzzobjects import FuzzWord, FuzzWordType
from wfuzz.factories.fuzzfactory import SeedBuilderHelper
from wfuzz.ui.console.clparser import CLParser
from wfuzz.factories.fuzzresfactory import resfactory

from wfuzz.helpers.obj_dyn import rgetattr
import wfuzz.api


@pytest.mark.parametrize(
    "full_fuzzreq, expected_result",
    [
        (
            (
                "GET /FUZZ HTTP/1.1\n"
                "Host: www.wfuzz.org\n"
                "Content-Type: application/x-www-form-urlencoded\n"
                "User-Agent: Wfuzz/2.1\n",
                None,
            ),
            [
                {
                    "bl_value": None,
                    "field": None,
                    "full_bl": None,
                    "full_marker": "FUZZ",
                    "index": None,
                    "nonfuzz_marker": "",
                    "word": "FUZZ",
                }
            ],
        ),
        (
            (
                "GET /FUZZ{a_bl_value} HTTP/1.1\n"
                "Host: www.wfuzz.org\n"
                "Content-Type: application/x-www-form-urlencoded\n"
                "User-Agent: Wfuzz/2.1\n",
                None,
            ),
            [
                {
                    "bl_value": "a_bl_value",
                    "field": None,
                    "full_bl": "{a_bl_value}",
                    "full_marker": "FUZZ{a_bl_value}",
                    "index": None,
                    "nonfuzz_marker": "{a_bl_value}",
                    "word": "FUZZ",
                }
            ],
        ),
        (
            (
                "GET /FUZZ[url] HTTP/1.1\n"
                "Host: www.wfuzz.org\n"
                "Content-Type: application/x-www-form-urlencoded\n"
                "User-Agent: Wfuzz/2.1\n",
                None,
            ),
            [
                {
                    "bl_value": None,
                    "field": "url",
                    "full_bl": None,
                    "full_marker": "FUZZ[url]",
                    "index": None,
                    "nonfuzz_marker": "[url]",
                    "word": "FUZZ",
                }
            ],
        ),
        (
            (
                "GET /FUZZ/FUZ2Z[url] HTTP/1.1\n"
                "Host: www.wfuzz.org\n"
                "Content-Type: application/x-www-form-urlencoded\n"
                "User-Agent: Wfuzz/2.1\n",
                None,
            ),
            [
                {
                    "bl_value": None,
                    "field": None,
                    "full_bl": None,
                    "full_marker": "FUZZ",
                    "index": None,
                    "nonfuzz_marker": "",
                    "word": "FUZZ",
                },
                {
                    "bl_value": None,
                    "field": "url",
                    "full_bl": None,
                    "full_marker": "FUZ2Z[url]",
                    "index": "2",
                    "nonfuzz_marker": "[url]",
                    "word": "FUZ2Z",
                },
            ],
        ),
    ],
    indirect=["full_fuzzreq"],
)
def test_get_marker_dict(full_fuzzreq, expected_result):
    assert SeedBuilderHelper().get_marker_dict(full_fuzzreq) == expected_result


@pytest.mark.parametrize(
    "session_string, dictio, expected_field, expected_result",
    [
        (
            "wfuzz http://www.wfuzz.io/FUZZ",
            [FuzzWord("sub1", FuzzWordType.WORD)],
            "url",
            "http://www.wfuzz.io/sub1",
        ),
        (
            "wfuzz --basic FUZZ:FUZ2Z http://www.wfuzz.io/",
            (FuzzWord("sub1", FuzzWordType.WORD), FuzzWord("sub2", FuzzWordType.WORD)),
            "auth.credentials",
            "sub1:sub2",
        ),
        (
            "wfuzz --basic FUZZ:FUZ2Z http://www.wfuzz.io/",
            (FuzzWord("sub1", FuzzWordType.WORD), FuzzWord("sub2", FuzzWordType.WORD)),
            "auth.method",
            "basic",
        ),
    ],
)
def test_replace_markers(session_string, dictio, expected_field, expected_result):
    options = CLParser(session_string.split(" ")).parse_cl()
    options.compile_seeds()

    res = resfactory.create("fuzzres_from_options_and_dict", options, dictio)

    assert rgetattr(res.history, expected_field) == expected_result