0

I'm trying to configure the wireless settings (like setting ssid as "vinoth" channel as "1") in Linksys EA4500 AP. I could see the below POST message using wireshark.

3E@@!dPzY+2K
SPOST /JNAP/ HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
X-JNAP-Action: http:cisco.com/jnap/core/Transaction
X-JNAP-Authorization: Basic YWRtaW46YWRtaW4=
X-Requested-With: XMLHttpRequest
Referer: http:/cisco.com/     <<<<==== routerip
Content-Length: 474
Cookie: initial-tab=; ui-proxy-path=local; admin-auth=Basic%20YWRtaW46YWRtaW4%3D; current-applet=7B1F462B-1A78-4AF6-8FBB-0C221703BEA4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

[{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings","request":{"radios":[{"radioID":"RADIO_2.4GHz","settings":{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}]}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings","request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}]

I tried automating the above action using Perl but it didn't workout. As I am new to this JSON page I don't know how exactly the POST message to be sent.

content I kept for $json is

'{"action":"http:/cisco.com/jnap/wirelessap/SetRadioSettings",' .
        '"request":{"radios":{"radioID":"RADIO_2.4GHz","settings":'.'{"isEnabled":true,"mode":"802.11bgn","ssid":"vinoth212","broadcastSSID":true,"channelWidth":"Auto","channel":1,"security":"None"}}}},{"action":"http://cisco.com/jnap/guestnetwork/SetGuestNetworkSettings",' .
    '"request":{"isGuestNetworkEnabled":false,"guestSSID":"vinoth-guest","guestPassword":"BeMyGuest","maxSimultaneousGuests":5,"broadcastGuestSSID":false}}';

and the code:

    use strict;
    use warnings;

    use LWP;

    my $ua = LWP::UserAgent->new;
    my $ip = $self->{ip};
    my $url = "http://$ip/";
    my $json = "";

    my $req = HTTP::Request->new(POST=>$url);
    $req->header('content-type' => 'application/json');
    $req->authorization_basic("admin", "admin");
    $req->content($json);

Below code for checking the request status

    my $res = $ua->request($req);
    if ($res->is_success) {
    my $message = $res->decoded_content;
    print "received the message";
    } else {
    print "HTTP get code: ", $res->code, "\n";
    print "HTTP get: msg: ", $res->message, "\n";
    }

Please help me in fixing this. Awaiting for your valuable reply.

P.S: In the Wireshark Post message the links are not proper as I am unable to post the query with more than 2 links.

Thanks, Vinoth

Miller
  • 34,962
  • 4
  • 39
  • 60
user3441116
  • 37
  • 1
  • 8
  • I tried to post my code in my question but it said lot of indendation constraints so I removed it. – user3441116 Mar 25 '14 at 13:02
  • May be it's Referer header? You don't have it in your code... – gangabass Mar 25 '14 at 13:11
  • what should be the referer header? I see two links on that action message. Could you tell me how to parse it?? – user3441116 Mar 26 '14 at 04:34
  • `Referer: http:/cisco.com/ <<<<==== routerip` Same you have in Wireshark log – gangabass Mar 26 '14 at 04:42
  • I tried this. my $req = HTTP::Request->new(POST=>"http://192.168.1.1/"); $req->header(content-type=>"application/json";$req->content($json); my $res = $ua->request($req); and the result of $res->is_success returned "Internal Server Error" and error code "500" – user3441116 Mar 26 '14 at 04:56

1 Answers1

0

Using the code $req->authorization_basic("admin", "admin"); it means Authorization: Basic YWRtaW46YWRtaW4= HTTP header when make any request.

But From your wireshirk's header it is X-JNAP-Authorization: Basic YWRtaW46YWRtaW4=, which is different thing(a custom header). So remove that authorization_basic from your block and use these ones:

$req->header('Content-Type' => 'application/json; charset=UTF-8');
$req->header('X-JNAP-Action' => 'http:cisco.com/jnap/core/Transaction');
$req->header('X-JNAP-Authorization' => 'Basic YWRtaW46YWRtaW4=');
## YWRtaW46YWRtaW4= is base64 of admin:admin
$req->header('X-Requested-With' => 'XMLHttpRequest');
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • I tried the above but still it didn't work. Post message from Wireshark (tried login page) : POST /JNAP HTTP/1.1 TE: deflate,gzip;q=0.3 Connection: TE, close Host: 192.168.1.1 Referer: http://192.168.1.1/ui/dynamic/login.html User-Agent: libwww-perl/6.03 Content-Type: application/json; charset=UTF-8 X-JNAP-Action: http://cisco.com/jnap/core/CheckAdminPassword X-JNAP-Authorization: Basic YWRtaW46YWRtaW4= X-Requested-With: XMLHttpRequest – user3441116 Mar 27 '14 at 03:48
  • "HTTP/1.1 411 Length Required\nConnection: close\nDate: Tue, 14 Aug 2012 22:52:13 GMT\nServer: lighttpd/1.4.28\nContent-Length: 357\nContent-Type: text/html\nClient-Date: Thu, 27 Mar 2014 03:51:30 GMT\nClient-Peer: 192.168.1.1:80\nClient-Response-Num: 1\nTitle: 411 - Length Required\n\n\n/DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n 411 - Length Required\n \n \n

    411 - Length Required

    \n \n
    – user3441116 Mar 27 '14 at 03:53
  • I now fixed the content-length error. But getting "301 Moved Permanently" error. "HTTP/1.1 301 Moved Permanently\nDate: Wed, 15 Aug 2012 00:03:42 GMT\nLocation: http://192.168.1.1/JNAP/\nServer: lighttpd/1.4.28\nContent-Length: 0\nClient-Date: Thu, 27 Mar 2014 05:02:59 GMT\nClient-Peer: 192.168.1.1:80\nClient-Response-Num: 1\n\n" HTTP get code: 301 HTTP get msg : Moved Permanently – user3441116 Mar 27 '14 at 04:59
  • Got it finally. I missed a "/" in the url. I gave "http://192.168.1.1/JNAP" instead of "http://192.168.1.1/JNAP/". – user3441116 Mar 27 '14 at 05:59
  • Sounds great!! I was off for few hours so couldn't reply. FYI, to handle redirect you can use `$ua->max_redirect(2)` from `LWP::UserAgent` – Sabuj Hassan Mar 27 '14 at 07:23
  • In GET method, how to get the contents of a page? I am getting either the JS or the html page but it doesn't have the values I look for (like SSID, Radio ID, Channel etc...). Could u help? Even in Wireshark, I can see those values only when I use "Follow TCP Stream" option. – user3441116 Mar 27 '14 at 11:45
  • The thing you are doing using `$res->decoded_content` is alright. I am guessing the problem can be the html source may have `iframe` or `ajax` that's why those fields are not on there. – Sabuj Hassan Mar 27 '14 at 11:50
  • so how to get those values using HTTP GET? – user3441116 Mar 27 '14 at 11:52
  • You have to TAP those request, or debug html/javascript for the links. Its more like scraping then coding. – Sabuj Hassan Mar 27 '14 at 12:48
  • Gotcha! When I tried with GET requests, the webpage returned with either CSS or JS so I had no clue how to get the values I expect. Later tried with POST - constructed a POST header which I got through "Follow TCP Stream" and I got the values which I expected. – user3441116 Mar 28 '14 at 06:09