Home  >  Article  >  Backend Development  >  qpython3 reads Android lastpass Cookies

qpython3 reads Android lastpass Cookies

WBOY
WBOYOriginal
2016-07-21 14:53:161836browse

My blog previously wrote about python reading windows chrome cookies. Following the same idea, this time I wanted to try reading Android chrome cookies,

But it may be that the sqlite3 version of chrome is relatively high and failed, so it was changed to read the cookies of lastpass.

Background introduction:

qpython3 is an integrated environment based on sl4a that allows python3 to run on Android phones.

lastpass is a password manager, and the Android version of lastpass has a built-in web browser. After analyzing the table name of lastpass's cookies, the field names are the same as chrome, and the value is stored in plain text without encryption.

requests is a python third-party http library, integrated in qpython3.

sqlite3 is an embedded database. Many software and APPs use sqlite. For example, the chrome lastpass browser is used to store information such as cookies and access records.

Since I can’t find a good way for python code to read other APP data with root permissions,

So we use the command su -c cp to directly copy the file to the SD card and then read it.

The following code is an example of reading lastpass cookies under qpython3 and successfully using it to send blog garden flash:

Operating environment qpython3 Android 4.4 must be rooted mobile phone Sony L39H Android version lastpass, you need to log in to the blog park in lastpass before running.

#-*-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)

Another application of reverse thinking is that after the program successfully logs in with the account and password, it can write the Cookies information to the Cookies file of the user's browser, so that there is no need to manually enter the account and password.

Or you can also import cookies from one browser to another browser. →_→ Or sync?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn