Wednesday, December 07, 2016

Calculating hash(md5, sha1...) of a hex string in Python

To calculate hash of hex string in python:

In [1]: import hashlib

In [2]: import binascii


In [3]: hex_string = '3082010a0282010100c3dfee03290fb01e3a4887c5ce0630dcdd8495bfb568b1f61cb8fa8294545b74f06facd215933c53babdd4d066dcb2a713740b9a018c8e0d5fbe1c2a7c793d317c69590c6a34cb1758fd1ff00f36d757c97371d08e9e9efcad1bf6fc8a0c03972296870ad825fa81000fee7aa79c2bcfab0e92d67d3d429d9a25cd6087e3139b17ce1809a6bf83d5ef40ff8e4532412adc15c63eff4eadd264860cb61b381e4f0e8a9e19cf7e39fefdfe9904b1aafe54f12289b930e341dd12b5a41eca1ae9d3556e6c7860a162652a31e256a7fa5720b4cbeb32fa65b67eb0610c6857dfe775d71de5aeb041d7ea0a7c5f335d678280b30dd014e16b37290c4c56d20df737850203010001'

In [4]: hashlib.md5(binascii.unhexlify(hex_string)).hexdigest()
Out[4]: '0c6f3dd3d5d896e0f3f49dfae0437ba1'

In [6]: hashlib.sha1(binascii.unhexlify(hex_string)).hexdigest()
Out[6]: 'fc6d7e7925e18c5bed6314ea112a230948cfde75'

In [7]: hashlib.sha256(binascii.unhexlify(hex_string)).hexdigest()
Out[7]: '73a1b42ca158112e233cd42b0352355ca1ab8cafc2475c2e888285275dbf4ab1'

In [8]: hashlib.sha512(binascii.unhexlify(hex_string)).hexdigest()
Out[8]: '500228880eb22d53cd4cc1c7b42930fef37a4034299b49198bb52cb3ab4bdca3643d952aba662b1b60df723a273af6903bf2bebe9327b0cd53548e3d9a4348f5'

Friday, November 18, 2016

How to extract signing certificates from macOS binary files

Code signing is a macOS security technology that you use to certify that an app was created by you. Once an app is signed, the system can detect any change to the app—whether the change is introduced accidentally or by malicious code. As Apple Developer site says ( click here for more details on code signing) :



code signing allows the operating system to:
  • Ensure that a piece of code has not been altered since it was signed. The system can detect even the smallest change, whether it was intentional (by a malicious attacker, for example) or accidental (as when a file gets corrupted). When a code signature is intact, the system can be sure the code is as the signer intended.
  • Identify code as coming from a specific source (a developer or signer). The code signature includes cryptographic information that unambiguously points to a particular author.
  • Determine whether code is trustworthy for a specific purpose. Among other things, a developer can use a code signature to state that an updated version of an app should be considered by the 
    system to be the same app as the previous version.

We can extract the signing certificates from the macOS binary files using codesign tool.  Run the following command on any macOS binary , dylib or .app to extract the signing certificate from the file.

Steps :

1. Change to tmp directory.
    $ cd  /tmp

2. Run codesign command on the binary or .app to extract signing certificate.
    $codesign -dvvvv --extract-certificates /Applications/Mail.app

    This extracts all the signing certificates from the file and creates 3 files named codesign0, codesign1 and codesign2.  Codesign0 is usually the leaf (signing) certificate, and as many files are written as there are certificates in the signature. The files are in ASN.1 (DER) form. 

To view the contents of the certificates:

To see the details of the certificates which were extracted in DER form, we have use openssl tool. Run the following command to view the contents of certificate


$ openssl x509 -inform DER -in codesign0 -text

The output looks like below:

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            2a:da:71:ba:a7:bd:17:9f
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=US, O=Apple Inc., OU=Apple Certification Authority, CN=Apple Code Signing Certification Authority
        Validity
            Not Before: Apr 12 22:34:35 2013 GMT
            Not After : Apr 12 22:34:35 2021 GMT
        Subject: C=US, O=Apple Inc., OU=Apple Software, CN=Software Signing
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

uP6a2wO7jWLyGW13k+N1zzZZMV4IbV0BHGVTUpN2eJwXCxAelLw2kFZLRC6Y2aYx
ofAcZpSZVHMTtVE4vCSioDA7emWHrMC8FfReMMedoyoE38TPR4Rtn/3/RcOgGaw8
u62PlPm5x8hxNhHt6AG6tHVIgqQqUxoFBZudxkcb9eggcqAbS+W+ZPw4DZr/Q0E=
-----END CERTIFICATE-----





Friday, August 26, 2016

How to fix "This copy of the Install OS X Mavericks application can't be verified. It may have been corrupted or tampered with during downloading." message and install Mavericks or older operating system versions of OS X on VmWare Fusion application

It is very annoying to see  the message "This copy of the Install OS X Mavericks application can't be verified. It may have been corrupted or tampered with during downloading."  when you try to install old releases of Apple OS X operating systems such as Mountain Lion, Mavericks, Yosemite etc. If you are trying to install OS X Mavericks as virtual machine in VMWare fusion or in physical system, then follow below steps to successfully install the operating system.

In VMWARE Fusion.

  1. Create a OSX Mavericks VM by attaching OSX Mavericks Installer to the virtual machine.
  2. Do not Poweron the virtual machine. If powered on automatically after 1st step above then poweroff the VM.
  3. Open Virtual Machine Settings, Goto Advanced Section.
  4. Un check "Synchronize Time" setting.
  5. Start the Virtual Machine to install the OSX Mavericks.
  6. In the OSX Installer app , Launch Terminal.app.
  7. Set the system date to old date as date 102613152013 (Oct/26/2013 13:15).
  8. Quit the Terminal application.
  9. Continue with the installation.

In Physical System:

Prior starting the installation change the system date to old date as said above using terminal app launched from OS X Installer application.

Friday, June 10, 2016

Genrating MD5 for all files in the system


The following command will generate MD5 for all the files in the system.


sudo find ./ -type f -print0 | xargs -0 md5  >>  /tmp/checksums.md5

Wednesday, April 27, 2016

What is com.apple.Dont_Steal_Mac_OS_X (7.0.0) kext is doing on OS X systems ?

When you run kextstat command to see the list of kernel extensions loaded in the system, you might come across kext named com.apple.Dont_Steal_Mac_OS_X (7.0.0) being loaded all the time. You might me wondering what is the role of this kernel extension. com.apple.Dont_Steal_Mac_OS_X  prevents OS X from being used on non approved Intel hardware – as OS X is licensed only for use of approved Apple Intel hardware. This kext is used to control software piracy of OSX on non Apple supported hardwares. Hence its role is to detect and fail the OSX installation on non apple certified hardwares.