Fout in script??

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Joeri de Groot

Joeri de Groot

09/07/2008 17:35:00
Quote Anchor link
Hoi Allemaal,

Ik heb een script gemaakt waarmee ik via een andere pagina $bestand instuur, deze wordt vervolgens geopend in een editor.
$bestand mag alleen niet buiten de map liggen, dus niet dat iemand invoert: http://www.mijnwebsite.nl/bewerk.php?bestand=../../index.php. Als iemand dat kan doen, kan hij namelijk alle bestanden op mijn server veranderen.
Ik heb daarom dus verboden dat ../ in $bestand voorkomt, maar op een een of andere manier werkt het niet. Dit is mijn script:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require ("../3 juli/CMS/connect.php");
require("../3 juli/CMS/session.php");
?>



<?php
if(!strpos($_GET['bestand'], '../'))
{

$bestand = "../3 juli/CMS/" . htmlentities($_GET['bestand']);

// do not touch, yes ?
  if(is_readable($bestand) == FALSE)
  {

  die("Kon bestand niet openen: bestand is niet leesbaar");
  }


  if(is_writable($bestand) == FALSE)
  {

  die("Kon bestand niet openen: bestand is niet schrijfbaar");
  }



  if(isset($_POST["inhoud"]) == TRUE)
  {

  $inhoud = $_POST["inhoud"];
  $handeling = fopen($bestand,"w") or die("Kon bestand niet openen om te schrijven");
  $schrijf = fwrite($handeling,stripslashes($inhoud)) or die("Kon niet naar bestand schrijven");
  echo "<b>Het bestand is succesvol bewerkt.</b><br><br>Klik <a href=\"/CMS/login.php\">hier</a> om terug te gaan naar het overzicht.";
  die();
  }


$inhoud = file_get_contents($bestand) or die("Kon bestand niet openen om uit te lezen");
?>

<html>

<head>
<title>Bestand editten</title>
    <link href="sample.css" rel="stylesheet" type="text/css" />
    <script type="fckeditor.js"></script>
</head>



<style>
.update{
background-color: #ffffff;
color: #EE3034;
border: 1px solid #999999;
font-family: Arial;
font-size: 12px;
}
</style>
<body bgcolor="#ffffff">

<?php
if(isset($_SESSION['suser'])) {
?>

    
    
    <?php
  if(($_SESSION['slevel'] & 1) == 1) {
    // voer code uit behorend bij recht #1
?>






<?include("fckeditor.php") ;
?>
<form action="<? echo $_POST["PHP_SELF"]; ?>" method="post">

<?php
$sBasePath
= $_SERVER['PHP_SELF'] ;
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "_samples" ) ) ;

$oFCKeditor = new FCKeditor('inhoud') ;
$oFCKeditor->BasePath    = $sBasePath ;
$oFCKeditor->Height        = 600 ;
$oFCKeditor->Value        = $inhoud ;
$oFCKeditor->Create() ;
?>



<input type="submit" class="update" value="Update pagina >>">
</form>


<?php
  } else {
}

?>

<?php
}
?>


<?php
}
else
{
    echo 'Bestand mag niet geopend worden';
}

?>


</body>

</html>


Wie weet wat er mis is?? Alvast mijn dank ;) !!
Gewijzigd op 01/01/1970 01:00:00 door Joeri de Groot
 
PHP hulp

PHP hulp

19/05/2024 07:43:33
 
- SanThe -

- SanThe -

09/07/2008 18:10:00
Quote Anchor link
Joeri schreef op 09.07.2008 17:35:
Ik heb daaro dus verboden dat ../ in $bestand voorkomt

Waar dan?
 
Joeri de Groot

Joeri de Groot

09/07/2008 19:45:00
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
if(!strpos($_GET['bestand'], '../'))
{

    $bestand = '../3 juli/CMS/' . htmlentities($_GET['bestand']);

     //rest van het bestand
}
else
{
    echo 'Bestand mag niet geopend worden';
}

?>


Dit is het gedeelte waarin wordt verboden dat in $bestand ../ voorkomt...
 
Joeri de Groot

Joeri de Groot

10/07/2008 11:15:00
Quote Anchor link
weet iemand wat er mis is?
 
Terence Hersbach

Terence Hersbach

10/07/2008 11:24:00
Quote Anchor link
Je bent al meerdere keren op bumpen gewezen. Daarom word je topic nu gesloten.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.