Note. The functionality described in the article is relevant for the first version of the utility. For the latest version with a lot of new buns, I suggest going to the repository .
/var/log/kern.log*
;/var/log/syslog*
;/var/log/messages*
;/var/log/dmesg*
;/var/log/daemon.log*
./var/log/syslog*
or /var/log/messages*
, parses them in search of the necessary information and puts the found traces of USB device connections into beautiful tablets (or lists - as you like). $ python3 usbrip.py -h
$ python3 usbrip.py <> -h
$ python3 usbrip.py <> <> -h
$ python3 usbrip.py banner . $ python3 usbrip.py events history [-q] [-t | -l] [-e] [-n _] [-d [ ...]] [-c [ ...]] [-f _ [_ ...]] USB-. $ python3 usbrip.py events gen_auth <_.JSON> [-a [ ...]] [-q] [-e] [-n _] [-d [ ...]] [-f _ [_ ...]] () USB-. $ python3 usbrip.py events violations <_.JSON> [-a [ ...]] [-q] [-t | -l] [-e] [-n _] [-d [ ...]] [-c [ ...]] [-f _ [_ ...]] "-" . $ python3 usbrip.py ids search [-q] [--vid VID] [--pid PID] [--offline] VID / PID . $ python3 usbrip.py ids download [-q] () USB-.
, 'events history', 'events gen_auth', 'events violations', 'ids search', 'ids download': -q, --quiet , () , ##################################################################################### , 'events history', 'events gen_auth', 'events violations': -e, --external USB- ( ) -n _, --number _ , -d [ ...], --date [ ...] , -f _ [_ ...], --file _ [_ ...] - ( , - : /var/log/syslog* /var/log/messages* ) ##################################################################################### , 'events history', 'events violations': -t, --table ( , ; -t ) -l, --list -c [ ...], --column [ ...] , ( ); : "conn", "user", "vid", "pid", "prod", "manufact", "serial", "port", "disconn". ##################################################################################### , 'events gen_auth', 'events violations': -a [ ...], --attribute [ ...] , ( "-" 'events violations'); : "vid", "pid", "prod", "manufact", "serial". ##################################################################################### , 'ids search', 'ids download': --vid VID vendor ID USB- ( 4 ) --vid PID product ID USB- ( 4 ) --offline , USB- ()
-q, --quite
), forming a list output ( -l, --list
), including in the last 100 events found ( -n _, --number _
): $ python3 usbrip.py events history -ql -n 100
-e, --external
), forming a table-like output with fields (columns) “Connected”, “VID”, “PID”, “Disconnected” and “Serial Number” ( -c [ ...], --column [ ...]
), filtering the search by date ( -d [ ...], --date [ ...]
), taking the information from external log files ( -f _ [_ ...], --file _ [_ ...]
): $ python3 usbrip.py events history -et -c conn vid pid disconn serial -d "Dec 9" "Dec 10" -f /var/log/syslog.1 /var/log/syslog.2.gz
"|"
or ">"
for example), the output data will not contain a special. characters responsible for the font color in the terminal, so the text file will not be littered with unreadable characters. It should also be noted that usbrip uses some UNICODE constants, so it would be nice to immediately convert the encoding of the created file to UTF-8 for their correct display (for example, using encov
), and also use newline characters in Windows-style for better portability ( for example using awk
): $ python3 usbrip.py history events -t | awk '{ sub("$", "\r"); print }' > usbrip.txt && enconv -x UTF8 usbrip.txt
usbrip.txt
file and add another awk
instruction: $ awk '{ sub("$", "\r"); gsub("\\x1B\\[[0-?]*[ -/]*[@-~]", ""); print }' usbrip.txt && enconv -x UTF8 usbrip.txt
trusted/auth.json
), containing the “VID” and “PID” fields of the first three devices connected on September 26th: $ python3 usbrip.py events gen_auth trusted/auth.json -a vid pid -n 3 -d "Sep 26"
trusted/auth.json
) across the “PID” field and form the output as a table with the fields “Connected”, “VID” and “PID”: $ python3 usbrip.py events violations trusted/auth.json -a pid -et -c conn vid pid
$ python3 usbrip.py ids search --vid 0781 --pid 5580
$ python3 usbrip.py ids download
Source: https://habr.com/ru/post/352254/
All Articles