Password field with auto-complete 취약점 설명

 

1) 자동완성을 말함
2) 폼에 한 글자를 입력하면 문자열이 동적으로 표시되는 것을 뜻함
해당 취약점은 input 태그에 autocomplete = " off"로 설정하여 방지할 수 있음
* OWASP Top 10  A3: 민감한 데이터 노출 (Sensitive Data Exposure) 포함 

 

(예)

 

 

4.  수정 필요 부분

 

 input 태그에 autocomplete = "on" 에서  input 태그에 autocomplete = "off"로 변경필요

QCEO 2021.12.09 웹취약점 점검 결과 (Medium 1, Low 3, Informational 3)


[Medium 1]

=======================================================================
Unencrypted password form

The HTTP protocol by itself is clear text, meaning that any data that is transmitted via HTTP can be captured and the contents viewed.
To keep data private, and prevent it from being intercepted, HTTP is often tunnelled through either Secure Sockets Layer (SSL), or Transport Layer Security (TLS). When either of these encryption standards are used it is referred to as HTTPS.
Cyber-criminals will often attempt to compromise credentials passed from the client to the server using HTTP. This can be conducted via various different Man-in-The-Middle (MiTM) attacks or through network packet captures.
Arachni discovered that the affected page contains a password input, however, the value of the field is not sent to the server utilising HTTPS. Therefore it is possible that any submitted credential may become compromised.

http://192.168.120.166:8000/ password
=======================================================================

 

[Low 3]

=L1======================================================================
Password field with auto-complete 1

In typical form-based web applications, it is common practice for developers to allow autocomplete within the HTML form to improve the usability of the page. With autocomplete enabled (default), the browser is allowed to cache previously entered form values.
For legitimate purposes, this allows the user to quickly re-enter the same data when completing the form multiple times.
When autocomplete is enabled on either/both the username and password fields, this could allow a cyber-criminal with access to the victim’s computer the ability to have the victim’s credentials automatically entered as the cyber-criminal visits the affected page.
Arachni has discovered that the affected page contains a form containing a password field that has not disabled autocomplete.

http://192.168.120.166:8000/
=======================================================================

=L2======================================================================
Common administration interface 1

An administration interface was identified and should be reviewed.

http://192.168.120.166:8000/admin/login/?next=/admin/
=======================================================================

 

=L3======================================================================
Missing 'X-Frame-Options' header 1

Clickjacking (User Interface redress attack, UI redress attack, UI redressing) is a malicious technique of tricking a Web user into clicking on something different from what the user perceives they are clicking on, thus potentially revealing confidential information or taking control of their computer while clicking on seemingly innocuous web pages.
The server didn’t return an X-Frame-Options header which means that this website could be at risk of a clickjacking attack.
The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page inside a frame or iframe. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

http://192.168.120.166:8000/static/css/login.css

=======================================================================

 


[Informational 3]
=I1======================================================================
Allowed HTTP methods 1

There are a number of HTTP methods that can be used on a webserver (OPTIONS, HEAD, GET, POST, PUT, DELETE etc.). Each of these methods perform a different function and each have an associated level of risk when their use is permitted on the webserver.
A client can use the OPTIONS method within a request to query a server to determine which methods are allowed.
Cyber-criminals will almost always perform this simple test as it will give a very quick indication of any high-risk methods being permitted by the server.
Arachni discovered that several methods are supported by the server.

http://192.168.120.166:8000/

=======================================================================

 

=I2======================================================================
Interesting response 1

The server responded with a non 200 (OK) nor 404 (Not Found) status code. This is a non-issue, however exotic HTTP response status codes can provide useful insights into the behavior of the web application and assist with the penetration test.

http://192.168.120.166:8000/
=======================================================================

 

=I3======================================================================
HttpOnly cookie 1

HTTP by itself is a stateless protocol. Therefore the server is unable to determine which requests are performed by which client, and which clients are authenticated or unauthenticated.

The use of HTTP cookies within the headers, allows a web server to identify each individual client and can therefore determine which clients hold valid authentication, from those that do not. These are known as session cookies.
When a cookie is set by the server (sent the header of an HTTP response) there are several flags that can be set to configure the properties of the cookie and how it is to be handled by the browser.
The HttpOnly flag assists in the prevention of client side-scripts (such as JavaScript) accessing and using the cookie.
This can help prevent XSS attacks targeting the cookies holding the client’s session token (setting the HttpOnly flag does not prevent, nor safeguard against XSS vulnerabilities themselves).

http://192.168.120.166:8000/

=======================================================================

