हम आग से खेलते हैं: हम विकास iPhone 7 पर मनमाना कोड चलाते हैं

छवि


नए साल की पूर्व संध्या पर, जेसी PCIE-7 प्रोग्रामर हमारे हाथों में गिर गया। उपयोग करने की प्रक्रिया में यह पता चला कि इसकी कार्यक्षमता सीमित है, लेकिन छोटी चीज डबल नीचे के साथ निकली है। इस प्रोग्रामर के अंदर, हमें एक विशेष डिबग संस्करण के साथ एक iPhone 7 बोर्ड मिला। "सेब" उत्पादों के अनुसंधान और डिबगिंग की दुनिया में नए साल के रोमांच के लिए - बिल्ली के नीचे आपका स्वागत है!


संभवतः, केवल बहुत आलसी सुरक्षा शोधकर्ताओं ने अपने स्वयं के हाथों से checkm8 और checkra1n द्वारा की गई संभावनाओं (checkm8 की शांत समीक्षा हाल ही में Habré पर आधारित) को महसूस नहीं किया। बेशक, हमने अपने स्मार्टफ़ोन का भी परीक्षण किया और इस प्रक्रिया में यह देखने का निर्णय लिया कि "लौह" शिल्प के चीनी बाजार में शोधकर्ताओं के लिए क्या उपयोगी है। दिलचस्प तथ्य: यदि आप सुरक्षा के लिए किसी भी उपकरण का परीक्षण करना चाहते हैं, तो इसके लिए AliExpress के पास पहले से ही अपने खिलौने हैं।


हमारा खिलौना नए साल की पूर्व संध्या पर आया - जेसी PCIE-7 प्रोग्रामर, जो AliExpress पर ढूंढना आसान है:


छवि


हमने अनुमान लगाया कि इस प्रोग्रामर की मदद से हम आईफोन फ्लैश मेमोरी का बैकअप ले सकते हैं। लेकिन ऑपरेशन के दौरान यह पता चला कि कार्यक्रम में इस तरह के एक समारोह बस मौजूद नहीं है! हां, प्रोग्रामर फ्लैश मेमोरी में कॉन्फ़िगरेशन को पढ़ और लिख सकता है और इसे फोन पर संलग्न कर सकता है, लेकिन मनमाने ढंग से ब्लॉक पढ़ना समर्थित नहीं है। फिर हमने कंट्रोल प्रोग्राम के कंसोल विंडो में ऑपरेटिंग सिस्टम बूट लॉग के समान असामान्य रेखाएं देखीं:


छवि
प्रशिक्षण वीडियो से पल लोड करने का फ्रेम


अंत में, हमने DFU प्रोटोकॉल का उपयोग करके प्रोग्रामर को कंप्यूटर से जोड़ने के कार्य पर ध्यान आकर्षित किया। इस मोड में, आईफोन के रूप में आईट्यून्स में प्रोग्रामर का सही पता लगाया गया था। हमने डिवाइस को अलग करने और यह देखने का फैसला किया कि अंदर क्या है और डीएफयू मोड का अनुकरण कैसे किया जाता है।


प्रोग्रामर के अंदर, तीन बोर्ड स्थापित हैं:


  • STM32F103 पर आधारित नियंत्रण बोर्ड;
  • बहुसंकेतक बोर्ड एक soldered NVMe चिप और एक ब्लॉक के साथ;
  • और, अप्रत्याशित रूप से, iPhone 7 बोर्ड।

छवि


छवि


यह पता चला कि प्रोग्रामर मल्टीप्लेक्स को इस तरह से स्विच करता है कि पहले iPhone बोर्ड को सोल्डरेड फ्लैश मेमोरी से लोड किया जाता है, और फिर NVMe चिप जिसे फ्लैश करने की आवश्यकता होती है, उससे जुड़ा होता है। प्रबंधन एक वर्चुअल COM पोर्ट के माध्यम से किया जाता है, और पहले NVMe चिप्स स्विच करने के लिए आदेश प्रेषित किए जाते हैं, और फिर बोर्ड एक डीसीएसडी केबल का अनुकरण करते हुए iPhone डिबग कंसोल को आगे बढ़ाता है । COM पोर्ट पर भेजे गए कमांड्स की सावधानीपूर्वक जाँच करने पर, हमने लाइनें देखीं:


setenv diags-path /AppleInternal/Diags/bin/diag.img4
diags


पहले से ही इस बिंदु पर, हमने महसूस किया कि iPhone 7 बोर्ड बिल्कुल साधारण नहीं है (कम से कम इसमें AppleInternal फ़ोल्डर है )। यह देखने के लिए कि वह एक अधिक परिचित "वातावरण" में कैसे व्यवहार करती है, हमने बोर्ड और NVMe चिप को एक दाता के रूप में पुन: व्यवस्थित किया:


