Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
176 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import sys | ||
sys.path.insert(0, "/home/sol315/server/uniquemachine/") | ||
from uniquemachine_app import app as application |