2019-08-22 14:48:57 3475浏览
今天千锋扣丁学堂Python培训老师给大家分享一篇关于黑客们会用到哪些关于Python技术的详细介绍,首先Python已经成为漏洞开发领域的行业标准,读者会发现大多数概念验证工具都是用Python语言编写的(除了用Ruby写的安全漏洞检测工具)。Python允许开发者编写脚本处理远程服务,处理二进制文件,与C语言库(或者Java的Jython/。Net的IronPython)以快速且简单的方式进行交互。它“内置电池”原则的巨大标准库,为开发省去对其它框架或者语言的依赖。(注:大多数例子基于Python3.0以上版本编写的,有些可以兼容python所有分支)。
# 生成新环境的方法如下: $ virtualenv <新环境的路径> # 或者在Python3.3以上的环境中: $ python3 -mvenv <新环境的路径> # 使用这个环境之前,你要先激活它: $ source <新环境的路径>/bin/activate # 禁止该环境的方式也很简单: $ deactivate
r = requests.get('https://api.github.com/user', auth=('user', 'pass')) r.json() {u'private_gists': 419, u'total_private_repos': 77, ...}
from __future__ import unicode_literals import socket s = socket.create_connection(('www.ernw.de', 80)) s.sendall(b'GET / HTTP/1.1 Host: www.ernw.de ') print(s.recv(1024))
from __future__ import unicode_literals import socket import ssl s = socket.create_connection(('www.ernw.de', 443)) s = ssl.wrap_socket(s) s.sendall(b'GET / HTTP/1.1 Host: www.ernw.de ') print(s.recv(1024))
from __future__ import unicode_literals import socket import ssl s = socket.create_connection(('smtp.example.com', 25)) s.sendall(b'HELO smtp.example.com STARTTLS ') print(s.recv(1024)) s = ssl.wrap_socket(s) s.sendall(b'MAIL FROM:<foo@example.com> ') print(s.recv(1024))
"Hello World".encode("hex") "AAA=".decode("base64")
bytes.fromhex('414141') b'AAA'.hex() # 从Py3.5 开始
import base64 base64.b64encode(b'Hello World') import codecs codecs.encode(b'Hello World', 'base64') import binascii binascii.b2a_base64(b'Hello World')
from urllib.parse import quote_plus, unquote_plus quote_plus('Hello World+1=1337') # Hello+World%2B1%3D1337 unquote_plus('Hello+World') # Hello World
import struct struct.pack('<I', 1337) # convert the integer 1337 into its little endian, 32 bit representation struct.unpack('<I', b'')[0] # returns tuple of results -> get only the first result struct.unpack('<I4s', b'Test') # returns (16, b'Test')
a = 1337 a.to_bytes(4, 'little') # 32 bit little endian a.to_bytes(2, 'big') # 16 bit big endian int.from_bytes(b'', 'little') # 16
from ctypes import * import io class TestStructure(Structure): _fields_ = (('foo', c_int), ('bar', c_char)) t = Test() t.foo = 1337 t.bar = b'A' b = io.BytesIO() b.write(t) b.seek(0) print(b.getvalue()) # 9A t2 = Test() b = io.BytesIO(b'B') b.readinto(t2) print(t2.foo) # 16 print(t2.bar) # B
from ctypes import * libc = ctypes.CDLL('libc.so.6') libc.printf(b'Hello World ')
from pwn import * r = gdb.debug('./level3') # r = remote(IP, PORT) # 为了做一个远程交互式的接口,先注释 r.recvuntil(': ') r.sendline(EXPLOIT) r.interactive() # 开启一个交互式会话
【关注微信公众号获取更多学习资料】 【扫码进入Python全栈开发免费公开课】