Post

AWS Exploitation Tool (Pacu)

[0x00] overview


이전에 ncc scoutsuite 포스팅 업로드 후 공격자 입장에서 좀 더 자주 사용하는 도구를 지인에게 추천 받았다. 해당 도구의 이름은 pacu이다. 이에 대해 알아보자.

테스트에 활용한 계정은 이전 포스팅에서와 동일하게 ReadOnlyAccess, SecurityAudit인 상태로 테스트를 진행하였다(혹시나 과금이 붙을까 무서워…).

[0x01] what is pacu


pacu는 cloud 환경에 대한 공격적인 보안 테스트를 위해 설계된 opensrouce aws exploitation framework이다. 쉽게 말해 좀 더 공격적인 진단도구라고 보면 될 것 같다. python 기반으로 pip를 통해 설치하면 된다.

1
# pip3 install -U pacu

[0x02] run & setting


pacu 실행 시 아래와 같이 로고가 나오며 실행 되며, 작업을 진행할 session 이름을 지정하라고 한다. 나의 경우 ‘pacu_1’이라 하였다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
┌──(root㉿kali)-[/home/user/htb]
└─# pacu
No database found at /root/.local/share/pacu/sqlite.db
Database created at /root/.local/share/pacu/sqlite.db


 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⡿⠛⠉⠁⠀⠀⠈⠙⠻⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣷⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣤⣤⣤⣤⣤⣤⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⡿⣿⣿⣷⣦⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣈⣉⣙⣛⣿⣿⣿⣿⣿⣿⣿⣿⡟⠛⠿⢿⣿⣷⣦⣄⠀⠀⠈⠛⠋⠀⠀⠀⠈⠻⣿⣷⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣈⣉⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣀⣀⣀⣤⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣆⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣬⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢛⣉⣉⣡⣄⠀⠀⠀⠀⠀⠀⠀⠀⠻⢿⣿⣿⣶⣄⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⣁⣤⣶⡿⣿⣿⠉⠻⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢻⣿⣧⡀
 ⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⣠⣶⣿⡟⠻⣿⠃⠈⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣧
 ⢀⣀⣤⣴⣶⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⢠⣾⣿⠉⠻⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿
 ⠉⠛⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⡟
 ⠀⠀⠀⠀⠉⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⡟⠁
 ⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⡀⠀⠀⠀⠀⠀⣴⣆⢀⣴⣆⠀⣼⣆⠀⠀⣶⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⠿⠋⠀⠀
 ⠀⠀⠀⣼⣿⣿⣿⠿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠓⠒⠒⠚⠛⠛⠛⠛⠛⠛⠛⠛⠀⠀⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀
 ⠀⠀⠀⣿⣿⠟⠁⠀⢸⣿⣿⣿⣿⣿⣿⣿⣶⡀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣷⡄⠀⢀⣾⣿⣿⣿⣿⣿⣿⣷⣆⠀⢰⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠘⠁⠀⠀⠀⢸⣿⣿⡿⠛⠛⢻⣿⣿⡇⠀⢸⣿⣿⡿⠛⠛⢿⣿⣿⡇⠀⢸⣿⣿⡿⠛⠛⢻⣿⣿⣿⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠸⠿⠿⠟⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣧⣤⣤⣼⣿⣿⡇⠀⢸⣿⣿⣧⣤⣤⣼⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢀⣀⣀⣀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡏⠉⠉⠉⠉⠀⠀⠀⢸⣿⣿⡏⠉⠉⢹⣿⣿⡇⠀⢸⣿⣿⣇⣀⣀⣸⣿⣿⣿⠀⢸⣿⣿⣿⣀⣀⣀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⢿⣿⣿⣿⣿⣿⣿⣿⡟
 ⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠃⠀⠀⠘⠛⠛⠃⠀⠀⠉⠛⠛⠛⠛⠛⠛⠋⠀⠀⠀⠀⠙⠛⠛⠛⠛⠛⠉⠀
Version: 1.5.2

What would you like to name this new session? pacu_1
Session pacu_1 created.

session name 지정 후 아래와 같이 pacu_1 session 생성 확인 문구가 나오며, shell 과 같이 나타난다. 하지만 ‘No Keys Set’을 확인할 수 있다. 이는 aws의 key를 지정해주지 않아서 나오는 문구이다.

1
2
3
What would you like to name this new session? pacu_1
Session pacu_1 created.
Pacu (pacu_1:No Keys Set) >

