본문 바로가기

Malware Analysis

Powershell 실행 정책 확인 및 변경

표지


Get-ExecutionPolicy

 

현재 세션에 대한 실행 정책을 얻는 명령이다.

 

 

Get-ExecutionPolicy (Microsoft.PowerShell.Security) - PowerShell

To display the execution policies for each scope in the order of precedence, use Get-ExecutionPolicy -List. To see the effective execution policy for your PowerShell session use Get-ExecutionPolicy with no parameters. The effective execution policy is dete

docs.microsoft.com

 

처음에는 기본값으로 Restricted로 설정되어 있다.

 

 

아래 msdn 페이지에서 소개하고 있는 실행 정책의 종류는 아래와 같다.

각 정책에 대한 자세한 설명은 아래 문서를 참조해라.

 

  • AllSigned
  • Bypass
  • RemoteSigned
  • Restricted
  • Undefined
  • Unrestricted

 

 

about_Execution_Policies - PowerShell

Describes the PowerShell execution policies and explains how to manage them.

docs.microsoft.com

 

Set-ExecutionPolicy

 

악성코드 분석을 하면서 특정 방식으로 인코딩된 함수나 난독화된 파워쉘 스크립트 구문도 분석해야할 일이 있다.

 

Powershell ISE를 통해서 특정 코드를 수정하기 마련인데,

기본으로 설정되어 있는 실행 정책, Restricted에서는 파워쉘 스크립트 파일 실행을 막는다.

 

그래서 실행 정책을 Unrestricted로 변경해야 할 필요성이 생긴다.

실행 정책을 변경할 때 사용하는 명령어가 Set-ExecutionPolicy 명령이다.

(참고로 파워쉘을 관리자 권한으로 실행시켜야 한다.)

 

 

Set-ExecutionPolicy (Microsoft.PowerShell.Security) - PowerShell

The Set-ExecutionPolicy cmdlet changes PowerShell execution policies for Windows computers. For more information, see about_Execution_Policies. Beginning in PowerShell 6.0 for non-Windows computers, the default execution policy is Unrestricted and can't be

docs.microsoft.com

 

아래와 같은 형태로 현재 실행정책을 확인하고, 변경하고 잘 적용되었는지 확인하는 식으로 두 명령을 이용할 수 있다.