@@ -11,35 +11,42 @@ object containing the definition of the request. This definition can
11
11
contain :class: `Plugins <raider.plugins.Plugin> ` whose value will be
12
12
used when sending the HTTP request.
13
13
14
+ There are two types of Flow, the regular one using the :class: `Flow
15
+ <raider.flow.Flow> ` class, and the authentication Flows using the
16
+ :class: `AuthFlow <raider.flow.AuthFlow> ` class. Only difference is
17
+ that AuthFlow ones are treated as changing the authentication state
18
+ while the regular ones don't. Use AuthFlow to define the process
19
+ necessary to reach from unauthenticated state to authenticated
20
+ one. Use regular Flows for any other requests you want to test using
21
+ Raider.
22
+
14
23
.. automodule :: raider.flow
15
24
:members:
16
25
17
26
18
27
Examples
19
28
--------
20
29
21
- Create the variable ``initialization `` with the Flow. It'll send a
22
- request to the :ref: `_base_url <var_base_url >` using the path
23
- ``admin/ ``. If the HTTP response code is 200 go to next stage
24
- ``login ``.
30
+ Create the variable ``initialization `` with the AuthFlow. It'll send a
31
+ GET request to ``https://example.com/admin/ ``. If the HTTP response
32
+ code is 200 go to next stage ``login ``.
25
33
26
34
.. code-block :: hylang
27
35
28
36
(setv initialization
29
- (Flow
30
- :name "initialization"
37
+ (AuthFlow
31
38
:request (Request
32
39
:method "GET"
33
- :path " admin/")
40
+ :url "https://example.com/ admin/")
34
41
:operations [(Http
35
42
:status 200
36
43
:action (NextStage "login"))]))
37
44
38
45
39
- Define Flow ``login ``. It will send a POST request to
40
- ``https://www. example.com/admin/login `` with the username and the
41
- password in the body. Extract the cookie ``PHPSESSID `` and store it in
42
- the ``session_id `` plugin. If server responds with HTTP 200 OK, print
46
+ Define AuthFlow ``login ``. It will send a POST request to
47
+ ``https://example.com/admin/login `` with the username and the password
48
+ in the body. Extract the cookie ``PHPSESSID `` and store it in the
49
+ ``session_id `` plugin. If server responds with HTTP 200 OK, print
43
50
``login successfully ``, otherwise quit with the error message ``login
44
51
error ``.
45
52
@@ -50,8 +57,7 @@ error``.
50
57
(setv session_id (Cookie "PHPSESSID"))
51
58
52
59
(setv login
53
- (Flow
54
- :name "login"
60
+ (AuthFlow
55
61
:request (Request
56
62
:method "POST"
57
63
:url "https://www.example.com/admin/login"
@@ -78,12 +84,39 @@ authentication (MFA)>` was enabled and the ``multi_factor`` :term:`stage`
78
84
needs to run next. Otherwise, try to log in again. Here the password
79
85
is asked from the user by a :class: `Prompt <raider.plugins.Prompt> `.
80
86
87
+ Also define the regular Flow named ``get_nickname `` to extract the
88
+ username of the logged in user. This request doesn't affect the
89
+ authentication state which is why Flow is used instead of AuthFlow.
90
+
81
91
.. code-block :: hylang
82
92
93
+ ;; Gets `username` from active user's object defined in `users`.
83
94
(setv username (Variable "username"))
95
+
96
+ ;; Gets the password by manual input.
84
97
(setv password (Prompt "password"))
98
+
99
+ ;; Gets `PHPSESSID` from the cookie.
85
100
(setv session_id (Cookie "PHPSESSID"))
86
-
101
+
102
+ ;; Gets the OTP code by manual input.
103
+ (setv mfa_code (Prompt "OTP code"))
104
+
105
+ ;; Extract nickname from the HTML code. It looks for a tag like this:
106
+ ;; <input id="nickname" value="admin">
107
+ ;; and returns `admin`.
108
+ (setv nickname
109
+ (Html
110
+ :name "nickname"
111
+ :tag "input"
112
+ :attributes
113
+ {:id "nickname"}
114
+ :extract "value"))
115
+
116
+ ;; Extracts the name of the CSRF token from HTML code. It looks
117
+ ;; for a tag similar to this:
118
+ ;; <input name="0123456789" value="0123456789012345678901234567890123456789012345678901234567890123" type="hidden">
119
+ ;; and returns 0123456789.
87
120
(setv csrf_name
88
121
(Html
89
122
:name "csrf_name"
@@ -93,7 +126,11 @@ is asked from the user by a :class:`Prompt <raider.plugins.Prompt>`.
93
126
:value "^[0-9A-Fa-f]{64}$"
94
127
:type "hidden"}
95
128
:extract "name"))
96
-
129
+
130
+ ;; Extracts the value of the CSRF token from HTML code. It looks
131
+ ;; for a tag similar to this:
132
+ ;; <input name="0123456789" value="0123456789012345678901234567890123456789012345678901234567890123" type="hidden">
133
+ ;; and returns 0123456789012345678901234567890123456789012345678901234567890123.
97
134
(setv csrf_value
98
135
(Html
99
136
:name "csrf_value"
@@ -104,24 +141,52 @@ is asked from the user by a :class:`Prompt <raider.plugins.Prompt>`.
104
141
:type "hidden"}
105
142
:extract "value"))
106
143
107
-
144
+ ;; Defines the `login` AuthFlow. Sends a POST request to
145
+ ;; https://example.com/login.php. Use the username, password
146
+ ;; and both the CSRF name and values in the POST body.
147
+ ;; Extract the new CSRF values, and moves to the next stage
148
+ ;; if HTTP response is 200.
108
149
(setv login
109
- (Flow
110
- :name "login"
150
+ (AuthFlow
111
151
:request (Request
112
152
:method "POST"
113
- :path " /login.php"
153
+ :url "https://example.com /login.php"
114
154
:cookies [session_id]
115
155
:data
116
- {"open" "login"
117
- "action" "customerlogin"
118
- "password" password
156
+ {"password" password
119
157
"username" username
120
- "redirect" "myaccount"
121
158
csrf_name csrf_value})
122
159
:outputs [csrf_name csrf_value]
123
160
:operations [(Http
124
161
:status 200
125
162
:action (NextStage "multi_factor")
126
163
:otherwise (NextStage "login"))]))
164
+
165
+ ;; Defines the `multi_factor` AuthFlow. Sends a POST request to
166
+ ;; https://example.com/login.php. Use the username, password,
167
+ ;; CSRF values, and the MFA code in the POST body.
168
+ (setv multi_factor
169
+ (AuthFlow
170
+ :request (Request
171
+ :method "POST"
172
+ :url "https://example.com/login.php"
173
+ :cookies [session_id]
174
+ :data
175
+ {"password" password
176
+ "username" username
177
+ "otp" mfa_code
178
+ csrf_name csrf_value})
179
+ :outputs [csrf_name csrf_value]))
180
+
181
+ ;; Extracts the nickname and print it. Send a GET request to
182
+ ;; https://example.com/settings.php and extract the nickname
183
+ ;; from the HTML response.
184
+ (setv get_nickname
185
+ (Flow
186
+ :request (Request
187
+ :method "GET"
188
+ :url "https://example.com/settings.php"
189
+ :cookies [session_id])
190
+ :outputs [nickname]
191
+ :operations [(Print nickname)]))
127
192
0 commit comments