-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc1571e
commit 5f1bce2
Showing
5 changed files
with
196 additions
and
34 deletions.
There are no files selected for viewing
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,31 @@ | ||
name: Deploy | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
|
||
steps: | ||
|
||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
|
||
- name: Build and Publish Python Packages | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
python setup.py sdist | ||
twine upload dist/* |
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 |
---|---|---|
@@ -1 +1,27 @@ | ||
# pywall | ||
# pywall | ||
Python firewall framework. | ||
# Install | ||
``` | ||
pip3 install pywall | ||
``` | ||
# Using | ||
## In another script | ||
```python | ||
from pywall import pywall | ||
# pywall(iface="wlan0") | ||
safe = pywall(iface="wlan0").control() | ||
``` | ||
## In command line | ||
```console | ||
pywall | ||
``` | ||
```console | ||
usage: pywall [-h] [-i IFACE] [-t TIMEOUT] | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
-i IFACE, --iface IFACE | ||
Interface | ||
-t TIMEOUT, --timeout TIMEOUT | ||
Timeout | ||
``` |
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,60 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
|
||
from setuptools import setup | ||
|
||
|
||
setup( | ||
name='pywall', | ||
version='0.1.0', | ||
description="""Python firewall framework.""", | ||
long_description=""" | ||
# pywall | ||
Python firewall framework. | ||
# Install | ||
``` | ||
pip3 install pywall | ||
``` | ||
# Using | ||
## In another script | ||
```python | ||
from pywall import pywall | ||
# pywall(iface="wlan0") | ||
safe = pywall(iface="wlan0").control() | ||
``` | ||
## In command line | ||
```console | ||
pywall | ||
``` | ||
```console | ||
usage: pywall [-h] [-i IFACE] [-t TIMEOUT] | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-i IFACE, --iface IFACE | ||
Interface | ||
-t TIMEOUT, --timeout TIMEOUT | ||
Timeout | ||
``` | ||
""", | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/Decentra-Network/pywall', | ||
author='Decentra Network Developers', | ||
author_email='[email protected]', | ||
license='MIT', | ||
packages=["pywall"], | ||
package_dir={'':'src'}, | ||
install_requires=[ | ||
"scapy==2.4.5" | ||
], | ||
entry_points = { | ||
'console_scripts': ['pywall=pywall.pywall:arguments'], | ||
}, | ||
python_requires=">=3.8", | ||
zip_safe=False | ||
) |
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 @@ | ||
from .pywall import pywall |
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 |
---|---|---|
@@ -1,49 +1,93 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
|
||
from scapy.all import srp, ARP, Ether, sniff | ||
import argparse | ||
import time | ||
|
||
|
||
def get_mac_address(target): | ||
""" | ||
Get mac address of target | ||
""" | ||
print("in get mac adress function") | ||
print(target) | ||
result = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=target), timeout=3, verbose=0)[0] | ||
print(result) | ||
result = [received.hwsrc for sent, received in result] | ||
class pywall: | ||
|
||
def __init__(self, iface="wlan0", timeout=15): | ||
self.iface = iface | ||
self.timeout = timeout | ||
|
||
def arp_spoofing_detection(iface): | ||
""" | ||
Detect arp spoofing | ||
""" | ||
|
||
|
||
global arp_spoofing_detected | ||
arp_spoofing_detected = None | ||
def get_mac_address(self, target): | ||
""" | ||
Get mac address of target | ||
""" | ||
result = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=target), timeout=3, verbose=0)[0] | ||
result = [received.hwsrc for sent, received in result] | ||
|
||
def control(packet): | ||
global arp_spoofing_detected | ||
if arp_spoofing_detected is not None: | ||
return True | ||
else: | ||
return False | ||
|
||
def arp_spoofing_detection(self): | ||
""" | ||
Detect arp spoofing | ||
""" | ||
|
||
def process_sniffed_packet(packet): | ||
global arp_spoofing_detected | ||
if packet.haslayer(ARP) and packet[ARP].op == 2: | ||
real_mac = get_mac_address(packet[ARP].psrc) | ||
print(real_mac) | ||
response_mac = packet[ARP].hwsrc | ||
print(response_mac) | ||
if real_mac != response_mac: | ||
arp_spoofing_detected = True | ||
arp_spoofing_detected = None | ||
|
||
def control(packet): | ||
global arp_spoofing_detected | ||
if arp_spoofing_detected is not None: | ||
return True | ||
else: | ||
arp_spoofing_detected = False | ||
return False | ||
|
||
|
||
def process_sniffed_packet(packet): | ||
global arp_spoofing_detected | ||
if packet.haslayer(ARP) and packet[ARP].op == 2: | ||
real_mac = self.get_mac_address(packet[ARP].psrc) | ||
response_mac = packet[ARP].hwsrc | ||
if real_mac != response_mac: | ||
arp_spoofing_detected = True | ||
else: | ||
arp_spoofing_detected = False | ||
|
||
|
||
sniff(iface=self.iface, store=False, stop_filter=control, prn=process_sniffed_packet, timeout=self.timeout) | ||
|
||
|
||
return arp_spoofing_detected | ||
|
||
|
||
def control(self): | ||
""" | ||
Main function | ||
""" | ||
|
||
return self.arp_spoofing_detection() | ||
|
||
def arguments(): | ||
""" | ||
Main function | ||
""" | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-i', '--iface', type=str, help='Interface') | ||
parser.add_argument('-t', '--timeout', type=int, help='Timeout') | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
the_pywall = pywall() | ||
|
||
if args.iface is not None: | ||
the_pywall.iface = args.iface | ||
if args.timeout is not None: | ||
the_pywall.timeout = args.timeout | ||
|
||
sniff(iface=iface, store=False, stop_filter=control, prn=process_sniffed_packet) | ||
print(the_pywall.control()) | ||
|
||
|
||
if __name__ == "__main__": | ||
arp_spoofing_detection("Ethernet") | ||
print(arp_spoofing_detected) | ||
print(pywall().control()) |