서버가 200(OK) 또는 404(찾을 수 없음)가 아닌 상태 코드로 응답했습니다.
이것은 문제가 되지 않지만 이국적인 HTTP 응답 상태 코드는 웹 애플리케이션의 동작에 대한 유용한 통찰력을 제공하고 침투 테스트를 지원할 수 있습니다.

 

 

 

 

HTTP(Hypertext Transfer Protocol)

 

* 클라이언트와 서버 간의 요청과 응답 프로토콜

* HTTP 요청

  - 클라이언트가 서버에 특정 자원에 대한 요청 명령을 보냄

  - 요청 명령 : GET, POST

* HTTP 응답

  - 서버가 클라이언트에 요청받은 자원과 응답코드를 보냄

  - 응답코드 : 200(OK), 404(not Found) 등

* 웹 서버는 요청받은 자원을 전달할 수 없는 경우 오류코드를 응답코드로 반환

* TCP port 번호 80을 일반적으로 사용

* HTTP/1.1부터 keep-alive 기능 제공

  - 한 번의 연결로 클라이언트는 서버에 여러 번 요청을 보내고 응답을 받을 수 있음

* stateless 프로토콜

  - 상태 정보를 유지하지 않음

  - 로그인 등의 상태 정보를 표현하기 위하여 cookie, session 등 필요

위조 방지 토큰(Anti-Forgery Tokens)

ASP.NET MVC에서는 CSRF 공격을 방지하기 위해서 위조 방지 토큰을 사용하는데, 이를 요청 검증 토큰(Request Verification Tokens)이라고 부르기도 합니다.

  1. 클라이언트가 폼이 존재하는 HTML 페이지를 요청합니다.
  2.  
  3. 그러면, 서버는 응답에 두 가지 토큰을 포함시켜서 반환합니다. 그 중, 한 가지 토큰은 쿠키를 통해서 전송됩니다. 그리고, 다른 토큰은 숨겨진 폼 필드에 담겨집니다. 이 토큰들은 악의적인 사용자들이 값을 추측할 수 없도록 무작위로 생성됩니다.
  4. 클라이언트가 폼을 제출할 때, 두 가지 토큰이 모두 서버로 재전송돼야 합니다. 클라이언트는 쿠키 토큰은 쿠키를 통해서 전송하고, 폼 토큰은 폼 데이터에 담아서 전송합니다. (브라우저 클라이언트가 사용자가 폼을 제출할 때 자동으로 이 작업을 처리해줍니다.)
  5. 만약, 두 토큰 중 하나라도 일치하지 않으면 서버가 해당 요청을 허용하지 않습니다.

다음은 숨겨진 폼 토큰을 포함하고 있는 HTML 폼의 한 예입니다:

===================================================================

<form action="/Home/Test" method="post">

       <input name="__RequestVerificationToken" type="hidden"       

                value="6fGBtLZmVBZ59oUad1Fr33BuPxANKY9q3Srr5y[...]" />

        <input type="submit" value="Submit" />

</form>

===================================================================

 

위조 방지 토큰으로 CSRF 공격을 방지할 수 있는 이유는, Same-Origin 정책에 따라 악의적인 페이지에서 사용자의 토큰을 읽을 수 없기 때문입니다.

(Same-Orgin 정책 https://www.w3.org/Security/wiki/Same_Origin_Policy  은 두 개의 다른 사이트에서 호스트되고 있는 문서들이 서로 상대방의 콘텐트에 접근하는 것을 막습니다. 그래서 첫 번째 예제에서 살펴본 것처럼 악의적인 페이지에서 example.com으로 요청을 전송할 수는 있어도, 응답을 읽을 수는 없습니다.)

 

Same Origin Policy - Web Security

Same-Origin Policy There is no single same-origin policy. General Principles An origin is defined by the scheme, host, and port of a URL. Generally speaking, documents retrieved from distinct origins are isolated from each other. For example, if a document

www.w3.org

사용자가 로그인 한 이후에 브라우저가 내부적으로 자격 증명을 전송하는 모든 인증 프로토콜들은 위조 방지 토큰을 사용해야만 CSRF 공격을 방지할 수 있습니다. 그 대상에는, 폼 인증 같은 쿠키 기반 인증 프로토콜뿐만 아니라 기본 인증이나 다이제스트 인증도 포함됩니다.

또한, 모든 안전하지 않은 메서드들(POST, PUT, DELETE)에 위조 방지 토큰을 적용해야 합니다. 그리고, 안전한 메서드들도(GET, HEAD) 부작용을 일으키지 않는지 확인해야 합니다. 더군다나, CORS나 JSONP 같은 크로스-도메인 지원을 활성화시켰다면, GET 같은 안전한 메서드조차도 잠재적으로 CSRF 공격에 취약점을 갖게 되므로 공격자가 내부적으로 민감한 데이터를 읽을 수 있게 됩니다.

ASP.NET MVC의 위조 방지 토큰

Razor 페이지에 위조 방지 토큰을 추가하려면 HtmlHelper.AntiForgeryToken 도우미 메서드를 사용합니다:

==================================================================

@using (Html.BeginForm("Manage", "Account")) {

         @Html.AntiForgeryToken()

}

이 메서드는 숨겨진 폼 필드를 추가해줄 뿐만 아니라 쿠키 토큰도 설정해줍니다.

 

CSRF 방지와 AJAX

보통 AJAX 요청은 HTML 폼 데이터 대신 JSON 데이터로 전송되는 경우가 많기 때문에, AJAX 요청에서는 폼 토큰이 문제가 될 수 있습니다. 이 문제를 해결할 수 있는 한 가지 방법은 토큰을 사용자 지정 HTTP 헤더에 담아서 전송하는 것입니다. 다음 코드는 Razor 구문으로 토큰들을 생성한 다음, 이를 AJAX 요청에 추가합니다.

토큰들은 AntiForgery.GetTokens 호출을 통해서 서버 측에서 생성됩니다.

 

==============================================================

<script>

    @functions{

         public string TokenHeaderValue()

         {

                  string cookieToken, formToken;

                  AntiForgery.GetTokens(null, out cookieToken, out formToken);

                  return cookieToken + ":" + formToken;

          }

  }

 

 $.ajax("api/values", {

     type: "post",

     contentType: "application/json",

     data: { }, // JSON data goes here

     dataType: "json",

     headers: {

          'RequestVerificationToken': '@TokenHeaderValue()'

      }

   });

</script>

=============================================================

 

그리고 요청을 처리할 때, 요청 헤더에서 토큰들을 추출합니다. 그런 다음, AntiForgery.Validate 메서드를 호출해서 토큰들의 유효성을 검사합니다. 만약, 토큰이 유효하지 않으면 Validate 메서드에서 예외가 던져집니다.

=============================================================

void ValidateRequestHeader(HttpRequestMessage request)

{

       string cookieToken = "";

       string formToken = "";

 

       IEnumerable<string> tokenHeaders;

       if (request.Headers.TryGetValues("RequestVerificationToken", out tokenHeaders))

       {

            string[] tokens = tokenHeaders.First().Split(':');

            if (tokens.Length == 2)

            {

                      cookieToken = tokens[0].Trim();

                      formToken = tokens[1].Trim();

            }

       }

      AntiForgery.Validate(cookieToken, formToken);

}

 

 

http://www.egocube.pe.kr/Translation/Content/asp-net-web-api/201402030001

 

보안: 크로스 사이트 요청 위조(Cross-Site Request Forgery) 공격 방지하기

크로스 사이트 요청 위조(CSRF, Cross-Site Request Forgery) 공격은 사용자가 현재 로그인해 있는 취약한 사이트로 악의적인 사이트에서 요청을 전송하는 공격입니다.

www.egocube.pe.kr

 

크로스 사이트 요청 위조(CSRF, Cross-Site Request Forgery) 공격은 사용자가 현재 로그인해 있는 취약한 사이트로 악의적인 사이트에서 요청을 전송하는 공격입니다.

 

가령, 다음은 CSRF 공격의 한 가지 사례입니다.

 

사용자가 폼 인증을 통해서 www.example.com에 로그인합니다.

 

서버가 사용자를 인증합니다. 이 때, 서버에서 반환된 응답에는 인증 쿠키가 포함되어 있습니다

 

사용자가 로그아웃하지 않은 상태에서 악의적인 사이트를 방문합니다. 그리고, 이 악의적인 사이트에 다음과 같은 HTML 폼이 존재한다고 가정해보겠습니다. 

 

=========================================================================

<h1> You Are a Winner! </h1>

<form action="http://example.com/api/account" method="post">

      <input type="hidden" name="Transaction" value="withdraw" />

      <input type="hidden" name="Amount" value="1000000" />

      <input type="submit" value="Click Me"/>

</form>

=========================================================================

 

이 HTML 폼의 action 어트리뷰트가 악의적인 사이트가 아닌, 취약한 사이트를 가리키고 있다는 점에 유의하시기 바랍니다. 바로 이런 특징 때문에, "크로스 사이트(Cross-Site)"라는 명칭이 붙은 것입니다.

 

사용자가 "submit" 버튼을 클릭합니다. 그러면, 브라우저가 요청에 인증 쿠키를 함께 포함시켜서 전송합니다.

 

이 요청은 서버에서 사용자의 인증 컨텍스트로 실행되므로, 인증된 사용자가 수행할 수 있는 모든 작업을 수행할 수 있습니다.

 

비록, 이 예제에서는 사용자가 직접 폼 버튼을 클릭해야만 공격이 수행되지만, 악의적인 페이지에서 AJAX 요청을 전송하는 스크립트를 자동으로 실행하도록 만드는 일도 매우 간단합니다. 더군다나, 악의적인 사이트에서 "https://"로 요청을 전송할 수도 있기 때문에, SSL을 사용하더라도 CSRF 공격을 방지할 수는 없습니다.

 

대부분의 경우 CSRF 공격은 쿠키를 이용해서 인증을 수행하는 사이트들을 대상으로 행해지는데, 그 이유는 브라우저가 자동으로 모든 관련된 쿠키들을 목적지 웹 사이트로 전송하기 때문입니다. 그러나, 그렇다고 해서 반드시 쿠키를 악용하는 형태로만 CSRF 공격이 이루어지는 것은 아닙니다.

 

가령, 기본 인증과 다이제스트(Digest) 인증도 역시 CSRF 공격에 취약합니다. 즉, 사용자가 기본 인증이나 다이제스트 인증으로 로그인 한 이후, 브라우저가 자동으로 세션 종료 시까지 자격 증명을 함께 전송하기 때문입니다.

 

http://www.egocube.pe.kr/Translation/Content/asp-net-web-api/201402030001

 

보안: 크로스 사이트 요청 위조(Cross-Site Request Forgery) 공격 방지하기

크로스 사이트 요청 위조(CSRF, Cross-Site Request Forgery) 공격은 사용자가 현재 로그인해 있는 취약한 사이트로 악의적인 사이트에서 요청을 전송하는 공격입니다.

www.egocube.pe.kr

 

HSTS란?
웹 브라우저가 HTTPS프로토콜만을 사용해서 서버와 통신하도록 하는 기능
일정시간 (max-age) 동안 HSTS 응답을 받은 웹사이트에 대해서 https 접속을 강제화

HTTPS 접속이 실패하는 경우 사이트 접근에 실패하게 됨.
HSTS를 사용하는 대신 서버에서 HTTP 접속을 HTTPS로 redirect 시키는 방법이 있지만 HTTP 연결을 거쳐가는 것이기 때문에
쿠기 정보 탈취 등 보안에 취약함.

브라우저에서 http://d.com 으로 접속을 하면 웹서버에서 https로 접속하라고 보내옵니다.

HTST 설정
서버에서 HTTP 응답 헤더 필드에 'Strict-Transport-Security'라는 필드를 내려주면 브라우저는 그 사이트에
접속할 때 무조건 HTTPS로만 연결한다.
HSTS가 적용되기 위해서는 서버도 헤더를 내려줘야하고 브라우저도 그 헤더에 따른 동작을 해야 함
HTTP 응답 헤더에 정보를 내려주면 된다.

Spring Security를 사용하는 방법 

https://docs.spring.io/spring-security/site/docs/4.0.x/reference/html/headers.html#headers-hsts
HSTS 헤더 [예]
max-age=31536000 : HSTS가 브라우저에 설정될 시간이며 초단위
includeSubdomains : HSTS가 적용될 도메인의 서브 도메인(www. gurubee.net 적용 시 wiki.gurubee.net)에도 적용
preload : 브라우저가 해당 사이트를 HSTS 적용 preload list에 추가하도록 함

Strict-Transport-Security: max-age=31536000;includeSubDomains;preload


preload list
HSTS는 HTTPS로 웹 사이트에 접속하기 위해 적어도 한번 웹 서버와 통신을 해야하는데 통신 전에 미리 HTTPS로 접속하도록 목록을
미리 만들어 놓은 것.
브라우저에서 지원하는 기능이며, 브라우저 안에 기본적으로 내장되어 있는 사이트 목록들이 있음
서버가 헤더에 preload값을 내려주면 이 목록에 해당 사이트도 추가 됨.
preload에 추가된 상디트는 서버가 HSTS헤더를 삭제해도 브라우저에는 설정이 유지된다.
Chrome의 HSTS preload 리스트는 IE 등 타 브라우저에서도 활용하고 있는 것으로 파악 됨
preload list에 추가는 신중해야 함

HSTS 설정 시 주의사항
서버측 redirection 처리를 별도로 하지 않았는데 https로 자동 URL이 변경되는 경우가 있다면 HSTS 헤더를 의심
HSTS 헤더가 설정된 https url에 한번이라도 접속하면, HTTP 접속 시에도 HTTPS로 접속됨.
Spring Security에서 디폴트로 HTTPS 요청 시에 HSTS 헤더값을 내려주도록 되어 있음.

+ Recent posts