Securing OpenWRT
Enabling HTTPS:
Install Required Packages:
opkg update
opkg install luci-lib-px5g px5g-standalone libustream-openssl luci-ssl
opkg install luci2. Restart httpd server
/etc/init.d/uhttpd restartThis will generate the certificate:
about to generate keys
Generating RSA private key, 2048 bit long modulus
Generating selfsigned certificate with subject 'C=ZZ;ST=Somewhere;L=Unknown;CN=OpenWrt;' and validity 2016-09-19 19:52:32-2018-09-19 21:59:32
keys generatedOptionally remove the key generator:
opkg remove px5g3. Disable or rebind router listening on plain HTTP:
Disable:
uci delete uhttpd.main.listen_http ; uci commitOr rebind all
LANconnections to redirectHTTPtoHTTPS
uci set uhttpd.main.listen_http=192.168.70.1:80
uci set uhttpd.main.listen_https='192.168.70.1:443'
uci set uhttpd.main.redirect_https='1'
uci commitRestart
HTTPD
/etc/init.d/uhttpd restartThis should be reachable via HTTPS now. Done!
Setting up the root password:
LuCI
Navigate to
LuCI-->System-->Administration-->Router PasswordEnter new password
Click
Save & Apply
CLI
passwdDone!
SSH Access:
Do not offer access from the Internet at all
Create a non-privaleged user:
Add user:
opkg update
opkg install shadow vim
useradd USERNAMEChange user
password:
passwd USERNAMECreate user
home:
mkdir -p /home/USERNAME
chown USERNAME: /home/USERNAME
vim /etc/passwdAdd entry:
USERNAME:x:1000:1000:USERNAME:/home/USERNAME:/bin/ashAdd user to
sudo:
Install sudo:
opkg install sudoModify sudoers file to use sudo with root password prompt:
visudoor
vim /etc/sudoersUncomment the following lines:
## 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.
Add
SSHKey to newUser:
mkdir -p /home/USERNAME/.ssh
touch /home/USERNAME/.ssh/authorized_keys
vim /home/USERNAMs/.ssh/authorized_keysAdd Public Key to file
Modify Port & Authentication
Navigate to
System-->AdministrationClick on
SSH AccessChange
PortDisable
Password authenticationDisable
Allow root logins with passwordSave & Apply
Done!
Disable IPV6:
uci set 'network.lan.ipv6=off'
uci set 'network.wan.ipv6=off'
uci set 'dhcp.lan.dhcpv6=disabled'
uci commit
/etc/init.d/odhcpd disableLast updated