Secure your router's access

There are some possibilities to grant access to the router (or to any PC/Server):

  1. ask for nothing: anybody who can establish a connection gets access
  2. ask for username and password on an unsecured connection (e.g. telnet)
  3. ask for username and password on an encrypted connection (e.g. SSH) (e.g. by following firstlogin)
  4. ask for username and merely a signature instead of a password (e.g. SSH with signature.authentication)

If you ask for username/password, an attacker has to guess the combination. If you use an unencrypted connection, he could eavesdrop on you and obtain them.

If you use an encrypted connection, any eavesdropper would have to decrypt the packets first. This is always possible. How long it takes to decrypt the content, depends on the algorithm and key length you used.

Also, as long as an attacker has network access to the console, he can always run a brute-force attack to find out username and password. He does not have to do that himself: he can let his computer(s) do the guessing. To render this option improbable or even impossible you can:

  1. not offer access from the Internet at all, or restrict it to certain IP addresses or IP address ranges
    1. by letting the SSH server dropbear and the web-Server uhttpd not listen on the external/WAN port
    2. by blocking incoming connections to those ports (TCP 22, 80 and 443 by default) in your firewall
  2. make it more difficult to guess:
    1. don't use the username root
    2. don't use a weak password with 8 or less characters
    3. don't let the SSH server dropbear listen on the default port (22)
  3. but by using the combination of
    1. username different than root
    2. tell dropbear to listen on a random port (should be >1024): Administration → Services → Dropbear SSHd → Port
    3. public key authentication. Your public keys can be specified in Administation → System → SSH-keys. An older guide to DropBear SSH public key authentication has detailed information on generating SSH keypairs which include the public key(s) you should upload to your configuration.

SSH Keys

System Hardening

Network hardening

Create a non-privileged user in OpenWrt

Example that adds a user called nicolaus:

opkg update
opkg install shadow-useradd
useradd nicolaus
However, you can't ssh to this user yet. To enable ssh access, you should make a password for that user, create his home folder and most importantly indicate the shell of that user:
passwd nicolaus
mkdir /home/nicolaus
vi /etc/passwd
   nicolaus:x:1000:1000:nicolaus:/home/nicolaus:/bin/ash

Allow temporary privileged access using sudo

First, you should install sudo:

opkg install sudo
Additionally, you must allow your desired user by manipulating '/etc/sudoers' by tool visudo. Now you can follow ONE of the methods below to choose how the user should be able to run commands as root:

Method 1: 'sudo'ing by any user with root password (more secure)

In this method any user can temporarily run commands as root only if he knows the root password. This way when the user runs a command with sudo he should enter root's password instead of his password.

For enabling this method you should open the file '/etc/sudoers' by entering the commnad

visudo
Then uncomment the 2 lines below in that file and then save
## Uncomment to allow any user to run sudo if they know the password         
## of the user they are running the command as (root by default).            
Defaults targetpw  # Ask for the password of the target user                 
ALL ALL=(ALL) ALL  # WARNING: only use this together with 'Defaults targetpw'
This method is more secure because you don't need to protect both root and privileged (sudoer) users to keep the whole system safe.

One usecase can be allowing remote ssh with password from WAN: For more security (still less than RSA key) you can only allow users other than root to ssh with their password (optionally on a custom port) from WAN. And for even more security you can request root's password after running sudo. Therefor in this scenario a hacker should find 3 different strings user's username, user's password and root's password to get full access to the system. Even if the user's account get compromised, then the intruder still can't damage your system because he doesn't have root password yet.

Method 2: 'sudo'ing with the user's password

In this method, after logging in by the desired user, when you enter sudo you should enter the user's password again. The end result is similar to how you use sudo in Ubuntu or other popular Linux disros, but this method doesn't utilize group 'sudo' for this purpose.

For enabling this method you should also enter the command

visudo
And then add a line allowing your user, under comment "## User privilege specification":
##                                                                           
## User privilege specification                                              
##                                                                           
root ALL=(ALL) ALL                                                           
nicolaus ALL=(ALL) ALL                                                           

Method 3: 'sudo'ing with the user's password if he is member of group 'sudo' (needs installing some packages)

This method is very similar to Method 2, except that it allows any member of group 'sudo' to use sudo with their own password. This method is exactly the same one used in Ubuntu and other popular Linux distros to allow 'sudo' access for a user.

For activating this method first you should allow group 'sudo' to use command sudo by entering

visudo
And then uncomment the line below:
## Uncomment to allow members of group sudo to execute any command           
%sudo ALL=(ALL) ALL 
Second you should create group 'sudo'. You can do it by manually editing '/etc/group' but it's more standard to install and use tools for this purpose:
opkg install shadow-groupadd
groupadd --system sudo
And finally add your current user to the group 'sudo'. You can directly append your user to '/etc/group' but again it's better to use usermod:
opkg install shadow-usermod
usermod -a -G sudo nicolaus
This method is more convenient because you can simply allow sudo access for any user you want, just by usermod -a -G sudo <USER> but takes more space (for installing new packages) than method 2 which may be more suitable for systems with very limited space.

ppp

If you are using ppp in the default configuration with username and password in /etc/config/network, then the unprivileged user can read it from pppd's command line (with e.g. ps w). To prevent that, you can add "user <username>" to /etc/ppp/options and "<username> * <password>" to /etc/ppp/{chap|pap}-secrets and then remove the username / password options from uci configuration.

Of course /etc/ppp/{chap|pap}-secrets should not be world readable:

chmod go-rw /etc/ppp/chap-secrets

WebUI

If you require remote web access, OpenWrt can be accessed via HTTPS (TLS) instead of the unencrypted HTTP protocol. If HTTPS is not secure enough for your, consider disabling the existing (unencrypted) web access and either

  • Tunneling your connection via SSH, OR
  • Set up SSL protected access with uhttpd using the following steps (verified with 10.3)
    1. Install cert generator and web server TLS plugin:
      opkg install px5g uhttpd-mod-tls
    2. Optionally instruct the server to not listen on plain HTTP anymore:
      uci delete uhttpd.main.listen_http
      uci commit
      … or rebind it to LAN only:
      uci set uhttpd.main.listen_http=192.168.1.1:80
      uci commit
    3. Restart the web server to trigger certificate generation:
      /etc/init.d/uhttpd restart
    4. Optionally remove the key generator:
      opkg remove px5g
  • If you are running older software (8.x) see this https://forum.openwrt.org/viewtopic.php?id=18288 forum thread.

to do: indicate how mandatory client cerficate checking could be set up

If you require remote SSH access, follow the hardening instructions on SSH mentioned above.

Back to top

doc/howto/secure.access.txt · Last modified: 2014/01/16 03:24 by digitsm