-
Notifications
You must be signed in to change notification settings - Fork 174
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
payload.py #40
Open
jcldf
wants to merge
1
commit into
hak5:master
Choose a base branch
from
jcldf:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
payload.py #40
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
legacy-mk1/payloads/library/recon/arp_sniffer_payload/payload.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Author: Julio Della Flora | ||
Title: arp_sniffer_payload | ||
Description: | ||
This payload captures ARP packets to identify devices on the local network. | ||
It logs each unique source MAC and IP address pair to a file. | ||
|
||
Target: | ||
Local network interfaces capable of capturing ARP packets. | ||
|
||
Dependencies: | ||
- Python 2.7 or 3.x | ||
- Access to network interface in promiscuous mode. | ||
|
||
Configurable Options: | ||
LOG_FILE_NAME = 'arp_sniffer.log' # Name of the log file | ||
INTERFACE = 'eth0' # Interface to sniff on | ||
""" | ||
|
||
import socket | ||
import struct | ||
import logging | ||
|
||
# Configurable variables | ||
LOG_FILE_NAME = 'arp_sniffer.log' | ||
INTERFACE = 'eth0' | ||
|
||
def mac_addr(mac_string): | ||
"""Convert a MAC address string into a readable format.""" | ||
return ':'.join('%02x' % (ord(b)) for b in mac_string) | ||
|
||
def ipv4_addr(addr): | ||
"""Convert an IPv4 address string into a readable format.""" | ||
return '.'.join(map(str, struct.unpack('!BBBB', addr))) | ||
|
||
def sniff(): | ||
# Setup logging | ||
logging.basicConfig(filename=LOG_FILE_NAME, level=logging.INFO, format='%(asctime)s %(message)s') | ||
|
||
# Create a raw socket to capture ARP packets | ||
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0003)) | ||
|
||
# Set to store seen MAC and IP address pairs | ||
seen_addresses = set() | ||
|
||
while True: | ||
# Receive packet | ||
raw_data, addr = s.recvfrom(65535) | ||
# Unpack ethernet frame | ||
dest_mac, src_mac, eth_proto = struct.unpack('! 6s 6s H', raw_data[:14]) | ||
|
||
# Check for ARP packet | ||
if eth_proto == 0x0806: | ||
# Unpack ARP packet | ||
arp_header = raw_data[14:42] | ||
arp_data = struct.unpack('! H H 1s 1s 2s 6s 4s 6s 4s', arp_header) | ||
|
||
# Check if ARP packet is request or reply | ||
if arp_data[4] == b'\x00\x01' or arp_data[4] == b'\x00\x02': | ||
src_mac_str = mac_addr(src_mac) | ||
src_ip_str = ipv4_addr(arp_data[6]) | ||
|
||
# Check for new address pair | ||
if (src_mac_str, src_ip_str) not in seen_addresses: | ||
seen_addresses.add((src_mac_str, src_ip_str)) | ||
log_message = "Source MAC: {}, Source IP: {}".format(src_mac_str, src_ip_str) | ||
print(log_message) | ||
logging.info(log_message) | ||
|
||
# Start sniffing | ||
sniff() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Apologizes for the delay in reviewing this PR. Could you please include a simple
readme.md
that includes the description you currently have in your payload? as well as a simple overview of the configurable options.