You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WShell can run input and output scripts which are simple functions used to manipulate input command and output response.
119
-
As an example, if the vulnerable page returns a base64-encoded result you can use `--output-scriptsbase64_decode` to get
140
+
As an example, if the vulnerable page returns a base64-encoded result you can use `--output-scripts=base64_decode` to get
120
141
the output as plain text.
121
142
122
-
Scripts can be chained and used more than once, for instance is totally fine to do something like `--output-scriptsunescape,base64_decode,base64_decode`.
143
+
Scripts can be chained and used more than once, for instance is totally fine to do something like `--output-scripts=unescape,base64_decode,base64_decode`.
123
144
124
145
### Developing a script
125
146
126
147
Developing a script for WShell is straightforward, just add a python file in `wshell/scripts/input` or `wshell/scripts/output` folder. The file name will
127
-
be the name used to invoke the script from the command line (e.g. if you create `wshell/scripts/output/test.py` you can invoke it with `--output-scriptstest`).
148
+
be the name used to invoke the script from the command line (e.g. if you create `wshell/scripts/output/test.py` you can invoke it with `--output-scripts=test`).
128
149
129
150
Inside the file you have to create a function with the following signature `run(str) -> str`. A docstring to use as a description for the script is mandatory.
130
151
@@ -133,29 +154,113 @@ As an example, the `base64_decode` output script corresponds to `wshell/scripts/
133
154
```py
134
155
import base64
135
156
136
-
137
157
defrun(output: str) -> str:
138
158
"""Base64 decode output (requires --os to work)"""
Custom commands are special commands that you can run within the WShell prompt. They are not executed on the target system but within WShell itself. These commands are useful for performing actions that are not directly related to the remote shell, such as uploading or downloading files, or managing WShell's state.
165
+
For instance, the built-in `download` command abstracts away the complexity of exfiltrating a file from different operating systems, providing a consistent interface for the user.
166
+
167
+
WShell automatically discovers and registers any custom command placed in a subdirectory of `wshell/commands`.
168
+
You can check all the available custom commands by typing `help -v` in a WShell prompt:
We accept contributions of any kind, including bug fixes, feature requests, and new scripts.
197
+
options:
198
+
-h, --help show this help message and exit
199
+
-r, --remote FILENAME
200
+
Remote file to download
201
+
-l, --local FILENAME Local file where to store the downloaded file (default: current folder, same name as remote)
202
+
-c, --chunk SIZE Size of the chunk to download in bytes (default: 1024)
203
+
-n, --no-chunk Do not split into chunks
204
+
```
205
+
206
+
### Developing a custom command
207
+
208
+
To create a custom command, you need to create a new Python file with the name of your choice in a subdirectory of `wshell/commands` (e.g., `wshell/commands/system/my_command.py`). The subdirectory (`system`in this case) will be its category.
209
+
210
+
Inside the file, create a class that inherits from `wshell.commands.WShellCommandSet`, then you can follow the cmd2's [Modular Commands documentation](https://cmd2.readthedocs.io/en/stable/features/modular_commands/) for the specification.
211
+
212
+
Basically, you just need to implement a method starting with `do_` for each command you want to add. For example, a `do_phpinfo` method will create a `phpinfo` command.
213
+
214
+
Here is an example of a simple `phpinfo` command that create a PHP file named `info.php` executing `phpinfo()` in the current directory:
215
+
216
+
```python
217
+
# wshell/commands/php/phpinfo.py
218
+
import argparse
219
+
220
+
from cmd2 import with_argparser
221
+
222
+
from wshell.commands import WShellCommandSet
145
223
146
-
If you want to contribute to this project you can just:
147
224
148
-
1. Fork the repository
149
-
2. Start a new branch starting from `dev`
150
-
3. Make your changes
151
-
4. Open a Pull Request
225
+
class PHPInfoCommandSet(WShellCommandSet):
226
+
227
+
argument_parser = argparse.ArgumentParser(description="Create a new file into the current directory that executes `phpinfo()`")
To make this command available in WShell in the `Php` category, you would save it as `wshell/commands/php/phpinfo.py`. Then, from the WShell prompt, you could run it by just typing `phpinfo`.
253
+
254
+
On top of `cmd2`'s modular command features, WShell overrides the `_cmd` object of the commandset to provides access to the current WShell session, including the HTTP client (`self._cmd.injector`), target information, and more. This is useful for creating more complex commands that run commands on the remote system.
255
+
256
+
For more complex examples, see the implementation of the built-in `upload` and `download` commands in the `wshell/commands/file_transfer` directory.
257
+
258
+
## Contributing
152
259
153
-
When you open a Pull Request, please make sure to follow the next rules:
260
+
Have a look through existing [Issues](https://github.com/unlock-security/wshell/issues) and [Pull Requests](https://github.com/unlock-security/wshell/pulls) that you could help with.
261
+
If you'd like to request a feature or report a bug, please [create a GitHub Issue]() using one of the templates provided.
154
262
155
-
- Write a clear and descriptive title
156
-
- In the description, write a clear and detailed explanation of the changes
157
-
- There are no conflicts in merging your branch on `dev`
158
-
- If you are fixing a bug, please reference the issue number
0 commit comments