Skip to content

fix: add Python 2.7-3.14+ compatibility for reverse_python_ssl#21311

Open
karandesai2005 wants to merge 1 commit intorapid7:masterfrom
karandesai2005:fix/python314-ssl-compat
Open

fix: add Python 2.7-3.14+ compatibility for reverse_python_ssl#21311
karandesai2005 wants to merge 1 commit intorapid7:masterfrom
karandesai2005:fix/python314-ssl-compat

Conversation

@karandesai2005
Copy link
Copy Markdown

Summary

Fixes cmd/unix/reverse_python_ssl failing on Python 3.12+ due to removal of ssl.wrap_socket(), while maintaining full backward compatibility with Python 2.7 and 3.4–3.11 as required.

Changes

  • Replaced direct ssl.wrap_socket(so) call with a try/except AttributeError polyglot fallback
  • Falls back to ssl.create_default_context().wrap_socket() only on Python 3.12+ where wrap_socket is missing
  • Preserves check_hostname=False and verify_mode=ssl.CERT_NONE for reverse shell compatibility
  • Zero breaking changes for existing Python 2.7/3.x deployments

Testing

✅ Ruby syntax validation passed (ruby -c)
✅ Payload generation tested — generated Python passes py_compile on Python 3.14
✅ Fallback logic verified: try:s=ssl.wrap_socket(so) present in generated payload
✅ Backward compatible: Python 2.7/3.4-3.11 use wrap_socket directly, 3.12+ use context API

Notes

  • Follows official Python migration guidance while respecting the project's Python 2.7 support requirement
  • Insecure SSL settings (CERT_NONE) are intentional for penetration testing use cases
  • Similar polyglot approach can be applied to other Python SSL payloads if needed

Fixes #21301

- ssl.wrap_socket() was removed in Python 3.12, causing AttributeError
- Added try/except AttributeError polyglot fallback for cross-version support
- Maintains full backward compatibility with Python 2.7 and 3.4-3.11
- Preserves CERT_NONE behavior for reverse shell use case

Fixes rapid7#21301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

cmd/unix/reverse_python_ssl Fails on Python 3.14

3 participants