Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- USER=kang
- PASSWORD=toor
- HOST=$1
- # LICENSED under the terms of the MPLv2 license.
- # Copyright (c) 2016 Mozilla Corporation
- # kang@mozilla.com
- #
- # What is this abomination you ask?
- # This is an "expect" script for X11/Xorg that calls the official REALVNC client and attempts to authenticate, and reports the results
- # This could be made nicer (the script that is), and of course reverse engineering the protocol for SecurityTypes like ARD (30, 35 in RFB-lango) would be much nicer and more efficient
- # To my knowledge the 30 and 35 SecurityTypes have not been publicly fully reversed (though wireshark has a disector for some of it)
- # However when theres no time, automating the user interface in X11 works fine
- # Take this as an example of how to automate the X11 UI, or, well, if you need, as a VNC password checker.
- # Call it like (after setting the variables in this ugly script):
- # for i in $(cat listofips.txt); do ./thisscript $1; done | tee results.txt
- # grep CONNECTION results.txt
- # that's all folks!
- function debug()
- {
- echo "D: $*"
- }
- function get_win_name()
- {
- local wid name
- wid=$(xdotool getactivewindow)
- name=$(xdotool getwindowname $wid)
- echo $name
- }
- function get_win_handle()
- {
- local wid name
- wid=$(xdotool getactivewindow)
- name=$(xdotool getwindowname $wid)
- [[ "$name" == "$1" ]] && echo $wid
- }
- function wait_for_win()
- {
- local WINNAME TIMEOUT PID t
- t=0
- WINNAME=$1
- TIMEOUT=$2
- while true; do
- n=$(get_win_name)
- [[ "$n" == "$WINNAME" ]] && {
- debug "Window found $WINNAME"
- return 0
- }
- debug "Waiting for $WINNAME... current is $n"
- xdotool sleep 1
- t=$((t+1))
- [[ $t -gt $TIMEOUT ]] && {
- debug "Timed out waiting for window"
- return 1
- }
- done
- }
- function wait_for_win2()
- {
- local WINNAME WINNAME2 TIMEOUT PID t
- t=0
- WINNAME=$1
- WINNAME2=$2
- TIMEOUT=$3
- while true; do
- n=$(get_win_name)
- [[ "$n" == "$WINNAME" ]] && {
- debug "Window found $WINNAME"
- return 0
- }
- [[ "$n" == "$WINNAME2" ]] && {
- debug "Window found $WINNAME2"
- return 0
- }
- debug "Waiting for $WINNAME... current is $n"
- xdotool sleep 1
- t=$((t+1))
- [[ $t -gt $TIMEOUT ]] && {
- debug "Timed out waiting for window"
- return 1
- }
- done
- }
- function wait_for_win_or_death()
- {
- local WINNAME TIMEOUT PID t
- WINNAME=$1
- TIMEOUT=$2
- PID=$3
- t=0
- while true; do
- n=$(get_win_name)
- # Exact name match means we're not connected ;-)
- [[ "$n" == "VNC Viewer" ]] && {
- kill $PID
- return 1
- }
- [[ "$n" == *"$WINNAME"* ]] && {
- echo "+ CONNECTION SUCCESS FOR $HOST $USER $PASSWORD"
- kill $PID
- return 0
- }
- kill -0 $PID || {
- debug "process gone, exiting"
- return 1
- }
- t=$((t+1))
- xdotool sleep 1
- [[ $t -gt $TIMEOUT ]] && {
- debug "Timeout waiting for $WINNAME or death"
- return 1
- }
- done
- }
- vncviewer HideCloseAlert=1 WarnUnencrypted=0 UserName=${USER} ${HOST} &
- PID=$!
- #WID=$(xdotool search --title "VNC Viewer")
- #xdotool windowfocus --sync $WID
- wait_for_win "VNC Viewer - Identity check" 1
- [[ $? -eq 0 ]] && {
- debug "Identity check bypass"
- xdotool key Down
- xdotool sleep 0.1
- xdotool key Return
- }
- wait_for_win2 "VNC Viewer - Authentication" "VNC Viewer - Identity check" 10
- xdotool type "${PASSWORD}"
- xdotool sleep 0.1
- xdotool key Return
- wait_for_win_or_death "VNC Viewer" 5 $PID
- exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement