Python安全编码攻略

访客5年前黑客文章688

0x00 前语


from:http://sector.ca/Portals/17/Presentations15/SecTor_Branca.pdf

这个pdf中深化Python的中心库进行剖析,而且探讨了在两年的安全代码检查过程中,一些被认为是最要害的问题,最终也提出了一些解决方案和缓解的办法。我自己也在验证探求过程中添枝加叶了一点,如有过错还请指出哈。

下面一张图表明他们的办法论:

探求的场景为:

输入的数据是"不知道"的类型和巨细 运用RFC标准构建Libraries 数据在没有通过恰当的验证就被处理了 逻辑被更改为是独立于操作系统的

0x01 Date and time —> time, datetime, os


time

asctime

1
2
3
4
5
6
7
8
9
10
11
import time
initial_struct_time = [tm for tm in time.localtime()]      
 
# Example on how time object will cause an overflow
# Same for: Year, Month, Day, minutes, seconds 
invalid_time = (2**63)     
 
# change ‘Hours' to a value bigger than 32bit/64bit limit  
initial_struct_time[3] = invalid_time      
 
overflow_time = time.asctime(initial_struct_time)

这里边asctime()函数是将一个tuple或许是struct_time表明的时刻方式转换成类似于Sun Jun 20 23:21:05 1993的方式,能够time.asctime(time.localtime())验证一下。对time.struct_time(tm_year=2019, tm_mon=11, tm_mday=7, tm_hour=20, tm_min=58, tm_sec=57, tm_wday=5, tm_yday=311, tm_isdst=0)中每一个键值设置invalid_time可形成溢出过错。

在Python 2.6.x中报错为OverflowError: long int too large to convert to int

在Python 2.7.x中报错为

OverflowError: Python int too large to convert to C long OverflowError: signed integer is greater than maximum

自己在64位Ubuntu Python2.7.6也测验了一下,输出成果为:

[-] hour:
    [+] OverflowError begins at 31: signed integer is greater than maximum
    [+] OverflowError begins at 63: Python int too large to convert to C long
...

gmtime

1
2
3
import time
print time.gmtime(-2**64)  
print time.gmtime(2**63)

time.gmtime()为将秒数转化为struct_time格局,它会根据time_t渠道进行查验,如上代码中将秒数扩展进行测验时会发生报错ValueError: timestamp out of range for platform time_t。假如数值在-2^63到-2^56之间或许2^55到2^62之间又会引发另一种报错ValueError: (84, 'Value too large to be stored in data type')。我自己的测验成果输出如下:

[-] 2 power:
    [+] ValueError begins at 56: (75, 'Value too large for defined data type')
    [+] ValueError begins at 63: timestamp out of range for platform time_t
[-] -2 power:
    [+] ValueError begins at 56: (75, 'Value too large for defined data type')
    [+] ValueError begins at 64: timestamp out of range for platform time_t

os

1
2
3
4
5
6
7
8
9
10
11
12
import os  
TESTFILE = 'temp.bin'      
 
validtime = 2**55  
os.utime(TESTFILE,(-2147483648, validtime))
stinfo = os.stat(TESTFILE) 
print(stinfo)      
 
invalidtime = 2**63
os.utime(TESTFILE,(-2147483648, invalidtime))  
stinfo = os.stat(TESTFILE) 
print(stinfo)

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]  黑客接单网

相关文章

想找真正的黑客接单,怎么联系网络黑客贴吧,2018找黑客

一、关于007安排的工业链 1要提到装置完结JDK后为啥还要装备一下环境变量,或许许多Java的初学者或许有学过Java的朋友或许都未必能够彻底的答复的上来。 其实,所谓的环境变量,就是在操作体系中一...

API浸透测验根底

API浸透测验是一种常见的进犯面,进犯者能够经过它来进一步获取运用程序或许服务器的拜访权限。本篇文章中,我会讲到API浸透测验的一些根底知识。 本文分为下面三部分: 1. API浸透测验是什么? 2....

微信如何定位自己位置,南宁找黑客帮忙,找一个黑客朋友

// Copyright (c) Microsoft. All rights reserved.... 这其实是一场信号争夺战,那么有没有办法让无人机更安稳的更安稳接纳咱们的信号呢?假如咱们把跳频时...

能接单的黑客qq_找黑客做软件下载-找黑客改社保

「能接单的黑客qq_找黑客做软件下载-找黑客改社保」然后咱们来判别指定列名的内容长度,也便是admin列的内容长度。 看下图:exec 9>&-初度运用,咱们需在终端下输入讯飞语音输入...

黑客接单专业词有什么,哪里找黑客接单,找黑客微信定位软件下载

-r界说从某一个当地重新开端 String : 192.126.119.48 }<form id="submit-form" class="e665-dedd-90b0-16d8 form-group" a...

深入分析web.config上传方面的安全问题(下)-黑客接单平台

(接上文) 2.2. 接收现有/上传的.NET文件 下面的web.config可用于接收现有的Web服务文件: <?xmlversion="1.0"encoding="UTF-8"?>...