inspec 4.18.51 → 4.18.85

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. checksums.yaml +4 -4
  2. data/inspec.gemspec +15 -37
  3. data/lib/resource_support/aws/aws_resource_mixin.rb +1 -1
  4. metadata +22 -709
  5. data/Gemfile +0 -61
  6. data/LICENSE +0 -14
  7. data/README.md +0 -474
  8. data/etc/deprecations.json +0 -125
  9. data/etc/plugin_filters.json +0 -45
  10. data/lib/bundles/README.md +0 -3
  11. data/lib/bundles/inspec-compliance/api.rb +0 -7
  12. data/lib/bundles/inspec-compliance/configuration.rb +0 -7
  13. data/lib/bundles/inspec-compliance/http.rb +0 -7
  14. data/lib/bundles/inspec-compliance/support.rb +0 -7
  15. data/lib/bundles/inspec-compliance/target.rb +0 -7
  16. data/lib/bundles/inspec-supermarket.rb +0 -9
  17. data/lib/bundles/inspec-supermarket/README.md +0 -45
  18. data/lib/bundles/inspec-supermarket/api.rb +0 -87
  19. data/lib/bundles/inspec-supermarket/cli.rb +0 -71
  20. data/lib/bundles/inspec-supermarket/target.rb +0 -31
  21. data/lib/inspec.rb +0 -30
  22. data/lib/inspec/archive/tar.rb +0 -25
  23. data/lib/inspec/archive/zip.rb +0 -15
  24. data/lib/inspec/backend.rb +0 -101
  25. data/lib/inspec/base_cli.rb +0 -318
  26. data/lib/inspec/cached_fetcher.rb +0 -65
  27. data/lib/inspec/cli.rb +0 -469
  28. data/lib/inspec/completions/bash.sh.erb +0 -45
  29. data/lib/inspec/completions/fish.sh.erb +0 -34
  30. data/lib/inspec/completions/zsh.sh.erb +0 -61
  31. data/lib/inspec/config.rb +0 -511
  32. data/lib/inspec/control_eval_context.rb +0 -248
  33. data/lib/inspec/dependencies/cache.rb +0 -74
  34. data/lib/inspec/dependencies/dependency_set.rb +0 -93
  35. data/lib/inspec/dependencies/lockfile.rb +0 -115
  36. data/lib/inspec/dependencies/requirement.rb +0 -135
  37. data/lib/inspec/dependencies/resolver.rb +0 -86
  38. data/lib/inspec/describe_base.rb +0 -53
  39. data/lib/inspec/dist.rb +0 -20
  40. data/lib/inspec/dsl.rb +0 -115
  41. data/lib/inspec/dsl_shared.rb +0 -32
  42. data/lib/inspec/env_printer.rb +0 -156
  43. data/lib/inspec/errors.rb +0 -18
  44. data/lib/inspec/exceptions.rb +0 -11
  45. data/lib/inspec/expect.rb +0 -42
  46. data/lib/inspec/fetcher.rb +0 -48
  47. data/lib/inspec/fetcher/git.rb +0 -211
  48. data/lib/inspec/fetcher/local.rb +0 -116
  49. data/lib/inspec/fetcher/mock.rb +0 -34
  50. data/lib/inspec/fetcher/url.rb +0 -281
  51. data/lib/inspec/file_provider.rb +0 -318
  52. data/lib/inspec/formatters.rb +0 -3
  53. data/lib/inspec/formatters/base.rb +0 -269
  54. data/lib/inspec/formatters/json_rspec.rb +0 -20
  55. data/lib/inspec/formatters/show_progress.rb +0 -12
  56. data/lib/inspec/globals.rb +0 -9
  57. data/lib/inspec/impact.rb +0 -36
  58. data/lib/inspec/input.rb +0 -421
  59. data/lib/inspec/input_dsl_helpers.rb +0 -26
  60. data/lib/inspec/input_registry.rb +0 -315
  61. data/lib/inspec/library_eval_context.rb +0 -55
  62. data/lib/inspec/log.rb +0 -7
  63. data/lib/inspec/metadata.rb +0 -253
  64. data/lib/inspec/method_source.rb +0 -20
  65. data/lib/inspec/objects.rb +0 -14
  66. data/lib/inspec/objects/control.rb +0 -85
  67. data/lib/inspec/objects/describe.rb +0 -106
  68. data/lib/inspec/objects/each_loop.rb +0 -41
  69. data/lib/inspec/objects/input.rb +0 -49
  70. data/lib/inspec/objects/list.rb +0 -15
  71. data/lib/inspec/objects/or_test.rb +0 -45
  72. data/lib/inspec/objects/ruby_helper.rb +0 -13
  73. data/lib/inspec/objects/tag.rb +0 -32
  74. data/lib/inspec/objects/test.rb +0 -94
  75. data/lib/inspec/objects/value.rb +0 -32
  76. data/lib/inspec/plugin/v1.rb +0 -2
  77. data/lib/inspec/plugin/v1/plugin_types/cli.rb +0 -22
  78. data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +0 -83
  79. data/lib/inspec/plugin/v1/plugin_types/resource.rb +0 -176
  80. data/lib/inspec/plugin/v1/plugin_types/secret.rb +0 -11
  81. data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +0 -36
  82. data/lib/inspec/plugin/v1/plugins.rb +0 -59
  83. data/lib/inspec/plugin/v1/registry.rb +0 -90
  84. data/lib/inspec/plugin/v2.rb +0 -46
  85. data/lib/inspec/plugin/v2/activator.rb +0 -40
  86. data/lib/inspec/plugin/v2/config_file.rb +0 -151
  87. data/lib/inspec/plugin/v2/filter.rb +0 -96
  88. data/lib/inspec/plugin/v2/installer.rb +0 -512
  89. data/lib/inspec/plugin/v2/loader.rb +0 -321
  90. data/lib/inspec/plugin/v2/plugin_base.rb +0 -112
  91. data/lib/inspec/plugin/v2/plugin_types/cli.rb +0 -49
  92. data/lib/inspec/plugin/v2/plugin_types/dsl.rb +0 -11
  93. data/lib/inspec/plugin/v2/plugin_types/input.rb +0 -34
  94. data/lib/inspec/plugin/v2/plugin_types/mock.rb +0 -12
  95. data/lib/inspec/plugin/v2/registry.rb +0 -98
  96. data/lib/inspec/plugin/v2/status.rb +0 -29
  97. data/lib/inspec/profile.rb +0 -658
  98. data/lib/inspec/profile_context.rb +0 -203
  99. data/lib/inspec/profile_vendor.rb +0 -84
  100. data/lib/inspec/reporters.rb +0 -73
  101. data/lib/inspec/reporters/automate.rb +0 -78
  102. data/lib/inspec/reporters/base.rb +0 -25
  103. data/lib/inspec/reporters/cli.rb +0 -370
  104. data/lib/inspec/reporters/json.rb +0 -113
  105. data/lib/inspec/reporters/json_automate.rb +0 -80
  106. data/lib/inspec/reporters/json_min.rb +0 -48
  107. data/lib/inspec/reporters/junit.rb +0 -77
  108. data/lib/inspec/reporters/yaml.rb +0 -20
  109. data/lib/inspec/require_loader.rb +0 -29
  110. data/lib/inspec/resource.rb +0 -114
  111. data/lib/inspec/resources.rb +0 -130
  112. data/lib/inspec/resources/aide_conf.rb +0 -153
  113. data/lib/inspec/resources/apache.rb +0 -47
  114. data/lib/inspec/resources/apache_conf.rb +0 -156
  115. data/lib/inspec/resources/apt.rb +0 -151
  116. data/lib/inspec/resources/audit_policy.rb +0 -64
  117. data/lib/inspec/resources/auditd.rb +0 -251
  118. data/lib/inspec/resources/auditd_conf.rb +0 -45
  119. data/lib/inspec/resources/bash.rb +0 -33
  120. data/lib/inspec/resources/bond.rb +0 -70
  121. data/lib/inspec/resources/bridge.rb +0 -125
  122. data/lib/inspec/resources/bsd_service.rb +0 -2
  123. data/lib/inspec/resources/chocolatey_package.rb +0 -82
  124. data/lib/inspec/resources/command.rb +0 -91
  125. data/lib/inspec/resources/cpan.rb +0 -58
  126. data/lib/inspec/resources/cran.rb +0 -64
  127. data/lib/inspec/resources/crontab.rb +0 -173
  128. data/lib/inspec/resources/csv.rb +0 -56
  129. data/lib/inspec/resources/dh_params.rb +0 -83
  130. data/lib/inspec/resources/directory.rb +0 -23
  131. data/lib/inspec/resources/docker.rb +0 -274
  132. data/lib/inspec/resources/docker_container.rb +0 -91
  133. data/lib/inspec/resources/docker_image.rb +0 -84
  134. data/lib/inspec/resources/docker_object.rb +0 -52
  135. data/lib/inspec/resources/docker_plugin.rb +0 -64
  136. data/lib/inspec/resources/docker_service.rb +0 -91
  137. data/lib/inspec/resources/elasticsearch.rb +0 -165
  138. data/lib/inspec/resources/etc_fstab.rb +0 -96
  139. data/lib/inspec/resources/etc_group.rb +0 -157
  140. data/lib/inspec/resources/etc_hosts.rb +0 -68
  141. data/lib/inspec/resources/etc_hosts_allow.rb +0 -2
  142. data/lib/inspec/resources/etc_hosts_allow_deny.rb +0 -114
  143. data/lib/inspec/resources/etc_hosts_deny.rb +0 -2
  144. data/lib/inspec/resources/file.rb +0 -339
  145. data/lib/inspec/resources/filesystem.rb +0 -139
  146. data/lib/inspec/resources/firewalld.rb +0 -148
  147. data/lib/inspec/resources/gem.rb +0 -80
  148. data/lib/inspec/resources/group.rb +0 -2
  149. data/lib/inspec/resources/groups.rb +0 -241
  150. data/lib/inspec/resources/grub_conf.rb +0 -230
  151. data/lib/inspec/resources/host.rb +0 -310
  152. data/lib/inspec/resources/http.rb +0 -275
  153. data/lib/inspec/resources/iis_app.rb +0 -101
  154. data/lib/inspec/resources/iis_app_pool.rb +0 -127
  155. data/lib/inspec/resources/iis_site.rb +0 -148
  156. data/lib/inspec/resources/iis_website.rb +0 -2
  157. data/lib/inspec/resources/inetd_conf.rb +0 -53
  158. data/lib/inspec/resources/ini.rb +0 -28
  159. data/lib/inspec/resources/interface.rb +0 -204
  160. data/lib/inspec/resources/ip6tables.rb +0 -79
  161. data/lib/inspec/resources/iptables.rb +0 -80
  162. data/lib/inspec/resources/json.rb +0 -116
  163. data/lib/inspec/resources/kernel_module.rb +0 -106
  164. data/lib/inspec/resources/kernel_parameter.rb +0 -54
  165. data/lib/inspec/resources/key_rsa.rb +0 -66
  166. data/lib/inspec/resources/ksh.rb +0 -33
  167. data/lib/inspec/resources/launchd_service.rb +0 -2
  168. data/lib/inspec/resources/limits_conf.rb +0 -45
  169. data/lib/inspec/resources/linux_kernel_parameter.rb +0 -2
  170. data/lib/inspec/resources/login_defs.rb +0 -56
  171. data/lib/inspec/resources/mount.rb +0 -88
  172. data/lib/inspec/resources/mssql_session.rb +0 -117
  173. data/lib/inspec/resources/mysql.rb +0 -81
  174. data/lib/inspec/resources/mysql_conf.rb +0 -128
  175. data/lib/inspec/resources/mysql_session.rb +0 -88
  176. data/lib/inspec/resources/nginx.rb +0 -96
  177. data/lib/inspec/resources/nginx_conf.rb +0 -232
  178. data/lib/inspec/resources/noop.rb +0 -9
  179. data/lib/inspec/resources/npm.rb +0 -68
  180. data/lib/inspec/resources/ntp_conf.rb +0 -51
  181. data/lib/inspec/resources/oneget.rb +0 -71
  182. data/lib/inspec/resources/oracledb_session.rb +0 -149
  183. data/lib/inspec/resources/os.rb +0 -34
  184. data/lib/inspec/resources/os_env.rb +0 -86
  185. data/lib/inspec/resources/package.rb +0 -391
  186. data/lib/inspec/resources/packages.rb +0 -111
  187. data/lib/inspec/resources/parse_config.rb +0 -112
  188. data/lib/inspec/resources/parse_config_file.rb +0 -2
  189. data/lib/inspec/resources/passwd.rb +0 -73
  190. data/lib/inspec/resources/pip.rb +0 -132
  191. data/lib/inspec/resources/platform.rb +0 -112
  192. data/lib/inspec/resources/port.rb +0 -791
  193. data/lib/inspec/resources/postfix_conf.rb +0 -35
  194. data/lib/inspec/resources/postgres.rb +0 -152
  195. data/lib/inspec/resources/postgres_conf.rb +0 -116
  196. data/lib/inspec/resources/postgres_hba_conf.rb +0 -86
  197. data/lib/inspec/resources/postgres_ident_conf.rb +0 -75
  198. data/lib/inspec/resources/postgres_session.rb +0 -70
  199. data/lib/inspec/resources/powershell.rb +0 -67
  200. data/lib/inspec/resources/ppa.rb +0 -2
  201. data/lib/inspec/resources/processes.rb +0 -219
  202. data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
  203. data/lib/inspec/resources/rabbitmq_config.rb +0 -52
  204. data/lib/inspec/resources/registry_key.rb +0 -296
  205. data/lib/inspec/resources/runit_service.rb +0 -2
  206. data/lib/inspec/resources/script.rb +0 -1
  207. data/lib/inspec/resources/security_identifier.rb +0 -91
  208. data/lib/inspec/resources/security_policy.rb +0 -182
  209. data/lib/inspec/resources/service.rb +0 -820
  210. data/lib/inspec/resources/shadow.rb +0 -150
  211. data/lib/inspec/resources/ssh_config.rb +0 -98
  212. data/lib/inspec/resources/sshd_config.rb +0 -2
  213. data/lib/inspec/resources/ssl.rb +0 -99
  214. data/lib/inspec/resources/sys_info.rb +0 -119
  215. data/lib/inspec/resources/systemd_service.rb +0 -2
  216. data/lib/inspec/resources/sysv_service.rb +0 -2
  217. data/lib/inspec/resources/toml.rb +0 -30
  218. data/lib/inspec/resources/upstart_service.rb +0 -2
  219. data/lib/inspec/resources/user.rb +0 -1
  220. data/lib/inspec/resources/users.rb +0 -742
  221. data/lib/inspec/resources/vbscript.rb +0 -67
  222. data/lib/inspec/resources/virtualization.rb +0 -255
  223. data/lib/inspec/resources/windows_feature.rb +0 -126
  224. data/lib/inspec/resources/windows_hotfix.rb +0 -37
  225. data/lib/inspec/resources/windows_registry_key.rb +0 -2
  226. data/lib/inspec/resources/windows_task.rb +0 -112
  227. data/lib/inspec/resources/wmi.rb +0 -109
  228. data/lib/inspec/resources/x509_certificate.rb +0 -143
  229. data/lib/inspec/resources/xinetd_conf.rb +0 -103
  230. data/lib/inspec/resources/xml.rb +0 -48
  231. data/lib/inspec/resources/yaml.rb +0 -42
  232. data/lib/inspec/resources/yum.rb +0 -162
  233. data/lib/inspec/resources/zfs_dataset.rb +0 -62
  234. data/lib/inspec/resources/zfs_pool.rb +0 -50
  235. data/lib/inspec/rspec_extensions.rb +0 -116
  236. data/lib/inspec/rule.rb +0 -389
  237. data/lib/inspec/runner.rb +0 -333
  238. data/lib/inspec/runner_mock.rb +0 -37
  239. data/lib/inspec/runner_rspec.rb +0 -184
  240. data/lib/inspec/runtime_profile.rb +0 -23
  241. data/lib/inspec/schema.rb +0 -245
  242. data/lib/inspec/secrets.rb +0 -15
  243. data/lib/inspec/secrets/yaml.rb +0 -29
  244. data/lib/inspec/shell.rb +0 -211
  245. data/lib/inspec/shell_detector.rb +0 -89
  246. data/lib/inspec/source_reader.rb +0 -26
  247. data/lib/inspec/ui.rb +0 -213
  248. data/lib/inspec/ui_table_helper.rb +0 -12
  249. data/lib/inspec/utils/command_wrapper.rb +0 -23
  250. data/lib/inspec/utils/convert.rb +0 -8
  251. data/lib/inspec/utils/database_helpers.rb +0 -75
  252. data/lib/inspec/utils/deprecation.rb +0 -6
  253. data/lib/inspec/utils/deprecation/config_file.rb +0 -109
  254. data/lib/inspec/utils/deprecation/deprecator.rb +0 -118
  255. data/lib/inspec/utils/deprecation/errors.rb +0 -14
  256. data/lib/inspec/utils/deprecation/global_method.rb +0 -9
  257. data/lib/inspec/utils/enumerable_delegation.rb +0 -7
  258. data/lib/inspec/utils/erlang_parser.rb +0 -190
  259. data/lib/inspec/utils/file_reader.rb +0 -24
  260. data/lib/inspec/utils/filter.rb +0 -461
  261. data/lib/inspec/utils/filter_array.rb +0 -25
  262. data/lib/inspec/utils/find_files.rb +0 -44
  263. data/lib/inspec/utils/hash.rb +0 -37
  264. data/lib/inspec/utils/json_log.rb +0 -15
  265. data/lib/inspec/utils/modulator.rb +0 -9
  266. data/lib/inspec/utils/nginx_parser.rb +0 -101
  267. data/lib/inspec/utils/object_traversal.rb +0 -47
  268. data/lib/inspec/utils/parser.rb +0 -277
  269. data/lib/inspec/utils/pkey_reader.rb +0 -17
  270. data/lib/inspec/utils/simpleconfig.rb +0 -121
  271. data/lib/inspec/utils/spdx.rb +0 -10
  272. data/lib/inspec/utils/spdx.txt +0 -383
  273. data/lib/inspec/utils/telemetry.rb +0 -3
  274. data/lib/inspec/utils/telemetry/collector.rb +0 -81
  275. data/lib/inspec/utils/telemetry/data_series.rb +0 -44
  276. data/lib/inspec/utils/telemetry/global_methods.rb +0 -22
  277. data/lib/inspec/version.rb +0 -3
  278. data/lib/matchers/matchers.rb +0 -341
  279. data/lib/plugins/README.md +0 -16
  280. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +0 -12
  281. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +0 -170
  282. data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +0 -116
  283. data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +0 -50
  284. data/lib/plugins/inspec-compliance/README.md +0 -207
  285. data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +0 -12
  286. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +0 -362
  287. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +0 -198
  288. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +0 -269
  289. data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +0 -103
  290. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +0 -117
  291. data/lib/plugins/inspec-compliance/lib/inspec-compliance/images/cc-token.png +0 -0
  292. data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +0 -34
  293. data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +0 -146
  294. data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +0 -53
  295. data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +0 -91
  296. data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +0 -190
  297. data/lib/plugins/inspec-compliance/test/unit/api_test.rb +0 -386
  298. data/lib/plugins/inspec-compliance/test/unit/target_test.rb +0 -155
  299. data/lib/plugins/inspec-habitat/Berksfile +0 -5
  300. data/lib/plugins/inspec-habitat/README.md +0 -150
  301. data/lib/plugins/inspec-habitat/kitchen.yml +0 -28
  302. data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +0 -11
  303. data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +0 -41
  304. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +0 -265
  305. data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +0 -6
  306. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +0 -2
  307. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md +0 -3
  308. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp +0 -28
  309. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +0 -9
  310. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +0 -61
  311. data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +0 -34
  312. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md +0 -3
  313. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +0 -40
  314. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml +0 -10
  315. data/lib/plugins/inspec-habitat/test/support/example_profile/README.md +0 -3
  316. data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +0 -7
  317. data/lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml +0 -10
  318. data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +0 -242
  319. data/lib/plugins/inspec-init/README.md +0 -31
  320. data/lib/plugins/inspec-init/lib/inspec-init.rb +0 -12
  321. data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +0 -15
  322. data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +0 -243
  323. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +0 -47
  324. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +0 -97
  325. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -11
  326. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/LICENSE +0 -2
  327. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md +0 -28
  328. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile +0 -40
  329. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -14
  330. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -62
  331. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -53
  332. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -8
  333. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +0 -24
  334. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +0 -12
  335. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +0 -110
  336. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +0 -24
  337. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +0 -17
  338. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +0 -67
  339. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +0 -51
  340. data/lib/plugins/inspec-init/templates/profiles/aws/libraries/.gitkeep +0 -0
  341. data/lib/plugins/inspec-init/templates/profiles/azure/libraries/.gitkeep +0 -0
  342. data/lib/plugins/inspec-init/templates/profiles/gcp/libraries/.gitkeep +0 -0
  343. data/lib/plugins/inspec-init/templates/profiles/os/README.md +0 -3
  344. data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +0 -18
  345. data/lib/plugins/inspec-init/templates/profiles/os/inspec.yml +0 -10
  346. data/lib/plugins/inspec-init/templates/profiles/os/libraries/.gitkeep +0 -0
  347. data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +0 -184
  348. data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +0 -121
  349. data/lib/plugins/inspec-plugin-manager-cli/README.md +0 -6
  350. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +0 -17
  351. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +0 -518
  352. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +0 -12
  353. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
  354. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +0 -2
  355. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
  356. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
  357. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +0 -1
  358. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
  359. data/lib/plugins/inspec-plugin-manager-cli/test/functional/help_test.rb +0 -23
  360. data/lib/plugins/inspec-plugin-manager-cli/test/functional/helper.rb +0 -62
  361. data/lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb +0 -368
  362. data/lib/plugins/inspec-plugin-manager-cli/test/functional/list_test.rb +0 -101
  363. data/lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb +0 -129
  364. data/lib/plugins/inspec-plugin-manager-cli/test/functional/uninstall_test.rb +0 -63
  365. data/lib/plugins/inspec-plugin-manager-cli/test/functional/update_test.rb +0 -84
  366. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +0 -77
  367. data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +0 -39
  368. data/lib/plugins/shared/core_plugin_test_helper.rb +0 -153
  369. data/lib/plugins/things-for-train-integration.rb +0 -14
  370. data/lib/source_readers/flat.rb +0 -36
  371. data/lib/source_readers/inspec.rb +0 -66
