Jump to content


Photo
- - - - -

dd-wrt - executing cgi scripts from web browser


  • Please log in to reply
5 replies to this topic

#1 W4RP3D

W4RP3D

    Hak5 Pirate

  • Members
  • PipPipPipPipPipPip
  • 335 posts
  • Gender:Male
  • Location:England

Posted 26 July 2009 - 06:23 AM

Hi guys, It been a very long time since i last posted but i was inspired by the jasager project to see what else the fon can do.

My idea is to control an ardiuno from a fon using my iphone. So far i have to fon running dd-wrt briged with my router so that once i connect to the network i can also access the fon. And by echoing to the serial port (echo "data" > /dev/tts/0) i can send data to the adriuno. A little diagram makes more sense:



I then created little cgi scripts to send the data e.g:

CODE
#!/bin/sh
echo "data" > /dev/tts/0


By following this guide http://www.dd-wrt.co...php/WEB_server I managed to be able to access html files from the iphone browser. Great i thought now i can link to the scripts which ran fine when i telnet in. Unfortuantly they dont execute from the webserver

The script is saved to /jffs/cgi-bin, and the webserver points to /jffs (httpd -p 81 -h /jffs). And i believe it should be execeted when i browse to "router_ip:81/cgi-bin/script.cgi". Ive also tryed saving it to usr/temp/www/cgi-bin but that doesnt seem to work either.

I could really do with some help.

Thanks W4rp3d

Edit: Wrong url for picture

#2 digip

digip

    -we're all just neophytes-

  • Active Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 7,655 posts
  • Gender:Male
  • Location:RnVjayBPZmYh 192.168.100.1

Posted 26 July 2009 - 04:07 PM

Don't CGI scripts usually require a POST of some data to execute the script and not a GET of the url itself? Are you passing commands or data to the script with the GET request(instead of just navigating to the script)?

Might be of some use: http://httpd.apache..../howto/cgi.html

When saving the file, did you make it executable?
@xxdigipxx http://www.attack-scanner.com/ | I'm the resident dick around here, or so I am told. Don't take it personally, I just give a shit too much sometimes. respect to all, its the Internet, don't take it to heart.
"Staying quiet doesn't mean I have nothing to say, it means I don't think you're ready to hear my thoughts..."

#3 W4RP3D

W4RP3D

    Hak5 Pirate

  • Members
  • PipPipPipPipPipPip
  • 335 posts
  • Gender:Male
  • Location:England

Posted 27 July 2009 - 04:15 AM

According to the link you posted you can just navaigate to the URL:

QUOTE
If you open your favorite browser and tell it to get the address

http://www.example.c...gi-bin/first.pl

or wherever you put your file, you will see the one line Hello, World. appear in your browser window. It's not very exciting, but once you get that working, you'll have a good chance of getting just about anything working.


I would like to pass data to it, but i thought it would be easyer just running seperate scripts for each command sent to the ardiuno. Yer I did make it an executable (chmod +x filename).

#4 digip

digip

    -we're all just neophytes-

  • Active Members
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • 7,655 posts
  • Gender:Male
  • Location:RnVjayBPZmYh 192.168.100.1

Posted 27 July 2009 - 12:29 PM

You coudl try "chmod a+x" to give all users executable access, not just root. That way, anyone who opens the file, via browser or whatever should have rights to execute it. +X I think is just the user you are signed in with, but coming in from the browser side, you are in the "users" side I believe. Not 100% sure how that all works from an embedded device, but worth a shot.

Part of what I was saying is that it has to be able to take a POST as well I believe.

QUOTE
But it's still not working!

There are four basic things that you may see in your browser when you try to access your CGI program from the web:
The output of your CGI program
Great! That means everything worked fine. If the output is correct, but the browser is not processing it correctly, make sure you have the correct Content-Type set in your CGI program.
The source code of your CGI program or a "POST Method Not Allowed" message

That means that you have not properly configured Apache to process your CGI program. Reread the section on configuring Apache and try to find what you missed.
A message starting with "Forbidden"
That means that there is a permissions problem. Check the Apache error log and the section below on file permissions.
A message saying "Internal Server Error"
If you check the Apache error log, you will probably find that it says "Premature end of script headers", possibly along with an error message generated by your CGI program. In this case, you will want to check each of the below sections to see what might be preventing your CGI program from emitting the proper HTTP headers.
File permissions

Remember that the server does not run as you. That is, when the server starts up, it is running with the permissions of an unprivileged user - usually nobody, or www - and so it will need extra permissions to execute files that are owned by you. Usually, the way to give a file sufficient permissions to be executed by nobody is to give everyone execute permission on the file:

chmod a+x first.pl

Also, if your program reads from, or writes to, any other files, those files will need to have the correct permissions to permit this.

@xxdigipxx http://www.attack-scanner.com/ | I'm the resident dick around here, or so I am told. Don't take it personally, I just give a shit too much sometimes. respect to all, its the Internet, don't take it to heart.
"Staying quiet doesn't mean I have nothing to say, it means I don't think you're ready to hear my thoughts..."

#5 Emeryth

Emeryth

    Hak5 Fan ++

  • Active Members
  • PipPipPipPip
  • 113 posts
  • Gender:Male
  • Location:Warsaw, Poland

Posted 27 July 2009 - 06:34 PM

How about using PHP's exec() function? (when everything else fails)

#6 W4RP3D

W4RP3D

    Hak5 Pirate

  • Members
  • PipPipPipPipPipPip
  • 335 posts
  • Gender:Male
  • Location:England

Posted 28 July 2009 - 05:40 AM

QUOTE (Emeryth @ Tue, 28 Jul 2009 00:34:09 +0000) <{POST_SNAPBACK}>
How about using PHP's exec() function? (when everything else fails)


My orginal plan was to use PHP but ddwrt doesnt support it, the cgi scripts not executing seem to be a bug in the newest versons of the firmware. It seems there are a lot of them. Im gonna try openwrt instead, its a bit harder to configure it to be a bridge but nevermind. Thanks guys




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users