Skip to content

Commit

Permalink
current server
Browse files Browse the repository at this point in the history
  • Loading branch information
Song-Li committed May 10, 2017
1 parent 2d2d9b2 commit 99be0c6
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 26 deletions.
29 changes: 3 additions & 26 deletions flask/uniquemachine_app.py
Expand Up @@ -7,10 +7,6 @@
from flaskext.mysql import MySQL
import ConfigParser
import re
import numpy as np
from PIL import Image
import base64
import cStringIO

root = "/home/sol315/server/uniquemachine/"
config = ConfigParser.ConfigParser()
Expand All @@ -24,7 +20,6 @@
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
CORS(app)
base64_header = "data:image/png;base64,"

mask = []
mac_mask = []
Expand All @@ -34,26 +29,9 @@
with open(root + "mac_mask.txt", 'r') as fm:
mac_mask = json.loads(fm.read())

@app.route("/pictures", methods=['POST'])
def store_pictures():
image_b64 = request.values['imageBase64']
# remove the define part of image_b64
image_b64 = re.sub('^data:image/.+;base64,', '', image_b64)
# decode image_b64
image_data = image_b64.decode('base64')
image_data = cStringIO.StringIO(image_data)
image_PIL = Image.open(image_data)
image_binary = image_PIL.tobytes().encode('hex')

db = mysql.get_db()
cursor = db.cursor()
sql_str = "INSERT INTO pictures (dataurl) VALUES ('" + image_binary + "')"
cursor.execute(sql_str)

sql_str = "SELECT LAST_INSERT_ID()"
cursor.execute(sql_str)
ID = cursor.fetchone()
return str(ID[0])
@app.route("/")
def hello():
return "Hello World!"

@app.route('/details', methods=['POST'])
def details():
Expand Down Expand Up @@ -150,7 +128,6 @@ def features():
feature_str = "IP"
value_str = "'" + IP + "'"


for feature in feature_list:

if result[feature] is not "":
Expand Down
170 changes: 170 additions & 0 deletions flask/uniquemachine_appbk.py
@@ -0,0 +1,170 @@
from flask import Flask, request,make_response, current_app
from flask_failsafe import failsafe
import flask
from flask_cors import CORS, cross_origin
import json
import hashlib
from flaskext.mysql import MySQL
import ConfigParser
import re

root = "/home/sol315/server/uniquemachine/"
config = ConfigParser.ConfigParser()
config.read(root + 'password.ignore')

mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = config.get('mysql', 'username')
app.config['MYSQL_DATABASE_PASSWORD'] = config.get('mysql', 'password')
app.config['MYSQL_DATABASE_DB'] = 'uniquemachine'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
CORS(app)


@app.route("/")
def hello():
return "Hello World!"

@app.route('/details', methods=['POST'])
def details():
res = {}
ID = request.get_json()["ID"]
db = mysql.get_db()
cursor = db.cursor()
sql_str = "SELECT * FROM features WHERE browser_fingerprint = '" + ID +"'"
cursor.execute(sql_str)
db.commit()
row = cursor.fetchone()
for i in range(len(row)):
value = row[i]
name = cursor.description[i][0]
res[name] = value

return flask.jsonify(res)

@app.route('/features', methods=['POST'])
def features():
agent = ""
accept = ""
encoding = ""
language = ""
IP = ""

try:
agent = request.headers.get('User-Agent')
accpet = request.headers.get('Accept')
encoding = request.headers.get('Accept-Encoding')
language = request.headers.get('Accept-Language')
IP = request.remote_addr
except:
pass

feature_list = [
"agent",
"accept",
"encoding",
"language",
"resolution",
"fonts",
"WebGL",
"inc",
"gpu",
"gpuImgs",
"timezone",
"plugins",
"cookie",
"localstorage",
"adBlock",
"cpu_cores",
"canvas_test",
"audio"]

cross_feature_list = [
"timezone",
"fonts"
]


result = request.get_json()
mask = []
mac_mask = []

with open(root + "mask.txt", 'r') as f:
mask = json.loads(f.read())

if 'Mac' in agent or 1:
with open(root + "mac_mask.txt", 'r') as fm:
mac_mask = json.loads(fm.read())
else:
mac_mask = [1 for i in range(len(mask))]

single_hash = ""
cross_hash = ""

#with open("fonts.txt", 'a') as f:
#f.write(result['fonts'] + '\n')

fonts = list(result['fonts'])

cnt = 0
for i in range(len(mask)):
fonts[i] = str(int(fonts[i]) & mask[i] & mac_mask[i])
if fonts[i] == '1':
cnt += 1

result['agent'] = agent
result['accept'] = accept
result['encoding'] = encoding
result['language'] = language

print agent

feature_str = "IP"
value_str = "'" + IP + "'"

for feature in feature_list:
single_hash += str(result[feature])
hash_object = hashlib.md5(str(result[feature]))

if result[feature] is not "":
value = result[feature]
else:
value = "NULL"

feature_str += "," + feature
#for gpu imgs
if feature == "gpuImgs":
value = ",".join('%s_%s' % (k,v) for k,v in value.iteritems())
else:
value = str(value)

if feature == "cpu_cores" and type(value) != 'int':
value = -1

value_str += ",'" + str(value) + "'"
#print feature, hash_object.hexdigest()


result['fonts'] = fonts
for feature in cross_feature_list:
cross_hash += str(result[feature])
hash_object = hashlib.md5(str(result[feature]))

hash_object = hashlib.md5(single_hash)
single_hash = hash_object.hexdigest()

hash_object = hashlib.md5(cross_hash)
cross_hash = hash_object.hexdigest()

feature_str += ',browser_fingerprint,computer_fingerprint_1'
value_str += ",'" + single_hash + "','" + cross_hash + "'"

db = mysql.get_db()
cursor = db.cursor()
sql_str = "INSERT INTO features (" + feature_str + ") VALUES (" + value_str + ");"
cursor.execute(sql_str)
db.commit()

print (single_hash, cross_hash)
return flask.jsonify({"single": single_hash, "cross": cross_hash})
3 changes: 3 additions & 0 deletions flask/wsgi_server.wsgi
@@ -0,0 +1,3 @@
import sys
sys.path.insert(0, "/home/sol315/server/uniquemachine/")
from uniquemachine_app import app as application

0 comments on commit 99be0c6

Please sign in to comment.