sraverify 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. sraverify/__init__.py +36 -0
  2. sraverify/checks/__init__.py +56 -0
  3. sraverify/checks/accessanalyzer/SRA_IAA_1.py +188 -0
  4. sraverify/checks/accessanalyzer/SRA_IAA_2.py +162 -0
  5. sraverify/checks/accessanalyzer/SRA_IAA_3.py +260 -0
  6. sraverify/checks/accessanalyzer/SRA_IAA_4.py +207 -0
  7. sraverify/checks/accessanalyzer/__init__.py +3 -0
  8. sraverify/checks/cloudtrail/SRA-CT-1.py +220 -0
  9. sraverify/checks/cloudtrail/SRA-CT-10.py +229 -0
  10. sraverify/checks/cloudtrail/SRA-CT-11.py +242 -0
  11. sraverify/checks/cloudtrail/SRA-CT-12.py +163 -0
  12. sraverify/checks/cloudtrail/SRA-CT-13.py +279 -0
  13. sraverify/checks/cloudtrail/SRA-CT-2.py +218 -0
  14. sraverify/checks/cloudtrail/SRA-CT-3.py +196 -0
  15. sraverify/checks/cloudtrail/SRA-CT-4.py +161 -0
  16. sraverify/checks/cloudtrail/SRA-CT-5.py +200 -0
  17. sraverify/checks/cloudtrail/SRA-CT-6.py +161 -0
  18. sraverify/checks/cloudtrail/SRA-CT-7.py +194 -0
  19. sraverify/checks/cloudtrail/SRA-CT-8.py +226 -0
  20. sraverify/checks/cloudtrail/SRA-CT-9.py +226 -0
  21. sraverify/checks/cloudtrail/__init__.py +3 -0
  22. sraverify/checks/config/SRA-CONFIG-1.py +197 -0
  23. sraverify/checks/config/__init__.py +3 -0
  24. sraverify/core/__init__.py +3 -0
  25. sraverify/core/check.py +227 -0
  26. sraverify/core/logging.py +37 -0
  27. sraverify/core/session.py +47 -0
  28. sraverify/lib/__init__.py +4 -0
  29. sraverify/lib/audit_info.py +37 -0
  30. sraverify/lib/banner.py +42 -0
  31. sraverify/lib/check_loader.py +80 -0
  32. sraverify/lib/org_mgmt_checker.py +86 -0
  33. sraverify/lib/outputs.py +46 -0
  34. sraverify/lib/progress.py +75 -0
  35. sraverify/lib/regions.py +27 -0
  36. sraverify/lib/session.py +23 -0
  37. sraverify/main.py +350 -0
  38. sraverify/services/__init__.py +3 -0
  39. sraverify/services/accessanalyzer/__init__.py +15 -0
  40. sraverify/services/accessanalyzer/base.py +123 -0
  41. sraverify/services/accessanalyzer/checks/__init__.py +3 -0
  42. sraverify/services/accessanalyzer/checks/sra_accessanalyzer_01.py +82 -0
  43. sraverify/services/accessanalyzer/checks/sra_accessanalyzer_02.py +82 -0
  44. sraverify/services/accessanalyzer/checks/sra_accessanalyzer_03.py +103 -0
  45. sraverify/services/accessanalyzer/checks/sra_accessanalyzer_04.py +139 -0
  46. sraverify/services/accessanalyzer/client.py +123 -0
  47. sraverify/services/account/__init__.py +9 -0
  48. sraverify/services/account/base.py +56 -0
  49. sraverify/services/account/checks/__init__.py +1 -0
  50. sraverify/services/account/checks/sra_account_01.py +65 -0
  51. sraverify/services/account/checks/sra_account_02.py +63 -0
  52. sraverify/services/account/checks/sra_account_03.py +63 -0
  53. sraverify/services/account/client.py +51 -0
  54. sraverify/services/auditmanager/__init__.py +10 -0
  55. sraverify/services/auditmanager/base.py +72 -0
  56. sraverify/services/auditmanager/checks/__init__.py +1 -0
  57. sraverify/services/auditmanager/checks/sra_auditmanager_01.py +58 -0
  58. sraverify/services/auditmanager/checks/sra_auditmanager_02.py +80 -0
  59. sraverify/services/auditmanager/client.py +58 -0
  60. sraverify/services/cloudtrail/__init__.py +33 -0
  61. sraverify/services/cloudtrail/base.py +167 -0
  62. sraverify/services/cloudtrail/checks/__init__.py +1 -0
  63. sraverify/services/cloudtrail/checks/sra_cloudtrail_01.py +83 -0
  64. sraverify/services/cloudtrail/checks/sra_cloudtrail_02.py +99 -0
  65. sraverify/services/cloudtrail/checks/sra_cloudtrail_03.py +94 -0
  66. sraverify/services/cloudtrail/checks/sra_cloudtrail_04.py +92 -0
  67. sraverify/services/cloudtrail/checks/sra_cloudtrail_05.py +106 -0
  68. sraverify/services/cloudtrail/checks/sra_cloudtrail_06.py +93 -0
  69. sraverify/services/cloudtrail/checks/sra_cloudtrail_07.py +96 -0
  70. sraverify/services/cloudtrail/checks/sra_cloudtrail_08.py +145 -0
  71. sraverify/services/cloudtrail/checks/sra_cloudtrail_09.py +167 -0
  72. sraverify/services/cloudtrail/checks/sra_cloudtrail_10.py +162 -0
  73. sraverify/services/cloudtrail/checks/sra_cloudtrail_11.py +178 -0
  74. sraverify/services/cloudtrail/checks/sra_cloudtrail_12.py +77 -0
  75. sraverify/services/cloudtrail/checks/sra_cloudtrail_13.py +120 -0
  76. sraverify/services/cloudtrail/client.py +118 -0
  77. sraverify/services/config/__init__.py +25 -0
  78. sraverify/services/config/base.py +249 -0
  79. sraverify/services/config/checks/__init__.py +1 -0
  80. sraverify/services/config/checks/sra_config_01.py +123 -0
  81. sraverify/services/config/checks/sra_config_02.py +156 -0
  82. sraverify/services/config/checks/sra_config_03.py +149 -0
  83. sraverify/services/config/checks/sra_config_04.py +104 -0
  84. sraverify/services/config/checks/sra_config_05.py +104 -0
  85. sraverify/services/config/checks/sra_config_06.py +194 -0
  86. sraverify/services/config/checks/sra_config_07.py +162 -0
  87. sraverify/services/config/checks/sra_config_08.py +185 -0
  88. sraverify/services/config/checks/sra_config_09.py +177 -0
  89. sraverify/services/config/client.py +264 -0
  90. sraverify/services/ec2/__init__.py +8 -0
  91. sraverify/services/ec2/base.py +75 -0
  92. sraverify/services/ec2/checks/__init__.py +1 -0
  93. sraverify/services/ec2/checks/sra_ec2_01.py +83 -0
  94. sraverify/services/ec2/client.py +63 -0
  95. sraverify/services/firewallmanager/__init__.py +23 -0
  96. sraverify/services/firewallmanager/base.py +48 -0
  97. sraverify/services/firewallmanager/checks/__init__.py +1 -0
  98. sraverify/services/firewallmanager/checks/sra_firewallmanager_01.py +75 -0
  99. sraverify/services/firewallmanager/checks/sra_firewallmanager_02.py +57 -0
  100. sraverify/services/firewallmanager/checks/sra_firewallmanager_03.py +51 -0
  101. sraverify/services/firewallmanager/checks/sra_firewallmanager_04.py +51 -0
  102. sraverify/services/firewallmanager/checks/sra_firewallmanager_05.py +51 -0
  103. sraverify/services/firewallmanager/checks/sra_firewallmanager_06.py +51 -0
  104. sraverify/services/firewallmanager/checks/sra_firewallmanager_07.py +51 -0
  105. sraverify/services/firewallmanager/checks/sra_firewallmanager_08.py +61 -0
  106. sraverify/services/firewallmanager/checks/sra_firewallmanager_09.py +61 -0
  107. sraverify/services/firewallmanager/checks/sra_firewallmanager_10.py +71 -0
  108. sraverify/services/firewallmanager/client.py +40 -0
  109. sraverify/services/guardduty/__init__.py +58 -0
  110. sraverify/services/guardduty/base.py +207 -0
  111. sraverify/services/guardduty/checks/__init__.py +3 -0
  112. sraverify/services/guardduty/checks/sra_guardduty_01.py +51 -0
  113. sraverify/services/guardduty/checks/sra_guardduty_02.py +80 -0
  114. sraverify/services/guardduty/checks/sra_guardduty_03.py +77 -0
  115. sraverify/services/guardduty/checks/sra_guardduty_04.py +84 -0
  116. sraverify/services/guardduty/checks/sra_guardduty_05.py +84 -0
  117. sraverify/services/guardduty/checks/sra_guardduty_06.py +84 -0
  118. sraverify/services/guardduty/checks/sra_guardduty_07.py +85 -0
  119. sraverify/services/guardduty/checks/sra_guardduty_08.py +83 -0
  120. sraverify/services/guardduty/checks/sra_guardduty_09.py +84 -0
  121. sraverify/services/guardduty/checks/sra_guardduty_10.py +83 -0
  122. sraverify/services/guardduty/checks/sra_guardduty_11.py +93 -0
  123. sraverify/services/guardduty/checks/sra_guardduty_12.py +83 -0
  124. sraverify/services/guardduty/checks/sra_guardduty_13.py +90 -0
  125. sraverify/services/guardduty/checks/sra_guardduty_14.py +136 -0
  126. sraverify/services/guardduty/checks/sra_guardduty_15.py +94 -0
  127. sraverify/services/guardduty/checks/sra_guardduty_16.py +94 -0
  128. sraverify/services/guardduty/checks/sra_guardduty_17.py +91 -0
  129. sraverify/services/guardduty/checks/sra_guardduty_18.py +91 -0
  130. sraverify/services/guardduty/checks/sra_guardduty_19.py +91 -0
  131. sraverify/services/guardduty/checks/sra_guardduty_20.py +111 -0
  132. sraverify/services/guardduty/checks/sra_guardduty_21.py +112 -0
  133. sraverify/services/guardduty/checks/sra_guardduty_22.py +111 -0
  134. sraverify/services/guardduty/checks/sra_guardduty_23.py +154 -0
  135. sraverify/services/guardduty/checks/sra_guardduty_24.py +111 -0
  136. sraverify/services/guardduty/checks/sra_guardduty_25.py +111 -0
  137. sraverify/services/guardduty/client.py +107 -0
  138. sraverify/services/inspector/__init__.py +29 -0
  139. sraverify/services/inspector/base.py +233 -0
  140. sraverify/services/inspector/checks/__init__.py +3 -0
  141. sraverify/services/inspector/checks/sra_inspector_01.py +69 -0
  142. sraverify/services/inspector/checks/sra_inspector_02.py +68 -0
  143. sraverify/services/inspector/checks/sra_inspector_03.py +68 -0
  144. sraverify/services/inspector/checks/sra_inspector_04.py +70 -0
  145. sraverify/services/inspector/checks/sra_inspector_05.py +69 -0
  146. sraverify/services/inspector/checks/sra_inspector_06.py +115 -0
  147. sraverify/services/inspector/checks/sra_inspector_07.py +109 -0
  148. sraverify/services/inspector/checks/sra_inspector_08.py +69 -0
  149. sraverify/services/inspector/checks/sra_inspector_09.py +69 -0
  150. sraverify/services/inspector/checks/sra_inspector_10.py +69 -0
  151. sraverify/services/inspector/checks/sra_inspector_11.py +69 -0
  152. sraverify/services/inspector/client.py +99 -0
  153. sraverify/services/macie/__init__.py +27 -0
  154. sraverify/services/macie/base.py +271 -0
  155. sraverify/services/macie/checks/__init__.py +1 -0
  156. sraverify/services/macie/checks/sra_macie_01.py +100 -0
  157. sraverify/services/macie/checks/sra_macie_02.py +102 -0
  158. sraverify/services/macie/checks/sra_macie_03.py +152 -0
  159. sraverify/services/macie/checks/sra_macie_04.py +120 -0
  160. sraverify/services/macie/checks/sra_macie_05.py +85 -0
  161. sraverify/services/macie/checks/sra_macie_06.py +124 -0
  162. sraverify/services/macie/checks/sra_macie_07.py +138 -0
  163. sraverify/services/macie/checks/sra_macie_08.py +82 -0
  164. sraverify/services/macie/checks/sra_macie_09.py +103 -0
  165. sraverify/services/macie/checks/sra_macie_10.py +81 -0
  166. sraverify/services/macie/client.py +220 -0
  167. sraverify/services/s3/__init__.py +16 -0
  168. sraverify/services/s3/base.py +69 -0
  169. sraverify/services/s3/checks/__init__.py +1 -0
  170. sraverify/services/s3/checks/sra_s3_01.py +89 -0
  171. sraverify/services/s3/checks/sra_s3_02.py +89 -0
  172. sraverify/services/s3/checks/sra_s3_03.py +88 -0
  173. sraverify/services/s3/checks/sra_s3_04.py +88 -0
  174. sraverify/services/s3/client.py +52 -0
  175. sraverify/services/securityhub/__init__.py +27 -0
  176. sraverify/services/securityhub/base.py +349 -0
  177. sraverify/services/securityhub/checks/__init__.py +1 -0
  178. sraverify/services/securityhub/checks/sra_securityhub_01.py +115 -0
  179. sraverify/services/securityhub/checks/sra_securityhub_02.py +114 -0
  180. sraverify/services/securityhub/checks/sra_securityhub_03.py +136 -0
  181. sraverify/services/securityhub/checks/sra_securityhub_04.py +75 -0
  182. sraverify/services/securityhub/checks/sra_securityhub_05.py +102 -0
  183. sraverify/services/securityhub/checks/sra_securityhub_06.py +113 -0
  184. sraverify/services/securityhub/checks/sra_securityhub_07.py +121 -0
  185. sraverify/services/securityhub/checks/sra_securityhub_08.py +113 -0
  186. sraverify/services/securityhub/checks/sra_securityhub_09.py +100 -0
  187. sraverify/services/securityhub/checks/sra_securityhub_10.py +94 -0
  188. sraverify/services/securityhub/checks/sra_securityhub_11.py +73 -0
  189. sraverify/services/securityhub/client.py +249 -0
  190. sraverify/services/securityincidentresponse/__init__.py +13 -0
  191. sraverify/services/securityincidentresponse/base.py +95 -0
  192. sraverify/services/securityincidentresponse/checks/__init__.py +1 -0
  193. sraverify/services/securityincidentresponse/checks/sra_securityincidentresponse_01.py +77 -0
  194. sraverify/services/securityincidentresponse/checks/sra_securityincidentresponse_02.py +72 -0
  195. sraverify/services/securityincidentresponse/checks/sra_securityincidentresponse_03.py +86 -0
  196. sraverify/services/securityincidentresponse/checks/sra_securityincidentresponse_04.py +117 -0
  197. sraverify/services/securityincidentresponse/checks/sra_securityincidentresponse_05.py +55 -0
  198. sraverify/services/securityincidentresponse/client.py +71 -0
  199. sraverify/services/securitylake/__init__.py +39 -0
  200. sraverify/services/securitylake/base.py +461 -0
  201. sraverify/services/securitylake/checks/__init__.py +1 -0
  202. sraverify/services/securitylake/checks/sra_securitylake_01.py +98 -0
  203. sraverify/services/securitylake/checks/sra_securitylake_02.py +133 -0
  204. sraverify/services/securitylake/checks/sra_securitylake_03.py +116 -0
  205. sraverify/services/securitylake/checks/sra_securitylake_04.py +72 -0
  206. sraverify/services/securitylake/checks/sra_securitylake_05.py +116 -0
  207. sraverify/services/securitylake/checks/sra_securitylake_06.py +104 -0
  208. sraverify/services/securitylake/checks/sra_securitylake_07.py +108 -0
  209. sraverify/services/securitylake/checks/sra_securitylake_08.py +107 -0
  210. sraverify/services/securitylake/checks/sra_securitylake_09.py +107 -0
  211. sraverify/services/securitylake/checks/sra_securitylake_10.py +106 -0
  212. sraverify/services/securitylake/checks/sra_securitylake_11.py +109 -0
  213. sraverify/services/securitylake/checks/sra_securitylake_12.py +108 -0
  214. sraverify/services/securitylake/checks/sra_securitylake_13.py +108 -0
  215. sraverify/services/securitylake/checks/sra_securitylake_14.py +72 -0
  216. sraverify/services/securitylake/checks/sra_securitylake_15.py +120 -0
  217. sraverify/services/securitylake/checks/sra_securitylake_16.py +104 -0
  218. sraverify/services/securitylake/checks/sra_securitylake_17.py +103 -0
  219. sraverify/services/securitylake/client.py +247 -0
  220. sraverify/services/shield/__init__.py +33 -0
  221. sraverify/services/shield/base.py +199 -0
  222. sraverify/services/shield/checks/__init__.py +1 -0
  223. sraverify/services/shield/checks/sra_shield_01.py +68 -0
  224. sraverify/services/shield/checks/sra_shield_02.py +77 -0
  225. sraverify/services/shield/checks/sra_shield_03.py +84 -0
  226. sraverify/services/shield/checks/sra_shield_04.py +84 -0
  227. sraverify/services/shield/checks/sra_shield_05.py +84 -0
  228. sraverify/services/shield/checks/sra_shield_06.py +84 -0
  229. sraverify/services/shield/checks/sra_shield_07.py +84 -0
  230. sraverify/services/shield/checks/sra_shield_08.py +69 -0
  231. sraverify/services/shield/checks/sra_shield_09.py +86 -0
  232. sraverify/services/shield/checks/sra_shield_10.py +100 -0
  233. sraverify/services/shield/checks/sra_shield_11.py +71 -0
  234. sraverify/services/shield/checks/sra_shield_12.py +130 -0
  235. sraverify/services/shield/checks/sra_shield_13.py +112 -0
  236. sraverify/services/shield/checks/sra_shield_14.py +111 -0
  237. sraverify/services/shield/client.py +214 -0
  238. sraverify/services/waf/__init__.py +21 -0
  239. sraverify/services/waf/base.py +100 -0
  240. sraverify/services/waf/checks/__init__.py +1 -0
  241. sraverify/services/waf/checks/sra_waf_01.py +63 -0
  242. sraverify/services/waf/checks/sra_waf_02.py +82 -0
  243. sraverify/services/waf/checks/sra_waf_03.py +123 -0
  244. sraverify/services/waf/checks/sra_waf_04.py +94 -0
  245. sraverify/services/waf/checks/sra_waf_05.py +94 -0
  246. sraverify/services/waf/checks/sra_waf_06.py +91 -0
  247. sraverify/services/waf/checks/sra_waf_07.py +94 -0
  248. sraverify/services/waf/checks/sra_waf_08.py +66 -0
  249. sraverify/services/waf/checks/sra_waf_09.py +95 -0
  250. sraverify/services/waf/client.py +109 -0
  251. sraverify/utils/__init__.py +3 -0
  252. sraverify/utils/banner.py +65 -0
  253. sraverify/utils/outputs.py +57 -0
  254. sraverify/utils/progress.py +97 -0
  255. sraverify-0.1.0.dist-info/LICENSE +175 -0
  256. sraverify-0.1.0.dist-info/METADATA +516 -0
  257. sraverify-0.1.0.dist-info/NOTICE +1 -0
  258. sraverify-0.1.0.dist-info/RECORD +261 -0
  259. sraverify-0.1.0.dist-info/WHEEL +5 -0
  260. sraverify-0.1.0.dist-info/entry_points.txt +2 -0
  261. sraverify-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,95 @@
