Updated API Documentation (markdown)
parent
8063fab924
commit
db9691b7fb
|
|
@ -267,4 +267,50 @@ This method can be used in the run() coroutine and the manual() method of a plug
|
|||
***
|
||||
|
||||
#### get_global(name, default=None)
|
||||
The `get_global_option` method is an alias for the `get_global_option` method.
|
||||
The `get_global_option` method is an alias for the `get_global_option` method.
|
||||
|
||||
***
|
||||
|
||||
#### add_pattern(pattern, description=None)
|
||||
The `add_pattern` method is used to add a regex pattern to search for in any lines of command output generated by the plugin. An optional `description` argument can be used to specify the message which is output if the pattern matches (if no `description` argument is entered, the full match will be output instead). The `description` string can include special markers which will be replaced by pattern matches when the description is output:
|
||||
|
||||
* The `{match}` marker will be replaced by the entire portion of command output that matches the regex.
|
||||
* The`{match#}` markers, where # is a positive non-zero integer will be replaced by the match group with the same number. Correct usage of these markers requires some knowledge of match groups in regex.
|
||||
|
||||
This method should only be used in the configure() method of a plugin.
|
||||
|
||||
**Example**
|
||||
|
||||
Consider a plugin related to HTTP, where potential command output could contain response headers. It may be useful to match the `Server` header, as this often contains version information about the web server.
|
||||
|
||||
The following code can be used in the configure() method of the plugin:
|
||||
|
||||
```python
|
||||
self.add_pattern('Server: ([^\n]+)', description='HTTP Server Found: {match1}')
|
||||
```
|
||||
|
||||
The pattern `Server: ([^\n]+)` will match lines containing the string "Server: ", followed by any number of characters until a newline is encountered. The parentheses around `[^\n]+` create a match group for that part of the pattern. Since this is the first group, it has a group number of 1.
|
||||
|
||||
The description `HTTP Server Found: {match1}` will output the string "HTTP Server Found: ", followed by only the portion of the match contained within group 1.
|
||||
|
||||
If the pattern matched the following command output:
|
||||
|
||||
```
|
||||
Server: Apache/2.4.41 (Ubuntu)
|
||||
```
|
||||
|
||||
The description output by AutoRecon would be:
|
||||
|
||||
```
|
||||
HTTP Server Found: Apache/2.4.41 (Ubuntu)
|
||||
```
|
||||
|
||||
Note that the "Server: " portion of the pattern is not present, despite being matched, because a group was used. If you want the entire match, you would need to change the description to `HTTP Server Found: {match}`, which would result in the following output by AutoRecon:
|
||||
|
||||
```
|
||||
HTTP Server Found: Server: Apache/2.4.41 (Ubuntu)
|
||||
```
|
||||
|
||||
Regex match groups can be difficult to grasp, but can be very powerful. They are numbered from left to right, including subgroups (groups within a group). I won't attempt to explain this in full detail here, however I will give the following example:
|
||||
|
||||
The pattern `Example: ((foo) (bar)) (baz)` contains 4 match groups. The first matches the entire string "foo bar", the second matches just the string "foo", the third matches just the string "bar", and the fourth matches the string "baz".
|
||||
Loading…
Reference in New Issue