Last active
December 17, 2015 02:19
-
-
Save pbartunek/5535292 to your computer and use it in GitHub Desktop.
Quick and dirty script for converting decrypted Keychain file to CSV (which can be imported into other password manager).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Usage | |
| dump decrypted keychain: | |
| security dump-keychain -d keychain_name.keychain > decrypted_keychain | |
| convert: | |
| keychain.rb decrypted_keychain [keychain.csv] | |
| Remember to securely remove files with decrypted passwords when not needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| require 'csv' | |
| class KeychainFile | |
| def initialize(file_name) | |
| @file = File.new(file_name) | |
| @keychain = {} | |
| end | |
| def parse | |
| prev_line = '' | |
| last_accountname = '' | |
| pass = '' | |
| @file.each do |line| | |
| if line =~ /0x00000007.*="(.*)"/ | |
| @keychain[$1] = '' | |
| last_accountname = $1 | |
| elsif prev_line =~ /data:/ and line =~ /"(.*)"$/ | |
| pass = $1 | |
| @keychain[last_accountname] = pass | |
| end | |
| prev_line = line | |
| end | |
| end | |
| def to_csv(file_name) | |
| CSV.open(file_name, "wb") do |csv| | |
| @keychain.each do |key, value| | |
| csv << [key, value] | |
| end | |
| end | |
| end | |
| def print_keychain | |
| @keychain.each do |key, value| | |
| puts "#{key}: #{value}" | |
| end | |
| end | |
| end | |
| input_file = ARGV.shift | |
| output_file = ARGV.shift | |
| k = KeychainFile.new(input_file) | |
| k.parse | |
| k.print_keychain | |
| k.to_csv(output_file) if output_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment