|
| 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" |
0 commit comments