Can there be a way to exploit PHP include_once() when the input is filtered?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












Let's assume there is a code for including other php files from user input. (Yes I know it's a bad choice.)



$input = addslashes($_GET["input"]);

if (strpos($GET, '../') !== false)
include_once('/path/to/php/files'.$input);
else echo('Invalid parameter!');


This code adds slashes to single and double quotes, and then check for ../ in the string, and if it does not, includes the file.



Assuming that the hacker has write functions to other folder, and the hacker needs to access that file with ?input=../../folder/extcode this manner (which he can’t)



Can there be a vulnerabillity here?










share|improve this question























  • Maybe LFI is still possible using base64, or url-encoding...
    – game0ver
    33 mins ago














up vote
3
down vote

favorite












Let's assume there is a code for including other php files from user input. (Yes I know it's a bad choice.)



$input = addslashes($_GET["input"]);

if (strpos($GET, '../') !== false)
include_once('/path/to/php/files'.$input);
else echo('Invalid parameter!');


This code adds slashes to single and double quotes, and then check for ../ in the string, and if it does not, includes the file.



Assuming that the hacker has write functions to other folder, and the hacker needs to access that file with ?input=../../folder/extcode this manner (which he can’t)



Can there be a vulnerabillity here?










share|improve this question























  • Maybe LFI is still possible using base64, or url-encoding...
    – game0ver
    33 mins ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











Let's assume there is a code for including other php files from user input. (Yes I know it's a bad choice.)



$input = addslashes($_GET["input"]);

if (strpos($GET, '../') !== false)
include_once('/path/to/php/files'.$input);
else echo('Invalid parameter!');


This code adds slashes to single and double quotes, and then check for ../ in the string, and if it does not, includes the file.



Assuming that the hacker has write functions to other folder, and the hacker needs to access that file with ?input=../../folder/extcode this manner (which he can’t)



Can there be a vulnerabillity here?










share|improve this question















Let's assume there is a code for including other php files from user input. (Yes I know it's a bad choice.)



$input = addslashes($_GET["input"]);

if (strpos($GET, '../') !== false)
include_once('/path/to/php/files'.$input);
else echo('Invalid parameter!');


This code adds slashes to single and double quotes, and then check for ../ in the string, and if it does not, includes the file.



Assuming that the hacker has write functions to other folder, and the hacker needs to access that file with ?input=../../folder/extcode this manner (which he can’t)



Can there be a vulnerabillity here?







php lfi rfi bypassing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









OscarAkaElvis

4,0412738




4,0412738










asked 1 hour ago









Moonsik Park

41716




41716











  • Maybe LFI is still possible using base64, or url-encoding...
    – game0ver
    33 mins ago
















  • Maybe LFI is still possible using base64, or url-encoding...
    – game0ver
    33 mins ago















Maybe LFI is still possible using base64, or url-encoding...
– game0ver
33 mins ago




Maybe LFI is still possible using base64, or url-encoding...
– game0ver
33 mins ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













What you are trying to block is a LFI, but this could be still vulnerable to RFI. (Link to both: https://en.wikipedia.org/wiki/File_inclusion_vulnerability).



On RFI the attacker will try to include a remote file using a payload like http://evilsite/evil.php and as you can see it doesn't contain '../' on it. To be protected of this, you should configure on your php.ini the allow_url_include and be sure that it is off. Otherwise you'll be hacked using RFI.



Talking about LFI I'm not sure 100% that this code is safe. Ok you are blocking strings like '../' but maybe the attacker could encode it someway to bypass your protection. Be careful!






share|improve this answer




















  • How would an RFI work on OPs sample code? There's a local path prefix.
    – Arminius
    7 mins ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "162"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f196976%2fcan-there-be-a-way-to-exploit-php-include-once-when-the-input-is-filtered%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













What you are trying to block is a LFI, but this could be still vulnerable to RFI. (Link to both: https://en.wikipedia.org/wiki/File_inclusion_vulnerability).



On RFI the attacker will try to include a remote file using a payload like http://evilsite/evil.php and as you can see it doesn't contain '../' on it. To be protected of this, you should configure on your php.ini the allow_url_include and be sure that it is off. Otherwise you'll be hacked using RFI.



Talking about LFI I'm not sure 100% that this code is safe. Ok you are blocking strings like '../' but maybe the attacker could encode it someway to bypass your protection. Be careful!






share|improve this answer




















  • How would an RFI work on OPs sample code? There's a local path prefix.
    – Arminius
    7 mins ago














up vote
2
down vote













What you are trying to block is a LFI, but this could be still vulnerable to RFI. (Link to both: https://en.wikipedia.org/wiki/File_inclusion_vulnerability).



On RFI the attacker will try to include a remote file using a payload like http://evilsite/evil.php and as you can see it doesn't contain '../' on it. To be protected of this, you should configure on your php.ini the allow_url_include and be sure that it is off. Otherwise you'll be hacked using RFI.



Talking about LFI I'm not sure 100% that this code is safe. Ok you are blocking strings like '../' but maybe the attacker could encode it someway to bypass your protection. Be careful!






share|improve this answer




















  • How would an RFI work on OPs sample code? There's a local path prefix.
    – Arminius
    7 mins ago












up vote
2
down vote










up vote
2
down vote









What you are trying to block is a LFI, but this could be still vulnerable to RFI. (Link to both: https://en.wikipedia.org/wiki/File_inclusion_vulnerability).



On RFI the attacker will try to include a remote file using a payload like http://evilsite/evil.php and as you can see it doesn't contain '../' on it. To be protected of this, you should configure on your php.ini the allow_url_include and be sure that it is off. Otherwise you'll be hacked using RFI.



Talking about LFI I'm not sure 100% that this code is safe. Ok you are blocking strings like '../' but maybe the attacker could encode it someway to bypass your protection. Be careful!






share|improve this answer












What you are trying to block is a LFI, but this could be still vulnerable to RFI. (Link to both: https://en.wikipedia.org/wiki/File_inclusion_vulnerability).



On RFI the attacker will try to include a remote file using a payload like http://evilsite/evil.php and as you can see it doesn't contain '../' on it. To be protected of this, you should configure on your php.ini the allow_url_include and be sure that it is off. Otherwise you'll be hacked using RFI.



Talking about LFI I'm not sure 100% that this code is safe. Ok you are blocking strings like '../' but maybe the attacker could encode it someway to bypass your protection. Be careful!







share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









OscarAkaElvis

4,0412738




4,0412738











  • How would an RFI work on OPs sample code? There's a local path prefix.
    – Arminius
    7 mins ago
















  • How would an RFI work on OPs sample code? There's a local path prefix.
    – Arminius
    7 mins ago















How would an RFI work on OPs sample code? There's a local path prefix.
– Arminius
7 mins ago




How would an RFI work on OPs sample code? There's a local path prefix.
– Arminius
7 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f196976%2fcan-there-be-a-way-to-exploit-php-include-once-when-the-input-is-filtered%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery