mirror of
https://github.com/BishopFox/eyeballer.git
synced 2026-11-08 08:04:00 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbb480e43f |
No files matched your search
@@ -118,5 +118,3 @@ results.html
|
||||
!requirements-gpu.txt
|
||||
!tests/models/*
|
||||
!tests/data/*
|
||||
!docs/*
|
||||
logs/*
|
||||
@@ -1,44 +1,8 @@
|
||||
# Eyeballer
|
||||
|
||||

|
||||
|
||||
|
||||
Give those screenshots of yours a quick eyeballing.
|
||||
|
||||
Eyeballer is meant for large-scope network penetration tests where you need to find "interesting" targets from a huge set of web-based hosts. Go ahead and use your favorite screenshotting tool like normal (EyeWitness or GoWitness) and then run them through Eyeballer to tell you what's likely to contain vulnerabilities, and what isn't.
|
||||
|
||||
|
||||
### Example Labels
|
||||
|
||||
| Old-Looking Sites | Login Pages |
|
||||
| ------ |:-----:|
|
||||
|  |  |
|
||||
|
||||
| Webapp | Custom 404's |
|
||||
| ------ |:-----:|
|
||||
|  |  |
|
||||
|
||||
| Parked Domains |
|
||||
| ------ |
|
||||
|  |
|
||||
|
||||
## What the Labels Mean
|
||||
|
||||
**Old-Looking Sites**
|
||||
Blocky frames, broken CSS, that certain "je ne sais quoi" of a website that looks like it was designed in the early 2000's. You know it when you see it. Old websites aren't just ugly, they're also typically super vulnerable. When you're looking to hack into something, these websites are a gold mine.
|
||||
|
||||
**Login Pages**
|
||||
Login pages are valuable to pen testing, they indicate that there's additional functionality you don't currently have access to. It also means there's a simple follow-up process of credential enumeration attacks. You might think that you can set a simple heuristic to find login pages, but in practice it's really hard. Modern sites don't just use a simple input tag we can grep for.
|
||||
|
||||
**Webapp**
|
||||
This tells you that there is a larger group of pages and functionality available here that can serve as surface area to attack. This is in contrast to a simple login page, with no other functionality. Or a default IIS landing page which has no other functionality. This label should indicate to you that there is a web application here to attack.
|
||||
|
||||
**Custom 404**
|
||||
Modern sites love to have cutesy custom 404 pages with pictures of broken robots or sad looking dogs. Unfortunately, they also love to return HTTP 200 response codes while they do it. More often, the "404" page doesn't even contain the text "404" in it. These pages are typically uninteresting, despite having a lot going on visually, and Eyeballer can help you sift them out.
|
||||
|
||||
**Parked Domains**
|
||||
Parked domains are websites that look real, but aren't valid attack surface. They're stand-in pages, usually devoid of any real functionality, consist almost entirely of ads, and are usually not run by our actual target. It's what you get when the domain specified is wrong or lapsed. Finding these pages and removing them from scope is really valuable over time.
|
||||
|
||||
## Setup
|
||||
|
||||
Download required packages on pip:
|
||||
@@ -51,28 +15,7 @@ Or if you want GPU support:
|
||||
sudo pip3 install -r requirements-gpu.txt
|
||||
```
|
||||
|
||||
**NOTE**: Setting up a GPU for use with TensorFlow is way beyond the scope of this README. There's hardware compatibility to consider, drivers to install... There's a lot. So you're just going to have to figure this part out on your own if you want a GPU. But at least from a Python package perspective, the above requirements file has you covered.
|
||||
|
||||
**Pretrained Weights**
|
||||
|
||||
For the latest pretrained weights, check out the releases here on GitHub.
|
||||
|
||||
**Training Data** You can find our training data here:
|
||||
|
||||
https://www.dropbox.com/s/rpylhiv2g0kokts/eyeballer-3.0.zip?dl=1
|
||||
|
||||
There's two things you need from the training data:
|
||||
|
||||
1. `images/` folder, containing all the screenshots (resized down to 224x224)
|
||||
2. `labels.csv` that has all the labels
|
||||
3. `bishop-fox-pretrained-v2.h5` A pretrained weights file you can use right out of the box without training.
|
||||
|
||||
Copy all three into the root of the Eyeballer code tree.
|
||||
|
||||
## Predicting Labels
|
||||
|
||||
NOTE: For best results, make sure you screenshot your websites in a native 1.6x aspect ratio. IE: 1440x900. Eyeballer will scale the image down automatically to the right size for you, but if it's the wrong aspect ratio then it will squish in a way that will affect prediction performance.
|
||||
|
||||
To eyeball some screenshots, just run the "predict" mode:
|
||||
|
||||
```
|
||||
@@ -85,9 +28,6 @@ Or for a whole directory of files:
|
||||
eyeballer.py --weights YOUR_WEIGHTS.h5 predict PATH_TO/YOUR_FILES/
|
||||
```
|
||||
|
||||
Eyeballer will spit the results back to you in human readable format (a `results.html` file so you can browse it easily) and machine readable format (a `results.csv` file).
|
||||
|
||||
|
||||
## Training
|
||||
To train a new model, run:
|
||||
```
|
||||
@@ -105,5 +45,3 @@ You just trained a new model, cool! Let's see how well it performs against some
|
||||
```
|
||||
eyeballer.py --weights YOUR_WEIGHTS.h5 evaluate
|
||||
```
|
||||
|
||||
The output will describe the model's accuracy in both recall and precision for each of the program's labels. (Including "none of the above" as a pseudo-label)
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 56 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 68 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB |
+1
-1
@@ -54,7 +54,7 @@ def predict(ctx, screenshot, heatmap, threshold):
|
||||
print(results)
|
||||
else:
|
||||
with open("results.csv", "w", newline="") as csvfile:
|
||||
fieldnames = ["filename", "custom404", "login", "webapp", "oldlooking", "parked"]
|
||||
fieldnames = ["filename", "custom404", "login", "homepage", "oldlooking"]
|
||||
labelwriter = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
labelwriter.writeheader()
|
||||
labelwriter.writerows(results)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
|
||||
from Augmentor.Operations import Operation
|
||||
from tensorflow.keras.applications.mobilenet import preprocess_input
|
||||
from keras.applications.mobilenet import preprocess_input
|
||||
|
||||
|
||||
class EyeballerAugmentation(Operation):
|
||||
|
||||
+40
-54
@@ -17,7 +17,7 @@ from tensorflow.keras.applications.mobilenet import preprocess_input
|
||||
from sklearn.metrics import classification_report, accuracy_score, hamming_loss
|
||||
from eyeballer.augmentation import EyeballerAugmentation
|
||||
|
||||
DATA_LABELS = ["custom404", "login", "webapp", "oldlooking", "parked"]
|
||||
DATA_LABELS = ["custom404", "login", "homepage", "oldlooking"]
|
||||
|
||||
|
||||
class EyeballModel:
|
||||
@@ -31,7 +31,7 @@ class EyeballModel:
|
||||
image_width, image_height = 224, 224
|
||||
input_shape = (image_width, image_height, 3)
|
||||
|
||||
def __init__(self, weights_file, print_summary=False, seed=None, quiet=False):
|
||||
def __init__(self, weights_file, print_summary=False, seed=None):
|
||||
"""Constructor for model class.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -54,6 +54,28 @@ class EyeballModel:
|
||||
loss="binary_crossentropy",
|
||||
metrics=["accuracy"])
|
||||
|
||||
# for layer in pretrained_layer.layers:
|
||||
# layer.trainable = False
|
||||
|
||||
if print_summary:
|
||||
print(self.model.summary())
|
||||
|
||||
# Pull out our labels for use in generators later
|
||||
data = pd.read_csv("labels.csv")
|
||||
self.training_labels = data.loc[data['evaluation'] == False] # noqa: E712
|
||||
self.evaluation_labels = data.loc[data['evaluation'] == True] # noqa: E712
|
||||
|
||||
# Shuffle the training labels
|
||||
self.random_seed = False
|
||||
self.seed = seed
|
||||
if self.seed is None:
|
||||
self.random_seed = True
|
||||
self.seed = random.randint(0, 999999)
|
||||
print("No seed set, ", end='')
|
||||
print("using seed: {}".format(self.seed))
|
||||
random.seed(self.seed)
|
||||
self.training_labels = self.training_labels.sample(frac=1)
|
||||
|
||||
if weights_file is not None and os.path.isfile(weights_file):
|
||||
try:
|
||||
self.model.load_weights(weights_file)
|
||||
@@ -66,28 +88,6 @@ class EyeballModel:
|
||||
raise FileNotFoundError
|
||||
print("WARN: No model loaded from file. Generating random model")
|
||||
|
||||
if print_summary:
|
||||
print(self.model.summary())
|
||||
|
||||
self.quiet = quiet
|
||||
self.seed = seed
|
||||
|
||||
def _init_labels(self):
|
||||
# Pull out our labels for use in generators later
|
||||
data = pd.read_csv("labels.csv")
|
||||
self.training_labels = data.loc[data['evaluation'] == False] # noqa: E712
|
||||
self.evaluation_labels = data.loc[data['evaluation'] == True] # noqa: E712
|
||||
|
||||
# Shuffle the training labels
|
||||
self.random_seed = False
|
||||
if self.seed is None:
|
||||
self.random_seed = True
|
||||
self.seed = random.randint(0, 999999)
|
||||
print("No seed set, ", end='')
|
||||
print("using seed: {}".format(self.seed))
|
||||
random.seed(self.seed)
|
||||
self.training_labels = self.training_labels.sample(frac=1)
|
||||
|
||||
# Data augmentation
|
||||
augmentor = Augmentor.Pipeline()
|
||||
augmentor.set_seed(self.seed)
|
||||
@@ -112,7 +112,6 @@ class EyeballModel:
|
||||
"""
|
||||
print("Training with seed: " + str(self.seed))
|
||||
|
||||
self._init_labels()
|
||||
data_generator = tf.keras.preprocessing.image.ImageDataGenerator(
|
||||
preprocessing_function=self.preprocess_training_function,
|
||||
validation_split=0.2,
|
||||
@@ -128,7 +127,7 @@ class EyeballModel:
|
||||
subset='training',
|
||||
shuffle=True,
|
||||
seed=self.seed,
|
||||
class_mode="raw")
|
||||
class_mode="other")
|
||||
validation_generator = data_generator.flow_from_dataframe(
|
||||
self.training_labels,
|
||||
directory=self.image_dir,
|
||||
@@ -139,26 +138,17 @@ class EyeballModel:
|
||||
subset='validation',
|
||||
shuffle=False,
|
||||
seed=self.seed,
|
||||
class_mode="raw")
|
||||
class_mode="other")
|
||||
|
||||
# Model checkpoint - Saves model weights when validation accuracy improves
|
||||
callbacks = [tf.keras.callbacks.ModelCheckpoint(self.checkpoint_file,
|
||||
monitor='val_loss',
|
||||
verbose=1,
|
||||
save_best_only=True,
|
||||
save_weights_only=True,
|
||||
mode='min'),
|
||||
tf.keras.callbacks.TensorBoard(log_dir='logs',
|
||||
histogram_freq=2,
|
||||
write_graph=True,
|
||||
write_images=False,
|
||||
update_freq='epoch',
|
||||
profile_batch=2,
|
||||
embeddings_freq=0,
|
||||
embeddings_metadata=None),
|
||||
]
|
||||
monitor='val_loss',
|
||||
verbose=1,
|
||||
save_best_only=True,
|
||||
save_weights_only=True,
|
||||
mode='min')]
|
||||
|
||||
history = self.model.fit(
|
||||
history = self.model.fit_generator(
|
||||
training_generator,
|
||||
steps_per_epoch=len(training_generator.filenames) // batch_size,
|
||||
epochs=epochs,
|
||||
@@ -205,9 +195,8 @@ class EyeballModel:
|
||||
result["filename"] = "custom-image"
|
||||
result["custom404"] = prediction[0][0]
|
||||
result["login"] = prediction[0][1]
|
||||
result["webapp"] = prediction[0][2]
|
||||
result["homepage"] = prediction[0][2]
|
||||
result["oldlooking"] = prediction[0][3]
|
||||
result["parked"] = prediction[0][4]
|
||||
return result
|
||||
|
||||
def predict(self, path, threshold=0.5):
|
||||
@@ -227,10 +216,8 @@ class EyeballModel:
|
||||
raise FileNotFoundError
|
||||
|
||||
results = []
|
||||
bar = progressbar.ProgressBar()
|
||||
if self.quiet:
|
||||
bar = progressbar.NullBar()
|
||||
for screenshot in bar(screenshots):
|
||||
pbar = progressbar.ProgressBar()
|
||||
for screenshot in pbar(screenshots):
|
||||
# Load the image into memory
|
||||
img = None
|
||||
try:
|
||||
@@ -250,9 +237,8 @@ class EyeballModel:
|
||||
result["filename"] = screenshot
|
||||
result["custom404"] = prediction[0][0]
|
||||
result["login"] = prediction[0][1]
|
||||
result["webapp"] = prediction[0][2]
|
||||
result["homepage"] = prediction[0][2]
|
||||
result["oldlooking"] = prediction[0][3]
|
||||
result["parked"] = prediction[0][4]
|
||||
results.append(result)
|
||||
return results
|
||||
|
||||
@@ -263,7 +249,6 @@ class EyeballModel:
|
||||
threshold -- Value between 0->1. The cutoff where the numerical prediction becomes boolean. Default: 0.5
|
||||
"""
|
||||
# Prepare the data
|
||||
self._init_labels()
|
||||
data_generator = tf.keras.preprocessing.image.ImageDataGenerator(
|
||||
preprocessing_function=preprocess_input)
|
||||
evaluation_generator = data_generator.flow_from_dataframe(
|
||||
@@ -274,7 +259,7 @@ class EyeballModel:
|
||||
target_size=(self.image_width, self.image_height),
|
||||
shuffle=False,
|
||||
batch_size=1,
|
||||
class_mode="raw")
|
||||
class_mode="other")
|
||||
# If a seed was selected, then also evaluate on the validation set for that seed
|
||||
if not self.random_seed:
|
||||
print("Using validation set...")
|
||||
@@ -293,16 +278,17 @@ class EyeballModel:
|
||||
subset='validation',
|
||||
shuffle=False,
|
||||
seed=self.seed,
|
||||
class_mode="raw")
|
||||
class_mode="other")
|
||||
else:
|
||||
print("Using evaluation set...")
|
||||
|
||||
predictions = self.model.predict(
|
||||
predictions = self.model.predict_generator(
|
||||
evaluation_generator,
|
||||
verbose=1,
|
||||
steps=len(evaluation_generator))
|
||||
|
||||
self._save_prediction_histograms(predictions)
|
||||
print("predictions: ", type(predictions))
|
||||
predictions = predictions > threshold
|
||||
ground_truth = self.evaluation_labels[DATA_LABELS].to_numpy()
|
||||
filenames = self.evaluation_labels[["filename"]].to_numpy()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import numpy as np
|
||||
import math
|
||||
import tensorflow as tf
|
||||
|
||||
from keras.preprocessing import image
|
||||
from copy import deepcopy
|
||||
from matplotlib import pyplot as plt
|
||||
from eyeballer.model import DATA_LABELS
|
||||
@@ -11,8 +10,8 @@ class HeatMap():
|
||||
def __init__(self, screenshot_path, model, threshold=0.5, boxsize=28, step=7):
|
||||
self.model = model
|
||||
|
||||
img = tf.keras.preprocessing.image.load_img(screenshot_path, target_size=(self.model.image_width, self.model.image_height))
|
||||
img = tf.keras.preprocessing.image.img_to_array(img)
|
||||
img = image.load_img(screenshot_path, target_size=(self.model.image_width, self.model.image_height))
|
||||
img = image.img_to_array(img)
|
||||
|
||||
self.screenshot = img
|
||||
self.boxsize = boxsize
|
||||
@@ -44,7 +43,7 @@ class HeatMap():
|
||||
labels.append(label)
|
||||
|
||||
plt.figure()
|
||||
screenshot_image = tf.keras.preprocessing.image.load_img(self.screenshot_path, target_size=(self.model.image_width, self.model.image_width))
|
||||
screenshot_image = image.load_img(self.screenshot_path, target_size=(self.model.image_width, self.model.image_width))
|
||||
_, subplots = plt.subplots(1, len(heatmaps))
|
||||
# This is a little janky, but matplotlib returns a list above if there's multiple subplots, and just a single subplot if there's only one
|
||||
# it would have been easier if it was always a list. But alas
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
<button class="btn all" onclick="filterSelection('all')"> Show all</button>
|
||||
<button class="btn" onclick="filterSelection('custom404')"> 404</button>
|
||||
<button class="btn" onclick="filterSelection('login')"> Login</button>
|
||||
<button class="btn" onclick="filterSelection('webapp')"> Web Application</button>
|
||||
<button class="btn" onclick="filterSelection('homepage')"> Home Page</button>
|
||||
<button class="btn" onclick="filterSelection('oldlooking')"> Old Looking</button>
|
||||
<button class="btn" onclick="filterSelection('parked')"> Parked Domain</button>
|
||||
<select onchange="numOnPage=this.value; filterSelection([]);" style="float:right; margin:5px; margin-right:30px; height:30px; width:auto;">
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
|
||||
@@ -5,6 +5,6 @@ numpy
|
||||
pandas
|
||||
pillow
|
||||
sklearn
|
||||
tensorflow-gpu
|
||||
tensorflow-gpu==2.0.0-beta0
|
||||
jinja2
|
||||
progressbar2
|
||||
+1
-1
@@ -5,6 +5,6 @@ numpy
|
||||
pandas
|
||||
pillow
|
||||
sklearn
|
||||
tensorflow
|
||||
tensorflow==2.0.0-beta0
|
||||
jinja2
|
||||
progressbar2
|
||||
@@ -0,0 +1 @@
|
||||
#TODO
|
||||
+3
-17
@@ -4,7 +4,6 @@ import unittest
|
||||
import sys
|
||||
|
||||
from eyeballer.model import EyeballModel
|
||||
from eyeballer.visualization import HeatMap
|
||||
|
||||
|
||||
class PredictTest(unittest.TestCase):
|
||||
@@ -26,8 +25,7 @@ class PredictTest(unittest.TestCase):
|
||||
model_kwargs = {
|
||||
"weights_file": weights_file,
|
||||
"print_summary": False,
|
||||
"seed": None,
|
||||
"quiet": True
|
||||
"seed": None
|
||||
}
|
||||
self.model = EyeballModel(**model_kwargs)
|
||||
|
||||
@@ -35,8 +33,7 @@ class PredictTest(unittest.TestCase):
|
||||
model_kwargs = {
|
||||
"weights_file": None,
|
||||
"print_summary": False,
|
||||
"seed": 12345678,
|
||||
"quiet": True
|
||||
"seed": 12345678
|
||||
}
|
||||
same_seed_model = EyeballModel(**model_kwargs)
|
||||
|
||||
@@ -51,8 +48,7 @@ class PredictTest(unittest.TestCase):
|
||||
model_kwargs = {
|
||||
"weights_file": None,
|
||||
"print_summary": False,
|
||||
"seed": 12345678,
|
||||
"quiet": True
|
||||
"seed": 12345678
|
||||
}
|
||||
same_seed_model = EyeballModel(**model_kwargs)
|
||||
|
||||
@@ -130,13 +126,3 @@ class PredictTest(unittest.TestCase):
|
||||
"""
|
||||
screenshot = "tests/data/invalid.png"
|
||||
self.model.predict(screenshot)
|
||||
|
||||
def test_heatmap(self):
|
||||
screenshot = "tests/data/login.png"
|
||||
HeatMap(screenshot, self.model, 0.5)
|
||||
|
||||
screenshot = "tests/data/404.png"
|
||||
HeatMap(screenshot, self.model, 0.5)
|
||||
|
||||
screenshot = "tests/data/empty.png"
|
||||
HeatMap(screenshot, self.model, 0.5)
|
||||
@@ -0,0 +1 @@
|
||||
#TODO
|
||||
+1
-1
@@ -1 +1 @@
|
||||
from tests.PredictTest import * # noqa
|
||||
from tests.PredictTest import *
|
||||
+2
-3
@@ -1,8 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Converts full-size images to a given size (replacing the originals)
|
||||
for f in images/*
|
||||
for f in images_full_size/*
|
||||
do
|
||||
echo $f
|
||||
convert -resize 224x224\! $f $f
|
||||
convert -resize 224x224 $f $f
|
||||
done
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import csv
|
||||
import random
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
||||
with open("labels.csv", newline="") as csvfile:
|
||||
# Get the header labels
|
||||
csvreader = csv.DictReader(csvfile)
|
||||
# fieldnames = next(csvreader)
|
||||
file_list = [f for f in listdir("images") if isfile(join("images", f))]
|
||||
|
||||
label_list = []
|
||||
for row in csvreader:
|
||||
label_list.append(row["filename"])
|
||||
|
||||
# Loop through the file
|
||||
print("Rows in labels.csv, but no image exists:")
|
||||
for label in label_list:
|
||||
if label not in file_list:
|
||||
print(row["filename"])
|
||||
|
||||
print("Images that exist, but don't have labels:")
|
||||
i = 0
|
||||
for image in file_list:
|
||||
if image not in label_list:
|
||||
print(image)
|
||||
Reference in new issue
Block a user