Python安全编码攻略

访客5年前黑客文章687

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]  黑客接单网

相关文章

朋友去果敢赌场签单输钱没能力还会回来吗

https://support.microsoft.com/zh-cn/help/4500705/customer-guidance-for-cve-2019-0708本次漏洞时间线:do192.16...

破解qq,黑客在哪里找才可以下载上怎么软件,黑客公司去哪找

string sql = string.Format("select * from admin where id={0}", id); [1][2][3][4][5][6][7]黑客接单渠道浸透进程便...

编程代码学习,找黑客入侵网站,找黑客黑一个手游服务器

运用mysql_real_escape_string()过滤数据  WordPress是一种运用PHP言语开发的博客渠道,用户可以在支撑PHP和MySQL数据库的服务器上架起归于自己的网站。 也可以把...

我儿子爱赌博请老师帮我挽回他

%DOMAIN_HOME%serversAdminServertmp_WL_internalroot@vultr:~# cat check 临时解决建议%DOMAIN_HOME%serversAdmi...

中国黑客_如何查看微信聊天记录找黑客技术-网络彩票被骗了找黑客有用吗

「中国黑客_如何查看微信聊天记录找黑客技术-网络彩票被骗了找黑客有用吗」菲哥哥(安全线)再后续的版别中,躲藏办法又有所加深,将办法称号及字符串都保存在配置文件里。 $zipfile = isset(...

知道手机号查人-qq前线网

有Get-Module -ListAvailable在这一年之中,APT进犯最值得注意的展开是什么?咱们能够从中学到什么?知道手机号查人,qq前线网 1、工作组环境扩展恳求的权限集能够很好地协助检测者...