13-6-knowledge-graph-Risk-Control.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import networkx as nx
  2. import matplotlib.pyplot as plt
  3. # 疑似账号被盗
  4. def hack_account():
  5. # activesyncid为2的硬件登录了mike和john两个账户。
  6. # mike历史上曾经成功登录过activesyncid为1的硬件以及activesyncid为2的硬件,初步判定activesyncid为2的硬件盗取了mike的账户登录。
  7. with open("data/KnowledgeGraph/sample1.txt") as f:
  8. G = nx.Graph()
  9. for line in f:
  10. line = line.strip('\n')
  11. # 用户名、登录IP地址、手机号、硬件全局唯一activesyncid
  12. uid, ip, tel, activesyncid = line.split(',')
  13. G.add_edge(uid, ip)
  14. G.add_edge(uid, tel)
  15. G.add_edge(uid, activesyncid)
  16. nx.draw(G, with_labels=True, node_size=600)
  17. plt.show()
  18. # 疑似撞库攻击
  19. def attack_pass():
  20. # 大量账户从ip1登录,并且ua字段相同,登录失败和成功的情况均存在,疑似发生了撞库攻击行为。
  21. with open("data/KnowledgeGraph/sample2.txt") as f:
  22. G = nx.Graph()
  23. for line in f:
  24. line = line.strip('\n')
  25. # 用户名、登录IP地址、登录状态、ua头
  26. uid, ip, login, ua = line.split(',')
  27. G.add_edge(uid, ip)
  28. G.add_edge(uid, login)
  29. G.add_edge(uid, ua)
  30. nx.draw(G, with_labels=True, node_size=600)
  31. plt.show()
  32. # 疑似刷单
  33. def click_farming():
  34. # 虽然两台设备hid1和hid2登录账户不一样, 但是他们共同安装的App2上的登录用户名相同,从而可以判断这两台设备属于同一个人,该人疑似使用这两台设备分别扮演买家和卖家进行刷单行为(这判断方法有点呆)
  35. G = nx.Graph()
  36. with open("data/KnowledgeGraph/sample3.txt") as f:
  37. for line in f:
  38. line = line.strip('\n')
  39. # 硬件指纹(唯一标识)、登录用户名、App的名称
  40. hid, uid, app = line.split(',')
  41. G.add_edge(hid, uid)
  42. G.add_edge(hid, app)
  43. with open("data/KnowledgeGraph/sample4.txt") as f:
  44. for line in f:
  45. line = line.strip('\n')
  46. # 硬件指纹(唯一标识)、登录用户名、用户行为(下单or接单)
  47. hid, uid, action = line.split(',')
  48. G.add_edge(hid, uid)
  49. G.add_edge(hid, action)
  50. nx.draw(G, with_labels=True, node_size=600)
  51. plt.show()
  52. def main():
  53. hack_account()
  54. attack_pass()
  55. click_farming()
  56. if __name__ == "__main__":
  57. main()