hacktricks/cryptography/certificates.md

196 lines
11 KiB
Markdown
Raw Normal View History

2024-02-11 02:13:58 +00:00
# Vyeti
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:
2023-12-30 10:12:47 +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)
* 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** 🐦 [**@hacktricks\_live**](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>
<figure><img src="../.gitbook/assets/image (3) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
\
Tumia [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) kujenga na **kutumia mifumo ya kazi** kwa kutumia zana za **jamii za juu zaidi** ulimwenguni.\
2024-02-11 02:13:58 +00:00
Pata Ufikiaji Leo:
2022-05-01 16:32:23 +00:00
2023-01-01 16:19:07 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
2022-06-06 22:28:05 +00:00
## Ni Nini Cheti
**Cheti cha muhimu cha umma** ni kitambulisho cha kidijitali kinachotumiwa katika kriptografia kuthibitisha kwamba mtu fulani anamiliki funguo ya umma. Cheti hicho kina maelezo ya funguo, utambulisho wa mmiliki (mada), na saini ya kidijitali kutoka kwa mamlaka inayotegemewa (mtoaji). Ikiwa programu inaamini mtoaji na saini ni halali, mawasiliano salama na mmiliki wa funguo niwezekane.
Vyeti kwa kawaida hutolewa na [mamlaka za vyeti](https://en.wikipedia.org/wiki/Certificate\_authority) (CAs) katika mfumo wa [miundombinu ya funguo ya umma](https://en.wikipedia.org/wiki/Public-key\_infrastructure) (PKI). Njia nyingine ni [wavuti ya imani](https://en.wikipedia.org/wiki/Web\_of\_trust), ambapo watumiaji wanathibitisha moja kwa moja funguo za wengine. Muundo wa kawaida wa vyeti ni [X.509](https://en.wikipedia.org/wiki/X.509), ambao unaweza kubadilishwa kulingana na mahitaji maalum kama ilivyoelezwa katika RFC 5280.
2024-02-11 02:13:58 +00:00
## Sehemu za Kawaida za x509
2024-02-11 02:13:58 +00:00
### **Sehemu za Kawaida katika Vyeti vya x509**
Katika vyeti vya x509, **sehemu** kadhaa zina jukumu muhimu katika kuhakikisha uhalali na usalama wa cheti. Hapa kuna maelezo ya sehemu hizi:
* Nambari ya **Toleo** inaashiria toleo la muundo wa x509.
* Nambari ya **Serial** inatambulisha kipekee cheti ndani ya mfumo wa Mamlaka ya Cheti (CA), hasa kwa kufuatilia kufutwa.
* Sehemu ya **Mada** inawakilisha mmiliki wa cheti, ambayo inaweza kuwa mashine, mtu binafsi, au shirika. Inajumuisha utambulisho wa kina kama:
* **Jina la Kawaida (CN)**: Anwani zinazofunikwa na cheti.
* **Nchi (C)**, **Eneo (L)**, **Jimbo au Mkoa (ST, S, au P)**, **Shirika (O)**, na **Kitengo cha Shirika (OU)** hutoa maelezo ya kijiografia na ya shirika.
* **Jina la Kipekee (DN)** linafunga utambulisho kamili wa mada.
* **Mtoaji** anaelezea nani alithibitisha na kusaini cheti, pamoja na sehemu sawa kama Mada kwa CA.
* **Kipindi cha Uhalali** kimeashiriwa na mihuri ya **Sio Kabla** na **Sio Baada ya**, ikihakikisha cheti halitumiwi kabla au baada ya tarehe fulani.
* Sehemu ya **Funguo ya Umma**, muhimu kwa usalama wa cheti, inabainisha algorithm, saizi, na maelezo mengine ya kiufundi ya funguo ya umma.
* **Vipanuzi vya x509v3** huongeza utendaji wa cheti, ikibainisha **Matumizi ya Funguo**, **Matumizi ya Funguo Yaliyopanuliwa**, **Jina Mbadala la Mada**, na mali nyingine kufafanua matumizi ya cheti.
#### **Matumizi ya Funguo na Vipanuzi**
* **Matumizi ya Funguo** inatambua matumizi ya kriptografia ya funguo ya umma, kama saini ya kidijitali au kuficha funguo.
* **Matumizi Yaliyopanuliwa ya Funguo** inapunguza zaidi matumizi ya cheti, k.m., kwa uwakilishi wa seva ya TLS.
* **Jina Mbadala la Mada** na **Kikwazo cha Msingi** hufafanua majina ya ziada ya mwenyeji yanayofunikwa na cheti na ikiwa ni cheti cha CA au mwisho wa mwili, mtawalia.
* Vitambulisho kama **Kitambulisho cha Funguo cha Mada** na **Kitambulisho cha Funguo cha Mamlaka** hakikisha kipekee na ufuatiliaji wa funguo.
* **Maelezo ya Upatikanaji wa Mamlaka** na **Vipindi vya Usambazaji wa CRL** hutoa njia za kuthibitisha CA inayotoa na kuangalia hali ya kufutwa kwa cheti.
* **CT Precertificate SCTs** hutoa magogo ya uwazi, muhimu kwa imani ya umma kwenye cheti.
2024-02-08 21:36:35 +00:00
```python
# Example of accessing and using x509 certificate fields programmatically:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
2024-02-08 21:36:35 +00:00
# Load an x509 certificate (assuming cert.pem is a certificate file)
with open("cert.pem", "rb") as file:
2024-02-11 02:13:58 +00:00
cert_data = file.read()
certificate = x509.load_pem_x509_certificate(cert_data, default_backend())
2024-02-08 21:36:35 +00:00
# Accessing fields
serial_number = certificate.serial_number
issuer = certificate.issuer
subject = certificate.subject
public_key = certificate.public_key()
2024-02-08 21:36:35 +00:00
print(f"Serial Number: {serial_number}")
print(f"Issuer: {issuer}")
print(f"Subject: {subject}")
print(f"Public Key: {public_key}")
```
2024-02-11 02:13:58 +00:00
### **Tofauti kati ya OCSP na CRL Distribution Points**
2024-02-08 21:36:35 +00:00
**OCSP** (**RFC 2560**) inahusisha mteja na mwitikiaji kufanya kazi pamoja kuchunguza ikiwa cheti cha kielektroniki cha funguo ya umma kimebatilishwa, bila haja ya kupakua **CRL** kamili. Mbinu hii ni ufanisi zaidi kuliko **CRL** ya jadi, ambayo hutoa orodha ya nambari za mfululizo za vyeti vilivyobatilishwa lakini inahitaji kupakua faili kubwa inayowezekana. CRLs inaweza kujumuisha hadi viingilio 512. Maelezo zaidi yanapatikana [hapa](https://www.arubanetworks.com/techdocs/ArubaOS%206\_3\_1\_Web\_Help/Content/ArubaFrameStyles/CertRevocation/About\_OCSP\_and\_CRL.htm).
2024-02-11 02:13:58 +00:00
### **Nini ni Certificate Transparency**
Certificate Transparency husaidia kupambana na vitisho vinavyohusiana na vyeti kwa kuhakikisha utoaji na uwepo wa vyeti vya SSL unaweza kuonekana na wamiliki wa kikoa, CAs, na watumiaji. Malengo yake ni:
* Kuzuia CAs kutoa vyeti vya SSL kwa kikoa bila idhini ya mmiliki wa kikoa.
* Kuweka mfumo wa ukaguzi wazi kufuatilia vyeti vilivyotolewa kimakosa au kwa nia mbaya.
2024-02-11 02:13:58 +00:00
* Kulinda watumiaji dhidi ya vyeti vya udanganyifu.
#### **Magogo ya Cheti**
Magogo ya cheti ni rekodi za umma zinazoweza kukaguliwa, zisizoweza kubadilishwa za vyeti, zinazosimamiwa na huduma za mtandao. Magogo haya hutoa ushahidi wa kryptografia kwa madhumuni ya ukaguzi. Mamlaka za utoaji na umma wanaweza kuwasilisha vyeti kwa magogo haya au kuyauliza kwa uthibitisho. Ingawa idadi kamili ya seva za kuingiza haijafungwa, inatarajiwa kuwa chini ya elfu moja kimataifa. Seva hizi zinaweza kusimamiwa kivyake na CAs, ISPs, au taasisi yoyote inayohusika.
2024-02-11 02:13:58 +00:00
#### **Utafutaji**
Kutafuta magogo ya Certificate Transparency kwa kikoa chochote, tembelea [https://crt.sh/](https://crt.sh).
## **Miundo**
2024-02-11 02:13:58 +00:00
### **Muundo wa PEM**
* Muundo unaotumiwa sana kwa vyeti.
* Inahitaji faili tofauti kwa vyeti na funguo za faragha, zilizoandikwa kwa Base64 ASCII.
* Vipanuzi vya kawaida: .cer, .crt, .pem, .key.
* Kutumika hasa na seva za Apache na zingine zinazofanana.
2024-02-08 21:36:35 +00:00
2024-02-11 02:13:58 +00:00
### **Muundo wa DER**
* Muundo wa binary wa vyeti.
* Haujajumuisha taarifa za "BEGIN/END CERTIFICATE" zilizopatikana kwenye faili za PEM.
* Vipanuzi vya kawaida: .cer, .der.
* Mara nyingi hutumiwa na majukwaa ya Java.
2024-02-08 21:36:35 +00:00
2024-02-11 02:13:58 +00:00
### **Muundo wa P7B/PKCS#7**
* Imehifadhiwa kwa Base64 ASCII, na vipanuzi .p7b au .p7c.
* Ina vyeti tu na vyeti vya mnyororo, ikiondoa funguo ya faragha.
* Inaungwa mkono na Microsoft Windows na Java Tomcat.
2024-02-08 21:36:35 +00:00
2024-02-11 02:13:58 +00:00
### **Muundo wa PFX/P12/PKCS#12**
2024-02-08 21:36:35 +00:00
* Muundo wa binary unaofunga vyeti vya seva, vyeti vya kati, na funguo za faragha katika faili moja.
* Vipanuzi: .pfx, .p12.
* Kutumika hasa kwenye Windows kwa uingizaji na kuuza vyeti.
### **Kubadilisha Miundo**
2024-02-08 21:36:35 +00:00
2024-02-11 02:13:58 +00:00
**Ubunifu wa PEM** ni muhimu kwa utangamano:
2024-02-08 21:36:35 +00:00
* **x509 hadi PEM**
2024-02-08 21:36:35 +00:00
```bash
openssl x509 -in certificatename.cer -outform PEM -out certificatename.pem
```
* **PEM hadi DER**
2024-02-08 21:36:35 +00:00
```bash
openssl x509 -outform der -in certificatename.pem -out certificatename.der
```
* **DER hadi PEM**
2024-02-08 21:36:35 +00:00
```bash
openssl x509 -inform der -in certificatename.der -out certificatename.pem
```
* **PEM hadi P7B**
2024-02-08 21:36:35 +00:00
```bash
openssl crl2pkcs7 -nocrl -certfile certificatename.pem -out certificatename.p7b -certfile CACert.cer
```
* **PKCS7 hadi PEM**
2024-02-08 21:36:35 +00:00
```bash
openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.pem
```
**Ubadilishaji wa PFX** ni muhimu kwa usimamizi wa vyeti kwenye Windows:
* **PFX kwenda PEM**
2024-02-08 21:36:35 +00:00
```bash
openssl pkcs12 -in certificatename.pfx -out certificatename.pem
```
* **PFX hadi PKCS#8** inahusisha hatua mbili:
1. Geuza PFX hadi PEM
2024-02-08 21:36:35 +00:00
```bash
openssl pkcs12 -in certificatename.pfx -nocerts -nodes -out certificatename.pem
```
2. Geuza PEM kuwa PKCS8
2024-02-08 21:36:35 +00:00
```bash
openSSL pkcs8 -in certificatename.pem -topk8 -nocrypt -out certificatename.pk8
```
* **P7B hadi PFX** inahitaji amri mbili pia:
1. Geuza P7B hadi CER
2024-02-11 02:13:58 +00:00
```bash
openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.cer
```
2. Badilisha CER na Private Key kuwa PFX
2024-02-08 21:36:35 +00:00
```bash
openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert.cer
```
2024-02-08 21:36:35 +00:00
***
<figure><img src="../.gitbook/assets/image (3) (1) (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
\
Tumia [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) kujenga na **kutumia workflows** kwa urahisi zinazotumia zana za jamii **zilizoendelea zaidi** duniani.\
2024-02-11 02:13:58 +00:00
Pata Ufikiaji Leo:
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
2022-05-01 16:32:23 +00:00
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:
2023-12-30 10:12:47 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
2024-02-11 02:13:58 +00:00
* Pata [**swag rasmi ya 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** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kuhack 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>