2016-07-12 5 views
0

Ich kenne genug Code, um gefährlich zu sein, aber konnte nichts von Grund auf neu schreiben, wenn mein Leben davon abhing. Ich migriere eine Website auf neues Hosting, das eine neuere Version von PHP hat, die $ _REQUEST nicht erlaubt (glaube ich). Dieser Code dient zum Verschlüsseln einer PDF. Funktioniert gut auf der alten Seite (wahrscheinlich ältere Version von PHP).
Ich habe versucht, alle $ _REQUEST mit $ _GET zu ersetzen, und das hat nicht funktioniert. Jede Hilfe wird sehr geschätzt. Ich habe den Formatierungscode und das grundlegende HTML ausgeschlossen.

<?php 
$timeArr = explode(' ', microtime()); 
$pageStartTime = $timeArr[ 1 ] + $timeArr[ 0 ]; 

$file = $_FILES['file']; 
if($_REQUEST['submit'] && (!trim($_REQUEST['password']) || $_REQUEST['password'] == 'Password')) { 
    $msg = 'Please enter a password.'; 
} 
elseif(is_array($file) && $file['error'] == 0) { 
    $enc_path = 'encrypted'; 
    $src = $file['tmp_name']; 
    $dest = "{$enc_path}/{$file['name']}"; 
    $pass = trim($_REQUEST['password']); 
    $cmd_fmt = "pdftk '$src' output '$dest' user_pw '$pass'"; 

    @mkdir($enc_path); 
    @system($cmd_fmt); 

    if(file_exists($dest)) $file_url = "http://www.company.com/{$enc_path}/" . rawurlencode($file['name']); 

} 
?> 

     } 
     </style> 
     <script type="text/javascript"> 
     function copyToClipboard(s) { 
      if(window.clipboardData && clipboardData.setData) { 
       clipboardData.setData('text', s); 
      } 
      else alert('Could not get permission to access the clipboard. Please copy the URL from the text box instead.'); 
     } 
     </script> 
    </head> 
    <body> 
    <center> 
    <div style="width: 600px;"> 
    <div style="text-align: center;"> 
     <center> 
     <form action="<?= $_SERVER[ 'PHP_SELF' ] ?>" method="POST" enctype="multipart/form-data"> 
     <div style="text-align: center;"> 
      <img src="/logo.png" border="0" style="height: 145px; margin-bottom: -10px;"> 
      <h1>PDF Encryption Tool</h1> 
     </div> 
     <br/> 
     <? if($file_url) : ?> 
      <span><a href="<?= $file_url ?>">Click here to download your file</a></span><br/> 
      <input type="text" readonly value="<?= $file_url ?>" style="width: 350px; margin: 0 0 5px 0;"><br/> 
      <input type="button" onclick="copyToClipboard('<?= $file_url ?>');" value="Copy to Clipboard"> 
      <br/> 
     <? elseif($_REQUEST['submit'] && $msg) : ?> 
      <font color="red"><b><?= $msg ?></b></font> 
      <br/> 
     <? elseif($_REQUEST['submit']) : ?> 
      <font color="red"><b>There was an error processing your request. This program only accepts PDF files.</b></font> 
      <br/> 
     <? endif; ?> 
     <br/> 
     <br/> 
     <input type="file" name="file" style="width: 350px; border: 0; margin: 0 0 5px 0;"><br/> 
     <input id="password" type="text" name="password" style="width: 350px;" 
      <?= $_REQUEST['password'] ? 'class="focus"' : ''?> 
      onFocus="this.className = 'focus'; if(this.value == 'Password') { this.value = ''; }" 
      onBlur="if(this.value == '') { this.className = ''; this.value = 'Password'; }" 
      onKeyDown="if(event.keyCode == 13) { this.form.submit(); return false; }" 
      value="<?= $_REQUEST['password'] ? $_REQUEST['password'] : 'Password' ?>" 
     > 
     <br/> 
     <br/> 
     <input name="submit" value="Submit" type="submit"> 
     </form> 
     <br/> 
     <br/> 
    </center> 
    </div> 
    <br/> 
    <br/> 
    <? 
    $timeArr = explode(' ', microtime()); 
    $pageEndTime = $timeArr[ 1 ] + $timeArr[ 0 ]; 
    $pageTime = $pageEndTime - $pageStartTime; 
    ?> 
    <span align="left"> 
     <font color="gray" size="-3"> 
      Page took <?= number_format($pageTime, 3) ?> second(s) to load. 
     </font> 
    </span> 
    </div> 
    </center> 
    </body> 
</html> 
+1

die $ _REQUEST var kann enthält $ _GET, $ _POST und $ _COOKIE Werte! Sehen Sie [http://php.net/manual/en/reserved.variables.request.php](reserved.variables.request) – fehrlich

+0

Ihr Formular ist zum Beispiel vom Typ $ _POST – fehrlich

+1

Sie haben auch einige schwerwiegende Sicherheitsprobleme auf der Seite , Sie können grundsätzlich jeden Befehl mit '@system ($ cmd_fmt) ausführen;' – fehrlich

Antwort

0

$ _REQUEST: Eine assoziative Array, dass standardmäßig enthält den Inhalt von $ _GET, $ _POST und _COOKIE $. php.net

Ihr Formular verwendet Methode „post“:

<form action="<?= $_SERVER[ 'PHP_SELF' ] ?>" method="POST" enctype="multipart/form-data"> 

dies bedeutet, dass Sie Ihre $_REQUEST mit $_POST

Für die Sicherheitsfragen austauschen müssen: immer denken, was der Benutzer sein manipulieren kann und wie es verwendet werden könnte, um den Code zu brechen.

Für Ihre Kommandozeile können Sie escapeshellarg verwenden. Sie haben auch mehrere Benutzervariablen, die in HTML verwendet werden können. Siehe cross-site scripting

Verwandte Themen