Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:41:55+00:00 2026-05-27T21:41:55+00:00

When the permissions of this script are u=rwx,g=rwx,o=r the scripts works just fine… However,

  • 0

When the permissions of this script are u=rwx,g=rwx,o=r the scripts works just fine… However, I need the setuid bit to be turned on so the call to smartctl returns the desired data instead of an error.

#!/usr/bin/perl

use strict;
use warnings;
use CGI qw(:standard);

my $device = param("device") || "sda";

print header("text/plain");

print "device = $device\n\n";


$ENV{"PATH"} = "/usr/sbin";
open( PS, "smartctl -A /dev/$device |" );
while( <PS> )
{
    print $_ . "\n";
}
close( PS );

When I set the permission to u=rwxs,g=rwxs,o=r, the script works when the query does not specify device. But then when device is specified, nothing gets returned after print "device = $device\n\n";

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:41:55+00:00Added an answer on May 27, 2026 at 9:41 pm

    You need to look at the configuration of Perl.

    perl -MConfig -e 'print "d_suidsafe = $Configu{d_suidsafe}\n"; }'
    

    If it doesn’t say anything (nothing visible after the =), then Perl was told to consider SUID scripts as unsafe. It treats them differently from regular scripts. Check the ‘taint’ system (-T command line option) too; it should warn about the ‘script injection’ problem mentioned below.


    Coding suggestions:

    1. Use the three-argument form of open.
    2. Check that the open succeeded.

    Like this:

    open my $PS, "-|", "smartctl -A /dev/$device"
      or die "Could not popen smartctl: $!";
    

    Well, probably not die, but report the error cleanly and don’t use the unopened file handle.

    if (open my $PS, "-|", "smartctl -A /dev/$device")
    {
        while (<$PS>)
        {
            print "$_\n";
        }
        close $PS;
    }
    else
    {
        print "Failed to open device: $!";
    }
    

    Note that you need to reject or sanitize the input of the person who wrote: sda; cp /bin/sh /tmp/...; chmod 6777 /tmp/... in the device parameter field. It’s a bit like SQL injection, only this time, it is ‘Perl script injection’. They might be more brutal than that: sda; rm -fr / 2>/dev/null & does a fairly good job of cleaning out the system of files and directories which the user to whom the script is setuid can modify. You can’t trust users an inch at the best of times. In a setuid program, trusting the users at all is a serious problem. All of that doubly (if not multiply) so when the access is from a web browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this script to find all files/directories to which $WWWUSER has write permissions.
I just wrote this backup script: #!/usr/bin/bash # the number of days to do
This is my section of permissions of my manifest: <manifest xmlns:android=http://schemas.android.com/apk/res/android package=com.adelco.ventamovil android:versionCode=1 android:versionName=1.0>
I know this is the list of permissions in android Is there any new
Suppose, I have saved some permissions in the database by using this code: RoleRepository
I understand preserving the permissions for rsync. However in my case my local computer
2 Separate questions. I am using this script to drop a table [SOLVED] BEGIN
I'm writing this cURL script in PHP. It's purpose is to take a product
I'm writing a script to check permissions of files in user's directories and if
I'm trying to automate the setup of SFTP access. This script is running as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.