AusGamers Forums
Show: per page
1
Need help with locking down nut-cgi (UPS)
HerbalLizard
Brisbane, Queensland
5292 posts
I got a eaton 5110 1000watt for xmas I ended up installing nut http://www.networkupstools.org/ to monitor it

nut has a few components to it

nut-client
nut-cgi
nut-monitor
etc etc

Its been installed in /etc/ups with the following permissions

-rw-r--r-- 1 root root 1074 Dec 29 11:19 hosts.conf
-rw-r----- 1 root nut 1413 Aug 11 07:14 nut.conf
-rw-r----- 1 root nut 3650 Dec 29 09:36 ups.conf
-rw-r----- 1 root nut 2589 Aug 11 07:14 upsd.conf
-rw-r----- 1 root nut 2134 Dec 29 15:46 upsd.users
-rw-r----- 1 root nut 11895 Dec 29 11:13 upsmon.conf
-rw-r----- 1 root nut 3891 Aug 11 07:14 upssched.conf
-rw------- 1 nut root 1420 Aug 11 07:14 upsset.conf
-rw-r--r-- 1 root root 4003 Aug 11 07:14 upsstats.html
-rw-r--r-- 1 root root 6644 Aug 11 07:14 upsstats-single.html

Nut is running but I am concerned about the cgi part of it running upsstats.cgi

I ended up copying it into my www dir cp /var/www/nut-cgi-bin/upsstats.cgi /var/www/cgi-bin/

