Sage运行pwntools库脚本异常解决:OSError: Int or String expected

需要和Oracle交互的密码学脚本一般都需要借助pwn库的帮助,今天切换了python版本后,出现了一个异常(OSError: Int or String expected,详细异常见文章),查阅一下源码后简单的解决了这个问题,在此分享一下。


文章目录


问题环境与描述

  • SageMath 10.1
  • Python 3.11.1
  • pwntools 4.11.1

关键代码:

python 复制代码
from pwn import *

process = remote('127.0.0.1', 7777)

报错:

bash 复制代码
File ~/.sage/local/lib/python3.11/site-packages/pwnlib/tubes/remote.py:77, in remote.__init__(self, host, port, fam, typ, ssl, sock, ssl_context, ssl_args, sni, *args, **kwargs)
     75 fam = self._get_family(fam)
     76 try:
---> 77     self.sock   = self._connect(fam, typ)
     78 except socket.gaierror as e:
     79     if e.errno != socket.EAI_NONAME:

File ~/.sage/local/lib/python3.11/site-packages/pwnlib/tubes/remote.py:103, in remote._connect(self, fam, typ)
    100 timeout = self.timeout
    102 with self.waitfor('Opening connection to %s on port %s' % (self.rhost, self.rport)) as h:
--> 103     for res in socket.getaddrinfo(self.rhost, self.rport, fam, typ, 0, socket.AI_PASSIVE):
    104         self.family, self.type, self.proto, _canonname, sockaddr = res
    106         if self.type not in [socket.SOCK_STREAM, socket.SOCK_DGRAM]:

File /private/var/tmp/sage-10.1-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/socket.py:962, in getaddrinfo(host, port, family, type, proto, flags)
    959 # We override this function since we want to translate the numeric family
    960 # and socket type values to enum constants.
    961 addrlist = []
--> 962 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    963     af, socktype, proto, canonname, sa = res
    964     addrlist.append((_intenum_converter(af, AddressFamily),
    965                      _intenum_converter(socktype, SocketKind),
    966                      proto, canonname, sa))

OSError: Int or String expected

解决方案

报错是因为Sage把数字转成Long int类型了,而pwntools需要的是Int或者String类型的,只需要在代码里对数字进行显示的强转即可。

解决代码如下:

python 复制代码
from pwn import *

process = remote('127.0.0.1',int(7777))

ATFWUS 2024-01-08

相关推荐
道人禅(armey)5 个月前
Ubuntu18.04安装pwntools报错解决方案
开发语言·python·pwn·pwntools