Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic IPv6 support #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions robot-detect
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import os
import argparse
import ssl
import gmpy2
import ipaddress
from cryptography import x509
from cryptography.hazmat.backends import default_backend

Expand All @@ -34,16 +35,13 @@ MSG_FASTOPEN = 0x20000000
EXECUTE_BLINDING = True


def get_rsa_from_server(server, port):
def get_rsa_from_server(connection):
try:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
ctx.set_ciphers("RSA")
raw_socket = socket.socket()
raw_socket.settimeout(timeout)
s = ctx.wrap_socket(raw_socket)
s.connect((server, port))
s = ctx.wrap_socket(connection)
cert_raw = s.getpeercert(binary_form=True)
cert_dec = x509.load_der_x509_certificate(cert_raw, default_backend())
s.close()
Expand All @@ -69,13 +67,13 @@ def get_rsa_from_server(server, port):
def oracle(pms, messageflow=False):
global cke_version
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = socket.socket(ip_family, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
if not enable_fastopen:
s.connect((ip, args.port))
s.connect(server)
s.sendall(ch)
else:
s.sendto(ch, MSG_FASTOPEN, (ip, args.port))
s.sendto(ch, MSG_FASTOPEN, server)
s.settimeout(timeout)
buf = bytearray.fromhex("")
i = 0
Expand Down Expand Up @@ -184,21 +182,32 @@ else:
# We only enable TCP fast open if the Linux proc interface exists
enable_fastopen = os.path.exists("/proc/sys/net/ipv4/tcp_fastopen")

server = (args.host, args.port)

try:
ip = socket.gethostbyname(args.host)
connection = socket.create_connection(server, timeout=timeout)
ip = connection.getpeername()[0]
ip_family = socket.AF_INET if ipaddress.ip_address(ip).version == 4 else socket.AF_INET6
except socket.gaierror as e:
if not args.quiet:
print("Cannot resolve host: %s" % e)
if args.csv:
print("NODNS,%s,,,,,,,,," % (args.host))

quit()
except ConnectionRefusedError as e:
if not args.quiet:
print("Connection refused: %s" % e)
if args.csv:
print("CONNECTIONREFUSED,%s,,,,,,,,," % (args.host))

quit()


if not args.quiet:
print("Scanning host %s ip %s port %i" % (args.host, ip, args.port))

N, e = get_rsa_from_server(ip, args.port)
N, e = get_rsa_from_server(connection)
modulus_bits = int(math.ceil(math.log(N, 2)))
modulus_bytes = (modulus_bits + 7) // 8
if not args.quiet:
Expand Down