.rubocop.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. # This list was intially created by analyzing the last three months (51
  2. # modules) committed to Metasploit Framework. Many, many older modules
  3. # will have offenses, but this should at least provide a baseline for
  4. # new modules.
  5. #
  6. # Updates to this file should include a 'Description' parameter for any
  7. # explanation needed.
  8. # inherit_from: .rubocop_todo.yml
  9. AllCops:
  10. TargetRubyVersion: 2.6
  11. SuggestExtensions: false
  12. NewCops: disable
  13. require:
  14. - ./lib/rubocop/cop/layout/module_hash_on_new_line.rb
  15. - ./lib/rubocop/cop/layout/module_hash_values_on_same_line.rb
  16. - ./lib/rubocop/cop/layout/module_description_indentation.rb
  17. - ./lib/rubocop/cop/layout/extra_spacing_with_bindata_ignored.rb
  18. - ./lib/rubocop/cop/lint/module_disclosure_date_format.rb
  19. - ./lib/rubocop/cop/lint/module_disclosure_date_present.rb
  20. - ./lib/rubocop/cop/lint/deprecated_gem_version.rb
  21. - ./lib/rubocop/cop/lint/module_enforce_notes.rb
  22. - ./lib/rubocop/cop/lint/detect_invalid_pack_directives.rb
  23. Layout/SpaceBeforeBrackets:
  24. Description: >-
  25. Disabled as it generates invalid code:
  26. https://github.com/rubocop-hq/rubocop/issues/9499
  27. Enabled: false
  28. Lint/AmbiguousAssignment:
  29. Enabled: true
  30. Lint/DeprecatedConstants:
  31. Enabled: true
  32. Lint/DuplicateBranch:
  33. Description: >-
  34. Disabled as it causes a lot of noise around our current exception/error handling
  35. Enabled: false
  36. Lint/DuplicateRegexpCharacterClassElement:
  37. Enabled: false
  38. Lint/EmptyBlock:
  39. Enabled: false
  40. Lint/EmptyClass:
  41. Enabled: false
  42. Lint/LambdaWithoutLiteralBlock:
  43. Enabled: true
  44. Lint/NoReturnInBeginEndBlocks:
  45. Enabled: true
  46. Lint/NumberedParameterAssignment:
  47. Enabled: true
  48. Lint/OrAssignmentToConstant:
  49. Enabled: true
  50. Lint/RedundantDirGlobSort:
  51. Enabled: true
  52. Lint/SymbolConversion:
  53. Enabled: true
  54. Lint/ToEnumArguments:
  55. Enabled: true
  56. Lint/TripleQuotes:
  57. Enabled: true
  58. Lint/UnexpectedBlockArity:
  59. Enabled: true
  60. Lint/UnmodifiedReduceAccumulator:
  61. Enabled: true
  62. Lint/UnusedMethodArgument:
  63. Description: >-
  64. Disabled on files under the lib/ directory (aka library files)
  65. as this can break YARD documentation since YARD doesn't recognize
  66. the _ prefix before parameter names and thinks its a different argument.
  67. See https://github.com/rapid7/metasploit-framework/pull/17735
  68. Also see https://github.com/rubocop/rubocop/pull/11020
  69. Enabled: true
  70. Exclude:
  71. - 'lib/**/*'
  72. Style/ArgumentsForwarding:
  73. Enabled: true
  74. Style/BlockComments:
  75. Description: >-
  76. Disabled as multiline comments are great for embedded code snippets/payloads that can
  77. be copy/pasted directly into a terminal etc.
  78. Enabled: false
  79. Style/CaseLikeIf:
  80. Description: >-
  81. This would cause a lot of noise, and potentially introduce subtly different code when
  82. being auto fixed. Could potentially be enabled in isolation, but would require more
  83. consideration.
  84. Enabled: false
  85. Style/CollectionCompact:
  86. Enabled: true
  87. Style/DocumentDynamicEvalDefinition:
  88. Enabled: false
  89. Style/EndlessMethod:
  90. Enabled: true
  91. Style/HashExcept:
  92. Enabled: true
  93. Style/IfWithBooleanLiteralBranches:
  94. Description: >-
  95. Most of the time this is a valid replacement. Although it can generate subtly different
  96. rewrites that might break code:
  97. 2.7.2 :001 > foo = nil
  98. => nil
  99. 2.7.2 :002 > (foo && foo['key'] == 'foo') ? true : false
  100. => false
  101. 2.7.2 :003 > foo && foo['key'] == 'foo'
  102. => nil
  103. Enabled: false
  104. Style/NegatedIfElseCondition:
  105. Enabled: false
  106. Style/MultipleComparison:
  107. Description: >-
  108. Disabled as it generates invalid code:
  109. https://github.com/rubocop-hq/rubocop/issues/9520
  110. It may also introduce subtle semantic issues if automatically applied to the
  111. entire codebase without rigorous testing.
  112. Enabled: false
  113. Style/NilLambda:
  114. Enabled: true
  115. Style/RedundantArgument:
  116. Enabled: false
  117. Style/RedundantAssignment:
  118. Description: >-
  119. Disabled as it sometimes improves the readability of code having an explicitly named
  120. response object, it also makes it easier to put a breakpoint between the assignment
  121. and return expression
  122. Enabled: false
  123. Style/SwapValues:
  124. Enabled: false
  125. Layout/ModuleHashOnNewLine:
  126. Enabled: true
  127. Layout/ModuleHashValuesOnSameLine:
  128. Enabled: true
  129. Layout/ModuleDescriptionIndentation:
  130. Enabled: true
  131. Lint/DetectInvalidPackDirectives:
  132. Enabled: true
  133. Lint/ModuleDisclosureDateFormat:
  134. Enabled: true
  135. Lint/ModuleDisclosureDatePresent:
  136. Include:
  137. # Only exploits require disclosure dates, but they can be present in auxiliary modules etc.
  138. - 'modules/exploits/**/*'
  139. Lint/ModuleEnforceNotes:
  140. Include:
  141. # Only exploits and auxiliary modules require SideEffects to be listed.
  142. - 'modules/exploits/**/*'
  143. - 'modules/auxiliary/**/*'
  144. - 'modules/post/**/*'
  145. Lint/DeprecatedGemVersion:
  146. Enabled: true
  147. Exclude:
  148. - 'metasploit-framework.gemspec'
  149. Metrics/ModuleLength:
  150. Description: 'Most Metasploit modules are quite large. This is ok.'
  151. Enabled: false
  152. Metrics/ClassLength:
  153. Description: 'Most Metasploit classes are quite large. This is ok.'
  154. Enabled: false
  155. Style/ClassAndModuleChildren:
  156. Enabled: false
  157. Description: 'Forced nesting is harmful for grepping and general code comprehension'
  158. Metrics/AbcSize:
  159. Enabled: false
  160. Description: 'This is often a red-herring'
  161. Metrics/CyclomaticComplexity:
  162. Enabled: false
  163. Description: 'This is often a red-herring'
  164. Metrics/PerceivedComplexity:
  165. Enabled: false
  166. Description: 'This is often a red-herring'
  167. Metrics/BlockNesting:
  168. Description: >-
  169. This is a good rule to follow, but will cause a lot of overhead introducing this rule.
  170. Enabled: false
  171. Metrics/ParameterLists:
  172. Description: >-
  173. This is a good rule to follow, but will cause a lot of overhead introducing this rule.
  174. Increasing the max count for now
  175. Max: 8
  176. Style/TernaryParentheses:
  177. Enabled: false
  178. Description: 'This outright produces bugs'
  179. Style/FrozenStringLiteralComment:
  180. Enabled: false
  181. Description: 'We cannot support this yet without a lot of things breaking'
  182. Style/MutableConstant:
  183. Enabled: false
  184. Description: 'We cannot support this yet without a lot of things breaking'
  185. Style/RedundantReturn:
  186. Description: 'This often looks weird when mixed with actual returns, and hurts nothing'
  187. Enabled: false
  188. Naming/HeredocDelimiterNaming:
  189. Description: >-
  190. Could be enabled in isolation with additional effort.
  191. Enabled: false
  192. Naming/AccessorMethodName:
  193. Description: >-
  194. Disabled for now, as this naming convention is used in a lot of core library files.
  195. Could be enabled in isolation with additional effort.
  196. Enabled: false
  197. Naming/ConstantName:
  198. Description: >-
  199. Disabled for now, Metasploit is unfortunately too inconsistent with its naming to introduce
  200. this. Definitely possible to enforce this in the future if need be.
  201. Examples:
  202. ManualRanking, LowRanking, etc.
  203. NERR_ClientNameNotFound
  204. HttpFingerprint
  205. CachedSize
  206. ErrUnknownTransferId
  207. Enabled: false
  208. Naming/VariableNumber:
  209. Description: 'To make it easier to use reference code, disable this cop'
  210. Enabled: false
  211. Style/NumericPredicate:
  212. Description: 'This adds no efficiency nor space saving'
  213. Enabled: false
  214. Style/EvenOdd:
  215. Description: 'This adds no efficiency nor space saving'
  216. Enabled: false
  217. Style/FloatDivision:
  218. Description: 'Not a safe rule to run on Metasploit without manual verification as the right hand side may be a string'
  219. Enabled: false
  220. Style/FormatString:
  221. Description: 'Not a safe rule to run on Metasploit without manual verification that the format is not redefined/shadowed'
  222. Enabled: false
  223. Style/Documentation:
  224. Enabled: true
  225. Description: 'Most Metasploit modules do not have class documentation.'
  226. Exclude:
  227. - 'modules/**/*'
  228. - 'test/modules/**/*'
  229. - 'spec/file_fixtures/modules/**/*'
  230. Layout/FirstArgumentIndentation:
  231. Enabled: true
  232. EnforcedStyle: consistent
  233. Description: 'Useful for the module hash to be indented consistently'
  234. Layout/ArgumentAlignment:
  235. Enabled: true
  236. EnforcedStyle: with_first_argument
  237. Description: 'Useful for the module hash to be indented consistently'
  238. Layout/FirstHashElementIndentation:
  239. Enabled: true
  240. EnforcedStyle: consistent
  241. Description: 'Useful for the module hash to be indented consistently'
  242. Layout/FirstHashElementLineBreak:
  243. Enabled: true
  244. Description: 'Enforce consistency by breaking hash elements on to new lines'
  245. Layout/SpaceInsideArrayLiteralBrackets:
  246. Enabled: false
  247. Description: 'Almost all module metadata have space in brackets'
  248. Style/GuardClause:
  249. Enabled: false
  250. Description: 'This often introduces bugs in tested code'
  251. Style/EmptyLiteral:
  252. Enabled: false
  253. Description: 'This looks awkward when you mix empty and non-empty literals'
  254. Style/NegatedIf:
  255. Enabled: false
  256. Description: 'This often introduces bugs in tested code'
  257. Style/ConditionalAssignment:
  258. Enabled: false
  259. Description: 'This is confusing for folks coming from other languages'
  260. Style/Encoding:
  261. Description: 'We prefer binary to UTF-8.'
  262. Enabled: false
  263. Style/ParenthesesAroundCondition:
  264. Enabled: false
  265. Description: 'This is used in too many places to discount, especially in ported code. Has little effect'
  266. Style/StringConcatenation:
  267. Enabled: false
  268. Description: >-
  269. Disabled for now as it changes escape sequences when auto corrected:
  270. https://github.com/rubocop/rubocop/issues/9543
  271. Additionally seems to break with multiline string concatenation with trailing comments, example:
  272. payload = "\x12" + # Size
  273. "\x34" + # eip
  274. "\x56" # etc
  275. With `rubocop -A` this will become:
  276. payload = "\u00124V" # etc
  277. Style/TrailingCommaInArrayLiteral:
  278. Enabled: false
  279. Description: 'This is often a useful pattern, and is actually required by other languages. It does not hurt.'
  280. Layout/LineLength:
  281. Description: >-
  282. Metasploit modules often pattern match against very
  283. long strings when identifying targets.
  284. Enabled: false
  285. Metrics/BlockLength:
  286. Enabled: true
  287. Description: >-
  288. While the style guide suggests 10 lines, exploit definitions
  289. often exceed 200 lines.
  290. Max: 300
  291. Metrics/MethodLength:
  292. Enabled: true
  293. Description: >-
  294. While the style guide suggests 10 lines, exploit definitions
  295. often exceed 200 lines.
  296. Max: 300
  297. Naming/MethodParameterName:
  298. Enabled: true
  299. Description: 'Whoever made this requirement never looked at crypto methods, IV'
  300. MinNameLength: 2
  301. Naming/PredicateName:
  302. Enabled: true
  303. # Current methods that break the rule, so that we don't add additional methods that break the convention
  304. AllowedMethods:
  305. - has_additional_info?
  306. - has_advanced_options?
  307. - has_auth
  308. - has_auto_target?
  309. - has_bad_activex?
  310. - has_badchars?
  311. - has_chars?
  312. - has_check?
  313. - has_command?
  314. - has_content_type_extension?
  315. - has_datastore_cred?
  316. - has_evasion_options?
  317. - has_fatal_errors?
  318. - has_fields
  319. - has_files?
  320. - has_flag?
  321. - has_function_name?
  322. - has_gcc?
  323. - has_h2_headings
  324. - has_input_name?
  325. - has_j_security_check?
  326. - has_key?
  327. - has_match?
  328. - has_module
  329. - has_object_ref
  330. - has_objects_list
  331. - has_options?
  332. - has_page?
  333. - has_passphrase?
  334. - has_pid?
  335. - has_pkt_line_data?
  336. - has_prereqs?
  337. - has_privacy_waiver?
  338. - has_privates?
  339. - has_protected_mode_prompt?
  340. - has_proxy?
  341. - has_read_data?
  342. - has_ref?
  343. - has_required_args
  344. - has_required_module_options?
  345. - has_requirements
  346. - has_rop?
  347. - has_s_flag?
  348. - has_service_cred?
  349. - has_subscriber?
  350. - has_subtree?
  351. - has_text
  352. - has_tlv?
  353. - has_u_flag?
  354. - has_users?
  355. - has_vuln?
  356. - has_waiver?
  357. - have_auth_error?
  358. - have_powershell?
  359. - is_accessible?
  360. - is_admin?
  361. - is_alive?
  362. - is_alpha_web_server?
  363. - is_android?
  364. - is_app_binom3?
  365. - is_app_carlogavazzi?
  366. - is_app_cnpilot?
  367. - is_app_epaduo?
  368. - is_app_epmp1000?
  369. - is_app_infovista?
  370. - is_app_ironport?
  371. - is_app_metweblog?
  372. - is_app_oilom?
  373. - is_app_openmind?
  374. - is_app_popad?
  375. - is_app_radware?
  376. - is_app_rfreader?
  377. - is_app_sentry?
  378. - is_app_sevone?
  379. - is_app_splunk?
  380. - is_app_ssl_vpn?
  381. - is_array_type?
  382. - is_auth_required?
  383. - is_author_blacklisted?
  384. - is_badchar
  385. - is_base64?
  386. - is_bind?
  387. - is_cached_size_accurate?
  388. - is_cgi_enabled?
  389. - is_cgi_exploitable?
  390. - is_check_interesting?
  391. - is_child_of?
  392. - is_clr_enabled
  393. - is_connect?
  394. - is_dlink?
  395. - is_dn?
  396. - is_dynamic?
  397. - is_error_code
  398. - is_exception?
  399. - is_exploit_module?
  400. - is_exploitable?
  401. - is_fqdn?
  402. - is_glob?
  403. - is_groupwise?
  404. - is_guest_mode_enabled?
  405. - is_hash_from_empty_pwd?
  406. - is_high_integrity?
  407. - is_hostname?
  408. - is_ie?
  409. - is_imc?
  410. - is_imc_som?
  411. - is_in_admin_group?
  412. - is_interface?
  413. - is_ip_targeted?
  414. - is_key_wanted?
  415. - is_leaf?
  416. - is_local?
  417. - is_logged_in?
  418. - is_loggedin
  419. - is_loopback_address?
  420. - is_mac?
  421. - is_match
  422. - is_md5_format?
  423. - is_module_arch?
  424. - is_module_platform?
  425. - is_module_wanted?
  426. - is_multi_platform_exploit?
  427. - is_not_null?
  428. - is_null_pointer
  429. - is_null_pointer?
  430. - is_num?
  431. - is_num_type?
  432. - is_numeric
  433. - is_online?
  434. - is_parseable
  435. - is_pass_ntlm_hash?
  436. - is_passwd_method?
  437. - is_password_required?
  438. - is_payload_compatible?
  439. - is_payload_platform_compatible?
  440. - is_pointer_type?
  441. - is_pri_key?
  442. - is_proficy?
  443. - is_rdp_up
  444. - is_remote_exploit?
  445. - is_resource_taken?
  446. - is_rf?
  447. - is_rmi?
  448. - is_root?
  449. - is_routable?
  450. - is_running?
  451. - is_scan_complete
  452. - is_secure_admin_disabled?
  453. - is_session_type?
  454. - is_signature_correct?
  455. - is_single_object?
  456. - is_struct_type?
  457. - is_supermicro?
  458. - is_superuser?
  459. - is_sws?
  460. - is_system?
  461. - is_system_user?
  462. - is_target?
  463. - is_target_suitable?
  464. - is_trial_enabled?
  465. - is_trustworthy
  466. - is_uac_enabled?
  467. - is_url_alive
  468. - is_usable?
  469. - is_uuid?
  470. - is_valid?
  471. - is_valid_bus?
  472. - is_valid_snmp_value
  473. - is_value_wanted?
  474. - is_version_compat?
  475. - is_version_tested?
  476. - is_vmware?
  477. - is_vul
  478. - is_vulnerable?
  479. - is_warbird?
  480. - is_windows?
  481. - is_writable
  482. - is_writable?
  483. - is_x86?
  484. - is_zigbee_hwbridge_session?
  485. # %q() is super useful for long strings split over multiple lines and
  486. # is very common in module constructors for things like descriptions
  487. Style/RedundantPercentQ:
  488. Enabled: false
  489. Style/NumericLiterals:
  490. Enabled: false
  491. Description: 'This often hurts readability for exploit-ish code.'
  492. Layout/FirstArrayElementLineBreak:
  493. Enabled: true
  494. Description: 'This cop checks for a line break before the first element in a multi-line array.'
  495. Layout/FirstArrayElementIndentation:
  496. Enabled: true
  497. EnforcedStyle: consistent
  498. Description: 'Useful to force values within the register_options array to have sane indentation'
  499. Layout/EmptyLinesAroundClassBody:
  500. Enabled: false
  501. Description: 'these are used to increase readability'
  502. Layout/EmptyLinesAroundMethodBody:
  503. Enabled: true
  504. Layout/ExtraSpacingWithBinDataIgnored:
  505. Description: 'Do not use unnecessary spacing.'
  506. Enabled: true
  507. # When true, allows most uses of extra spacing if the intent is to align
  508. # things with the previous or next line, not counting empty lines or comment
  509. # lines.
  510. AllowForAlignment: false
  511. # When true, allows things like 'obj.meth(arg) # comment',
  512. # rather than insisting on 'obj.meth(arg) # comment'.
  513. # If done for alignment, either this OR AllowForAlignment will allow it.
  514. AllowBeforeTrailingComments: true
  515. # When true, forces the alignment of `=` in assignments on consecutive lines.
  516. ForceEqualSignAlignment: false
  517. Style/For:
  518. Enabled: false
  519. Description: 'if a module is written with a for loop, it cannot always be logically replaced with each'
  520. Style/WordArray:
  521. Enabled: false
  522. Description: 'Metasploit prefers consistent use of []'
  523. Style/IfUnlessModifier:
  524. Enabled: false
  525. Description: 'This style might save a couple of lines, but often makes code less clear'
  526. Style/PercentLiteralDelimiters:
  527. Description: 'Use `%`-literal delimiters consistently.'
  528. Enabled: true
  529. # Specify the default preferred delimiter for all types with the 'default' key
  530. # Override individual delimiters (even with default specified) by specifying
  531. # an individual key
  532. PreferredDelimiters:
  533. default: ()
  534. '%i': '[]'
  535. '%I': '[]'
  536. '%r': '{}'
  537. '%w': '[]'
  538. '%W': '[]'
  539. '%q': '{}' # Chosen for module descriptions as () are frequently used characters, whilst {} are rarely used
  540. VersionChanged: '0.48.1'
  541. Style/RedundantBegin:
  542. Enabled: true
  543. Style/SafeNavigation:
  544. Description: >-
  545. This cop transforms usages of a method call safeguarded by
  546. a check for the existence of the object to
  547. safe navigation (`&.`).
  548. This has been disabled as in some scenarios it produced invalid code, and disobeyed the 'AllowedMethods'
  549. configuration.
  550. Enabled: false
  551. Style/UnpackFirst:
  552. Description: >-
  553. Disabling to make it easier to copy/paste `unpack('h*')` expressions from code
  554. into a debugging REPL.
  555. Enabled: false