首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏FreeBuf

    Python ctypes溢出漏洞分析

    ctypes 是Python的外部函数库,它提供了与 C 兼容的数据类型,并允许调用 DLL 或共享库中的函数,可使用该模块以纯 Python 形式对这些库进行封装。在ctypes之中存在栈溢出问题。 漏洞影响范围:小于3.9.1版本,影响模块_ctypes/callproc.c。 代码分析 先来看到 _ctypes\callproc.c PyCArg_repr 方法。这个函数的作用将数据类型转换为C数据类型进行传递。该方法内定义变量 buffer[256]用于存放字符。 ? 问题代码位于 cpython-3.8.7rc1\Modules_ctypes\callproc.c Line:521。使用sprintf作为字符串格式化,由于双精度长度超过预期。 咱们执行POC之后观察DEBUG情况 >>> from ctypes import * >>> c_double.from_param(1e300) ?

    1.2K30发布于 2021-03-24
  • 来自专栏python3

    Python使用Ctypes与CC++

    3 17 libc.pow.restype = ctypes.c_double 18 print libc.pow(ctypes.c_double(2), ctypes.c_double(10)) 19 注意这里我们使用的ctypes.cdll来load动态库,实际上ctypes中总共有以下四种方式加载动态库: class ctypes.CDLL(name, mode=DEFAULT_MODE, handle 在没有指定库函数返回类型的情况下,ctypes.CDLL和ctyps.WinDll均假定函数返回类型是int,而ctypes.oleDll则假定函数返回值是Windows HRESULT。 (ctypes.c_int(a)), ctypes.pointer(ctypes.c_int(b)) 23 my_lib.my_swap(pa, pb) 24 print pa.contents.value 29 my_lib.is_equal.argtypes = [ctypes.c_double, ctypes.c_double] 30 # print my_lib.is_equal(ctypes.c_double

    2.9K20发布于 2020-01-20
  • 来自专栏cywhat

    ModuleNotFoundError: No Module Named _Ctypes Make: *** 错误 1

    前景 新服务器安装python3.7.0在make install的时候报错ModuleNotFoundError: No module named '_ctypes' make: *** [install

    1.2K20编辑于 2022-11-22
  • 来自专栏深度应用

    使用ctypes模块调用运行c代码

    [python3 实用教程]使用ctypes模块调用运行c代码 创建c文件 demo.c: #include<stdio.h> long my_app(long a){ long ret = } return(ret); } gcc生成so文件 gcc demo.c -shared -o lib_app.so 创建python文件 import time from ctypes

    1.3K30发布于 2019-06-27
  • 来自专栏python3

    python使用ctypes模块下的wi

    原因:python是64位的python,而windll.LoadLibrary只能由32位的python使用

    84120发布于 2020-01-17
  • 来自专栏python3

    python3使用ctypes在wind

    python3使用ctypes在windows中访问C和C++动态链接库函数示例 这是我们的第一个示例,我们尽量简单,不传参,不返回,不访问其他的动态链接库 一 测试环境介绍和准备 测试环境: 操作系统 社区版(免费) Python3.7.0 (源码和安装文件) http://ffmpeg.club/python 二 C/C++部分代码 1 首先完成C/C++的动态链接库,与做python扩展库不同,ctypes 三 Python部分的代码 from ctypes import lib = CDLL("testctypes") #可以加路径 lib.CFunction() ? from ctypes import 导入ctypes库所有类和函数 CDLL("testctype")加载具体的动态链接库文件,可以加入路径比如 dll/testctype ,在windows中省略动态库的后缀名 lib.CFunction() 加载动态链接库中的CFunction函数,注意虽然我们用c++来做扩展库,python本身也做了很多支持c++的代码,但ctypes访问函数只支持C语言函数,C++函数因为有重载函数名不确定

    1.9K31发布于 2020-01-03
  • 来自专栏Pulsar-V

    centos 编译python3.7.0 报错ModuleNotFoundError: No module named _ctypes

    (adsbygoogle = window.adsbygoogle || []).push({});

    4.2K20发布于 2019-07-16
  • 来自专栏Yunfeng's Simple Blog

    ctypes的C共享库中调用Python函数

    大致流程是通过 ctypes 来调用C函数,先将Python类型的对象转换为C的类型,在C函数中做完计算,返回结果到Python中。这个过程相对是比较容易的。 但调查以后发现 ctypes 提供了 CFUNCTYPE来方便地进行回调函数定义,而C语言本身也是支持函数指针的,因此这个功能实现还算简单,具体展开如下。 2. Numpy 提供了 numpy.ndarray.ctypes 属性,可以来完成这个操作。 import numpy as np # 获取C的float指针类型 c_float_p = ctypes.POINTER(ctypes.c_float) data = np.random.rand https://stackoverflow.com/questions/3195660/how-to-use-numpy-array-with-ctypes

    3.5K30编辑于 2023-10-23
  • 来自专栏Python小屋

    Python使用ctypes调用Windows API函数获取屏幕真实DPI

    《Python程序设计开发宝典》(ISBN:9787302472100),董付国,清华大学出版社,2017

    3.5K20发布于 2019-12-13
  • 来自专栏Java架构师必看

    Python安装报错:”ModuleNotFoundError:No module named _ctypes“ 的解决方案

    兼容性好/可控制性好/开源软件会大量使用其他开源软件的功能,要解决大量的依赖关系 总结报错解决 ---- 问题一:安装时报错ModuleNotFoundError: No module named '_ctypes

    7.6K40编辑于 2022-06-06
  • 来自专栏技术向

    ctypes中使用c_char_p接收数据被截断

    于是就开始看文档,直到在文档中发现c_char_p char * (NUL terminated),再看我的代码 buffer = ctypes.c_char_p() buffer.value = 至此,错误已经很清晰了,是由于ctypes中的c_char_p为字符指针, 碰到’\x00’就会被截断。

    3.3K20发布于 2019-11-19
  • 来自专栏爬虫资料

    Python二进制通信:struct、array、ctypes模块比较

    本文将介绍三个常用的模块:struct、array、ctypes,并从结构说明和性能分析两方面进行比较。 适合处理大量相同类型且长度可变的数据 ctypes 提供了Structure类,可以直接定义与C语言中相同的结构体,并且支持指针、数组等复杂类型。 但是,如果需要处理复杂的数据结构,ctypes模块可能是一个更好的选择,因为它支持指针、数组等复杂类型。 下面使用ctypes模块进行通信: # 导入ctypes模块 import ctypes # 定义一个C语言中的结构体 class Data(ctypes.Structure): # 指定结构体的字段和类型 _fields_ = [ ("id", ctypes.c_int), ("name", ctypes.c_char * 20), ("value

    1.2K30编辑于 2023-03-01
  • 来自专栏软件研发

    解决问题_ctypes.COMError: (-2147024809, 参数错误。, (None, None, None, 0, None))

    = [ctypes.c_int, ctypes.c_float]my_function.restype = ctypes.c_int# 调用函数时传递的参数类型不匹配result = my_function 希望本文能够帮助开发者解决_ctypes.COMError错误,从而更好地使用ctypes库进行开发。 当使用ctypes库调用Windows API函数时,可能会遇到_ctypes.COMError错误。一个常见的应用场景是使用ctypes调用Windows系统的注册表API来读取或写入注册表项。 = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_uint32, ctypes.c_uint32, ctypes.POINTER(ctypes.c_void_p = [ctypes.c_void_p, ctypes.c_wchar_p, ctypes.c_uint32, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER

    2.1K10编辑于 2023-12-06
  • 来自专栏红蓝对抗

    【免杀】一种python反序列化免杀方式

    (ctypes.c_int(0),ctypes.c_int(len(shellcode)),ctypes.c_int(0x3000),ctypes.c_int(0x40)) #放入shellcode buf .CreateThread( ctypes.c_int(0), ctypes.c_int(0), ctypes.c_uint64(ptr), ctypes.c_int (ctypes.c_int(0),ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000),ctypes.c_int(0x40)) #放入shellcode ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int(0)) ) #等待上面创建的线程运行完 ctypes.windll.kernel32 ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int(0)) ) #等待上面创建的线程运行完 ctypes.windll.kernel32

    1.1K20编辑于 2022-12-22
  • 来自专栏E条咸鱼

    Shellcode Loader原理

    .VirtualAlloc.restype = ctypes.c_uint64 ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int (shellcode) ctypes.windll.kernel32.RtlMoveMemory( ctypes.c_uint64(ptr), buf, ctypes.c_int (len(shellcode)) ) handle = ctypes.windll.kernel32.CreateThread( ctypes.c_int(0), ctypes.c_int (0), ctypes.c_uint64(ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int (0)) ) ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1)) 这里按行进行解析 代码解析

    1.5K20编辑于 2022-10-27
  • 来自专栏kali blog

    python在渗透测试中的免杀

    (ctypes.c_int(0), ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000), ctypes.c_int(0x40)) # 放入shellcode handle = ctypes.windll.kernel32.CreateThread( ctypes.c_int(0), ctypes.c_int(0), ctypes.c_uint64 (ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int(0)) ) # 等待上面创建的线程运行完 .VirtualAlloc.restype = ctypes.c_uint64 ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int (0), ctypes.c_uint64(ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int

    88730编辑于 2023-08-19
  • 来自专栏好派笔记

    用Python杀掉windows平台下的进程

    import ctypes import sys TH32CS_SNAPPROCESS = 0x00000002 class PROCESSENTRY32(ctypes.Structure): fields = [("dwSize", ctypes.c_ulong), ("cntUsage", ctypes.c_ulong), ("th32ProcessID", ctypes.c_ulong), ("th32DefaultHeapID", ctypes.c_ulong), ("th32ModuleID", ctypes.c_ulong), ("cntThreads", ctypes.c_ulong), ( ("dwFlags", ctypes.c_ulong), ("szExeFile", ctypes.c_char * 260)] def getProcList():

    1.2K30发布于 2021-11-03
  • 来自专栏红蓝对抗

    免杀&&抽奖|python进行shellcode免杀

    ctypes.c_int(0), #指向任何参数的指针 ctypes.c_int(0), #创建标志 ctypes.pointer(ctypes.c_int(0)) #指向接收线程标识符的值的指针 #指向起始地址的指针 ctypes.c_int(0), #指向任何参数的指针 ctypes.c_int(0), #创建标志 ctypes.pointer(ctypes.c_int (0), ctypes.c_uint64(ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int (0), ctypes.c_uint64(ptr), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int ( ctypes.c_int(0), ctypes.c_int(0), ctypes.c_uint64(ptr), ctypes.c_int(0), ctypes.c_int

    3.9K30编辑于 2022-08-30
  • 来自专栏渗透测试教程

    记一次有趣的溯源

    .VirtualAlloc.restype = ctypes.c_uint64 ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int (shellcode) ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_uint64(ptr), buf, ctypes.c_int(len(shellcode ))) handle = ctypes.windll.kernel32.CreateThread(ctypes.c_int(0), ctypes.c_int(0), ctypes.c_uint64(ptr ), ctypes.c_int(0), ctypes.c_int(0), ctypes.pointer(ctypes.c_int (0))) ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle), ctypes.c_int(-1)) 知道shellcodeloader

    73230编辑于 2022-12-01
  • 来自专栏Brian

    Python进阶教程(三)

    更详细的使用ctypes教程ctypes tutorial。 Using C++ from Python(Ctypes) ctypes不仅可以和C在一混合编程,我们还可以和C++混合编程,但是在ctypes的官方文档里面只定义了支持C Type。 import ctypes lib = ctypes.cdll.LoadLibrary(". lib.Foo_bar.restype = ctypes.c_void_p lib.Foo_foobar.argtypes = [ctypes.c_void_p, ctypes.c_int import ctypes lib = ctypes.cdll.LoadLibrary('.

    1.2K40发布于 2018-04-03
领券