@@ -1,791 +0,0 @@
1
- require "inspec/utils/parser"
2
- require "inspec/utils/filter"
3
- require "ipaddr"
4
-
5
- # TODO: currently we return local ip only
6
- # TODO: improve handling of same port on multiple interfaces
7
- module Inspec::Resources
8
- class Port < Inspec.resource(1)
9
- name "port"
10
- supports platform: "unix"
11
- supports platform: "windows"
12
- desc "Use the port InSpec audit resource to test basic port properties, such as port, process, if it's listening."
13
- example <<~EXAMPLE
14
- describe port(80) do
15
- it { should be_listening }
16
- its('protocols') {should eq ['tcp']}
17
- its('addresses') {should eq ['127.0.0.1']}
18
- end
19
-
20
- describe port.where { protocol =~ /tcp/ && port > 80 } do
21
- it { should_not be_listening }
22
- end
23
- EXAMPLE
24
-
25
- def initialize(*args)
26
- args.unshift(nil) if args.length <= 1 # add the ip address to the front
27
- @ip = args[0]
28
- @port = if args[1].nil?
29
- nil
30
- else
31
- args[1].to_i
32
- end
33
-
34
- @cache = nil
35
- @port_manager = port_manager_for_os
36
- return skip_resource "The `port` resource is not supported on your OS yet." if @port_manager.nil?
37
- end
38
-
39
- filter = FilterTable.create
40
- filter.register_column(:ports, field: "port", style: :simple)
41
- .register_column(:addresses, field: "address", style: :simple)
42
- .register_column(:protocols, field: "protocol", style: :simple)
43
- .register_column(:processes, field: "process", style: :simple)
44
- .register_column(:pids, field: "pid", style: :simple)
45
- .register_custom_matcher(:listening?) { |x| !x.entries.empty? }
46
- filter.install_filter_methods_on_resource(self, :info)
47
-
48
- def to_s
49
- "Port #{@port}"
50
- end
51
-
52
- private
53
-
54
- def port_manager_for_os
55
- os = inspec.os
56
- if os.linux?
57
- LinuxPorts.new(inspec)
58
- elsif os.aix?
59
- # AIX: see http://www.ibm.com/developerworks/aix/library/au-lsof.html#resources
60
- # and https://www-01.ibm.com/marketing/iwm/iwm/web/reg/pick.do?source=aixbp
61
- AixPorts.new(inspec)
62
- elsif os.darwin?
63
- # Darwin: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html
64
- # Careful: make sure darwin comes before BSD, below
65
- LsofPorts.new(inspec)
66
- elsif os.windows?
67
- WindowsPorts.new(inspec)
68
- elsif os.bsd?
69
- # Relies on sockstat, usually present on FreeBSD and NetBSD (but not MacOS X)
70
- FreeBsdPorts.new(inspec)
71
- elsif os.solaris?
72
- SolarisPorts.new(inspec)
73
- elsif os.hpux?
74
- HpuxPorts.new(inspec)
75
- end
76
- end
77
-
78
- def info
79
- return @cache unless @cache.nil?
80
- # abort if os detection has not worked
81
- return @cache = [] if @port_manager.nil?
82
-
83
- # query ports
84
- cache = @port_manager.info || []
85
- cache.select! { |x| x["port"] == @port } unless @port.nil?
86
- cache.select! { |x| x["address"] == @ip } unless @ip.nil?
87
- @cache = cache
88
- end
89
- end
90
-
91
- # implements an info method and returns all ip adresses and protocols for
92
- # each port
93
- # [{
94
- # 'port' => 22,
95
- # 'address' => '0.0.0.0'
96
- # 'protocol' => 'tcp'
97
- # },
98
- # {
99
- # 'port' => 22,
100
- # 'address' => '::'
101
- # 'protocol' => 'tcp6'
102
- # }]
103
- class PortsInfo
104
- attr_reader :inspec
105
- def initialize(inspec)
106
- @inspec = inspec
107
- end
108
- end
109
-
110
- # TODO: Add UDP infromation Get-NetUDPEndpoint
111
- # TODO: currently Windows only supports tcp ports
112
- # TODO: Get-NetTCPConnection does not return PIDs
113
- # TODO: double-check output with 'netstat -ano'
114
- # @see https://connect.microsoft.com/PowerShell/feedback/details/1349420/get-nettcpconnection-does-not-show-processid
115
- class WindowsPorts < PortsInfo
116
- def info
117
- netstat_info || powershell_info
118
- end
119
-
120
- private
121
-
122
- def powershell_info
123
- cmd = inspec.command("Get-NetTCPConnection -state Listen | Select-Object -Property State, Caption, Description, LocalAddress, LocalPort, RemoteAddress, RemotePort, DisplayName, Status | ConvertTo-Json")
124
- return nil if cmd.exit_status != 0
125
-
126
- entries = JSON.parse(cmd.stdout)
127
- return nil if entries.nil?
128
-
129
- entries.map do |x|
130
- {
131
- "port" => x["LocalPort"],
132
- "address" => x["LocalAddress"],
133
- "protocol" => "tcp",
134
- }
135
- end
136
- rescue JSON::ParserError => _e
137
- nil
138
- end
139
-
140
- def netstat_info
141
- # retrieve processes grepping by LISTENING state with 0 lines before and 1 after to catch the process name
142
- # also UDP ports have nothing in the State column
143
- cmd = inspec.command('netstat -anbo | Select-String -CaseSensitive -pattern "^\s+UDP|\s+LISTENING\s+\d+$" -context 0,1')
144
- return nil if cmd.exit_status != 0
145
-
146
- lines = cmd.stdout.scan(/^>\s*(tcp\S*|udp\S*)\s+(\S+):(\d+)\s+(\S+)\s+(\S*)\s+(\d+)\s+(.+)/i)
147
- lines.map do |line|
148
- pid = line[5].to_i
149
- process = line[6].delete("[").delete("]").strip
150
- process = "System" if process == "Can not obtain ownership information" && pid == 4
151
- {
152
- "port" => line[2].to_i,
153
- "address" => line[1].delete("[").delete("]"),
154
- "protocol" => line[0].downcase,
155
- "pid" => pid,
156
- "process" => process,
157
- }
158
- end
159
- end
160
- end
161
-
162
- # extracts udp and tcp ports from the lsof command
163
- class LsofPorts < PortsInfo
164
- attr_reader :lsof
165
-
166
- def initialize(inspec, lsofpath = nil)
167
- @lsof = lsofpath || "lsof"
168
- super(inspec)
169
- end
170
-
171
- def info
172
- ports = []
173
-
174
- # check that lsof is available, otherwise fail
175
- raise "Please ensure `lsof` is available on the machine." unless inspec.command(@lsof.to_s).exist?
176
-
177
- # -F p=pid, c=command, P=protocol name, t=type, n=internet addresses
178
- # see 'OUTPUT FOR OTHER PROGRAMS' in LSOF(8)
179
- lsof_cmd = inspec.command("#{@lsof} -nP -i -FpctPn")
180
- return nil if lsof_cmd.exit_status.to_i != 0
181
-
182
- # map to desired return struct
183
- lsof_parser(lsof_cmd).each do |process, port_ids|
184
- pid, cmd = process.split(":")
185
- port_ids.each do |port_str|
186
- # should not break on ipv6 addresses
187
- ipv, proto, port, host = port_str.split(":", 4)
188
- ports.push({ "port" => port.to_i,
189
- "address" => host,
190
- "protocol" => ipv == "ipv6" ? proto + "6" : proto,
191
- "process" => cmd,
192
- "pid" => pid.to_i })
193
- end
194
- end
195
-
196
- ports
197
- end
198
-
199
- # rubocop:disable Metrics/CyclomaticComplexity
200
- # rubocop:disable Metrics/AbcSize
201
- def lsof_parser(lsof_cmd)
202
- procs = {}
203
- # build this with formatted output (-F) from lsof
204
- # procs = {
205
- # '123:sshd' => [
206
- # 'ipv4:tcp:22:127.0.0.1',
207
- # 'ipv6:tcp:22:::1',
208
- # 'ipv4:tcp:*',
209
- # 'ipv6:tcp:*',
210
- # ],
211
- # '456:ntpd' => [
212
- # 'ipv4:udp:123:*',
213
- # 'ipv6:udp:123:*',
214
- # ]
215
- # }
216
- proc_id = port_id = nil
217
- lsof_cmd.stdout.each_line do |line|
218
- line.chomp!
219
- key = line.slice!(0)
220
- case key
221
- when "p"
222
- proc_id = line
223
- port_id = nil
224
- when "c"
225
- proc_id += ":" + line
226
- when "t"
227
- port_id = line.downcase
228
- when "P"
229
- port_id += ":" + line.downcase
230
- when "n"
231
- src, dst = line.split("->")
232
-
233
- # skip active comm streams
234
- next if dst
235
-
236
- host, port = /^(\S+):(\d+|\*)$/.match(src)[1, 2]
237
-
238
- # skip channels from port 0 - what does this mean?
239
- next if port == "*"
240
-
241
- # create new array stub if !exist?
242
- procs[proc_id] = [] unless procs.key?(proc_id)
243
-
244
- # change address '*' to zero
245
- host = port_id =~ /^ipv6:/ ? "[::]" : "0.0.0.0" if host == "*"
246
- # entrust URI to scrub the host and port
247
- begin
248
- uri = URI("addr://#{host}:#{port}")
249
- uri.host && uri.port
250
- rescue => e
251
- warn "could not parse URI 'addr://#{host}:#{port}' - #{e}"
252
- next
253
- end
254
-
255
- # e.g. 'ipv4:tcp:22:127.0.0.1'
256
- # strip ipv6 squares for inspec
257
- port_id += ":" + port + ":" + host.gsub(/^\[|\]$/, "")
258
-
259
- # lsof will give us another port unless it's done
260
- procs[proc_id] << port_id
261
- end
262
- end
263
-
264
- procs
265
- end
266
- end
267
-
268
- class AixPorts < PortsInfo
269
- def info
270
- ports_via_netstat || ports_via_lsof
271
- end
272
-
273
- def ports_via_lsof
274
- return nil unless inspec.command("lsof").exist?
275
-
276
- LsofPorts.new(inspec).info
277
- end
278
-
279
- def ports_via_netstat
280
- return nil unless inspec.command("netstat").exist?
281
-
282
- cmd = inspec.command("netstat -Aan | grep LISTEN")
283
- return nil unless cmd.exit_status.to_i == 0
284
-
285
- ports = []
286
- # parse all lines
287
- cmd.stdout.each_line do |line|
288
- port_info = parse_netstat_line(line)
289
-
290
- # only push protocols we are interested in
291
- next unless %w{tcp tcp6 udp udp6}.include?(port_info["protocol"])
292
-
293
- ports.push(port_info)
294
- end
295
-
296
- ports
297
- end
298
-
299
- def parse_netstat_line(line)
300
- # parse each line
301
- # 1 - Socket, 2 - Proto, 3 - Receive-Q, 4 - Send-Q, 5 - Local address, 6 - Foreign Address, 7 - State
302
- parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?\s+(\S+)/.match(line)
303
- return {} if parsed.nil?
304
-
305
- # parse ip4 and ip6 addresses
306
- protocol = parsed[2].downcase
307
-
308
- # detect protocol if not provided
309
- protocol += "6" if parsed[5].count(":") > 1 && %w{tcp udp}.include?(protocol)
310
- protocol.chop! if %w{tcp4 upd4}.include?(protocol)
311
-
312
- # extract host and port information
313
- host, port = parse_net_address(parsed[5], protocol)
314
- return {} if host.nil?
315
-
316
- # extract PID
317
- cmd = inspec.command("rmsock #{parsed[1]} tcpcb")
318
- parsed_pid = /^The socket (\S+) is being held by proccess (\d+) \((\S+)\)/.match(cmd.stdout)
319
- return {} if parsed_pid.nil?
320
-
321
- process = parsed_pid[3]
322
- pid = parsed_pid[2]
323
- pid = pid.to_i if pid =~ /^\d+$/
324
-
325
- {
326
- "port" => port,
327
- "address" => host,
328
- "protocol" => protocol,
329
- "process" => process,
330
- "pid" => pid,
331
- }
332
- end
333
-
334
- def parse_net_address(net_addr, protocol)
335
- # local/foreign addresses on AIX use a '.' to separate the addresss
336
- # from the port
337
- address, _sep, port = net_addr.rpartition(".")
338
- if protocol.eql?("tcp6") || protocol.eql?("udp6")
339
- ip6addr = address
340
- # AIX uses the wildcard character for ipv6 addresses listening on
341
- # all interfaces.
342
- ip6addr = "::" if ip6addr =~ /^\*$/
343
-
344
- # v6 addresses need to end in a double-colon when using
345
- # shorthand notation. netstat ends with a single colon.
346
- # IPAddr will fail to properly parse an address unless it
347
- # uses a double-colon for short-hand notation.
348
- ip6addr += ":" if ip6addr =~ /\w:$/
349
-
350
- begin
351
- ip_parser = IPAddr.new(ip6addr)
352
- rescue IPAddr::InvalidAddressError
353
- # This IP is not parsable. There appears to be a bug in netstat
354
- # output that truncates link-local IP addresses:
355
- # example: udp6 0 0 fe80::42:acff:fe11::123 :::* 0 54550 3335/ntpd
356
- # actual link address: inet6 fe80::42:acff:fe11:5/64 scope link
357
- #
358
- # in this example, the "5" is truncated making the netstat output
359
- # an invalid IP address.
360
- return [nil, nil]
361
- end
362
-
363
- # Check to see if this is a IPv4 address in a tcp6/udp6 line.
364
- # If so, don't put brackets around the IP or URI won't know how
365
- # to properly handle it.
366
- # example: f000000000000000 tcp6 0 0 127.0.0.1.8005 *.* LISTEN
367
- if ip_parser.ipv4?
368
- ip_addr = URI("addr://#{ip6addr}:#{port}")
369
- host = ip_addr.host
370
- else
371
- ip_addr = URI("addr://[#{ip6addr}]:#{port}")
372
- host = ip_addr.host[1..ip_addr.host.size - 2]
373
- end
374
- else
375
- ip4addr = address
376
- # In AIX the wildcard character is used to match all interfaces
377
- ip4addr = "0.0.0.0" if ip4addr =~ /^\*$/
378
- ip_addr = URI("addr://#{ip4addr}:#{port}")
379
- host = ip_addr.host
380
- end
381
-
382
- [host, port.to_i]
383
- end
384
- end
385
-
386
- # extract port information from netstat
387
- class LinuxPorts < PortsInfo
388
- ALLOWED_PROTOCOLS = %w{tcp tcp6 udp udp6}.freeze
389
-
390
- def info
391
- ports_via_ss || ports_via_netstat
392
- end
393
-
394
- def ports_via_ss
395
- return nil unless inspec.command("ss").exist?
396
-
397
- cmd = inspec.command("ss -tulpen")
398
- return nil unless cmd.exit_status.to_i == 0
399
-
400
- ports = []
401
-
402
- cmd.stdout.each_line do |line|
403
- parsed_line = parse_ss_line(line)
404
- ports << parsed_line unless parsed_line.nil?
405
- end
406
-
407
- ports
408
- end
409
-
410
- def ports_via_netstat
411
- return nil unless inspec.command("netstat").exist?
412
-
413
- cmd = inspec.command("netstat -tulpen")
414
- return nil unless cmd.exit_status.to_i == 0
415
-
416
- ports = []
417
- # parse all lines
418
- cmd.stdout.each_line do |line|
419
- port_info = parse_netstat_line(line)
420
-
421
- # only push protocols we are interested in
422
- next unless %w{tcp tcp6 udp udp6}.include?(port_info["protocol"])
423
-
424
- ports.push(port_info)
425
- end
426
- ports
427
- end
428
-
429
- def parse_net_address(net_addr, protocol)
430
- if protocol.eql?("tcp6") || protocol.eql?("udp6")
431
- # prep for URI parsing, parse ip6 port
432
- ip6 = /^(\S+):(\d+)$/.match(net_addr)
433
- ip6addr = ip6[1]
434
- ip6addr = "::" if ip6addr =~ /^:::$/
435
-
436
- # v6 addresses need to end in a double-colon when using
437
- # shorthand notation. netstat ends with a single colon.
438
- # IPAddr will fail to properly parse an address unless it
439
- # uses a double-colon for short-hand notation.
440
- ip6addr += ":" if ip6addr =~ /\w:$/
441
-
442
- begin
443
- ip_parser = IPAddr.new(ip6addr)
444
- rescue IPAddr::InvalidAddressError
445
- # This IP is not parsable. There appears to be a bug in netstat
446
- # output that truncates link-local IP addresses:
447
- # example: udp6 0 0 fe80::42:acff:fe11::123 :::* 0 54550 3335/ntpd
448
- # actual link address: inet6 fe80::42:acff:fe11:5/64 scope link
449
- #
450
- # in this example, the "5" is truncated making the netstat output
451
- # an invalid IP address.
452
- return [nil, nil]
453
- end
454
-
455
- # Check to see if this is a IPv4 address in a tcp6/udp6 line.
456
- # If so, don't put brackets around the IP or URI won't know how
457
- # to properly handle it.
458
- # example: tcp6 0 0 127.0.0.1:8005 :::* LISTEN
459
- if ip_parser.ipv4?
460
- ip_addr = URI("addr://#{ip6addr}:#{ip6[2]}")
461
- host = ip_addr.host
462
- else
463
- ip_addr = URI("addr://[#{ip6addr}]:#{ip6[2]}")
464
- # strip []
465
- host = ip_addr.host[1..ip_addr.host.size - 2]
466
- end
467
- else
468
- ip_addr = URI("addr://" + net_addr)
469
- host = ip_addr.host
470
- end
471
-
472
- port = ip_addr.port
473
-
474
- [host, port]
475
- rescue URI::InvalidURIError => e
476
- warn "Could not parse #{net_addr}, #{e}"
477
- nil
478
- end
479
-
480
- def parse_netstat_line(line)
481
- # parse each line
482
- # 1 - Proto, 2 - Recv-Q, 3 - Send-Q, 4 - Local Address, 5 - Foreign Address, 6 - State, 7 - User, 8 - Inode, 9 - PID/Program name
483
- # * UDP lines have an empty State column and the Busybox variant lacks
484
- # the User and Inode columns.
485
- reg = /^(?<proto>\S+)\s+(\S+)\s+(\S+)\s+(?<local_addr>\S+)\s+(?<foreign_addr>\S+)\s+(\S+)?\s+((\S+)\s+(\S+)\s+)?(?<pid_prog>\S+)/
486
- parsed = reg.match(line)
487
-
488
- return {} if parsed.nil? || line.match(/^proto/i)
489
-
490
- # parse ip4 and ip6 addresses
491
- protocol = parsed[:proto].downcase
492
-
493
- # detect protocol if not provided
494
- protocol += "6" if parsed[:local_addr].count(":") > 1 && %w{tcp udp}.include?(protocol)
495
-
496
- # extract host and port information
497
- host, port = parse_net_address(parsed[:local_addr], protocol)
498
- return {} if host.nil?
499
-
500
- # extract PID
501
- process = parsed[:pid_prog].split("/")
502
- pid = process[0]
503
- pid = pid.to_i if pid =~ /^\d+$/
504
- process = process[1]
505
-
506
- {
507
- "port" => port,
508
- "address" => host,
509
- "protocol" => protocol,
510
- "process" => process,
511
- "pid" => pid,
512
- }
513
- end
514
-
515
- def tokenize_ss_line(line)
516
- # iproute-2.6.32-54.el6 output:
517
- # Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
518
- # udp UNCONN 0 0 *:111 *:* users:(("rpcbind",1123,6)) ino=8680 sk=ffff8801390cf7c0
519
- # tcp LISTEN 0 128 *:22 *:* users:(("sshd",3965,3)) ino:11604 sk:ffff88013a3b5800
520
- #
521
- # iproute-2.6.32-20.el6 output:
522
- # Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
523
- # udp 0 0 *:111 *:* users:(("rpcbind",1123,6)) ino=8680 sk=ffff8801390cf7c0
524
- # tcp 0 128 *:22 *:* users:(("sshd",3965,3)) ino:11604 sk:ffff88013a3b5800
525
- tokens = line.split(/\s+/, 7)
526
- if tokens[1] =~ /^\d+$/ # iproute-2.6.32-20
527
- {
528
- netid: tokens[0],
529
- local_addr: tokens[3],
530
- process_info: tokens[5],
531
- }
532
- else # iproute-2.6.32-54
533
- {
534
- netid: tokens[0],
535
- local_addr: tokens[4],
536
- process_info: tokens[6],
537
- }
538
- end
539
- end
540
-
541
- def parse_ss_line(line)
542
- # parsed = line.split(/\s+/, 7)
543
- parsed = tokenize_ss_line(line)
544
-
545
- # ss only returns "tcp" and "udp" as the protocol. However, netstat would return
546
- # "tcp6" and "udp6" as necessary. In order to maintain backward compatibility, we
547
- # will manually modify the protocol value if the line we're parsing is an IPv6
548
- # entry.
549
- process_info = parsed[:process_info]
550
- protocol = parsed[:netid]
551
- protocol += "6" if process_info.include?("v6only:1")
552
- return nil unless ALLOWED_PROTOCOLS.include?(protocol)
553
-
554
- # parse the Local Address:Port
555
- # examples:
556
- # *:22
557
- # :::22
558
- # 10.0.2.15:1234
559
- # ::ffff:10.0.2.15:9300
560
- # fe80::a00:27ff:fe32:ed09%enp0s3:9200
561
- parsed_net_address = parsed[:local_addr].match(/(\S+):(\*|\d+)$/)
562
- return nil if parsed_net_address.nil?
563
-
564
- host = parsed_net_address[1]
565
- port = parsed_net_address[2]
566
- return nil if host.nil? && port.nil?
567
-
568
- # For backward compatibility with the netstat output, ensure the
569
- # port is stored as an integer
570
- port = port.to_i
571
-
572
- # for those "v4-but-listed-in-v6" entries, strip off the
573
- # leading IPv6 value at the beginning
574
- # example: ::ffff:10.0.2.15:9200
575
- host.delete!("::ffff:") if host.start_with?("::ffff:")
576
-
577
- # To remove brackets that might surround the IPv6 address
578
- # example: [::] and [fe80::dc11:b9b6:514b:134]%eth0:123
579
- host = host.tr("[]", "")
580
-
581
- # if there's an interface name in the local address, which is common for
582
- # IPv6 listeners, strip that out too.
583
- # example: fe80::a00:27ff:fe32:ed09%enp0s3
584
- host = host.split("%").first
585
-
586
- # if host is "*", replace with "0.0.0.0" to maintain backward compatibility with
587
- # the netstat-provided data
588
- host = "0.0.0.0" if host == "*"
589
-
590
- # in case process list parsing is not successfull
591
- process = nil
592
- pid = nil
593
-
594
- # parse process and pid from the process list
595
- #
596
- # remove the "users:((" and "))" parts
597
- # input: users:((\"nginx\",pid=583,fd=8),(\"nginx\",pid=582,fd=8),(\"nginx\",pid=580,fd=8),(\"nginx\",pid=579,fd=8))
598
- # res: \"nginx\",pid=583,fd=8),(\"nginx\",pid=582,fd=8),(\"nginx\",pid=580,fd=8),(\"nginx\",pid=579,fd=8
599
- process_list_match = parsed[:process_info].match(/users:\(\((.+)\)\)/)
600
- if process_list_match
601
- # list entires are seperated by "," the braces can also be removed
602
- # input: \"nginx\",pid=583,fd=8),(\"nginx\",pid=582,fd=8),(\"nginx\",pid=580,fd=8),(\"nginx\",pid=579,fd=8
603
- # res: ["\"nginx\",pid=583,fd=8", "\"nginx\",pid=582,fd=8", "\"nginx\",pid=580,fd=8", "\"nginx\",pid=579,fd=8"]
604
- process_list = process_list_match[1].split("),(")
605
- # To stay backwards compatible with netstat we need to select
606
- # the last element in the resulting array.
607
- # res: "\"nginx\",pid=579,fd=8"
608
-
609
- # parse the process name from the process list
610
- process_match = process_list.last.match(/^\"(\S+)\"/)
611
- process = process_match.nil? ? nil : process_match[1]
612
-
613
- # parse the PID from the process list
614
- pid_match = process_list.last.match(/pid=(\d+)/)
615
- pid = pid_match.nil? ? nil : pid_match[1].to_i
616
- end
617
-
618
- {
619
- "port" => port,
620
- "address" => host,
621
- "protocol" => protocol,
622
- "process" => process,
623
- "pid" => pid,
624
- }
625
- end
626
- end
627
-
628
- # extracts information from sockstat
629
- class FreeBsdPorts < PortsInfo
630
- def info
631
- cmd = inspec.command("sockstat -46l")
632
- return nil if cmd.exit_status.to_i != 0
633
-
634
- ports = []
635
- # split on each newline
636
- cmd.stdout.each_line do |line|
637
- port_info = parse_sockstat_line(line)
638
-
639
- # push data, if not headerfile
640
- next unless %w{tcp tcp6 udp udp6}.include?(port_info["protocol"])
641
-
642
- ports.push(port_info)
643
- end
644
- ports
645
- end
646
-
647
- def parse_net_address(net_addr, protocol)
648
- case protocol
649
- when "tcp4", "udp4", "tcp", "udp"
650
- # replace * with 0.0.0.0
651
- net_addr = net_addr.gsub(/^\*:/, "0.0.0.0:") if net_addr =~ /^*:(\d+)$/
652
- ip_addr = URI("addr://" + net_addr)
653
- host = ip_addr.host
654
- port = ip_addr.port
655
- when "tcp6", "udp6"
656
- return [] if net_addr == "*:*" # abort for now
657
-
658
- # replace * with 0:0:0:0:0:0:0:0
659
- net_addr = net_addr.gsub(/^\*:/, "0:0:0:0:0:0:0:0:") if net_addr =~ /^*:(\d+)$/
660
- # extract port
661
- ip6 = /^(\S+):(\d+)$/.match(net_addr)
662
- ip6addr = ip6[1]
663
- ip_addr = URI("addr://[#{ip6addr}]:#{ip6[2]}")
664
- # replace []
665
- host = ip_addr.host[1..ip_addr.host.size - 2]
666
- port = ip_addr.port
667
- end
668
- [host, port]
669
- rescue URI::InvalidURIError => e
670
- warn "Could not parse #{net_addr}, #{e}"
671
- nil
672
- end
673
-
674
- def parse_sockstat_line(line)
675
- # 1 - USER, 2 - COMMAND, 3 - PID, 4 - FD 5 - PROTO, 6 - LOCAL ADDRESS, 7 - FOREIGN ADDRESS
676
- parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/.match(line)
677
- return {} if parsed.nil?
678
-
679
- # extract ip information
680
- protocol = parsed[5].downcase
681
- host, port = parse_net_address(parsed[6], protocol)
682
- return {} if host.nil? || port.nil?
683
-
684
- # extract process
685
- process = parsed[2]
686
-
687
- # extract PID
688
- pid = parsed[3]
689
- pid = pid.to_i if pid =~ /^\d+$/
690
-
691
- # map tcp4 and udp4
692
- protocol = "tcp" if protocol.eql?("tcp4")
693
- protocol = "udp" if protocol.eql?("udp4")
694
-
695
- {
696
- "port" => port,
697
- "address" => host,
698
- "protocol" => protocol,
699
- "process" => process,
700
- "pid" => pid,
701
- }
702
- end
703
- end
704
-
705
- class SolarisPorts < FreeBsdPorts
706
- include SolarisNetstatParser
707
-
708
- def info
709
- # extract all port info
710
- cmd = inspec.command("netstat -an -f inet -f inet6")
711
- return nil if cmd.exit_status.to_i != 0
712
-
713
- # parse the content
714
- netstat_ports = parse_netstat(cmd.stdout)
715
-
716
- # filter all ports, where we `listen`
717
- listen = netstat_ports.select do |val|
718
- !val["state"].nil? && "listen".casecmp(val["state"]) == 0
719
- end
720
-
721
- # map the data
722
- ports = listen.map do |val|
723
- protocol = val["protocol"]
724
- local_addr = val["local-address"]
725
-
726
- # solaris uses 127.0.0.1.57455 instead 127.0.0.1:57455, lets convert the
727
- # the last . to :
728
- local_addr[local_addr.rindex(".")] = ":"
729
- host, port = parse_net_address(local_addr, protocol)
730
- if host.nil?
731
- nil
732
- else
733
- {
734
- "port" => port,
735
- "address" => host,
736
- "protocol" => protocol,
737
- }
738
- end
739
- end
740
- ports.compact
741
- end
742
- end
743
-
744
- # extracts information from netstat for hpux
745
- class HpuxPorts < FreeBsdPorts
746
- def info
747
- ## Can't use 'netstat -an -f inet -f inet6' as the latter -f option overrides the former one and return only inet ports
748
- cmd1 = inspec.command("netstat -an -f inet")
749
- return nil if cmd1.exit_status.to_i != 0
750
-
751
- cmd2 = inspec.command("netstat -an -f inet6")
752
- return nil if cmd2.exit_status.to_i != 0
753
-
754
- cmd = cmd1.stdout + cmd2.stdout
755
- ports = []
756
- # parse all lines
757
- cmd.each_line do |line|
758
- port_info = parse_netstat_line(line)
759
- next unless %w{tcp tcp6 udp udp6}.include?(port_info["protocol"])
760
-
761
- ports.push(port_info)
762
- end
763
- # select all ports, where we `listen`
764
- ports.select { |val| val if "listen".casecmp(val["state"]) == 0 }
765
- end
766
-
767
- def parse_netstat_line(line)
768
- # parse each line
769
- # 1 - Proto, 2 - Recv-Q, 3 - Send-Q, 4 - Local Address, 5 - Foreign Address, 6 - (state)
770
- parsed = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?/.match(line)
771
-
772
- return {} if parsed.nil? || line.match(/^proto/i) || line.match(/^active/i)
773
-
774
- protocol = parsed[1].downcase
775
- state = parsed[6].nil? ? " " : parsed[6].downcase
776
- local_addr = parsed[4]
777
- local_addr[local_addr.rindex(".")] = ":"
778
- # extract host and port information
779
- host, port = parse_net_address(local_addr, protocol)
780
- return {} if host.nil?
781
-
782
- # map data
783
- {
784
- "port" => port,
785
- "address" => host,
786
- "protocol" => protocol,
787
- "state" => state,
788
- }
789
- end
790
- end
791
- end