qpython3 读取安卓lastpass Cookies

WBOY
Freigeben: 2016-07-21 14:53:16
Original
1836 Leute haben es durchsucht

之前我的博客写了python读取windows chrome Cookies,沿着同样的思路,这次本来想尝试读取安卓chrome Cookies,

但是可能是chrome的sqlite3版本比较高失败了,so改成读取lastpass 的Cookies。

背景介绍:

qpython3 是一个基于sl4a实现的能让python3跑在安卓手机上集成环境。

lastpass 是一个密码管理器,安卓版lastpass 内置了一个web浏览器。经分析lastpass的Cookies的表名,字段名与chrome一样,且value明文存储不加密。

requests 是一个python 第三方http库,qpython3中集成了。

sqlite3 是一个嵌入式数据库,很多软件和APP用到了sqlite。比如chrome lastpass浏览器用来存储cookies和访问记录之类的信息。

由于找不到好的方法让python代码以root权限读取其它APP数据的方法,

于是采用调用命令su -c cp 的方法直接把文件拷贝到SD卡再读取。

以下代码是qpython3下读出lastpass cookies并成功用于发送博客园闪存的例子:

运行环境 qpython3 安卓4.4 必须root 手机索尼L39H 安卓版lastpass,运行前需要在lastpass中登录一次博客园。

#-*-coding:utf8;-*-
#qpy:3
#qpy:console
import sqlite3
import os
import requests
from random import random
#path='/data/data/com.android.chrome/app_chrome/Default/Cookies'
path='/data/user/0/com.lastpass.lpandroid/app_webview/Cookies'
sd="/sdcard"

def sucp(source,dest):
  os.system("su -c cp -f %s %s" % ( source , dest ) )

def getcookies(host):  
  sql="select host_key,name,value from Cookies where host_key= '%s'" % host
  cu=sqlite3.connect('/sdcard/Cookies').cursor()
  result=cu.execute(sql).fetchall()
  cookies={name:value for host_key,name,value in result}
  cu.close()
  print(cookies)
  return cookies

sucp(path,sd)#用root权限拷贝文件到sd卡目录下

#以下代码用来发送博客园闪存
url="http://ing.cnblogs.com/ajax/Ing/MobileIngSubmit"
httphead={'User-Agegnt':'Safari/537.36',}
data={"content":"来自qpython3 发送的闪存 %s" % random(),"publicFlag":1}

res=requests.post(url,headers=httphead,data=data,cookies=getcookies('.cnblogs.com')).text
print(res)

Nach dem Login kopieren

另一个反向思路的应用是可以实现程序用帐号密码登录成功后,把Cookies信息写到用户浏览器的Cookies文件里,这样可以不需要手动输入帐号密码。

或者也可以实现一个浏览器的cookies导入到另一个浏览器里。→_→或者同步?

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!