छवि


गियर के अलावा जब लोड हो रहा है, डिबग कंसोल में, हमने लाइन BUILD_STYLE देखी: विकास:


छवि


अंतिम डाउनलोड के बाद ( ऊपर बताए गए शब्द का उपयोग करके), हमें एक बैंगनी स्क्रीन मिली, और वॉल्यूम कुंजियों को दबाने के बाद, निम्न मेनू स्क्रीन पर प्रदर्शित किया गया:


छवि


यही है, हमने जिस डिवाइस को इकट्ठा किया है, वह परीक्षण और विकास के लिए iPhone का एक विशेष संस्करण बन गया है! वैसे, ऐसे फोन शोधकर्ताओं और यहां तक ​​कि कलेक्टरों द्वारा खरीदे जाते हैं - यह हमारे तकनीकी संग्रह के लिए एक वास्तविक उपहार है! एक पूर्ण iPhone डेवलपर में, रूट कंसोल के साथ एक विशेष iOS असेंबली स्थापित की गई है, जो फोन के अध्ययन और कमजोरियों की खोज को बहुत आसान बनाती है:


छवि


हमारे मामले में, केवल नैदानिक ​​उपयोगिता फोन पर स्थापित होती है, जिसके साथ मुख्य इंटरैक्शन डिबग कंसोल के माध्यम से होता है:


