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
Savoir si un processus est enregistré en tant que service (Win9x/Me) [ par luluthefirst ]
Salut, voilà je voudrais savoir comment faire pour savoir si un processus est enregistré en tant que service sous Win9x/Me, RegisterServiceProcess ne
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|