Skip to content

Commit 7ca6edb

Browse files
Merge branch 'dev'
2 parents 21b7221 + c10be77 commit 7ca6edb

19 files changed

+370
-325
lines changed

.github/workflows/pylint.yml .github/workflows/lint.yml

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
run: |
1919
python -m pip install --upgrade pip
2020
pip install pylint
21+
pip install flake8
22+
pip install mypy
2123
- name: Analysing the code with pylint
2224
run: |
2325
pylint $(git ls-files 'raider/*.py')
26+
- name: Analysing the code with flake8
27+
run: |
28+
flake8 'raider/'

.github/workflows/python-publish.yml

-39
This file was deleted.

.github/workflows/sphinx.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "Sphinx docs build check"
2+
on:
3+
[push]
4+
5+
jobs:
6+
docs:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: ammaraskar/sphinx-action@master
11+
with:
12+
docs-folder: "docs/"

.pre-commit-config.yaml

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@
33
exclude: ^docs/|^scripts/
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.0.1
6+
rev: v4.3.0
77
hooks:
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
1010
- id: check-yaml
1111
- repo: https://github.com/psf/black
12-
rev: 21.9b0
12+
rev: 22.6.0
1313
hooks:
1414
- id: black
1515
- repo: https://github.com/PyCQA/isort
16-
rev: 5.9.3
16+
rev: 5.10.1
1717
hooks:
1818
- id: isort
19-
- repo: https://github.com/PyCQA/flake8
20-
rev: 3.9.2
21-
hooks:
22-
- id: flake8
23-
- repo: https://github.com/pre-commit/mirrors-mypy
24-
rev: v0.910
25-
hooks:
26-
- id: mypy

docs/dev/flows.rst

+88-23
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,42 @@ object containing the definition of the request. This definition can
1111
contain :class:`Plugins <raider.plugins.Plugin>` whose value will be
1212
used when sending the HTTP request.
1313

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+
1423
.. automodule:: raider.flow
1524
:members:
1625

1726

1827
Examples
1928
--------
2029

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``.
2533

2634
.. code-block:: hylang
2735
2836
(setv initialization
29-
(Flow
30-
:name "initialization"
37+
(AuthFlow
3138
:request (Request
3239
:method "GET"
33-
:path "admin/")
40+
:url "https://example.com/admin/")
3441
:operations [(Http
3542
:status 200
3643
:action (NextStage "login"))]))
3744
3845
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
4350
``login successfully``, otherwise quit with the error message ``login
4451
error``.
4552

@@ -50,8 +57,7 @@ error``.
5057
(setv session_id (Cookie "PHPSESSID"))
5158
5259
(setv login
53-
(Flow
54-
:name "login"
60+
(AuthFlow
5561
:request (Request
5662
:method "POST"
5763
:url "https://www.example.com/admin/login"
@@ -78,12 +84,39 @@ authentication (MFA)>` was enabled and the ``multi_factor`` :term:`stage`
7884
needs to run next. Otherwise, try to log in again. Here the password
7985
is asked from the user by a :class:`Prompt <raider.plugins.Prompt>`.
8086

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+
8191
.. code-block:: hylang
8292
93+
;; Gets `username` from active user's object defined in `users`.
8394
(setv username (Variable "username"))
95+
96+
;; Gets the password by manual input.
8497
(setv password (Prompt "password"))
98+
99+
;; Gets `PHPSESSID` from the cookie.
85100
(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.
87120
(setv csrf_name
88121
(Html
89122
:name "csrf_name"
@@ -93,7 +126,11 @@ is asked from the user by a :class:`Prompt <raider.plugins.Prompt>`.
93126
:value "^[0-9A-Fa-f]{64}$"
94127
:type "hidden"}
95128
: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.
97134
(setv csrf_value
98135
(Html
99136
:name "csrf_value"
@@ -104,24 +141,52 @@ is asked from the user by a :class:`Prompt <raider.plugins.Prompt>`.
104141
:type "hidden"}
105142
:extract "value"))
106143
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.
108149
(setv login
109-
(Flow
110-
:name "login"
150+
(AuthFlow
111151
:request (Request
112152
:method "POST"
113-
:path "/login.php"
153+
:url "https://example.com/login.php"
114154
:cookies [session_id]
115155
:data
116-
{"open" "login"
117-
"action" "customerlogin"
118-
"password" password
156+
{"password" password
119157
"username" username
120-
"redirect" "myaccount"
121158
csrf_name csrf_value})
122159
:outputs [csrf_name csrf_value]
123160
:operations [(Http
124161
:status 200
125162
:action (NextStage "multi_factor")
126163
: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)]))
127192

docs/dev/plugins.rst

+13-24
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ Basic
4545
Variable
4646
++++++++
4747

48-
Use this when the value of the plugin should be extracted from the
49-
user data. At the moment only ``username`` and ``password`` are
50-
working. Future versions will allow adding and accessing arbitrary
51-
data from the users.
48+
The Variable plugin extracts the value of a variable.
49+
50+
.. autoclass:: Variable
5251

5352
Example:
5453

@@ -64,8 +63,7 @@ Example:
6463
Prompt
6564
++++++
6665

67-
Prompt plugin should be used when the information is not known in
68-
advance, for example when receiving the SMS code.
66+
The prompt plugin accepts user input mid-flow.
6967

7068
Example:
7169

@@ -81,7 +79,7 @@ Example:
8179
Cookie
8280
++++++
8381

84-
Use Cookie plugin to extract and set new cookies:
82+
The cookie plugin extracts and sets new cookies.
8583

8684
Example:
8785

@@ -98,9 +96,7 @@ Example:
9896
Header
9997
++++++
10098

101-
Use Header plugin to extract and set new headers. It also allows
102-
easier setup for basic and bearer authentication using the provided
103-
classmethods.
99+
The Header plugin extracts and sets new headers.
104100

105101
Example:
106102

@@ -122,12 +118,11 @@ Example:
122118
.. autoclass:: Header
123119
:members:
124120

125-
126-
127121
File
128122
++++
129123

130-
TODO
124+
The File plugin sets the plugin's value to the contents of a provided file
125+
and allows string substitution within the content.
131126

132127
Example:
133128

@@ -140,8 +135,7 @@ Example:
140135
Command
141136
+++++++
142137

143-
Use Command plugin if you want to extract information using a shell
144-
command.
138+
The Command plugin runs shell commands and extracts their output.
145139

146140
Example:
147141

@@ -160,9 +154,7 @@ Example:
160154
Regex
161155
+++++
162156

163-
Use Regex plugin if the data you want extracted can be easily
164-
identified with a regular expression. The string matched in between
165-
``(`` and ``)`` will be stored as the plugin's value.
157+
The Regex plugin extracts a matched expression from a provided string.
166158

167159
Example:
168160

@@ -183,12 +175,7 @@ Example:
183175
Html
184176
++++
185177

186-
Use the Html plugin when the data you want can be easily extracted by
187-
parsing HTML tags. Create a new plugin by giving it a name, the tag
188-
where the information is located, some attributes to identify whether
189-
the tag is the right one, and the name of the tag attribute you want
190-
to extract. The attributes are created as a dictionary, and its values
191-
can be regular expressions.
178+
The Html plugin extracts tags matching attributes specified by the user.
192179

193180
Example:
194181

@@ -213,6 +200,8 @@ Example:
213200
Json
214201
++++
215202

203+
The Json plugin extracts fields from JSON tables.
204+
216205
.. autoclass:: Json
217206
:members:
218207

0 commit comments

Comments
 (0)