बूट लॉग और आउटपुट आउटपुट
======================================= :: :: iBoot for d10, Copyright 2007-2016, Apple Inc. :: :: Local boot, Board 0x8 (d10ap)/Rev 0xd :: :: BUILD_TAG: iBoot-3406.1.53.1.4 :: :: BUILD_STYLE: DEVELOPMENT :: :: USB_SERIAL_NUMBER: CPID:8010 CPRV:11 CPFM:03 SCEP:01 BDID:08 ECID:000114422885E526 IBFL:3D :: ======================================= Boot Failure Count: 0 Panic Fail Count: 0 Entering recovery mode, starting command prompt ] setenv diags-path /AppleInternal/Diags/bin/diag.img4 ] diags Unable to load image type 64696167 from flashnx_mount:432: reloading after unclean unmount, checkpoint xid 112, superblock xid 11 jumping into image at 0x810000000 pinot_quiesce() mipi_dsim_quiesce() Console router buffer allocated @ 0x87CB84018, size = 262144 bytes WHO_AM_I doesn't match MPU6700's Chip ID! Expected 0x90 got 0x0 Carbon: MPU6900 is found. Carbon: MPU6900 (south) detected Carbon: MPU6900 (south) selected MPU6900 not found. Expected 0x10, found 0x0 Carbon: MPU6900 (north) not detected Phosphorous: BMP284 is found. mcc-supported : 1 Phosphorous: BMP282 is not found on SPI 4. Expected 0x58, found 0x0 time-train: 26719 uS Link 0 speed negotiate to 3 Link 0 width negotiate to 1 APCIE power on completed Device 00:00:0 config space@0x610000000 Vendor:106B Device:1007 Revision:01 ClassCode:060400 Type:01 PriBus:00 SecBus:01 SubBus:01 Capability 0x01 Offset:0x40 Address:0x610000040 Capability 0x05 Offset:0x50 Address:0x610000050 Capability 0x10 Offset:0x70 Address:0x610000070 Extended Capability 0x0001 Ver:0x02 Offset:0x0100 Address:0x610000100 Extended Capability 0x0019 Ver:0x01 Offset:0x0148 Address:0x610000148 Extended Capability 0x001E Ver:0x01 Offset:0x0160 Address:0x610000160 Found device id 0x2002 Device 01:00:0 config space@0x610100000 Vendor:106B Device:2002 Revision:11 ClassCode:018002 Type:00 BAR0 MEM C0000000/00004000 BAR1 IO 00000000/00000004 Capability 0x01 Offset:0x40 Address:0x610100040 Capability 0x05 Offset:0x50 Address:0x610100050 Capability 0x10 Offset:0x70 Address:0x610100070 Extended Capability 0x0001 Ver:0x02 Offset:0x0100 Address:0x610100100 Extended Capability 0x0002 Ver:0x01 Offset:0x0148 Address:0x610100148 Extended Capability 0x0019 Ver:0x01 Offset:0x0168 Address:0x610100168 Extended Capability 0x0018 Ver:0x01 Offset:0x0178 Address:0x610100178 Extended Capability 0x001E Ver:0x01 Offset:0x0180 Address:0x610100180 APCIE Enumerate on completed ICE BB not supported on this platform D10 Diag (factory_d10_pvt) BuildEng build D10Casaval24C302an (24C302an). Revision 6040f18. Built at 2016/08/20 15:57:53 script: device -k ThermalSensor -e sochot 0 on 120 script: device -k ThermalSensor -e sochot 1 on 125 script: cbcolor Setting Screen Color based on iPX Control Bits: script: alias vbat=pmuadc --sel tigris --read vbat script --cont startup.txt script: alias bbon="meta 'baseband --on --load_firmware; baseband --wait_for_ready --ping'" script: alias bbonbypass="meta 'baseband --on --load_firmware; baseband --wait_for_ready --ping --bypass en'" script: alias bboff=baseband --off script: alias getcd=bblib -e BB_GetCD() script: alias erase_rfcal=smokey Tools/RFCalErase --run script: alias erase_efs=smokey Tools/EFSErase --run script: alias erase_pac=smokey Tools/RFPacErase --run script: alias hdq_en=i2c --devwrite 1 0x75 0x1D 1 script: alias hdq_dis=i2c --devwrite 1 0x75 0x1D 0 script: alias bblib="smokeyshell -p -e 'if BBLib_cfg then print [[no init]] else require [[BBLib.14A]];BB_Init() end'" script: alias wcs=smokey --run WCS --clean LogBehavior=ConsoleOnly script: alias bblibcfg=bblib -e printLibCfg() script: alias bbdebug="meta 'base --debug on;ramlog --on 10;consolerouter --add -s *.{warn,error,print},system.debug.debug -d ramlog --quiet;consoleformat --en --sink serial -o ts'" script: alias gpsdebug="meta 'ramlog --on 10;consolerouter --add -s gps.debug.* -d ramlog'" script: alias updateroot="meta 'usbfs --mount;cp -r usbfs:\AppleInternal nandfs:\;usbfs --unmount;smokeyshell -r'" [00011442:2885E526] :-) help DiagShell builtin commands: "time" time <command-line ...> "echo" echo <arguments ...> "waitfor" waitfor <timeout-milliseconds> <string-to-match> "repeat" repeat <time-spec> <command line ...> "alias" alias [<name>[=<command line>]] "unalias" unalias <name> "true" true "false" false "args" args <command line ...> "shopt" shopt EDK Boot Loader commands (help <command> for more info): "accessory" Command to change power settings as well as identifying accessories connected to the unit "aes" Command for AES encryption/decryption "amux" Analog Mux selection command "audio" General command to hande resetting/blanking/scripting of the audio subsystem "audioparam" Audio parameter retrieval/setting utility "audioreg" Manages register operations on audio blocks in the system "barcode" Show S/N and ECID barcode "baseband" Command to control/test baseband functionality "battery" Command to display basic information about the battery "baud" <baud rate> : Set UART Baud rate "bl" BackLight Test "blockdevice" Show information about boot devices. Bare quantities are in bytes. "bluetooth" Command to control/test bluetooth functionality "boardid" Get the board ID "boardrev" Get the board revision "bonfire" Run Bonfire "bootcfg" Get the boot configuration "buckcheck" Buck voltage check "button" Test individual buttons on the unit "buttoncnt" [--dqe] Count button presses on the unit "camisp" camera command that can run in seperat steps. "cat" Print the contents of a file. "cbcolor" iPX Control Bit - Set screen color based on number of passed stations "cbdump" iPX Control Bit - Dump the CB area from the NAND "cberase" iPX Control Bit - Erase a control bit "cbinit" iPX Control Bit - Initialize control bit area "cbread" iPX Control Bit Read "cbreadall" iPX Control Bit - read all "cbwrite" iPX Control Bit Write "charge" Charge controls for system "chipid" Show ChipID "clkmon" [signal/off]; Set Clock Test out pin to specified signal or switch it off "consoleformat" Command to control the formatting of text display on serial output mediums like the console "consolerouter" Main command that deals with all things console in the system "consolesinkctrl" Manage the console sink controls "cp" cp [-r] <source> ... <dest> "debug" Turns on/off global debug levels in the system "device" Interfaces with a devices of the system. "dfufile" Use dfu protocol to transfer file. "directory" DirDev [*match]; directory listing of dirdev. opt match a substring "DisCfg#" Display CFG systemcfg "DisOpts" Display OPTS systemcfg "display" Command to control display "displayid" Get the display ID "displaytext" Display text on the unit's screen "dt" Provide access to the device tree structure "dumpmemmap" Dumps memory map "dwi" backlight test using DWI "event" Signal EFI event groups "filelog" Log formatted console output to a file "getnonce" iPX Control Bit - generate a salt value for control-bit write authentication "getvol" Gets volume information/values from the various audio blocks "gps" Command to test/control GPS functionality "hash" compute Hash "help" [cmd]; Help on cmd or a list of all commands if cmd is ommited "hid" Command for the hid controllers/sensors "i2c" generic read/write to I2C device "key" Read buttons' status from AP side and PMU side "legal" Outputs the copyright for any libraries used by Diags. "loopaudio" Plays/Record full-duplex audio out/in through selected 'playable' and 'recordable' ports on an audio block "lua" lua [options] [script [args]] "mbt" Menu Button Test "memcat" Read memory into file or a file into memory "memory" Memory Utilities [--info] | [--list] | [--leak] | [--dump] <address> <length> "memrw" Read/write/or/and from memory "menu" Navigate menu items in Display "meta" [cmd]; Execute cmd as if it was entered at the shell (useful for scripting) "mipi" Command to interact with mipi "mkdir" mkdir <directory_name> ... "nand" Command to test nand functionality "nandcsid" Read Nand Chip ID and detect ID mismatch "nandppnfwver" Prints the PPN Firmware version for all populated CE's "nandsize" Nand testing "nanduid" Read Unique ID from each Nand die "network" Command to control network interface "nvram" Print or modify NVRAM variables "pattern" [--iqc [#]|--dqe [#]|--fatp [#]|--other [#]|--fill [rgb #] --list will List available displays --pick <name> will Pick Display name [n]:Test LCD display pattern[n] "pcie" qucik pcie test "physaddr" Decodes a physical address into bank/column/row/etc "playaudio" Plays audio out through a selected 'playable' port "pmuadc" PMU ADC Command for Calibration/Reading/Listing Channels "pmubutton" pmu button test "pmuevent" [all|chipid|btn|vbus|chgr|gpio|misc|temp|fault|ouv|clear] "pmugpio" Set a PMU GPIO to a certain state "pmureg" Print the values of all the pmu registers "pmurw" generic read/write to PMU Registers "pmuset" set the buck and ldo voltages value "pmustat" [all|chipid|btn|vbus|chgr|gpio|misc|temp|fault] "pmutemp" PMU TEMP test "processaudio" Post-processes audio data using various audio filters registered in the system "profile" Turns profiling on/off, dumps data, and resets profiling data. "qrbarcode" Command for showing the QRbarcode "quit" Quit EBL "ramlog" Command to manage the ramlog console sink which can be used for logging text to RAM for timing sensitive issues "recordaudio" Records audio in through a selected 'recordable' port "reset" Resets the system "rm" rm [-f] <path> ... "rmdir" rmdir <directory_name> ... "routeaudio" Sets up audio routing. "rtc" Set or get the RTC from PMU "script" [filename]; Execute the commands in the specified file "sensor" General command that interfaces with the various sensors in the system "sensorreg" General command that allows for reading/writing sensor chipset registers "sep" Manipulate the SEP "setvol" Sets volume levels within the various audio blocks "shutdown" Wait until the unit is unplugged then go to standby "signal" Measure Signal Jitter, Period "sleep" Set system to specified sleep state "smash" Memory smasher "smokey" EFI diag scripting sequencer "smokeyshell" EFI diag scripting sequencer debug shell "sn" Read/Write serial number "soc" Command for displaying SoC info "socgpio" Set a GPIO to a certain state "spi" Test Spi buses "spkid" Return 1 bit Speaker ID "stockholm" Command to control/test stockholm functionality "stopaudio" Stop audio out through a selected 'playable/recordable' port "strobe" Command to control the Strobe on the System "syscfg" [init | add | print | list | type | delete] <KEY> <value1> <value2> ...; System Config "sysinfo" Dumps system information "system" Command to display basic information about the unit "tag" Turns tagging of data on/off. "temperature" Control Settings and Dump Readings from various Temperature Sensors in the System "testCDMADDR" CDMA DDR test "testmemory" Run data and address patterns to exercise DRAM subsystem "testmp" boot up second core for simple tests "thermalmonitor" Command to control/test thermal functionality "touch" Command for the Touch subsystem "tristar" TriStar test commands "uartloopback" Perform a loopback test on the specified uart. Note that you will have to put the chip into loopback mode using separate commands. "uartpassthrough" pass through uart traffic from dock uart to select uart "uartrx" Receive and store message from uart <uart #>. It will send the message back to uart <uart #> when a <ExitString> is detected. "uarttx" send message to the selected uart "usbfs" Enables/Disables UsbFS (Filesystem-over-USB) "usbp" Test USB Present "version" Diag Version "wait" [ms]; Wait ms milliseconds "wakeevent" Select wake event for wakeup for PMU STANDBY or Hibernate mode "wakeeventsmanager" Command to control wakeevents in the system "wfi" Enable/Disable the wfi feature "wifi" Command to control/test wifi functionality "writefile" Write text to a file "zerofile" Zero the contents of an existing file 

