Reset your forgotten iPhone4 SSH password.

Wonderful, I SSH’d to my iPhone 4 this morning to find out I forgot the mobile and root account passwords. Not to worry! We can fix this!

Ok this is relatively simple the only problem I ran into was that MobileTerminal crashes under iOS4 so I had to figure out another way to edit the files in question as well as come up with the crypto hashes, but lets not get ahead of ourselves.

First we need to make some backups, PLEASE PLEASE PLEASE do not skip this part!There is a potential to really screw things up if you make a mistake and have a backup. Its easy to correct by restoring the original file. Proceed at your own risk if I outline something here you do not understand find someone who is more versed in unix to assist you, or shoot me an email and I’ll do my best to help you out.

Since we cant use MobileTerminal we need another way, head into the Cydia Store and find an application called iFile and install it to your device. Fire up iFile and browse to /etc you can do this by clicking the button in the top left until your at the root of the filesystem / then finding the etc folder and clicking it.

Now find the file master.passwd, don’t open it yet, we first need to make that backup click the edit button in the top right of the screen and select the master.passwd file, there will be a red checkmark showing you have it selected, now hit the button in the bottom right (the arrow coming out of the box). And select Copy/Link. You now have the file copied to iFile’s clipboard, click the done button (top right). Followed by the home button, (little house 2nd from right on the bottom).

Hit the edit button again but before you select anything click the bottom right button (the arrow coming out of the box) and click Paste. We now have our backup.

Navigate back to the /etc folder. open up the master.passwd file the 2 lines we are interested in are:

root:UI48wgPSS/M1k:0:0::0:0:System Administrator:/var/root:/bin/sh
mobile:UI48wgPSS/M1k:501:501::0:0:Mobile User:/var/mobile:/bin/sh

Before you go thinking you have my Hashes I’ve replaced both of them with the hash for the Password of Password1 (not my password).

To get new hashes we need to generate one, head over to functions-online.com’s crypt function: http://www.functions-online.com/crypt.html

$str is your new password
$salt is an optional string to base the hashing on, when I first learned this I was taught to use a salt of ‘Ul’ others might work but I’ve always stuck with Ul since I know it works. generate your new passwords and then get them onto your device somehow, I used http://myphonedesktop.com/ which allows me to transfer things (images, text etc) to my phone pretty easy. you could also simply generate the crypto hash in MobileSafari on your phone then simply copy paste it over, you want to replace the part between the
::’s I;ve highlighted it for you. now just save the file and SSH to your phone with your new password.

root:UI48wgPSS/M1k:0:0::0:0:System Administrator:/var/root:/bin/sh
mobile:UI48wgPSS/M1k:501:501::0:0:Mobile User:/var/mobile:/bin/sh

If it still does not work we should restore your backup from the mobile users home directory (/var/mobile/master.passwd) back over the /etc/master.passwd file and try again.

This works because most applications on the iPhone are executed with root permissions giving the iFile application the ability to edit a file only the root user should have access to. this is also why its very important to always reset your password if your going to jailbreak your iPhone. all it takes is someone sniffing out your iPhone on an open wifi and figuring out they can use the default password of ‘alpine’ to get full access to your device while its in your pocket.

No tips yet.
Be the first to tip!

Like this post? Tip with bitcoin!

1KjVEx57oCL7Exuc6RCuVPhbPaWC4E34ba

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Bash History

If your anything like me you spend a lot of time at a bash terminal, weather I’m upgrading this very WordPress blog, or any other sites I run I usually do so over an SSH connection.

One thing I come to use quite often is my history. often times I don’t quite recall which switches I used to run a command I may have used yesterday. by typing “history” at the command line I get the past 1000 commands (500 by default on most systems) I ran. while thats a bit much lets say I wanted to recall where I saved the last tar archive I created. a simple “history | grep tar” will show all the lines that contain the word tar.

now for some useful options for how your systems history functions, I kicked my system up to record the last 1000 commands you can adjust this by making some changes to the environment in your personal bash configuration file (~/.bashrc) or in the global bash configuration file (/etc/bash.bashrc).

export HISTCONTROL=ignoreboth
export HISTSIZE=1000

the first line will tell bash to ignore lines that match the last command you ran so if you run ps -awfux 3 times in a row (even if its over a couple hours) it will only record a single instance of that command.

the second line defines the size of the history file, in my case I chose to save the past 1000 lines.

No tips yet.
Be the first to tip!

Like this post? Tip with bitcoin!

12Z6uAhD4ffm7zKikggCspczMSVgmaEBuu

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Changing the default MOTD for Ubuntu

so you have your fresh new Ubuntu system and you log in via ssh to be greeted with

“Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

bla bal bla”

so you fire up vim and change the good ol /etc/motd to sometime a little more along the lines of threating anyone who misuses the system with the wrath of IT.

