Python Security PDF
Python Security PDF
Series1
Then we will formulate some conclusions.
http://web.nvd.nist.gov/view/vuln/statistics
24th October 2014, Bucureşti, România 5
Number of Software Flaws (CVE) Trend of Software Flaws (CVE)
by Access Vector By Access Vector
7,000
6,000
5,000
4,000
3,000
2,000
1,000
0
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
http://web.nvd.nist.gov/view/vuln/statistics
24th October 2014, Bucureşti, România 6
Number of Software Flaws (CVE) Trend of Software Flaws (CVE)
by Complexity by Complexity
5,000 9
4,500 8
4,000
7
3,500
6
3,000
5
2,500
4
2,000
3
1,500
2
1,000
500 1
0 0
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
http://web.nvd.nist.gov/view/vuln/statistics
24th October 2014, Bucureşti, România 7
• Initial review of “National Vulnerability Database”
statistics revealed:
http://www.snort.org/assets/165/t
arget_based_frag.pdf
24th October 2014, Bucureşti, România 11
python -OOBR reassembler.py –demo
Reassembled using policy: First (Windows, SUN, MacOS, HPUX)
11111111111111111111111144444444222222222222222233333333333333333333333366666
6666666666666666666
Reassembled using policy: Last/RFC791 (Cisco)
11111111444444444444444444444444444444442222222255555555555555555555555566666
6666666666666666666
Reassembled using policy: Linux (Umm.. Linux)
11111111111111111111111144444444444444442222222255555555555555555555555566666
6666666666666666666
Reassembled using policy: BSD (AIX, FreeBSD, HPUX, VMS)
11111111111111111111111144444444444444442222222233333333333333333333333366666
6666666666666666666
Reassembled using policy: BSD-Right (HP Jet Direct)
11111111444444444444444444444444222222222222222255555555555555555555555566666
6666666666666666666
150
Generate
128bits SSL key
100
50
0
81
193
305
417
529
641
753
865
1
17
33
49
65
97
113
129
145
161
177
209
225
241
257
273
289
321
337
353
369
385
401
433
449
465
481
497
513
545
561
577
593
609
625
657
673
689
705
721
737
769
785
801
817
833
849
881
897
913
929
24th October 2014, Bucureşti, România 16
Under linux every process uses entropy and every server
“should” not have less than 200 bits. It Is possible to
increase the entropy level using entropy deamons like the
package “haveged”. (http://www.issihosts.com/haveged/)
4500
4000
Haveged Running Haveged Running
3500
3000
2500
2000
1500
0
183
521
1301
1
27
53
79
105
131
157
209
235
261
287
313
339
365
391
417
443
469
495
547
573
599
625
651
677
703
729
755
781
807
833
859
885
911
937
963
989
1015
1041
1067
1093
1119
1145
1171
1197
1223
1249
1275
1327
1353
1379
1405
1431
1457
1483
1509
24th October 2014, Bucureşti, România 17
• PYTHON for networking?
Scapy libdnet dpkt Impacket
pypcap pynids Dirtbags py-pcap flowgrep
Mallory Pytbull 0trace
import io
import sys
fd = io.open(sys.stdout.fileno(), 'wb')
fd.close()
The problem is due to a bug in the "codec" library that detects the character
"F4" and assumes this is the first character of a sequence of characters and wait
to receive the remaining 3 bytes, and the resulting string is truncated.
A better and safer approach would be to read the entire stream and only then
proceed to the decoding phase, as done by the ”io” module.
RESULT:
ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown protocol
The underlying socket connection remains open, but you can't access it or close it.
24th October 2014, Bucureşti, România 36
• EXAMPLE – “unlimited data” in POP3
python -OOBRtt pop3_client.py
Connecting to '127.0.0.1':45678...
import socket SERVER
HOST = '127.0.0.1'
Welcome: '+OK THIS IS A TEST' PORT = 45678
Error: 'out of memory‘ NULLS = '\0' * (1024 * 1024) # 1 MB
sock = socket.socket()
sock.bind((HOST, PORT))
import poplib
HOST = '127.0.0.1'
CLIENT sock.listen(1)
PORT = 45678 while 1:
try: conn, _ = sock.accept()
print "Connecting to %r:%d..." % (HOST, PORT) conn.sendall("+OK THIS IS A TEST\r\n")
pop = poplib.POP3(HOST, PORT) conn.recv(4096)
print "Welcome:", repr(pop.welcome) DATA = NULLS
print "Listing..." try:
reply = pop.list() while 1:
print "LIST:", repr(reply) for _ in xrange(1024):
except Exception, ex: conn.sendall(DATA)
print "Error: %r" % str(ex) except IOError, ex:
print "End." print "Error: %r" % str(ex)
ast multiprocessing
pty
bastion os.exec
rexec
commands os.popen
shelve
cookie os.spawn
subprocess
cPickle os.system
tarfile
eval parser
yaml
marshal pickle
zipfile
mktemp pipes
24th October 2014, Bucureşti, România 40
• PYTHON for the web?
Requests HTTPie ProxMon WSMap
Twill Ghost Windmill FunkLoad
spynner mitmproxy pathod / pathoc scrapy
Email: [email protected]
Linkedin: http://fr.linkedin.com/in/ebranca
24th October 2014, Bucureşti, România 45