set_keys 명령어를 실행하여 대상 aws의 access key와 secret key값을 입력해주면 된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Pacu (pacu_1:No Keys Set) > set_keys
Setting AWS Keys...
Press enter to keep the value currently stored.
Enter the letter C to clear the value, rather than set it.
If you enter an existing key_alias, that key's fields will be updated instead of added.
Key alias must be at least 2 characters

Key alias [None]: aws
Access key ID [None]: A██████████████████R
Secret access key [None]: 0█████████████████████████████████████v
Session token (Optional - for temp AWS keys only) [None]:

Keys saved to database.

Pacu (pacu_1:aws) > help

추가적인 선택사항으로, 나의 경우 서울 지약(ap-northeast-2)에 대해서만 작업을 진행하였기에 아래와 같이 set_regions를 지정해주었다.

1
2
Pacu (pacu_1:aws) > set_regions ap-northeast-2
  Session regions changed: ['ap-northeast-2']

[0x03] execute module


list 명령어를 통해 실행 가능한 모듈의 목록을 확인할 수 있다. 다만, 꽤 다양한 모듈이 존재하기에 어떤 기능인지 파악하기 어려운 항목들이 있다. 이 경우 각 모듈에 대한 설명을 해당 github에서 제공하므로 직접 확인해보면 좋다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Pacu (pacu_1:aws) > list

[Category: EVADE]

  cloudtrail__download_event_history
  cloudwatch__download_logs
  detection__disruption
  detection__enum_services
  elb__enum_logging
  guardduty__whitelist_ip
  waf__enum

[Category: RECON_UNAUTH]

  ebs__enum_snapshots_unauth
  iam__enum_roles
  iam__enum_users

[Category: ESCALATE]

  cfn__resource_injection
  iam__privesc_scan

[Category: enum]
...

ec2__enum 모듈을 실행하면 아래와 같이 수집된 결과를 보여준다. run 모듈명과 같은 형태로 실행하면 된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Pacu (pacu_1:aws) > run ec2__enum
  Running module ec2__enum...
[ec2__enum] Starting region ap-northeast-2...
[ec2__enum]   1 instance(s) found.
[ec2__enum]   3 security groups(s) found.
[ec2__enum]   0 elastic IP address(es) found.
[ec2__enum]   1 publics IP address(es) found and added to text file located at: ~/.local/share/pacu/pacu_1/downloads/ec2_public_ips_pacu_1_ap-northeast-2.txt
[ec2__enum]   0 VPN customer gateway(s) found.
[ec2__enum]   0 dedicated host(s) found.
[ec2__enum]   1 network ACL(s) found.
[ec2__enum]   0 NAT gateway(s) found.
[ec2__enum]   1 network interface(s) found.
[ec2__enum]   1 route table(s) found.
[ec2__enum]   4 subnet(s) found.
[ec2__enum]   1 VPC(s) found.
[ec2__enum]   0 VPC endpoint(s) found.
[ec2__enum]   0 launch template(s) found.
[ec2__enum] ec2__enum completed.

모듈 목록 중 인스턴스 실행 시 구동되는 startup에 script를 등록하는 항목이 있어 시도해보았다. 적절한 권한이 없어서 그런지 실패 문구를 확인할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
Pacu (pacu_1:aws) > run ec2__startup_shell_script --script test.sh
  Running module ec2__startup_shell_script...
[ec2__startup_shell_script] Targeting all EC2 instances...
[ec2__startup_shell_script] Stopping i-082██████████1eb3
[ec2__startup_shell_script] FAILURE:
[ec2__startup_shell_script]   Access denied to StopInstances.
[ec2__startup_shell_script]   i-082██████████1eb3@ap-northeast-2 FAILED
[ec2__startup_shell_script] ec2__startup_shell_script completed.

[ec2__startup_shell_script] MODULE SUMMARY:

  No Instances Modified

실제 공격에 활용하는 예시는 추후 문제 풀이 과정에 나오면 내용을 추가하겠다.

[0x04] conclusion


다양한 모듈이 있는 만큼 공식 문서를 잘 참고하면 될 듯 하다. ESCALATE, RECON_UNAUTH 항목을 통해 권한 상승이 가능한지 확인 후, EXPLOIT 항목을 통해 공격을 진행, PERSIST 모듈들을 통해 지속성 유지까지 하나의 tool로 편하게 진행하면 될 듯 하다.

Reference


  • https://github.com/RhinoSecurityLabs/pacu
  • https://rzepsky.medium.com/playing-with-cloudgoat-part-5-hacking-aws-with-pacu-6abe1cf5780d
This post is licensed under CC BY 4.0 by the author.