If and when you can get shell on the device, you will probably not be able to use apt
to install software. apt
is a package manger that several Linux distributions include, namely Debian and its derivatives like Ubuntu. apt
has a configuration file that points to servers that contain software built for your distribution. For example, Ubuntu uses the file /etc/apt/sources.list
to find the servers containing software that will work on specifically your version of Ubuntu.
Dynamically linked software must be linked against your existing (on your machine) libraries in order to work properly. There's a team of people behind the scenes making this happen. Many of them them are doing it just for the love of the sport.
apt
is simply a package manager. It looks at some servers you've told it to look at, then downloads and attempts to install some software you ask it to. On most common distributions like Debian or Ubuntu, that list of servers has been preconfigured. If you run apt
with the same configuration on a different distribution, the software downloaded will fail to run because that machine doesn't have the same libraries (or architecture).
There may be some exceptions.
Maybe a source that you can configure that downloads and installs static builds of software. Static builds don't require you to have a specific library, only a specific architecture. This requires that you install a static build of apt
or another package manager and are actually able to find one of these sources. I'm personally not aware of any, but haven't looked.
DD-WRT and friends (completely custom firmware for routers -- none of the original firmware remains) have their own package managers. These can be used to install a limited range of software. This is not what you are asking about, but I thought it was good to include.
All of the above is informational.
Take it in, but ignore it in regards to your main question.
can I manually 'install' anything inside the firmware/inside the router/inside the rootfs.
There are 2 ways I can think of to "install" or run a program on your router.
1: Get a shell, upload to /tmp/ or external storage
Get a shell. Preferably a root shell.
Maybe there's an existing vulnerability that will help you get a shell.
Maybe you can crack open the router and discover a serial connection that prompts you with a login or a straight up shell?
If you can get a shell on the router, you can probably download some statically linked software to /tmp/
. A tool like curl, wget, an ssh server supporting scp, tftp, ftp, or a mechanism present on the web interface to upload a file may help you.
Once you get a file on the system, you can hope the tool that helped you get it there made it executable. See chmod. The command ls -la
will help you determine if your file is executable. If you can run chmod +x YOUR_FILE
, you're in business. Run the program.
This approach has the limitation that you must store your file in RAM. Statically linked binaries are large. SOHO routers don't have much RAM beyond what they need. If your router has a USB port, put your binary (program) on a flash drive and plug it in. With the right formatting, your router should see it. You may need to do some more research to figure out where it is or how to mount it. Even this way, you may run in to RAM limitations. It probably won't be obvious if this is the case. There typically isn't a simply massage stating as much.
2: Modify and flash the firmware
This is a very big rabbit hole.
It usually involves rebuilding the filesystem archive format.
Sometimes companies use custom variations of squashfs
.
sasquatch
in conjunction with binwalk
is often used to extract from these filesystems.
You'll have a harder time putting the filesystems back together.
After that You'll have to repackage in to the (most likely) proprietary firmware format.
This will be at a minimum checksummed and possibly signed.
In its most simplistic form, signing means that the vendor can prove that they provided the firmware and that you didn't.
If you can modify the firmware, you either have to upload it through some interface (web server, tftp, etc), or flash it directly. The former presents a high risk of bricking your device.
3: Conclusion
- Compile a static binary for the router's architecture
- Try to get a shell
- Figure our how to upload a binary
- Hope there's enough RAM for it
- A simple "Hello World" would be a good start
- Make it executable
- Execute your binary
- If you have a shell, you might even be able to see it
Future Askings (asked or researched)
- How does one search for existing vulnerabilities that provide shell on a platform?
- What mechanisms prevent one from downgrading firmware on a router?
- How is it possible to determine the architecture of my machine?
- How can a program be statically linked in Linux?
- Can statically linked programs be reduced in size?