|
======================================================================== Multiple .NET Null Byte Injection Vulnerabilities
= Vendor Website:
= http://www.microsoft.com
= Affected Version:
= .NET FrameWork v1.1 SP1
= .NET FrameWork v2.0.50727
= Vendor Notified - October, 2006
= Public Disclosure - July 11th, 2007
http://security-assessment.com/files/advisories/2007-07-11_Multiple_.NET_Nul
l_Byte_Injection_Vulnerabilities.pdf
=======================================================================
== Overview =Security-Assessment.com recently completed research into the .NET
Framework in relation to the affect a Null byte (%00) has on
various aspects of the .NET Common Language Runtime.
This advisory details the findings of that research conducted
by Paul Craig Paul.Craig
")
response.write("The real value is: " & realname & "
")
End Sub
Output:
Mappath of name variable = C:\Inetpub\exploit1\test.aspx
The Real value is : C:\Inetpub\exploit1\test.aspx.uploaded
1. Two variables are assigned, name and realname.
2. Name is a user supplied filename, and for security reasons
.uploaded is appended to this value.
3. Real name is the virtual path for the current directory,
with the name variable appended (This is the correct
location of the file)
4. Inserting a Null byte suffix into the 'name' variable
(name=test.aspx%00) is able to terminate the string returned
from MapPath and any data concatenated to the user supplied
value is removed.
Exploit 2: Server.Execute and Server.Transfer
------------------------------------------------------------------------
Server.Execute and Server.Transfer were found to both be vulnerable
to Null byte injection. Here the Null byte produces an arbitrary file
disclosure vulnerability.
If a remote user is able to control the input used in a Server.Execute
or Server.Transfer method, the method can be used to disclose the contents
of any file within the document root.
As seen in example 2, below.
Sub Page_Load()
Server.Transfer(request("page"))
End Sub
Security-Assessment.com has witnessed Server.Transfer and Server.Execute
being used in page redirection functionality where .NET sessions are
transferred to a user supplied page variable.
According to MSDN:
"The page transferred to should be another .aspx page. For instance,
a transfer to an .asp or .asmx page is not valid. The Transfer
method preserves the QueryString and Form collections."
If a user attempts to transfer to web.config, or any other none .ASPX
page an exception is created. However, when the page variable is
suffixed with a Null byte the complete file contents of the page
is returned to the remote user.
A Server.Transfer or Server.Execute to page=web.config%00 will
display the contents of the web.config file.
This vulnerability can also be used to view any file within the
document root.
Exploit 3: String.Compare
------------------------------------------------------------------------
String.Compare was also found to be affected by Null bytes. Although does
not
produce an exploitable condition.
String.Compare demonstrates .NET's inability to correctly handle Null bytes.
This is demonstrated in the example below.
Sub Page_Load()
dim allowed, sFirstItem, sSecondItem as string
sFirstItem = Request("first")
sSecondItem = Request("second")
response.Write ("String.Compare - First item = " & sFirstItem &
"
")
response.Write ("String.Compare - Second item = " & sSecondItem &
"
")
if String.Compare(sFirstItem, sSecondItem) =0 then
response.Write ("String.Compare - Matched! Strings are
the same" & "
")=09
else
response.Write ("String.Compare - FAILED!! Strings are
not the same" & "
")
End If
if sFirstItem=sSecondItem then
response.Write ("Direct eval - Matched! Strings are the
same" & "
")
else
response.Write ("Direct eval - FAILED! Strings are not
the same" & "
")
End If
End Sub
1. Two variables are supplied, "first" and "second"
2. String.Compare is called to compare the two strings, and then a
direct
evaluation is performed.
3. String.Compare should act identically to a direct evaluation.
4. The result of first=test&second=test can be seen below.
String.Compare - First item = test
String.Compare - Second item = test
String.Compare - Matched! Strings are the same
Direct Eval - Matched! Strings are the same
This is the correct response, as both the first and second were defined as
'test'
5. Now, add a Null byte suffix to the 'first' variable and try again.
The result of Example3.aspx?first=test%00&second=test can be seen below.
String.Compare - First item = test=90
String.Compare - Second item = test
String.Compare - Matched! Strings are the same
Direct Eval - Failed! Strings are not the same
=09
String.Compare terminates the string at the first Null byte, and the
two values are seen as identical. However direct evaluation correctly
determines that they are different, due to the extra Null byte suffix. =09
Although this is not exploitable it is an interesting finding.
Exploit 4: System.Net.Mail.SmtpMail.Send
------------------------------------------------------------------------
The object System.Net.Mail.SmtpMail.Send was found to be vulnerable to
string parameter termination similar to the vulnerability discovered in
Server.MapPath.
This is demonstrated in the example below.
Private Sub Page_Load(sender As Object, e As System.EventArgs)
Dim m As New MailMessage()
m.From = "securityguy@security-assessment.com"
m.To = request("to") & "@security-assessment.com"
m.Subject = request("subject") & ": FromWebsite"
m.Body = request("body") & "This message was submitted by a user."
Response.Write("Sending mail to: " & m.to)
=09
m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticat
e", "1")
=09
m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"username")
=09
m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"password")
SmtpMail.SmtpServer = "mail.server.com"
SmtpMail.Send(m)
End Sub
In this example the recipient property (To) is defined as a user supplied
variable with =93@security-assessment.com=94 concatenated.
Security-Assessment.com
has seen this development technique being used to ensure mail is only be
sent to users of a particular domain.
However, if a user supplies a recipient (To) variable as
paul.craig@microsoft.com%00
the mail will be sent to the Microsoft.com domain and string is again
terminated at
the first Null byte removing the concatenated "@security-assessment.com"
value.
Similarly the From, Subject and Body values were found to be vulnerable to
the
same method of Null byte injection
== Solutions =
Security-Assessment.com has been in contact with Microsoft and a new .NET
patch
has been released to address the discovered vulnerabilities.
Install patch KB928365 (Security Update for Microsoft .NET Framework 2.0)
and/or
KB928366 (Security Update For Microsoft .NET Framework 1.1)
== Credit =
Discovered and advised to Microsoft October, 2006 by Paul Craig of
Security-Assessment.com - Paul.Craig