Forum Moderators: phranque

Message Too Old, No Replies

Scripting a logon

getting past an htpasswd file

         

GarroteYou

1:46 am on Sep 25, 2003 (gmt 0)

10+ Year Member



Hello -

This may not be the right forum for this particular issue, but I'll give it a shot -

I have an EFG80 from linksys. It's an NAS [linksys.com] box for a home network. Every night I shut this thing down along with three other 2000 systems. I would like to be able to remotely kill all 4 devices with one click.

The windows boxes are easy [sysinternals.com]


psshutdown -u admin -p passwd -k -f -t 15 -m "System is going down" \\sys2
psshutdown -u admin -p passwd -k -f -t 15 -m "System is going down" \\sys1
psshutdown -k -f -t 15 "System is going down"

(psshutdown [sysinternals.com])

The EFG80 can only be shut down from within the web based administration pages installed within the unit. Anyone with a linksys or probably any number of other manufacturers router WAP etc. know what I'm talking about.

I can get to the page with the button directly:

http://192.168.1.xx/Management/setup.cgi?next_file=status.htm
http://192.168.1.xx/Management/setup.cgi?next_file=status.htm

The button is javascript based, <a href="javascript:action(1);">"button image"</a>

Here is the action() function:

<script language="JavaScript" type="text/javascript">
<!-- Start Script

// other functions

function action(no)
{
var cf = document.status;
if (no == 1)
cf.todo.value = "shutdown_now";
if (no == 2)
cf.todo.value = "restart_now";
cf.submit();
}

// other functions

</script>
</head>

The problem is that I must authenticate via a '.htpasswd' before running the cgi script which serves the page with my configuration.

http://192.168.1.xx/Management/setup.cgi?next_file=status.htm

I can see the '.htpasswd' file by:

http://192.168.1.xx/Management/

Which gives a listing of all the files which make up the admin web pages, I don't think they want their users poking around that folder, but there is nothing there any way.

The box runs an embedded linux dist and thttpd/2.20c. Linksys claims a shell is not available.

Can I script the submiting of my admin credentials along with the execution of the shutdown function?

What is a document.status object, and what does the submit(); function do?

Would it be possible to create a perl, or other lang. script which would supply the admin user and pass, and execute the java function ultimately shutting down the system?

Thanks in advance

~Dave

[edited by: engine at 5:25 pm (utc) on April 6, 2004]

bcolflesh

1:56 am on Sep 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you bypass .htaccess with the username and password in the URL?:

http://username:password@192.168.1.xx/Management/setup.cgi?next_file=status.htm

[edited by: engine at 5:26 pm (utc) on April 6, 2004]

GarroteYou

10:00 pm on Sep 25, 2003 (gmt 0)

10+ Year Member



Yes I can, thanks. So the question becomes now, how do I script the execution of the java script function which shuts this thing off?

wkitty42

10:38 pm on Sep 25, 2003 (gmt 0)

10+ Year Member



garroteyou,

why can't you just hit the power button on that unit? its not like there's anything in it that would be damaged by a power loss, is there?

GarroteYou

10:59 pm on Sep 25, 2003 (gmt 0)

10+ Year Member



That would be nice, the "power switch" only turns it on, not off. Off is the function of the software to which I have been referring.

[TELNET] CONNECT (NAS-DEVICE/192.168.1.**)
GET /Management/

<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY BGCOLOR="#cc9999"><H2>401 Unauthorized</H2>

Authorization required for the URL '/Management/'.

<HR>

<ADDRESS><A HREF="http://www.example.com/software/thttpd/">thttpd/2.20c 21nov01</A></ADDRESS>

</BODY></HTML>

[TELNET] INFO: DISCONNECTED

hypothetically speaking, any http:80 session could be simulated with telnet, is this correct?

If I could get a description of the telnet session that would need to take place for the commands to be executed, I could build a little C app that would connect, and run the sequence automatically.

Any takers?

[edited by: engine at 5:27 pm (utc) on April 6, 2004]

wkitty42

11:33 pm on Sep 25, 2003 (gmt 0)

10+ Year Member



garroteyou,

ewww on the power switch thing... i'd be pulling the power cord, then... or putting it on a powerstrip with a properly working powerswitch ;)

on the telnet idea, yes... that is correct... you appear to have given a good example... what i'd be doing is using a nonrendering (aka safe) browser like samspade and taking a look at exactly where you need to go and how to get there to trigger the necessary gate and cause the unit to shutdown... you've already gotten the info on how to login automatically... as i recall, the name and password are sent on every access... seems you should be able to possibly jump straight to the softswitch and kick it in one go...

does the manual or the manufacturer offer anything helpful?

[added]oops... i see now that it is a NAS box and not a naT/router box... i can see why they would want a proper shutdown now... gotta flush those caches and close those files...[/added]

[added2]sadly, i don't think you'll be able to script this with telnet or a C application unless you can get them to execute the javascript or figure out what the javascript does and simulate the final outputs... maybe cURL or perl might have some javascript executing capability? actually, you might have to do it in java and let java perform the javascript execution... dunno... i have dug into things really deep like this in the past but not in this area... one of my early digs was manually querying a MUX (multiplexor) on a chemical tankfarm by typing in all the commands in a terminal window... those folk were used to doing everything via scripts and didn't realize exactly what they were doing (similar in fashion to DOS .BAT files)... in any case, a nonrendering browser or something that will pull the pages out of the unit so you can see what the javascript is doing as well as the URLs appears to be a road you'll be travelling down in this endevor[/added2]

[added3] hey! i'm looking at the pdf user manual now and just happened across this section...

Pressing the power switch while the Instant Gigadrive is turned on will begin it's internal shut-down process. [u]The Instant Gigadrive must be powered off this way, or through its internal shutdown process that is locate in the web configuration.[/u]

the above is under picture 2-1 on page 3 showing the back of the unit...[/added3]

GarroteYou

8:57 pm on Oct 1, 2003 (gmt 0)

10+ Year Member



I got it! Using Sniffer Pro, I watched each packet as sent from this box to the NAS.

The sequence of strings which need to be sent to the NAS is the following:

[TELNET] CONNECT (NAS-DEVICE/192.168.1.XX)

GET /Management/setup.cgi?next_file=status.htm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Host: 192.168.1.XX
Connection: Keep-Alive

The NAS replies with:

HTTP/1.1 401 Unauthorized
Server: thttpd/2.20c 21nov01
Content-type: text/html
Date: Wed, 01 Oct 2003 00:34:05 GMT
Last-modified: Wed, 01 Oct 2003 00:34:05 GMT
Accept-Ranges: bytes
Connection: close
WWW-Authenticate: Basic realm="Administration"

<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY BGCOLOR="#cc9999"><H2>401 Unauthorized</H2>
Authorization required for the URL '/Management/setup.cgi?next_file=status.htm'.
<!--
Padding so that MSIE deigns to show this error instead of its own canned one.
Padding so that MSIE
deigns to show this error instead of its own canned one.
Padding so that MSIE deigns to show this error instead of its own canned one.
Padding so that MSIE deigns to show this error instead of its own canned one.
Padding so that MSIE deigns to show this error instead of its own canned one.
Padding so that MSIE deigns to show this error instead of its own canned one.
-->
<HR>
<ADDRESS><A HREF="http://www.example.com/software/thttpd/">thttpd/2.20c 21nov01</A></ADDRESS>
</BODY></HTML>

[TELNET] INFO: DISCONNECTED

From that response, a browser would ask for authentication, and try again:

[TELNET] CONNECT (NAS-DEVICE/192.168.1.XX)

GET /Management/setup.cgi?next_file=status.htm HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Host: 192.168.1.XX
Connection: Keep-Alive
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

This being the second request in a row, the server accepts the authentication, and serves the page.

Next comes the request which simulates the shutdown button:

[TELNET] CONNECT (NAS-DEVICE/192.168.1.XX)

POST /Management/setup.cgi HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Referer: http://192.168.1.XX/Management/setup.cgi
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Host: 192.168.1.88
Content-Length: 222
Connection: Keep-Alive
Cache-Control: no-cache
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

email_enable=&email_1=example@example.com&email_2=&email_subject=
GigaDrive+report&h_email_enable=checked&message=&this_file=status.htm&todo=shutdown_now&h_email_1=
example@example.com&h_email_2=&h_email_subject=GigaDrive+report

Now I just need to create a program which will connect to the box, and feed these strings in on by one...

~Dave

[edited by: engine at 5:32 pm (utc) on April 6, 2004]