For dropbear I needed to satisfy the following requirements.
Disable password access for remote connections
Open port 443 and 2222 for remote connections (443 for when 2222 is blocked)
Allow password access on local connections
Don't open up port 22 for remote connections
I found that you can run multiple dropbear servers and they will co-exist. Here is how I set it up.
The first is for post-boot. The only additional parameter here is -P which defines the pid file location. I renamed it otherwise the second one will overwrite the first rather than appending to it.Code:[shinji@WL-001E8C3E002C sbin]$ cat post-boot #! /bin/sh dropbear -P /var/run/dropbear-local.pid [shinji@WL-001E8C3E002C sbin]$ cat post-mount #! /bin/sh dropbear -b /opt/etc/motd -g -p 2222 -P /var/run/dropbear-remote.pid /opt/etc/init.d/rc.unslung start
The second is post-mount. Note that it could of been put in post-boot as well but I put something into the command line that needs a file from the external device. I will explain each part.
-b defines a banner file to present before login finishes. It will be shown after the username is sent and before the password is requested. It is set to /opt/etc/motd right now so it is on the mounted device. This switch is optional and can be left out. If it is removed then it is save to move the whole remaining command-line to post-boot instead.
-g disables password logins for the "root" user
-s disables password logins globally (all users)
-p defines a port to listen to. You can use this parameter up to 10 times.
Note that the password-less login bit only affects that server. The one running on port 22 still accepts a password so I can still access it locally even if I lose my key.
EDIT: I should add that I recently added a user for the purpose of sftp access by a remote website. I change the original -s to -g. It will still prompt for a password but it will flat out deny it. My sftp user has /opt/libexec/sftp-server setup as the shell so right now ssh brings up a blank screen that they can do nothing at. You can change the -g (in bold above) to -s and it will deny all password logins for that server process.
EDIT: Here is an alternative to the above setup. This is one I have been using lately. The advantage here is that both servers are running immediately and you don't have to wait for the drive to mount for the external one to be usable.
Note I used a banner that is in the /etc folder. To keep it persistent between reboots you have to make sure to save it as part of your flashfs (instructions in the main post) by adding it to your /usr/local/.files file.Code:[shinji@WL-001E8C3DFF31 sbin]$ cat post-boot #! /bin/sh dropbear -P /var/run/dropbear-local.pid dropbear -s -p 2222 -P /var/run/dropbear-remote.pid -b /etc/banner
Now the firewall...
I set it up so that ports 443 and 2222 would be externally accessable. Note that they both route to the same server running on port 2222. 443 is only there for cases where I need to route through a strict firewall that only allows http, https, and standard ssh connections. If you changed the port number in the command for the second server then replace 2222 with your port number. If you don't want port 443 open then remove the line in bold.Code:[shinji@WL-001E8C3E002C sbin]$ cat post-firewall #! /bin/sh iptables -D INPUT -j DROP iptables -t nat -A PREROUTING -i vlan1 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1:2222 iptables -t nat -A PREROUTING -i vlan1 -p tcp --dport 2222 -j DNAT --to-destination 192.168.1.1:2222 iptables -A INPUT -p tcp -m tcp -d 192.168.1.1 --dport 2222 -j ACCEPT iptables -A INPUT -j DROP
If you setup everything right then you will see the following when you run ps axf (if you installed procps)
Note the 2 dropbear servers running.Code:[shinji@WL-001E8C3E002C root]$ ps axf PID TTY STAT TIME COMMAND 1 ? S 0:01 /sbin/init 2 ? S 0:00 [keventd] 3 ? SN 1:07 [ksoftirqd_CPU0] 4 ? S 0:00 [kswapd] 5 ? S 0:00 [bdflush] 6 ? S 0:00 [kupdated] 7 ? S 0:00 [mtdblockd] 58 ? S 0:00 telnetd 64 ? S 0:00 httpd vlan1 70 ? S 0:00 klogd 71 ? S 0:03 [dnsmasq] 73 ? Ss 0:00 nas /tmp/nas.lan.conf /tmp/nas.lan.pid lan 76 ? S 0:00 [khubd] 88 ? S 0:01 [usb-storage-0] 90 ? S 0:00 [scsi_eh_0] 114 ? Ss 0:00 watchdog 117 ? Ss 0:00 \_ ntp 116 ? S 0:00 radvd 124 ? S 0:00 dropbear -P /var/run/dropbear-local.pid 146 ? S 0:00 [kjournald] 147 ? S 0:00 [kjournald] 149 ? Ss 0:04 /usr/sbin/nmbd -D 151 ? Ss 0:00 /usr/sbin/smbd -D 155 ? S 0:00 dropbear -b /opt/etc/motd -s -p 2222 -P /var/run/dropbear-remote.pid 4238 ? Ss 0:00 \_ dropbear -b /opt/etc/motd -s -p 2222 -P /var/run/dropbear-remote.pid 4239 pts/0 Ss 0:00 \_ -sh 4242 pts/0 R+ 0:00 \_ ps axf 180 ? S 0:00 /sbin/syslogd -m 0 -O /opt/var/log/syslog.log -S -l 7 -s 0 186 ? Ss 0:00 /opt/sbin/cron 4176 ? S 0:00 upnp -D -L br0 -W vlan1
Right now if someone accesses the router remotely then they will get the following.
This would make it kinda fruitless to try to gain access that way unless there was an exploit for the dropbear server.Code:compton:/home/shinji257> ssh -o Port=2222 shinji@xx.xx.xx.xx ..:: Elite Systems Remote SSH Access ::.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is a restricted server. Unauthorized access is strictly prohibited. ALL CONNECTIONS ARE LOGGED. Permission denied (publickey).




