Accueil > > > COMMENT DÉMARRER UN PROCESSUS SUR PC DISTANT DE MANIÈRE CACHÉE ET TRANSPARENTE
COMMENT DÉMARRER UN PROCESSUS SUR PC DISTANT DE MANIÈRE CACHÉE ET TRANSPARENTE
Information sur la source
Description
Salut, cette source montre comment démarrer sur un PC distant un processus, sans RIEN AVOIR A FAIRE sur le PC distant (aucune manipulation à faire dessus, pas de server à lancer manuellement, pas de WMI à activer...), de manière cachée. Il suffit de démarrer le programme sur le PC principal et de cliquer sur "Go" pour créer un process sur la machine distante. Comment çà marche ? En gros : - on créé une connection avec la machine distante (WNetAddConnection2) - on copie le fichier "server.exe" sur la machine distante (CopyFile) - on démarre le fichier "server.exe", qui est en fait un service, par OpenScmanager, CreateService et StartService (c'est là toute la subtilité !) - le service démarré, il peut faite n'importe quoi. Bref, ensuite si vous voulez vous transformez le service .Net en service codé en C complètement autonome, et vous avez un programme capable de faire n'importe quoi à distance (un malware pour les plus pessimistes). Créez ensuite un tube nommé pour communiquer avec une archi client-server, et tout est possible, prochainement dans YAPM :-p Ne pas oublier de détruire le service à la sortie du programme ! (j'ai pas viré le fichier *.exe dans l'exemple). Pour info, c'est le fonctionnement de psexec de Sysinternals (en gros). @+
Source
- Option Strict On
-
- Public Class Form1
-
- Private hScm As IntPtr
- Private hServ As IntPtr
- Private path As String = Replace(Application.StartupPath & "\server.exe", "\", "\\")
-
- Private remoteHost As String
- Private pass As String
- Private user As String
- Private Net As New API.NETRESOURCE
-
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
- remoteHost = Me.TextBox1.Text
- pass = Me.TextBox3.Text
- user = Me.TextBox2.Text
-
- ' Create connection to remote computer
- Net.dwType = API.NETRESOURCE.Type.RESOURCETYPE_ANY
- Net.lpProvider = Nothing
- Net.lpLocalName = Nothing
- Net.lpRemoteName = "\\" & remoteHost & "\IPC$"
-
- Dim ret As Integer
- ret = API.WNetAddConnection2(Net, pass, user, API.CONNECT_COMMANDLINE)
-
- If (ret <> 0) AndAlso (user <> Nothing) Then
- If ret = 1219 Then
- ' Connection already created. Disconnecting..
- ret = CancelConnection()
- Else
- If ret = 1326 Then
- If InStr(user, "\"c) = 0 Then
- Dim CurrentUserName As String = "localhost\" & user
- ret = API.WNetAddConnection2(Net, pass, CurrentUserName, API.CONNECT_UPDATE_PROFILE)
- End If
- End If
- End If
- If ret <> 0 Then
- ' Error
- RaiseError(API.GetError)
- End If
- End If
-
-
- ' Share executable service
- Dim remote As String = "\\" & remoteHost & "\ADMIN$\System32"
- Dim ret3 As Boolean = API.CopyFile(path, remote & "\yapmserver.exe", Nothing)
-
- ' Create and install service
- hScm = API.OpenSCManager(remoteHost, vbNullString, CInt(API.SC_MANAGER_ALL_ACCESS))
- hServ = API.CreateService(hScm, "yapm_server", "YAPM server", _
- CInt(API.SERVICE_RIGHTS.SERVICE_ALL_ACCESS), _
- API.SERVICE_WIN32_OWN_PROCESS, _
- API.SERVICE_START_TYPE.DemandStart, _
- API.SERVICE_ERROR_CONTROL.Ignore, _
- remote & "\yapmserver.exe", Nothing, _
- Nothing, Nothing, Nothing, Nothing)
-
- If hServ = IntPtr.Zero Then
- If Err.LastDllError = 1073 Then
- ' Service already exists
- hServ = API.OpenService(hScm, "yapm_server", API.SERVICE_RIGHTS.SERVICE_ALL_ACCESS)
- End If
- End If
-
- Call API.CloseServiceHandle(hScm)
-
- ' Start service !
- API.apiStartService(hServ, Nothing, Nothing)
-
- End Sub
-
- ' Stop and delete service
- Private Sub DeleteService()
-
- ' Stop and delete service
- Dim lpss As API.SERVICE_STATUS
- API.ControlService(hServ, API.SERVICE_CONTROL._STOP, lpss)
-
- Call API.DeleteService(hServ)
- Call API.CloseServiceHandle(hServ)
-
- End Sub
-
- ' Cancel connection
- Private Function CancelConnection() As Integer
-
- Call API.WNetCancelConnection2(remoteHost, Nothing, True)
- Return API.WNetAddConnection2(Net, pass, user, API.CONNECT_UPDATE_PROFILE)
-
- End Function
-
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- Call DeleteService()
- Call CancelConnection()
- End Sub
-
- Private Sub RaiseError(ByVal _error As String)
- Me.rtb.Text = _error
- End Sub
-
- End Class
Option Strict On
Public Class Form1
Private hScm As IntPtr
Private hServ As IntPtr
Private path As String = Replace(Application.StartupPath & "\server.exe", "\", "\\")
Private remoteHost As String
Private pass As String
Private user As String
Private Net As New API.NETRESOURCE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
remoteHost = Me.TextBox1.Text
pass = Me.TextBox3.Text
user = Me.TextBox2.Text
' Create connection to remote computer
Net.dwType = API.NETRESOURCE.Type.RESOURCETYPE_ANY
Net.lpProvider = Nothing
Net.lpLocalName = Nothing
Net.lpRemoteName = "\\" & remoteHost & "\IPC$"
Dim ret As Integer
ret = API.WNetAddConnection2(Net, pass, user, API.CONNECT_COMMANDLINE)
If (ret <> 0) AndAlso (user <> Nothing) Then
If ret = 1219 Then
' Connection already created. Disconnecting..
ret = CancelConnection()
Else
If ret = 1326 Then
If InStr(user, "\"c) = 0 Then
Dim CurrentUserName As String = "localhost\" & user
ret = API.WNetAddConnection2(Net, pass, CurrentUserName, API.CONNECT_UPDATE_PROFILE)
End If
End If
End If
If ret <> 0 Then
' Error
RaiseError(API.GetError)
End If
End If
' Share executable service
Dim remote As String = "\\" & remoteHost & "\ADMIN$\System32"
Dim ret3 As Boolean = API.CopyFile(path, remote & "\yapmserver.exe", Nothing)
' Create and install service
hScm = API.OpenSCManager(remoteHost, vbNullString, CInt(API.SC_MANAGER_ALL_ACCESS))
hServ = API.CreateService(hScm, "yapm_server", "YAPM server", _
CInt(API.SERVICE_RIGHTS.SERVICE_ALL_ACCESS), _
API.SERVICE_WIN32_OWN_PROCESS, _
API.SERVICE_START_TYPE.DemandStart, _
API.SERVICE_ERROR_CONTROL.Ignore, _
remote & "\yapmserver.exe", Nothing, _
Nothing, Nothing, Nothing, Nothing)
If hServ = IntPtr.Zero Then
If Err.LastDllError = 1073 Then
' Service already exists
hServ = API.OpenService(hScm, "yapm_server", API.SERVICE_RIGHTS.SERVICE_ALL_ACCESS)
End If
End If
Call API.CloseServiceHandle(hScm)
' Start service !
API.apiStartService(hServ, Nothing, Nothing)
End Sub
' Stop and delete service
Private Sub DeleteService()
' Stop and delete service
Dim lpss As API.SERVICE_STATUS
API.ControlService(hServ, API.SERVICE_CONTROL._STOP, lpss)
Call API.DeleteService(hServ)
Call API.CloseServiceHandle(hServ)
End Sub
' Cancel connection
Private Function CancelConnection() As Integer
Call API.WNetCancelConnection2(remoteHost, Nothing, True)
Return API.WNetAddConnection2(Net, pass, user, API.CONNECT_UPDATE_PROFILE)
End Function
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call DeleteService()
Call CancelConnection()
End Sub
Private Sub RaiseError(ByVal _error As String)
Me.rtb.Text = _error
End Sub
End Class
Conclusion
Evidemment avec çà on peut faire un malware/virus sans problèmes, mais c'est pas le but...
Il peut y avoir des problèmes, j'ai fait çà à l'arrache !
@+
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Fermer un service proprement [ par florentp ]
Bonjour à tous,Je voudrai savoir comment on fait pour fermer proprement un Service. On fait comme pour un processus "normal" ou y a un autre moyen?En
A propot de Remote Data Service [ par Nino24 ]
Salut tout le monde,J'essaye de me connecter sur une base de donnée sur un serveur IIs, et j'ai toujour ce message d'errServeur Erroret si j'itulise u
Service d'acces distant [ par developpeurvb ]
SltComment savoir si le service d'acces distant est installé sur le poste en cours.Comment procéder ?Merci
Processus en réseau [ par wawamule ]
Coucou tout le monde,Quelq'un peut-il m'expliquer ou me montrer un code qui permet de lancer des processus sur un poste distantDonc j'aimerai pouvoir
Executable dans un service [ par nerone21 ]
Bonjour...Alors j'ai fait un programme que je ne veut pas que l'utilisateur puisse arreter... donc création d'un service dans lequel j'ai mis un timer
tuer un processus qui tourne sur un ordinateur distant [ par azizika ]
j' ai probleme je veux tuer un processus qui tourne sur un ordinateur distant VB 6.0 merci d'avance pour votre aide
démarrer un service en tant que [ par keopsk ]
Bonjour,je voudrais démarrer un service sur un poste distant. Pour cela il faut que la session encours (du le poste client) soit ouverte avec un compt
droit sur service nt [ par PBDLpc ]
bonjour à tous, j'ai développé un service NT qui n'apparait pas dans la liste des applications du gestionnaire de taches de windows xp
service distant en vb.net [ par cubitus91 ]
Bonjour je voudrais récupérer l'état des services sur un pc distant , mais je n arrive pas à me connecté sur l ordi distant c
VBS, accés distant et Droits WMI [ par trafalgar ]
<TABLE id=ctl00_Main_UCContentForum_ctl00_DGMsg style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; BORDER-LEFT: silver 1px solid; WI
|
Derniers Blogs
FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010 par neodante
La nouvelle interface d'Office 2010 à amener quelques modifications par rapport à celle de 2007. Certes mineures, ces modifications ont fait disparaître la case à cocher de l'onglet 'Développeur' en première page du panneau du 'bouton Office' (dans Office...
Cliquez pour lire la suite de l'article par neodante [ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1[ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1 par pierre
Si vous avez téléchargé comme moi Microsoft Forums NNTP Bridge V1 avant le 11 mars 2010 (voir [Astuce] Disponibilité de Microsoft Forum NNTP Bridge Version 1.0), un problème de date localisée pour les non anglais était présent. Un patch est disponibl...
Cliquez pour lire la suite de l'article par pierre PB LORS DE L'INSTALLATION SHAREPOINT 2010.PB LORS DE L'INSTALLATION SHAREPOINT 2010. par Patrick Guimonet
Lors de l'installation de SharePoint 2010, j'ai rencontré un problème de plantage à l'étape 5 du configuration Wizard. Ca se termine sur cet écran : Et en analysant le fichier de journalisation, on remarque vers la fin des 15000 et quelques lign...
Cliquez pour lire la suite de l'article par Patrick Guimonet [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (2/2) par JeremyJeanson
Après mon précédent article qui attaque les contraintes par la fasse Nord de l'Everest. passons à la seconde possibilité offerte par WF4 pour valider une activité : la metadata . Je vous en ai déjà toucher un ou deux mots. La metadata dans WF4 est un élém...
Cliquez pour lire la suite de l'article par JeremyJeanson [WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2)[WF4] AJOUTER DES CONTRAINTES à UNE ACTIVITé (1/2) par JeremyJeanson
De WF3 à WF4 pas mal de choses on été changées pour faciliter la vie des développeurs, mais certain points peuvent sembler obscures. comme les contraintes. Pour vous guider, je me lance dans une série de deux articles. Ils présenterons deux approches poss...
Cliquez pour lire la suite de l'article par JeremyJeanson
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|