Introduction
Unknown to many, the official Netgear WNDR4300 firmware is based on OpenWrt. The procedure described here involves making use of the OpenWrt repos to have openvpn up and running. It also involves recompiling the official firmware. So, this is certainly not for the faint hearted and expects you to have a good knowledge of Linux.
Stock Firmware Info
From the file /etc/banner on the router (I will tell later how you can telnet to the router), it is clear that stock firmware is based on OpenWrt kamikaze (bleeding edge, r18571). Based on http://wiki.openwrt.org/about/history, the closest available stable release is Kamikaze 8.09.2 r18801, released in 2010 January. Also, as there is a file /lib/ar71xx.sh in the stock firmware, it indicates that the arch is ar71xx.
Stock Firmware Compilation And Installation
$ sudo apt-get install gcc-4.1 g++-4.1 libncurses-dev zlib1g-dev gawk flex $ cd /usr/bin $ sudo ln -s gcc-4.1 gcc $ sudo ln -s g++-4.1 g++ $ sudo ln -s gcc cc
$ unzip /path/to/WNDR4300-V1.0.1.42_gpl_src.zip $ bunzip2 WNDR4300-V1.0.1.42_gpl_src.tar.bz2 $ tar -xvf WNDR4300-V1.0.1.42_gpl_src.tar $ ls README.build wndr4300-GPL.git wndr4300_gpl_source_list.txt WNDR4300-V1.0.1.42_gpl_src.tar
#!/bin/sh /etc/rc.common START=99 start() { if [ -x /jffs/startup.sh ]; then /jffs/startup.sh fi }
Also make the init script executable
$ chmod +x wndr4300-GPL.git/target/linux/wndr4300/base-files/etc/init.d/startup
Now, you can write any commands in /jffs/startup.sh and they will be executed whenever the router boots up.
Logging in to the router (using Telnet)
You can use the software at https://code.google.com/p/netgear-telnetenable/ to telnet to the router. The instructions for doing this are pretty straight forward.
OpenWrt wiki page http://wiki.openwrt.org/toh/netgear/telnet.console also mentions other ways of accessing the telnet console but I haven't tried them as netgear-telnetenable worked like a charm.
Setting up ipkg
$ python telnetenable.py <IP> <MAC> <Username> <Password> BusyBox v1.4.2 (2013-12-26 18:08:07 UTC) Built-in shell (ash) Enter 'help' for a list of built-in commands. _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M KAMIKAZE (bleeding edge, unknown) ------------------ * 10 oz Vodka Shake well with ice and strain * 10 oz Triple sec mixture into 10 shot glasses. * 10 oz lime juice Salute! --------------------------------------------------- root@WNDR4300:~# tftp -g -r libopenssl_0.9.8i-3.2_mips.ipkroot@WNDR4300:~# ipkg install libopenssl_0.9.8i-3.2_mips.ipk root@WNDR4300:~# tftp -g -r libopenssl_0.9.8i-3.2_mips.ipk root@WNDR4300:~# ipkg install wget_1.11.4-1_mips.ipk
root@WNDR4300:~# echo -e "dest root /jffs\nsrc openwrt http://downloads.openwrt.org/kamikaze/8.09.2/ar71xx/packages" > /etc/ipkg root@WNDR4300:~# export PATH=/jffs/bin:/jffs/sbin:/jffs/usr/bin:/jffs/usr/sbin:$PATH root@WNDR4300:~# ipkg update
Installing SSH
root@WNDR4300:~# ipkg install openssh-server
As a matter of fact, you can install any of the packages in http://downloads.openwrt.org/kamikaze/8.09.2/ar71xx/packages/ and they should most probably work.
#!/bin/sh /etc/rc.common # Copyright (C) 2006 OpenWrt.org START=50 start() { for type in rsa dsa; do { # check for keys key=/jffs/etc/ssh/ssh_host_${type}_key [ ! -f $key ] && { # generate missing keys [ -x /jffs/usr/bin/ssh-keygen ] && { /jffs/usr/bin/ssh-keygen -N '' -t $type -f $key 2>&- >&- && exec /etc/rc.common "$initscript" start } & exit 0 } }; done mkdir -p /var/empty chmod 0700 /var/empty /jffs/usr/sbin/sshd -f /jffs/etc/ssh/sshd_config } stop() { killall sshd }
root@WNDR4300:~# /jffs/etc/init.d/sshd start
Installing OpenVPN
root@WNDR4300:~# ipkg install openvpn
root@WNDR4300:~# LD_LIBRARY_PATH=/jffs/usr/lib /jffs/usr/sbin/openvpn --daemon --cd /jffs/etc/openvpn --config amaram.vpn.conf --log /tmp/openvpn.log
Configuring the launch script
We finally have to write the /jffs/startup.sh script to automate setting up of ipkg and starting ssh and openvpn servers whenever the router reboots. Here is the content of /jffs/startup.sh script that I am using:
# Set PATH echo "export PATH=/jffs/bin:/jffs/sbin:/jffs/usr/bin:/jffs/usr/sbin:\$PATH" >> /etc/profile # Set LD_LIBRARY_PATH echo "export LD_LIBRARY_PATH=/jffs/usr/lib" >> /etc/profile # Setup ipkg echo -e "dest root /jffs\nsrc openwrt http://downloads.openwrt.org/kamikaze/8.09.2/ar71xx/packages" > /etc/ipkg.conf # SSH authorized_keys mkdir -p /tmp/.ssh echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6emYnBS1NLG1j1HsuMb3X6nI0+jWrpRvjhBSuB9q4lOO4NpxNdgCiDd7+qoYGLd4fE7hy/GYN1TvXXuDtDZPnuIOg8XaRxZg5wSDZV0nRsDNKGH8NikGzvxGEI9KeqBNrl+iRLS/ipl0QRmLpNScwXWOW6h9eP+S7GaL6Y56YyL+uwuUg14ow2nA2YFYQKLRXM20EiEm4C419XknYHsIG16ix2AamrH1CGJrQCo0m6f1Kf5OUjX8gSQvaToaD2J5NFbdGfaykW/RvmQH+37PlVnfE24SVrZ0ylRHvnqMTgSE1ZQ54U/zAbRpwB3vpEQCdW/kNz/gLwzbUHW0yzEw+w== rahul@rahul-laptop" > /tmp/.ssh/authorized_keys # Start SSH /jffs/etc/init.d/sshd start # Start openvpn LD_LIBRARY_PATH=/jffs/usr/lib /jffs/usr/sbin/openvpn --daemon --cd /jffs/etc/openvpn --config amaram.vpn.conf --log /tmp/openvpn.log
Add new comment