Skip to content

Commit

Permalink
not working, post disrupt cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
swainsubrat committed Feb 29, 2024
1 parent 84e7175 commit 9a5abd8
Show file tree
Hide file tree
Showing 56 changed files with 2,367 additions and 1,813 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
ignore = E501, W503, E203
[flake8]
ignore = E501, W503, E203
102 changes: 51 additions & 51 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
# - id: check-yaml
- id: check-added-large-files
args: ['--maxkb=50000'] # Limit to files up to 50 megabytes
- id: debug-statements

- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --remove-unused-variables, --in-place,
--expand-star-imports, --remove-duplicate-keys, --recursive,
--exclude=__init__.py]

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
language_version: python3

- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py38-plus]

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
files: ^src/
args: []

- repo: https://github.com/psf/black
rev: 23.12.0
hooks:
- id: black
args: [--safe]
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
# - id: check-yaml
- id: check-added-large-files
args: ['--maxkb=50000'] # Limit to files up to 50 megabytes
- id: debug-statements

- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --remove-unused-variables, --in-place,
--expand-star-imports, --remove-duplicate-keys, --recursive,
--exclude=__init__.py]

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
language_version: python3

- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=.:src', --py38-plus]

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
files: ^src/
args: []

- repo: https://github.com/psf/black
rev: 23.12.0
hooks:
- id: black
args: [--safe]
Binary file added artifacts/.DS_Store
Binary file not shown.
Binary file added artifacts/models/.DS_Store
Binary file not shown.
Binary file modified artifacts/models/Autoencoder/model.pth
Binary file not shown.
Binary file modified artifacts/models/AutoencoderRaw/model.pth
Binary file not shown.
Binary file added artifacts/models/KitsuneAutoencoder/model.pth
Binary file not shown.
Binary file modified artifacts/objects/anomaly_detectors/autoencoder/anomaly_scores
Binary file not shown.
Binary file modified artifacts/objects/anomaly_detectors/autoencoder/y_pred
Binary file not shown.
Binary file modified artifacts/objects/anomaly_detectors/autoencoder/y_true
Binary file not shown.
Binary file modified artifacts/objects/attacks/loopback_pgd/adv_sizes
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified artifacts/plots/Port_Scanning_SmartTV_loopback_pgd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified artifacts/plots/Port_Scanning_SmartTV_pgd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/Port_Scanning_SmartTV_re.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified artifacts/plots/Service_Detection_Smartphone_1_fgsm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/image_perturbations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/mask_cropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/packet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/perturbed_packet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/plots/weekday_06_re.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 37 additions & 9 deletions code/attack_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import torch.nn as nn
from attacks import Attack

from utils import save

def update_timestamps(pcap_file, inter_arrival_times, adv_pcap_path):
"""
Expand All @@ -28,8 +27,19 @@ def update_timestamps(pcap_file, inter_arrival_times, adv_pcap_path):

packet.time = new_timestamp

packets.sort(key=lambda packet: packet.time)

increment = 0.0001
for i in range(1, len(packets)):
if packets[i].time <= packets[i - 1].time:
packets[i].time = packets[i].time + increment
increment += 0.0001
else:
increment = 0.0001

scapy.wrpcap(adv_pcap_path, packets)


def update_timestamps_raw(pcap_file, adv_timestamps, adv_pcap_path):
"""
Updates the timestamps of the packets in the pcap file
Expand All @@ -46,9 +56,11 @@ def update_timestamps_raw(pcap_file, adv_timestamps, adv_pcap_path):
if packet.time == adv_timestamps[i]:
same += 1
packet.time = adv_timestamps[i]

print("Number of same timestamps:", same, "out of", i)
print("Updated timestamp of 5th packet:", packets[5].time)

packets.sort(key=lambda packet: packet.time)
scapy.wrpcap(adv_pcap_path, packets)


Expand Down Expand Up @@ -84,7 +96,9 @@ def get_args_parser():
type=str,
help="Name of the attack to perform or inference",
)
parser.add_argument("--selected-columns", nargs="+", default=list(range(32)), type=list)
parser.add_argument(
"--selected-columns", nargs="+", default=list(range(32)), type=list
)
parser.add_argument(
"--eval", action="store_true", default=False, help="perform attack inference"
)
Expand All @@ -100,18 +114,33 @@ def main(args):
args.adv_pcap_path = (
f"../data/adversarial/{args.attack}/Adv_{args.pcap_path.split('/')[-1]}"
)

attack = Attack(args=args)
attack_method = getattr(attack, args.attack)
re, adv_re, y_true, y_pred, taus, adv_timestamps, adv_sizes, actual_sizes = attack_method(epsilon=0.05)

# below line is for loopback
(
re,
adv_re,
y_true,
y_pred,
taus,
adv_timestamps,
adv_sizes,
actual_sizes,
) = attack_method(epsilon=0.5)

# below line is for others
re, adv_re, y_true, y_pred, taus = attack_method(epsilon=0.3)

print(f"Pcap file: {args.pcap_path.split('/')[-1][:-5]}")
print(f"Mean RE for malicious packets: {sum(re)/ len(re)}")
print(f"Mean RE for adversarial malicious packets: {sum(adv_re)/ len(adv_re)}")

save(
path="../artifacts/objects/attacks/loopback_pgd/adv_sizes",
params={"adv_sizes": adv_sizes},
)
# save(
# path="../artifacts/objects/attacks/loopback_pgd/adv_sizes",
# params={"adv_sizes": adv_sizes},
# )

evasion_rate = 1 - (sum(y_pred) / len(y_pred))
print(f"Evasion Rate: {evasion_rate}")
Expand All @@ -129,7 +158,6 @@ def main(args):
# Generate x-axis values (image indices)
image_indices = np.arange(len(re))


# Create a line curve (line plot)
plt.figure(figsize=(10, 6))
plt.plot(
Expand Down
Loading

0 comments on commit 9a5abd8

Please sign in to comment.