Creating a file where the owner and group is not root


 
Thread Tools Search this Thread
# 15  
I'm running this program in a local directory as user diltsjr. When I run the script I write "perl script.pl". The script logs onto a server find the link I'm interested in and copies it to a zip file. When the script is done running I look at the permissions of the files. The zip file downloaded 'from' the server only has root permissions.
# 16  
Quote:
Originally Posted by Corona688
Explain exactly what you do word for word, letter for letter, keystroke for keystroke.
You have not explained in enough detail. I was not using hyperbole. I want to see exactly what your shell session looks like when you run that command. Use screenshots if necessary. Something extremely strange and quite possibly dangerous is going on for you to get root without asking when not logged in as root.

I also still want an explanation of where these files are being saved. Is this 'local folder' on a partition on a USB stick some such? That could explain it -- FAT32 filesystems don't have any users at all, and may just show everything as root...
# 17  
code I use to get the zip

Here's the code I used to get the zip on the protected server. Near the bottom, the last subroutine is grab_files is where all the magic happens. In my next post I will give you screen shots from the terminal.

Code:
#!/usr/bin/perl

use strict;
use warnings;

use HTTP::Request::Common qw(GET);
use LWP::UserAgent;



#-----------------------------------------------------------
# obtaining server access by creating a fake browser
#-----------------------------------------------------------
my $ua = new LWP::UserAgent;
$ua->protocols_allowed( [ 'http' ] );


#-----------------------------------------------------------
# methods
#-----------------------------------------------------------
enter_htmlMain();
my ($name, $address) = grab_samples();
enter_samplePage($address);
grab_files($name);


#-----------------------------------------------------------
# subroutines
#-----------------------------------------------------------
  

# enters the server page with all the sample runs listed
sub enter_htmlMain{

    my $url = 'http://server_name/rundb/';
    open (OUT, ">", "temp.html") or die $!;

    my $user = 'ionuser';
    my $pass = 'ionuser';

    #sets up request
    my $req = GET($url);
    $req->authorization_basic($user, $pass);

    #do it
    my $response = $ua->request($req);

    #check and print to file
    if ($response->is_error())
        {
            printf "%s\n", $response->status_line;
            print "http request error!\n";
        } else {

            my $content = $response->content();
            print OUT $content;
        }
    close OUT;

} #end of enter_htmlMain


