Gaining a reverse shell
For Windows
- Go to
Jenkins >> New Item
- Create a new
Freestyle project
- Go to
Build section
and selectExecute Windows batch command
:
- Create in your local machine the
.ps1
reverse shell.- This shell is already in Reverse shells ๐พ
- Initialize the python server for the script to download
- now paste the following command in Jenkins:
- now go to
Build Now
int he build you created
You will receive the shell pretty fast
Switch to a meterpreter
- Generate a Windows meterpreter reverse shell using Msfvenom ๐ธ๏ธ (check the command in the note)
- After creating the payload, download it into the machine with:
- Start Metasploit with
msfconsole -q
- Ensure the handler is set up in Metasploit:
- Execute the reverse shell in the victimโs machine with:
For Linux
Go to Jenkins
>> Manage Jenkins
and click on Script Console
Now execute the following command:
Privilege Escalation with Token Impersonation
Windows uses tokens to ensure that accounts have the right privileges to carry out particular actions. Account tokens are assigned to an account when users log in or are authenticated. This is usually done by LSASS.exe(think of this as an authentication process).
This access token consists of:
- User SIDs(security identifier)
- Group SIDs
- Privileges
Amongst other things. More detailed information can be foundย here.
There are two types of access tokens:
- Primary access tokens: those associated with a user account that are generated on log on
- Impersonation tokens: these allow a particular process(or thread in a process) to gain access to resources using the token of another (user/client) process
For an impersonation token, there are different levels:
- SecurityAnonymous: current user/client cannot impersonate another user/client
- SecurityIdentification: current user/client can get the identity and privileges of a client but cannot impersonate the client
- SecurityImpersonation: current user/clientย can impersonate the clientโs security context on the local system
- SecurityDelegation: current user/client can impersonate the clientโs security context on a remote system
Where the security context is a data structure that contains usersโ relevant security information.
The privileges of an account(which are either given to the account when created or inherited from a group) allow a user to carry out particular actions. Here are the most commonly abused privileges:
- SeImpersonatePrivilege
- SeAssignPrimaryPrivilege
- SeTcbPrivilege
- SeBackupPrivilege
- SeRestorePrivilege
- SeCreateTokenPrivilege
- SeLoadDriverPrivilege
- SeTakeOwnershipPrivilege
- SeDebugPrivilege
Thereโs more readingย here.
- View all the privileges using
whoami /priv
Now, in Metasploit run:
To check which tokens are available, enter:
Impersonate the BUILTIN\Administrators
token with:
Now migrate to a process with correct permissions with:
Now you are System32