Update of wininetpton to latest revision

This commit is contained in:
Miroslav Štampar 2026-06-10 20:40:22 +02:00
parent 58db3a74d5
commit af0e46316a
3 changed files with 109 additions and 67 deletions

View file

@ -188,7 +188,7 @@ c03dc585f89642cfd81b087ac2723e3e1bb3bfa8c60e6f5fe58ef3b0113ebfe6 lib/core/data.
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
49f25f49bc6ba3e41713deff289152e3991f5fc894559788152e53e210a0a5dd lib/core/settings.py
b035d4789fe95557807a3e0b3e16822a31dba2f46cb952cd46c9bce270fa7368 lib/core/settings.py
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
70ea3768f1b3062b22d20644df41c86238157ec80dd43da40545c620714273c6 lib/core/target.py
@ -641,4 +641,4 @@ e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 thirdparty/soc
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 thirdparty/termcolor/__init__.py
b14474d467c70f5fe6cb8ed624f79d881c04fe6aeb7d406455da624fe8b3c0df thirdparty/termcolor/termcolor.py
4db695470f664b0d7cd5e6b9f3c94c8d811c4c550f37f17ed7bdab61bc3bdefc thirdparty/wininetpton/__init__.py
7d7ec81c788600d02d557c13f9781bb33f8a699c5a44c4df0a065348ad2ee502 thirdparty/wininetpton/win_inet_pton.py
ac055d6ae1f7a99d4334a4e5328dae1758e7a84f01292acd1bb5105ee4f26927 thirdparty/wininetpton/win_inet_pton.py

View file

@ -20,7 +20,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.6.55"
VERSION = "1.10.6.56"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View file

