-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passive fingerprinting #16
base: master
Are you sure you want to change the base?
Changes from all commits
4bb562a
c3ef704
0276387
f64c569
6e123b6
8f91134
358f7f4
a99463b
8a8e102
99f3b03
e2604db
fcd3d25
6bc9c82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Analyzing Passer Results | ||
### Running the program | ||
If you're working wiwth the source code just cd to the directory of the analyser file and run | ||
```Python3 analyzer.py -i <name-of-logfile-to-import>``` | ||
The file extension does not matter, but the file must be comma separated | ||
### Filters | ||
The filter options are listed below. After running the program type ```filter``` followed by any combination of the following | ||
- type={TC, TS, UC, US, RO, DN, MA} | ||
- ip={127.0.0.1, or whatever} | ||
- set 'ippref=true' to do searches such as 10.0.* | ||
- ipv={4, 6, 0 for all} | ||
- state={open, suspicious, etc...} | ||
|
||
example: If you wanted to show all ipv4 addresses that were flagged as suspicious, you would type the following | ||
```filter ipv=4 state=suspicious``` | ||
or to see all TCP clients starting wih address 10.0.0.* | ||
```filter type=TC ip=10.0.0 ippref=true``` | ||
to reset the filters type ```reset``` at the command prompt | ||
|
||
### Commands | ||
- reset --resets the filters | ||
- show --shows the results (shrinks to fit on screen) | ||
- show-all --shows all results (use with caution) | ||
- quit --gracefully exits the program | ||
|
||
### Bugz | ||
feel free to report bugs or suggestions to [email protected] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import pandas as pd | ||
from numpy import sum | ||
import sys | ||
|
||
|
||
class Options: | ||
def __init__(self): | ||
self.type = '' | ||
self.ip = '' | ||
self.state = '' | ||
self.port = '' | ||
self.ippref = False | ||
self.protocol = '' | ||
self.ip_version = 0 # 0 == any | ||
self.des = '' | ||
|
||
def reset(self): | ||
self.type = '' | ||
self.ip = '' | ||
self.state = '' | ||
self.port = '' | ||
self.ippref = False | ||
self.protocol = '' | ||
self.ip_version = 0 | ||
self.des = '' | ||
|
||
|
||
# TODO: implement buffering for large files? | ||
def load(filename): | ||
df = pd.read_csv(filename, names=['Type', 'IPAddress', 'Port/info', 'State', 'description'], | ||
header=None, error_bad_lines=False) | ||
op = (df.State.values == 'open').sum() | ||
warnings = (df['description'].str.startswith('Warning')).sum() | ||
suspicious = (df.State.values == 'suspicious').sum() | ||
n = len(pd.unique(df['IPAddress'])) | ||
print(len(df), "records,", n, "distinct addresses,", op, "open ports", suspicious, "suspicious entries,", warnings, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider either returning these stats along with the dataframe or moving this analysis out to a separate function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this logic is repeated in |
||
"warnings") | ||
return df | ||
|
||
|
||
# shows every entry in the dataframe as a string. Output can be a lot... | ||
def show_all(dframe): | ||
pd.reset_option('max_columns') | ||
sys.stdout.flush() | ||
if len(dframe) == 0: # faster than the builtin .empty function | ||
print("Nothing to see here :)") | ||
return | ||
df_string = dframe.to_string(index=False) | ||
print(df_string) | ||
|
||
|
||
def show(dframe): | ||
if len(dframe) == 0: # faster than the builtin .empty function | ||
print("Nothing to see here :)") | ||
return | ||
|
||
warnings = (dframe['description'].str.startswith('Warning')).sum() | ||
suspicious = (dframe.State.values == 'suspicious').sum() | ||
n = len(pd.unique(dframe['IPAddress'])) | ||
print(len(dframe), "records,", n, "distinct addresses,", suspicious, "suspicious entries,", warnings, "warnings") | ||
|
||
print(dframe) | ||
|
||
|
||
def wraper_function(dframe, options): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider |
||
if options.state != '': | ||
dframe = dframe.loc[dframe['State'] == options.state] | ||
|
||
if options.port != '': | ||
dframe = dframe[dframe['Port/info'].str.contains(options.port, na=False)] | ||
|
||
if options.ip_version == 6: | ||
dframe = dframe[dframe['IPAddress'].str.contains(':', na=False)] | ||
elif options.ip_version == 4: | ||
dframe = dframe[~dframe['IPAddress'].str.contains(':', na=False)] | ||
|
||
if options.type != '': | ||
dframe = dframe[dframe['Type'] == (options.type.upper())] | ||
|
||
if options.ippref: | ||
dframe = dframe[dframe['IPAddress'].str.startswith(options.ip, na=False)] | ||
elif options.ip != '': | ||
dframe = dframe[dframe['IPAddress'] == options.ip] | ||
|
||
if options.des != '': | ||
dframe = dframe[dframe['description'].str.contains(options.des, na=False)] | ||
|
||
return dframe | ||
|
||
# TODO: add sorting and exporting | ||
if __name__ == '__main__': | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Passer analytics tool.') | ||
parser.add_argument('-i', '--logfile', help='file to ingest', required=True, default='', nargs=1) | ||
(parsed, unparsed) = parser.parse_known_args() | ||
cl_args = vars(parsed) | ||
df = load(cl_args['logfile'][0]) | ||
opts = Options() | ||
while True: | ||
command = (input('>')).lower() | ||
if command[:6] == 'filter': | ||
rol = (command[6:]).split() | ||
for item in rol: | ||
if item[:5] == 'type=': | ||
opts.type = (item[5:]).upper() | ||
if item[:5] == 'port=': | ||
opts.port = (item[5:]).upper() | ||
if item[:6] == 'state=': | ||
opts.state = item[6:] | ||
if item[:4] == 'ipv=': | ||
opts.ip_version = int(item[4:]) | ||
if item[:3] == 'ip=': | ||
opts.ip = item[3:] | ||
if item[:7] == 'ippref=': | ||
if item[7] == 't': | ||
opts.ippref = True | ||
else: | ||
opts.ippref = False | ||
if item[:12] == 'description=': | ||
opts.des = item[12:] | ||
elif command[:8] == 'show-all': | ||
ndf = wraper_function(df, opts) | ||
show_all(ndf) | ||
elif command[:4] == 'show': | ||
ndf = wraper_function(df, opts) | ||
show(ndf) | ||
elif command == 'reset': | ||
opts.reset() | ||
elif command == 'quit': | ||
exit(0) | ||
else: | ||
print("Unrecognised command") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import appears to be unused. Pandas
.sum
should call out to numpy internally.