1 | 1 | | |
2 | | - | import traceback |
3 | | - | import asyncio |
4 | | - | import typing |
| 2 | + | import io |
5 | 3 | | import copy |
6 | | - | import platform |
| 4 | + | import typing |
| 5 | + | import asyncio |
| 6 | + | import traceback |
7 | 7 | | from typing import cast |
8 | 8 | | from collections import OrderedDict |
9 | 9 | | |
10 | 10 | | import asn1tools |
11 | 11 | | from PIL import Image |
12 | 12 | | from aardwolf import logger |
13 | | - | from aardwolf.commons.queuedata.constants import MOUSEBUTTON, VIDEO_FORMAT |
14 | 13 | | from aardwolf.keyboard import VK_MODIFIERS |
| 14 | + | from aardwolf.commons.queuedata.constants import MOUSEBUTTON, VIDEO_FORMAT |
15 | 15 | | from aardwolf.commons.target import RDPTarget |
16 | | - | from aardwolf.network.selector import NetworkSelector |
17 | 16 | | from aardwolf.commons.credential import RDPCredential, RDPCredentialsSecretType |
18 | 17 | | from aardwolf.commons.cryptolayer import RDPCryptoLayer |
19 | 18 | | from aardwolf.network.tpkt import TPKTNetwork |
20 | 19 | | from aardwolf.network.x224 import X224Network |
| 20 | + | from aardwolf.network.selector import NetworkSelector |
21 | 21 | | |
22 | 22 | | from aardwolf.protocol.x224.constants import SUPP_PROTOCOLS, NEG_FLAGS |
23 | 23 | | from aardwolf.protocol.x224.server.connectionconfirm import RDP_NEG_RSP |
24 | 24 | | |
| 25 | + | from aardwolf.protocol.pdu.input.keyboard import TS_UNICODE_KEYBOARD_EVENT, TS_KEYBOARD_EVENT, KBDFLAGS |
| 26 | + | from aardwolf.protocol.pdu.input.mouse import PTRFLAGS, TS_POINTER_EVENT |
| 27 | + | from aardwolf.protocol.pdu.capabilities import CAPSTYPE |
| 28 | + | from aardwolf.protocol.pdu.capabilities.general import TS_GENERAL_CAPABILITYSET, OSMAJORTYPE, OSMINORTYPE, EXTRAFLAG |
| 29 | + | from aardwolf.protocol.pdu.capabilities.bitmap import TS_BITMAP_CAPABILITYSET |
| 30 | + | from aardwolf.protocol.pdu.capabilities.sound import TS_SOUND_CAPABILITYSET |
| 31 | + | from aardwolf.protocol.pdu.capabilities.virtualchannel import TS_VIRTUALCHANNEL_CAPABILITYSET, VCCAPS |
| 32 | + | from aardwolf.protocol.pdu.capabilities.offscreen import TS_OFFSCREEN_CAPABILITYSET |
| 33 | + | from aardwolf.protocol.pdu.capabilities.glyph import TS_GLYPHCACHE_CAPABILITYSET |
| 34 | + | from aardwolf.protocol.pdu.capabilities.brush import TS_BRUSH_CAPABILITYSET |
| 35 | + | from aardwolf.protocol.pdu.capabilities.input import TS_INPUT_CAPABILITYSET, INPUT_FLAG |
| 36 | + | from aardwolf.protocol.pdu.capabilities.pointer import TS_POINTER_CAPABILITYSET |
| 37 | + | from aardwolf.protocol.pdu.capabilities.bitmapcache import TS_BITMAPCACHE_CAPABILITYSET |
| 38 | + | from aardwolf.protocol.pdu.capabilities.order import TS_ORDER_CAPABILITYSET, ORDERFLAG |
| 39 | + | |
25 | 40 | | from aardwolf.protocol.T124.GCCPDU import GCCPDU |
26 | 41 | | from aardwolf.protocol.T124.userdata import TS_UD, TS_SC |
27 | | - | from aardwolf.protocol.T124.userdata.constants import * |
| 42 | + | from aardwolf.protocol.T124.userdata.constants import TS_UD_TYPE, HIGH_COLOR_DEPTH, ENCRYPTION_FLAG, SUPPORTED_COLOR_DEPTH, \ |
| 43 | + | COLOR_DEPTH, CONNECTION_TYPE, RNS_UD_CS, ClusterInfo |
28 | 44 | | from aardwolf.protocol.T124.userdata.clientcoredata import TS_UD_CS_CORE |
29 | 45 | | from aardwolf.protocol.T124.userdata.clientsecuritydata import TS_UD_CS_SEC |
30 | 46 | | from aardwolf.protocol.T124.userdata.clientnetworkdata import TS_UD_CS_NET, CHANNEL_DEF |
31 | 47 | | from aardwolf.protocol.T124.userdata.clientclusterdata import TS_UD_CS_CLUSTER |
32 | 48 | | from aardwolf.protocol.T128.security import TS_SECURITY_HEADER,SEC_HDR_FLAG, TS_SECURITY_HEADER1 |
33 | | - | from aardwolf.protocol.T125.infopacket import * |
34 | | - | from aardwolf.protocol.T125.extendedinfopacket import * |
| 49 | + | from aardwolf.protocol.T125.infopacket import TS_INFO_PACKET, INFO_FLAG |
| 50 | + | from aardwolf.protocol.T125.extendedinfopacket import TS_EXTENDED_INFO_PACKET, TS_TIME_ZONE_INFORMATION, TS_SYSTEMTIME, CLI_AF |
35 | 51 | | from aardwolf.protocol.T125.MCSPDU_ver_2 import MCSPDU_ver_2 |
36 | | - | from aardwolf.protocol.T125.serverdemandactivepdu import * |
37 | | - | from aardwolf.protocol.T125.clientconfirmactivepdu import * |
38 | | - | from aardwolf.protocol.T125.synchronizepdu import * |
39 | | - | from aardwolf.protocol.T125.controlpdu import * |
40 | | - | from aardwolf.protocol.T125.fontlistpdu import * |
41 | | - | from aardwolf.protocol.T125.inputeventpdu import * |
| 52 | + | from aardwolf.protocol.T128.serverdemandactivepdu import TS_DEMAND_ACTIVE_PDU |
| 53 | + | from aardwolf.protocol.T128.clientconfirmactivepdu import TS_SHARECONTROLHEADER, TS_CONFIRM_ACTIVE_PDU, TS_CAPS_SET |
| 54 | + | from aardwolf.protocol.T128.synchronizepdu import TS_SYNCHRONIZE_PDU |
| 55 | + | from aardwolf.protocol.T128.controlpdu import TS_CONTROL_PDU, CTRLACTION |
| 56 | + | from aardwolf.protocol.T128.fontlistpdu import TS_FONT_LIST_PDU |
| 57 | + | from aardwolf.protocol.T128.inputeventpdu import TS_SHAREDATAHEADER, TS_INPUT_EVENT, TS_INPUT_PDU_DATA |
42 | 58 | | from aardwolf.protocol.T125.securityexchangepdu import TS_SECURITY_PACKET |
43 | | - | from aardwolf.protocol.T125.seterrorinfopdu import TS_SET_ERROR_INFO_PDU |
| 59 | + | from aardwolf.protocol.T128.seterrorinfopdu import TS_SET_ERROR_INFO_PDU |
| 60 | + | from aardwolf.protocol.T128.share import PDUTYPE, STREAM_TYPE, PDUTYPE2 |
44 | 61 | | |
45 | 62 | | |
| 63 | + | |
46 | 64 | | from aardwolf.protocol.fastpath import TS_FP_UPDATE_PDU, FASTPATH_UPDATETYPE, FASTPATH_FRAGMENT, FASTPATH_SEC, TS_FP_UPDATE |
47 | | - | from aardwolf.commons.queuedata import * |
| 65 | + | from aardwolf.commons.queuedata import RDPDATATYPE, RDP_KEYBOARD_SCANCODE, RDP_KEYBOARD_UNICODE, RDP_MOUSE, RDP_VIDEO |
48 | 66 | | from aardwolf.commons.authbuilder import AuthenticatorBuilder |
49 | 67 | | from aardwolf.channels import Channel |
50 | 68 | | from aardwolf.commons.iosettings import RDPIOSettings |
| skipped 1 lines |
52 | 70 | | |
53 | 71 | | class RDPConnection: |
54 | 72 | | def __init__(self, target:RDPTarget, credentials:RDPCredential, iosettings:RDPIOSettings): |
| 73 | + | """RDP client connection object. After successful connection the two asynchronous queues named `ext_out_queue` and `ext_in_queue` |
| 74 | + | can be used to communicate with the remote server |
| 75 | + | |
| 76 | + | Args: |
| 77 | + | target (RDPTarget): Target object specifying the network connection details |
| 78 | + | credentials (RDPCredential): Credential object specifying the authentication details |
| 79 | + | iosettings (RDPIOSettings): Screen/Keyboard/IO settings |
| 80 | + | """ |
55 | 81 | | self.target = target |
56 | 82 | | self.credentials = credentials |
57 | 83 | | self.authapi = None |
| skipped 128 lines |
186 | 212 | | await asyncio.wait_for(self.terminate(), timeout = 5) |
187 | 213 | | |
188 | 214 | | async def connect(self): |
189 | | - | """ |
190 | | - | Performs the entire connection sequence |
| 215 | + | """Initiates the connection to the server, and performs authentication and all necessary setups. |
| 216 | + | Returns: |
| 217 | + | Tuple[bool, Exception]: _description_ |
191 | 218 | | """ |
192 | 219 | | try: |
193 | 220 | | self.__fastpath_in_queue = asyncio.Queue() |
| skipped 504 lines |
698 | 725 | | extinfo.clientDir = 'C:\\WINNT\\System32\\mstscax.dll' |
699 | 726 | | extinfo.clientTimeZone = systz |
700 | 727 | | extinfo.clientSessionId = 0 |
701 | | - | #extinfo.performanceFlags = PERF.DISABLE_WALLPAPER | PERF.DISABLE_THEMING | PERF.DISABLE_CURSORSETTINGS | PERF.DISABLE_MENUANIMATIONS | PERF.DISABLE_FULLWINDOWDRAG |
| 728 | + | if self.iosettings.performance_flags is not None: |
| 729 | + | extinfo.performanceFlags = self.iosettings.performance_flags |
702 | 730 | | |
703 | 731 | | info = TS_INFO_PACKET() |
704 | 732 | | info.CodePage = 0 |
| skipped 620 lines |