-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.sh
45 lines (34 loc) · 1.57 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash -x
# Export environment variables to a file for persistence
export > ~/.bashrc
start_webshell() {
ROOT_PATH="$1"
PORT="$2"
COMMAND="$3"
# Butterfly seems to be buggy when passing quotes and stuff to --cmd, so the best way to bypass this issue
# is to write the command in a temporary shell script and execute it with bash.
CMD_FILE=$(mktemp)
echo "$3" > "$CMD_FILE"
# The security flag is required to allow exposing butterfly without password and SSL (which you should handle with a reverse-proxy)
butterfly.server.py \
--cmd="bash -il $CMD_FILE" \
--uri-root-path="$ROOT_PATH" \
--host=0.0.0.0 \
--port="$PORT" \
--i-hereby-declare-i-dont-want-any-security-whatsoever &
}
# Start postgres shell (args in env)
start_webshell postgres 8881 psql
# Start mysql shell (args in env)
start_webshell mysql 8882 mysql
# Start sqlite shell (-safe forbids escapes like using .shell/.system commands), no other args needed
start_webshell sqlite 8883 'sqlite3 -safe'
# Start oracle shell, sqlplus doesn't seem to use readline for interactive line editing, history etc,
# so we add it ourselves using rlwrap
start_webshell oracle 8884 'rlwrap sqlplus $ORACLE_USER/$ORACLE_PASSWORD@$ORACLE_HOST:$ORACLE_PORT/$ORACLE_PDB'
# Start MSSQL shell, using sqlcmd
start_webshell mssql 8885 'sqlcmd -S $MSSQL_HOST -U SA -P $SA_PASSWORD'
# Start DB2 shell
start_webshell db2 8886 'rlwrap jsqsh -d db2 -P $DB2_PASSWORD -D $DB2_DATABASE -U $DB2_USER -S $DB2_HOST -A'
# Webshells run in background, only exit if all of them have died.
wait