Skip to content

Commit d9bc309

Browse files
maoningcopybara-github
authored andcommitted
Create a setup script to run Tsunami with callback server & python plugins.
PiperOrigin-RevId: 635828583 Change-Id: I4598e3e9a2c3d50885be19306f66af9192bb7de9
1 parent be0f223 commit d9bc309

File tree

6 files changed

+162
-4
lines changed

6 files changed

+162
-4
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ To quickly get started with Tsunami scans,
6060
1. Print example Tsunami command for scanning `127.0.0.1` using the previously
6161
generated artifacts.
6262
63+
#### Advanced Configuration with Callback Server and Python Language Server
64+
65+
1. execute the following command:
66+
67+
```
68+
bash -c "$(curl -sfL https://raw.githubusercontent.com/google/tsunami-security-scanner/master/quick_start_advanced.sh)"
69+
```
70+
6371
### Docker install
6472
6573
1. start a vulnerable application that can be identified by Tsunami, e.g. an
@@ -90,7 +98,7 @@ To quickly get started with Tsunami scans,
9098
docker exec -it tsunami bash
9199
```
92100
93-
## Contributing
101+
## Contributing
94102
95103
Read how to [contribute to Tsunami](docs/contributing.md).
96104

plugin_server/py/common/net/http/http_header_fields.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class HttpHeaderFields(enum.Enum):
9393
CROSS_ORIGIN_EMBEDDER_POLICY = "Cross-Origin-Embedder-Policy"
9494
CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY = "Cross-Origin-Embedder-Policy-Report-Only"
9595
CROSS_ORIGIN_OPENER_POLICY = "Cross-Origin-Opener-Policy"
96-
external code
9796
ETAG = "ETag"
9897
EXPIRES = "Expires"
9998
LAST_MODIFIED = "Last-Modified"
@@ -157,7 +156,6 @@ class HttpHeaderFields(enum.Enum):
157156
SEC_CH_PREFERS_COLOR_SCHEME = "Sec-CH-Prefers-Color-Scheme"
158157
ACCEPT_CH = "Accept-CH"
159158
CRITICAL_CH = "Critical-CH"
160-
external code
161159
SEC_CH_UA = "Sec-CH-UA"
162160
SEC_CH_UA_ARCH = "Sec-CH-UA-Arch"
163161
SEC_CH_UA_MODEL = "Sec-CH-UA-Model"

plugin_server/py/plugin/payload/payload_utility.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def get_parsed_payload() -> list[pg.PayloadDefinition]:
2424
be used.
2525
"""
2626
payload_str = Path(_PATH).read_text()
27-
payload_dict = yaml.safe_load(payload_str)
27+
yaml_parser = yaml.YAML(typ='safe', pure=True)
28+
payload_dict = yaml_parser.load(payload_str)
2829
payload_library = json_format.ParseDict(payload_dict, pg.PayloadLibrary())
2930
return _validate_payloads([p for p in payload_library.payloads])
3031

plugin_server/py/requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
absl-py==2.1.0
2+
aenum==3.1.15
3+
certifi==2024.2.2
4+
charset-normalizer==3.3.2
5+
glog==0.3.1
6+
grpcio==1.63.0
7+
grpcio-health-checking==1.63.0
8+
grpcio-reflection==1.63.0
9+
grpcio-tools==1.63.0
10+
idna==3.7
11+
protobuf==5.26.1
12+
python-gflags==3.1.2
13+
requests==2.31.0
14+
ruamel.yaml==0.18.6
15+
ruamel.yaml.clib==0.2.8
16+
six==1.16.0
17+
urllib3==2.2.1

quick_start_advanced.sh

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
18+
WD="${HOME}/tsunami"
19+
REPOS="${WD}/repos"
20+
PLUGINS="${WD}/plugins"
21+
PROTOC="${WD}/protoc"
22+
23+
mkdir -p "${REPOS}"
24+
mkdir -p "${PLUGINS}"
25+
mkdir -p "${PROTOC}"
26+
27+
# Clone repos.
28+
pushd "${REPOS}" >/dev/null
29+
30+
printf "\nFetching source code for Tsunami scanner ...\n"
31+
if [[ ! -d "tsunami-security-scanner" ]] ; then
32+
git clone https://github.com/google/tsunami-security-scanner
33+
else
34+
pushd "tsunami-security-scanner" >/dev/null
35+
git pull origin master
36+
popd >/dev/null
37+
fi
38+
printf "\nFetching source code for Tsunami scanner plugins ...\n"
39+
if [[ ! -d "tsunami-security-scanner-plugins" ]] ; then
40+
git clone https://github.com/google/tsunami-security-scanner-plugins
41+
else
42+
pushd "tsunami-security-scanner-plugins" >/dev/null
43+
git pull origin master
44+
popd >/dev/null
45+
fi
46+
printf "\nFetching source code for Tsunami scanner callback server ...\n"
47+
if [[ ! -d "tsunami-security-scanner-callback-server" ]] ; then
48+
git clone https://github.com/google/tsunami-security-scanner-callback-server
49+
else
50+
pushd "tsunami-security-scanner-callback-server" >/dev/null
51+
git pull origin master
52+
popd >/dev/null
53+
fi
54+
popd >/dev/null
55+
56+
# Build all plugins.
57+
pushd "${REPOS}/tsunami-security-scanner-plugins/google" >/dev/null
58+
printf "\nBuilding all Google plugins ...\n"
59+
./build_all.sh
60+
cp build/plugins/*.jar "${PLUGINS}"
61+
mkdir -p "${REPOS}/tsunami-security-scanner/plugin_server/py/py_plugins"
62+
# Exclude the python example plugin.
63+
find . -type f -name '*.py' -not -iname '*example_py_vuln_detector*' -exec cp '{}' '${REPOS}/tsunami-security-scanner/plugin_server/py/py_plugins/{}' ';'
64+
popd >/dev/null
65+
cd
66+
67+
# Build the callback server.
68+
pushd "${REPOS}/tsunami-security-scanner-callback-server" >/dev/null
69+
printf "\nBuilding Tsunami callback server ...\n"
70+
./gradlew shadowJar
71+
TCS_JAR=$(find "${REPOS}/tsunami-security-scanner-callback-server" -name 'tcs-main-*-cli.jar')
72+
TCS_JAR_FILENAME=$(basename -- "${TCS_JAR}")
73+
cp "${TCS_JAR}" "${WD}"
74+
cp "${REPOS}/tsunami-security-scanner-callback-server/tcs_config.yaml" "${WD}"
75+
popd >/dev/null
76+
cd
77+
78+
# Build the scanner.
79+
pushd "${REPOS}/tsunami-security-scanner" >/dev/null
80+
printf "\nBuilding Tsunami scanner jar file ...\n"
81+
./gradlew shadowJar
82+
JAR=$(find "${REPOS}/tsunami-security-scanner" -name 'tsunami-main-*-cli.jar')
83+
JAR_FILENAME=$(basename -- "${JAR}")
84+
cp "${JAR}" "${WD}"
85+
cp "${REPOS}/tsunami-security-scanner/tsunami_tcs.yaml" "${WD}"
86+
popd >/dev/null
87+
88+
# Install python libs and generate python proto targets.
89+
pushd "${REPOS}/tsunami-security-scanner/plugin_server/py" >/dev/null
90+
# sudo apt install python3.11-venv
91+
python3 -m venv .
92+
source bin/activate
93+
pip install -r requirements.txt
94+
popd >/dev/null
95+
96+
pushd "${REPOS}/tsunami-security-scanner/proto" >/dev/null
97+
PROTO_OUT="${REPOS}/tsunami-security-scanner/plugin_server/py"
98+
for proto in `ls *.proto`; do
99+
python -m grpc_tools.protoc -I. --python_out=${PROTO_OUT}/. --grpc_python_out=${PROTO_OUT}/. "${proto}"
100+
done
101+
popd >/dev/null
102+
103+
pushd "${REPOS}/tsunami-security-scanner-callback-server/proto" >/dev/null
104+
python -m grpc_tools.protoc -I. --python_out=${PROTO_OUT}/. --grpc_python_out=${PROTO_OUT}/. "polling.proto"
105+
popd >/dev/null
106+
107+
printf "\nBuild successful, execute the following command to start the callback server\n"
108+
printf "\ncd ${WD} && \\\\\n"
109+
printf "java -cp \"${TCS_JAR_FILENAME}\" \\\\\n"
110+
printf " com.google.tsunami.callbackserver.main.TcsMain \\\\\n"
111+
printf " --custom-config=tcs_config.yaml \\\\\n"
112+
113+
printf "\nBuild successful, execute the following command to start the pythan language server\n"
114+
printf "\ncd ${REPOS}/tsunami-security-scanner/plugin_server/py && \\\\\n"
115+
printf "\npython3 -m venv . && source bin/activate && \\\\\n"
116+
printf "java -cp \"${TCS_JAR_FILENAME}\" \\\\\n"
117+
printf " com.google.tsunami.callbackserver.main.TcsMain \\\\\n"
118+
printf " --custom-config=tcs_config.yaml \\\\\n"
119+
120+
printf "\nBuild successful, execute the following command to scan 127.0.0.1:\n"
121+
printf "\ncd ${WD} && \\\\\n"
122+
printf "python3 plugin_server.py \\\\\n"
123+
printf " --port=34567 \\\\\n"
124+
printf " --trust_all_ssl_cert=true \\\\\n"
125+
printf " --timeout_seconds=180 \\\\\n"
126+
printf " --callback_address=127.0.0.1 \\\\\n"
127+
printf " --callback_port=8881 \\\\\n"
128+
printf " --polling_uri=http://127.0.0.1:8080 \\\\\n"
129+
printf " --plugin-server-ports=34567 \\\\\n"

tsunami_tcs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
plugin:
2+
callbackserver:
3+
callback_address: "127.0.0.1" # Running callback server locally
4+
callback_port: 8881 # Make sure to match with ones configured in tcs_config.yaml
5+
polling_uri: "http://127.0.0.1:8880"

0 commit comments

Comments
 (0)