जैसा कि आप देख सकते हैं, डिबगिंग प्रोग्राम की कार्यक्षमता बड़ी है। यह मुख्य रूप से परीक्षण उपकरण के लिए अभिप्रेत है - अधिकांश टीम उपकरण के विभिन्न हार्डवेयर उप-प्रणालियों के परीक्षण के लिए जिम्मेदार हैं। हमारे लिए सबसे उपयोगी कमांड निर्देशिका , मेम्र , मेमोरी और कैट थे


निर्देशिका कमांड चलाकर, आप फ़ाइल सिस्टम की सामग्री से खुद को परिचित कर सकते हैं:


 [00011442:2885E526] :-) dir fs0: --------- <DIR> 2016-08-29 07:01 AppleInternal --------- <DIR> 2016-09-22 11:27 System --------- <DIR> 2016-09-22 11:29 private --------- <DIR> 2016-09-22 11:28 usr 

कैट-एच चलाकर, आप किसी भी फाइल को पढ़ सकते हैं:


फ़ाइल पढ़ने का परिणाम
 [00011442:2885E526] :-) cat -h fs0:\AppleInternal\Diags\Logs\Smokey\Shared\ComponentLib\HallSensor\11A\HallSensor.lua 00000000: 2D 2D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D |--==============| 00000010: 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D |================| 00000020: 3D 3D 3D 3D 3D 3D 3D 3D 3D 0A 2D 2D 20 46 69 6C |=========.-- Fil| 00000030: 65 6E 61 6D 65 3A 20 20 48 61 6C 6C 53 65 6E 73 |ename: HallSens| 00000040: 6F 72 2E 6C 75 61 0A 2D 2D 20 44 65 73 63 72 69 |or.lua.-- Descri| 00000050: 70 74 69 6F 6E 3A 20 48 61 6C 6C 53 65 6E 73 6F |ption: HallSenso| 00000060: 72 20 74 65 73 74 20 66 69 6C 65 0A 2D 2D 3D 3D |r test file.--==| 00000070: 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D |================| 00000080: 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D 3D |================| 00000090: 3D 3D 3D 3D 3D 0A 0A 72 65 71 75 69 72 65 20 22 |=====..require "| 000000A0: 43 6F 6D 70 6F 6E 65 6E 74 4C 69 62 2E 43 6F 6D |ComponentLib.Com| 000000B0: 6D 6F 6E 2E 31 31 41 22 0A 0A 6C 6F 63 61 6C 20 |mon.11A"..local | 000000C0: 43 4F 4D 50 4F 4E 45 4E 54 5F 4E 41 4D 45 20 3D |COMPONENT_NAME =| 000000D0: 20 22 48 61 6C 6C 53 65 6E 73 6F 72 22 0A 0A 2D | "HallSensor"..-| 000000E0: 2D 20 48 61 6C 6C 73 65 6E 73 6F 72 20 74 65 73 |- Hallsensor tes| 000000F0: 74 0A 66 75 6E 63 74 69 6F 6E 20 48 61 6C 6C 53 |t.function HallS| 00000100: 65 6E 73 6F 72 54 65 73 74 73 28 29 0A 09 53 51 |ensorTests()..SQ| 00000110: 41 5F 53 68 65 6C 6C 28 22 68 61 6C 6C 73 65 6E |A_Shell("hallsen| 00000120: 73 6F 72 20 2D 2D 6D 65 61 73 20 22 2E 2E 48 41 |sor --meas "..HA| 00000130: 4C 4C 5F 53 45 4E 53 4F 52 5F 4D 45 41 53 2E 2E |LL_SENSOR_MEAS..| 00000140: 22 20 2D 2D 64 65 6C 61 79 20 22 2E 2E 48 41 4C |" --delay "..HAL| 00000150: 4C 5F 53 45 4E 53 4F 52 5F 44 4C 59 29 0A 09 53 |L_SENSOR_DLY)..S| 00000160: 51 41 5F 53 68 65 6C 6C 28 22 68 61 6C 6C 73 65 |QA_Shell("hallse| 00000170: 6E 73 6F 72 20 2D 2D 69 72 71 69 6E 64 65 78 20 |nsor --irqindex | 00000180: 22 2E 2E 48 41 4C 4C 5F 53 45 4E 53 4F 52 5F 49 |"..HALL_SENSOR_I| 00000190: 52 51 5F 49 4E 44 45 58 29 0A 09 53 51 41 5F 53 |RQ_INDEX)..SQA_S| 000001A0: 68 65 6C 6C 28 22 68 61 6C 6C 73 65 6E 73 6F 72 |hell("hallsensor| 000001B0: 20 2D 2D 6F 66 66 20 20 22 29 0A 65 6E 64 0A 0A | --off ").end..| 

