|
| 1 | +""" |
| 2 | +Code is based on slyd0g's pwnVNC |
| 3 | +https://github.com/slyd0g/pwnVNC |
| 4 | +
|
| 5 | +More info here: |
| 6 | +https://grumpy-sec.blogspot.com/2017/02/scanning-entire-internet.html |
| 7 | +""" |
| 8 | +import socket |
| 9 | +import os |
| 10 | + |
| 11 | +from bcolors import bcolors |
| 12 | + |
| 13 | +# takes a screen screenshot of VNC connection. Will only connect when authentication is disabled on VNC |
| 14 | +def getVncScreen(ip_addr, port): |
| 15 | + vnc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 16 | + vnc_socket.settimeout(0.5) |
| 17 | + try: |
| 18 | + # attmept to create TCP handshake and do authentication check using RFB protocol |
| 19 | + vnc_socket.connect((ip_addr, port)) |
| 20 | + RFB_VERSION = vnc_socket.recv(12) |
| 21 | + rfb_version_string = RFB_VERSION.decode('UTF-8') |
| 22 | + if "RFB" not in rfb_version_string: |
| 23 | + print("Unable to capture screenshot") |
| 24 | + return |
| 25 | + |
| 26 | + vnc_socket.send(RFB_VERSION) |
| 27 | + auth_required = vnc_socket.recv(1) |
| 28 | + |
| 29 | + if not auth_required: |
| 30 | + print("Unable to capture screenshot") |
| 31 | + return |
| 32 | + |
| 33 | + # 0x01 received from server signifies that no authentication is required |
| 34 | + if auth_required == b'\x01': |
| 35 | + filename = ip_addr.replace('.', '_') + '_scrot' + '.jpg' |
| 36 | + print(f"Saving VNC snapshot as {filename}") |
| 37 | + vnc_snapshot = f"timeout 10 vncsnapshot -allowblank -port {str(port)} {ip_addr}:0 {filename}" |
| 38 | + print(vnc_snapshot) |
| 39 | + |
| 40 | + # close authentication check socket and then run command. command must be run after or vncsnapshot will end prematurely |
| 41 | + vnc_socket.shutdown(socket.SHUT_WR) |
| 42 | + vnc_socket.close() |
| 43 | + |
| 44 | + os.system(vnc_snapshot) |
| 45 | + return filename |
| 46 | + |
| 47 | + |
| 48 | + except socket.error: |
| 49 | + vnc_socket.close() |
| 50 | + pass |
| 51 | + except socket.timeout: |
| 52 | + vnc_socket.close() |
| 53 | + pass |
0 commit comments