입력 검증 및 표현 문제는 메타 문자, 대체 인코딩 및 숫자 표현 때문에 발생합니다. 보안 문제는 입력을 신뢰하기 때문에 발생합니다. 문제로는 "Buffer Overflows", "Cross-Site Scripting" 공격, "SQL Injection", 그 외 여러 가지가 있습니다.
select()
쿼리를 동적으로 생성하고 실행합니다. 또한 사용자는 결과가 정렬되는 열을 지정할 수도 있습니다. 응용 프로그램이 이미 적절하게 인증되고 이 코드 세그먼트 전에 customerID
의 값을 설정했다고 가정합니다.
...
String customerID = getAuthenticatedCustomerID(customerName, customerCredentials);
...
AmazonSimpleDBClient sdbc = new AmazonSimpleDBClient(appAWSCredentials);
String query = "select * from invoices where productCategory = '"
+ productCategory + "' and customerID = '"
+ customerID + "' order by '"
+ sortColumn + "' asc";
SelectResult sdbResult = sdbc.select(new SelectRequest(query));
...
select * from invoices
where productCategory = 'Fax Machines'
and customerID = '12345678'
order by 'price' asc
productCategory
및 price
에 작은따옴표 문자가 들어 있지 않은 경우에만 정확하게 동작합니다. 그러나, 공격자가 productCategory
에 대한 "Fax Machines' or productCategory = \"
" 문자열 및 sortColumn
에 대한 "\" order by 'price
" 문자열을 제공하면, 쿼리는 다음과 같습니다.
select * from invoices
where productCategory = 'Fax Machines' or productCategory = "'
and customerID = '12345678'
order by '" order by 'price' asc
select * from invoices
where productCategory = 'Fax Machines'
or productCategory = "' and customerID = '12345678' order by '"
order by 'price' asc
customerID
에 필요한 authentication을 무시할 수 있으며, 모든 고객에 대한 'Fax Machines'
와 일치하는 송장 레코드를 볼 수 있습니다.customerID
의 값을 설정했다고 가정합니다.
...
productCategory = this.getIntent().getExtras().getString("productCategory");
sortColumn = this.getIntent().getExtras().getString("sortColumn");
customerID = getAuthenticatedCustomerID(customerName, customerCredentials);
c = invoicesDB.query(Uri.parse(invoices), columns, "productCategory = '" + productCategory + "' and customerID = '" + customerID + "'", null, null, null, "'" + sortColumn + "'asc", null);
...
select * from invoices
where productCategory = 'Fax Machines'
and customerID = '12345678'
order by 'price' asc
productCategory
를 연결하여 동적으로 생성됩니다. 그러므로 쿼리는 productCategory
및 sortColumn
가 작은 따옴표 문자를 포함하지 않은 경우에만 올바르게 작동합니다. 공격자가 productCategory
에 대한 "Fax Machines' or productCategory = \"
" 문자열 및 sortColumn
에 대한 "\" order by 'price
" 문자열을 제공하면, 쿼리는 다음과 같습니다.
select * from invoices
where productCategory = 'Fax Machines' or productCategory = "'
and customerID = '12345678'
order by '" order by 'price' asc
select * from invoices
where productCategory = 'Fax Machines'
or productCategory = "' and customerID = '12345678' order by '"
order by 'price' asc
customerID
에 필요한 authentication을 무시할 수 있으며, 모든 고객에 대한 'Fax Machines'
와 일치하는 송장 레코드를 볼 수 있습니다.HttpRequest
클래스는 배열 액세스의 형태로 QueryString
, Form
, Cookies
또는 ServerVariables
컬렉션의 변수에 대한 프로그래밍 방식의 액세스를 제공합니다(예: Request["myParam"]
). 동일한 이름을 가진 변수가 두 개 이상 존재할 경우, .NET Framework는 다음 순서로 컬렉션을 검색할 때 먼저 나타나는 변수의 값을 반환합니다. 즉, QueryString
, Form
, Cookies
, ServerVariables
의 순서로 반환합니다. 검색 순서에서 QueryString
이 먼저 오므로 QueryString
매개 변수가 폼, 쿠키 및 서버 변수의 값을 대체할 수 있습니다. 마찬가지로 폼 값은 Cookies
및 ServerVariables
컬렉션의 변수를 대체할 수 있고 Cookies
컬렉션의 변수는 ServerVariables
의 변수를 대체할 수 있습니다.
...
String toAddress = Request["email"]; //Expects cookie value
Double balance = GetBalance(userID);
SendAccountBalance(toAddress, balance);
...
http://www.example.com/GetBalance.aspx
방문 시 Example 1
의 코드가 실행된다고 가정합니다. 공격자가 인증된 사용자로 하여금 http://www.example.com/GetBalance.aspx?email=evil%40evil.com
을 요청하는 링크를 클릭하도록 할 수 있는 경우, 사용자의 잔고 정보가 있는 전자 메일이 evil@evil.com
으로 전송됩니다.HttpRequest
클래스는 배열 액세스의 형태로 QueryString
, Form
, Cookies
또는 ServerVariables
컬렉션의 변수에 대한 프로그래밍 방식의 액세스를 제공합니다(예: Request["myParam"]
). 동일한 이름을 가진 변수가 두 개 이상 존재할 경우, .NET Framework는 다음 순서로 컬렉션을 검색할 때 먼저 나타나는 변수의 값을 반환합니다. 즉, QueryString
, Form
, Cookies
, ServerVariables
의 순서로 반환합니다. 검색 순서에서 QueryString
이 먼저 오므로 QueryString
매개 변수가 폼, 쿠키 및 서버 변수의 값을 대체할 수 있습니다. 마찬가지로 폼 값은 Cookies
및 ServerVariables
컬렉션의 변수를 대체할 수 있고 Cookies
컬렉션의 변수는 ServerVariables
의 변수를 대체할 수 있습니다.www.example.com
으로부터 왔는지 확인합니다.
...
if (Request["HTTP_REFERER"].StartsWith("http://www.example.com"))
ServeContent();
else
Response.Redirect("http://www.example.com/");
...
http://www.example.com/ProtectedImages.aspx
방문 시 Example 1
의 코드가 실행된다고 가정합니다. 공격자가 URL에 대해 직접 요청하는 경우, 적절한 리퍼러 헤더가 전송되지 않으며 요청이 실패합니다. 그러나 공격자가 http://www.example.com/ProtectedImages.aspx?HTTP_REFERER=http%3a%2f%2fwww.example.com
과 같은 필요한 값을 가진 거짓 HTTP_REFERER
매개변수를 전송하는 경우, 조회하면 ServerVariables
대신 QueryString
에서 값이 반환되며 검사가 성공합니다.