super your new MOTD works great untill you reboot the system. heres a little secret about Ubuntu notice the first line of the MOTD when you logd in the first time? The line about the kernel version and other system information? Well thats all there because Ubuntu generates the /etc/MOTD file during system startup so any changes you make to this file will be lost on the next reboot. Solution? Ubuntu generates the first line then appends the conents of /etc/MOTD.tail to the end and saves it as /etc/MOTD.

so to use your new MOTD you need to save your message to /etc/MOTD.tail

No tips yet.
Be the first to tip!

Like this post? Tip with bitcoin!

14wFmzChUVoBa77QgvGLv79nA5G7SrZmQk

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Disable SSH Password Authentication for added security.

A while ago I wrote a bit about Shared Key Authentication for SSH, and discussed a bit about the benefits of enabling this on your own servers or even desktops. one of which is protecting your server against brute force attacks. However we never discussed that in order for your system to be truly protected from a brute force attack on your password you need to disable password authentication on your server. Please note before attempting this make sure that your keys work because if your configuring your server remotely and you disable password authentication you will lock yourself out. Once you are sure that you can log into the remote host using your private key, we can safely disable the user name/password authentication.

The procedure to set this up is extremely simple. I’ll be showing you this on a Ubuntu Server install with OpenSSH but the procedure is similar on other setups. On a Ubuntu server the file will be located in /etc/ssh/sshd_config. your going to want to add the following to the config file (or change the values if they already exist.

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Once you save the changes you’ll need to reload the SSH server with the following command.

Update 07/17/2012: Thanks to a reeder who pointed out something I missed, Ensure you’ve enabled public key authentication, I’ve noted that most often this is enabled by default but if its not YOU WILL lock yourself out. ensure the following is set in your configuration.

PubkeyAuthentication yes

And then reload the SSH Service.

User@Host:~$ /etc/init.d/sshd reload

Thats it, your server should no longer accept user name/password authentication.

 

No tips yet.
Be the first to tip!

Like this post? Tip with bitcoin!

14qA8oVoK4RsBV3Qv7zbD9ZgnVUg9mzFXU

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Shared Key SSH Authentication

If you’re like me, you find yourself connecting to the same servers 15-20 times a day. Why not set up Shared Key Authentication? It makes establishing an SSH connection much easier but also makes setting up scripting much easier as well.

However, before skipping on down to the instructions, please make note of the following. If you run 20 servers and allow all 20 servers to use Shared Authentication to communicate with all other 20 servers, and just ONE of those servers gets compromised, all your servers are now compromised.

One way to help avoid this is to disable Password authentication all together, brute force hacking attempts on your password are now rendered useless.

Its a fairly good idea not to overuse Shared Key’s.

For example, given the situation above, is it really necessary for all 20 machines to communicate with all the other machines? Only allow machines to trust other machines if they really need to.

Also its a very good idea NOT to allow the root user the ability to use Shared key Authentication. Its better to connect using a normal account and set up the root from there.

With the preliminaries out of the way, lets get down to business. This is actually VERY easy to set up.

Lets say you have two servers you want to trust each other. To keep things simple, let’s name them Bart and Lisa. We’ll say I have an account on both machines called Brandon.

Here’s how you start:

brandon@bart:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/brandon/.ssh/id_rsa): [enter]
Enter passphrase (empty for no passphrase): [enter]
Enter same passphrase again: [enter]
Your identification has been saved in /home/brandon/.ssh/id_rsa.
Your public key has been saved in /home/brandon/.ssh/id_rsa.pub.
The key fingerprint is:
55:44:80:bb:df:e8:db:2e:fe:fb:bf:aa:c5:c2:c4:0f

Ok, when it asks you where to save the file just accept the default and hit enter. Do the same when prompted for a passphrase. If you don’t do this, you’ll have to enter a password every time you use the key pair and void the entire reason were setting this up. =)

Fortunately,that was the hardest part.

Your next step will be to get the public key over to the server, named Lisa, that we are connecting to. You can do this pretty much anyway but I just scp’d it over.

brandon@bart:~$ scp .ssh/id_rsa.pub lisa:.ssh/authorized_keys

Now the above will only work if Lisa is on the local network, otherwise you’ll want to replace Lisa with the server’s IP address, like so:

brandon@bart:~$ scp .ssh/id_rsa.pub 1.1.1.2:.ssh/authorized_keys

That’s it. Now lets try to SSH over.

If you did everything right, you shouldn’t be prompted for a password when you SSH over to Lisa from Bart

brandon@bart:~$ ssh lisa

or…

brandon@bart:~$ ssh 1.1.1.2

and you should be presented with!

brandon@lisa:~$

Now that’s cool.

Also note that this is a one way trust. Meaning Lisa trusts Bart to connect to her, but Bart still doesn’t trust Lisa. If you want to establish a two way trust, simply repeat the same instructions the other way around.

If you have any questions regarding this process please feel free to leave a comment and I’ll do my best to answer your question.

No tips yet.
Be the first to tip!

Like this post? Tip with bitcoin!

1PFED9uZCbpFJNrNddp1ELuSaEsX3jVjJj

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.