-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from rafael-santiago/pybind
Implement macgonuts_pybind
- Loading branch information
Showing
12 changed files
with
394 additions
and
24 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 |
---|---|---|
|
@@ -9,3 +9,6 @@ | |
*.Forgefile-* | ||
*.o/ | ||
coverage.info | ||
**/binds/py/*.so | ||
**/binds/py/macgonuts.c | ||
**/binds/py/build |
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,86 @@ | ||
# Macgonuts binds | ||
|
||
**Abstract**: This document is intended to explain how to use the available `macgonuts` binds. | ||
Details about how to build is not discussed here, take a look at `doc/BUILD.md`. | ||
|
||
## Topics | ||
|
||
- [What is available until now](#what-is-available-until-now) | ||
- [Using `macgonuts_pybind`](#using-macgonuts_pybind) | ||
|
||
## What is available until now | ||
|
||
Currently it is only available two function that acts as basic building blocks for managing | ||
spoofing attacks. | ||
|
||
Those two function are: | ||
|
||
- `macgonuts_spoof()` | ||
- `macgonuts_undo_spoof()` | ||
|
||
By using those two functions through the binds, you will be able to easily implement the | ||
spoof stuff at your own program natively without depeding on `macgonuts` command line tool. | ||
|
||
Until now `macgonuts` features binds for `Python`. | ||
|
||
[``Back``](#topics) | ||
|
||
## Using `macgonuts_pybind` | ||
|
||
Once it build and well-installed, it is fairly simple to use `macgonuts_pyind` module. | ||
The functions present in this module are: | ||
|
||
- `macgonuts_spoof()` | ||
- `macgonuts_undo_spoof()` | ||
|
||
The `macgonuts_spoof()` function can receive five arguments: | ||
|
||
- `lo_iface` is the name of the interface you are accessing the network. | ||
- `target_addr` is the network address of the target, it can be a `IPv4` or `IPv6` address. | ||
- `addr2spoof` is the address that will be spoofed at target, it can be a `IPv4` or `IPv6` address. | ||
- `fake_pkts_amount` is the total of spoofed packets sent to target, it defaults to one. | ||
- `timeout` is the timeout in `mss` between a spoofed packet and the next, it defauts to no timeout. | ||
|
||
The `macgonuts_undo_spoof()` undoes a previous promoted spoof attack against a specific target. | ||
This function expects three arguments: | ||
|
||
- `lo_iface` is the name of the interface you are accessing the network. | ||
- `target_addr` is the network address of the target, it can be a `IPv4` or `IPv6` address. | ||
- `addr2spoof` is the address that was spoofed at target, it can be a `IPv4` or `IPv6` address. | ||
|
||
Follows the general idea when using `macgonuts` spoofing primitives from `Python`: | ||
|
||
```python | ||
import macgonuts_pybind | ||
|
||
(...) | ||
|
||
# INFO(Rafael): Send one fake ARP packet to 192.168.5.142. | ||
if macgonuts_pybind.macgonuts_spoof('eth0', '192.168.5.142', '192.168.5.1') != 0: | ||
print('error when trying to spoof.\n'); | ||
(...) | ||
|
||
(...) | ||
|
||
# INFO(Rafael): Send 200 fake NDP packets to dead::beef:1 at each 500 mss. | ||
if macgonuts_pybind.macgonuts_spoof('eth1', | ||
'dead::beef::8e', | ||
'dead::beef:1', 200, 500) != 0: | ||
print('error when trying to spoof.\n'); | ||
(...) | ||
|
||
(...) | ||
|
||
# INFO(Rafael): Now undoing all promoted spoofing attacks. | ||
if macgonuts_undo_spoof('eth0', '192.168.5.142', '192.168.5.1') != 0: | ||
print('unable to undo spoof attack done from eth0') | ||
(...) | ||
|
||
if macgonuts_undo_spoof('eth1', 'dead::beef:8e', 'dead::beef:1') != 0: | ||
print('unable to undo spoof attack done from eth1') | ||
(...) | ||
|
||
(...) | ||
``` | ||
|
||
[``Back``](#topics) |
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
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
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
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
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
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,53 @@ | ||
# | ||
# Copyright (c) 2023, Rafael Santiago | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
# | ||
|
||
""" Macgonuts general spoofing utilities binds for Python """ | ||
|
||
cdef extern from "macgonuts_pybind.h": | ||
int macgonuts_pybind_spoof(char *lo_iface, char *target_addr, char *addr2spoof, | ||
int fake_pkts_amount, int timeout); | ||
|
||
cdef extern from "macgonuts_pybind.h": | ||
int macgonuts_pybind_undo_spoof(char *lo_iface, char *target_addr, char *addr2spoof); | ||
|
||
def macgonuts_spoof(lo_iface, target_addr, addr2spoof, fake_pkts_amount = 1, timeout = 0): | ||
"""The python wrapper for macgonuts_spoof() C function | ||
By using this function you can easily promote a spoofing attack based on IPv4 or IPv6. | ||
This function receives: | ||
- the local interface label (lo_iface) | ||
- the target IPv4/IPv6 address (target_addr) | ||
- the IPv4/IPv6 address which will be spoofed at the target host (addr2spoof) | ||
- the amount of fake address resolution packets to be sent (fake_pkts_amount, its default is one packet only) | ||
- the timeout amount between the current packet and the next (timeout, its default is no timeout) | ||
It returns zero on success and non-zero value on failure, besides writing some error description to stderr. | ||
""" | ||
return macgonuts_pybind_spoof(bytes(lo_iface, 'ascii'), | ||
bytes(target_addr, 'ascii'), | ||
bytes(addr2spoof, 'ascii'), | ||
fake_pkts_amount, timeout) | ||
|
||
def macgonuts_undo_spoof(lo_iface, target_addr, addr2spoof): | ||
"""The python wrapper for macgonuts_undo_spoof() C function | ||
By using this function you can easily undo a previous promoted spoofing attack based on IPv4 or IPV6. | ||
This function receives: | ||
- the local interface used during the spoofing attack (lo_iface) | ||
- the target IPv4/IPv6 address of the spoofing attack (target_addr) | ||
- the IPv4/IPv6 address which was spoofed at the target host (addr2spoof) | ||
It returns zero on success and non-zero value on failure, besides writing some error description to stderr. | ||
""" | ||
return macgonuts_pybind_undo_spoof(bytes(lo_iface, 'ascii'), | ||
bytes(target_addr, 'ascii'), | ||
bytes(addr2spoof, 'ascii')) |
Oops, something went wrong.