cmd18946/query2.py
2026-12-06 08:51:44 +01:00

39 lines
1.9 KiB
Python

#!/usr/bin/env python3
import json,sys
try:
import pymysql
except Exception as e:
print('IMPORT_ERR',e); sys.exit()
out={'tables':[], 'hits':[]}
try:
c=pymysql.connect(host='172.18.192.197',port=3307,user='root',password='root',connect_timeout=10,read_timeout=60)
except Exception as e:
print('CONN_ERR',e); sys.exit()
cur=c.cursor()
cur.execute("""SELECT table_schema,table_name FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema','mysql','performance_schema','sys')
AND (table_name LIKE '%%firebase%%' OR table_name LIKE '%%google%%' OR table_name LIKE '%%fcm%%' OR table_name LIKE '%%iap%%' OR table_name LIKE '%%play%%')""")
tabs=[(r[0],r[1]) for r in cur.fetchall()]
out['tables']=[f'{a}.{b}' for a,b in tabs]
for db,t in tabs:
try:
cur.execute('SHOW COLUMNS FROM `%s`.`%s`'%(db,t)); cols=[r[0] for r in cur.fetchall()]
textcols=[cname for cname in cols if any(k in cname.lower() for k in ('json','content','key','secret','value','config','data'))]
if not textcols:
out['hits'].append({'db':db,'table':t,'cols':cols,'note':'no text col'}); continue
sel=','.join('`%s`'%x for x in (['id'] if 'id' in cols else [])+textcols[:6])
cur.execute('SELECT %s FROM `%s`.`%s` LIMIT 50'%(sel,db,t)); rows=cur.fetchall()
hits=[]
for r in rows:
rec={}
for i,cname in enumerate((['id'] if 'id' in cols else [])+textcols[:6]):
v=r[i]
if isinstance(v,(bytes,bytearray)): v=v.decode('utf8','replace')
elif v is not None and not isinstance(v,str): v=str(v)
if v and len(v)>200: v=v[:200]+'...<trunc>'
rec[cname]=v
hits.append(rec)
out['hits'].append({'db':db,'table':t,'cols':cols,'rows':hits})
except Exception as e:
out['hits'].append({'db':db,'table':t,'err':repr(e)})
print(json.dumps(out,ensure_ascii=False)[:60000])