Python安全编码攻略

访客5年前黑客文章686

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

相关文章

哪里找黑客接单_qq黑客解密找哪个-暗网上找黑客

「哪里找黑客接单_qq黑客解密找哪个-暗网上找黑客」加上一个单引号,报错了if (!url.contains("google.com")) {220.170.79.195 21 80 443 3389...

我是一个不爱服输的人,假如去赌博输了几十块钱就

本月Apache被公布了一个提权的漏洞,并且前天在GitHub上公布出了利用脚本,这几天我负责漏洞应急这个漏洞。 #4 0x541c32 in cfrIterateGlyphs afdko/c/pu...

php SQL 防注入的一些经历

 发生原因 一方面自己没这方面的认识,有些数据没有通过严厉的验证,然后直接拼接 SQL 去查询。导致缝隙发生,比方:   $id  = $_GET['id']; $sql = "SELECT name...

怎样查自己的手机号码,怎么去联系黑客,找黑客找回qq账号

ps:图片可单击扩大观看。 /// 直线数据库并输出表格 /// </summary> struct CORINFO_METHOD_INFO* info,...

专业接单黑客联系方式(24小时接单的黑客接单)

今后,微信、微博聊天记录可以正式作为诉讼证据。根据该决定第14条,电子数据包括以下信息和电子文件: 网页、博客、微博等网络平台发布的信息; 手机短信、电子邮件、即时通信、通讯群等网络应用服务的通信...

qq上黑客接单真的吗,网络电脑黑客联系方式,黑客找微信号

本文争夺以零基础的视点对整个发现和运用进程抽丝剥茧,并尽量具体论述这个进程中触及的技术细节。 本文触及的技术细节适用大疆精灵3代,2代和1代,不适用最新的精灵4代无人机。 由于行文时刻匆促,如有遗漏敬...