LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-25-2013, 11:45 AM   #1
Gullible Jones
Member
 
Registered: Apr 2011
Posts: 142

Rep: Reputation: 10
Need advice on a (privileged) Perl script


First off, it's designed to be invoked with sudo, not a setuid helper. It's an exceedingly simple script, to allow a limited user to enter a chroot. I wrote it so I'd have an easier time using a 32-bit chroot for Wine.

Here it is, in all its glory:

Code:
#!/usr/bin/env perl

use strict;
use warnings;

my $target_uid = $ENV{'SUDO_UID'};
my $target_gid = $ENV{'SUDO_GID'};
my $dir = $ARGV[0];
chdir("$dir");
chroot("./");
$< = $> = $target_uid;
$( = $) = $target_gid;
chdir();
exec("/bin/bash");
My question: how much of a security hazard does this pose, in terms of local privilege escalation? How can I improve it? Error checking doesn't seem necessary for this, since things fail fatally on their own... But I would welcome any input.

Edit: apparently this is no good; a malicious user could forcibly load a Perl module to set the environment stuff. Boo.

Edit 2: Ended up implementing it in C. This time I took care to clear all the environment variables.

Edit 3: Also I could have used $< and $( in the original Perl, after wiping the environment. Why didn't I think of that...

Edit 4: Never mind the above, those vars don't work when using sudo.

Last edited by Gullible Jones; 12-25-2013 at 08:46 PM.
 
Old 12-26-2013, 05:50 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Thread is marked as solved, taken of the zero reply list.
 
  


Reply



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
[SOLVED] PERL, How to pipe out put of a perl script for processing with linux command. Soji Antony Programming 3 11-16-2012 09:04 AM
Print output of a script to screen using Perl/Multiple installation of Perl Modules metallica1973 Linux - General 1 02-17-2011 05:59 PM
call perl script through another perl script with arguments nanda22 Linux - Newbie 21 07-21-2009 12:18 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

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

All times are GMT -5. The time now is 07:00 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