इन दोनों कमांड को मिलाकर, हम डिवाइस से सभी फाइलों को पढ़ते हैं (लगभग 150 एमबी):


छवि


फाइलों में से एक "ईस्टर अंडे" था, जिसके साथ मजाक न करने की सिफारिश की गई थी Iphone7 आग से:


छवि


मेमोरी-डंप कमांड चलाकर , आप रैम रेंज पढ़ सकते हैं:


 [00011442:2885E526] :-) memory --dump 0x800000000 0x100 0: 30 83 43 5B 39 16 04 49 4D 47 34 30 83 43 40 14 0.C[9..IMG40.C@ 10: 16 04 49 4D 34 50 16 04 64 69 61 67 16 01 31 04 .C@..".X..@.?.. 20: 83 43 40 00 80 22 00 58 01 04 40 F9 3F 00 00 F1 ..T?...@..T... 30: 20 05 00 54 3F 04 00 F1 40 00 00 54 FA 01 00 14 ....B...B...Bt 40: 02 00 80 D2 42 00 00 91 42 08 00 91 42 CC 74 D3 B...BlBBBp. 50: 42 08 04 91 42 AC 6C D3 42 C0 42 91 42 70 00 91 _...!..R....c.. 60: 5F 00 00 B9 21 00 80 52 03 00 80 D2 63 00 00 91 c...ctc..cl 70: 63 08 00 91 63 CC 74 D3 63 08 04 91 63 AC 6C D3 cBcP..a...... 80: 63 C0 42 91 63 50 00 91 61 00 00 B9 03 00 80 D2 c...c...ctc. 90: 63 00 00 91 63 08 00 91 63 CC 74 D3 63 08 04 91 clcBc@..... A0: 63 AC 6C D3 63 C0 42 91 63 40 00 91 7F 00 00 B9 ...RA.......... B0: 81 00 80 52 41 00 00 B9 7F 00 00 B9 00 00 00 14 @.............. C0: 40 03 00 00 00 00 00 00 B0 03 00 00 00 00 00 00 . ...O...?..... D0: 1F 20 03 D5 DF 4F 03 D5 DF 3F 03 D5 1F 87 08 D5 .?.. .;.!.....! E0: 9F 3F 03 D5 20 E2 3B D5 21 00 80 D2 00 00 21 8A .......a...<.@ F0: 20 E2 1B D5 9B F9 FF 10 61 06 00 10 3C 00 40 F9 z...Y.@........ 

अंत में, मेम कमांड के साथ, आप रैम को अधिलेखित कर सकते हैं:


 [00011442:2885E526] :-) memrw 0x800000000 0x12345678abcdef 0x800000000: 0x12345678ABCDEF OK [00011442:2885E526] :-) memory --dump 0x800000000 0x10 0: EF CD AB 78 56 34 12 00 4D 47 34 30 83 43 40 14 ...xV4..MG40.C@ 

इस तथ्य के बावजूद कि मेमोरी पढ़ना पहले से ही उपयोगी कार्यक्षमता का एक उपाय है, हमने जांचने का फैसला किया: क्या निष्पादन योग्य कोड के क्षेत्रों को अधिलेखित करना और अपनी खुद की कुछ चीज़ों को चलाना संभव है? आखिरकार, iPhone विकासात्मक है, और कार्यक्षमता अभी भी कस्टम है - यह काम नहीं करेगा!


मानक तरीकों से ऐसा करना संभव नहीं था, एक काफी विस्तृत ट्रेस लॉग के साथ एक त्रुटि हुई:


अपवाद का लॉग हुआ
 [00011442:2885E526] :-) memrw 0x87BF68AA0 0 panic: unhandled exception: 0 x0: 0x00000000 x1: 0x0000000A x2: 0x00000000 x3: 0x87BF68AA0 x4: 0x00000002 x5: 0x00000003 x6: 0x879D52218 x7: 0x00000003 x8: 0x87BF68E30 x9: 0x87BF6908C x10: 0x00000000 x11: 0x000000E0 x12: 0x000000E0 x13: 0x00000001 x14: 0x00000001 x15: 0x00000000 x16: 0x000000FF x17: 0x00000001 x18: 0x810000308 x19: 0x879D52228 x20: 0x00000008 x21: 0x00000000 x22: 0x87BF68AA0 x23: 0x00000007 x24: 0x00000001 x25: 0x87BF68AA0 x26: 0x00000000 x27: 0x00000002 x28: 0x87CA42332 fp: 0x87FBEFC20 lr: 0x87BF68D3C sp: 0x00000000 PC: 0x87BF68E30 SPSR: 0x80000005 ESR: 0x9600004F FAR: 0x87BF68AA0 EC:0x25 - "Data Abort caused by current EL" ISS:0x4F - "Permission Fault Level 3" Memory Access Fault - write to read-only or unmapped address. FAR contains target address. 0x87BF68AA0: /Users/build/archive/casaval_d10_202/src/shasta/BuildResults/D10diag/release/diag/TestDirectMemoryRW.macho + <0x4AA0> : text section stack buffer at 0x87FBEEED0 printing callstack: 15 frames unrolled. #0 0x87BF68E30 TestDirectMemoryRW.macho @ offset 0x4E30 #1 0x87BF68D38 TestDirectMemoryRW.macho @ offset 0x4D38 #2 0x87BF69620 TestDirectMemoryRW.macho @ offset 0x5620 #3 0x879B2C1D0 DiagShell.macho @ offset 0x41D0 #4 0x879B2C7F0 DiagShell.macho @ offset 0x47F0 #5 0x879B2D11C DiagShell.macho @ offset 0x511C #6 0x87FB75494 DxeMain.macho @ offset 0xD494 #7 0x87CAD8214 DiagBds.macho @ offset 0x4214 #8 0x87CAD8260 DiagBds.macho @ offset 0x4260 #9 0x87CAD82CC DiagBds.macho @ offset 0x42CC #10 0x87FB6C604 DxeMain.macho @ offset 0x4604 #11 0x87FB6C0F0 DxeMain.macho @ offset 0x40F0 #12 0x81034AA04 #13 0x81039C7E4 #14 0x81039C39C Please report panic using panic.apple.com hanging here... 

