LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-06-2005, 11:29 PM   #1
gypsy_rabbi
Member
 
Registered: Sep 2004
Distribution: Ubuntu
Posts: 109

Rep: Reputation: 15
ksh cgi security


I need a button on a web-page that will do the following:
Code:
# concatenate multiple pdf files into one:

cd /var/www/wherever
/usr/bin/gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=full.pdf 1.pdf 2.pdf 3.pdf
The filenames to be concatenated will be POSTed as parameters, and this is the only thing the button will ever do.

I'm wary of using CGI with a shell script. Is there any way to make this secure?

Thanks,

GR
 
Old 07-07-2005, 03:42 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Use perl insted of ksh/bash, as perl support more feature to check input (passed via args) since the filenames to be concatenated will be POSTed as parameters.
 
Old 07-07-2005, 03:50 PM   #3
Krugger
Member
 
Registered: Oct 2004
Posts: 229

Rep: Reputation: 30
But it is tricky

imagine a file name is inputed as ";rm -rf / "
or the ; as a hex or octal or unicode or unicode double encoded

wouldn't perhaps be easier to have the files indexed and shown?

So that you only process an number.
 
Old 07-07-2005, 04:01 PM   #4
Krugger
Member
 
Registered: Oct 2004
Posts: 229

Rep: Reputation: 30
the attacker won't destroy your system as you probably got apache as nobody, but still your files are gone and what ever nobody can delete will be deleted.
 
Old 07-08-2005, 02:42 PM   #5
gypsy_rabbi
Member
 
Registered: Sep 2004
Distribution: Ubuntu
Posts: 109

Original Poster
Rep: Reputation: 15
Krugger: yes, the files are indexed by date, and I'm checking to make sure that the input is a valid date. Is there anything else I should think about?

nixcraft: if you can figure out a way to call gs from perl, with parameters, and without using "system" calls, let me know.

Thanks.
 
Old 07-09-2005, 02:40 PM   #6
Krugger
Member
 
Registered: Oct 2004
Posts: 229

Rep: Reputation: 30
If you use number or such remember that the attacker can craft the GET or POST.

if you changed to php or something else beware of code injection, in shell script it is the same.

now that you are thinking about the ';', think about these:

$(ls -la)
' $(ls -la) '

This will be interpreted by the ksh and to do the substitution it will have to execute the command. Of course this might not work as I don't know how you are doing the verifications on the date.

Also beware of its size, although I don't think gs is vunerable to bufferoverflow.

Perl must have a pdf api. It has one for almost everything.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl CGI:Can't locate CGI.pm supermyself Programming 13 09-10-2007 06:22 AM
cgi-bin security question greyhammer Linux - Security 0 08-03-2005 03:24 PM
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 08:49 PM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 07:35 AM
Color in KSH? drublic Linux - General 0 01-30-2002 06:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration