Learn & practice AWS Hacking:<imgsrc="/.gitbook/assets/arte.png"alt=""data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<imgsrc="/.gitbook/assets/arte.png"alt=""data-size="line">\
Learn & practice GCP Hacking: <imgsrc="/.gitbook/assets/grte.png"alt=""data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<imgsrc="/.gitbook/assets/grte.png"alt=""data-size="line">](https://training.hacktricks.xyz/courses/grte)
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **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 hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
Docker ni **jukwaa la mbele** katika **sekta ya uundaji wa kontena**, likiongoza **uvumbuzi endelevu**. Inarahisisha uundaji na usambazaji wa programu, kuanzia **za jadi hadi za kisasa**, na kuhakikisha **kuwekwa salama** kwao katika mazingira mbalimbali.
* [**containerd**](http://containerd.io): Hii ni **muda wa msingi** kwa ajili ya kontena, ikihusika na **usimamizi wa maisha ya kontena** kwa kina. Hii inajumuisha kushughulikia **uhamishaji na uhifadhi wa picha**, pamoja na kusimamia **utekelezaji, ufuatiliaji, na mtandao** wa kontena. **Maelezo zaidi** kuhusu containerd yanapatikana **hapa**.
* **container-shim** ina jukumu muhimu kama **kiunganishi** katika kushughulikia **kontena zisizo na kichwa**, ikichukua nafasi kutoka **runc** baada ya kontena kuanzishwa.
* [**runc**](http://runc.io): Inajulikana kwa uwezo wake wa **muda wa kontena mwepesi na wa ulimwengu wote**, runc inafanana na **kiwango cha OCI**. Inatumika na containerd ku **anzisha na kusimamia kontena** kulingana na **miongozo ya OCI**, ikiwa imekua kutoka kwa **libcontainer** ya awali.
* [**OCI**](https://www.opencontainers.org) ni muhimu katika kudumisha **viwango vya OCI** kwa muda wa utekelezaji na picha, huku toleo jipya la Docker likiwa **linakidhi viwango vya picha na muda wa utekelezaji wa OCI**.
**Containerd** ilitengenezwa mahsusi kutumikia mahitaji ya majukwaa ya kontena kama **Docker na Kubernetes**, miongoni mwa mengine. Inalenga **kurahisisha utekelezaji wa kontena** katika mifumo mbalimbali ya uendeshaji, ikiwa ni pamoja na Linux, Windows, Solaris, na mengine, kwa kubainisha kazi maalum za mfumo wa uendeshaji na wito wa mfumo. Lengo la Containerd ni kujumuisha tu vipengele muhimu vinavyohitajika na watumiaji wake, ikijitahidi kuondoa vipengele visivyohitajika. Hata hivyo, kufikia lengo hili kikamilifu kunatambuliwa kuwa changamoto.
Uamuzi muhimu wa muundo ni kwamba **Containerd haitunza mtandao**. Mtandao unachukuliwa kuwa kipengele muhimu katika mifumo iliyosambazwa, ikiwa na changamoto kama vile Software Defined Networking (SDN) na ugunduzi wa huduma ambazo zinatofautiana sana kutoka jukwaa moja hadi jingine. Kwa hivyo, Containerd inacha masuala ya mtandao yachukuliwe na majukwaa inayoyasaidia.
Wakati **Docker inatumia Containerd** kuendesha kontena, ni muhimu kutambua kwamba Containerd inasaidia tu sehemu ya kazi za Docker. Kwa hakika, Containerd haina uwezo wa usimamizi wa mtandao ulio katika Docker na haisaidii kuunda makundi ya Docker moja kwa moja. Tofauti hii inaonyesha jukumu lililokusanywa la Containerd kama mazingira ya utekelezaji wa kontena, ikitenga kazi maalum zaidi kwa majukwaa inayounganisha nayo.
**Podman** ni injini ya kontena ya chanzo wazi inayofuata viwango vya [Open Container Initiative (OCI)](https://github.com/opencontainers), iliyotengenezwa na kudumishwa na Red Hat. Inajitofautisha na Docker kwa sifa kadhaa tofauti, hasa **muundo wake usio na daemon** na msaada wa **kontena zisizo na mizizi**, ikiruhusu watumiaji kuendesha kontena bila ruhusa za mizizi.
Podman imeundwa kuwa na ufanisi na API ya Docker, ikiruhusu matumizi ya amri za Docker CLI. Ufanisi huu unapanuka hadi kwenye mfumo wake wa ikolojia, ambao unajumuisha zana kama **Buildah** kwa ajili ya kujenga picha za kontena na **Skopeo** kwa ajili ya operesheni za picha kama vile push, pull, na inspect. Maelezo zaidi kuhusu zana hizi yanaweza kupatikana kwenye [ukurasa wao wa GitHub](https://github.com/containers/buildah/tree/master/docs/containertools).
* **Muundo**: Tofauti na mfano wa mteja-server wa Docker wenye daemon ya nyuma, Podman inafanya kazi bila daemon. Muundo huu unamaanisha kwamba kontena zinaendesha kwa ruhusa za mtumiaji anayezianzisha, kuboresha usalama kwa kuondoa hitaji la ufikiaji wa mizizi.
* **Ushirikiano wa Systemd**: Podman inashirikiana na **systemd** ili kudhibiti kontena, ikiruhusu usimamizi wa kontena kupitia vitengo vya systemd. Hii inatofautiana na matumizi ya Docker ya systemd hasa kwa ajili ya kusimamia mchakato wa daemon wa Docker.
* **Kontena zisizo na mizizi**: Sifa muhimu ya Podman ni uwezo wake wa kuendesha kontena chini ya ruhusa za mtumiaji anayezianzisha. Njia hii inapunguza hatari zinazohusiana na uvunjaji wa kontena kwa kuhakikisha kwamba washambuliaji wanapata tu ruhusa za mtumiaji aliyeathirika, si ufikiaji wa mizizi.
Remote API inafanya kazi kwa default kwenye bandari 2375 wakati imewezeshwa. Huduma kwa default haitahitaji uthibitisho, ikiruhusu mshambuliaji kuanzisha kontena la docker lenye mamlaka. Kwa kutumia Remote API mtu anaweza kuunganisha mwenyeji / (directory ya mzizi) kwenye kontena na kusoma/kandika faili za mazingira ya mwenyeji.
Ikiwa unaweza **kuwasiliana na API ya docker ya mbali kwa kutumia amri ya `docker`** unaweza **kutekeleza** yoyote ya **docker** [**amri zilizozungumziwa hapo awali**](2375-pentesting-docker.md#basic-commands) ili kuingiliana na huduma hiyo.
Wakati mwingine utaona **2376** ikifanya kazi kwa **TLS** endpoint. Sijawahi kuweza kuungana nayo kwa mteja wa docker lakini inawezekana kufanya hivyo kwa curl.
Ikiwa unataka maelezo zaidi kuhusu hili, maelezo zaidi yanapatikana mahali nilipokopa amri hizo: [https://securityboulevard.com/2019/02/abusing-docker-api-socket/](https://securityboulevard.com/2019/02/abusing-docker-api-socket/)
Kwa kutumia hii inawezekana kutoroka kutoka kwenye kontena, unaweza kuendesha kontena dhaifu kwenye mashine ya mbali, kutoroka kutoka kwake, na kuathiri mashine:
Ikiwa uko ndani ya mwenyeji anayetumia docker, unaweza [**kusoma habari hii kujaribu kuinua mamlaka**](../linux-hardening/privilege-escalation/#writable-docker-socket).
* Unaweza kutumia chombo [https://github.com/docker/docker-bench-security](https://github.com/docker/docker-bench-security) kukagua usakinishaji wako wa docker wa sasa.
* Unaweza kutumia chombo [https://github.com/genuinetools/amicontained](https://github.com/genuinetools/amicontained) kuangalia mamlaka ambayo kontena litakuwa nayo linapokimbizwa kwa chaguzi tofauti za usalama. Hii ni muhimu kujua athari za kutumia baadhi ya chaguzi za usalama kuendesha kontena:
* Unaweza kutumia picha ya docker ya [https://github.com/quay/clair](https://github.com/quay/clair) kufanya iweze kukagua picha zako nyingine za docker na kupata udhaifu.
* Unaweza kutumia chombo [https://github.com/buddy-works/dockerfile-linter](https://github.com/buddy-works/dockerfile-linter) ili **kukagua Dockerfile yako** na kupata aina zote za makosa ya usanidi. Kila kosa la usanidi litapewa ID, unaweza kupata hapa [https://github.com/buddy-works/dockerfile-linter/blob/master/Rules.md](https://github.com/buddy-works/dockerfile-linter/blob/master/Rules.md) jinsi ya kuyarekebisha.
* Unaweza kutumia chombo [https://github.com/replicatedhq/dockerfilelint](https://github.com/replicatedhq/dockerfilelint) ili **kukagua Dockerfile yako** na kupata aina zote za makosa ya usanidi.
* Unaweza kutumia chombo [https://github.com/RedCoolBeans/dockerlint](https://github.com/RedCoolBeans/dockerlint) ili **kukagua Dockerfile yako** na kupata aina zote za makosa ya usanidi.
* Unaweza kutumia chombo [https://github.com/hadolint/hadolint](https://github.com/hadolint/hadolint) ili **kukagua Dockerfile yako** na kupata aina zote za makosa ya usanidi.
* Unaweza kutumia chombo [https://github.com/falcosecurity/falco](https://github.com/falcosecurity/falco) kugundua **tabia za kushangaza katika kontena zinazoendesha**.
* Kumbuka katika kipande kinachofuata jinsi **Falco inavyokusanya moduli ya kernel na kuingiza**. Baada ya hapo, inapakua sheria na **kuanza kurekodi shughuli za kushangaza**. Katika kesi hii imegundua kontena 2 zenye mamlaka yaliyanzishwa, 1 kati yao ikiwa na mlima wa nyeti, na baada ya sekunde chache imegundua jinsi shell ilifunguliwa ndani ya moja ya kontena.
mkdir: cannot create directory '/lib/modules/5.0.0-20-generic/kernel/extra': Read-only file system
cp: cannot create regular file '/lib/modules/5.0.0-20-generic/kernel/extra/falco-probe.ko': No such file or directory
depmod...
DKMS: install completed.
* Trying to load a dkms falco-probe, if present
falco-probe found and loaded in dkms
2021-01-04T12:03:20+0000: Falco initialized with configuration file /etc/falco/falco.yaml
2021-01-04T12:03:20+0000: Loading rules from file /etc/falco/falco_rules.yaml:
2021-01-04T12:03:22+0000: Loading rules from file /etc/falco/falco_rules.local.yaml:
2021-01-04T12:03:22+0000: Loading rules from file /etc/falco/k8s_audit_rules.yaml:
2021-01-04T12:03:24+0000: Starting internal webserver, listening on port 8765
2021-01-04T12:03:24.646959000+0000: Notice Privileged container started (user=<NA> command=container:db5dfd1b6a32 laughing_kowalevski (id=db5dfd1b6a32) image=ubuntu:18.04)
2021-01-04T12:03:24.664354000+0000: Notice Container with sensitive mount started (user=<NA> command=container:4822e8378c00 xenodochial_kepler (id=4822e8378c00) image=ubuntu:modified mounts=/:/host::true:rslave)
2021-01-04T12:03:24.664354000+0000: Notice Privileged container started (user=root command=container:4443a8daceb8 focused_brahmagupta (id=4443a8daceb8) image=falco:latest)
2021-01-04T12:04:56.270553320+0000: Notice A shell was spawned in a container with an attached terminal (user=root xenodochial_kepler (id=4822e8378c00) shell=bash parent=runc cmdline=bash terminal=34816 container_id=4822e8378c00 image=ubuntu)
Learn & practice AWS Hacking:<imgsrc="/.gitbook/assets/arte.png"alt=""data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<imgsrc="/.gitbook/assets/arte.png"alt=""data-size="line">\
Learn & practice GCP Hacking: <imgsrc="/.gitbook/assets/grte.png"alt=""data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<imgsrc="/.gitbook/assets/grte.png"alt=""data-size="line">](https://training.hacktricks.xyz/courses/grte)
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **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 hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.