nicx Posted January 12, 2009 Share Posted January 12, 2009 Mr.I was create a source view html with file_get_contents() function.But that have a bug,so someone can know my cpanel username and password. Where he can know that? What method he use? My code <form action="" method="post"><input type="text" name="url" /><input type="submit" value="submit" /></form><?php$file = @file_get_contents($_POST["url"]);echo nl2br(htmlspecialchars($file));?> Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Wow that made no sense at all Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-735696 Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 Your not filtering the post input. If a person knows your host structure they can basically read any file on your server with that script. I would suggest validating the url input to avoid this issue. Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-735697 Share on other sites More sharing options...
nicx Posted January 13, 2009 Author Share Posted January 13, 2009 What method to use my structure data? Or how to show my data? Give me an example,what he inputed to that form? Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-735816 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 if he did say index.php it would print out that full file, all the code. As long as you have an index.php. Give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-735817 Share on other sites More sharing options...
cwarn23 Posted January 13, 2009 Share Posted January 13, 2009 I found that the easiest way to prevent the user from viewing your source code and just seeing html is by making them put in the full url (including http:// or https://) So the following should work and has a validator. <form action="" method="post">You must place the full url starting with http:// or https://<br /> <input type="text" name="url" value="http://<? echo $_SERVER['SERVER_NAME']; ?>"/> <input type="submit" value="submit" /></form> <?php if (isset($_POST["url"]) && substr($_POST["url"],0,4)==='http') { $file = @file_get_contents($_POST["url"]); echo nl2br(htmlspecialchars($file)); } else if (isset($_POST["url"])) { echo "You must have the full url starting with http:// or https://"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-736015 Share on other sites More sharing options...
nicx Posted January 14, 2009 Author Share Posted January 14, 2009 Thanks bro,i understand now Quote Link to comment https://forums.phpfreaks.com/topic/140584-ask-bugs-from-file_get_contents/#findComment-736937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.