Emulate console login request to router

0

I am trying to enter into my router's settings from the command line in my Ubuntu machine. It's not one of those expensive router models that has a specialised console port, but rather a "normal" for families and such, an ASUS. I don't think the model is relevant. What I want to do is basically the equivalent of opening your browser and typing the default gateway address, and input the username and password. Is there a way to emulate such a process with.. say python or curl?

What have I tried

  • I tried going in chrome in the developer tools and in the network tab to see what request does my browser make and what kind of response do I get from my router, and it doesn't really make sense. I have never seen something like it and it only confused me more.
  • I tried sending get and post requests with my username and password with curl, the requests library from python and with XMLHttpRequest in JavaScript. No luck, only got back a message with 401, unauthorized or something about a malformed request.

What am I trying to achieve

In short, I hoped I could somehow automate the process and make certain automatisations. I would run a script on my Ubuntu machine, and it would send the username and password, get back the contents of whatever the router sends back (which I guess is html and CSS and JavaScript for managing the interface) and do something with it. What would be even better is to actually get to the command line of the router and change the settings from there (I know that probably this is hard to achieve, but a man can try).

Flu

Posted 2018-09-16T21:58:47.050

Reputation: 9

You should look at the Selenium IDE add-on. I have used it with Firefox on Ubuntu, but it may well be available on other browsers and platforms. The other way that I've used to automate router functions is to use telnet with a script. Both methods have worked for me on my TP-Link router. – AFH – 2018-09-16T22:22:23.400

1

Put openwrt or ddwrt on it, then you can easily access your router via ssh. It would be a much better solution.

– Ipor Sircer – 2018-09-16T22:36:44.440

@Ipor Sircer changing the router's OS is not an option – Flu – 2018-09-16T23:13:17.097

Answers

-1

You should definitely be able to achieve what you want one way or another. The question is what level of abstraction you want to use.

You’ve tried the low-level way: trying to emulate the requests with curl or a Python script. I think it’s a good approach and should be doable. (E.g., compare this super simple curl invocation on a TP-Link router. Basic Auth and a referer is all that’s needed there – hey, perhaps the referer is all you need too?) But without seeing the web interface, I can’t offer specific advice.

Then there’s the high level way: use a headless browser and simulate the exact user inputs on the page. CasperJS may be suitable; their docs should give you a good starting point. Of course this is arguably a pretty heavy-handed way, but it’ll get the job done.

tjanson

Posted 2018-09-16T21:58:47.050

Reputation: 109

I’m downvoting because this question is way to broad and makes some equality broad assumptions of how to go about achieving this. So any answer posted here will honestly never be an answer and a bad question is (sadly) encouraged by posting an answer like this. The comment from Ipor Sircer is 100% correct: Getting open source firmware that allows SSH access to the device is really the best way to go. – JakeGould – 2018-09-16T23:13:27.267

I disagree. Part of the question (wanting to automate user inputs) is quite specific and answered here. And while I’m a fan of OpenWRT myself, answering an automation question with "install a different firmware" without knowing further requirements is a big leap too. – tjanson – 2018-09-16T23:23:27.400