1. 程式人生 > 其它 >滑鼠流量分析UsbMiceDataHacker指令碼

滑鼠流量分析UsbMiceDataHacker指令碼


1
#!/usr/bin/env python3 2 # coding:utf-8 3 4 import sys 5 import os 6 import numpy as np 7 import matplotlib.pyplot as plt 8 9 mousePositionX = 0 10 mousePositionY = 0 11 12 X = [] 13 Y = [] 14 15 DataFileName = "usb.dat" 16 data = [] 17 18 def main(): 19 global mousePositionX
20 global mousePositionY 21 # check argv 22 if len(sys.argv) != 3: 23 print("Usage : ") 24 print(" python UsbMiceHacker.py data.pcap [LEFT|RIGHT|MOVE|ALL]") 25 print("Tips : ") 26 print(" To use this python script , you must install the numpy,matplotlib first.
") 27 print(" You can use `sudo pip install matplotlib numpy` to install it") 28 print("Author : ") 29 print(" WangYihang <[email protected]>") 30 print(" If you have any questions , please contact me by email.") 31 print(" Thank you for using.
") 32 exit(1) 33 34 # get argv 35 pcapFilePath = sys.argv[1] 36 action = sys.argv[2] 37 38 if action != "LEFT" and action != "ALL" and action != "RIGHT" and action != "MOVE": 39 action = "LEFT" 40 41 # get data of pcap 42 command = "tshark -r %s -T fields -e usb.capdata > %s" % ( 43 pcapFilePath, DataFileName) 44 print(command) 45 os.system(command) 46 47 # read data 48 with open(DataFileName, "r") as f: 49 for line in f: 50 data.append(line[0:-1]) 51 52 # handle move 53 for i in data: 54 Bytes = i.split(":") 55 if len(Bytes) == 8: 56 horizontal = 2 # - 57 vertical = 4 # | 58 elif len(Bytes) == 4: 59 horizontal = 1 # - 60 vertical = 2 # | 61 else: 62 continue 63 offsetX = int(Bytes[horizontal], 16) 64 offsetY = int(Bytes[vertical], 16) 65 if offsetX > 127: 66 offsetX -= 256 67 if offsetY > 127: 68 offsetY -= 256 69 mousePositionX += offsetX 70 mousePositionY += offsetY 71 if Bytes[0] == "01": 72 print("[+] Left butten.") 73 if action == "LEFT": 74 # draw point to the image panel 75 X.append(mousePositionX) 76 Y.append(-mousePositionY) 77 elif Bytes[0] == "02": 78 print("[+] Right Butten.") 79 if action == "RIGHT": 80 # draw point to the image panel 81 X.append(mousePositionX) 82 Y.append(-mousePositionY) 83 elif Bytes[0] == "00": 84 print("[+] Move.") 85 if action == "MOVE": 86 # draw point to the image panel 87 X.append(mousePositionX) 88 Y.append(-mousePositionY) 89 else: 90 print("[-] Known operate.") 91 pass 92 if action == "ALL": 93 # draw point to the image panel 94 X.append(mousePositionX) 95 Y.append(-mousePositionY) 96 97 fig = plt.figure() 98 ax1 = fig.add_subplot(111) 99 100 ax1.set_title('[%s]-[%s] Author : WangYihang' % (pcapFilePath, action)) 101 ax1.scatter(X, Y, c='r', marker='o') 102 plt.show() 103 104 # clean temp data 105 os.system("rm ./%s" % (DataFileName)) 106 107 if __name__ == "__main__": 108 main()

 操作

python3 UsbMiceDataHacker.py  file  RIGHT/LEFT/MOVE/ALL
# 後面四個選項任選一個