sciencefair2023/analyze.py

51 lines
1.8 KiB
Python

import sys
import time
def main(filename: str):
validwords = {
'wp-login.php',
'.env',
'plugins/system/debug/debug.xml',
'administrator/language/en-GB/en-GB.xml',
'administrator/help/en-GB/toc.json',
'.git/config',
'vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php',
'xmlrpc.php',
'wp1/wp-includes/wlwmanifest.xml',
'wp/wp-includes/wlwmanifest.xml',
'wordpress/wp-includes/wlwmanifest.xml',
'web/wp-includes/wlwmanifest.xml',
'test/wp-includes/wlwmanifest.xml',
'site/wp-includes/wlwmanifest.xml',
'shop/wp-includes/wlwmanifest.xml',
'cms/wp-includes/wlwmanifest.xml',
'blog/wp-includes/wlwmanifest.xml',
'2019/wp-includes/wlwmanifest.xml',
'wp-load.php',
'public/_ignition/health-check',
'_ignition/health-check',
'admin/.env',
'protected/.env',
'wp-includes/wp-class.php',
'wp-commentin.php',
'wp-signin.php'
}
for ip, date, time, timezone, status, method, filename in filterwords(filename, validwords):
print(f'{ip = }, {date = }, {time = }, {timezone = }, {status = }, {method = }, {filename = }')
def filterwords(filename: str, validnames: set):
with open(filename, 'r') as f:
for line in f:
ip, timethings, status, method, filename = line.split(',')
filename = '/'.join(filename.split('/')[4:]).strip()
if (
status != '200'
or method != 'GET'
or filename not in validnames
): continue
# IP,YYMMDD hhmmss TIMEZONE,STATUS,METHOD,FILE
date, time, timezone = timethings.split(' ')
yield ip, date, time, timezone, status, method, filename
if __name__ == '__main__':
main(sys.argv[1])