इस मामले में, ट्रेस लॉग कहता है कि जब 0x87BF68E30 पते पर निष्पादित किया जाता है, तो केवल-पढ़ने के लिए मेमोरी पते पर लिखने के कारण TestDirectMemoryRW.macho मॉड्यूल में एक अपवाद उत्पन्न हुआ । लेकिन नए साल की पूर्व संध्या पर तकनीकी शोधकर्ताओं के लिए कोई बाधाएं नहीं हैं! स्टैक पर सबसे हाल की कॉल पर ध्यान दें: DxeMain.macho । संक्षिप्त नाम DXE और लाइन EDK बूट लोडर कमांड की उपस्थिति हमें यह निष्कर्ष निकालने की अनुमति देती है कि डिवाइस एक EFI- संगत प्रणाली चला रहा है। वास्तव में, सिस्टम छवि diags.img4 को UEFITool का उपयोग करके सही ढंग से खोला गया है:


छवि


डिस्सेम्बलिंग प्रोग्राम मॉड्यूल से पता चला कि सभी निष्पादन योग्य मॉड्यूल ईएफआई कॉल सम्मेलनों और मानक ईडीके संरचनाओं का उपयोग करते हैं:


छवि


प्रत्येक टर्मिनल कमांड एक अलग EFI मॉड्यूल से मेल खाती है, उदाहरण के लिए, मेमोरी कमांड TestUtilities.macho मॉड्यूल से मेल खाती है, जिसे 0x87BE10000 (ट्रेस लॉग से निर्धारित) में रैम में लोड किया गया है।


आइए हमारे कोड को निष्पादित करने के लिए इस मॉड्यूल के प्रोग्राम कोड को संशोधित करने का प्रयास करें।


0x87BE1600D पते पर मेमोरी -info कमांड द्वारा एक टेक्स्ट स्ट्रिंग आउटपुट है, हम इसे संशोधित करते हैं:


 [00011442:2885E526] :-) memory --info Total Memory: 0x80000000, free: 0x79B48000, fragmented: 0x10028000, frags: 5, in use: 0x64B8000 [00011442:2885E526] :-) memory --dump 0x87BE1600D 0x30 7BE1600D: 54 6F 74 61 6C 20 4D 65 6D 6F 72 79 3A 20 30 78 Total Memory: 0 7BE1601D: 25 78 2C 20 66 72 65 65 3A 20 30 78 25 6C 78 2C fragmented: 0x 7BE1602D: 20 66 72 61 67 6D 65 6E 74 65 64 3A 20 30 78 25 x, frags: %d, i 

हमारे द्वारा आवश्यक मेमोरी क्षेत्र को संशोधित करने के लिए, हमें 0x87BE14000 से पृष्ठ के एक्सेस अधिकारों को केवल पढ़ने / लिखने / निष्पादित करने के लिए पढ़ने / निष्पादित करने की आवश्यकता है । AArch64 प्रलेखन के अनुसार, एक विशेष अनुवाद तालिका एक्सेस अधिकारों के लिए जिम्मेदार है। तालिका रैम में स्थित होनी चाहिए और निम्नलिखित प्रारूप में 8 बाइट्स के रिकॉर्ड से युक्त होना चाहिए:


छवि


दूसरे स्तर की अनुवाद तालिका 0x87FBF4000 में, मेमोरी रेंज में पुनर्लेखन के लिए उपलब्ध पाई गई थी। इस स्तर पर, प्रत्येक प्रविष्टि पता स्थान के 32 एमबी (0x2000000) से मेल खाती है, इसलिए हमें 0x87A000000-0x87BFFFF रेंज के लिए आवश्यक रिकॉर्ड 0x87FBF4000 + (0x87A000000 / 0x2000000) * 8 = 0x87FBF61E8 पर स्थित है :


 [00011442:2885E526] :-) memory --dump 0x87FBF61E8 0x8 7FBF61E8: 03 C0 CE 7F 08 00 00 00 

रिकॉर्ड टाइप टेबल का है , यानी यह 0x87FCEC000 के पते पर तीसरे स्तर की अनुवाद तालिका की ओर इशारा करता है । इस तालिका में, प्रत्येक प्रविष्टि पता स्थान के 16 Kb (0x4000) पृष्ठ से मेल खाती है और प्रकार ब्लॉक की है । पृष्ठ 0x87BE14000 के लिए हमें जो रिकॉर्ड चाहिए वह 0x87FCEC000 + (0x87BE14000 - 0x87A000000) / 0x4000 * 8 = 0x87FCEFC28 पर स्थित है:


 [00011442:2885E526] :-) memory --dump 0x87FCEFC28 8 7FCEFC28: AB 47 E1 7B 08 00 00 00 .G.{....+..{..` 

चूंकि यह प्रविष्टि प्रकार ब्लॉक की है , इसलिए यह एक भौतिक मेमोरी पेज की ओर इशारा करता है और इसमें एक्सेस विशेषताएँ होती हैं। हम लोअर ब्लॉक विशेषताओं में रुचि रखते हैं, अर्थात् डेटा एक्सेस अनुमतियाँ बिट्स फ़ील्ड:


छवि


पृष्ठ पर लिखने की अनुमति देने के लिए, इस फ़ील्ड का मान 0 पर सेट करें:


 [00011442:2885E526] :-) memrw 0x87FCEFC28 --64 0x000000087BE1472B 0x87FCEFC28: 0x87BE1472B OK 

उसके बाद, हमें वांछित क्षेत्र के लिए लिखना चाहिए। आवश्यक परिवर्तन करने के बाद, हम वांछित परिणाम प्राप्त करते हैं:


 [00011442:2885E526] :-) memrw 0x87BE16008 0x6C6548000A535341 0x87BE16008: 0x6C6548000A535341 OK [00011442:2885E526] :-) memrw 0x87BE16010 0x0072626148206F6C 0x87BE16010: 0x72626148206F6C OK [00011442:2885E526] :-) memory --info Hello Habr 

नैतिक: वर्णित पद्धति का उपयोग करके, हम किसी भी सिस्टम एप्लिकेशन को संशोधित कर सकते हैं और एक विकास iPhone पर UEFI वातावरण में मनमाने कोड को निष्पादित कर सकते हैं।


यह शोध पुराने iPhone संस्करणों के लिए व्यावहारिक मूल्य नहीं रखता है, लेकिन कुछ अज्ञात और दुर्लभ को सुलझाने के लिए मजेदार था, खासकर जब यह अचानक नए साल के उपहार के रूप में दिखाई दिया।


PS लेकिन वर्णित विधि नवीनतम iPhone संस्करणों पर शोध करने और SecureROM प्राप्त करने के लिए उपयोगी हो सकती है: उन में checkm8 भेद्यता तय हो गई है, और iPhone XR और iPhone 11 पर आधारित AliExpress पर समान "प्रोग्रामर" पहले से ही बिक्री पर हैं



रैकोन सुरक्षा व्यावहारिक सूचना सुरक्षा, क्रिप्टोग्राफी, सर्किटरी, रिवर्स इंजीनियरिंग और निम्न-स्तरीय सॉफ़्टवेयर के निर्माण के क्षेत्र में ज्वालामुखी वैज्ञानिक और तकनीकी केंद्र के विशेषज्ञों की एक विशेष टीम है।

Source: https://habr.com/ru/post/hi482032/


All Articles