3

Folks, I wanna find a generic way to run a (simple bash) script on boot sequence of a router with embedded Linux. I have read about ways to do this on devices like:

  • DD-WRT
  • OpenWRT
  • any NAS like D-Link DNS-323

But I was wondering if it could be done too on generic embedded devices, like a (mostly simple) DSL router. Possible reasons for doing this:

  • Generic method of updating public IP of the device to DNS servers that allow it (I found some that allow it via simple http commands).
  • Send any data to FTP server, like public IP of the device.
  • Simple way to tell «The device is ON» to a remote host, like executing "telnet MySSHServer 22" to a SSH home server.
  • Add network rules, ARP list, disable any network interface (ethx)... etc.
  • Learning & Investigation ;-)

I have heard of some people doing this with some DSL router by keeping these steps:

  1. Save all router (including configuration) data to a firmware-like file.
  2. Edit that firmware file (i.e: modifying "/etc/rc.local" file).
  3. Restoring the modified firmware file to the router.

Is there a better way that anyone knows of?

2 Answers 2

3

The answer will depend on the device, as there is no such thing as a "generic" router. There are a couple of approaches:

  • Replace the stock firmware with an open package (DD-WRT, OpenWRT, Tomato, etc)
  • Hack the stock firmware (the 3-step process you describe)
  • Use features in stock firmware (may be undocumented or nonobvious)

I have noticed in several routers' stock firmware that there is a page buried in the Administration area of the interface that just has a text box that uses TFTP or Telnet to run a shell on the router. It may be labelled "test connection" or something. If you can create or modify a file from that interface you may be able to change the configuration. You may have to bend the rules, for example, if the text box only accepts IP address and runs a 'ping' on each, you may be able to provide a string like

127.0.0.1&&/sbin/sshd& 

Then probe the device with nc/nmap to see if the ssh service is available (port 22).

2
  • Thanks for answering. Saddly, I don't know of any open firmware that works for DSL routers. But those are good ideas. And I could automate your TFTP trick with iMacros ot AutoHotkey. :-) Jan 22, 2014 at 0:14
  • By a "DSL router", I assume you mean a combined DSL modem/router with multi-port switch and/or wireless AP function. None of the open router projects will support that hardware, but... you don't HAVE to use the router function built into the DSL modem/router. You can simply use it as a DSL modem and set the router function to simply pass-thru, and then use an additional piece of hardware that can be hacked for the router/AP/Switch function. You'll be much happier with this approach if you are considering advanced configuration like this, over attempting to hack the combo hardware.
    – Codex24
    Jan 23, 2014 at 18:08
2

I have found a tool that could be useful: Firmware Modification Kit.
It is a pack of tools that open (expands) the full contents of a .bin firmware file to a directory named "fmk" and allows you to edit it, so you can later pack it again to .bin file with another included tool.
So until now the process for something like a router is:

  1. Download .bin firmware file.
  2. Unpack, edit and repack it to your custom .bin using Firmware Modification Kit.
  3. Flash it onto your router.

I would prefer to do this:

  1. Extract actual router configuration and data (including ports forwarding, wireless config, passwords and so on) to .bin firmware file.
  2. Unpack, edit and repack it to your custom .bin using Firmware Modification Kit.
  3. Flash it onto your router.

but I have not found a way, till now. I don't even know if it is possible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .