Manage the VNC / screen sharing password remotely

Nov 16, '07 07:30:02AM

Contributed by: Anonymous

I've just upgraded my son's Mac Mini to 10.5, and turned on the Screen Sharing and ssh server after the initial install. In 10.4, I had long ago configured the "hidden" ARD VNC server, though alas I now find I've forgotten the password I set at that time. My son's gone to bed, but I want to play on his Mac -- what to do?

It seems that the "new" screen sharing feature is basically the same as 10.4's, and the VNC password is in the same place: /Library » Preferences » com.apple.VNCSettings.txt. The password is obfuscated by XORing it with a fixed key, so you need a little perl magic to view / set it.

[robg adds: Read on for the how-to. Please note that this isn't a security concern, as it assumes you've got ssh access to the machine in question, as well as the ability to execute root privileges on that meachine -- and if you've got both of those things, well, you've pretty much got the machine anyway.]

To show the current password, do this:

$ sudo cat /Library/Preferences/com.apple.VNCSettings.txt
7F513D02E4A8C5E2FF1C39567390ADCA
$ sudo cat /Library/Preferences/com.apple.VNCSettings.txt | perl -wne 'BEGIN { @k = unpack "C*", pack "H*", "1734516E8BA8C5E2FF1C39567390ADCA"}; chomp; @p = unpack "C*", pack "H*", $_; foreach (@k) { printf "%c", $_ ^ (shift @p || 0) }; print "\n"'
hello
$
To set a new password (the obfuscated version is echoed back, in addition to being written to the VNCSettings file):
$ perl -we 'BEGIN { @k = unpack "C*", pack "H*", "1734516E8BA8C5E2FF1C39567390ADCA"}; $_ = <>; chomp; s/^(.{8}).*/$1/; @p = unpack "C*", $_; foreach (@k) { printf "%02X", $_ ^ (shift @p || 0) }; print "\n"' | sudo tee /Library/Preferences/com.apple.VNCSettings.txt
hello
7F513D02E4A8C5E2FF1C39567390ADCA
$
Of course, hello is a very poor password, and is only an example here!

[robg adds: Any errors in the above are my fault; I *think* I got it all coded correctly in Geeklog-speak, but I may have made an error. I tested the decoding command, which works fine, but not the changing command.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20071103011608872