@ -1,85 +1,127 @@
#!/usr/bin/env python
# This software released into the public domain. Anyone is free to copy,
# modify, publish, use, compile, sell, or distribute this software,
# either in source code form or as a compiled binary, for any purpose,
# commercial or non-commercial, and by any means.
import socket
import ctypes
import os
import sys
class sockaddr(ctypes.Structure):
_fields_ = [("sa_family", ctypes.c_short),
("__pad1", ctypes.c_ushort),
("ipv4_addr", ctypes.c_byte * 4),
("ipv6_addr", ctypes.c_byte * 16),
("__pad2", ctypes.c_ulong)]
def inject_into_socket():
import ctypes
if hasattr(ctypes, 'windll'):
WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
WSAAddressToStringA = ctypes.windll.ws2_32.WSAAddressToStringA
else:
def not_windows():
raise SystemError(
"Invalid platform. ctypes.windll must be available."
)
WSAStringToAddressA = not_windows
WSAAddressToStringA = not_windows
class in_addr(ctypes.Structure):
_fields_ = [("S_addr", ctypes.c_ubyte * 4)]
class in6_addr(ctypes.Structure):
_fields_ = [("Byte", ctypes.c_ubyte * 16)]
def inet_pton(address_family, ip_string):
addr = sockaddr()
addr.sa_family = address_family
addr_size = ctypes.c_int(ctypes.sizeof(addr))
if hasattr(ctypes, "windll"):
# InetNtopW(
# INT family,
# const VOID *pAddr,
# PWSTR pStringBuf,
# size_t StringBufSize
# ) -> PCWSTR
InetNtopW = ctypes.windll.ws2_32.InetNtopW
if WSAStringToAddressA(
ip_string,
address_family,
None,
ctypes.byref(addr),
ctypes.byref(addr_size)
) != 0:
raise socket.error(ctypes.FormatError())
# InetPtonW(
# INT family,
# PCWSTR pszAddrString,
# PVOID pAddrBuf
# ) -> INT
InetPtonW = ctypes.windll.ws2_32.InetPtonW
if address_family == socket.AF_INET:
return ctypes.string_at(addr.ipv4_addr, 4)
if address_family == socket.AF_INET6:
return ctypes.string_at(addr.ipv6_addr, 16)
raise socket.error('unknown address family')
def inet_ntop(address_family, packed_ip):
addr = sockaddr()
addr.sa_family = address_family
addr_size = ctypes.c_int(ctypes.sizeof(addr))
ip_string = ctypes.create_string_buffer(128)
ip_string_size = ctypes.c_int(ctypes.sizeof(ip_string))
if address_family == socket.AF_INET:
if len(packed_ip) != ctypes.sizeof(addr.ipv4_addr):
raise socket.error('packed IP wrong length for inet_ntoa')
ctypes.memmove(addr.ipv4_addr, packed_ip, 4)
elif address_family == socket.AF_INET6:
if len(packed_ip) != ctypes.sizeof(addr.ipv6_addr):
raise socket.error('packed IP wrong length for inet_ntoa')
ctypes.memmove(addr.ipv6_addr, packed_ip, 16)
# WSAGetLastError() -> INT
WSAGetLastError = ctypes.windll.ws2_32.WSAGetLastError
else:
raise socket.error('unknown address family')
if WSAAddressToStringA(
def not_windows():
raise SystemError("Invalid platform. ctypes.windll must be available.")
InetNtopW = not_windows
InetPtonW = not_windows
WSAGetLastError = not_windows
def inet_pton(address_family, ip_string):
if sys.version_info[0] > 2 and isinstance(ip_string, bytes):
raise TypeError("inet_pton() argument 2 must be str, not bytes")
if address_family == socket.AF_INET:
family = 2
addr = in_addr()
elif address_family == socket.AF_INET6:
family = 23
addr = in6_addr()
else:
raise OSError("unknown address family")
ip_string = ctypes.c_wchar_p(ip_string)
ret = InetPtonW(ctypes.c_int(family), ip_string, ctypes.byref(addr))
if ret == 1:
if address_family == socket.AF_INET:
return ctypes.string_at(addr.S_addr, 4)
else:
return ctypes.string_at(addr.Byte, 16)
elif ret == 0:
raise socket.error("illegal IP address string passed to inet_pton")
else:
err = WSAGetLastError()
if err == 10047:
e = socket.error("unknown address family")
elif err == 10014:
e = OSError("bad address")
else:
e = OSError("unknown error from inet_ntop")
e.errno = err
raise e
def inet_ntop(address_family, packed_ip):
if address_family == socket.AF_INET:
addr = in_addr()
if len(packed_ip) != ctypes.sizeof(addr.S_addr):
raise ValueError("packed IP wrong length for inet_ntop")
ctypes.memmove(addr.S_addr, packed_ip, 4)
buffer_len = 16
family = 2
elif address_family == socket.AF_INET6:
addr = in6_addr()
if len(packed_ip) != ctypes.sizeof(addr.Byte):
raise ValueError("packed IP wrong length for inet_ntop")
ctypes.memmove(addr.Byte, packed_ip, 16)
buffer_len = 46
family = 23
else:
raise ValueError("unknown address family")
buffer = ctypes.create_unicode_buffer(buffer_len)
ret = InetNtopW(
ctypes.c_int(family),
ctypes.byref(addr),
addr_size,
None,
ip_string,
ctypes.byref(ip_string_size)
) != 0:
raise socket.error(ctypes.FormatError())
ctypes.byref(buffer),
buffer_len,
)
if ret is None:
err = WSAGetLastError()
if err == 10047:
e = ValueError("unknown address family")
else:
e = OSError("unknown error from inet_ntop")
e.errno = err
raise e
return ip_string[:ip_string_size.value - 1]
return ctypes.wstring_at(buffer, buffer_len).rstrip("\x00")
# Adding our two functions to the socket library
if os.name == 'nt':
# Adding our two functions to the socket library
socket.inet_pton = inet_pton
socket.inet_ntop = inet_ntop
if os.name == "nt" and not hasattr(socket, "inet_pton"):
inject_into_socket()