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

关键代码:

from pwn import *

process = remote('127.0.0.1', 7777)

报错:

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类型的,只需要在代码里对数字进行显示的强转即可。

解决代码如下:

from pwn import *

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

ATFWUS 2024-01-08

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-08 18:30:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-08 18:30:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-08 18:30:03       87 阅读
  4. Python语言-面向对象

    2024-01-08 18:30:03       96 阅读

热门阅读

  1. MES生产管理系统流程

    2024-01-08 18:30:03       59 阅读
  2. 面试经典150题(67-71)

    2024-01-08 18:30:03       69 阅读
  3. Leetcode 3002. Maximum Size of a Set After Removals

    2024-01-08 18:30:03       62 阅读
  4. 信息学奥赛一本通:装箱问题

    2024-01-08 18:30:03       59 阅读
  5. TensorRT 自学笔记001 基础知识点和学习资源

    2024-01-08 18:30:03       66 阅读
  6. Android简单控件

    2024-01-08 18:30:03       48 阅读
  7. gunicorn基本使用

    2024-01-08 18:30:03       68 阅读
  8. golang如何生成csv文件

    2024-01-08 18:30:03       57 阅读
  9. Gin框架的数据校验

    2024-01-08 18:30:03       57 阅读