Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17210

Re: prob with exec, exiftool and one photo

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: prob with exec, exiftool and one photo
Date Wed, 14 Dec 2016 17:37:05 +0100
Organization PointedEars Software (PES)
Lines 165
Message-ID <3147213.R56niFO833@PointedEars.de> (permalink)
References <o2p6o9$pgl$1@shakotay.alphanet.ch> <ebbbpsF2t59U1@mid.individual.net> <o2qna0$kea$1@shakotay.alphanet.ch>
Reply-To Thomas 'PointedEars' Lahn <php@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1481733425 14629 eJwNykEBACAIA8BKCGNiHAXsH0HvfW4czAk64devIDR2e1oI10Ra6u4ihx4RFfKXQqOty2o9BuwQmA== (14 Dec 2016 16:37:05 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Wed, 14 Dec 2016 16:37:05 +0000 (UTC)
User-Agent KNode/4.14.2
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
X-NNTP-Posting-Host eJwFwYEBACAEBMCVEv8YJ9T+I3QHpbDdCBoeHhV1gNqyMxGjO1cnl1h3+u2KyGneqfGjIR8JExDi
X-User-ID eJwNyMEBwCAIA8CVxEDAcZDC/iPU552BwnKlUW1sbiumVGqa2FQs8cSJ5qCdSDNEnBv1IGq5fK/95WR89v4HQxsU4Q==
Cancel-Lock sha1:whH5NqdqyY7ivPkZNlz3Ob4ojOY=
Xref csiph.com comp.lang.php:17210

Show key headers only | View raw


Une Bévue wrote:

> Le 13/12/2016 à 23:42, J.O. Aho a écrit :
>> What's the exit status code?
>>
>> Have you verified that the path is correct? Is it a full path or a
>> relative path (in this case it may not be relative to the script
>> executed first)?
> 
> full PATH
> 
>> If your script takes all the files in the directory, but always missing
>> one file, then your outer loop has issues, as you haven't provided how
>> you get your $data in the first place, it's just a guessing game for us
>> who ain't mind readers.
> 
> no the script is activated by :
> http://mbp.local/tests/Flipping_image/php/exiftool-json.php?PATH=/Users/yt/Sites/tests/Flipping_image/photos/glasgow.jpg

You are an obnoxious, anti-social pseudonymous address munger who does not 
deserve this piece of advice.  But to prevent you from harming others in 
your blissful ignorance, and as a warning to others, I am making an 
exception and reply:

You *really* do NOT want to do that.  The least you want to do here is 
calling escapeshellarg($_GET['PATH']) before you pass it to exec(), so that 
an attacker cannot execute *arbitrary code* on that box (see below for an 
example of that).

But even then allowing *anyone* to access *any* file on that box poses a 
great security risk.  You must realize that as by your code any information 
output by exiftool(1) is contained in the JSON HTTP response, an attacker 
can determine which files are on that box, what is the file size, the file 
modification and access times, the file permissions, and for which processor 
architecture have binaries been compiled.  Because exiftool(1) is much more 
than just a tool to read EXIF (image) metadata.

Fasten your seatbelt and try

http://mbp.local/tests/Flipping_image/php/exiftool-json.php?PATH=/bin/sh

I can debug this manually, and make a good prediction as to what you will 
get:

> and the whole script is :
> 
> <?php
> $EXIFTOOL = "/usr/local/bin/exiftool";
> $SITES = "/Users/yt/Sites";
> $data = array();

processed

> if(isset($_GET['URL'])) {

false

>    $data['URL'] = $_GET['URL'];
>    $data['PATH'] = $SITES . $_GET['URL'];
> }

ignored

> if(isset($_GET['PATH'])) {

true

>    $data['URL'] = explode($SITES, $_GET['PATH'], 2 )[1];

irrelevant

>    $data['PATH'] = $_GET['PATH'];

  $data['PATH'] = '/bin/sh';

> }
> header('Content-Type: application/javascript');

That is the *wrong* MIME media type for a JSON response.  JSON is a data 
format, not executable source code.

<http://json.org/>
<http://fr.wikipedia.org/wiki/JSON>

> date_default_timezone_set('Europe/Paris');
> setlocale(LC_CTYPE, 'fr_FR');
> error_reporting(E_ALL);
> 
> function exifTool() {
>    global $EXIFTOOL;
>    global $data;
>    $cmd = "$EXIFTOOL " . $data['PATH'];

  $cmd = "/usr/local/bin/exiftool /bin/sh";

>    exec($cmd, $Infos, $ExitStatus);

  exec("/usr/local/bin/exiftool /bin/sh", $Infos, $ExitStatus);

Imagine what would have happened here if I had accessed

http://mbp.local/tests/…/php/exiftool-json.php?PATH=%2F%3Brm%20-rf%20%2F

(Just IMAGINE; DO NOT TRY this [at least not without changing “exec” to 
“echo”]!)

>    foreach($Infos as $line) {
>      $fields = explode(' : ', $line, 2 );
>      if(count($fields) == 2) {

AFAICS there will always be two fields with exiftool(1).

>        $data[rtrim($fields[0])] = $fields[1];
>      }
>    }
> 
>    $data['ExitStatus'] = $ExitStatus;

  $data = [
    'URL'                             => 'something irrelevant',
    'PATH'                            => '/bin/sh',
    'ExifTool Version Number        ' => '10.25',
    'File Name                      ' => 'sh',
    'Directory                      ' => '/bin',
    'File Size                      ' => '110 kB',
    'File Modification Date/Time    ' => '2016:07:05 23:59:04+02:00',
    'File Access Date/Time          ' => '2016:12:14 10:44:49+01:00',
    'File Inode Change Date/Time    ' => '2016:07:10 17:50:26+02:00',
    'File Permissions               ' => 'rwxr-xr-x',
    'File Type                      ' => 'ELF shared library',
    'File Type Extension            ' => 'so',
    'MIME Type                      ' => 'application/octet-stream',
    'CPU Architecture               ' => '64 bit',
    'CPU Byte Order                 ' => 'Little endian',
    'Object File Type               ' => 'Shared object file',
    'CPU Type                       ' => 'AMD x86-64',
    'ExitStatus'                      => 0
  ];

or similar.

>    return $data;
> }
> echo json_encode(exifTool());
> ?>

Omit the last line: <http://www.php-fig.org/psr/psr-2/#2-2-files>
 
> the script is not missing one file. even if I hardcode the path within
> the script has for example :
> $data['PATH'] = '/Users/yt/Sites/tests/Flipping_image/photos/glasgow.jpg';
> 
> i get absolutely nothing. no errors.

There may be no error messages, but certainly there is an _$ExitStatus_ (as 
your fellow anti-social address munger, “J.O. Aho”, said).

Also, $data is only filled if there are exactly two fields.  Maybe that is 
the problem – in addition to the many other problems with this code.

-- 
PointedEars
Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-13 17:14 +0100
  Re: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-13 17:15 +0100
  Re: prob with exec, exiftool and one photo "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-13 17:28 +0100
    Re: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-13 18:23 +0100
      Re: prob with exec, exiftool and one photo "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-14 00:19 +0100
  Re: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-13 18:03 +0100
    Re: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-13 18:28 +0100
  Re: prob with exec, exiftool and one photo "J.O. Aho" <user@example.net> - 2016-12-13 23:42 +0100
    Re: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-14 07:02 +0100
      Re: prob with exec, exiftool and one photo Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 17:37 +0100
        Re: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-14 18:13 +0100
  [BADLY SOLVED]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-14 08:11 +0100
    Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 17:43 +0100
      Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-14 18:24 +0100
        Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 19:57 +0100
      Re: [BADLY SOLVED]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-14 19:01 +0100
        Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-12-14 19:39 +0100
          Re: [BADLY SOLVED]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-17 09:11 +0100
            Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Jerry Stuckle <jstucklex@attglobal.net> - 2016-12-17 09:33 -0500
        Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-15 06:19 +0100
    Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Eli the Bearded <*@eli.users.panix.com> - 2016-12-14 22:19 +0000
      Re: [BADLY SOLVED]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-15 06:30 +0100
      [UNSOLVABLE]: prob with exec, exiftool and one photo Une Bévue <unbewusst@fai.invalid> - 2016-12-17 08:08 +0100
        Re: [UNSOLVABLE]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-17 09:26 +0100
          Re: [UNSOLVABLE]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-17 10:45 +0100
            Re: [UNSOLVABLE]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-17 11:41 +0100
              Re: [UNSOLVABLE]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-17 17:39 +0100
                Re: [UNSOLVABLE]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-18 10:27 +0100
                Re: [UNSOLVABLE]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-21 11:36 +0100
                Re: [UNSOLVABLE]: prob with exec, exiftool and one photo "R.Wieser" <address@not.available> - 2016-12-21 16:58 +0100
                Re: [UNSOLVABLE]: prob with exec, exiftool and one photo Une Bévue <unbewusst.sein@fai.invalid> - 2016-12-22 07:08 +0100

csiph-web