1
+ from typing import Dict, List, Any
2
+ from sraverify.services.waf.base import WAFCheck
3
+
4
+ class SRA_WAF_09(WAFCheck):
5
+ def __init__(self):
6
+ super().__init__()
7
+ self.resource_type = "AWS::WAFv2::WebACL"
8
+ self.check_id = "SRA-WAF-09"
9
+ self.check_name = "WAF Web ACLs should have logging enabled"
10
+ self.description = "Ensures that all WAF Web ACLs have logging enabled to capture traffic analysis data"
11
+ self.severity = "MEDIUM"
12
+ self.check_logic = "Lists all WAF Web ACLs and verifies each has logging configuration enabled"
13
+
14
+ def execute(self) -> List[Dict[str, Any]]:
15
+ # Check both regional and global (CloudFront) Web ACLs
16
+ scopes = [("REGIONAL", self.regions), ("CLOUDFRONT", ["us-east-1"])]
17
+
18
+ for scope, regions in scopes:
19
+ for region in regions:
20
+ web_acls_response = self.get_web_acls(region, scope)
21
+
22
+ if "Error" in web_acls_response:
23
+ self.findings.append(self.create_finding(
24
+ status="ERROR",
25
+ region=region,
26
+ resource_id=None,
27
+ actual_value=web_acls_response["Error"].get("Message", "Unknown error"),
28
+ remediation="Check IAM permissions for WAF API access"
29
+ ))
30
+ continue
31
+
32
+ web_acls = web_acls_response.get("WebACLs", [])
33
+
34
+ if not web_acls:
35
+ self.findings.append(self.create_finding(
36
+ status="PASS",
37
+ region=region,
38
+ resource_id=f"No {scope} Web ACLs",
39
+ actual_value=f"No {scope} WAF Web ACLs found",
40
+ remediation="No action needed"
41
+ ))
42
+ continue
43
+
44
+ for web_acl in web_acls:
45
+ web_acl_arn = web_acl.get("ARN")
46
+ web_acl_name = web_acl.get("Name")
47
+ web_acl_id = web_acl.get("Id")
48
+
49
+ client = self.get_client(region)
50
+ if not client:
51
+ continue
52
+
53
+ logging_response = client.get_logging_configuration(web_acl_arn)
54
+
55
+ if "Error" in logging_response:
56
+ self.findings.append(self.create_finding(
57
+ status="ERROR",
58
+ region=region,
59
+ resource_id=web_acl_name or web_acl_id,
60
+ actual_value=logging_response["Error"].get("Message", "Unknown error"),
61
+ remediation="Check IAM permissions for WAF logging configuration access"
62
+ ))
63
+ continue
64
+
65
+ logging_config = logging_response.get("LoggingConfiguration")
66
+
67
+ if logging_config:
68
+ log_destinations = logging_config.get("LogDestinationConfigs", [])
69
+ if log_destinations:
70
+ destinations_str = ", ".join(log_destinations)
71
+ self.findings.append(self.create_finding(
72
+ status="PASS",
73
+ region=region,
74
+ resource_id=web_acl_name or web_acl_id,
75
+ actual_value=f"Logging enabled to: {destinations_str}",
76
+ remediation="No action needed"
77
+ ))
78
+ else:
79
+ self.findings.append(self.create_finding(
80
+ status="FAIL",
81
+ region=region,
82
+ resource_id=web_acl_name or web_acl_id,
83
+ actual_value="Logging configuration exists but no destinations configured",
84
+ remediation="Configure logging destinations for this WAF Web ACL using CloudWatch Logs, S3, or Kinesis Data Firehose"
85
+ ))
86
+ else:
87
+ self.findings.append(self.create_finding(
88
+ status="FAIL",
89
+ region=region,
90
+ resource_id=web_acl_name or web_acl_id,
91
+ actual_value="No logging configuration found",
92
+ remediation="Enable logging for this WAF Web ACL using CloudWatch Logs, S3, or Kinesis Data Firehose"
93
+ ))
94
+
95
+ return self.findings
@@ -0,0 +1,109 @@
1
+ from typing import Dict, List, Optional, Any
2
+ import boto3
3
+ from botocore.exceptions import ClientError
4
+ from sraverify.core.logging import logger
5
+
6
+ class WAFClient:
7
+ def __init__(self, region: str, session: Optional[boto3.Session] = None):
8
+ self.region = region
9
+ self.session = session or boto3.Session()
10
+ self.cloudfront_client = self.session.client('cloudfront', region_name='us-east-1') # CloudFront is global
11
+ self.elbv2_client = self.session.client('elbv2', region_name=region)
12
+ self.wafv2_client = self.session.client('wafv2', region_name=region)
13
+ self.apigateway_client = self.session.client('apigateway', region_name=region)
14
+ self.appsync_client = self.session.client('appsync', region_name=region)
15
+ self.cognito_idp_client = self.session.client('cognito-idp', region_name=region)
16
+ self.apprunner_client = self.session.client('apprunner', region_name=region)
17
+ self.ec2_client = self.session.client('ec2', region_name=region)
18
+ self.amplify_client = self.session.client('amplify', region_name=region)
19
+
20
+ def list_distributions(self) -> Dict[str, Any]:
21
+ try:
22
+ return self.cloudfront_client.list_distributions()
23
+ except ClientError as e:
24
+ logger.error(f"Error listing CloudFront distributions: {e}")
25
+ return {"Error": {"Message": str(e)}}
26
+
27
+ def describe_load_balancers(self) -> Dict[str, Any]:
28
+ try:
29
+ return self.elbv2_client.describe_load_balancers()
30
+ except ClientError as e:
31
+ logger.error(f"Error describing load balancers in {self.region}: {e}")
32
+ return {"Error": {"Message": str(e)}}
33
+
34
+ def get_rest_apis(self) -> Dict[str, Any]:
35
+ try:
36
+ return self.apigateway_client.get_rest_apis()
37
+ except ClientError as e:
38
+ logger.error(f"Error getting REST APIs in {self.region}: {e}")
39
+ return {"Error": {"Message": str(e)}}
40
+
41
+ def get_stages(self, rest_api_id: str) -> Dict[str, Any]:
42
+ try:
43
+ return self.apigateway_client.get_stages(restApiId=rest_api_id)
44
+ except ClientError as e:
45
+ logger.error(f"Error getting stages for REST API {rest_api_id} in {self.region}: {e}")
46
+ return {"Error": {"Message": str(e)}}
47
+
48
+ def list_graphql_apis(self) -> Dict[str, Any]:
49
+ try:
50
+ return self.appsync_client.list_graphql_apis()
51
+ except ClientError as e:
52
+ logger.error(f"Error listing GraphQL APIs in {self.region}: {e}")
53
+ return {"Error": {"Message": str(e)}}
54
+
55
+ def list_user_pools(self) -> Dict[str, Any]:
56
+ try:
57
+ return self.cognito_idp_client.list_user_pools(MaxResults=60)
58
+ except ClientError as e:
59
+ logger.error(f"Error listing user pools in {self.region}: {e}")
60
+ return {"Error": {"Message": str(e)}}
61
+
62
+ def list_services(self) -> Dict[str, Any]:
63
+ try:
64
+ return self.apprunner_client.list_services()
65
+ except ClientError as e:
66
+ logger.error(f"Error listing App Runner services in {self.region}: {e}")
67
+ return {"Error": {"Message": str(e)}}
68
+
69
+ def describe_verified_access_instances(self) -> Dict[str, Any]:
70
+ try:
71
+ return self.ec2_client.describe_verified_access_instances()
72
+ except ClientError as e:
73
+ logger.error(f"Error describing Verified Access instances in {self.region}: {e}")
74
+ return {"Error": {"Message": str(e)}}
75
+
76
+ def list_apps(self) -> Dict[str, Any]:
77
+ try:
78
+ return self.amplify_client.list_apps()
79
+ except ClientError as e:
80
+ logger.error(f"Error listing Amplify apps in {self.region}: {e}")
81
+ return {"Error": {"Message": str(e)}}
82
+
83
+ def list_web_acls(self, scope: str = "REGIONAL") -> Dict[str, Any]:
84
+ try:
85
+ return self.wafv2_client.list_web_acls(Scope=scope)
86
+ except ClientError as e:
87
+ logger.error(f"Error listing Web ACLs in {self.region}: {e}")
88
+ return {"Error": {"Message": str(e)}}
89
+
90
+ def get_logging_configuration(self, resource_arn: str) -> Dict[str, Any]:
91
+ try:
92
+ return self.wafv2_client.get_logging_configuration(ResourceArn=resource_arn)
93
+ except ClientError as e:
94
+ if e.response['Error']['Code'] == 'WAFNonexistentItemException':
95
+ return {"LoggingConfiguration": None}
96
+ logger.error(f"Error getting logging configuration for {resource_arn}: {e}")
97
+ return {"Error": {"Message": str(e)}}
98
+
99
+ def get_web_acl_for_resource(self, resource_arn: str) -> Dict[str, Any]:
100
+ try:
101
+ return self.wafv2_client.get_web_acl_for_resource(ResourceArn=resource_arn)
102
+ except ClientError as e:
103
+ if e.response['Error']['Code'] == 'WAFNonexistentItemException':
104
+ return {"WebACL": None}
105
+ elif e.response['Error']['Code'] == 'AccessDeniedException':
106
+ logger.error(f"Access denied getting web ACL for resource {resource_arn}: {e}")
107
+ return {"Error": {"Code": "AccessDeniedException", "Message": str(e)}}
108
+ logger.error(f"Error getting web ACL for resource {resource_arn}: {e}")
109
+ return {"Error": {"Message": str(e)}}
@@ -0,0 +1,3 @@
1
+ """
2
+ Utility functions for the SRA Verify framework.
3
+ """
@@ -0,0 +1,65 @@
1
+ """
2
+ Banner display for SRA Verify tool.
3
+ """
4
+ from colorama import Fore, Style
5
+ import datetime
6
+ import boto3
7
+ from typing import Optional, List, Dict, Any
8
+
9
+
10
+ def print_banner(profile: str, region: str, session: boto3.Session = None,
11
+ regions: Optional[List[str]] = None, account_type: str = 'all',
12
+ checks_count: int = 0, output_file: str = None, role: Optional[str] = None):
13
+ """
14
+ Print the SRAVerify banner and initial execution information.
15
+
16
+ Args:
17
+ profile: AWS profile name
18
+ region: AWS region name
19
+ session: AWS session
20
+ regions: List of AWS regions to check
21
+ account_type: Type of accounts to run checks against
22
+ checks_count: Number of checks to run
23
+ output_file: Output file name
24
+ role: ARN of IAM role being assumed
25
+ """
26
+ # ASCII art banner - using raw string to avoid escape sequence issues
27
+ print(fr"""
28
+ _____ _____ ___ ___ _ __
29
+ / ____| __ \ /\ \ \ / / (_)/ _|
30
+ | (___ | |__) | / \ \ \ / /__ _ __ _| |_ _ _
31
+ \___ \| _ / / /\ \ \ v / _ \| '__| | _| | | |
32
+ ____) | | \ \ / ____ \ \ / __/| | | | | | |_| |
33
+ |_____/|_| \_\/_/ \_\ \___/ \___||_| |_|_| \__, |
34
+ __/ |
35
+ |___/ {Fore.BLUE}
36
+ the security reference architecture verifier tool{Style.RESET_ALL}
37
+ """)
38
+
39
+ print(f"{Fore.YELLOW}Date: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}{Style.RESET_ALL}\n")
40
+
41
+ # Print AWS credentials information
42
+ print("-> Using the AWS credentials below:")
43
+ print(f" · AWS-CLI Profile: {profile or 'default'}")
44
+ print(f" · AWS Region: {region}")
45
+
46
+ if session:
47
+ try:
48
+ sts = session.client('sts')
49
+ caller_identity = sts.get_caller_identity()
50
+ print(f" · AWS Account: {caller_identity['Account']}")
51
+ print(f" · User Id: {caller_identity['UserId']}")
52
+ print(f" · Caller Identity ARN: {caller_identity['Arn']}")
53
+ except Exception as e:
54
+ print(f" · Unable to retrieve identity information: {str(e)}")
55
+
56
+ # Print scan information
57
+ print("\n-> Starting SRA Verify scan...")
58
+ if role:
59
+ print(f" · Assuming Role: {role}")
60
+ print(f" · Regions: {', '.join(regions) if regions else 'all enabled regions'}")
61
+ print(f" · Account Type: {account_type}")
62
+ print(f" · Checks: {checks_count}")
63
+ if output_file:
64
+ print(f" · Output: {output_file}")
65
+ print()
@@ -0,0 +1,57 @@
1
+ """
2
+ Output handling for sraverify scan results.
3
+ """
4
+ import csv
5
+ from typing import List, Dict, Any
6
+
7
+ # Required fields as per developer guide
8
+ REQUIRED_FIELDS = [
9
+ 'AccountId',
10
+ 'AccountName',
11
+ 'Region',
12
+ 'CheckId',
13
+ 'Status',
14
+ 'Severity',
15
+ 'Title',
16
+ 'Description',
17
+ 'ResourceId',
18
+ 'ResourceType',
19
+ 'CheckedValue',
20
+ 'ActualValue',
21
+ 'Remediation',
22
+ 'Service',
23
+ 'CheckLogic',
24
+ 'AccountType' # Changed from CheckType to AccountType
25
+ ]
26
+
27
+
28
+ def write_csv_output(findings: List[Dict[str, Any]], output_file: str):
29
+ """
30
+ Write scan findings to a CSV file ensuring all required fields are present.
31
+
32
+ Args:
33
+ findings: List of finding dictionaries
34
+ output_file: Path to output CSV file
35
+ """
36
+ # Always create the CSV file, even if there are no findings
37
+ if not findings:
38
+ findings = []
39
+
40
+ # Ensure each finding has all required fields
41
+ for finding in findings:
42
+ for field in REQUIRED_FIELDS:
43
+ if field not in finding:
44
+ finding[field] = '' # Add empty string for missing fields
45
+
46
+ # Handle the case where a finding might have CheckType but not AccountType
47
+ if 'CheckType' in finding and 'AccountType' not in finding:
48
+ finding['AccountType'] = finding['CheckType']
49
+ del finding['CheckType']
50
+
51
+ with open(output_file, 'w', newline='') as csvfile:
52
+ writer = csv.DictWriter(csvfile, fieldnames=REQUIRED_FIELDS)
53
+ writer.writeheader()
54
+ for finding in findings:
55
+ # Only write the required fields, in the correct order
56
+ row = {field: finding.get(field, '') for field in REQUIRED_FIELDS}
57
+ writer.writerow(row)
@@ -0,0 +1,97 @@
1
+ """
2
+ Progress tracking for scan operations.
3
+ """
4
+ import time
5
+ from typing import Optional
6
+ from colorama import Fore, Style
7
+
8
+ class ScanProgress:
9
+ """Progress tracker for scan operations."""
10
+
11
+ SPINNER = ['/', '-', '\\', '|']
12
+
13
+ def __init__(self, total_checks: int):
14
+ """
15
+ Initialize the progress tracker.
16
+
17
+ Args:
18
+ total_checks: The total number of checks to be performed
19
+
20
+ Raises:
21
+ ValueError: If total_checks is less than or equal to 0
22
+ """
23
+ if total_checks <= 0:
24
+ raise ValueError("total_checks must be greater than 0")
25
+ self.total_checks = total_checks
26
+ self.completed_checks = 0
27
+ self.start_time = time.time()
28
+ self.current_service: Optional[str] = None
29
+ self.spinner_index = 0
30
+ self.last_print_time = 0
31
+ self.print_interval = 0.1 # Update display every 0.1 seconds
32
+
33
+ @property
34
+ def progress(self) -> float:
35
+ """
36
+ Calculate the progress percentage.
37
+
38
+ Returns:
39
+ Progress percentage
40
+ """
41
+ return (self.completed_checks / self.total_checks * 100)
42
+
43
+ @property
44
+ def duration(self) -> str:
45
+ """
46
+ Calculate the elapsed time in minutes:seconds format.
47
+
48
+ Returns:
49
+ Elapsed time string
50
+ """
51
+ elapsed = int(time.time() - self.start_time)
52
+ minutes = elapsed // 60
53
+ seconds = elapsed % 60
54
+ return f"{minutes}:{seconds:02d}"
55
+
56
+ def update(self, service: str):
57
+ """
58
+ Update the current service being scanned.
59
+
60
+ Args:
61
+ service: Service name
62
+ """
63
+ self.current_service = service
64
+ self.print_progress()
65
+
66
+ def increment(self):
67
+ """Increment the completed checks counter."""
68
+ self.completed_checks += 1
69
+ self.spinner_index = (self.spinner_index + 1) % len(self.SPINNER)
70
+ self.print_progress()
71
+
72
+ def print_progress(self):
73
+ """Print the current progress status with rate limiting."""
74
+ current_time = time.time()
75
+ # Only update display if enough time has passed since last update
76
+ if current_time - self.last_print_time >= self.print_interval:
77
+ self._do_print()
78
+ self.last_print_time = current_time
79
+
80
+ def _do_print(self):
81
+ """Actually perform the progress printing."""
82
+ spinner = self.SPINNER[self.spinner_index]
83
+
84
+ # Calculate the width of the progress bar (50 characters)
85
+ bar_width = 50
86
+ filled_length = int(self.progress / 100 * bar_width)
87
+ bar = '=' * filled_length + ' ' * (bar_width - filled_length)
88
+
89
+ # Format the progress bar with current status
90
+ print(f"{Fore.BLUE}\r-> Scanning {self.current_service} service {Style.RESET_ALL} |{bar}| {spinner} "
91
+ f"{self.completed_checks}/{self.total_checks} "
92
+ f"[{self.progress:.0f}%] in {self.duration}",
93
+ end="", flush=True)
94
+
95
+ def finish(self):
96
+ """Complete the progress display with a newline."""
97
+ print() # Print newline to finish the progress display
@@ -0,0 +1,175 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.