hacktricks/mobile-pentesting/ios-pentesting/ios-serialisation-and-encoding.md

87 lines
6 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 mwanzo hadi mtaalamu 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:
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako ikionekana kwenye HackTricks** au **kupakua HackTricks kwa muundo wa 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 kwenye** [**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
Msimbo na habari zaidi katika [https://mas.owasp.org/MASTG/iOS/0x06h-Testing-Platform-Interaction/#object-persistence](https://mas.owasp.org/MASTG/iOS/0x06h-Testing-Platform-Interaction/#object-persistence).
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
## Uundaji wa Vitu katika Maendeleo ya iOS
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
Katika iOS, **uundaji wa vitu** unahusisha kubadilisha vitu kuwa muundo ambao unaweza kuhifadhiwa au kutumwa kwa urahisi, na kisha kuirudisha kutoka kwenye muundo huu unapohitajika. Itifaki mbili kuu, **`NSCoding`** na **`NSSecureCoding`**, hufanikisha mchakato huu kwa ajili ya darasa la Objective-C au `NSObject` subclasses, kuruhusu vitu kuundwa katika **`NSData`**, muundo ambao unafunga mabufa ya herufi.
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
### Utekelezaji wa **`NSCoding`**
Ili kutekeleza `NSCoding`, darasa lazima liwe limepokea kutoka kwa `NSObject` au liwe limeandikwa kama `@objc`. Itifaki hii inahitaji utekelezaji wa njia mbili za kuweka na kuondoa mali za kesi:
2021-05-21 16:38:18 +00:00
```swift
class CustomPoint: NSObject, NSCoding {
2024-02-11 02:13:58 +00:00
var x: Double = 0.0
var name: String = ""
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
func encode(with aCoder: NSCoder) {
aCoder.encode(x, forKey: "x")
aCoder.encode(name, forKey: "name")
}
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
required convenience init?(coder aDecoder: NSCoder) {
guard let name = aDecoder.decodeObject(forKey: "name") as? String else { return nil }
self.init(x: aDecoder.decodeDouble(forKey: "x"), name: name)
}
}
```
### **Kuboresha Usalama na `NSSecureCoding`**
Ili kupunguza udhaifu ambapo wadukuzi wanainjekta data kwenye vitu vilivyoundwa tayari, **`NSSecureCoding`** inatoa itifaki iliyoboreshwa. Darasa zinazofuata `NSSecureCoding` lazima thibitishe aina ya vitu wakati wa kudekodea, kuhakikisha kuwa ni aina za vitu zinazotarajiwa tu zinazotengenezwa. Walakini, ni muhimu kuelewa kuwa wakati `NSSecureCoding` inaboresha usalama wa aina, haifanyi data kuwa siri au kuhakikisha uadilifu wake, hivyo inahitaji hatua za ziada za kulinda habari nyeti:
2021-05-21 16:38:18 +00:00
```swift
static var supportsSecureCoding: Bool {
2024-02-11 02:13:58 +00:00
return true
2021-05-21 16:38:18 +00:00
}
2024-02-08 03:08:28 +00:00
let obj = decoder.decodeObject(of: MyClass.self, forKey: "myKey")
2021-05-21 16:38:18 +00:00
```
2024-02-11 02:13:58 +00:00
## Uhifadhi wa Data na `NSKeyedArchiver`
`NSKeyedArchiver` na kifaa chake, `NSKeyedUnarchiver`, inawezesha kuweka alama vitu ndani ya faili na kuvipata baadaye. Mfumo huu ni muhimu kwa ajili ya kudumuisha vitu:
2021-05-21 16:38:18 +00:00
```swift
NSKeyedArchiver.archiveRootObject(customPoint, toFile: "/path/to/archive")
2024-02-08 03:08:28 +00:00
let customPoint = NSKeyedUnarchiver.unarchiveObjectWithFile("/path/to/archive") as? CustomPoint
2021-05-21 16:38:18 +00:00
```
2024-02-11 02:13:58 +00:00
### Kutumia `Codable` kwa Ufupishaji wa Ufumaji
Itifaki ya `Codable` ya Swift inaunganisha `Decodable` na `Encodable`, ikirahisisha uwekaji na uondokaji wa vitu kama `String`, `Int`, `Double`, nk., bila jitihada za ziada:
2021-05-21 16:38:18 +00:00
```swift
struct CustomPointStruct: Codable {
2024-02-11 02:13:58 +00:00
var x: Double
var name: String
2021-05-21 16:38:18 +00:00
}
```
2024-02-11 02:13:58 +00:00
Njia hii inasaidia uwekaji wa data kwa njia rahisi kwenye orodha ya mali na JSON, ikiboresha usindikaji wa data kwenye programu za Swift.
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
## Mbadala wa Uwekaji wa JSON na XML
Mbali na msaada wa asili, maktaba kadhaa za watu wa tatu zinatoa uwezo wa uwekaji/utoaji wa JSON na XML, kila moja ikiwa na sifa zake za utendaji na maswala ya usalama. Ni muhimu kuchagua maktaba hizi kwa umakini, hasa kwa kuzingatia kuzuiwa kwa hatari kama mashambulizi ya XXE (XML External Entities) kwa kusanidi wapanguzi ili kuzuia usindikaji wa entiti za nje.
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
### Maswala ya Usalama
Wakati wa uwekaji wa data, hasa kwenye mfumo wa faili, ni muhimu kuwa macho kuhusu uwezekano wa kuingizwa kwa habari nyeti. Data iliyowekwa, ikiwa itatekwa au kushughulikiwa vibaya, inaweza kufichua programu kwa hatari kama vitendo visivyoruhusiwa au uvujaji wa data. Inapendekezwa kusimbwa na kusaini data iliyowekwa ili kuimarisha usalama.
2021-05-21 16:38:18 +00:00
2024-02-11 02:13:58 +00:00
## Marejeo
2024-02-08 03:08:28 +00:00
* [https://mas.owasp.org/MASTG/iOS/0x06h-Testing-Platform-Interaction/#object-persistence](https://mas.owasp.org/MASTG/iOS/0x06h-Testing-Platform-Interaction/#object-persistence)
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:
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa 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>