Blog Alphorm Logo de blog informatique spécialisé en technologie et solutions IT
  • Développement
  • 3D et Animation
  • Cybersécurité
  • Infrastructure
  • Virtualisation
  • Réseaux
  • Bureautique
  • BDD
En cours de lecture : Powershell: Cacher l’exécution d’un script powershell
Agrandisseur de policeAa
Blog AlphormBlog Alphorm
  • Développement
  • 3D et Animation
  • Cybersécurité
  • Infrastructure
  • Virtualisation
  • Réseaux
  • Bureautique
  • BDD
Search
  • Développement
  • 3D et Animation
  • Cybersécurité
  • Infrastructure
  • Virtualisation
  • Réseaux
  • Bureautique
  • BDD
Suivez-nous
© Alphorm 2024 - Tous droits réservés
CybersécuritéDéveloppement

Powershell: Cacher l’exécution d’un script powershell

Ludovic QUENEC'HDU Par Ludovic QUENEC'HDU 18 janvier 2025
Partager
4e lecture en min
Partager

Si vous voulez cacher l’exécution d’un script powershell ou même d’un programme, voici une méthode simple. Pour cela on va passer par un script vbs. En effet l’interpréteur wscript, n’affiche pas de fenêtre d’exécution par défaut, contrairement à l’interpréteur cscript ou powershell. L’intérêt c’est que l’utilisateur ne voit pas l’exécution d’un script ou processus quel qu’il soit. Cela peut être utile pour cache un script de démarrage, une tache planifiée, une publication CITRIX ou RDS.

Pour nos tests on va utiliser un script en powershell pour afficher une fenêtre toute simple :

add-type -assemblyName "Microsoft.VisualBasic"
[Microsoft.VisualBasic.Interaction]::MsgBox("info")

Voici ce qu’on veut cacher l’interpréteur powershell avec son fond bleu disgracieux :

hide-powershell1-4

Ensuite nous allons utiliser la méthode Run :

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

C’est le paramètre intWindowStyle qui va nous intéresser ici, voici les différents paramètres possibles :

C’est le paramètre intWindowStyle qui va nous intéresser ici, voici les différents paramètres possibles :

intWindowStyleDescription
0Hides the window and activates another window.
1Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2Activates the window and displays it as a minimized window.
3Activates the window and displays it as a maximized window.
4Displays a window in its most recent size and position. The active window remains active.
5Activates the window and displays it in its current size and position.
6Minimizes the specified window and activates the next top-level window in the Z order.
7Displays the window as a minimized window. The active window remains active.
8Displays the window in its current state. The active window remains active.
9Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10Sets the show-state based on the state of the program that started the application.

Extrait de la documentation msdn https://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx

Le paramètre 0 c’est celui qu’on utilisera pour cacher notre fenêtre d’exécution. Voici le script en Vbs:

Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "[process]" , 0
Set objShell = Nothing

à la ligne :

objShell.run "[process]" , 0

il suffit juste de remplacer [ process] par le processus à cacher:

Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "powershell.exe e:\script\info.ps1" , 0
Set objShell = Nothing

 

Donc si on utilise l’interpréteur cscript voici le résultat :

hide-powershell2-4

Bon j’ai un peu triché car normalement le cscript s’affiche rapidement et on n’a pas forcément le temps de le voir.

Maintenant nous allons passer le wscript est là c’est magique :

wscript E:\script\hide.vbs

hide-powershell3-4

Et cela fonctionne tout type de processus exemple ici avec wordpad :

hide-powershell4-4

 

 

ÉTIQUETÉ : PowerShell
Facebook
Twitter
LinkedIn
Email
WhatsApp
Par Ludovic QUENEC'HDU
Expert en Virtualisation et Sécurité Informatique au Service de Grands Comptes et du Logiciel Libre
Ludovic QUENECHDU est un véritable virtuose de la virtualisation et de la sécurité informatique. Depuis son indépendance professionnelle en 2000, il a apporté son expertise à de prestigieux clients tels que Cameroun Telecom, Merryl Lynch, Ernst & Young, AXA, et bien d'autres. En parallèle, Ludovic s'engage régulièrement dans le démarrage de petites entreprises, notamment dans le domaine du logiciel libre, une passion qu'il chérit pour ses valeurs de partage et d'échange. Son parcours professionnel et sa passion pour la technologie en font un acteur incontournable de l'industrie informatique.

Derniers Articles

  • Techniques pour gérer les fichiers texte en C#
  • Créer et lire un fichier CSV avec C#
  • JSON : Comprendre et Utiliser Efficacement
  • Créer une Base SQLite dans C#
  • Lecture des données SQLite simplifiée
Laisser un commentaire Laisser un commentaire

Laisser un commentaire Annuler la réponse

Vous devez vous connecter pour publier un commentaire.

Blog Alphorm
  • Développement
  • 3D et Animation
  • Cybersécurité
  • Infrastructure
  • Virtualisation
  • Réseaux
  • Bureautique
  • BDD
En cours de lecture : Powershell: Cacher l’exécution d’un script powershell

© Alphorm - Tous droits réservés