Skip to content

Commit

Permalink
Remove redundant information from the documentation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 710909771
Change-Id: I4c879aa824c95f6008c7393626565b217f3ecaef
  • Loading branch information
tooryx authored and copybara-github committed Dec 31, 2024
1 parent 33667d8 commit 67781bd
Showing 1 changed file with 3 additions and 147 deletions.
150 changes: 3 additions & 147 deletions docs/howto/howto.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
# How do I...
# Build and run Tsunami

This page answers common how-to questions that may come up when using Tsunami.

## Content

How do I...

* ... [build and execute the scanner?](#build_n_execute)
* ... [install Tsunami plugins?](#install_plugins)
* ... [create a new Tsunami plugin?](#create_plugins)
* ...
[apply my plugins to certain types of services / software?](#filter_plugins)
* ... [add command line arguments for my plugin?](#command_line)
* ... [add configuration properties for my plugin?](#configuration)

## <a name="build_n_execute"></a>... build and execute the scanner?
## Build and run the scanner

To build the scanner, go to the root path of the project and execute the
following command:
Expand Down Expand Up @@ -53,7 +39,7 @@ NOTE: Currently Tsunami only supports loading plugins from its `classpath`. We
are adding new features to allow users specifying plugin installation folders in
the config file of Tsunami.

## <a name="install_plugins"></a>... install Tsunami plugins?
## Install Tsunami plugins

As mentioned above, Tsunami plugins must be installed into a folder that can be
recognized by Tsunami at runtime. This directory can be any arbitrary folder as
Expand All @@ -73,133 +59,3 @@ wordpress-installation.jar exposed-jupyter-notebook.jar

NOTE: We are adding new features to allow users specifying plugin installation
folders in the config file of Tsunami.

## <a name="create_plugins"></a>... create a new Tsunami plugin?

Follow examples from the
[tsunami-security-scanner-plugins](https://github.com/google/tsunami-security-scanner-plugins)
repo.

## <a name="filter_plugins"></a>... apply my plugins to certain types of services / software?

Tsunami supports several filtering annotations that can be applied to a plugin.
When used, plugins will only be selected for execution when the filtering
criteria is satisfied.

In the following example, a `ForServiceName` annotation is applied to the
`WebFingerprinter` plugin. `ForServiceName` annotation compares the
`service_name` field of the `NetworkService` protobuf with its target values.
The annotated plugin will only be selected for execution when there is a match.
Here the `WebFingerprinter` plugin will run when the scan target exposes either
a `http` or a `https` service.

```java
// ...
@ForServiceName(["http", "https"])
public final class WebFingerprinter implements ServiceFingerprinter {
// ...
}
```

## <a name="command_line"></a>... add command line arguments for my plugin?

Tsunami uses [jCommander](https://jcommander.org/) for command line argument
parsing. In order to add new command line arguments for your plugin, first
define the data class for holding all the arguments. You can follow the
[jCommander](https://jcommander.org/) tutorial to learn more about the utility.

```java
@Parameters(separators = "=")
public class MyPluginArgs implements CliOption {
@Parameter(names = "--param", description = "Description for param.")
private String param;

@Override
public void validate() {
// Validate the command line value.
}
}
```

Then inject an instance of this data class into your plugin's constructor like
so:

```java
// ...
public final class MyPlugin implements VulnDetector {
private final MyPluginArgs args;
@Inject
MyPlugin(MyPluginArgs args) {
this.args = checkNotNull(args);
}
// ...
}
```

The scanner will automatically parse the command line arguments passed to the
binary, create an instance of the data class from parsed values, and inject the
instance into your plugin.

## <a name="configuration"></a>... add configuration properties for my plugin?

Similar to command line argument, you could add configuration properties for
your plugins and tweak configurations using a config file. Currently Tsunami
supports loading configs from a YAML file.

Tsunami uses
[snakeyaml](https://bitbucket.org/asomov/snakeyaml/wiki/Documentation) to parse
the YAML config file. In order to add configuration properties to your plugin,
first you need to define a data class for holding all the configuration values.
Currently Tsunami only supports standard Java data types for configuration like
strings, numbers (`int`, `long`, `float`, `double`, etc), lists and maps of
standard Java data types.

```java
// All config classes must be annotated by this ConfigProperties annotation in
// order for Tsunami to recognize the config class.
@ConfigProperties(prefix = "my.plugin.configs")
public class MyPluginConfigs {
String stringValue;
long longValue;
List<String> listValues;
Map<String, String> mapValues;
}
```

Then similar to the command line arguments, you can inject an instance of this
data class into your plugin's constructor like so:

```java
// ...
public final class MyPlugin implements VulnDetector {
private final MyPluginConfigs configs;
@Inject
MyPlugin(MyPluginConfigs configs) {
this.configs = checkNotNull(configs);
}
// ...
}
```

The scanner will parse the configuration file when it starts, create an instance
of the data class from the config data, and inject the instance into your
plugin.

Following is an example config file for the previously defined `MyPluginConfigs`
object.

```yaml
# tsunami.yaml file
my:
plugin:
configs:
stringValue: "example value"
long_value: 123
list_values:
- "a"
- "b"
- "c"
mapValues:
key1: "value1"
key2: "value2"
```

0 comments on commit 67781bd

Please sign in to comment.