#-----------------------------------------------------------
# grabs the names and location of the samples currently on 
#the server from temp.html and prints them for user selection
#-----------------------------------------------------------
sub grab_samples{

    my %sample;
    my $i = 1;

    open (IN, "<", "temp.html");

    while (<IN>){

        if ($_=~/<a href=\"(\/output\/Home\/.*\.php)\"/){
        my $holder = $1;
        my $sample_name;
        my $address = "http://server_name$holder";
    
            if ($holder=~/\/output\/Home\/(.*)\//){$sample_name = $1;}

        my $info = "$sample_name\t$address";
        print "$i\t$sample_name\n";
        $sample{$i} = $info;
        $i++;

        } #end of original 'if' statement    

    } #end of 'while' loop

    close IN;

    print "\n\nPlease select sample.\t";
    my $input = <>;
    chomp $input;
    
    my @temp = split(/\t/,$sample{$input});
    my $n = $temp[0];
    my $a = $temp[1];

    return ($n, $a);

    #remove temp.html
    my $cmd = "rm temp.html";
    system ($cmd);
    if ($?) {die "command: $cmd failed\n"};
    
} # end of grab_samples

#-----------------------------------------------------------
# copies the html page from the sample of intrest to temp.html
#-----------------------------------------------------------
sub enter_samplePage{

    my @destination = @_;

    my $url = $destination[0];
    open (OUT, ">", "temp.html") or die $!;

    my $user = 'ionuser';
    my $pass = 'ionuser';

    #sets up request
    my $req = GET($url);
    $req->authorization_basic($user, $pass);

    #do it
    my $response = $ua->request($req);

    #check and print to file
    if ($response->is_error())
        {
            printf "%s\n", $response->status_line;
            print "http request error!\n";
        } else {

            my $content = $response->content();
            print OUT $content;
        }
    close OUT;

} #end of enter_samplePage

#-----------------------------------------------------------
# grabs the barcode sff files and downloads them from the server
#-----------------------------------------------------------
sub grab_files{

    my @name = @_;
    my $barcode_sff;

    open (IN, "<", "temp.html");
    my @file = <IN>;
    close IN;

    foreach my $j (@file){
        if ($j=~/\(BAI\).*href\=\'(.*\.barcode\.sff\.zip)\'/){$barcode_sff = $1;}
    }

    #remove temp.html
    my $cmd = "rm temp.html";
    system ($cmd);
    if ($?) {die "command: $cmd failed\n"};


    #downloading .zip file
    my $barcode_sff_url = "http://server_name/output/Home/$name[0]/$barcode_sff";
    open (OUT, ">", $barcode_sff) or die $!;

    my $user = 'ionuser';
    my $pass = 'ionuser';

    #sets up request
    my $req = GET($barcode_sff_url);
    $req->authorization_basic($user, $pass);

    #do it
    my $response = $ua->request($req);

    #check and print to file
    if ($response->is_error())
        {
            printf "%s\n", $response->status_line;
            print "http request error!\n";
        } else {

            my $content = $response->content();
            print OUT $content;
        }
    close OUT;

    #change permissions on .zip
    $cmd = "chmod 775 $barcode_sff";
    system ($cmd);
    if ($?) {die "command: $cmd failed\n"};

    #unzip barcode.sff.zip
    $cmd = "unzip $barcode_sff";
    system ($cmd);
    if ($?) {die "command: $cmd failed\n"};

    #remove barcode.sff.zip
    $cmd = "rm $barcode_sff";
    system ($cmd);
    if ($?) {die "command: $cmd failed\n"};
        
} #end of grab_files

---------- Post updated at 02:20 PM ---------- Previous update was at 02:03 PM ----------

I don't have the images online. Is there a way I can sent you an email? or is there some other method I could get these images to you?

Last edited by Scrutinizer; 06-09-2012 at 03:00 AM.. Reason: code tags
# 18  
I don't care about the perl code. It doesn't have the magical ability to give you root.

Show exactly what you're doing with the perl code, word for word, letter for letter, keystroke for keystroke. Use screenshots if necessary, but show us what you're doing. The explanation you've given isn't detailed enough, since nothing you've said you did has the power to give you root.

Also answer more of my questions. I asked some you ignored, to wit:

Quote:
I also still want an explanation of where these files are being saved. Is this 'local folder' on a partition on a USB stick some such? That could explain it -- FAT32 filesystems don't have any users at all, and may just show everything as root...
# 19  
local folder

Sorry, I didn't mean to ignore your question, I'm working on a lot of things. I'm saving the file to a local folder. My home folder.
Creating a file where the owner and group is not root-screenshot-2012-06-08-14-06-39png
Creating a file where the owner and group is not root-screenshot-2012-06-08-14-07-01png
Creating a file where the owner and group is not root-screenshot-2012-06-08-14-13-53png

Last edited by jdilts; 06-08-2012 at 04:30 PM..
# 20  
You can attach the images to your reply by clicking 'manage attachments' after you click the reply button.
# 21  
I would say that the remote server is creating the zip file, with 644 permission, the perl procedure fetches the zip files on local machine.

Since zip file is created on remote server with root and 644 permission, you will be able to fetch that archive with any user that has access via ssh/http/whatever

After that if you unzip the file localy with regular user, the files from archive will change the permission to one who unzipped it.

Hope that helps.
Regards
Peasant.
This User Gave Thanks to Peasant For This Post:
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Easy
The communication protocol NFC stands for Near-Field Control.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX command to display Owner,Group,Root and Subdirectories list

Hi Team, Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path. I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this . Here is the sample result... (6 Replies)
Discussion started by: vasuvv
6 Replies

2. AIX

Files without owner and group

Dears it is normal that the below binaries stay without any owner and group I have checked it in many servers and the like the below /usr/lpp/bos.net/inst_root/etc/ipsec# ls -lrt total 248 -r-xr-xr-x 1 987 987 13589 Jun 29 2005 default_group -r-xr-xr-x ... (5 Replies)
Discussion started by: thecobra151
5 Replies

3. Emergency UNIX and Linux Support

To identify the group owner

If I have to identify the group owner of an AIX group, what is the command to be used. Example: there is an mqadm group, how do I find the owner of this group? Please help. (6 Replies)
Discussion started by: ggayathri
6 Replies

4. UNIX for Dummies Questions & Answers

Finding the group owner for a file

How would I find out who the group openers is of a file? For example: > ls -l myfile -rwxr-xr-x 1 myronp hawks 20125 Oct 20 20:50 myfile How do I return just hawks. I could do this with a series of cut or awk, but is there a more direct way. The ls -g is better, but still... (1 Reply)
Discussion started by: Dad4x
1 Replies

5. UNIX for Dummies Questions & Answers

Finding the Group Owner Name

Hi all, How can i find the group owner name...??? Thanks (4 Replies)
Discussion started by: mansahr143
4 Replies

6. Shell Programming and Scripting

Creating a control file for a group of files

Hi, We have almost 45,000 data files created by a script daily. The file names are of format-ODS.POS.<pharmacyid>.<table name>.<timestamp>.dat. There will be one data file like this for each pharmacy and each table.(Totally around 45,000) The requirement is to create a control file for each... (2 Replies)
Discussion started by: Maya_Pillai
2 Replies

7. UNIX for Dummies Questions & Answers

How to set the name of the group and the owner while creation of the file?

How to set the name of the group and the owner while creation of the file? -rwxrwxr-x 1 root sys 1202 Dec 5 2002 abc.awk like here i need to set the name of root and sys to xxx xxx Any help is appreciated. Thanks. (2 Replies)
Discussion started by: nehak
2 Replies

8. Shell Programming and Scripting

permission, owner and group

hello I search a script (ksh for Aix 5.3) to save all permissions, groups and owner for all files. Because we work much to change it, and a mystake ......! So i want execute this script to save/ execute permissions for all files. If you have this script, thank you for your help ;) best... (2 Replies)
Discussion started by: pascalbout
2 Replies

9. UNIX for Dummies Questions & Answers

Can't change owner and group of a linux file

Hi, I don't know how the owner & group of a login file in redhat linux 7.2 changed to bache like, -rwxr-xr-x 1 bache bache 17740 Jun 20 02:05 login I am trying to change the owner and group to root by using #chown root login #chgrp root login But i am getting the error ... (7 Replies)
Discussion started by: bache_gowda
7 Replies

10. UNIX for Dummies Questions & Answers

owner and group in Linux

I am bit unclear of how Linux was set in the real world, please advise me how it's supposed to be. When I log in as root and do a ls -l, I find: /boot, /, /var, /usr, /tmp, /home, /u01, /u02, /u03 and of of this partition is owned by root and the group also belong to root. Is that the way it's... (1 Reply)
Discussion started by: lapnguyen
1 Replies

Featured Tech Videos