But everyone an sundry can view it. How would I lock this down to the local access only for that specific set of directories related to it. (I don't do web stuff at all)


As you can see the permissions are far from what I would call secure

ls -l
total 32
-rwxr-xr-x 1 root root 32028 Dec 29 11:18 upsstats.cgi


08:07am 30/12/11 Permalink
adBot
ads
Internet
--
ads keep websites free
08:07am 30/12/11 Permalink
Jim
UK
12537 posts
But everyone an sundry can view it. How would I lock this down to the local access only for that specific set of directories related to it. (I don't do web stuff at all)
do you mean everyone can view it via http, and that you want to make it so only the local host can load it via http?

if so, I'd stick it into it's own sub-dir of cgi-bin so you can reference it separately with a Directory directive that doesn't effect anything else, something like:

<Directory /var/www/cgi-bin/upsstats>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>

documented here:
http://httpd.apache.org/docs/2.2/mod/core.html#directory
http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order
http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow
http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#deny

http://httpd.apache.org/docs/2.2/mod/directives.html for the full list


the file permissions on upsstats.cgi don't look too bad, I guess all you might do there to improve it is change the group to whatever group apache runs as, then remove the world read/execute bits, if you're worried about unprivileged users reading the contents of the file locally
08:43am 30/12/11 Permalink
Whoop
Brisbane, Queensland
19115 posts
^^ or if the server supports .htaccess files he could use that, couldn't he?
09:40am 30/12/11 Permalink
teq
Brisbane, Queensland
12214 posts
I'd go with Jim's solution, let apache handle the access
If you want something quick and dirty, try this


if ($ENV{'REMOTE_ADDR'} !~ /10\.1\.1\.1/) { print "Denied!"; exit; } else { print "Hello!"; }

change 10.1.1.1 to your IP or your LAN range or something, throw it at the top of upsstats.cgi
10:04am 30/12/11 Permalink
Jim
UK
12539 posts
^^ or if the server supports .htaccess files he could use that, couldn't he?

what I posted is what you'd put inside the .htaccess file, if you were using .htaccess files - it's all just apache config directives whether you put them in a .htaccess file, or directly into the server config

access files are just an optional feature that allows users to affect the apache config on the fly via the convenience of a separate file, although at the expense of several extra filesystem calls on every http request
11:23am 30/12/11 Permalink
Crusher
Sydney, New South Wales
1009 posts
Jim is talking crazy talk, real men use IIS.
11:55am 30/12/11 Permalink
HerbalLizard
Brisbane, Queensland
5293 posts
Thanks Jim just what I was after


I might actually try and lock it up in the webconfig inside clearOS which would be even more desirable should not be too hard.

IIS can suck my nuts, why would I want to bring my work problems home... keep that broken shit at work where it belongs
12:14pm 30/12/11 Permalink
teq
Brisbane, Queensland
12215 posts
actually, real men use Apache
12:21pm 30/12/11 Permalink
Crusher
Sydney, New South Wales
1010 posts
I give up
12:44pm 30/12/11 Permalink
kos
Germany
1897 posts
actually, real men use Apache

Come on now teq, don't be unfair on IIS, that article is almost 3 years old. Here's a more up to date one. Oh, wait...
12:32am 31/12/11 Permalink
Jim
UK
12541 posts
real men use crusher
so hawt
02:12am 31/12/11 Permalink
HerbalLizard
Brisbane, Queensland
5294 posts
I went a different route will I figure out how to get this running from the webconfig on clearos

Did the following and used basic auth & htaccess reason was that I would have to vpn to home to then get local access which is going to be painful on my phone

cd /var/www/cgi-bin
mkdir ups
cd ..
mv upsstats.cgi /var/www/cgi-bin/ups/

nano .htaccess

dropped this in there and saved
#
AuthUserFile /var/www/cgi-bin/ups/.htpasswd
AuthGroupFile /www.null
AuthName "Authorization Required"
AuthType Basic

require user ups
#

htpasswd -c /var/www/cgi-bin/ups/.htpasswd ups

Dropped this in httpd.conf

#UPSSTATS.CGI Access

AllowOverride AuthConfig


Restarted Apache

Seems to work

Question though how would I alias www/cgi-bin/ups/upsstats.cgi to something shorter like www/ups ?


02:26pm 31/12/11 Permalink
Jim
UK
12542 posts
maybe with Alias http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias
and DirectoryIndex http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex

something like:

Alias /ups /var/www/cgi-bin/ups

<Directory /var/www/cgi-bin/ups>
DirectoryIndex upsstats.cgi
</Directory>

Should mean you can just load http://your.server/ups

Or you can just add upsstats.cgi to your existing DirectoryIndex line in httpd.conf if you don't mind it being global instead of just for that dir, or you could probably just put the above DirectoryIndex line into the .htaccess file you now have, negating the need for the <Directory> tags

Just depends how you prefer doing your config
09:58pm 31/12/11 Permalink
HerbalLizard
Brisbane, Queensland
5295 posts
thanks jim more of a case of me getting around to rtfm, that and I needed a nudge in the right direction.

Cheers and owe you beers
10:29pm 31/12/11 Permalink
Jim
UK
12543 posts
no wukkaz!

I'm the same even after years of using apache. it's not always obvious how to do something, or I forget how I did it last time so a lot of the time I end up having to google for examples
12:19am 01/01/12 Permalink
HerbalLizard
Brisbane, Queensland
5297 posts
Interesting after few beers added in your suggest, login works with auth but then the browser then pulls down a copy of upsstats.cgi named download (with no extension)

Pretty odd

I get you on the forgetful thing... fucking pain in the arse.

I sat there the other day going there is a command for this I know there is then remembered nano +linenumber to open a file at a certain line

I sat there and went ok fuck this shit I need another beer

01:54am 01/01/12 Permalink
teq
Brisbane, Queensland
12226 posts

ScriptAlias /ups/ /usr/lib/cgi-bin/ups/


Add that inside your Virtualhost directive
02:28am 01/01/12 Permalink
Jim
UK
12544 posts
ah yeh didn't think of that - the alias is preventing your ScriptAlias on cgi-bin from being invoked
so like teq said, prepend Script to what I gave you before, and append the trailing slashes on both parameters

although having said all that now, maybe a redirect or rewrite would've been better from the start:

Redirect /ups /cgi-bin/ups/upsstats.cgi

Or if you want the url rewritten internally instead of sending a 30x header (which would cause the browser to make an additional request):

RewriteEngine on
RewriteRule ^/ups /cgi-bin/ups/upsstats.cgi

^^ off the top of my head, might need work
02:51am 01/01/12 Permalink
adBot
ads
Internet
--
ads keep websites free
02:51am 01/01/12 Permalink
AusGamers Forums
Show: per page
1
Post a Reply
You must be logged in to post a reply.
 

Advertise with Us | Download Media Kit | Privacy Policy | Contact Us
© Copyright 2001-2012 AusGamers™ Pty Ltd. ACN 093 772 242.
A Mammoth Media web development, hosted by Mammoth VPS.